Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
Make - automating the commands for building and installing

Coding projects (and their open source distributions) require build scripts - files of commands that convert the source code into executable programs, that install the various resultant files into place, and that can clean up the build area for a fresh build or for redistribution. The make system - with makefiles - is the usual way to do this (in the case of C and C++ programs anyway - in the Java world, Ant is the more usual approach).

How do build systems work?

You specify a target (the file you want to build), some dependencies (the files which - if changed - necessitate a rebuild) and a set of rules for making the target. You build a whole series of sets of targets, dependencies and rules with the target of one set of rules - the name of the output file from a set of rules - being amongst the dependencies (inputs) at the next level. Then when you say "make" the first target in your Makefile, and anything it depends on too, is rebuilt.

Make is very clever in that it examines the whole build tree before it does anything, so that rules are followed all the way back to see which need to be run, the they're run all the way forward so that they happen (a) only if necessary and (b) in the right order. File timestamps are used to check what has changed, so if you want to force one of the sets of rules to be run, you can simply touch one of the dependencies and rerun make.

There is a commented example of a Makefile - showing and describing its format - [here].

It's the nature of a compile and build operation in a language such as C or C++ that a very similar set of operations will be performed on a whole series of files - for example, there may be dozens of .cpp files to be compiled into .o files, all with the same compiler and compile time options. So to make your makefile shorter and easier to maintain for consistency, you can specify make variables and make default rules. There's a further example that shows these features [here] - again that's commented and kept fairly short and straight forward to help the newcomer.




When you download an open source distribution, please READ THE INSTALL GUIDE before you build and install it. You'll find that in a file called INSTALL or something similar in the unpacked distribution. And you'll often find the procedure goes like this:

./configure --with-summat --enable-summat-else --etc
make
make test
make install


With C and C++ programs which run across different flavors of operating systems, your makefile needs to be updated to ensure that the resulting executables make good use of what the OS offers, and that the build doesn't attempt to use facilities that aren't available. You also need the ability to choose options to build in and out, and perhaps to specify target directory paths. The ./configure script / program takes your various requests, analysis and looks round the system on which you're doing the build. It advises you of any dependencies that are missing (i.e. other bits of software you'll need to install files) and outputs a Makefile.

The make operation does the actual compiles and builds; that will usually include other subsidiary targets to unpack and prepare documentation directories, configuration files for the application itself when run, etc.

make test will put the newly build application through a whole series of checks to ensure that the output is 100% fine - this is designed to catch anything that hasn't worked as it should in the build process, and may also serve to give you an early alert of facilities that are missing or non-functional on your particular operating system / configuration. The output of make test is a report, so if you're repeating the same build across a large number of systems you might consider skipping it; on occasions that we're rebuilding a series of systems, we sometimes do - but then we're building for a week's training and not for systems that are going to sit in an exposed production environment for perhaps years.

The final step - make install - copies the output of make from the staging / development area where make wrote its output to the production area. You'll usually need to be logged in as the administrator - for this step only! - and you should remember to get yourself a full root environment. In other words - do not use su without any options; use su - (a lone minus option), even though the latter moves you to root's home directory and having to cd back to your build area.

P.S. Before you make install you should check that any prior versions that you're going to overwrite aren't actually running. Also consider using a fresh parallel install directory as that will give you the ability to rollback if you find the need.
(written 2010-11-16, updated 2010-12-04)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
A165 - Web Application Deployment - Installing Software
  [4259] Upgrading our training systems to all the current stable versions - (2014-04-07)
  [2201] Running straight from the jar, but not from a tar - (2009-05-26)
  [2139] OS Commerce install made simple - (2009-04-24)
  [1700] FTP server on Fedora Linux - (2008-07-06)
  [809] What to do during a Linux build - (2006-07-20)

A168 - Web Application Deployment - Compiler and development tools
  [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)
  [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)
  [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)

C050 - C and C based languages - C - General
  [4341] Segmentation Fault, Segmentation Violation, Bus Error, Stack Smashing - (2014-12-04)
  [4335] Flexible public courses - residential or commuting, programming newcomer or experienced, C or C++ - (2014-11-30)
  [3129] Extra courses - C and C++ - (2011-01-12)
  [2848] C course - final course example puts it all together - (2010-07-02)
  [2763] Our C and C++ training course are on Open Source platforms - (2010-05-13)
  [2669] Efficient use of dynamic memory - C and realloc - (2010-03-10)
  [2536] All the Cs ... and Java too - (2009-12-13)
  [2504] Learning to program in ... - (2009-11-15)
  [2091] C, C++ and C# ... Java and JavaScript - (2009-03-20)
  [2086] C Programming v Learning to Program in C. Which course? - (2009-03-17)
  [2002] New C Examples - pointers, realloc, structs and more - (2009-01-20)

C231 - C and C based languages - Introduction to C++
  [3250] C++ - how we teach the language and the concepts behind the language - (2011-04-17)
  [3069] Strings, Garbage Collection and Variable Scope in C++ - (2010-11-25)
  [3052] Getting your C++ program to run - (2010-11-15)
  [2845] Objects and Inheritance in C++ - an easy start - (2010-07-01)
  [2169] When should I use OO techniques? - (2009-05-11)
  [2004] Variable Scope in C++ - (2009-01-22)
  [928] C++ and Perl - why did they do it THAT way? - (2006-11-16)
  [336] Targetted Advertising - (2005-06-05)
  [318] Choosing a theme - (2005-05-20)
  [317] Programming languages - a comparison - (2005-05-20)


Back to
Getting your C++ program to run
Previous and next
or
Horse's mouth home
Forward to
Longhope Hotel
Some other Articles
Lots of things to do with and within a C++ class
C++ - a complete example with polymorphism, and how to split it into project files
Zyliana Kyrei Cox
Longhope Hotel
Make - automating the commands for building and installing
Positively reforming the system - could it be done?
Views of Melksham - November 2010
Computer Graphics is fun - even if Java Applets are Old Hat
String handling - from first steps to practical examples
4344 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 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., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3053_Mak ... lling.html • PAGE BUILT: Thu Sep 18 15:30:25 2014 • BUILD SYSTEM: WomanWithCat