[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Request for critique on a small makefile
From: |
Edward Z. Yang |
Subject: |
Re: Request for critique on a small makefile |
Date: |
Tue, 12 Dec 2006 16:26:21 -0500 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041206 Thunderbird/1.0 Mnenhy/0.6.0.104 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Philip Guenther wrote:
> 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.
Okay, I've read it, they seem to be very common sense rules, let's see
if I can see how they were applied.
> 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
Regarding number two, these two don't edit $@, does that mean we need a
.PHONY rule?
> fibonacci: fibonacci.o
> ${LINK.cc} -o $@ $< ${boostlib}
A lot of variables used here.
${LINK.cc} is a macro for a C++ linker with all the options we specified
above
$@ is the target of the rule
$< are the prerequisites (one or all of them?)
${boostlib} is the var we stated
> 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
I'm running GNU make of a cygwin compatibility layer. As is, the
executables are magically getting .exe suffixes, breaking `make clean`.
How do I fix this?
> - 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/
Okay. I read somewhere else that objects should be put in another
directory, but I'll read more about multi-architecture VPATH method
before doing it.
> 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
Regarding the auto-exe output, when I run `make -n`, I get the same
result, so it's not g++'s fault. Cygwin?
Also, is gmake the name of your make executable or simply an alias to
make to make sure any other programs named make don't conflict?
> 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'...
Good to know. I have found
<http://www.gnu.org/software/make/manual/html_node/Name-Index.html> to
be slightly more useful, though.
> Does that help at all?
Definitely.
- --
Edward Z. Yang Personal: address@hidden
SN:Ambush Commander Website: http://www.thewritingpot.com/
GPGKey:0x869C48DA http://www.thewritingpot.com/gpgpubkey.asc
3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFfx59qTO+fYacSNoRAjThAJ4p8qJcM4VHx2q6+CO/uqAuaOoOGwCePEz7
JPYLzB6ZyZiJCiuUE6YoPSo=
=C/x7
-----END PGP SIGNATURE-----
- Request for critique on a small makefile, Edward Z. Yang, 2006/12/11
- Re: Request for critique on a small makefile, Philip Guenther, 2006/12/12
- Re: Request for critique on a small makefile,
Edward Z. Yang <=
- 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