PackageProtocols.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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.10 3/4/2005 3:22:12 PM JPMugaas
  18. { Updated for fix.
  19. }
  20. {
  21. { Rev 1.9 3/4/2005 3:12:40 PM JPMugaas
  22. { Attempt to make D5 package work.
  23. }
  24. {
  25. { Rev 1.8 3/4/2005 3:02:06 PM JPMugaas
  26. { Remove D5 VCL dependancy in run-time package.
  27. }
  28. {
  29. { Rev 1.7 3/3/2005 7:46:24 PM JPMugaas
  30. { Backdoors for BDS assembly version information.
  31. }
  32. {
  33. { Rev 1.6 25/11/2004 8:10:22 AM czhower
  34. { Removed D4, D8, D10, D11
  35. }
  36. {
  37. { Rev 1.5 9/7/2004 3:50:46 PM JPMugaas
  38. { Updates.
  39. }
  40. {
  41. { Rev 1.4 04/09/2004 12:45:18 ANeillans
  42. { Moved the databasename and output paths into a globally accessible variable
  43. { -- makes it a lot easier to override if you need to (as I did for my local
  44. { file structure).
  45. }
  46. {
  47. { Rev 1.3 2004.08.30 11:27:58 czhower
  48. { Updates
  49. }
  50. {
  51. { Rev 1.2 03/06/2004 7:50:26 HHariri
  52. { Fixed Protocols Package Description
  53. }
  54. {
  55. { Rev 1.1 02/06/2004 17:00:46 HHariri
  56. { design-time added
  57. }
  58. {
  59. { Rev 1.0 2004.02.08 2:28:38 PM czhower
  60. { Initial checkin
  61. }
  62. {
  63. { Rev 1.0 2004.01.22 8:18:34 PM czhower
  64. { Initial checkin
  65. }
  66. unit PackageProtocols;
  67. interface
  68. uses
  69. Package;
  70. type
  71. TPackageProtocols = class(TPackage)
  72. protected
  73. procedure GenOptions; override;
  74. procedure GenPreRequiresClause; override;
  75. procedure GenRequires; override;
  76. procedure GenPreContainsClause; override;
  77. procedure GenPreContainsFile(const AUnit: string); override;
  78. procedure GenPostContainsFile(const AUnit: string; const AIsLastFile: Boolean); override;
  79. procedure GenFooter; override;
  80. procedure GenResourceScript; override;
  81. public
  82. constructor Create; override;
  83. procedure Generate(ACompiler: TCompiler; const AFlags: TGenerateFlags); override;
  84. procedure GenerateRC(ACompiler: TCompiler; const AFlags: TGenerateFlags); override;
  85. end;
  86. implementation
  87. uses
  88. SysUtils;
  89. const
  90. Delphi_Native_Ifdef_Windows_In_Contains = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE];
  91. Delphi_Native_Ifdef_Rtl_2 = Delphi_Native_Ifdef_Rtl - [ctDelphiXE2..ctDelphiXE3];
  92. Delphi_Native_Define_Windows_Before_Contains = Delphi_Native_Ifdef_Windows_In_Contains;
  93. { TPackageProtocols }
  94. constructor TPackageProtocols.Create;
  95. begin
  96. inherited;
  97. FOutputSubDir := 'Lib\Protocols';
  98. end;
  99. procedure TPackageProtocols.Generate(ACompiler: TCompiler; const AFlags: TGenerateFlags);
  100. var
  101. LFlags: TGenerateFlags;
  102. begin
  103. LFlags := AFlags;
  104. if (LFlags * [gfRunTime, gfDesignTime]) = [] then begin
  105. Include(LFlags, gfRunTime);
  106. end;
  107. if gfRunTime in LFlags then begin
  108. FName := 'IndyProtocols' + GCompilerID[ACompiler];
  109. FDesc := 'Protocols';
  110. FExt := '.dpk';
  111. inherited Generate(ACompiler, LFlags - [gfDesignTime]);
  112. WriteFile;
  113. end;
  114. if gfDesignTime in LFlags then begin
  115. FName := 'dclIndyProtocols' + GCompilerID[ACompiler];
  116. FDesc := 'Protocols Design Time';
  117. FExt := '.dpk';
  118. inherited Generate(ACompiler, LFlags - [gfRunTime]);
  119. WriteFile;
  120. end;
  121. end;
  122. // TODO: make the options configurable...
  123. procedure TPackageProtocols.GenOptions;
  124. const
  125. Delphi_Native_Align8 = Delphi_Native - [Delphi_Native_Lowest..ctDelphi13] + [ctDelphi2005];
  126. Delphi_OmittedOptions_DT = [Delphi_Native_Lowest..ctDelphiXE, ctKylix3] - [ctDelphi8Net];
  127. Delphi_OmittedOptions_RT = [Delphi_Native_Lowest..ctDelphiXE, ctKylix3];
  128. Delphi_Native_Ifdef_ImplicitBuilding = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE];
  129. Delphi_Native_Force_DebugInfo_Off = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE7];
  130. Delphi_Native_Force_Optimization_Off = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE];
  131. Delphi_Native_Force_OverflowChecks_Off = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE];
  132. Delphi_Native_Force_RangeChecks_Off = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE];
  133. Delphi_Native_Force_StackFrames_On = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE];
  134. Delphi_Native_Define_DebugRelease = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE];
  135. Delphi_Native_Define_Ver = Delphi_Native - [Delphi_Native_Lowest..ctDelphiXE3];
  136. function OnOrOff(const AForceOff, AForceOn: TCompilers; const ADefault: Boolean): string;
  137. begin
  138. if FCompiler in AForceOff then begin
  139. Result := 'OFF';
  140. end
  141. else if FCompiler in AForceOn then begin
  142. Result := 'ON';
  143. end
  144. else begin
  145. Result := iif(ADefault, 'ON', 'OFF');
  146. end;
  147. end;
  148. begin
  149. Code('');
  150. if FCompiler in Delphi_DotNet then begin
  151. Code('{$ALIGN 0}');
  152. end else begin
  153. Code('{$R *.res}');
  154. if FCompiler in Delphi_Native_Ifdef_ImplicitBuilding then begin
  155. Code('{$IFDEF IMPLICITBUILDING This IFDEF should not be used by users}');
  156. end;
  157. if FCompiler in Delphi_Native_Align8 then begin
  158. Code('{$ALIGN 8}');
  159. end;
  160. end;
  161. if FDesignTime then begin
  162. if not (FCompiler in Delphi_OmittedOptions_DT) then begin
  163. Code('{$ASSERTIONS ON}');
  164. end;
  165. end else begin
  166. if not (FCompiler in Delphi_OmittedOptions_RT) then begin
  167. Code('{$ASSERTIONS ON}');
  168. end;
  169. end;
  170. Code('{$BOOLEVAL OFF}');
  171. if FDesignTime then begin
  172. if not (FCompiler in Delphi_OmittedOptions_DT) then begin
  173. Code('{$DEBUGINFO ' + OnOrOff(Delphi_Native_Force_DebugInfo_Off, [], FDebug) + '}');
  174. end;
  175. end else begin
  176. if not (FCompiler in Delphi_OmittedOptions_RT) then begin
  177. Code('{$DEBUGINFO ' + OnOrOff(Delphi_Native_Force_DebugInfo_Off, [], FDebug) + '}');
  178. end;
  179. end;
  180. Code('{$EXTENDEDSYNTAX ON}');
  181. Code('{$IMPORTEDDATA ON}');
  182. if FDesignTime then begin
  183. if not (FCompiler in Delphi_OmittedOptions_DT) then begin
  184. Code('{$IOCHECKS ON}');
  185. end;
  186. end else begin
  187. if not (FCompiler in Delphi_OmittedOptions_RT) then begin
  188. Code('{$IOCHECKS ON}');
  189. end;
  190. end;
  191. Code('{$LOCALSYMBOLS ' + OnOrOff([], [], FDebug) + '}');
  192. Code('{$LONGSTRINGS ON}');
  193. Code('{$OPENSTRINGS ON}');
  194. Code('{$OPTIMIZATION ' + OnOrOff(Delphi_Native_Force_Optimization_Off, [], FDebug) +'}');
  195. if FDesignTime then begin
  196. if not (FCompiler in Delphi_OmittedOptions_DT) then begin
  197. Code('{$OVERFLOWCHECKS ' + OnOrOff(Delphi_Native_Force_OverflowChecks_Off, [], FDebug) + '}');
  198. Code('{$RANGECHECKS ' + OnOrOff(Delphi_Native_Force_RangeChecks_Off, [], FDebug) + '}');
  199. end;
  200. end else begin
  201. if not (FCompiler in Delphi_OmittedOptions_RT) then begin
  202. Code('{$OVERFLOWCHECKS ' + OnOrOff(Delphi_Native_Force_OverflowChecks_Off, [], FDebug) + '}');
  203. Code('{$RANGECHECKS ' + OnOrOff(Delphi_Native_Force_RangeChecks_Off, [], FDebug) + '}');
  204. end;
  205. end;
  206. Code('{$REFERENCEINFO ' + OnOrOff([], [], FDebug) + '}');
  207. Code('{$SAFEDIVIDE OFF}');
  208. Code('{$STACKFRAMES ' + OnOrOff([], Delphi_Native_Force_StackFrames_On, not FDebug) + '}');
  209. Code('{$TYPEDADDRESS OFF}');
  210. Code('{$VARSTRINGCHECKS ON}');
  211. Code('{$WRITEABLECONST OFF}');
  212. Code('{$MINENUMSIZE 1}');
  213. Code('{$IMAGEBASE $400000}');
  214. if FCompiler in Delphi_Native_Define_DebugRelease then begin
  215. Code('{$DEFINE ' + iif(FDebug, 'DEBUG', 'RELEASE') + '}');
  216. end;
  217. if FCompiler in Delphi_Native_Define_Ver then begin
  218. Code('{$DEFINE VER' + GCompilerVer[FCompiler] + '}');
  219. end;
  220. if FCompiler in Delphi_Native_Ifdef_ImplicitBuilding then begin
  221. Code('{$ENDIF IMPLICITBUILDING}');
  222. end;
  223. Code('{$DESCRIPTION ''Indy ' + FVersion + TrimRight(' ' + FDesc) + '''}');
  224. Code(iif(FDesignTime, '{$DESIGNONLY}', '{$RUNONLY}'));
  225. Code('{$IMPLICITBUILD OFF}');
  226. end;
  227. procedure TPackageProtocols.GenPreRequiresClause;
  228. begin
  229. if not FDesignTime then begin
  230. if (FCompiler in Delphi_Native_Ifdef_Rtl) or
  231. (FCompiler in Delphi_Native_Ifdef_Windows_In_Contains) then
  232. begin
  233. Code('');
  234. Code('// RLebeau: cannot use IdCompilerDefines.inc here!');
  235. end;
  236. end;
  237. end;
  238. procedure TPackageProtocols.GenRequires;
  239. begin
  240. Code('');
  241. if (not FDesignTime) and (FCompiler in Delphi_Native_Ifdef_Rtl_2) then begin
  242. Code('{$DEFINE HAS_PKG_RTL}');
  243. code('{$IFDEF NEXTGEN}');
  244. Code(' {$IFDEF IOS}');
  245. Code(' // there is no RTL package available for iOS');
  246. Code(' {$UNDEF HAS_PKG_RTL}');
  247. Code(' {$ENDIF}');
  248. Code('{$ENDIF}');
  249. Code('');
  250. end;
  251. Code('requires');
  252. if FDesignTime then begin
  253. if FCompiler in Delphi_DotNet then
  254. begin
  255. Code(' System.Windows.Forms,');
  256. Code(' Borland.Studio.Vcl.Design,');
  257. end
  258. else if FCompiler = ctDelphi4 then
  259. begin
  260. Code(' Vcl40,');
  261. end
  262. else if FCompiler = ctDelphi5 then
  263. begin
  264. Code(' Vcl50,');
  265. end else
  266. begin
  267. if FCompiler in [ctDelphi6, ctDelphi7] then
  268. begin
  269. Code(' vcl,');
  270. end;
  271. Code(' designide,');
  272. end;
  273. Code(' IndyProtocols' + GCompilerID[FCompiler] + ',');
  274. Code(' IndySystem' + GCompilerID[FCompiler] + ',');
  275. Code(' IndyCore' + GCompilerID[FCompiler] + ',');
  276. Code(' dclIndyCore' + GCompilerID[FCompiler] + ';');
  277. end else
  278. begin
  279. if FCompiler in Delphi_DotNet then begin
  280. Code(' Borland.Delphi,');
  281. Code(' Borland.VclRtl,');
  282. end
  283. else if FCompiler = ctDelphi4 then begin
  284. //Code(' Vcl40,');
  285. end
  286. else if FCompiler = ctDelphi5 then begin
  287. //Code(' Vcl50,');
  288. end else
  289. begin
  290. if FCompiler in Delphi_Native_Ifdef_Rtl_2 then begin
  291. Code(' {$IFDEF HAS_PKG_RTL}');
  292. end
  293. else if FCompiler = ctDelphiXE3 then begin
  294. Code(' {$IFNDEF NEXTGEN}');
  295. end;
  296. Code(' rtl,');
  297. if (FCompiler in Delphi_Native_Ifdef_Rtl_2) or
  298. (FCompiler = ctDelphiXE3) then
  299. begin
  300. Code(' {$ENDIF}');
  301. end;
  302. end;
  303. Code(' IndySystem' + GCompilerID[FCompiler] + ',');
  304. Code(' IndyCore' + GCompilerID[FCompiler] + ';');
  305. end;
  306. end;
  307. procedure TPackageProtocols.GenPreContainsClause;
  308. begin
  309. if (not FDesignTime) and
  310. (FCompiler in Delphi_Native_Define_Windows_Before_Contains) then
  311. begin
  312. Code('{$IFNDEF WINDOWS}');
  313. Code(' {$IFDEF MSWINDOWS}');
  314. Code(' {$DEFINE WINDOWS}');
  315. Code(' {$ENDIF}');
  316. Code('{$ENDIF}');
  317. Code('');
  318. end;
  319. end;
  320. procedure TPackageProtocols.GenPreContainsFile(const AUnit: string);
  321. begin
  322. if FCompiler in Delphi_Native_Ifdef_Windows_In_Contains then begin
  323. if SameText(AUnit, 'IdAuthenticationSSPI') or
  324. SameText(AUnit, 'IdSSPI') then
  325. begin
  326. Code(' {$IFDEF WINDOWS}');
  327. end;
  328. end;
  329. end;
  330. procedure TPackageProtocols.GenPostContainsFile(const AUnit: string; const AIsLastFile: Boolean);
  331. begin
  332. if FCompiler in Delphi_Native_Ifdef_Windows_In_Contains then begin
  333. if SameText(AUnit, 'IdAuthenticationSSPI') or
  334. SameText(AUnit, 'IdSSPI') then
  335. begin
  336. inherited GenPostContainsFile(AUnit, AIsLastFile);
  337. Code(' {$ENDIF}');
  338. Exit;
  339. end;
  340. end;
  341. inherited GenPostContainsFile(AUnit, AIsLastFile);
  342. end;
  343. procedure TPackageProtocols.GenFooter;
  344. begin
  345. if FCompiler in Delphi_DotNet then begin
  346. //back door for embedding version information into an assembly
  347. //without having to do anything to the package directly.
  348. Code(iif(FDesignTime, '{$I IddclProtocols90ASM90.inc}', '{$I IdProtocols90ASM90.inc}'));
  349. end;
  350. inherited GenFooter;
  351. end;
  352. procedure TPackageProtocols.GenerateRC(ACompiler: TCompiler; const AFlags: TGenerateFlags);
  353. var
  354. LFlags: TGenerateFlags;
  355. begin
  356. LFlags := AFlags;
  357. if (LFlags * [gfRunTime, gfDesignTime]) = [] then begin
  358. Include(LFlags, gfRunTime);
  359. end;
  360. if gfRunTime in LFlags then begin
  361. FName := 'IndyProtocols' + GCompilerID[ACompiler];
  362. FDesc := 'Protocols Run-Time';
  363. FExt := '.rc.tmpl';
  364. inherited GenerateRC(ACompiler, LFlags - [gfDesignTime] + [gfTemplate]);
  365. WriteFile;
  366. FExt := '.rc';
  367. inherited GenerateRC(ACompiler, LFlags - [gfDesignTime, gfTemplate]);
  368. WriteFile;
  369. end;
  370. if gfDesignTime in LFlags then begin
  371. FName := 'dclIndyProtocols' + GCompilerID[ACompiler];
  372. FDesc := 'Protocols Design-Time';
  373. FExt := '.rc.tmpl';
  374. inherited GenerateRC(ACompiler, LFlags - [gfRunTime] + [gfTemplate]);
  375. WriteFile;
  376. FExt := '.rc';
  377. inherited GenerateRC(ACompiler, LFlags - [gfRunTime, gfTemplate]);
  378. WriteFile;
  379. end;
  380. end;
  381. procedure TPackageProtocols.GenResourceScript;
  382. begin
  383. inherited GenResourceScript;
  384. WriteFile;
  385. end;
  386. end.