globals.pas 42 KB

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