Jump to content
  • Advertisement
Sign in to follow this  
Lord Gzoo

generating a list of needed files for use in makefiles

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
A minimal example of what I have in my makefiles


CC = g++ #compiler name
BIN = demo #binary name
SUBDIRS = . #list of source directories
SRC = $(foreach dir, $(SUBDIRS) , $(wildcard $(dir)/*.cpp)) #generate the list of source files
OBJ = $(SRC:.cpp=.o) #generatethe list of obj files

all: $(BIN)
$(CC) $(OBJ) -o $@

%.o : %.cpp
$(CC) -c $< -o $@



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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!