...
- GNU Make is the de facto standard build tool for software projects developed on and for Linux environments. It relies on a makefile, by default named
Makefile
, which contains the rules (including the sequence of commands, environment variables, options) that tell Make how to generate an executable from a source code. - The
configure
script is often used to automate the retrieval of system and user information before the compilation and linking steps are performed. It generates a tailoredMakefile
starting from a general template and the collected information. - CMake, not to be confused with GNU Make, is a meta-build tool that uses system-independent and compiler-independent configuration files to generate specific build scripts for a range of system-specific build tools, including GNU Make.
Warning | ||
---|---|---|
| ||
We have observed that In order to assign the correct group ownership to the generated files, users are instructed to execute all
OR
If the
instead of the correct group ownershipt which would be:
Incorrect ownership of files may affect your work in many ways. One of them is consuming the user's limited quota of maximum number of files in the sytem. |
Steps
Info | ||
---|---|---|
| ||
To keep your software organised, we recommend the following locations for your manual software installations:
|
The process of building software starts with obtaining and unpacking its source code into a directory, which from now on is referred to as $ROOT$ROOTBUILD_DIR
.
Identify the build process. Usually, the software package provides a detailed description of the build process. Otherwise, you should look for one of the following files indicating which tools are used for the purpose.
- A
CMakeLists.txt
file in the$ROOT$ROOTBUILD_DIR
directory indicates a CMake project. Go to step 3. - A
configure
orconfigure.sh
script in the$ROOT$ROOTBUILD_DIR
directory suggests that you must execute a script to configure the build process. Go to step 2. - A
Makefile
in the$ROOT$ROOTBUILD_DIR
directory signals that the project's build process is handled through GNU Make. Go to step 4.
- A
configure
scripts. A build process uses aconfigure
script to collect information regarding the environment (operating system, compilers, libraries, etc.) you intend to build the software in. It is able to collect most of the needed information and decide on the best configuration automatically. However, there are few options that you must usually set; for instance, the--prefix
option is used to specify the absolute path, the path starting from the root of the filesystem, to the installation directory. There may be options that are not required but desirable in a supercomputing environment, for example, options enabling vectorised instructions. Once the script has run, typically GNU Make must be executed next (step 4).Expand title Show configure usage examples ... To see the list of all options and arguments, execute the
configure
script with the–help
option,$ ./configure --help
As an example, the following line shows how to run a
configure
script specifying the--prefix
option:$ ./configure --prefix=/path/to/installation/dir
You can also set the value of the environment variables used by the
configure
script, like this:$ ./configure VAR=VALUE
Expand title List of most common compiling a linking variables Variable Meaning Example CC
C compiler CC=icc
CXX
C++ compiler CXX=icpc
FC
Fortran compiler FC=ifort
CFLAGS
C compiler flags CFLAGS=-O2
CXXFLAGS
C++ compiler flags CXXFLAGS=-O2
FCFLAGS
Fortran compiler flags FCFLAGS=-O2
CPPFLAGS
C/C++ preprocessor flags CPPFLAGS=-I<include dir>
LDDFLAGS
Linker flags LDDFLAGS=-L<library dir>
LIBS
Linker libraries LIBS=-l<lib name>
Notes and best practices. Always check the output produced by a
configure
script. It might contain warnings that call for a modification of the configure options or the shell environment. Someconfigure
scripts compile a test code and execute it, to set some compilation options accordingly. This may not work when compiling in nodes with different architecture from the compute nodes (like the login nodes). For instance, HPE-Cray EX login nodes on Setonix do not have GPU cards nor some of the related libraries, so configure testings may fail. This type of problems can still occur to pure CPU codes. Therefore, we recommend to run the build process on the intended compute nodes for execution (GPU or CPU). If the code is still under development or if the compilation is fast, users can use the development partitions(debug
orgpu-dev
in the case of Setonix). For long compilations, users should submit the compilation jobs to the "production" partitions (work
orgpu
in the case of Setonix).Building using CMake. Similarly to
configure
scripts, CMake generates one or more environment-dependent build files (for Linux-based system they areMakefiles
files, covered in step 4) from a high-level, environment-independent definition of the build process that is contained in theCMakeLists.txt
file. Terminal 1 shows the typical sequence of commands you should use. Once completed, move to step 4.Column width 900px Code Block language bash theme DJango title Terminal 1. Using CMake to generate build files $ cd $ROOT$ROOTBUILD_DIR $ mkdir build $ cd build $ sg <projectcode> -c 'cmake ..'
In words,
Change the working directory of the terminal to
$ROOT$ROOTBUILD_DIR
and create a directory namedbuild
(the name can vary, although the one suggested here is standard practice) within the same.Move Change again the terminal, this time to into the newly created folder.
From the
build
directory, execute the commandcmake
passing as an argument the path to the directory containing theCMakeLists.txt
file. Typically the relative path..
is used.
Like the
configure
script, you can specify options to CMake. The most common one is theCMAKE_INSTALL_PREFIX
option that dictates where binaries will be installed (the default location being/usr/local
). The syntax for specifying an option to CMake is-DOPTION=Value
. In this case, the command would look like this:$ cmake -DCMAKE_INSTALL_PREFIX=/path/to/installation/directory ..
Building using GNU Make. Conceptually, GNU Make executes commands to compile and link a program specified in the
Makefile
file, using a dedicated syntax that allows declaring dependencies between the building steps. To launch the build process, change the working directory of the terminal to the one containing theMakefile
(that is,$ROOT$ROOTBUILD_DIR
) and simply execute themake
command. Next, execute themake install
command to install the built executable or library.$ sg <projectcode> -c 'make'
$ sg <projectcode> -c 'make install'
The install argument to
make
is called target. A target represents a subset of theMakefil
e file that accomplishes a particular task in the larger context of the build process. In terminal 4, the firstmake
command executes the default target, which usually builds the software without installing it. The install target installs the binaries, that is, the produced executables or libraries.
Sometimes you must change the value of some variables defined in theMakefile
file. Some variable names are standard across mostMakefile
files. In particular,CC
,CXX
andFC
are used to define executable names for C, C++ and Fortran compilers, respectively, whereasCFLAGS
,CXXFLAGS
andFFLAGS
are used for the corresponding compiling flags.All the compiler modules in Pawsey HPC systems define the compiler variables
CC
,CXX
andFC
, which are then ready to use by GNU Make.
...