Make (2014-01-19)

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

This is a very simple Make example for people who have never heard of Make.

Say you wrote your resume in LaTeX. Maybe you also want to include a picture of
yourself! You have two files:

  $ ls
  portrait.jpg resume.tex

where resume.tex includes portrait.jpg in the source. Here is how you can
generate your resume:

  $ pdflatex resume.tex
  $ ls
  portrait.jpg resume.pdf resume.tex

But then you realize the file size of your resume is very large! You can reduce
the size of your portrait:

  $ convert portrait.jpg -resize 256x256 portrait_small.jpg
  $ ls
  portrait.jpg portrait_small.jpg resume.pdf resume.tex

and then edit resume.tex to use the new portrait file. If you ever change your
resume, you have to re-run pdflatex. Also, if you ever change your portrait
(e.g. you have grown a beard (or shaved it)), you must re-run convert AND
pdflatex! That's a lot of work!

With GNU Make, the whole build process becomes very easy. Just write a file
named "makefile" containing these two rules:

resume.pdf : resume.tex portrait_small.jpg
	pdflatex resume.tex

portrait_small.jpg : portrait.jpg
	convert portrait.jpg -resize 256x256 portrait_small.jpg

Now, if you ever change anything, all you need to do is run make:

  $ make resume.pdf

and you have your resume! In the makefile above, there are two "rules". Each
rule looks like this:

TARGET_FILE : REQUIRED_FILE_1 REQUIRED_FILE_2 ...
	commands that generate the "target" file from the "required" files
	can be multiple lines (must indent with tab)

In the makefile that generates your resume, Make attempts to create the target
"resume.pdf", but that requires "portrait_small.jpg" which might be old or
might not exist. It looks for another rule with a target named
"portrait_small.jpg" and finds it right below. After creating
portrait_small.jpg, it can go back to the first rule and generate your resume.

This is all the Make I needed to know to get by as an undergraduate in the
Computer Science department at UCLA. It's an extremely useful skill!

Troy

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBAgAGBQJS26n8AAoJEILOu+6H2FfC9bYP/i8iBLVxc0MLCLch3ozpI0hG
A169HNdkSfqfxQaYJr/vL1DL3i/lz6b1tWk1VWsW8hRM4+Nn9qT4ofRLa6FPBvkU
vaThJYs+c3yZUe9yyQr36TqrVaXQJUjKEj9+zhMTGvkRwiZ14sQi6vO6kUf5+T8n
KPQyBVUGCh1mknOUlAg4evBxpDao/34n7Q0+EtIT5WMEfZhQR21HBTet4NCvZ9aU
ay4OlU+4adkdCnMSbK0/q41Ev6WFxq126JhPEH8GuvXWYoEPNHHCxFpH6+y3neXu
X3f8f4jdUZkXzlYgFgUaBZ/9+vICBBW0ijnb64FDygQNK882XU0vAuwbi68yS2tX
YnR949PzQz1od/0iVnJPg+wv3C6sCEd+T3ltJQRcHwh3gVrl/wYPedZPC3NmAxBD
G5RH+NLezmPg8IaDL/o9AKrr6G5F3hMvAWPZXCG/iM7JuG6HcJ/Lf/HoLkvraIG0
4Z5YtQGxTWcFauU4okDBzFH/07q0IjYB2fjLs4+iKh/Ay5UbpxU2++1iABomrmv9
g2xgMPSOUheKVuQjzDAh/k64fc72FvCpbGDB0lcnCKpH+GWVLyn8bpeXkhcxNq4P
SzIcMpgPf1MYnIKGMIk85Q37TQDfCb/idZY61c70xLDQz1wK1nRlRy0h5aX4JzVt
zQ2E0KA7sCToxyb0z1Tp
=nMNL
-----END PGP SIGNATURE-----

back to Troy's homepage