I have a project written in C
and I am using mercurial
(I can use git
too) for version control and GNU
make
for building. The project includes several empty directorie开发者_如何学Gos used for build-time generated files, such as dependency makefiles and object files.
When I check out the project, however, empty directories are not created (they are ignored by the version control system) and the build fails.
The only remedy I have in mind is to add a mkdir -p
directive in every single recipe in the 58 makefiles of the project (it is quite big). Apart from a lot of editing, mkdir -p
is discouraged in the GNU
make
manual for being incompatible with other versions of make
.
Is there any smarter way to overcome the problem?
Both git and Mercurial track files, not directories, so empty directories will not be stored.
The common trick is to just add an empty file to the directories you need, like:
touch output/.empty
And then add that to the repository.
You can have:
output/%: output/.empty
output/.empty:
$(MKDIR_P) output
touch output/.empty
in the makefile. Than all files in output
will depend on creating the directory without modifying each rule separately.
The $(MKDIR_P)
definition (mkdir -p
for most systems or a special script where that does not work) can be provided by configuration script (e.g. autoconf using AC_PROG_MKDIR_P
) or conditional setting in the makefile.
As you mention that you could use git as well, maybe that you would be interested by the fact that bazaar can track directories the same way it does for files. I don't know if it is an option for you, just saying.
精彩评论