Compiling using make
Basic compilation
When compiling with make it is necessary to have the above directory structure. Compiling the compiler is achieved with the target cycle.
Under normal circumstances, recompiling the compiler is limited to the following instructions (assuming you start in directory /pp/src):
cd compiler make cycle
This will work only if the makefile is installed correctly and if the needed tools are present in the PATH. Which tools must be installed can be found in appendix Using fpcmake.
The above instructions will do the following:
Using the current compiler, the RTL is compiled in the correct directory, which is determined by the OS. e.g. under Linux, the RTL is compiled in directory
rtl/linux.The compiler is compiled using the newly compiled RTL. If successful, the newly compiled compiler executable is copied to a temporary executable.
Using the temporary executable from the previous step, the RTL is re-compiled.
Using the temporary executable and the newly compiled RTL from the last step, the compiler is compiled again.
The last two steps are repeated 3 times, until three passes have been made or until the generated compiler binary is equal to the binary it was compiled with. This process ensures that the compiler binary is correct.
Compiling for another target
When compiling the compiler for another target, it is necessary to specify the OS_TARGET makefile variable. It can be set to the following values: win32, go32v2, os2 and linux. As an example, cross-compilation for the go32v2 target from the win32 target is chosen:
cd compiler make cycle OS_TARGET=go32v2
This will compile the go32v2 RTL, and compile a go32v2 compiler.
When compiling a new compiler and the compiler should be compiled using an existing compiled RTL, the all target must be used, and another RTL directory than the default (which is the ../rtl/$(OS_TARGET) directory) must be indicated. For instance, assuming that the compiled RTL units are in /pp/rtl/units/i386-linux, typing
cd compiler make clean make all UNITDIR=/pp/rtl/units/i386-linux
should use the RTL from the /pp/rtl/units/i386-linux directory.
This will then compile the compiler using the RTL units in /pp/rtl/units/i386-linux. After this has been done, the ’make cycle’ can be used, starting with this compiler:
make cycle PP=./ppc386
This will do the make cycle from above, but will start with the compiler that was generated by the make all instruction.
In all cases, many options can be passed to make to influence the compile process. In general, the makefiles add any needed compiler options to the command line, so that the RTL and compiler can be compiled. Additional options (e.g. optimization options) can be specified by passing them in OPT.
Installing the new compiler
To install the newly compiled compiler, the install target can be used:
make install
This will install the compiler in the default location (what that is depends on your platform). If you want to specify the location, you can use the INSTALL_PREFIX variable:
make install INSTALL_PREFIX=/home/michael/
Speeding up compilation
The makefile supports compiling in parallel. For this, you can use the -j N make option, to start N processes.
For the packages and utils, the compilation is governed by fpmake, and make just starts fpmake.
The fpmake process can also compile in parallel, but this needs a separate option -T N. You need to specify this option in the FPMAKEOPT variable:
make all -j 7 FPMAKEOPT='-T 7'
The last step of a normal compilation cycle is recompiling the compiler with whole program optimization. This can be turned off:
make cycle NOWPOCYCLE=1
Adding debug information
By default the compiler, rtl and packages are compiled without debug information. You can force debug information using the OPT variable:
make all OPT=-gl
If you want heaptrc for checking for memory leaks, then add the -glh option:
make all OPT=-glh
Various other options
There are some more options that can be set with special variables. In general they are simply shortcuts and can be replaced with adding compiler command-line options to OPT:
- LINKSMART=1
-
adds
-XXto the compiler command-line options. - CREATESMART=1
-
adds
-CXto the compiler command-line options. - DEBUG=1
-
adds
-gland-dDEBUGto the compiler command-line options. - RELEASE=1
-
adds
-O1or-O2depending on the CPU, and-Urand-DRELEASEto the command-line. - STRIP=1
-
adds
-Xsto the command-line. - OPTIMIZE=1
-
adds
-O2to the command-line. - VERBOSE=1
-
adds
-vwnito the command-line.
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
