help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Simple Makefile Example


From: cppaddict
Subject: Simple Makefile Example
Date: Wed, 16 Jun 2004 07:08:15 GMT

Hi,

I'm searching for an elegant way to write a Makefile for compiling a
simple C++ application whose source files span multiple directories.
I know this must be a common problem, but I can't seem to find any
satisfactory examples or explanations of solutions on Google or in the
archives.  The general problem I have in mind can be summed up as
follows:

/module1/ -- contains .h .cpp files for module1 and (after make is
run) the .o files
/module2/ -- same as above but for module2
/module2/subModuleA -- same thing, but accounting for nesting deeper
than 1 level
....
etc

The final executable should be placed in the root directory.

Ideally, the Makefile will:

1. Be simple and clean, using Automatic Variables whenever possible.

2. Be robust to changes in the directory structure.  For example, if
file A.cpp moves from module1 to module2 for some reason, only one or
two lines in the Makefile should change.  I imagine info about the
directory structure would be set at the top of the file using
variables somehow, and the guts of the Makefile would depend only on
those variables.

Can anyone send a simple example of such a solution, or point me to a
good reference?

Thanks for any help,
cpp


reply via email to

[Prev in Thread] Current Thread [Next in Thread]