Sign in Join
Wiki copytemporary

FPC Dotted RTL: what changed

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

OldNewLine
11## The project
22
33The FPC distribution has support for creating a "dotted RTL". This is a set of units from RTL/Packages where all unit names are namespaced (dotted).
44
55The units that are found in Delphi 2009 (and upwards) and FPC have the same name. For units that exist in FPC but not in Delphi, the occasion has been used to make the names more consistent. New namespaces have been chosen for all packages, and the last part of the unitname has been cleaned up.
66
77The uses clause of the units in the RTL and Packages have been modified so they refer to the correct unit
88
99This is managed entirely through makefiles and fpmake.
1010
1111Note that fpcmake (the older tool) has no knowledge of the dotted RTL, it does not need this knowledge.
1212
1313The files that are dotted reside in a subdirectory *namespaced*. They set a define and include the non-dotted unit file.
1414
1515## Compiling
1616
1717Only the RTL and the packages can be compiled with dotted units. The creation of dotted units is managed through the FPC_DOTTEDUNITS define in the makefiles.
1818
1919To make the dotted rtl you must do, in the FPC dir
2020
2121 make -C rtl FPC_DOTTEDUNITS=1 clean all
2222 make -C packages FPC_DOTTEDUNITS=1 clean all
2323
2424and a
2525
2626 make -C rtl FPC_DOTTEDUNITS=1 install
2727 make -C packages FPC_DOTTEDUNITS=1 install
2828
2929afterwards.
3030
3131## Makefiles
3232
3333Here we explain how the makefiles manage the creation of dotted RTL/Packages.
3434
3535### RTL
3636
3737The Makefile.fpc files in the RTL directory have been cleaned up. The observation was made that almost all targets are common to all platforms (logical, it is the RTL). What differs per target for each os are the dependencies and possibly some compiler options.
3838
3939So a file was made **inc/Makefile.rtl**, which is used as an include file for the **Makefile.fpc** files in the OS-Specific directories. It is entirely parametrized.
4040
4141In the common **Makefile.rtl** the following definitions are made:
4242
4343- For each unit, a variable **NAMEUNIT** is defined. For example **SYSTEMUNIT** or **WINDOWSUNIT**.
4444
4545
4646
4747Depending on the **FPC_DOTTEDUNITS**, this will be the non-dotted or the dotted name.
4848
4949- For each unit, a **NAME_DEPS** variable is defined that specifies the dependencies for this unit.
5050- In the **prerules** section of the os-specific **Makefile.fpc**, you can define **NAME_DEPS_OS** and **NAME_DEPS_CPU** for OS and CPU specific dependencies.
5151
5252
5353
5454These defines will be taken into account in the target rules (see below)
5555
5656You should only use *NAMEUNIT\$(PPUEXT)* when defining unit dependencies, to make sure the correct unit is taken.
5757
5858- For each unit, 2 targets are defined:
5959
6060 name$(PPUEXT)''' : $(NAME_DEPS) $(NAME_DEPS_OS) $(NAME_DEPS_CPU)
6161 $(COMPILER) $(NAME_OPTS) $<
6262
6363 dottedname$(PPUEXT) : $(NAME_DEPS) $(NAME_DEPS_OS) $(NAME_DEPS_CPU)
6464 $(COMPILER) $(NAME_OPTS) $<
6565
6666Depending on **FPC_DOTTEDUNITS**, one of these 2 units will be compiled.
6767
6868The common targets have been removed from the OS-specific **Makefile.fpc** files, but OS-Specific make rules for os-specific targets remain in these OS-specific **Makefile.fpc** files:
6969
7070- The build units. For build units (**buildrtl**), the uses clause of the build unit is modified so it uses either dotted or non-dotted units.
7171- Loaders. (assembler files)
7272- Other os-specific files.
7373
7474To regenerate the OS-Specific Makefiles, you must include the **inc/Makefile.rtl** using the -x option. For example:
7575
7676 cd rtl/linux
7777 fpcmake -x ../inc/Makefile.rtl -Tlinux
7878
7979The **rtl/regenmakefiles.sh** script does this for all directories below the RTL. The **packages/regenmakefiles.sh** script does this for all directories in the packages.
8080
8181### Packages
8282
8383Noting that, since the use of fpmake, all package makefiles were in essence the same except for the package name a single makefile exists now in **build/Makefile.pkg**.
8484
8585This file is generated from **build/Makefile.fpc** and contains the rules to regenerate *fpmake* correctly.
8686
8787The package-specific Makefile.fpc has been removed. All package-level Makefiles have now been replaced with a 2-line Makefile:
8888
8989- a single line to set the package name.
9090- a single line to include the **build/Makefile.pkg**
9191
9292All the rest is handled by **fpmake**, see below.
9393
9494Every package directory now has a 'namespaces.lst' file which contains the mapping of non-dotted to dotted unit names (see below). it also contains some rule lines that specify how to map unit paths to include paths.
9595
9696## fpmake
9797
9898### working principle
9999
100100fpmake could already perfectly handle dotted names. What was needed was a way to keep the current files with as little modifications as possible. For this reason, a system was devised where the non-dotted names of units were mapped to dotted unit names.
101101
1021022 changes have been made in fpmake to make this possible:
103103
104104- It now understands a *transformations* file. The transformations listed in this file are applied to all target and dependency definitions.
105105
106-` This file can be specified with a property `**`NameSpaceMap`**` on the `**`TPackage`**` object. The name is relative to the package dir. `
106+``` pascal
107+ This file can be specified with a property NameSpaceMap on the TPackage object. The name is relative to the package dir.
108+```
107109
108110- a **--ns** or **--namespace** option was added. When added, the tranformations listed in the **NamespaceMap** are applied to the targets.
109111
110112### Transformations file
111113
112114The transformations file is a file containing rules. There are 2 kinds of lines
113115
114116- A filename transformation line
115117
116118 OldFile=NewFile
117119
118120
119121
120122for example
121123
122124 src/mysql56dyn.pp=namespaced/Api.Mysql56dyn.pp
123125
124126- a path transformation line. This is of the form
125127
126128 {<X><OP>:<dir>}[=DestDir]
127129
128130
129131
130132Here *X* is the path to transform, it is one of
131133
132134- **s** the source path
133135- **i** the include path
134136- **u** the unit path
135137
136138*OP* is the transformation operation to perform. It is one of
137139
138140- *'** It replaces the complete specified directory *dir* with *DestDir*
139141- *'-* It removes the specified *dir* from the search path.
140142- *'+* It adds the specified *dir* to the search path if it was not there yet.
141143
142144For example
143145
144146 {s*:src/}=namespaced/
145147
146148will replace all **src** directories in source paths with **namespaced**
147149
148150 {i+:src/}
149151
150152Will a dd *src* as a include file path.
151153
152154## Other utilities
153155
154156The utils/dotutils directory contain some utilities to help converting a project with non-dotted names to dotted names (or both)
155157
156158- **genunitnames** takes as input a list of tranformations (nondotted=dotted) and generates UNITNAME variables for use in a Makefile.
157159
158160- *'addnamespacetofpake* will add a line NameSpaceMap:='namespaces.lst' to a fpmake program source. It attempts to add this in the correct location.
159161
160162- **encloseunit** enclodes standard input in a IFDEF block
161163
162164 {$IFDEF FPC_DOTTEDUNITS}
163165 {$ENDIF FPC_DOTTEDUNITS}
164166
165167
166168
167169if your editor supports filtering a selection in a block, this can be used to quickly enclose a a block of lines in an ifdef
168170
169171- **fixuses** takes as a parameter a list of transformations (nondotted=dotted) to apply, and as standard input a uses line.
170172
171173it will then transform the uses clause to a form like this:
172174
173175 {$IFDEF FPC_DOTTEDUNITS}
174176 // dotted uses clause
175177 {$ELSE}
176178 // non-dotted uses clause
177179 {$ENDIF FPC_DOTTEDUNITS}
178180
179181
180182
181183if your editor supports filtering a selection in a block, this can be used to quickly enclose a a block of lines in the above-mentioned form
182184
183185- **makedottedfiles** will read a list of units and transform them to use a uses clause in the following form:
184186
185187{\$IFDEF FPC_DOTTEDUNITS} // dotted uses clause {\$ELSE} // non-dotted uses clause {\$ENDIF FPC_DOTTEDUNITS} The unit will then be written to a new file. It has various options which are listed with the **-h** command-line options.
186188
187189- **prefixunits** will read a single unit and transform it to use a uses clause in the following form:
188190
189191{\$IFDEF FPC_DOTTEDUNITS} // dotted uses clause {\$ELSE} // non-dotted uses clause {\$ENDIF FPC_DOTTEDUNITS} The unit will then be written to a new file. It has various options which are listed with the **-h** command-line options.
190192
191193- **proxyunit** is a small program that takes 2 names (non-dotted and dotted) of units and writes a dotted unit file which
192194
193195sets the correct define and includes the original filen.
194196
195197- **reworkmakefile** reworks makefile rules: it replaces hardcoded unit names xyz in a rule with variable XYZUNIT.
196198
197199
198200
199201(see genunitnames for how to create the variables)
200202
201203- **replaceunitnames** replaces unit names in a makefile with the **\$(NAMEUNIT)** macro.
202204
203205- **replaceword** replaces a word with another word in a list of files.
204206
205207The following units do the actual work:
206208
207209- **namespacetool** is a unit used to generate the **namespaces.lst** files in the packages directory, based on a list of known aliases.
208210- **prefixer** is the unit used in **makedottedfiles** which actually rewrites the uses clause of a unit.
209211- **rewritemakefile** is the unit used in **reworkmakfile** which does the actual work.
210212
211213There is a **readme.txt** file with more explanations, and the **known.txt** file contains all transformations used in RTL and packages
212214
213215---
214216*From the Free Pascal wiki, page "FPC Dotted RTL", as it stood on 2023-10-22 after a change by FPC user, 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).*
215217Category: RTL

Back to history