makefile - How to create directory if needed? -
i'm trying use makefile, problem have directory, src directory , makefile. use tmp directory have create. has object files in it. , performance, try not delete these when debugging. if create rule tmp create it, rebuilds c files. how this?
there number of ways. depends on version of make you're using , operating system you're using.
the 1 thing must never use directory simple prerequisite. rules filesystem uses update modified time on directories not work make.
for simple make on posix system, can pre-create directory in rule perform compilation:
obj/foo.o: foo.c @ mdkir -p obj $(cc) $(cppflags) $(cflags) -c -o $@ $< if have gnu make have 2 options. simplest 1 force directory created when makefile read in before else happens, adding line this:
_dummy := $(shell mkdir -p obj) the easy, fast, , reliable. downside directory created always, if it's not needed. nevertheless way it.
the fancy way, if have new-enough gnu make, use order-only prerequisites:
obj/foo.o: foo.c | obj $(cc) $(cppflags) $(cflags) -c -o $@ $< obj: mkdir -p $@ this forces obj target built before obj/foo.o target, but timestamp on obj ignored when determining whether obj/foo.o out of date.
Comments
Post a Comment