README.txt 6.2 KB

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