D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Make was Re: [LUG] shell programming continuued

 

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

PAUL SUTTON wrote:

Looking at make files in the book Linux programming by wrox press, page
368, It looks somewhat confusing,

Makefiles can be as complex as you like. This is what makes them confusing.

Here is a trivially simple example, it is nothing to do with programming.


We have a "book" and "three chapters" and a makefile.

srw@derek:~/tmp$ ls
book  chap1.txt  chap2.txt  chap3.txt  Makefile

The Makefile says that "book" depends on "chap[123].txt" and makes it by
concatenating.

srw@derek:~/tmp$ more Makefile
book: chap1.txt chap2.txt chap3.txt
        cat chap1.txt chap2.txt chap3.txt >book


srw@derek:~/tmp$ make
make: `book' is up to date.

Turns out "book" is newer than its dependencies.



Edit chap1.txt ;)
(Remember 'touch' just updates the time stamp, but that is all 'make'
cares about).

srw@derek:~/tmp$ touch chap1.txt


Now run make.

srw@derek:~/tmp$ make
cat chap1.txt chap2.txt chap3.txt >book


Obviously this "Makefile" is so trivial as to be useless in the real
world, but turn your chapters into "HTML" and force the "Makefile" to
run "tidy" over the chapters before it ftp's them to the webserver, and
you have a trivial web publishing system that only uploads files that
have changed. "book" would then be just be a timestamp file saying when
you last published, which you could "touch" at the end of the list of
actions.


Now read "info make" and check the simple Makefile example under the
"Introduction" section. Which shows and explains a trivial C code makefile.

As pointed out in my response to Robin, GNU make basically has
predefines all the patterns you need for basic programming in C, and
C++, and a few other languages (flex, bison). So often the "Makefile" is
trivial if you make it by hand. They end up looking complex because most
people use the GNU autoconf tools to make them, which are intended to
help you create portable build environments that will compile your code
anywhere the autoconf tools have enough programmed in knowledge.

In general simple C programs contain enough information about their own
structure to allow the GNU autoconf tools to generate their makefiles in
a completely automatic fashion. But I'd leave that till you are happy
writing small C programs, as tools like autoconf and automake are damn
fiddly and get in the way at first,
-----BEGIN PGP SIGNATURE-----
Comment: Encryption...is a powerful defensive weapon for free people.
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCmW4gGFXfHI9FVgYRAtOJAKDCbu2HQthn30YOCb7O9vGmXHMfsgCgjANu
mItWEY5EmTFXNcnYd7UUwTQ=
=qDY9
-----END PGP SIGNATURE-----

--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe. FAQ: www.dcglug.org.uk/linux_adm/list-faq.html