User Tools

Site Tools


wiki:make:introdution

Make

A common way to work with research codes is the following:

  1. Fix a bug or add a feature by editing source files.
  2. Recompile the source files into executable form
  3. Run the executable

MHD codes are made up of many files of Fortran and / or C++. If we want to fix a bug or add a feature to one of the files we have to recompile the program. However, the files contain subroutines, functions, classes, etc. that are called by code in other files. I.e. they all depend on each other. We have to compile and connect them in the right order. Doing this by hand is error prone. In the worst case we might find that the bug fix seems has no effect and only later do we realize that we forgot to compile some of the sources we changed. In addition, compiling large programs can take a significant amount of time, often we only need to recompile the small part of the code that we changed.

This is where tools like Make come in. One of the fundamental rules of computing is that anything worth repeating is worth automating. If we need to do the same tasks over and over again, we should use a build manager to handle the details. We can use make for any repetitive build: compiling several source files, generating a paper from latex with several figures, etc.

We describe dependencies in a build file, which is usually just a plain text file in some specialized format. We also describe how to update things, i.e., what commands to run when something's dependencies have been satisfied and it's ready to be refreshed itself. And that's all: the build manager handles everything else. In particular, it keeps track of what's up to date, and what's ready to be updated.

The most widely used build manager on Unix and its derivatives is called Make. And note that we said “most widely used”, not “most popular”. Make was invented by a summer intern at Bell Labs in 1976. ( Stuart Feldman went on to become a vice president at IBM and Google, which shows you how far a good program can take you.) Over 35 years, Make has grown into a little programming language. A very cryptic little language, without a debugger, whose conventions and rules only make sense if you understand the Unix shell.

The good news is, GNU Make (the de facto standard version of Make) is fast, free, and well-documented. And many other tools know how to work with Make. In particular, many integrated development environments can manage Make's build files more or less automatically, shielding users from the ugly details.

In this chapter, we'll look at Make's basic features, and a few of its advanced facilities as well.

wiki/make/introdution.txt · Last modified: 2022/07/21 06:59 by 127.0.0.1