globals.pas 42 KB

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