globals.pas 42 KB

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