Skip to main content
gamedev.net
🔒 Locked

generic Makefile

Started by trickypig Dec 12, 2008 at 2:44 PM 1 replies 650+ views
Original Post
trickypig
trickypig
I'm trying to create a Makefile that will automatically use all the .cpp files in my src/ directory to make objects in the obj/ directory, and then create an executable in the root directory. I can do all of this except make the object files go into a different directory. Can anyone help? Here is my Makefile so far: CC= g++ CFLAGS= -Wall LDFLAGS= -Wall SRCDIR= src # automatically get all .cpp files in the src/ directory SRCS= $(wildcard $(SRCDIR)/*.cpp) # ideally, this should be "obj" OBJDIR= src # build the list of .o files from the list of .cpp files # TODO: how to get it to change the directory from src/ to obj/ OBJS= $(SRCS:.cpp=.o) DEPEND= makedepend $(CFLAGS) all: hexmap $(OBJDIR)/%.o: $(SRCDIR)/%.cpp $(CC) -c -o $@ $< $(CFLAGS) hexmap: $(OBJS) $(CC) $(LDFLAGS) -o hexmap $(LIBS) $(OBJS) depend: $(SRCS) $(DEPEND) $(SRCS) clean: -rm hexmap *~ *.o *.bak core $(OBJDIR)/*.o
trickypig
trickypig
ok, figured it out:

OBJS= $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))

that builds the list of all necessary objs, but converts src/xxx.cpp to obj/xxx.o
the_edd
the_edd
Unfortunately, this doesn't track dependencies of object files on headers.

You'll need to use a tool like makedepend or some use some sed magic for that.


Sorry, i'll read more carefully next time :(

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.