README.txt 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. # Dotted units tools
  2. # Intro
  3. This directory contains tools to convert the sources of units or programs so
  4. their uses clause contains dotted names.
  5. It can also generate a dotted version of a unit in one of several ways.
  6. The prefixer unit and the namespacetool unit contain the functionality
  7. to change uses clauses in unit files.
  8. # Config files for the tools
  9. The tools expect one or two files:
  10. ## File transformation rules
  11. A file with rules to apply to units.
  12. Each line is constructed as follows:
  13. ```
  14. FileName=Rule;Compile Options
  15. ```
  16. Here
  17. * FileName is the undotted unit name to convert a dotted unit.
  18. * Rule is the rule to construct the dotted unit. See below for the rule.
  19. * Compile options are compile options as understood by fcl-pascal needed to correctly parse the unit source
  20. This file is used to construct dotted unit files from undotted files.
  21. The file must be contain all files in a give directory grouped:
  22. If a line contains no rule or compile options, the last used rule/compile options for a file in the same directory is reused.
  23. ```
  24. src/sysutils.pp=System;-S2
  25. src/classes.pp
  26. src/math/math.pp
  27. ```
  28. will result in classes being parsed with -S2 and the resulting name will be System.classes
  29. the name of the math unit will not be changed.
  30. ## Known units rules
  31. A file with OldName=Rule pairs to apply to unit names in a uses clause. a Rule may never specify a path
  32. or an extension. The same extension as the original is used.
  33. This file is used by the prefixunits tool.
  34. # Conversion Rules
  35. A rule can take the following forms:
  36. "*DottedUnitName" : Use the dotted name as typed.
  37. Example:
  38. ```
  39. sysutils=*System.SysUtils
  40. ```
  41. The resulting file is called System.SysUtils
  42. "Prefix" : Prepend the non-dotted name with the given prefix, separated by a dot.
  43. Example:
  44. ```
  45. sysutils=system
  46. ```
  47. will result in a file system.sysutils
  48. "Prefix,*UnitSuffix" : This is equivalent to *Prefix.UnitSuffix
  49. Example:
  50. ```
  51. sysutils=System,*SysUtils
  52. ```
  53. will result in System.SysUtils
  54. "Prefix,-TextToDelete" strips the indicated part from the start of the original filename and prepends the result with Prefix.
  55. Example:
  56. ```
  57. fpreportdata=FpReport,-fpreport
  58. ```
  59. Will result in FpReport.Data
  60. "Prefix,TextToDelete-" strips the indicated part from the end of the original filename and prepends the result with Prefix.
  61. Example:
  62. ```
  63. elfresource=System.Resources,resource-
  64. ```
  65. Will result in System.Resources.elf
  66. # Available tools
  67. ## addnamespacetofpmake.pp
  68. Utility to add a statement to add a namespace to a fpmake program file for FPC packages.
  69. This can be used to let fpmake dynamically change non-dotted names to dotted
  70. names in its targets and dependencies.
  71. ## conditionalprefix.pp
  72. Takes a unit name from standard input, pretty print it (first letter
  73. uppercased) and add a conditional define for a namespace.
  74. ```
  75. echo "sysutils" | conditionalprefix System will result in
  76. ```
  77. ```
  78. {$IFDEF FPC_DOTTEDUNITS}System{$ENDIF}.Sysutils
  79. ```
  80. To be used in shell scripts or to be invoked from an editor
  81. that allows you to filter a selection through a command
  82. ## dond.pp
  83. Tool to lowercase values in a Name=Value list
  84. (use to construct lowercase rules)
  85. ## fixuses.pp
  86. Read a complete uses clause from standard input, and replace it with a conditional uses clause that
  87. allows dotted and non-dotted units. The command needs a file with unit transform rules to apply
  88. to the units in the uses clause.
  89. To be used in shell scripts or to be invoked from an editor
  90. that allows you to filter a selection through a command.
  91. Example:
  92. ```
  93. echo "uses sysutils, classes" | fixuses known.txt
  94. ```
  95. results in
  96. ```
  97. {$IFDEF FPC_DOTTEDUNITS}
  98. uses System.SysUtils, System.Classes;
  99. {$ELSE}
  100. uses sysutils, classes
  101. {$ENDIF}
  102. ```
  103. ## genunitnames.pp
  104. Read a list of unit file transformations and generate a list of unit names for use in a Makefile.
  105. The output consists of a XYZUNIT variable for each unit in the file list, twice: once dotted, once not dotted.
  106. The variables can be used in target definitions and dependency lists.
  107. Example
  108. ```
  109. genunitnames list.txt
  110. ```
  111. with list.txt containing
  112. ```
  113. sysutils=*System.SysUtils
  114. classes=*System.Classes
  115. ```
  116. results in
  117. ```
  118. ifdef FPC_DOTTEDUNITS
  119. SYSUTILSUNIT=System.SysUtils
  120. CLASSESUNIT=System.Classes
  121. else
  122. SYSUTILSUNIT=sysutils
  123. CLASSESUNIT=classes
  124. endif
  125. ```
  126. ## makedottedfiles.pp
  127. Application to Prefix units in uses clause of a list of programs, and
  128. generate a dotted version of the unit. Optionally adapts an fpmake file.
  129. This tool accepts a lot of options, run with -h to get an explanation of
  130. what it does.
  131. It needs 2 files to be specified using the command-line options:
  132. a rule file of units to treat and the 'known mappings' rule file.
  133. ## prefixunits.pp
  134. Prefix units in a uses clause of a single program or unit.
  135. This is the main tool: it allows you to change the uses clause of your
  136. program or unit so it uses dotted names, based on a list of known aliases.
  137. ## proxyunit.pp
  138. Generate a skeleton unit with namespaced name which defines FPC_DOTTEDUNITS and
  139. includes the original non-dotted unit. The full path to the skeleton unit
  140. must be given, the original non-dotted unit must be given only as a name.
  141. The extension is optional, when not specified, .pp is assumed.
  142. Example:
  143. ```
  144. proxyunit namespaced/System.SysUtils.pp sysutils.pp
  145. ```
  146. results in
  147. ```
  148. unit System.SysUtils;
  149. {$DEFINE FPC_DOTTEDUNITS}
  150. {$i sysutils.pp}
  151. ```
  152. ## replaceunitnames.pp
  153. Replace hardcoded unit names xyz in a Makefile rule by a variable XYZUNIT.
  154. (see genunitnames for how to create the variables). Needs a rule file with
  155. names of units that may be replaced.
  156. Example:
  157. replaceunitnames list.txt Makefile.fpc
  158. with list.txt
  159. ```
  160. sysutils=*System.SysUtils
  161. classes=*System.Classes
  162. ```
  163. and the Makefile:
  164. ```
  165. sysutils($PPUEXT): sysutils.pp
  166. $(COMPILER) sysutils.pp
  167. classes($PPUEXT): classes.pp sysutils.pp
  168. $(COMPILER) classes.pp
  169. ```
  170. is transformed to
  171. sysutils($PPUEXT): $(SYSUTILSUNIT).pp
  172. $(COMPILER) $(SYSUTILSUNIT).pp
  173. classes($PPUEXT): $(CLASSESUNIT).pp $(SYSUTILSUNIT).pp
  174. $(COMPILER) $(CLASSESUNIT).pp
  175. ## reworkmakefile.pp
  176. Duplicate all rules in a Makefile.fpc [Rules] section according to the rules specified
  177. in the aliases file. Skip rules that are in the skip file. Every rule is
  178. duplicated so 2 targets are defined: a dotted target and a non-dotted
  179. target. More than one file can be specified.
  180. # Known aliases
  181. The known.txt file contains the aliases list for the FPC rtl and packages.
  182. This can be used to convert a project to use dotted names.