LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Makefile for multiple cpps (https://www.linuxquestions.org/questions/linux-general-1/makefile-for-multiple-cpps-557686/)

Swakoo 05-30-2007 03:25 AM

Makefile for multiple cpps
 
Hi guys

I have a project which has 5 CPPs files: each representing a component and runs stand-alone.

I know that Makefile can compile things base on the dependency...

1st file: dependence.1 dependence.2
2nd file (which is dependence.1): etc etc

But if I have 5 separate cpps, all dependent on the same set of dependecies.. how should I go about it?

I tried putting them in 1 makefile, but once it compiles the first one, it won't go beyond that, detecting the 1st as "up to date".

anyone?

my current file is like this:
Code:

Client/client: Client/Common/md5.o Client/Common/tea.o Client/Common/wrappers.o
        g++ -o Client/client Client/client.cpp Client/Common/md5.o Client/Common/tea.o Client/Common/wrappers.o
As/as: Client/Common/md5.o Client/Common/tea.o Client/Common/wrappers.o
        g++ -o As/as As/as.cpp Client/Common/md5.o Client/Common/tea.o Client/Common/wrappers.o
TGS/tgs: Client/Common/md5.o Client/Common/tea.o Client/Common/wrappers.o
        g++ -o TGS/tgs TGS/tgs.cpp Client/Common/md5.o Client/Common/tea.o Client/Common/wrappers.o
V1/v1: Client/Common/md5.o Client/Common/tea.o Client/Common/wrappers.o
        g++ -o V1/v1 V1/v1.cpp Client/Common/md5.o Client/Common/tea.o Client/Common/wrappers.o
V2/v2: Client/Common/md5.o Client/Common/tea.o Client/Common/wrappers.o
        g++ -o V2/v2 V2/v2.cpp Client/Common/md5.o Client/Common/tea.o Client/Common/wrappers.o
Client/Common/md5.o:
        g++ -g -c Client/Common/md5.cpp
Client/Common/tea.o: Client/Common/tea.h Client/Common/tea.cpp
        g++ -g -c Client/Common/tea.cpp
Client/Common/wrappers.o:
        g++ -g -c Client/Common/wrappers.cpp


Dark_Helmet 05-30-2007 03:47 AM

I'm going to take a stab at this, but my impression is you haven't looked much at the Make manual online, have you? That's not meant to be mean, but it's a hunch.

I'm assuming you have saved the text you've provided above in a file named "Makefile" and you're running "make" at the commandline, correct?

If that is the case, then my impression is correct. When you run make, you must specify a target. As in "make all" or "make clean". If you don't specify a target, then make assumes you want to update the first target listed in Makefile.

In this case, that would be "Client/client", or as you said yourself: 'the 1st as "up to date".'

You need to add a new target to your Makefile:
Code:

.PHONY: all

all: Client/client As/as TGS/tgs V1/v1 V2/v2

You can get a copy of the make manual (in many different formats) here.

I haven't used the .PHONY target in a while. You'll need to double-check that the syntax is correct.

Swakoo 06-05-2007 12:50 AM

thanks for the tip. i'll check them out


All times are GMT -5. The time now is 10:26 PM.