Sign in Join
Wiki copytemporary

FPC Subtarget Support: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: FPC Subtarget Support

OldNewLine
1+As of version 3.3.1, medio 2023, FPC has support for subtargets.
2+
3+## What are subtargets
4+
5+A subtarget is a named set of configuration options for the compiler which is applied during compilation and installation of the RTL, Packages and utils. The compiler itself can also be compiled with a subtarget if you so desire.
6+
7+This named set of configuration options is supplied as a configuration file much like the default configuration file (fpc.cfg). This file is read in addition to the regular configuration file, and must have a fixed name.
8+
9+For example, to create a subtarget 'myfeature', you must create a configuration file called **fpc-myfeature.cfg**. The configuration name must be lowercase in the filename.
10+
11+When compiling, you can select a subtarget on the command-line using the **-t** compiler option:
12+
13+ fpc -tmyfeature
14+
15+Only 1 subtarget can be specified, if you specify a second, you will get an error.
16+
17+If so desired, you can combine subtargets into a new subtarget with the help of the \#INCLUDE directive.
18+
19+In the subtarget definition file, you can put any options that you would specify on the command-line or in a configuration file.
20+
21+For example:
22+
23+ -dUNICODERTL
24+ -Municodestrings
25+
26+This configuration will always be loaded, also in the case when you specify **-n**. So in case of the following command-line
27+
28+ fpc -n -tmyfeature
29+
30+will not load *fpc.cfg*, but will load *fpc-myfeature.cfg*.
31+
32+When you specify a subtarget, besides loading the configuration file, the compiler does 3 other things:
33+
34+- The **\$fpctarget** macro will become **CPU-OS-SUBTARGETNAME**. For example
35+
36+ x86_64-linux-myfeature
37+
38+- It will define a macro **FPC_SUBTARGET_SUBTARGETNAME** , for example:
39+
40+ FPC_SUBTARGET_MYFEATURE
41+
42+- It will define a macro **FPC_SUBTARGET** with value **SUBTARGETNAME** , for example:
43+
44+ FPC_SUBTARGET=myfeature
45+
46+Because the **\$fpctarget** macro changes value when you specify a subtarget, this has an effect on the search path:
47+
48+The default configuration file uses this macro to specify the unit path. As a result, the compiler will search in a different directory for units.
49+
50+For example for linux 64-bit, if you specify **-tmyfeature** Instead of looking for units in the default
51+
52+ /usr/local/lib/fpc/3.3.1/x86_64-linux
53+
54+instead, it will search in directory
55+
56+ /usr/local/lib/fpc/3.3.1/x86_64-linux-myfeature
57+
58+## Using subtargets
59+
60+### Using subtargets in Makefiles
61+
62+To compile the FPC RTL and packages for a subtarget, you can specify the SUB_TARGET define
63+
64+ make SUB_TARGET=myfeature clean all
65+
66+This has 2 effects:
67+
68+1. The compiler is called with **-tmyfeature**
69+2. When doing an install, the subtarget name will be appended to the installation directory.
70+
71+ make SUB_TARGET=myfeature install
72+
73+will (on Linux) install into
74+
75+ /usr/local/lib/fpc/3.3.1/x86_64-linux-myfeature
76+
77+### Using subtargets in fpcmake
78+
79+The default fpcmake makefile generator creates now by default makefiles that understand the SUB_TARGET option.
80+
81+### Using subtargets with fpmake
82+
83+The **fpmake** tool also understands the subtarget concept, you can set the subtarget with the **-s** option.
84+
85+The Free Pascal rtl/packages use the subtarget concept to create the unicode RTL (where *string*=*unicodestring*) in parallel to the regular single-byte RTL (where string=ansistring or shortstring)
86+
87+---
88+*From the Free Pascal wiki, page "FPC Subtarget Support", as it stood on 2023-08-05 after a change by Alextpp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history