• 13
• 27
• 9
• 9
• 20

# generating a list of needed files for use in makefiles

This topic is 2885 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

In my makefiles, and other makefiles I've seen, there's always this kind of line:
$OBJECTS=main.o xxx.o yyy.o So, once you want to add another file or class or whatever to you project you have to manually add it to the makefile. For example, I want to add zingabo.cpp to my project so I have to edit the above line to: $OBJECTS=main.o xxx.o yyy.o zingabo.o
Is there a way to automatically do that? (Without using an IDE or my nice Python script) I've also read a little about the GNU autotools and from what I understood you still have this kind of problem only in a different manner, i.e. you still have to manually edit some file whenever a new file is added to the project. Please enlighten me. P.S. I'm using Vim under GNU/Linux.

##### Share on other sites
A minimal example of what I have in my makefiles

CC = g++ #compiler nameBIN = demo #binary nameSUBDIRS = . #list of source directoriesSRC = $(foreach dir,$(SUBDIRS) , $(wildcard$(dir)/*.cpp)) #generate the list of source filesOBJ = $(SRC:.cpp=.o) #generatethe list of obj filesall:$(BIN)     $(CC)$(OBJ) -o $@%.o : %.cpp$(CC) -c $< -o$@

You can also use cmake, which can do the same thing.