Skip to main content

"The GNU Make Book": probably more than you ever wanted to know about make

So, it's finally here. My second book, entitled The GNU Make Book and published by No Starch Press later this month (electronically it's available now). If you are a long time reader of my blog then you'll know that I've had a very long interest in GNU make and written quite a bit about it. For a while I had self-published all my articles on GNU make as a print on demand book.

The folks at No Starch Press kindly took my self-published effort and did the serious work of actually editing, organizing, indexing and generally sprucing it up. I added some articles that weren't in the old version and updated for GNU make 4.0.

And now it's here.



The book is not intended for people learning GNU make from scratch. If you need to do that go get the FSF's GNU make manual and read it. It covers all that you need to get started with GNU make.

Once you've done that you'll be ready to read mine. It's based on years of working with real makefiles, on having written a complete emulation of GNU make and having created the GNU Make Standard Library project.

It's thoroughly practical and I hope the ideas and techniques in it will prove useful to real-world makefile writers and maintainers. If you're interested there's sample chapter and Table of Contents.


Comments

Nick Alcock said…
I cannot recommend this book enough. I bought the previous version, printed it out, and am now trying to convince myself that the updates are surely worth paying for it again :) I suspect I will succumb fairly fast.
David L Ward said…
errata
I have make 3.81 on ubuntu 14.4
p8 env_file lacks line continuation \ chars


p82 @echo "S(subst ",\" - should be $ not S

p92 using gcc -MP
does not compile
# ~/gnumake/g_c/code/ch3/p92-> make
# cc1: error: to generate dependencies you must specify either -M or -MM
# make: *** [hello_fn.o] Error 1
# ~/gnumake/g_c/code/ch3/p92->


p98
include $(addsuffix /makefile,$(SUBDIRS ))
for the code that follows should be 'Makefile'

p125
' make strips all leading and trailing whitespace around function arguments'
I think this only applies to ws before the first argument. You could add that no whitespace should appear between '$(' and function name

p127
if-exists
misplaced '(' ($wildcard $1), ....
should be $(if $(wildcard $1),$2,$3)

p135

$(OUT)foo.o : ... should be $(OUT)/foo.o



p146
basename is /foo/bar/source NOT source

p165
'It converts both x-representation numbers to digits but compares --using $(filter-out) -- the first of them'
should be second


p167
bottom of page
should be make calc="1,3,-,3,21,5,*,+,/" not "3,1...
1,3,- gives 3-1=2
21*5 =105
105 +3 =108
108/2 =54 (LIFO)

p167 and p168
in input_int one too many closing parentheses


p205
$(call repeat 10,A) should be $(call repeat,A,10) --- $2 must be a numerical arg


Feedback

I found your treatment of non-recursive make very helpful and I liked your
David L Ward said…
errata
I have make 3.81 on ubuntu 14.4
p8 env_file lacks line continuation \ chars


p82 @echo "S(subst ",\" - should be $ not S

p92 using gcc -MP
does not compile
# ~/gnumake/g_c/code/ch3/p92-> make
# cc1: error: to generate dependencies you must specify either -M or -MM
# make: *** [hello_fn.o] Error 1
# ~/gnumake/g_c/code/ch3/p92->


p98
include $(addsuffix /makefile,$(SUBDIRS ))
for the code that follows should be 'Makefile'

p125
' make strips all leading and trailing whitespace around function arguments'
I think this only applies to ws before the first argument. You could add that no whitespace should appear between '$(' and function name

p127
if-exists
misplaced '(' ($wildcard $1), ....
should be $(if $(wildcard $1),$2,$3)

p135

$(OUT)foo.o : ... should be $(OUT)/foo.o



p146
basename is /foo/bar/source NOT source

p165
'It converts both x-representation numbers to digits but compares --using $(filter-out) -- the first of them'
should be second


p167
bottom of page
should be make calc="1,3,-,3,21,5,*,+,/" not "3,1...
1,3,- gives 3-1=2
21*5 =105
105 +3 =108
108/2 =54 (LIFO)

p167 and p168
in input_int one too many closing parentheses


p205
$(call repeat 10,A) should be $(call repeat,A,10) --- $2 must be a numerical arg


Feedback

I found your treatment of non-recursive make very helpful and I liked your
Unknown said…
Hello,

Someone tested the non-recursive makefile ? About 1 week I am trying to make it work. I've checked and rechecked my scripts.
I'm on Mac, using gnumake 3.8.
I'm using the example of the book and tried on e personal project too but the error seems to be from the same origin.
When I do a simple make at the root of the project, it says to me:
make: *** No rule to make target `/tmp/out//Users/malberte/work/generic_makefile/src/lib1.o', needed by `/tmp/out//Users/malberte/work/generic_makefile/src/lib.a'. Stop.

I've used $(info) on _MODULE_NAME, it gives me
_Users_malberte_work_generic_makefile_src

Inside the /tmp/out folder, weird folders are created too:
Users/
Users/malberte
Users/malberte/work
Users/malberte/work/generic_makefile

generic_makefile is the name of my project

Anyone has an idea of what is happening ?

Popular posts from this blog

Your last name contains invalid characters

My last name is "Graham-Cumming". But here's a typical form response when I enter it:


Does the web site have any idea how rude it is to claim that my last name contains invalid characters? Clearly not. What they actually meant is: our web site will not accept that hyphen in your last name. But do they say that? No, of course not. They decide to shove in my face the claim that there's something wrong with my name.

There's nothing wrong with my name, just as there's nothing wrong with someone whose first name is Jean-Marie, or someone whose last name is O'Reilly.

What is wrong is that way this is being handled. If the system can't cope with non-letters and spaces it needs to say that. How about the following error message:

Our system is unable to process last names that contain non-letters, please replace them with spaces.

Don't blame me for having a last name that your system doesn't like, whose fault is that? Saying "Your last name …

Importing an existing SSL key/certificate pair into a Java keystore

I'm writing this blog post in case anyone else has to Google that. In Java 6 keytool has been improved so that it now becomes possible to import an existing key and certificate (say one you generated outside of the Java world) into a keystore.

You need: Java 6 and openssl.

1. Suppose you have a certificate and key in PEM format. The key is named host.key and the certificate host.crt.

2. The first step is to convert them into a single PKCS12 file using the command: openssl pkcs12 -export -in host.crt -inkey host.key > host.p12. You will be asked for various passwords (the password to access the key (if set) and then the password for the PKCS12 file being created).

3. Then import the PKCS12 file into a keystore using the command: keytool -importkeystore -srckeystore host.p12 -destkeystore host.jks -srcstoretype pkcs12. You now have a keystore named host.jks containing the certificate/key you need.

For the sake of completeness here's the output of a full session I performe…

More fun with toys: the Ikea LILLABO Train Set

As further proof of my unsuitability to be a child minder (see previous post) I found myself playing with an Ikea LILLABO 20-piece basic set train.


The train set has 16 pieces of track (12 curves, two straight pieces and a two part bridge) and 4 pieces of train. What I wondered was... how many possible looping train tracks can be made using all 16 pieces?

The answer is... 9. Here's a picture of the 9 different layouts.


The picture was generated using a little program written in Processing. The bridge is red, the straight pieces are green and the curves are blue or magenta depending on whether they are oriented clockwise or anticlockwise. The curved pieces can be oriented in either way.

To generate those layouts I wrote a small program which runs through all the possible layouts and determines which form a loop. The program eliminates duplicate layouts (such as those that are mirror images of each other).

It outputs a list of instructions for building loops. These instructions con…