globals.pas 43 KB

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