[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Request for critique on a small makefile
From: |
Philip Guenther |
Subject: |
Re: Request for critique on a small makefile |
Date: |
Tue, 12 Dec 2006 00:59:44 -0700 |
On 12/11/06, Edward Z. Yang <address@hidden> wrote:
...
So, here is a fairly simple Makefile that works. I would like to know if
I did anything wrong, went against any good practice, i.e. did anything
that could become a bad habit. How portable is this Makefile? Thanks!
First off, you should take a look at Paul Smith's rules for makefiles:
http://make.paulandlesley.org/rules.html
You current makefile violates rules 2, 3, and 4 from that page.
Rather than try to do a line-by-line analysis, let me show how I would
write the makefile for building those two programs:
boostdir = /usr/include/boost-1_33_1
boostlib = -lboost_program_options-gcc-mt-s
# these next two variables are used by make's builtin pattern rules
CXXFLAGS = -ansi -pedantic
CPPFLAGS = -I${boostdir}
programs = fibonacci printNumbers
all : ${programs}
clean:
${RM} ${programs} *.o
fibonacci: fibonacci.o
${LINK.cc} -o $@ $< ${boostlib}
Notes:
- the source files aren't mentioned at all. Instead, I practice my
laziness and let
make's pattern rules figure out how to create the .o files
- as it traditionaly under UNIX, the executables don't have a .exe
suffix. If you *really*
want the suffix, you would do the following:
1) change the value of the 'programs' variable
2) add the .exe suffix to just the target in the rule for linking fibonacci
3) add a rule for linking printNumbers.exe similar to the one for
fibonacci.exe
- the object files are left in the current directory. Don't change
this without first
reading all of Paul's webpages on Make at http://make.paulandlesley.org/
Here's the output of make -n with that makefile in a directory
containing files fibonacci.cpp and printNumbers.cpp:
$ gmake -n
g++ -ansi -pedantic -I/usr/include/boost-1_33_1 -c -o fibonacci.o fibonacci.cpp
g++ -ansi -pedantic -I/usr/include/boost-1_33_1 -o fibonacci
fibonacci.o -lboost_program_options-gcc-mt-s
g++ -ansi -pedantic -I/usr/include/boost-1_33_1 printNumbers.cpp
-o printNumbers
If you aren't sure what pattern rules or variables are builtin to your
copy of GNU make, you can dump the entire set using the following
command:
gmake -pq -f/dev/null
That generates 1085 lines of output on my system, so you may want to
redirect it to a file or pipe it to 'less'...
Does that help at all?
Philip Guenther
- Request for critique on a small makefile, Edward Z. Yang, 2006/12/11
- Re: Request for critique on a small makefile,
Philip Guenther <=
- Re: Request for critique on a small makefile, Edward Z. Yang, 2006/12/12
- Re: Request for critique on a small makefile, Philip Guenther, 2006/12/12
- Re: Request for critique on a small makefile, Edward Z. Yang, 2006/12/12
- Re: Request for critique on a small makefile, Philip Guenther, 2006/12/12
- Re: Request for critique on a small makefile, Edward Z. Yang, 2006/12/12
- Re: Request for critique on a small makefile, Greg Chicares, 2006/12/12
- Re: Request for critique on a small makefile, Greg Chicares, 2006/12/12