globals.pas 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  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. begin
  621. { Replace some macros }
  622. Replace(s,'$FPCVERSION',version_string);
  623. Replace(s,'$FPCFULLVERSION',full_version_string);
  624. Replace(s,'$FPCDATE',date_string);
  625. Replace(s,'$FPCCPU',target_cpu_string);
  626. Replace(s,'$FPCOS',target_os_string);
  627. if tf_use_8_3 in Source_Info.Flags then
  628. Replace(s,'$FPCTARGET',target_os_string)
  629. else
  630. Replace(s,'$FPCTARGET',target_full_string);
  631. end;
  632. {****************************************************************************
  633. OS Dependent things
  634. ****************************************************************************}
  635. function GetEnvPChar(const envname:string):pchar;
  636. {$ifdef win32}
  637. var
  638. s : string;
  639. i,len : longint;
  640. hp,p,p2 : pchar;
  641. {$endif}
  642. begin
  643. {$ifdef hasunix}
  644. GetEnvPchar:=BaseUnix.fpGetEnv(envname);
  645. {$define GETENVOK}
  646. {$endif}
  647. {$ifdef win32}
  648. GetEnvPchar:=nil;
  649. p:=GetEnvironmentStrings;
  650. hp:=p;
  651. while hp^<>#0 do
  652. begin
  653. s:=strpas(hp);
  654. i:=pos('=',s);
  655. len:=strlen(hp);
  656. if upper(copy(s,1,i-1))=upper(envname) then
  657. begin
  658. GetMem(p2,len-length(envname));
  659. Move(hp[i],p2^,len-length(envname));
  660. GetEnvPchar:=p2;
  661. break;
  662. end;
  663. { next string entry}
  664. hp:=hp+len+1;
  665. end;
  666. FreeEnvironmentStrings(p);
  667. {$define GETENVOK}
  668. {$endif}
  669. {$ifdef os2}
  670. GetEnvPChar := Dos.GetEnvPChar (EnvName);
  671. {$define GETENVOK}
  672. {$endif}
  673. {$ifdef GETENVOK}
  674. {$undef GETENVOK}
  675. {$else}
  676. GetEnvPchar:=StrPNew(GetEnvironmentVariable(envname));
  677. {$endif}
  678. end;
  679. procedure FreeEnvPChar(p:pchar);
  680. begin
  681. {$ifndef hasunix}
  682. {$ifndef os2}
  683. freemem(p);
  684. {$endif}
  685. {$endif}
  686. end;
  687. {$if defined(MORPHOS) or defined(AMIGA)}
  688. {$define AMIGASHELL}
  689. {$endif}
  690. function Shell(const command:ansistring): longint;
  691. { This is already defined in the linux.ppu for linux, need for the *
  692. expansion under linux }
  693. {$ifdef hasunix}
  694. begin
  695. result := Unix.fpsystem(command);
  696. end;
  697. {$else hasunix}
  698. {$ifdef amigashell}
  699. begin
  700. result := ExecuteProcess('',command);
  701. end;
  702. {$else amigashell}
  703. var
  704. comspec : string;
  705. begin
  706. comspec:=GetEnvironmentVariable('COMSPEC');
  707. result := ExecuteProcess(comspec,' /C '+command);
  708. end;
  709. {$endif amigashell}
  710. {$endif hasunix}
  711. {$UNDEF AMIGASHELL}
  712. function is_number_float(d : double) : boolean;
  713. var
  714. bytearray : array[0..7] of byte;
  715. begin
  716. move(d,bytearray,8);
  717. { only 1.1 save, 1.0.x will use always little endian }
  718. {$ifdef FPC_BIG_ENDIAN}
  719. result:=((bytearray[0] and $7f)<>$7f) or ((bytearray[1] and $f0)<>$f0);
  720. {$else FPC_BIG_ENDIAN}
  721. result:=((bytearray[7] and $7f)<>$7f) or ((bytearray[6] and $f0)<>$f0);
  722. {$endif FPC_BIG_ENDIAN}
  723. end;
  724. function get_real_sign(r: bestreal): longint;
  725. var
  726. p: pbyte;
  727. begin
  728. p := pbyte(@r);
  729. {$ifdef CPU_ARM}
  730. inc(p,4);
  731. {$else}
  732. {$ifdef FPC_LITTLE_ENDIAN}
  733. inc(p,sizeof(r)-1);
  734. {$endif}
  735. {$endif}
  736. if (p^ and $80) = 0 then
  737. result := 1
  738. else
  739. result := -1;
  740. end;
  741. function convertdoublerec(d : tdoublerec) : tdoublerec;{$ifdef USEINLINE}inline;{$endif}
  742. {$ifdef CPUARM}
  743. var
  744. i : longint;
  745. begin
  746. for i:=0 to 3 do
  747. begin
  748. result.bytes[i+4]:=d.bytes[i];
  749. result.bytes[i]:=d.bytes[i+4];
  750. end;
  751. {$else CPUARM}
  752. begin
  753. result:=d;
  754. {$endif CPUARM}
  755. end;
  756. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  757. function string2guid(const s: string; var GUID: TGUID): boolean;
  758. function ishexstr(const hs: string): boolean;
  759. var
  760. i: integer;
  761. begin
  762. ishexstr:=false;
  763. for i:=1 to Length(hs) do begin
  764. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  765. exit;
  766. end;
  767. ishexstr:=true;
  768. end;
  769. function hexstr2longint(const hexs: string): longint;
  770. var
  771. i: integer;
  772. rl: longint;
  773. begin
  774. rl:=0;
  775. for i:=1 to length(hexs) do begin
  776. rl:=rl shl 4;
  777. case hexs[i] of
  778. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  779. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  780. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  781. end
  782. end;
  783. hexstr2longint:=rl;
  784. end;
  785. var
  786. i: integer;
  787. begin
  788. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  789. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  790. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  791. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  792. ishexstr(copy(s,26,12)) then begin
  793. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  794. { these values are arealdy in the correct range (4 chars = word) }
  795. GUID.D2:=word(hexstr2longint(copy(s,11,4)));
  796. GUID.D3:=word(hexstr2longint(copy(s,16,4)));
  797. for i:=0 to 1 do
  798. GUID.D4[i]:=byte(hexstr2longint(copy(s,21+i*2,2)));
  799. for i:=2 to 7 do
  800. GUID.D4[i]:=byte(hexstr2longint(copy(s,22+i*2,2)));
  801. string2guid:=true;
  802. end
  803. else if (length(s)=0) then
  804. begin
  805. FillChar(GUID,SizeOf(GUID),0);
  806. string2guid:=true;
  807. end
  808. else
  809. string2guid:=false;
  810. end;
  811. function guid2string(const GUID: TGUID): string;
  812. begin
  813. guid2string:=
  814. '{'+hexstr(GUID.D1,8)+
  815. '-'+hexstr(GUID.D2,4)+
  816. '-'+hexstr(GUID.D3,4)+
  817. '-'+hexstr(GUID.D4[0],2)+hexstr(GUID.D4[1],2)+
  818. '-'+hexstr(GUID.D4[2],2)+hexstr(GUID.D4[3],2)+
  819. hexstr(GUID.D4[4],2)+hexstr(GUID.D4[5],2)+
  820. hexstr(GUID.D4[6],2)+hexstr(GUID.D4[7],2)+
  821. '}';
  822. end;
  823. function SetAktProcCall(const s:string; var a:tproccalloption):boolean;
  824. const
  825. DefProcCallName : array[tproccalloption] of string[12] = ('',
  826. 'CDECL',
  827. 'CPPDECL',
  828. 'FAR16',
  829. 'OLDFPCCALL',
  830. '', { internproc }
  831. '', { syscall }
  832. 'PASCAL',
  833. 'REGISTER',
  834. 'SAFECALL',
  835. 'STDCALL',
  836. 'SOFTFLOAT',
  837. 'MWPASCAL'
  838. );
  839. var
  840. t : tproccalloption;
  841. hs : string;
  842. begin
  843. result:=false;
  844. if (s = '') then
  845. exit;
  846. hs:=upper(s);
  847. if (hs = 'DEFAULT') then
  848. begin
  849. a := pocall_default;
  850. result := true;
  851. exit;
  852. end;
  853. for t:=low(tproccalloption) to high(tproccalloption) do
  854. if DefProcCallName[t]=hs then
  855. begin
  856. a:=t;
  857. result:=true;
  858. break;
  859. end;
  860. end;
  861. function Setabitype(const s:string;var a:tabi):boolean;
  862. var
  863. t : tabi;
  864. hs : string;
  865. begin
  866. result:=false;
  867. hs:=Upper(s);
  868. for t:=low(t) to high(t) do
  869. if abi2str[t]=hs then
  870. begin
  871. a:=t;
  872. result:=true;
  873. break;
  874. end;
  875. end;
  876. function Setcputype(const s:string;var a:tcputype):boolean;
  877. var
  878. t : tcputype;
  879. hs : string;
  880. begin
  881. result:=false;
  882. hs:=Upper(s);
  883. for t:=low(tcputype) to high(tcputype) do
  884. if cputypestr[t]=hs then
  885. begin
  886. a:=t;
  887. result:=true;
  888. break;
  889. end;
  890. end;
  891. function SetFpuType(const s:string;var a:tfputype):boolean;
  892. var
  893. t : tfputype;
  894. begin
  895. result:=false;
  896. for t:=low(tfputype) to high(tfputype) do
  897. if fputypestr[t]=s then
  898. begin
  899. a:=t;
  900. result:=true;
  901. break;
  902. end;
  903. end;
  904. {$if defined(arm) or defined(avr)}
  905. function SetControllerType(const s:string;var a:tcontrollertype):boolean;
  906. var
  907. t : tcontrollertype;
  908. hs : string;
  909. begin
  910. result:=false;
  911. hs:=Upper(s);
  912. for t:=low(tcontrollertype) to high(tcontrollertype) do
  913. if controllertypestr[t]=hs then
  914. begin
  915. a:=t;
  916. result:=true;
  917. break;
  918. end;
  919. end;
  920. {$endif defined(arm) or defined(avr)}
  921. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  922. var
  923. tok : string;
  924. vstr : string;
  925. l : longint;
  926. code : integer;
  927. b : talignmentinfo;
  928. begin
  929. UpdateAlignmentStr:=true;
  930. uppervar(s);
  931. fillchar(b,sizeof(b),0);
  932. repeat
  933. tok:=GetToken(s,'=');
  934. if tok='' then
  935. break;
  936. vstr:=GetToken(s,',');
  937. val(vstr,l,code);
  938. if tok='PROC' then
  939. b.procalign:=l
  940. else if tok='JUMP' then
  941. b.jumpalign:=l
  942. else if tok='LOOP' then
  943. b.loopalign:=l
  944. else if tok='CONSTMIN' then
  945. begin
  946. b.constalignmin:=l;
  947. if l>b.constalignmax then
  948. b.constalignmax:=l;
  949. end
  950. else if tok='CONSTMAX' then
  951. b.constalignmax:=l
  952. else if tok='VARMIN' then
  953. begin
  954. b.varalignmin:=l;
  955. if l>b.varalignmax then
  956. b.varalignmax:=l;
  957. end
  958. else if tok='VARMAX' then
  959. b.varalignmax:=l
  960. else if tok='LOCALMIN' then
  961. begin
  962. b.localalignmin:=l;
  963. if l>b.localalignmax then
  964. b.localalignmax:=l;
  965. end
  966. else if tok='LOCALMAX' then
  967. b.localalignmax:=l
  968. else if tok='RECORDMIN' then
  969. begin
  970. b.recordalignmin:=l;
  971. if l>b.recordalignmax then
  972. b.recordalignmax:=l;
  973. end
  974. else if tok='RECORDMAX' then
  975. b.recordalignmax:=l
  976. else { Error }
  977. UpdateAlignmentStr:=false;
  978. until false;
  979. UpdateAlignment(a,b);
  980. end;
  981. function UpdateOptimizerStr(s:string;var a:toptimizerswitches):boolean;
  982. var
  983. tok : string;
  984. doset,
  985. found : boolean;
  986. opt : toptimizerswitch;
  987. begin
  988. result:=true;
  989. uppervar(s);
  990. repeat
  991. tok:=GetToken(s,',');
  992. if tok='' then
  993. break;
  994. if Copy(tok,1,2)='NO' then
  995. begin
  996. delete(tok,1,2);
  997. doset:=false;
  998. end
  999. else
  1000. doset:=true;
  1001. found:=false;
  1002. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  1003. begin
  1004. if OptimizerSwitchStr[opt]=tok then
  1005. begin
  1006. found:=true;
  1007. break;
  1008. end;
  1009. end;
  1010. if found then
  1011. begin
  1012. if doset then
  1013. include(a,opt)
  1014. else
  1015. exclude(a,opt);
  1016. end
  1017. else
  1018. result:=false;
  1019. until false;
  1020. end;
  1021. function UpdateWpoStr(s: string; var a: twpoptimizerswitches): boolean;
  1022. var
  1023. tok : string;
  1024. doset,
  1025. found : boolean;
  1026. opt : twpoptimizerswitch;
  1027. begin
  1028. result:=true;
  1029. uppervar(s);
  1030. repeat
  1031. tok:=GetToken(s,',');
  1032. if tok='' then
  1033. break;
  1034. if Copy(tok,1,2)='NO' then
  1035. begin
  1036. delete(tok,1,2);
  1037. doset:=false;
  1038. end
  1039. else
  1040. doset:=true;
  1041. found:=false;
  1042. if (tok = 'ALL') then
  1043. begin
  1044. for opt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  1045. if doset then
  1046. include(a,opt)
  1047. else
  1048. exclude(a,opt);
  1049. end
  1050. else
  1051. begin
  1052. for opt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  1053. begin
  1054. if WPOptimizerSwitchStr[opt]=tok then
  1055. begin
  1056. found:=true;
  1057. break;
  1058. end;
  1059. end;
  1060. if found then
  1061. begin
  1062. if doset then
  1063. include(a,opt)
  1064. else
  1065. exclude(a,opt);
  1066. end
  1067. else
  1068. result:=false;
  1069. end;
  1070. until false;
  1071. end;
  1072. function UpdateDebugStr(s:string;var a:tdebugswitches):boolean;
  1073. var
  1074. tok : string;
  1075. doset,
  1076. found : boolean;
  1077. opt : tdebugswitch;
  1078. begin
  1079. result:=true;
  1080. uppervar(s);
  1081. repeat
  1082. tok:=GetToken(s,',');
  1083. if tok='' then
  1084. break;
  1085. if Copy(tok,1,2)='NO' then
  1086. begin
  1087. delete(tok,1,2);
  1088. doset:=false;
  1089. end
  1090. else
  1091. doset:=true;
  1092. found:=false;
  1093. for opt:=low(tdebugswitch) to high(tdebugswitch) do
  1094. begin
  1095. if DebugSwitchStr[opt]=tok then
  1096. begin
  1097. found:=true;
  1098. break;
  1099. end;
  1100. end;
  1101. if found then
  1102. begin
  1103. if doset then
  1104. include(a,opt)
  1105. else
  1106. exclude(a,opt);
  1107. end
  1108. else
  1109. result:=false;
  1110. until false;
  1111. end;
  1112. function IncludeFeature(const s : string) : boolean;
  1113. var
  1114. i : tfeature;
  1115. begin
  1116. result:=true;
  1117. for i:=low(tfeature) to high(tfeature) do
  1118. if s=featurestr[i] then
  1119. begin
  1120. include(features,i);
  1121. exit;
  1122. end;
  1123. result:=false;
  1124. end;
  1125. function SetMinFPConstPrec(const s: string; var a: tfloattype) : boolean;
  1126. var
  1127. value, error: longint;
  1128. begin
  1129. if (upper(s)='DEFAULT') then
  1130. begin
  1131. a:=s32real;
  1132. result:=true;
  1133. exit;
  1134. end;
  1135. result:=false;
  1136. val(s,value,error);
  1137. if (error<>0) then
  1138. exit;
  1139. case value of
  1140. 32: a:=s32real;
  1141. 64: a:=s64real;
  1142. { adding support for 80 bit here is tricky, since we can't really }
  1143. { check whether the target cpu+OS actually supports it }
  1144. else
  1145. exit;
  1146. end;
  1147. result:=true;
  1148. end;
  1149. function var_align(want_align: longint): shortint;
  1150. begin
  1151. var_align := used_align(want_align,current_settings.alignment.varalignmin,current_settings.alignment.varalignmax);
  1152. end;
  1153. function var_align_size(siz: longint): shortint;
  1154. begin
  1155. siz := size_2_align(siz);
  1156. var_align_size := var_align(siz);
  1157. end;
  1158. function const_align(want_align: longint): shortint;
  1159. begin
  1160. const_align := used_align(want_align,current_settings.alignment.constalignmin,current_settings.alignment.constalignmax);
  1161. end;
  1162. function const_align_size(siz: longint): shortint;
  1163. begin
  1164. siz := size_2_align(siz);
  1165. const_align_size := const_align(siz);
  1166. end;
  1167. {$ifdef ARM}
  1168. function is_double_hilo_swapped: boolean;{$ifdef USEINLINE}inline;{$endif}
  1169. begin
  1170. result := (current_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  1171. not(cs_fp_emulation in current_settings.moduleswitches);
  1172. {$ifdef FPC_DOUBLE_HILO_SWAPPED}
  1173. { inverse result if compiler was compiled with swapped hilo already }
  1174. result := not result;
  1175. {$endif FPC_DOUBLE_HILO_SWAPPED}
  1176. end;
  1177. {$endif ARM}
  1178. function floating_point_range_check_error : boolean;
  1179. begin
  1180. result:=cs_ieee_errors in current_settings.localswitches;
  1181. end;
  1182. {****************************************************************************
  1183. Init
  1184. ****************************************************************************}
  1185. {$ifdef unix}
  1186. {$define need_path_search}
  1187. {$endif unix}
  1188. {$ifdef os2}
  1189. {$define need_path_search}
  1190. {$endif os2}
  1191. {$ifdef macos}
  1192. {$define need_path_search}
  1193. {$endif macos}
  1194. procedure get_exepath;
  1195. var
  1196. localExepath : TCmdStr;
  1197. exeName:TCmdStr;
  1198. {$ifdef need_path_search}
  1199. hs1 : TPathStr;
  1200. {$endif need_path_search}
  1201. begin
  1202. localexepath:=GetEnvironmentVariable('PPC_EXEC_PATH');
  1203. if localexepath='' then
  1204. begin
  1205. exeName := FixFileName(system.paramstr(0));
  1206. localexepath := ExtractFilePath(exeName);
  1207. end;
  1208. {$ifdef need_path_search}
  1209. if localexepath='' then
  1210. begin
  1211. hs1 := ExtractFileName(exeName);
  1212. ChangeFileExt(hs1,source_info.exeext);
  1213. {$ifdef macos}
  1214. FindFile(hs1,GetEnvironmentVariable('Commands'),false,localExepath);
  1215. {$else macos}
  1216. FindFile(hs1,GetEnvironmentVariable('PATH'),false,localExepath);
  1217. {$endif macos}
  1218. localExepath:=ExtractFilePath(localExepath);
  1219. end;
  1220. {$endif need_path_search}
  1221. exepath:=FixPath(localExepath,false);
  1222. end;
  1223. procedure DoneGlobals;
  1224. begin
  1225. librarysearchpath.Free;
  1226. unitsearchpath.Free;
  1227. objectsearchpath.Free;
  1228. includesearchpath.Free;
  1229. frameworksearchpath.Free;
  1230. LinkLibraryAliases.Free;
  1231. LinkLibraryOrder.Free;
  1232. end;
  1233. procedure InitGlobals;
  1234. begin
  1235. get_exepath;
  1236. { reset globals }
  1237. do_build:=false;
  1238. do_release:=false;
  1239. do_make:=true;
  1240. compile_level:=0;
  1241. codegenerror:=false;
  1242. DLLsource:=false;
  1243. paratarget:=system_none;
  1244. paratargetasm:=as_none;
  1245. paratargetdbg:=dbg_none;
  1246. { Output }
  1247. OutputFileName:='';
  1248. OutputPrefix:=Nil;
  1249. OutputSuffix:=Nil;
  1250. OutputExeDir:='';
  1251. OutputUnitDir:='';
  1252. { Utils directory }
  1253. utilsdirectory:='';
  1254. utilsprefix:='';
  1255. cshared:=false;
  1256. rlinkpath:='';
  1257. sysrootpath:='';
  1258. { Search Paths }
  1259. librarysearchpath:=TSearchPathList.Create;
  1260. unitsearchpath:=TSearchPathList.Create;
  1261. includesearchpath:=TSearchPathList.Create;
  1262. objectsearchpath:=TSearchPathList.Create;
  1263. frameworksearchpath:=TSearchPathList.Create;
  1264. { Def file }
  1265. usewindowapi:=false;
  1266. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1267. DescriptionSetExplicity:=false;
  1268. SetPEFlagsSetExplicity:=false;
  1269. ImageBaseSetExplicity:=false;
  1270. MinStackSizeSetExplicity:=false;
  1271. MaxStackSizeSetExplicity:=false;
  1272. dllversion:='';
  1273. dllmajor:=1;
  1274. dllminor:=0;
  1275. dllrevision:=0;
  1276. nwscreenname := '';
  1277. nwthreadname := '';
  1278. nwcopyright := '';
  1279. UseDeffileForExports:=false;
  1280. UseDeffileForExportsSetExplicitly:=false;
  1281. GenerateImportSection:=false;
  1282. RelocSection:=false;
  1283. RelocSectionSetExplicitly:=false;
  1284. LinkTypeSetExplicitly:=false;
  1285. { memory sizes, will be overridden by parameter or default for target
  1286. in options or init_parser }
  1287. stacksize:=0;
  1288. { not initialized yet }
  1289. jmp_buf_size:=-1;
  1290. apptype:=app_cui;
  1291. { Init values }
  1292. init_settings:=default_settings;
  1293. if init_settings.optimizecputype=cpu_none then
  1294. init_settings.optimizecputype:=init_settings.cputype;
  1295. LinkLibraryAliases :=TLinkStrMap.Create;
  1296. LinkLibraryOrder :=TLinkStrMap.Create;
  1297. { enable all features by default }
  1298. features:=[low(Tfeature)..high(Tfeature)];
  1299. end;
  1300. end.