Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
Python and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Lua, etc
 
A Complete makefile example

Part of a series, written to brush up some make notes I'm using for some make training next week

Let's write a complete makefile - from first principles:

  # This is our first makefile
  
  # Target "always" never exists, so rules will always run
  
  always:
      echo "Hello Make World"
  
  # Rule will only run if "once" already exists
  # By touching the file, we create it thus preventing re-runs
  
  once:
      echo "single shot"
      touch once
  
  # Target "clean" never exists, so this will always run
  # extra "@" supresses the echoing of the command being run
  # but you still see their output
  
  clean:
      @echo "Cleaning up"
      @rm once
      @echo "Completed"


Let's see that running:

  wizard:mc graham$ make -f firstmake
  echo "Hello Make World"
  Hello Make World
  wizard:mc graham$ make -f firstmake
  echo "Hello Make World"
  Hello Make World
  wizard:mc graham$ make -f firstmake once
  echo "single shot"
  single shot
  touch once
  wizard:mc graham$ make -f firstmake once
  make: `once' is up to date.
  wizard:mc graham$


Some things to note:

* If no dependencies are given, the rule is always applied (and if multiple dependencies are given, then the rules are applied if ANY of the files is newer than the target)

* touch is commonly used to create an empty file if you're wanting to perform actions and don't really need an output file at all.

* If you preceed a command with an @symbol, the command is not echoed out as it is run. The first two examples above rather nastily double up the echoed text, but in "clean" that's not the case.

* If an error occurs during the application of a rule, it will cease at that point:

  wizard:mc graham$ make clean
  Cleaning up
  rm: once: No such file or directory
  make: *** [clean] Error 1
  wizard:mc graham$


but an extra - sign will cause the error to be ignored in that the rule will continue:
    @-rm once

* The default makefile is called "makefile" or "Makefile" (both will work). You can use the -f command line option to specify a different file, or the MAKEFILES environment variable though this latter has some implications with regard to nesting of makefiles later on:

  wizard:mc graham$ export MAKEFILES=secondmake
  wizard:mc graham$ make clean
  Cleaning up
  wizard:mc graham$

(written 2012-03-14)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
A168 - Web Application Deployment - Compiler and development tools
  [4585] What is make? What is gcc? - (2015-11-28)
  [4013] Web Frameworks - nested templates - (2013-02-22)
  [3666] Makefile variables - defined internally, from the command line and from the environment - (2012-03-22)
  [3658] Using Make for a distribution - (2012-03-17)
  [3651] Makefile - some basics, and a demonstration - (2012-03-13)
  [3632] What is Make? - (2012-03-02)
  [3053] Make - automating the commands for building and installing - (2010-11-16)
  [2674] Make and makefiles - a commented example to help you learn - (2010-03-12)
  [1671] Compiling C programs with gcc - an overview - (2008-06-10)
  [694] Ant and Make - (2006-04-22)


Back to
Makefile - some basics, and a demonstration
Previous and next
or
Horse's mouth home
Forward to
What is happening in 59 days time in Melksham?
Some other Articles
TrainWest 2012 - 14th and 15th April, Melksham, Wiltshire
Sights and scenes - more London trip pictures
On a sunny afternoon in London
What is happening in 59 days time in Melksham?
A Complete makefile example
Possessive Regular Expression Matching - Perl, Objective C and some other languages
A single action for multiple iPad / iPhone buttons, and animation
iPad and iPhone programming - our seminar weekend with Xcode
Along the brook - East Melksham to Melksham
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2019: 404 The Spa • Melksham, Wiltshire • United Kingdom • SN12 6QL
PH: 01225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3652_A-C ... ample.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat