Your SlideShare is downloading. ×
Basic Make
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Basic Make


Published on

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

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

Published in: Technology

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide
  • Transcript

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