PackageSystem.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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.4 3/3/2005 7:46:24 PM JPMugaas
  18. { Backdoors for BDS assembly version information.
  19. }
  20. {
  21. { Rev 1.3 04/09/2004 12:45:16 ANeillans
  22. { Moved the databasename and output paths into a globally accessible variable
  23. { -- makes it a lot easier to override if you need to (as I did for my local
  24. { file structure).
  25. }
  26. {
  27. { Rev 1.2 2004.06.13 8:06:12 PM czhower
  28. { Update for D8
  29. }
  30. {
  31. { Rev 1.1 02/06/2004 17:00:48 HHariri
  32. { design-time added
  33. }
  34. {
  35. { Rev 1.0 2004.02.08 2:28:40 PM czhower
  36. { Initial checkin
  37. }
  38. {
  39. { Rev 1.0 2004.01.22 8:18:34 PM czhower
  40. { Initial checkin
  41. }
  42. unit PackageSystem;
  43. interface
  44. uses
  45. Package;
  46. type
  47. TPackageSystem = class(TPackage)
  48. protected
  49. procedure GenOptions; override;
  50. procedure GenPreRequiresClause; override;
  51. procedure GenRequires; override;
  52. procedure GenPreContainsClause; override;
  53. procedure GenPreContainsFile(const AUnit: string); override;
  54. procedure GenPostContainsFile(const AUnit: string; const AIsLastFile: Boolean); override;
  55. function IgnoreContainsFile(const AUnit: string): Boolean; override;
  56. procedure GenFooter; override;
  57. procedure GenResourceScript; override;
  58. public
  59. constructor Create; override;
  60. procedure Generate(ACompiler: TCompiler; const AFlags: TGenerateFlags); override;
  61. procedure GenerateRC(ACompiler: TCompiler; const AFlags: TGenerateFlags); override;
  62. end;
  63. implementation
  64. uses
  65. DModule, SysUtils;
  66. const
  67. Delphi_Native_Ifdef_Windows_In_Contains = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE];
  68. Delphi_Native_Define_Windows_Before_Requires = [ctDelphiXE8..ctDelphiTokyo];
  69. Delphi_Native_Ifdef_Requires = Delphi_Native_Ifdef_Rtl - Delphi_Native_Define_Windows_Before_Requires;
  70. Delphi_Native_Define_Windows_Before_Contains = Delphi_Native_Ifdef_Windows_In_Contains - Delphi_Native_Define_Windows_Before_Requires;
  71. Delphi_Native_Ifdef_Fmx = Delphi_Native_Define_Windows_Before_Requires;
  72. { TPackageSystem }
  73. constructor TPackageSystem.Create;
  74. begin
  75. inherited;
  76. FOutputSubDir := 'Lib\System';
  77. end;
  78. procedure TPackageSystem.Generate(ACompiler: TCompiler; const AFlags: TGenerateFlags);
  79. begin
  80. FName := 'IndySystem' + GPackageVer[ACompiler];
  81. FDesc := 'System';
  82. FExt := '.dpk';
  83. inherited Generate(ACompiler, AFlags - [gfDesignTime]);
  84. WriteFile;
  85. end;
  86. // TODO: make the options configurable...
  87. procedure TPackageSystem.GenOptions;
  88. const
  89. Delphi_Native_Align8 = Delphi_Native - [Delphi_Native_Lowest..ctDelphiPre2010NR] + [ctDelphi2005];
  90. Delphi_OmittedOptions = [Delphi_Native_Lowest..ctDelphiXE, ctKylix3] - [ctDelphi8Net];
  91. Delphi_Native_Ifdef_ImplicitBuilding = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE];
  92. Delphi_Native_Force_DebugInfo_Off = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE7];
  93. Delphi_Native_Force_Optimization_On = [Delphi_Native_Lowest..ctDelphiXE];
  94. Delphi_Native_Force_Optimization_Off = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE];
  95. Delphi_Native_Force_OverflowChecks_Off = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE];
  96. Delphi_Native_Force_RangeChecks_Off = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE];
  97. Delphi_Native_Force_StackFrames_Off = Delphi_Native - [ctDelphiXE2..Delphi_Native_Highest] + Delphi_DotNet + [ctKylix3];
  98. Delphi_Native_Force_StackFrames_On = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE];
  99. Delphi_Native_Define_DebugRelease = [ctDelphiXE2..ctDelphiSydney];
  100. Delphi_Native_Define_Ver = [ctDelphiXE4..ctDelphiSydney];
  101. function OnOrOff(const AForceOff, AForceOn: TCompilers; const ADefault: Boolean): string;
  102. begin
  103. if FCompiler in AForceOff then begin
  104. Result := 'OFF';
  105. end
  106. else if FCompiler in AForceOn then begin
  107. Result := 'ON';
  108. end
  109. else begin
  110. Result := iif(ADefault, 'ON', 'OFF');
  111. end;
  112. end;
  113. begin
  114. Code('');
  115. if FCompiler in Delphi_DotNet then begin
  116. Code('{$ALIGN 0}');
  117. end else begin
  118. Code('{$R *.res}');
  119. if FCompiler in Delphi_Native_Ifdef_ImplicitBuilding then begin
  120. Code('{$IFDEF IMPLICITBUILDING This IFDEF should not be used by users}');
  121. end;
  122. if FCompiler in Delphi_Native_Align8 then begin
  123. Code('{$ALIGN 8}');
  124. end;
  125. end;
  126. if not (FCompiler in Delphi_OmittedOptions) then begin
  127. Code('{$ASSERTIONS ON}');
  128. end;
  129. Code('{$BOOLEVAL OFF}');
  130. if not (FCompiler in Delphi_OmittedOptions) then begin
  131. Code('{$DEBUGINFO ' + OnOrOff(Delphi_Native_Force_DebugInfo_Off, [], FDebug) + '}');
  132. end;
  133. Code('{$EXTENDEDSYNTAX ON}');
  134. Code('{$IMPORTEDDATA ON}');
  135. if not (FCompiler in Delphi_OmittedOptions) then begin
  136. Code('{$IOCHECKS ON}');
  137. end;
  138. Code('{$LOCALSYMBOLS ON}');
  139. Code('{$LONGSTRINGS ON}');
  140. Code('{$OPENSTRINGS ON}');
  141. Code('{$OPTIMIZATION ' + OnOrOff(Delphi_Native_Force_Optimization_Off, Delphi_Native_Force_Optimization_On, FDebug) + '}');
  142. if not (FCompiler in Delphi_OmittedOptions) then begin
  143. Code('{$OVERFLOWCHECKS ' + OnOrOff(Delphi_Native_Force_OverflowChecks_Off, [], FDebug) + '}');
  144. Code('{$RANGECHECKS ' + OnOrOff(Delphi_Native_Force_RangeChecks_Off, [], FDebug) + '}');
  145. end;
  146. Code('{$REFERENCEINFO ON}');
  147. Code('{$SAFEDIVIDE OFF}');
  148. Code('{$STACKFRAMES ' + OnOrOff(Delphi_Native_Force_StackFrames_Off, Delphi_Native_Force_StackFrames_On, {not} FDebug) + '}');
  149. Code('{$TYPEDADDRESS OFF}');
  150. Code('{$VARSTRINGCHECKS ON}');
  151. Code('{$WRITEABLECONST OFF}');
  152. Code('{$MINENUMSIZE 1}');
  153. Code('{$IMAGEBASE $400000}');
  154. if FCompiler in Delphi_Native_Define_DebugRelease then begin
  155. Code('{$DEFINE ' + iif(FDebug, 'DEBUG', 'RELEASE') + '}');
  156. end;
  157. if FCompiler in Delphi_Native_Define_Ver then begin
  158. Code('{$DEFINE VER' + GCompilerVer[FCompiler] + '}');
  159. end;
  160. if FCompiler in Delphi_Native_Ifdef_ImplicitBuilding then begin
  161. Code('{$ENDIF IMPLICITBUILDING}');
  162. end;
  163. Code('{$DESCRIPTION ''Indy ' + FVersion + TrimRight(' ' + FDesc) + '''}');
  164. Code(iif(FDesignTime, '{$DESIGNONLY}', '{$RUNONLY}'));
  165. Code('{$IMPLICITBUILD OFF}');
  166. end;
  167. procedure TPackageSystem.GenPreRequiresClause;
  168. begin
  169. if (FCompiler in Delphi_Native_Ifdef_Rtl) or
  170. (FCompiler in Delphi_Native_Ifdef_Windows_In_Contains) then
  171. begin
  172. Code('');
  173. Code('// RLebeau: cannot use IdCompilerDefines.inc here!');
  174. end;
  175. if FCompiler in Delphi_Native_Define_Windows_Before_Requires then begin
  176. Code('');
  177. Code('{$IFNDEF WINDOWS}');
  178. Code(' {$IFDEF MSWINDOWS}');
  179. Code(' {$DEFINE WINDOWS}');
  180. Code(' {$ENDIF}');
  181. Code('{$ENDIF}')
  182. end;
  183. end;
  184. procedure TPackageSystem.GenRequires;
  185. begin
  186. Code('');
  187. if FCompiler in Delphi_Native_Ifdef_Requires then begin
  188. if FCompiler in Delphi_Native_Ifdef_Rtl_CheckIOS then begin
  189. Code('{$DEFINE HAS_PKG_RTL}');
  190. code('{$IFDEF NEXTGEN}');
  191. Code(' {$IFDEF IOS}');
  192. Code(' // there is no RTL package available for iOS');
  193. Code(' {$UNDEF HAS_PKG_RTL}');
  194. Code(' {$ENDIF}');
  195. Code('{$ENDIF}');
  196. Code('');
  197. Code('{$IFDEF HAS_PKG_RTL}');
  198. end else begin
  199. Code('{$IFNDEF NEXTGEN}');
  200. end;
  201. end;
  202. Code('requires');
  203. if FCompiler in Delphi_DotNet then begin
  204. Code(' Borland.Delphi,');
  205. Code(' Borland.VclRtl;');
  206. end
  207. else if FCompiler = ctDelphi4 then begin
  208. Code(' Vcl40;');
  209. end
  210. else if FCompiler = ctDelphi5 then begin
  211. Code(' Vcl50;');
  212. end
  213. else if FCompiler in Delphi_Native_Ifdef_Fmx then begin
  214. Code(' rtl');
  215. Code(' {$IFNDEF WINDOWS}');
  216. Code(' , fmx');
  217. Code(' {$ENDIF}');
  218. Code(' ;');
  219. end
  220. else begin
  221. Code(' rtl;');
  222. end;
  223. if FCompiler in Delphi_Native_Ifdef_Requires then begin
  224. Code('{$ENDIF}');
  225. end;
  226. end;
  227. procedure TPackageSystem.GenPreContainsClause;
  228. begin
  229. if FCompiler in Delphi_Native_Define_Windows_Before_Contains then begin
  230. Code('{$IFNDEF WINDOWS}');
  231. Code(' {$IFDEF MSWINDOWS}');
  232. Code(' {$DEFINE WINDOWS}');
  233. Code(' {$ENDIF}');
  234. Code('{$ENDIF}');
  235. Code('');
  236. end;
  237. end;
  238. procedure TPackageSystem.GenPreContainsFile(const AUnit: string);
  239. begin
  240. if FCompiler in Delphi_Native_Ifdef_Windows_In_Contains then begin
  241. if SameText(AUnit, 'IdResourceStringsUnix') then begin
  242. Code(' {$IFNDEF WINDOWS}');
  243. end
  244. else if SameText(AUnit, 'IdStackWindows') or
  245. SameText(AUnit, 'IdWinsock2') then
  246. begin
  247. Code(' {$IFDEF WINDOWS}');
  248. end
  249. else if SameText(AUnit, 'IdStackVCLPosix') or
  250. SameText(AUnit, 'IdVCLPosixSupplemental') then
  251. begin
  252. Code(' {$ELSE}');
  253. end;
  254. end;
  255. end;
  256. procedure TPackageSystem.GenPostContainsFile(const AUnit: string; const AIsLastFile: Boolean);
  257. begin
  258. if FCompiler in Delphi_Native_Ifdef_Windows_In_Contains then begin
  259. if SameText(AUnit, 'IdResourceStringsVCLPosix') or
  260. SameText(AUnit, 'IdStackVCLPosix') then
  261. begin
  262. inherited GenPostContainsFile(AUnit, AIsLastFile);
  263. Code(' {$ENDIF}');
  264. Exit;
  265. end;
  266. if SameText(AUnit, 'IdVCLPosixSupplemental') then
  267. begin
  268. Code(' {$ENDIF}');
  269. Code(' ');
  270. end
  271. else if SameText(AUnit, 'IdWship6') then begin
  272. Exit;
  273. end;
  274. end;
  275. inherited GenPostContainsFile(AUnit, AIsLastFile);
  276. end;
  277. function TPackageSystem.IgnoreContainsFile(const AUnit: string): Boolean;
  278. begin
  279. if FCompiler in Delphi_NoVCLPosix then begin
  280. // can't use Ini.ReadBool() because it only handles '0'/'1', not 'False'/'True'
  281. //Result := DM.Ini.ReadBool(AUnit, 'VCLPosix', False);
  282. Result := StrToBoolDef(DM.Ini.ReadString(AUnit, 'VCLPosix', ''), False);
  283. if Result then Exit;
  284. end;
  285. Result := inherited IgnoreContainsFile(AUnit);
  286. end;
  287. procedure TPackageSystem.GenFooter;
  288. begin
  289. if FCompiler in Delphi_DotNet then begin
  290. //back door for embedding version information into an assembly
  291. //without having to do anything to the package directly.
  292. Code('{$I IdSystem90ASM90.inc}');
  293. end;
  294. inherited GenFooter;
  295. end;
  296. procedure TPackageSystem.GenerateRC(ACompiler: TCompiler; const AFlags: TGenerateFlags);
  297. begin
  298. FName := 'IndySystem' + GPackageVer[ACompiler];
  299. FDesc := 'System Run-Time';
  300. FExt := '.rc.tmpl';
  301. inherited GenerateRC(ACompiler, AFlags - [gfDesignTime] + [gfTemplate]);
  302. WriteFile;
  303. FExt := '.rc';
  304. inherited GenerateRC(ACompiler, AFlags - [gfDesignTime, gfTemplate]);
  305. WriteFile;
  306. end;
  307. procedure TPackageSystem.GenResourceScript;
  308. begin
  309. inherited GenResourceScript;
  310. WriteFile;
  311. end;
  312. end.