I have several programs in several directories and want to use make to build the executables. What I have done is to put the main programs in their own directory together with a makefile to build the program. Then I am thinking of having another makefile residing in the directory above so I can run those makefiles.
Is this the way to do things or are there better suggestions?
---------- Post updated at 02:54 PM ---------- Previous update was at 02:23 PM ----------
Currently I have the following tree
boost-exx
bin
exx01
exx01.cc
exx01.o
Makefile
exx02
exx02.cc
Makefile
exx03
exx03.cc
Makefile
Makefile
---------- Post updated at 03:01 PM ---------- Previous update was at 02:54 PM ----------
The sub makefiles are as follows, with different SOURCES and EXECUTABLE
according to the directory name.
CPP = g++
CPPFLAGS = -pedantic -Wall -Wextra -Werror -Wno-non-template-friend -DNDEBUG
BOOSTIP = -I../boost_1_52_0
BOOSTLP = -L./library/boost_1_52_0/libs
SOURCES = exx01.cc
OBJECTS = $(SOURCES:.cc=.o)
EXECUTABLE = exx01
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CPP) $(BOOSTLP) $(OBJECTS) -o $@
.cc.o:
$(CPP) $(CPPFLAGS) $(BOOSTIP) $< -o $@
.PHONY: clean
clean:
rm -f $(EXECUTABLE) *.o
---------- Post updated at 03:14 PM ---------- Previous update was at 03:01 PM ----------
The main makefile is like this, but is not working
# Main makefile
PROG = exx
TRGTS = exx01 exx02 exx03
$(PROG): $(TRGTS)
all: $(TRGTS)
exx01:
cd ./exx01 ; make exx01
exx02:
cd ./exx02 ; make exx02
exx03:
cd ./exx03 ; make exx03
clean:
rm -f *.o *~
cd ./exx01 ; make clean
cd ./exx02 ; make clean
cd ./exx03 ; make clean
---------- Post updated at 03:47 PM ---------- Previous update was at 03:14 PM ----------
My subdirectory makefiles are not working either
---------- Post updated at 04:19 PM ---------- Previous update was at 03:47 PM ----------
Now I have changed the internal makefiles which build the programs successfully
Hence the remaining problem is fixing the top makefile
CPP = g++
CPPFLAGS = -pedantic -Wall -Wextra -Werror -Wno-non-template-friend -DNDEBUG
BOOSTIP = -I../../boost_1_52_0
BOOSTLP = -L../../boost_1_52_0/libs
SOURCES = exx02.cc
OBJECTS = $(SOURCES:.cc=.o)
EXECUTABLE = exx02
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CPP) $(BOOSTLP) $(OBJECTS) -o $(EXECUTABLE)
%.o : %.c
$(CPP) $(CPPFLAGS) $(BOOSTIP) -c $<
.PHONY: clean
clean:
rm -f $(EXECUTABLE) *.o