Introduction to Make <ul><ul><li>Alec Clews </li></ul></ul><ul><ul><li>Victorian Linux Programmers </li></ul></ul><ul><ul>...
Building Software <ul><li>Computer programmes can be large and complex. </li></ul><ul><li>Building is hard to do </li></ul...
Make is <ul><li>An expert system that builds software (or anything else e.g. Docbook) </li></ul><ul><li>Easy for end users...
How is it used? <ul><li>Build instructions listed in a makefile, with a list of components to be build </li></ul><ul><ul><...
Example <ul><li>Consider a small C program </li></ul><ul><ul><ul><li>./inc/fa.h </li></ul></ul></ul><ul><ul><ul><li>./inc/...
Example makefile <ul><li>bin/proga: obj/proga.o obj/fa.o obj/fb.o </li></ul><ul><ul><li>-mkdir bin/ </li></ul></ul><ul><ul...
Makefile format <ul><li>Makefile stanzas look like </li></ul><ul><ul><li><targetfile>: <dependend files> </li></ul></ul><u...
Makefile processing <ul><li>Make locates all the dependency (source) files and attempts to locate the target. </li></ul><u...
Implicit rules <ul><li>Previous example had lots of identical rules </li></ul><ul><li>Make supports a generic rule templat...
Implicit rule example <ul><li>%.fo: %.dbkx </li></ul><ul><li>xsltproc --output $@  $(XSLT_FILES)  $<  </li></ul><ul><li>I....
Makefiles are hard to debug <ul><li>There is no debugger and processing does not follow the makefile in order </li></ul><u...
Java Issues <ul><li>Make has a problem with languages such as Java (also Ada, Delphi ...) where dependencies are calculate...
Alternatives to Make <ul><li>The make supplied by your SCM vendor </li></ul><ul><li>The make supplied by your compiler ven...
Meta make tools <ul><li>Tools to support the use of Make. Two reasons: </li></ul><ul><ul><li>Handle the generation of make...
Further Reading <ul><li>GNU Make manual </li></ul><ul><li>'Recursive Make considered Harmful', Peter Miller http://cj5.inf...
Upcoming SlideShare
Loading in...5
×

Basic Make

1,118

Published on

