PackageVersInc.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. { Rev 1.0 1/24/2024 6:25:00 PM RLebeau
  18. { IdVers.inc generation.
  19. }
  20. unit PackageVersInc;
  21. interface
  22. uses
  23. Package;
  24. type
  25. TVersInc = class(TPackage)
  26. private
  27. procedure GenIdVers;
  28. procedure GenAsmVers;
  29. procedure GenAsmInfo;
  30. procedure GenIdCompilerDefines;
  31. public
  32. constructor Create; override;
  33. procedure Generate(ACompiler: TCompiler; const AFlags: TGenerateFlags); override;
  34. end;
  35. implementation
  36. uses
  37. Classes, SysUtils, DateUtils, StrUtils, DModule;
  38. { TVersInc }
  39. constructor TVersInc.Create;
  40. begin
  41. inherited;
  42. FExt := '.inc';
  43. end;
  44. procedure TVersInc.Generate(ACompiler: TCompiler; const AFlags: TGenerateFlags);
  45. begin
  46. FCompiler := ACompiler;
  47. FDesignTime := False;
  48. FTemplate := False;
  49. if gfTemplate in AFlags then begin
  50. FTemplate := True;
  51. FName := 'IdVers';
  52. FExt := '.inc.tmpl';
  53. GenIdVers;
  54. FOutputSubDir := 'Lib\System';
  55. WriteFile;
  56. FOutputSubDir := 'Lib\FCL';
  57. WriteFile;
  58. FTemplate := False;
  59. FExt := '.inc';
  60. end;
  61. if gfRunTime in AFlags then begin
  62. FDesignTime := False;
  63. FName := 'IdVers';
  64. GenIdVers;
  65. FOutputSubDir := 'Lib\System';
  66. WriteFile;
  67. FOutputSubDir := 'Lib\FCL';
  68. WriteFile;
  69. FName := 'IdSystem90ASM90';
  70. FDesc := 'System Run-Time';
  71. GenAsmVers;
  72. FOutputSubDir := 'Lib\System';
  73. WriteFile;
  74. FName := 'IdCore90ASM90';
  75. FDesc := 'Core Run-Time';
  76. GenAsmVers;
  77. FOutputSubDir := 'Lib\Core';
  78. WriteFile;
  79. FName := 'IdProtocols90ASM90';
  80. FDesc := 'Protocols Run-Time';
  81. GenAsmVers;
  82. FOutputSubDir := 'Lib\Protocols';
  83. WriteFile;
  84. FName := 'IdSecurity90ASM90';
  85. FDesc := 'Security Run-Time';
  86. GenAsmVers;
  87. FOutputSubDir := 'Lib\Security';
  88. WriteFile;
  89. // Why is the above file also in the Protocols directory???
  90. FOutputSubDir := 'Lib\Protocols';
  91. WriteFile;
  92. FName := 'IdAssemblyInfo';
  93. FDesc := '';
  94. FOutputSubDir := 'Lib\System';
  95. GenAsmInfo;
  96. WriteFile;
  97. FName := 'IdCompilerDefines';
  98. GenIdCompilerDefines;
  99. FOutputSubDir := 'Lib\System';
  100. WriteFile;
  101. FOutputSubDir := 'Lib\Core';
  102. WriteFile;
  103. FOutputSubDir := 'Lib\Protocols';
  104. WriteFile;
  105. FOutputSubDir := 'Lib\FCL';
  106. WriteFile;
  107. FOutputSubDir := 'Lib\SuperCore';
  108. WriteFile;
  109. end;
  110. if gfDesignTime in AFlags then begin
  111. FDesignTime := True;
  112. FName := 'IddclCore90ASM90';
  113. FDesc := 'Core Design-Time';
  114. GenAsmVers;
  115. FOutputSubDir := 'Lib\Core';
  116. WriteFile;
  117. FName := 'IddclProtocols90ASM90';
  118. FDesc := 'Protocols Design-Time';
  119. GenAsmVers;
  120. FOutputSubDir := 'Lib\Protocols';
  121. WriteFile;
  122. FName := 'IddclSecurity90ASM90';
  123. FDesc := 'Security Design-Time';
  124. GenAsmVers;
  125. FOutputSubDir := 'Lib\Security';
  126. WriteFile;
  127. end;
  128. end;
  129. procedure TVersInc.GenIdVers;
  130. var
  131. FileVersion, BuildStr: String;
  132. begin
  133. FCode.Clear;
  134. BuildStr := iif(FTemplate,
  135. IndyVersion_Build_Template,
  136. IndyVersion_Build_Str);
  137. FileVersion := iif(FTemplate,
  138. IndyVersion_FileVersion_Template,
  139. IndyVersion_FileVersion_Str);
  140. Code(' gsIdVersionMajor = ' + IndyVersion_Major_Str + ';');
  141. Code(' {$NODEFINE gsIdVersionMajor}');
  142. Code(' gsIdVersionMinor = ' + IndyVersion_Minor_Str + ';');
  143. Code(' {$NODEFINE gsIdVersionMinor}');
  144. Code(' gsIdVersionRelease = ' + IndyVersion_Release_Str + ';');
  145. Code(' {$NODEFINE gsIdVersionRelease}');
  146. Code(' gsIdVersionBuild = ' + BuildStr + ';');
  147. Code(' {$NODEFINE gsIdVersionBuild}');
  148. Code('');
  149. Code(' (*$HPPEMIT ''#define gsIdVersionMajor ' + IndyVersion_Major_Str + '''*)');
  150. Code(' (*$HPPEMIT ''#define gsIdVersionMinor ' + IndyVersion_Minor_Str + '''*)');
  151. Code(' (*$HPPEMIT ''#define gsIdVersionRelease ' + IndyVersion_Release_Str + '''*)');
  152. Code(' (*$HPPEMIT ''#define gsIdVersionBuild ' + BuildStr + '''*)');
  153. Code(' (*$HPPEMIT ''''*)');
  154. Code('');
  155. Code(' gsIdVersion = ''' + FileVersion + '''; {do not localize}');
  156. Code(' gsIdProductName = ''Indy''; {do not localize}');
  157. Code(' gsIdProductVersion = ''' + IndyVersion_ProductVersion_Str + '''; {do not localize}');
  158. end;
  159. procedure TVersInc.GenAsmVers;
  160. begin
  161. FCode.Clear;
  162. Code('[assembly: AssemblyDescription(''Internet Direct (Indy) ' + IndyVersion_ProductVersion_Str + ' ' + FDesc + ' Package for Borland Developer Studio'')]');
  163. Code('[assembly: AssemblyConfiguration('''')]');
  164. Code('[assembly: AssemblyCompany(''Chad Z. Hower a.k.a Kudzu and the Indy Pit Crew'')]');
  165. Code('[assembly: AssemblyProduct(''Indy for Microsoft .NET Framework'')]');
  166. Code('[assembly: AssemblyCopyright(''Copyright © 1993 - ' + IntToStr(YearOf(Date)) + ' Chad Z. Hower a.k.a Kudzu and the Indy Pit Crew'')]');
  167. Code('[assembly: AssemblyTrademark('''')]');
  168. Code('[assembly: AssemblyCulture('''')]');
  169. Code('[assembly: AssemblyTitle(''Indy .NET ' + FDesc + ' Package'')]');
  170. Code('[assembly: AssemblyVersion(''' + IndyVersion_ProductVersion_Str + '.*'')]');
  171. Code('[assembly: AssemblyDelaySign(false)]');
  172. Code('[assembly: AssemblyKeyFile('''')]');
  173. Code('[assembly: AssemblyKeyName('''')]');
  174. end;
  175. procedure TVersInc.GenAsmInfo;
  176. var
  177. LFileName, LLine: string;
  178. Data: TStringList;
  179. I: Integer;
  180. begin
  181. FCode.Clear;
  182. LFileName := DM.OutputPath + 'Lib\System\IdAssemblyInfo.pas';
  183. if FileExists(LFileName) then begin
  184. // TStreamReader would be preferred, but its broken!
  185. Data := TStringList.Create;
  186. try
  187. Data.LoadFromFile(LFileName);
  188. for I := 0 to Data.Count-1 do begin
  189. LLine := Data[I];
  190. if LLine <> 'unit IdAssemblyInfo;' then
  191. Code(LLine)
  192. else
  193. Break;
  194. end;
  195. finally
  196. Data.Free;
  197. end;
  198. end;
  199. Code('unit IdAssemblyInfo;');
  200. Code('');
  201. Code('interface');
  202. Code('');
  203. Code('uses');
  204. Code(' System.Reflection, System.Runtime.CompilerServices;');
  205. Code('');
  206. Code('//');
  207. Code('// General Information about an assembly is controlled through the following');
  208. Code('// set of attributes. Change these attribute values to modify the information');
  209. Code('// associated with an assembly.');
  210. Code('//');
  211. Code('[assembly: AssemblyTitle(''Indy'')]');
  212. Code('[assembly: AssemblyDescription(''Internet Direct (Indy) ' + IndyVersion_ProductVersion_Str +' for Visual Studio .NET'')]');
  213. Code('[assembly: AssemblyConfiguration('''')]');
  214. Code('[assembly: AssemblyCompany(''Chad Z. Hower a.k.a Kudzu and the Indy Pit Crew'')]');
  215. Code('[assembly: AssemblyProduct(''Indy for Microsoft .NET Framework'')]');
  216. Code('[assembly: AssemblyCopyright(''Copyright © 1993 - ' + IntToStr(YearOf(Date)) + ' Chad Z. Hower a.k.a Kudzu and the Indy Pit Crew'')]');
  217. Code('[assembly: AssemblyTrademark('''')]');
  218. Code('[assembly: AssemblyCulture('''')]');
  219. Code('');
  220. Code('//');
  221. Code('// Version information for an assembly consists of the following four values:');
  222. Code('//');
  223. Code('// Major Version');
  224. Code('// Minor Version');
  225. Code('// Build Number');
  226. Code('// Revision');
  227. Code('//');
  228. Code('// You can specify all the values or you can default the Revision and Build Numbers');
  229. Code('// by using the ''*'' as shown below:');
  230. Code('');
  231. Code('[assembly: AssemblyVersion(''' + IndyVersion_ProductVersion_Str + '.*'')]');
  232. Code('');
  233. Code('//');
  234. Code('// In order to sign your assembly you must specify a key to use. Refer to the');
  235. Code('// Microsoft .NET Framework documentation for more information on assembly signing.');
  236. Code('//');
  237. Code('// Use the attributes below to control which key is used for signing.');
  238. Code('//');
  239. Code('// Notes:');
  240. Code('// (*) If no key is specified, the assembly is not signed.');
  241. Code('// (*) KeyName refers to a key that has been installed in the Crypto Service');
  242. Code('// Provider (CSP) on your machine. KeyFile refers to a file which contains');
  243. Code('// a key.');
  244. Code('// (*) If the KeyFile and the KeyName values are both specified, the');
  245. Code('// following processing occurs:');
  246. Code('// (1) If the KeyName can be found in the CSP, that key is used.');
  247. Code('// (2) If the KeyName does not exist and the KeyFile does exist, the key');
  248. Code('// in the KeyFile is installed into the CSP and used.');
  249. Code('// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.');
  250. Code('// When specifying the KeyFile, the location of the KeyFile should be');
  251. Code('// relative to the project output directory which is');
  252. Code('// %Project Directory%\bin\<configuration>. For example, if your KeyFile is');
  253. Code('// located in the project directory, you would specify the AssemblyKeyFile');
  254. Code('// attribute as [assembly: AssemblyKeyFile(''..\\..\\mykey.snk'')]');
  255. Code('// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework');
  256. Code('// documentation for more information on this.');
  257. Code('//');
  258. Code('[assembly: AssemblyDelaySignAttribute(true)]');
  259. Code('[assembly: AssemblyKeyFileAttribute(''Indy.snk'')]');
  260. Code('[assembly: AssemblyKeyName('''')]');
  261. Code('');
  262. Code('implementation');
  263. Code('');
  264. Code('end.');
  265. end;
  266. procedure TVersInc.GenIdCompilerDefines;
  267. var
  268. LFileName, LOldDefinePrefix, LProductDefine, LVersionDefine: string;
  269. Data: TStringList;
  270. I, LPadding: Integer;
  271. begin
  272. FCode.Clear;
  273. // TODO: put the version defines into their own .inc file that
  274. // IdCompilerDefines.inc can then include...
  275. LFileName := DM.OutputPath + 'Lib\System\IdCompilerDefines.inc';
  276. LProductDefine := '{$DEFINE ' + StringReplace(IndyVersion_ProductVersion_Str, '.', '_', [rfReplaceAll]) + '}';
  277. LVersionDefine := '{$DEFINE ' + StringReplace(IndyVersion_FileVersion_Str, '.', '_', [rfReplaceAll]) + '}';
  278. LPadding := Length(LVersionDefine) - Length(LProductDefine);
  279. LVersionDefine := LVersionDefine + ' //so developers can IFDEF for this specific version';
  280. // TStreamReader would be preferred, but its broken!
  281. Data := TStringList.Create;
  282. try
  283. Data.LoadFromFile(LFileName);
  284. LOldDefinePrefix := '{$DEFINE ' + IndyVersion_Major_Str + '_';
  285. for I := 0 to Data.Count-1 do begin
  286. if StartsStr(LOldDefinePrefix, Data[I]) then
  287. begin
  288. Data[I] := LProductDefine + StringOfChar(' ', LPadding) + ' //so developers can IFDEF for this product version';
  289. if StartsStr(LOldDefinePrefix, Data[I+1]) then begin
  290. Data[I+1] := LVersionDefine;
  291. end else begin
  292. Data.Insert(I+1, LVersionDefine);
  293. end;
  294. Break;
  295. end;
  296. end;
  297. FCode.Assign(Data);
  298. finally
  299. Data.Free;
  300. end;
  301. end;
  302. end.