Original Post
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