How can I add a directory path to my makefile?

This what my makefile looks like now.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CXXFLAGS = -m32

all: p2

p2 : CreatureClass.o HumanoidClass.o MonsterClass.o
 
CreatureClass.o : CreatureClass.h 

HumanoidClass.o : HumanoidClass.h

MonsterClass.o : MonsterClass.h

clean: 
	rm CreatureClass.o HumanoidClass.o MonsterClass.o p2 



Obviously all of the files are in the same folder at the moment but I would like for Creature, Monster, and Humanoid to have their own folders.

How can I revise this makefile so that I can specify a path to each folder?

Let's say that:

Creature path = "~330/program/p2/Creature"
Monster path = "~330/program/p2/Monster"
Humanoid path = "~330/program/p2/Humanoid"

Thanks in advance



It must not be easy then, I guess.
I'd say annoying would be a more accurate description of this task then difficult. So much so that I (personally) would normally just start a new project and add the objects source code to the new project by hand through the IDE. What you're asking IS possilble though.
If you are using gnu make then you can specify where to put an object file using -o

e.g.

Creature/Creature.o : Creature/Creature.h Creature/Creature.cpp
g++ -c -o Creature/Creature.o Creature/Creature.cpp

will compile Creature/Creature.cpp and put the object file in Creature/Creature.o

you can then make the whole project from a single Makefile (i.e. not using recursive make)
Topic archived. No new replies allowed.