globals.pas 42 KB

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