globals.pas 42 KB

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