globals.pas 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements some support functions and global variables
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit globals;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. {$ifdef windows}
  22. windows,
  23. {$endif}
  24. {$ifdef os2}
  25. dos,
  26. {$endif os2}
  27. {$ifdef hasunix}
  28. Baseunix,unix,
  29. {$endif}
  30. {$IFNDEF USE_FAKE_SYSUTILS}
  31. sysutils,
  32. {$ELSE}
  33. fksysutl,
  34. {$ENDIF}
  35. { comphook pulls in sysutils anyways }
  36. cutils,cclasses,cfileutl,
  37. cpuinfo,
  38. globtype,version,systems;
  39. const
  40. delphimodeswitches =
  41. [m_delphi,m_class,m_objpas,m_result,m_string_pchar,
  42. m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
  43. m_out,m_default_para,m_duplicate_names,m_hintdirective,
  44. m_property,m_default_inline,m_except,m_advanced_records,m_type_helpers];
  45. delphiunicodemodeswitches = delphimodeswitches + [m_systemcodepage,m_default_unicodestring];
  46. fpcmodeswitches =
  47. [m_fpc,m_string_pchar,m_nested_comment,m_repeat_forward,
  48. m_cvar_support,m_initfinal,m_hintdirective,
  49. m_property,m_default_inline];
  50. objfpcmodeswitches =
  51. [m_objfpc,m_fpc,m_class,m_objpas,m_result,m_string_pchar,m_nested_comment,
  52. m_repeat_forward,m_cvar_support,m_initfinal,m_out,m_default_para,m_hintdirective,
  53. m_property,m_default_inline,m_except];
  54. tpmodeswitches =
  55. [m_tp7,m_tp_procvar,m_duplicate_names];
  56. {$ifdef gpc_mode}
  57. gpcmodeswitches =
  58. [m_gpc,m_tp_procvar];
  59. {$endif}
  60. macmodeswitches =
  61. [m_mac,m_cvar_support,m_mac_procvar,m_nested_procvars,m_non_local_goto,m_isolike_unary_minus,m_default_inline];
  62. isomodeswitches =
  63. [m_iso,m_tp_procvar,m_duplicate_names,m_nested_procvars,m_non_local_goto,m_isolike_unary_minus];
  64. { maximum nesting of routines }
  65. maxnesting = 32;
  66. { Filenames and extensions }
  67. sourceext = '.pp';
  68. pasext = '.pas';
  69. pext = '.p';
  70. treelogfilename = 'tree.log';
  71. {$if defined(CPUARM) and defined(FPUFPA)}
  72. MathQNaN : tcompdoublerec = (bytes : (0,0,252,255,0,0,0,0));
  73. MathInf : tcompdoublerec = (bytes : (0,0,240,127,0,0,0,0));
  74. MathNegInf : tcompdoublerec = (bytes : (0,0,240,255,0,0,0,0));
  75. MathPi : tcompdoublerec = (bytes : (251,33,9,64,24,45,68,84));
  76. {$else}
  77. {$ifdef FPC_LITTLE_ENDIAN}
  78. MathQNaN : tcompdoublerec = (bytes : (0,0,0,0,0,0,252,255));
  79. MathInf : tcompdoublerec = (bytes : (0,0,0,0,0,0,240,127));
  80. MathNegInf : tcompdoublerec = (bytes : (0,0,0,0,0,0,240,255));
  81. MathPi : tcompdoublerec = (bytes : (24,45,68,84,251,33,9,64));
  82. MathPiExtended : tcompextendedrec = (bytes : (53,194,104,33,162,218,15,201,0,64));
  83. {$else FPC_LITTLE_ENDIAN}
  84. MathQNaN : tcompdoublerec = (bytes : (255,252,0,0,0,0,0,0));
  85. MathInf : tcompdoublerec = (bytes : (127,240,0,0,0,0,0,0));
  86. MathNegInf : tcompdoublerec = (bytes : (255,240,0,0,0,0,0,0));
  87. MathPi : tcompdoublerec = (bytes : (64,9,33,251,84,68,45,24));
  88. MathPiExtended : tcompextendedrec = (bytes : (64,0,201,15,218,162,33,104,194,53));
  89. {$endif FPC_LITTLE_ENDIAN}
  90. {$endif}
  91. CP_UTF8 = 65001;
  92. CP_UTF16LE = 1200;
  93. CP_UTF16BE = 1201;
  94. CP_NONE = 65535;
  95. { by default no local variable trashing }
  96. localvartrashing: longint = -1;
  97. nroftrashvalues = 4;
  98. trashintvalues: array[0..nroftrashvalues-1] of int64 = ($5555555555555555,$AAAAAAAAAAAAAAAA,$EFEFEFEFEFEFEFEF,0);
  99. type
  100. { this is written to ppus during token recording for generics,
  101. it used to required to be packed,
  102. but this requirement is now obsolete,
  103. as the fields are written one by one. PM 2012-06-13 }
  104. tsettings = record
  105. alignment : talignmentinfo;
  106. globalswitches : tglobalswitches;
  107. targetswitches : ttargetswitches;
  108. moduleswitches : tmoduleswitches;
  109. localswitches : tlocalswitches;
  110. modeswitches : tmodeswitches;
  111. optimizerswitches : toptimizerswitches;
  112. { generate information necessary to perform these wpo's during a subsequent compilation }
  113. genwpoptimizerswitches: twpoptimizerswitches;
  114. { perform these wpo's using information generated during a previous compilation }
  115. dowpoptimizerswitches: twpoptimizerswitches;
  116. debugswitches : tdebugswitches;
  117. { 0: old behaviour for sets <=256 elements
  118. >0: round to this size }
  119. setalloc,
  120. packenum : shortint;
  121. packrecords : shortint;
  122. maxfpuregisters : shortint;
  123. cputype,
  124. optimizecputype : tcputype;
  125. fputype : tfputype;
  126. asmmode : tasmmode;
  127. interfacetype : tinterfacetypes;
  128. defproccall : tproccalloption;
  129. sourcecodepage : tstringencoding;
  130. minfpconstprec : tfloattype;
  131. disabledircache : boolean;
  132. {$if defined(i8086)}
  133. x86memorymodel : tx86memorymodel;
  134. {$endif defined(i8086)}
  135. {$if defined(ARM)}
  136. instructionset : tinstructionset;
  137. {$endif defined(ARM)}
  138. { CPU targets with microcontroller support can add a controller specific unit }
  139. controllertype : tcontrollertype;
  140. { WARNING: this pointer cannot be written as such in record token }
  141. pmessage : pmessagestaterecord;
  142. end;
  143. const
  144. LinkMapWeightDefault = 1000;
  145. type
  146. TLinkRec = record
  147. Key : AnsiString;
  148. Value : AnsiString; // key expands to valuelist "value"
  149. Weight: longint;
  150. end;
  151. TLinkStrMap = class
  152. private
  153. itemcnt : longint;
  154. fmap : Array Of TLinkRec;
  155. function Lookup(key:Ansistring):longint;
  156. function getlinkrec(i:longint):TLinkRec;
  157. public
  158. procedure Add(key:ansistring;value:AnsiString='';weight:longint=LinkMapWeightDefault);
  159. procedure addseries(keys:AnsiString;weight:longint=LinkMapWeightDefault);
  160. function AddDep(keyvalue:String):boolean;
  161. function AddWeight(keyvalue:String):boolean;
  162. procedure SetValue(key:AnsiString;Weight:Integer);
  163. procedure SortonWeight;
  164. function Find(key:AnsiString):AnsiString;
  165. procedure Expand(src:TCmdStrList;dest: TLinkStrMap);
  166. procedure UpdateWeights(Weightmap:TLinkStrMap);
  167. constructor Create;
  168. property count : longint read itemcnt;
  169. property items[I:longint]:TLinkRec read getlinkrec; default;
  170. end;
  171. tpendingstate = record
  172. nextverbositystr : shortstring;
  173. nextlocalswitches : tlocalswitches;
  174. nextverbosityfullswitch: longint;
  175. nextcallingstr : shortstring;
  176. nextmessagerecord : pmessagestaterecord;
  177. verbosityfullswitched,
  178. localswitcheschanged : boolean;
  179. end;
  180. var
  181. { specified inputfile }
  182. inputfilepath : string;
  183. inputfilename : string;
  184. { specified outputfile with -o parameter }
  185. outputfilename : string;
  186. outputprefix : pshortstring;
  187. outputsuffix : pshortstring;
  188. { specified with -FE or -FU }
  189. outputexedir : TPathStr;
  190. outputunitdir : TPathStr;
  191. { specified with -FW and -Fw }
  192. wpofeedbackinput,
  193. wpofeedbackoutput : TPathStr;
  194. { external assembler extra option }
  195. asmextraopt : string;
  196. { things specified with parameters }
  197. paralinkoptions : TCmdStr;
  198. paradynamiclinker : string;
  199. paraprintnodetree : byte;
  200. {$ifdef PREPROCWRITE}
  201. parapreprocess : boolean;
  202. {$endif PREPROCWRITE}
  203. printnodefile : text;
  204. { typical cross compiling params}
  205. { directory where the utils can be found (options -FD) }
  206. utilsdirectory : TPathStr;
  207. { targetname specific prefix used by these utils (options -XP<path>) }
  208. utilsprefix : TCmdStr;
  209. cshared : boolean; { pass --shared to ld to link C libs shared}
  210. Dontlinkstdlibpath: Boolean; { Don't add std paths to linkpath}
  211. rlinkpath : TCmdStr; { rpath-link linkdir override}
  212. sysrootpath : TCmdStr; { target system root to search dyn linker }
  213. { some flags for global compiler switches }
  214. do_build,
  215. do_release,
  216. do_make : boolean;
  217. { Path to ppc }
  218. exepath : TPathStr;
  219. { Path to unicode charmap/collation binaries }
  220. unicodepath : TPathStr;
  221. { path for searching units, different paths can be seperated by ; }
  222. librarysearchpath,
  223. unitsearchpath,
  224. objectsearchpath,
  225. includesearchpath,
  226. frameworksearchpath : TSearchPathList;
  227. autoloadunits : string;
  228. { linking }
  229. usegnubinutils : boolean;
  230. forceforwardslash : boolean;
  231. usewindowapi : boolean;
  232. description : string;
  233. SetPEFlagsSetExplicity,
  234. SetPEOptFlagsSetExplicity,
  235. ImageBaseSetExplicity,
  236. MinStackSizeSetExplicity,
  237. MaxStackSizeSetExplicity,
  238. DescriptionSetExplicity : boolean;
  239. dllversion : string;
  240. dllmajor,
  241. dllminor,
  242. dllrevision : word; { revision only for netware }
  243. { win pe }
  244. peoptflags,
  245. peflags : longint;
  246. minstacksize,
  247. maxstacksize,
  248. imagebase : puint;
  249. UseDeffileForExports : boolean;
  250. UseDeffileForExportsSetExplicitly : boolean;
  251. GenerateImportSection,
  252. GenerateImportSectionSetExplicitly,
  253. RelocSection : boolean;
  254. MacOSXVersionMin,
  255. iPhoneOSVersionMin: string[15];
  256. RelocSectionSetExplicitly : boolean;
  257. current_tokenpos, { position of the last token }
  258. current_filepos : tfileposinfo; { current position }
  259. nwscreenname : string;
  260. nwthreadname : string;
  261. nwcopyright : string;
  262. codegenerror : boolean; { true if there is an error reported }
  263. exception_raised : boolean; { true if there is an exception reported }
  264. block_type : tblock_type; { type of currently parsed block }
  265. compile_level : word;
  266. exceptblockcounter : integer; { each except block gets a unique number check gotos }
  267. current_exceptblock : integer; { the exceptblock number of the current block (0 if none) }
  268. LinkLibraryAliases : TLinkStrMap;
  269. LinkLibraryOrder : TLinkStrMap;
  270. init_settings,
  271. current_settings : tsettings;
  272. pendingstate : tpendingstate;
  273. { Memory sizes }
  274. heapsize,
  275. maxheapsize,
  276. stacksize : longint;
  277. {$Ifdef EXTDEBUG}
  278. { parameter switches }
  279. debugstop : boolean;
  280. {$EndIf EXTDEBUG}
  281. { Application type (platform specific)
  282. see globtype.pas for description }
  283. apptype : tapptype;
  284. features : tfeatures;
  285. { prefix added to automatically generated setters/getters. If empty,
  286. no getters/setters will be automatically generated except if required
  287. for visibility reasons (but in that case the names will be mangled so
  288. they are unique) }
  289. prop_auto_getter_prefix,
  290. prop_auto_setter_prefix : string;
  291. const
  292. DLLsource : boolean = false;
  293. Inside_asm_statement : boolean = false;
  294. global_unit_count : word = 0;
  295. { for error info in pp.pas }
  296. parser_current_file : string = '';
  297. {$if defined(m68k) or defined(arm)}
  298. { PalmOS resources }
  299. palmos_applicationname : string = 'FPC Application';
  300. palmos_applicationid : string[4] = 'FPCA';
  301. {$endif defined(m68k) or defined(arm)}
  302. {$ifdef powerpc}
  303. { default calling convention used on MorphOS }
  304. syscall_convention : string = 'LEGACY';
  305. {$endif powerpc}
  306. { default name of the C-style "main" procedure of the library/program }
  307. { (this will be prefixed with the target_info.cprefix) }
  308. defaultmainaliasname = 'main';
  309. mainaliasname : string = defaultmainaliasname;
  310. const
  311. default_settings : TSettings = (
  312. alignment : (
  313. procalign : 0;
  314. loopalign : 0;
  315. jumpalign : 0;
  316. constalignmin : 0;
  317. constalignmax : 0;
  318. varalignmin : 0;
  319. varalignmax : 0;
  320. localalignmin : 0;
  321. localalignmax : 0;
  322. recordalignmin : 0;
  323. recordalignmax : 0;
  324. maxCrecordalign : 0;
  325. );
  326. globalswitches : [cs_check_unit_name,cs_link_static];
  327. targetswitches : [];
  328. moduleswitches : [cs_extsyntax,cs_implicit_exceptions];
  329. localswitches : [cs_check_io,cs_typed_const_writable,cs_pointermath{$ifdef i8086},cs_force_far_calls{$endif}];
  330. modeswitches : fpcmodeswitches;
  331. optimizerswitches : [];
  332. genwpoptimizerswitches : [];
  333. dowpoptimizerswitches : [];
  334. debugswitches : [ds_dwarf_sets];
  335. setalloc : 0;
  336. packenum : 4;
  337. {$ifdef i8086}
  338. packrecords : 1;
  339. {$else i8086}
  340. packrecords : 0;
  341. {$endif i8086}
  342. maxfpuregisters : 0;
  343. { Note: GENERIC_CPU is used together with generic subdirectory to
  344. be able to compile some of the units without any real CPU.
  345. This is used to generate a CPU independant PPUDUMP utility. PM }
  346. {$ifdef GENERIC_CPU}
  347. cputype : cpu_none;
  348. optimizecputype : cpu_none;
  349. fputype : fpu_none;
  350. {$else not GENERIC_CPU}
  351. {$ifdef i386}
  352. cputype : cpu_Pentium;
  353. optimizecputype : cpu_Pentium3;
  354. fputype : fpu_x87;
  355. {$endif i386}
  356. {$ifdef m68k}
  357. cputype : cpu_MC68020;
  358. optimizecputype : cpu_MC68020;
  359. fputype : fpu_soft;
  360. {$endif m68k}
  361. {$ifdef powerpc}
  362. cputype : cpu_PPC604;
  363. optimizecputype : cpu_ppc7400;
  364. fputype : fpu_standard;
  365. {$endif powerpc}
  366. {$ifdef POWERPC64}
  367. cputype : cpu_PPC970;
  368. optimizecputype : cpu_ppc970;
  369. fputype : fpu_standard;
  370. {$endif POWERPC64}
  371. {$ifdef sparc}
  372. cputype : cpu_SPARC_V9;
  373. optimizecputype : cpu_SPARC_V9;
  374. fputype : fpu_hard;
  375. {$endif sparc}
  376. {$ifdef arm}
  377. cputype : cpu_armv4;
  378. optimizecputype : cpu_armv4;
  379. fputype : fpu_fpa;
  380. {$endif arm}
  381. {$ifdef x86_64}
  382. cputype : cpu_athlon64;
  383. optimizecputype : cpu_athlon64;
  384. fputype : fpu_sse64;
  385. {$endif x86_64}
  386. {$ifdef avr}
  387. cputype : cpuinfo.cpu_avr5;
  388. optimizecputype : cpuinfo.cpu_avr5;
  389. fputype : fpu_none;
  390. {$endif avr}
  391. {$ifdef mips}
  392. cputype : cpu_mips2;
  393. optimizecputype : cpu_mips2;
  394. fputype : fpu_mips2;
  395. {$endif mips}
  396. {$ifdef jvm}
  397. cputype : cpu_none;
  398. optimizecputype : cpu_none;
  399. fputype : fpu_standard;
  400. {$endif jvm}
  401. {$ifdef aarch64}
  402. cputype : cpu_armv8;
  403. optimizecputype : cpu_armv8;
  404. fputype : fpu_vfp;
  405. {$endif aarch64}
  406. {$ifdef i8086}
  407. cputype : cpu_8086;
  408. optimizecputype : cpu_8086;
  409. fputype : fpu_x87;
  410. {$endif i8086}
  411. {$endif not GENERIC_CPU}
  412. asmmode : asmmode_standard;
  413. {$ifndef jvm}
  414. interfacetype : it_interfacecom;
  415. {$else jvm}
  416. interfacetype : it_interfacejava;
  417. {$endif jvm}
  418. defproccall : pocall_default;
  419. sourcecodepage : 28591;
  420. minfpconstprec : s32real;
  421. disabledircache : false;
  422. {$if defined(i8086)}
  423. x86memorymodel : mm_small;
  424. {$endif defined(i8086)}
  425. {$if defined(ARM)}
  426. instructionset : is_arm;
  427. {$endif defined(ARM)}
  428. controllertype : ct_none;
  429. pmessage : nil;
  430. );
  431. var
  432. starttime : real;
  433. function getdatestr:string;
  434. function gettimestr:string;
  435. function filetimestring( t : longint) : string;
  436. function getrealtime : real;
  437. procedure DefaultReplacements(var s:ansistring);
  438. function GetEnvPChar(const envname:ansistring):pchar;
  439. procedure FreeEnvPChar(p:pchar);
  440. function is_number_float(d : double) : boolean;
  441. { discern +0.0 and -0.0 }
  442. function get_real_sign(r: bestreal): longint;
  443. procedure InitGlobals;
  444. procedure DoneGlobals;
  445. function string2guid(const s: string; var GUID: TGUID): boolean;
  446. function guid2string(const GUID: TGUID): string;
  447. function SetAktProcCall(const s:string; var a:tproccalloption):boolean;
  448. function Setabitype(const s:string;var a:tabi):boolean;
  449. function Setoptimizecputype(const s:string;var a:tcputype):boolean;
  450. function Setcputype(const s:string;var a:tsettings):boolean;
  451. function SetFpuType(const s:string;var a:tfputype):boolean;
  452. function SetControllerType(const s:string;var a:tcontrollertype):boolean;
  453. function IncludeFeature(const s : string) : boolean;
  454. function SetMinFPConstPrec(const s: string; var a: tfloattype) : boolean;
  455. {# Routine to get the required alignment for size of data, which will
  456. be placed in bss segment, according to the current alignment requirements }
  457. function var_align(want_align: longint): shortint;
  458. function var_align_size(siz: longint): shortint;
  459. {# Routine to get the required alignment for size of data, which will
  460. be placed in data/const segment, according to the current alignment requirements }
  461. function const_align(want_align: longint): shortint;
  462. function const_align_size(siz: longint): shortint;
  463. {$ifdef ARM}
  464. function is_double_hilo_swapped: boolean;{$ifdef USEINLINE}inline;{$endif}
  465. {$endif ARM}
  466. function floating_point_range_check_error : boolean;
  467. function use_dotted_functions: boolean;
  468. { hide Sysutils.ExecuteProcess in units using this one after SysUtils}
  469. const
  470. ExecuteProcess = 'Do not use' deprecated 'Use cfileutil.RequotedExecuteProcess instead, ExecuteProcess cannot deal with single quotes as used by Unix command lines';
  471. implementation
  472. uses
  473. {$ifdef macos}
  474. macutils,
  475. {$endif}
  476. {$ifdef mswindows}
  477. windirs,
  478. {$endif}
  479. comphook;
  480. {****************************************************************************
  481. TLinkStrMap
  482. ****************************************************************************}
  483. Constructor TLinkStrMap.create;
  484. begin
  485. inherited;
  486. itemcnt:=0;
  487. end;
  488. procedure TLinkStrMap.Add(key:ansistring;value:AnsiString='';weight:longint=LinkMapWeightDefault);
  489. begin
  490. if lookup(key)<>-1 Then
  491. exit;
  492. if itemcnt<=length(fmap) Then
  493. setlength(fmap,itemcnt+10);
  494. fmap[itemcnt].key:=key;
  495. fmap[itemcnt].value:=value;
  496. fmap[itemcnt].weight:=weight;
  497. inc(itemcnt);
  498. end;
  499. function TLinkStrMap.AddDep(keyvalue:String):boolean;
  500. var
  501. i : Longint;
  502. begin
  503. AddDep:=false;
  504. i:=pos('=',keyvalue);
  505. if i=0 then
  506. exit;
  507. Add(Copy(KeyValue,1,i-1),Copy(KeyValue,i+1,length(KeyValue)-i));
  508. AddDep:=True;
  509. end;
  510. function TLinkStrMap.AddWeight(keyvalue:String):boolean;
  511. var
  512. i,j : Longint;
  513. Code : Word;
  514. s : AnsiString;
  515. begin
  516. AddWeight:=false;
  517. i:=pos('=',keyvalue);
  518. if i=0 then
  519. exit;
  520. s:=Copy(KeyValue,i+1,length(KeyValue)-i);
  521. val(s,j,code);
  522. if code=0 Then
  523. begin
  524. Add(Copy(KeyValue,1,i-1),'',j);
  525. AddWeight:=True;
  526. end;
  527. end;
  528. procedure TLinkStrMap.addseries(keys:AnsiString;weight:longint);
  529. var
  530. i,j,k : longint;
  531. begin
  532. k:=length(keys);
  533. i:=1;
  534. while i<=k do
  535. begin
  536. j:=i;
  537. while (i<=k) and (keys[i]<>',') do
  538. inc(i);
  539. add(copy(keys,j,i-j),'',weight);
  540. inc(i);
  541. end;
  542. end;
  543. procedure TLinkStrMap.SetValue(Key:Ansistring;weight:Integer);
  544. var
  545. j : longint;
  546. begin
  547. j:=lookup(key);
  548. if j<>-1 then
  549. fmap[j].weight:=weight;
  550. end;
  551. function TLinkStrMap.find(key:Ansistring):Ansistring;
  552. var
  553. j : longint;
  554. begin
  555. find:='';
  556. j:=lookup(key);
  557. if j<>-1 then
  558. find:=fmap[j].value;
  559. end;
  560. function TLinkStrMap.lookup(key:Ansistring):longint;
  561. var
  562. i : longint;
  563. begin
  564. lookup:=-1;
  565. i:=0;
  566. while (i<itemcnt) and (fmap[i].key<>key) do
  567. inc(i);
  568. if i<>itemcnt then
  569. lookup:=i;
  570. end;
  571. procedure TLinkStrMap.SortOnWeight;
  572. var
  573. i, j : longint;
  574. m : TLinkRec;
  575. begin
  576. if itemcnt <2 then exit;
  577. for i:=0 to itemcnt-1 do
  578. for j:=i+1 to itemcnt-1 do
  579. begin
  580. if fmap[i].weight>fmap[j].weight Then
  581. begin
  582. m:=fmap[i];
  583. fmap[i]:=fmap[j];
  584. fmap[j]:=m;
  585. end;
  586. end;
  587. end;
  588. function TLinkStrMap.getlinkrec(i:longint):TLinkRec;
  589. begin
  590. result:=fmap[i];
  591. end;
  592. procedure TLinkStrMap.Expand(Src:TCmdStrList;Dest:TLinkStrMap);
  593. // expands every thing in Src to Dest for linkorder purposes.
  594. var
  595. r : longint;
  596. LibN : TCmdStr;
  597. begin
  598. while not src.empty do
  599. begin
  600. LibN:=src.getfirst;
  601. r:=lookup (LibN);
  602. if r=-1 then
  603. dest.add(LibN)
  604. else
  605. dest.addseries(fmap[r].value);
  606. end;
  607. end;
  608. procedure TLinkStrMap.UpdateWeights(Weightmap:TLinkStrMap);
  609. var
  610. l,r : longint;
  611. begin
  612. for l := 0 to itemcnt-1 do
  613. begin
  614. r:=weightmap.lookup (fmap[l].key);
  615. if r<>-1 then
  616. fmap[l].weight:=weightmap[r].weight;
  617. end;
  618. end;
  619. {****************************************************************************
  620. Time Handling
  621. ****************************************************************************}
  622. Function L0(l:longint):string;
  623. {
  624. return the string of value l, if l<10 then insert a zero, so
  625. the string is always at least 2 chars '01','02',etc
  626. }
  627. var
  628. s : string;
  629. begin
  630. Str(l,s);
  631. if l<10 then
  632. s:='0'+s;
  633. L0:=s;
  634. end;
  635. function gettimestr:string;
  636. {
  637. get the current time in a string HH:MM:SS
  638. }
  639. var
  640. hour,min,sec,hsec : word;
  641. begin
  642. DecodeTime(Time,hour,min,sec,hsec);
  643. gettimestr:=L0(Hour)+':'+L0(min)+':'+L0(sec);
  644. end;
  645. function getdatestr:string;
  646. {
  647. get the current date in a string YY/MM/DD
  648. }
  649. var
  650. Year,Month,Day: Word;
  651. begin
  652. DecodeDate(Date,year,month,day);
  653. getdatestr:=L0(Year)+'/'+L0(Month)+'/'+L0(Day);
  654. end;
  655. function filetimestring( t : longint) : string;
  656. {
  657. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  658. }
  659. var
  660. DT : TDateTime;
  661. hsec : word;
  662. Year,Month,Day: Word;
  663. hour,min,sec : word;
  664. begin
  665. if t=-1 then
  666. begin
  667. Result := 'Not Found';
  668. exit;
  669. end;
  670. DT := FileDateToDateTime(t);
  671. DecodeTime(DT,hour,min,sec,hsec);
  672. DecodeDate(DT,year,month,day);
  673. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  674. end;
  675. function getrealtime : real;
  676. var
  677. h,m,s,s1000 : word;
  678. begin
  679. DecodeTime(Time,h,m,s,s1000);
  680. result:=h*3600.0+m*60.0+s+s1000/1000.0;
  681. end;
  682. {****************************************************************************
  683. Default Macro Handling
  684. ****************************************************************************}
  685. procedure DefaultReplacements(var s:ansistring);
  686. {$ifdef mswindows}
  687. procedure ReplaceSpecialFolder(const MacroName: string; const ID: integer);
  688. begin
  689. // Only try to receive the special folders (and thus dynamically
  690. // load shfolder.dll) when that's needed.
  691. if pos(MacroName,s)>0 then
  692. Replace(s,MacroName,GetWindowsSpecialDir(ID));
  693. end;
  694. {$endif mswindows}
  695. var
  696. envstr: string;
  697. envvalue: pchar;
  698. i: integer;
  699. begin
  700. { Replace some macros }
  701. Replace(s,'$FPCVERSION',version_string);
  702. Replace(s,'$FPCFULLVERSION',full_version_string);
  703. Replace(s,'$FPCDATE',date_string);
  704. Replace(s,'$FPCCPU',target_cpu_string);
  705. Replace(s,'$FPCOS',target_os_string);
  706. if (tf_use_8_3 in Source_Info.Flags) or
  707. (tf_use_8_3 in Target_Info.Flags) then
  708. Replace(s,'$FPCTARGET',target_os_string)
  709. else
  710. Replace(s,'$FPCTARGET',target_full_string);
  711. Replace(s,'$FPCSUBARCH',lower(cputypestr[init_settings.cputype]));
  712. Replace(s,'$FPCABI',lower(abiinfo[target_info.abi].name));
  713. {$ifdef i8086}
  714. Replace(s,'$FPCMEMORYMODEL',lower(x86memorymodelstr[init_settings.x86memorymodel]));
  715. {$else i8086}
  716. Replace(s,'$FPCMEMORYMODEL','flat');
  717. {$endif i8086}
  718. {$ifdef mswindows}
  719. ReplaceSpecialFolder('$LOCAL_APPDATA',CSIDL_LOCAL_APPDATA);
  720. ReplaceSpecialFolder('$APPDATA',CSIDL_APPDATA);
  721. ReplaceSpecialFolder('$COMMON_APPDATA',CSIDL_COMMON_APPDATA);
  722. ReplaceSpecialFolder('$PERSONAL',CSIDL_PERSONAL);
  723. ReplaceSpecialFolder('$PROGRAM_FILES',CSIDL_PROGRAM_FILES);
  724. ReplaceSpecialFolder('$PROGRAM_FILES_COMMON',CSIDL_PROGRAM_FILES_COMMON);
  725. ReplaceSpecialFolder('$PROFILE',CSIDL_PROFILE);
  726. {$endif mswindows}
  727. { Replace environment variables between dollar signs }
  728. i := pos('$',s);
  729. while i>0 do
  730. begin
  731. envstr:=copy(s,i+1,length(s)-i);
  732. i:=pos('$',envstr);
  733. if i>0 then
  734. begin
  735. envstr := copy(envstr,1,i-1);
  736. envvalue := GetEnvPChar(envstr);
  737. if assigned(envvalue) then
  738. begin
  739. Replace(s,'$'+envstr+'$',envvalue);
  740. // Look if there is another env.var in the string
  741. i:=pos('$',s);
  742. end
  743. else
  744. // if the env.var is not set, do not replace the env.variable
  745. // and stop looking for more env.var within the string
  746. i := 0;
  747. FreeEnvPChar(envvalue);
  748. end;
  749. end;
  750. end;
  751. {****************************************************************************
  752. OS Dependent things
  753. ****************************************************************************}
  754. function GetEnvPChar(const envname:ansistring):pchar;
  755. {$ifdef mswindows}
  756. var
  757. s : string;
  758. i,len : longint;
  759. hp,p,p2 : pchar;
  760. {$endif}
  761. begin
  762. {$ifdef hasunix}
  763. GetEnvPchar:=BaseUnix.fpGetEnv(pansichar(envname));
  764. {$define GETENVOK}
  765. {$endif}
  766. {$ifdef mswindows}
  767. GetEnvPchar:=nil;
  768. p:=GetEnvironmentStringsA;
  769. hp:=p;
  770. while hp^<>#0 do
  771. begin
  772. s:=strpas(hp);
  773. i:=pos('=',s);
  774. len:=strlen(hp);
  775. if upper(copy(s,1,i-1))=upper(envname) then
  776. begin
  777. GetMem(p2,len-length(envname));
  778. Move(hp[i],p2^,len-length(envname));
  779. GetEnvPchar:=p2;
  780. break;
  781. end;
  782. { next string entry}
  783. hp:=hp+len+1;
  784. end;
  785. FreeEnvironmentStrings(p);
  786. {$define GETENVOK}
  787. {$endif}
  788. {$ifdef os2}
  789. GetEnvPChar := Dos.GetEnvPChar (EnvName);
  790. {$define GETENVOK}
  791. {$endif}
  792. {$ifdef GETENVOK}
  793. {$undef GETENVOK}
  794. {$else}
  795. GetEnvPchar:=StrPNew(GetEnvironmentVariable(envname));
  796. if (length(GetEnvPChar)=0) then
  797. begin
  798. FreeEnvPChar(GetEnvPChar);
  799. GetEnvPChar:=nil;
  800. end;
  801. {$endif}
  802. end;
  803. procedure FreeEnvPChar(p:pchar);
  804. begin
  805. {$ifndef hasunix}
  806. {$ifndef os2}
  807. freemem(p);
  808. {$endif}
  809. {$endif}
  810. end;
  811. function is_number_float(d : double) : boolean;
  812. var
  813. bytearray : array[0..7] of byte;
  814. begin
  815. move(d,bytearray,8);
  816. { only 1.1 save, 1.0.x will use always little endian }
  817. {$ifdef FPC_BIG_ENDIAN}
  818. result:=((bytearray[0] and $7f)<>$7f) or ((bytearray[1] and $f0)<>$f0);
  819. {$else FPC_BIG_ENDIAN}
  820. result:=((bytearray[7] and $7f)<>$7f) or ((bytearray[6] and $f0)<>$f0);
  821. {$endif FPC_BIG_ENDIAN}
  822. end;
  823. function get_real_sign(r: bestreal): longint;
  824. var
  825. p: pbyte;
  826. begin
  827. p := pbyte(@r);
  828. {$ifdef CPU_ARM}
  829. inc(p,4);
  830. {$else}
  831. {$ifdef FPC_LITTLE_ENDIAN}
  832. inc(p,sizeof(r)-1);
  833. {$endif}
  834. {$endif}
  835. if (p^ and $80) = 0 then
  836. result := 1
  837. else
  838. result := -1;
  839. end;
  840. function convertdoublerec(d : tcompdoublerec) : tcompdoublerec;{$ifdef USEINLINE}inline;{$endif}
  841. {$ifdef CPUARM}
  842. var
  843. i : longint;
  844. begin
  845. for i:=0 to 3 do
  846. begin
  847. result.bytes[i+4]:=d.bytes[i];
  848. result.bytes[i]:=d.bytes[i+4];
  849. end;
  850. {$else CPUARM}
  851. begin
  852. result:=d;
  853. {$endif CPUARM}
  854. end;
  855. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  856. function string2guid(const s: string; var GUID: TGUID): boolean;
  857. function ishexstr(const hs: string): boolean;
  858. var
  859. i: integer;
  860. begin
  861. ishexstr:=false;
  862. for i:=1 to Length(hs) do begin
  863. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  864. exit;
  865. end;
  866. ishexstr:=true;
  867. end;
  868. function hexstr2longint(const hexs: string): longint;
  869. var
  870. i: integer;
  871. rl: longint;
  872. begin
  873. rl:=0;
  874. for i:=1 to length(hexs) do begin
  875. rl:=rl shl 4;
  876. case hexs[i] of
  877. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  878. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  879. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  880. end
  881. end;
  882. hexstr2longint:=rl;
  883. end;
  884. var
  885. i: integer;
  886. begin
  887. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  888. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  889. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  890. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  891. ishexstr(copy(s,26,12)) then begin
  892. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  893. { these values are arealdy in the correct range (4 chars = word) }
  894. GUID.D2:=word(hexstr2longint(copy(s,11,4)));
  895. GUID.D3:=word(hexstr2longint(copy(s,16,4)));
  896. for i:=0 to 1 do
  897. GUID.D4[i]:=byte(hexstr2longint(copy(s,21+i*2,2)));
  898. for i:=2 to 7 do
  899. GUID.D4[i]:=byte(hexstr2longint(copy(s,22+i*2,2)));
  900. string2guid:=true;
  901. end
  902. else if (length(s)=0) then
  903. begin
  904. FillChar(GUID,SizeOf(GUID),0);
  905. string2guid:=true;
  906. end
  907. else
  908. string2guid:=false;
  909. end;
  910. function guid2string(const GUID: TGUID): string;
  911. begin
  912. guid2string:=
  913. '{'+hexstr(GUID.D1,8)+
  914. '-'+hexstr(GUID.D2,4)+
  915. '-'+hexstr(GUID.D3,4)+
  916. '-'+hexstr(GUID.D4[0],2)+hexstr(GUID.D4[1],2)+
  917. '-'+hexstr(GUID.D4[2],2)+hexstr(GUID.D4[3],2)+
  918. hexstr(GUID.D4[4],2)+hexstr(GUID.D4[5],2)+
  919. hexstr(GUID.D4[6],2)+hexstr(GUID.D4[7],2)+
  920. '}';
  921. end;
  922. function SetAktProcCall(const s:string; var a:tproccalloption):boolean;
  923. const
  924. DefProcCallName : array[tproccalloption] of string[12] = ('',
  925. 'CDECL',
  926. 'CPPDECL',
  927. 'FAR16',
  928. 'OLDFPCCALL',
  929. '', { internproc }
  930. '', { syscall }
  931. 'PASCAL',
  932. 'REGISTER',
  933. 'SAFECALL',
  934. 'STDCALL',
  935. 'SOFTFLOAT',
  936. 'MWPASCAL',
  937. 'INTERRUPT'
  938. );
  939. var
  940. t : tproccalloption;
  941. hs : string;
  942. begin
  943. result:=false;
  944. if (s = '') then
  945. exit;
  946. hs:=upper(s);
  947. if (hs = 'DEFAULT') then
  948. begin
  949. a := pocall_default;
  950. result := true;
  951. exit;
  952. end;
  953. for t:=low(tproccalloption) to high(tproccalloption) do
  954. if DefProcCallName[t]=hs then
  955. begin
  956. a:=t;
  957. result:=true;
  958. break;
  959. end;
  960. end;
  961. function Setabitype(const s:string;var a:tabi):boolean;
  962. var
  963. t : tabi;
  964. hs : string;
  965. begin
  966. result:=false;
  967. hs:=Upper(s);
  968. for t:=low(t) to high(t) do
  969. if abiinfo[t].supported and
  970. (abiinfo[t].name=hs) then
  971. begin
  972. a:=t;
  973. { abi_old_win32_gnu is a win32 i386 specific "feature" }
  974. if (t<>abi_old_win32_gnu) or (target_info.system=system_i386_win32) then
  975. result:=true;
  976. break;
  977. end;
  978. end;
  979. function Setoptimizecputype(const s:string;var a:tcputype):boolean;
  980. var
  981. t : tcputype;
  982. hs : string;
  983. begin
  984. result:=false;
  985. hs:=Upper(s);
  986. for t:=low(tcputype) to high(tcputype) do
  987. if cputypestr[t]=hs then
  988. begin
  989. a:=t;
  990. result:=true;
  991. break;
  992. end;
  993. end;
  994. function Setcputype(const s:string;var a:tsettings):boolean;
  995. var
  996. t : tcputype;
  997. hs : string;
  998. begin
  999. result:=false;
  1000. hs:=Upper(s);
  1001. for t:=low(tcputype) to high(tcputype) do
  1002. if cputypestr[t]=hs then
  1003. begin
  1004. a.cputype:=t;
  1005. result:=true;
  1006. break;
  1007. end;
  1008. {$ifdef arm}
  1009. { set default instruction set for arm }
  1010. if result then
  1011. begin
  1012. if a.cputype in [cpu_armv6m,cpu_armv6t2,cpu_armv7m,cpu_armv7em] then
  1013. a.instructionset:=is_thumb
  1014. else
  1015. a.instructionset:=is_arm;
  1016. end;
  1017. {$endif arm}
  1018. end;
  1019. function SetFpuType(const s:string;var a:tfputype):boolean;
  1020. var
  1021. t : tfputype;
  1022. begin
  1023. result:=false;
  1024. for t:=low(tfputype) to high(tfputype) do
  1025. if fputypestr[t]=s then
  1026. begin
  1027. a:=t;
  1028. result:=true;
  1029. break;
  1030. end;
  1031. end;
  1032. function SetControllerType(const s:string;var a:tcontrollertype):boolean;
  1033. var
  1034. t : tcontrollertype;
  1035. hs : string;
  1036. begin
  1037. { The following check allows to reduce amount of code for platforms }
  1038. { not supporting microcontrollers due to evaluation at compile time. }
  1039. {$PUSH}
  1040. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  1041. if ControllerSupport then
  1042. begin
  1043. result:=false;
  1044. hs:=Upper(s);
  1045. for t:=low(tcontrollertype) to high(tcontrollertype) do
  1046. if embedded_controllers[t].controllertypestr=hs then
  1047. begin
  1048. a:=t;
  1049. result:=true;
  1050. break;
  1051. end;
  1052. end
  1053. else
  1054. begin
  1055. a := ct_none;
  1056. Result := true;
  1057. end;
  1058. {$POP}
  1059. end;
  1060. function IncludeFeature(const s : string) : boolean;
  1061. var
  1062. i : tfeature;
  1063. begin
  1064. result:=true;
  1065. for i:=low(tfeature) to high(tfeature) do
  1066. if s=featurestr[i] then
  1067. begin
  1068. include(features,i);
  1069. exit;
  1070. end;
  1071. result:=false;
  1072. end;
  1073. function SetMinFPConstPrec(const s: string; var a: tfloattype) : boolean;
  1074. var
  1075. value, error: longint;
  1076. begin
  1077. if (upper(s)='DEFAULT') then
  1078. begin
  1079. a:=s32real;
  1080. result:=true;
  1081. exit;
  1082. end;
  1083. result:=false;
  1084. val(s,value,error);
  1085. if (error<>0) then
  1086. exit;
  1087. case value of
  1088. 32: a:=s32real;
  1089. 64: a:=s64real;
  1090. { adding support for 80 bit here is tricky, since we can't really }
  1091. { check whether the target cpu+OS actually supports it }
  1092. else
  1093. exit;
  1094. end;
  1095. result:=true;
  1096. end;
  1097. function var_align(want_align: longint): shortint;
  1098. begin
  1099. var_align := used_align(want_align,current_settings.alignment.varalignmin,current_settings.alignment.varalignmax);
  1100. end;
  1101. function var_align_size(siz: longint): shortint;
  1102. begin
  1103. siz := size_2_align(siz);
  1104. var_align_size := var_align(siz);
  1105. end;
  1106. function const_align(want_align: longint): shortint;
  1107. begin
  1108. const_align := used_align(want_align,current_settings.alignment.constalignmin,current_settings.alignment.constalignmax);
  1109. end;
  1110. function const_align_size(siz: longint): shortint;
  1111. begin
  1112. siz := size_2_align(siz);
  1113. const_align_size := const_align(siz);
  1114. end;
  1115. {$ifdef ARM}
  1116. function is_double_hilo_swapped: boolean;{$ifdef USEINLINE}inline;{$endif}
  1117. begin
  1118. result := (current_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  1119. not(cs_fp_emulation in current_settings.moduleswitches);
  1120. {$ifdef FPC_DOUBLE_HILO_SWAPPED}
  1121. { inverse result if compiler was compiled with swapped hilo already }
  1122. result := not result;
  1123. {$endif FPC_DOUBLE_HILO_SWAPPED}
  1124. end;
  1125. {$endif ARM}
  1126. function floating_point_range_check_error : boolean;
  1127. begin
  1128. result:=cs_ieee_errors in current_settings.localswitches;
  1129. end;
  1130. function use_dotted_functions: boolean;
  1131. begin
  1132. result:=
  1133. (target_info.system in systems_dotted_function_names) and
  1134. (target_info.abi<>abi_powerpc_elfv2);
  1135. end;
  1136. {****************************************************************************
  1137. Init
  1138. ****************************************************************************}
  1139. {$ifdef unix}
  1140. {$define need_path_search}
  1141. {$endif unix}
  1142. {$ifdef os2}
  1143. {$define need_path_search}
  1144. {$endif os2}
  1145. {$ifdef macos}
  1146. {$define need_path_search}
  1147. {$endif macos}
  1148. procedure get_exepath;
  1149. var
  1150. localExepath : TCmdStr;
  1151. exeName:TCmdStr;
  1152. {$ifdef need_path_search}
  1153. hs1 : TPathStr;
  1154. {$endif need_path_search}
  1155. begin
  1156. localexepath:=GetEnvironmentVariable('PPC_EXEC_PATH');
  1157. exeName := '';
  1158. if localexepath='' then
  1159. begin
  1160. exeName := FixFileName(system.paramstr(0));
  1161. localexepath := ExtractFilePath(exeName);
  1162. end;
  1163. {$ifdef need_path_search}
  1164. if localexepath='' then
  1165. begin
  1166. hs1 := ExtractFileName(exeName);
  1167. ChangeFileExt(hs1,source_info.exeext);
  1168. {$ifdef macos}
  1169. FindFile(hs1,GetEnvironmentVariable('Commands'),false,localExepath);
  1170. {$else macos}
  1171. FindFile(hs1,GetEnvironmentVariable('PATH'),false,localExepath);
  1172. {$endif macos}
  1173. localExepath:=ExtractFilePath(localExepath);
  1174. end;
  1175. {$endif need_path_search}
  1176. exepath:=FixPath(localExepath,false);
  1177. end;
  1178. procedure DoneGlobals;
  1179. begin
  1180. librarysearchpath.Free;
  1181. unitsearchpath.Free;
  1182. objectsearchpath.Free;
  1183. includesearchpath.Free;
  1184. frameworksearchpath.Free;
  1185. LinkLibraryAliases.Free;
  1186. LinkLibraryOrder.Free;
  1187. end;
  1188. procedure InitGlobals;
  1189. begin
  1190. get_exepath;
  1191. { reset globals }
  1192. do_build:=false;
  1193. do_release:=false;
  1194. do_make:=true;
  1195. compile_level:=0;
  1196. codegenerror:=false;
  1197. DLLsource:=false;
  1198. { Output }
  1199. OutputFileName:='';
  1200. OutputPrefix:=Nil;
  1201. OutputSuffix:=Nil;
  1202. OutputExeDir:='';
  1203. OutputUnitDir:='';
  1204. { Utils directory }
  1205. utilsdirectory:='';
  1206. utilsprefix:='';
  1207. cshared:=false;
  1208. rlinkpath:='';
  1209. sysrootpath:='';
  1210. { Search Paths }
  1211. unicodepath:='';
  1212. librarysearchpath:=TSearchPathList.Create;
  1213. unitsearchpath:=TSearchPathList.Create;
  1214. includesearchpath:=TSearchPathList.Create;
  1215. objectsearchpath:=TSearchPathList.Create;
  1216. frameworksearchpath:=TSearchPathList.Create;
  1217. { Def file }
  1218. usewindowapi:=false;
  1219. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1220. DescriptionSetExplicity:=false;
  1221. SetPEFlagsSetExplicity:=false;
  1222. SetPEOptFlagsSetExplicity:=false;
  1223. ImageBaseSetExplicity:=false;
  1224. MinStackSizeSetExplicity:=false;
  1225. MaxStackSizeSetExplicity:=false;
  1226. dllversion:='';
  1227. dllmajor:=1;
  1228. dllminor:=0;
  1229. dllrevision:=0;
  1230. nwscreenname := '';
  1231. nwthreadname := '';
  1232. nwcopyright := '';
  1233. UseDeffileForExports:=false;
  1234. UseDeffileForExportsSetExplicitly:=false;
  1235. GenerateImportSection:=false;
  1236. RelocSection:=false;
  1237. RelocSectionSetExplicitly:=false;
  1238. MacOSXVersionMin:='';
  1239. iPhoneOSVersionMin:='';
  1240. { memory sizes, will be overridden by parameter or default for target
  1241. in options or init_parser }
  1242. stacksize:=0;
  1243. { not initialized yet }
  1244. apptype:=app_cui;
  1245. { Init values }
  1246. init_settings:=default_settings;
  1247. if init_settings.optimizecputype=cpu_none then
  1248. init_settings.optimizecputype:=init_settings.cputype;
  1249. LinkLibraryAliases :=TLinkStrMap.Create;
  1250. LinkLibraryOrder :=TLinkStrMap.Create;
  1251. { enable all features by default }
  1252. features:=[low(Tfeature)..high(Tfeature)];
  1253. end;
  1254. end.