How to create directories from makefiles?
Could you help me with the following code I have written?
VPATH= balll mall fall
OBJECTS= objj/goka.o objj/foka.o objj/hoka.o
exec/gola: $(OBJECTS)
gcc $^ -o $@
$(OBJECTS): objj/%.o : %.c
gcc -c $< -o $@
What I want to do is: I don't have exec directory and obj directory and I want them to be created during the compiling of the file and save those files in their respective directories. Can I do that? Creating the directory exec and telling the gcc to save the gola target file in exe开发者_如何学Pythonc directory and same with the objective files. Is there any command to deal with it?
Try order-only prerequisites. (See the make manual).
Just add mkdir -p dir1 dir2
to the appropriate rule of your makefile, prior to compilation.
Example: (You'll have to modify this for your particular setup)
DIR = obj exec
VPATH= balll mall fall
OBJECTS= objj/goka.o objj/foka.o objj/hoka.o
exec/gola:$(OBJECTS)
gcc $^ -o $@
$(OBJECTS): objj/%.o : %.c
mkdir -p $(DIR)
gcc -c $< -o $@
精彩评论