globals.pas 42 KB

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