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
 
Makefile variables - defined internally, from the command line and from the environment

How do you control makefiles from the environment in which they are run? You can do so with make variables, which can be set externally from your calling shell / program, or from the make command line.

If I set a shell variable and export it, it will be available in my Makefile.
If I specify a variable on the command line to make, then it will be available in my Makefile.
If I specify a varaible with ":=" within my Makefile, it will be immediatelly avaiable thereafter.

If you specify the same variable in more than one of these ways, it's the latter that takes precedence.

Within my Makefile, I can also specify a variable with "?=", in which case that setting takes a lower precedence - in other words, I'm specifying a safety net to be used only if the value's not specified in the outer shell or on the command line.

And - to add a further step to the complexity - I can also specify a variable with "=" within my Makefile. In this case, the actual substitution is delayed until the variable is actually used (and indeed it's then substitued recuresively). So the value assigned will be a run time value, rather than an immediate value. If you're an experienced Tcl programmer, this is rather like a deferred block in {} as opposed to an immediate parameter in "".

In order to help delegates to whom I was teaching Make earlier this week, I put together an example that sets various variable types. The full make file is [here]. Have a look at the mode variable.

  munchkin:csv grahamellis$ make clean
  Melksham and
  Mode no. 30, written by Graham of Melksham
  Written by Graham of [i]
  Written by Graham of Melksham [d]
  Copyright, Well House Consultants
  Copyright, Well House Consultants,
  Make level is 0
  Mode setting from file and is recursive
  munchkin:csv grahamellis$ make mode=40 clean
  Melksham and
  Mode no. 40, written by Graham of Melksham
  Written by Graham of [i]
  Written by Graham of Melksham [d]
  Copyright, Well House Consultants
  Copyright, Well House Consultants,
  Make level is 0
  Mode setting from command line and is recursive
  munchkin:csv grahamellis$ export mode=50
  munchkin:csv grahamellis$ make clean
  Melksham and
  Mode no. 50, written by Graham of Melksham
  Written by Graham of [i]
  Written by Graham of Melksham [d]
  Copyright, Well House Consultants
  Copyright, Well House Consultants,
  Make level is 0
  Mode setting from environment and is recursive
  munchkin:csv grahamellis$


You'll note how I can get back and see where the variable was set from as well, using the make origin function, and tell if it's recursive (deferred) or not, using the make flavor function.

Not included within this example - I can also use += to add onto the end of a variable.

This Makefile example also includes manu other features such as GNUMake's conditionals, and other functions - covered during the course and published here for delegates to refer back to online.
(written 2012-03-22, updated 2012-03-24)

 
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)
  [3658] Using Make for a distribution - (2012-03-17)
  [3652] A Complete makefile example - (2012-03-14)
  [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
Will will smile?
Previous and next
or
Horse's mouth home
Forward to
A modern area of Cambridge - some thoughts provoked?
Some other Articles
Reading Google Analytics results, based on the relative populations of countries
Stepping through a list (or an array) in reverse order
Kings Cross - new concourse - between Python in Cambridge and Objective C in London
A modern area of Cambridge - some thoughts provoked?
Makefile variables - defined internally, from the command line and from the environment
Will will smile?
Error checking in a Python program - making your program robust via exceptions
Changing shops and organisations - Melksham, the last and next five years
Finding all the unique lines in a file, using Python or Perl
Keeping forum and blog comments clean
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/3666_Mak ... nment.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat