globals.pas 41 KB

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