Reputation: 21
I'm new to makefiles, and I'm using Cygwin to make my files. I have source files in three different directories and I compiled them using the VPATH technique, but the object files are generated in the current directory.
I want all the object files to be generated in one directory and the target file in other directory. [That is, the .mk file in some other directory] How can I do that? How can I tell the compiler to generate them in the specified directory?
Here is my program:
vpath %.c bad good ugly
gcc $(CFLAGS) -c $< -o $@
gola:goka.o foka.o hoka.o
gcc $^ -o $@
goka.o:goka.c
gcc -c $<
foka.o:foka.c
gcc -c $<
hoka.o:hoka.c
gcc -c $<
How do I put all object files in one directory and the gola
[mk] file in the specified directory?
Upvotes: 2
Views: 596
Reputation: 99164
You haven't said where you want these files (and I couldn't make sense out of what you said about "mk file"), but this will put the object files in obj/
and construct gola
in bin/
.
vpath %.c bad good ugly
# gcc $(CFLAGS) -c $< -o $@ this line makes no sense
OBJECTS = obj/goka.o obj/foka.o obj/hoka.o
bin/gola: $(OBJECTS)
gcc $^ -o $@
$(OBJECTS): obj/%.o : %.c
gcc -c $< -o $@
There are ways to make the makefile cleaner, shorter, more flexible, but they are advanced techniques.
Upvotes: 1