globals.pas 42 KB

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