# generating a list of needed files for use in makefiles

## Recommended Posts

Lord Gzoo    155
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
Arkhyl    626
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.

##### Share on other sites
demonkoryu    980

##### Share on other sites
Lord Gzoo    155
Alright :) thank you very much for the replies