globals.pas 41 KB

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