A short presentation I gave in 2004 introducing the basic concepts of make

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,118
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Basic Make

    1. 1. Introduction to Make <ul><ul><li>Alec Clews </li></ul></ul><ul><ul><li>Victorian Linux Programmers </li></ul></ul><ul><ul><li>March 2004 </li></ul></ul>
    2. 2. Building Software <ul><li>Computer programmes can be large and complex. </li></ul><ul><li>Building is hard to do </li></ul><ul><ul><li>Takes a long time to rebuild large systems when only small changes made as all files are rebuilt </li></ul></ul><ul><ul><li>Lots of different related components </li></ul></ul><ul><ul><li>Arcane syntax required by tools </li></ul></ul><ul><ul><li>Difficult to repeat reliably </li></ul></ul><ul><ul><li>Documentation (process, environments, inputs, outputs) </li></ul></ul>
    3. 3. Make is <ul><li>An expert system that builds software (or anything else e.g. Docbook) </li></ul><ul><li>Easy for end users to run </li></ul><ul><li>Only rebuilds what has changed </li></ul><ul><li>Understands dependencies between components (files) </li></ul><ul><li>Documents (??) the process and the outputs </li></ul>
    4. 4. How is it used? <ul><li>Build instructions listed in a makefile, with a list of components to be build </li></ul><ul><ul><li>Default file name is 'makefile' </li></ul></ul><ul><li>User types make and makefile is processed </li></ul><ul><li>Usually run in the root of the source/build tree </li></ul>
    5. 5. Example <ul><li>Consider a small C program </li></ul><ul><ul><ul><li>./inc/fa.h </li></ul></ul></ul><ul><ul><ul><li>./inc/fb.h </li></ul></ul></ul><ul><ul><ul><li>./src/fa.c </li></ul></ul></ul><ul><ul><ul><li>./src/fb.c </li></ul></ul></ul><ul><ul><ul><li>./src/proga.c </li></ul></ul></ul>
    6. 6. Example makefile <ul><li>bin/proga: obj/proga.o obj/fa.o obj/fb.o </li></ul><ul><ul><li>-mkdir bin/ </li></ul></ul><ul><ul><li>gcc -o bin/proga obj/proga.o obj/fa.o obj/fb.o </li></ul></ul><ul><li>obj/proga.o: src/proga.c inc/fa.h inc/fb.h </li></ul><ul><ul><li>gcc -o obj/proga.o src/proga.c </li></ul></ul><ul><li>obj/fa.o: src/fa.c inc/fa.h </li></ul><ul><ul><li>gcc -I ./inc -o obj/fa.o src/fa.c </li></ul></ul><ul><li>obj/fb.o: src/fb.c inc/fb.h </li></ul><ul><ul><li>gcc -I ./inc -o obj/fb.o src/fb.c </li></ul></ul>
    7. 7. Makefile format <ul><li>Makefile stanzas look like </li></ul><ul><ul><li><targetfile>: <dependend files> </li></ul></ul><ul><ul><li><tab><shell command to build target> </li></ul></ul><ul><ul><li><tab><optionally more commands> </li></ul></ul>
    8. 8. Makefile processing <ul><li>Make locates all the dependency (source) files and attempts to locate the target. </li></ul><ul><ul><li>If the target does not exist or is out of date compared to a dependency then it's rule fires </li></ul></ul><ul><ul><li>If a dependency does not exist (or is out of date) then make will try and rebuild that first </li></ul></ul><ul><li>I.E. Make traverses the dependency tree and rebuilds out of date or missing nodes </li></ul>
    9. 9. Implicit rules <ul><li>Previous example had lots of identical rules </li></ul><ul><li>Make supports a generic rule template called an implicit rule </li></ul><ul><li>If something needs to be built and there is no explicit rule then implicit rules are searched </li></ul><ul><li>Must use pre-defined macros. e.g. $<, $@ etc. </li></ul>
    10. 10. Implicit rule example <ul><li>%.fo: %.dbkx </li></ul><ul><li>xsltproc --output $@ $(XSLT_FILES) $< </li></ul><ul><li>I.E. if an fo file is required and a dbkx file is found then run xsltproc and supply target name ($@) as output file and first dependency file as input ($<). </li></ul><ul><li>Notes: This example is simplified. </li></ul><ul><li>XSLT_FILE is defined elsewhere in the makefile </li></ul>
    11. 11. Makefiles are hard to debug <ul><li>There is no debugger and processing does not follow the makefile in order </li></ul><ul><li>Use the -p and -d options to dump out (lots) of information for analysis </li></ul><ul><li>Beware the VPATH directive -- it groups the contents of multiple directories together (concatenates the dependency search path) </li></ul>
    12. 12. Java Issues <ul><li>Make has a problem with languages such as Java (also Ada, Delphi ...) where dependencies are calculated by the compiler when doing syntax analysis </li></ul><ul><li>Use Ant instead (an Ant build.xml file does not list all dependencies, depends on javac) </li></ul>
    13. 13. Alternatives to Make <ul><li>The make supplied by your SCM vendor </li></ul><ul><li>The make supplied by your compiler vendor </li></ul><ul><li>Cook by Peter Miller, Canberra – Different syntax </li></ul><ul><li>Apache ANT – Uses an XML build file, very powerful. Consider using instead of make </li></ul><ul><li>JAM – used by the Boost Project </li></ul><ul><li>Openmake (costs $) from Catalyst </li></ul>
    14. 14. Meta make tools <ul><li>Tools to support the use of Make. Two reasons: </li></ul><ul><ul><li>Handle the generation of makefile from a simpler list of source files and final targets </li></ul></ul><ul><ul><li>Handle the porting of makefile between platforms and tool sets. </li></ul></ul><ul><li>GNU uses autoconf and automake </li></ul><ul><li>X uses imake (shudder) </li></ul><ul><li>See also </li></ul><ul><ul><li>CMAKE </li></ul></ul><ul><ul><li>OpenMake ($) </li></ul></ul>
    15. 15. Further Reading <ul><li>GNU Make manual </li></ul><ul><li>'Recursive Make considered Harmful', Peter Miller http://cj5.info/pmiller/books/rmch/ </li></ul><ul><li>'Building with a Version Control Audit Trail', Alec Clews http://xrl.us/os3df </li></ul><ul><li>Managing Projects with make, 2nd Edition, publisher O'Reilly (not brilliant, but about the only single topic book on the subject) </li></ul><ul><li>Many serious *NIX programming books </li></ul>
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×