# make questions

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

## Recommended Posts

Yo, noob here. Or actually, not noob. Just a noob with make. Very nice, that thing, it's just: I can't get it work with different directories. I once worked with Ant, very nice, but Ant makes problems with the 'sdl-config' script. I wanna put all my sources into one directory ([...]/src), then the objects ([...]/obj) and the executable in the root dir of the project... I can't get it to work, make makes problems I can solve, and the documentation has huge holes on that topic. Or maybe I'm just too stupid, who knows... Anyway, I hope you can help me, and forgive my stupitidy... Scánkalantesh...

##### Share on other sites
When I had problems with my makefiles several weeks ago, I refered to this thread.
Especially this post.
And all my problems magically dissapeared.

Hope that helps. If not, I could post my own makefile here.

##### Share on other sites
Does this makefile work for you?

test.exe: obj\test.o	gcc -o test.exe obj\test.oobj\test.o: src\test.c	gcc -o obj\test.o src\test.c -c

Place it in the root directory of your project, which contains subdirs src\ and obj\. This will compile a source file src\test.c, placing the object file in obj\ (obj\test.o), and the executable file in the root directory.

##### Share on other sites
Sorry, but not really...
I tried that, yeh, but I wanna but them all into one variable... I tried this:
symbol.

##### Share on other sites
You might want to do what most projects do:
1. Create a general-purpose makefile that compiles all sources in current directory.
2. Copy such makefile to each directory.
3. Recursively call makefiles in child directories.
4. Each recursive call will also move compiled .o files to target location (just like VC++ does).

##### Share on other sites
Well... that could be the problem... It is looking for the file in the root directory, isn't it? How can I solve that?
with
%.o: $(SRCDIR)/%.cpp maybe? #### Share this post ##### Link to post ##### Share on other sites How do I make recursive make calls? #### Share this post ##### Link to post ##### Share on other sites Quote:  Original post by FalShenWell... that could be the problem... It is looking for the file in the root directory, isn't it? How can I solve that? me thinks: copy the makefile to each directory and call that recursively. #### Share this post ##### Link to post ##### Share on other sites well, it works now with this code: CC = g++CFLAGS = -O3 -s sdl-config --cflagsLFLAGS = -O3 -s sdl-config --libsOBJECTS = main.oEXECUTABLE = colinSRCDIR = srcOBJDIR = objall:$(EXECUTABLE)$(EXECUTABLE):$(OBJECTS)	$(CC)$(LFLAGS) -o $@$(OBJDIR)/$(OBJECTS)%.o:$(SRCDIR)/%.cpp	$(CC)$(CFLAGS) -c -o $(OBJDIR)/$@ $< Well... I'd also like to see the solution with the recursive calls... But it's solved. Thanks to everyone! #### Share this post ##### Link to post ##### Share on other sites Quote:  Original post by FalShenHow do I make recursive make calls? all: make -C some_directory_1 make -C some_directory_2 mv some_directory_1/*.o$(BUILD_DIR)     mv  some_directory_2/*.o  $(BUILD_DIR) How to automagically get list of directories to maintain such a command-list, I do not know at the moment. I got to think a bit... #### Share this post ##### Link to post ##### Share on other sites Quote:  Original post by FalShen$(EXECUTABLE): $(OBJECTS)$(CC) $(LFLAGS) -o$@ $(OBJDIR)/$(OBJECTS)%.o: $(SRCDIR)/%.cpp$(CC) $(CFLAGS) -c -o$(OBJDIR)/$@$<

It seems to me like it will be recompiling the whole project each time, since the
%.o: $(SRCDIR)/%.cpp directive wil be searching for local .o files, when they will be already in$(OBJDIR).

Quite crappy, IMO.

##### Share on other sites
Well, I now made it with the recursive calls.
Thanks for the help!
Scánkalantesh

$dir1 = dir1/$dir2 = dir2/$files1 = f1.o f2.o f3.o$files2 = f4.o f5.o f6.oall: addprefix($dir1,$files1) addprefix($dir2,$files2)