globals.pas 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements some support functions and global variables
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit globals;
  19. {$i fpcdefs.inc}
  20. { Use the internal linker by default }
  21. { define INTERNALLINKER}
  22. interface
  23. uses
  24. {$ifdef win32}
  25. windows,
  26. {$endif}
  27. {$ifdef unix}
  28. {$ifdef ver1_0}
  29. linux,
  30. {$else}
  31. unix,
  32. {$endif}
  33. {$endif}
  34. {$ifdef os2}
  35. doscalls,
  36. {$endif}
  37. {$ifdef Delphi}
  38. SysUtils,
  39. dmisc,
  40. {$else}
  41. strings,
  42. dos,
  43. {$endif}
  44. cutils,cclasses,
  45. globtype,version,systems,cpuinfo;
  46. const
  47. {$ifdef Splitheap}
  48. testsplit : boolean = false;
  49. {$endif Splitheap}
  50. delphimodeswitches : tmodeswitches=
  51. [m_delphi,m_all,m_class,m_objpas,m_result,m_string_pchar,
  52. m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
  53. m_out,m_default_para,m_hintdirective,m_duplicate_names];
  54. fpcmodeswitches : tmodeswitches=
  55. [m_fpc,m_all,m_string_pchar,m_nested_comment,m_repeat_forward,
  56. m_cvar_support,m_initfinal,m_add_pointer];
  57. objfpcmodeswitches : tmodeswitches=
  58. [m_objfpc,m_fpc,m_all,m_class,m_objpas,m_result,m_string_pchar,m_nested_comment,
  59. m_repeat_forward,m_cvar_support,m_initfinal,m_add_pointer,m_out,m_default_para];
  60. tpmodeswitches : tmodeswitches=
  61. [m_tp7,m_all,m_tp_procvar,m_duplicate_names];
  62. gpcmodeswitches : tmodeswitches=
  63. [m_gpc,m_all];
  64. type
  65. pfileposinfo = ^tfileposinfo;
  66. tfileposinfo = record
  67. line : longint;
  68. column : word;
  69. fileindex : word;
  70. { moduleindex : word; }
  71. end;
  72. TSearchPathList = class(TStringList)
  73. procedure AddPath(s:string;addfirst:boolean);
  74. procedure AddPath(SrcPath,s:string;addfirst:boolean);
  75. procedure AddList(list:TSearchPathList;addfirst:boolean);
  76. function FindFile(const f : string;var foundfile:string):boolean;
  77. end;
  78. tcodepagestring = string[20];
  79. { the ordinal type used when evaluating constant integer expressions }
  80. TConstExprInt = int64;
  81. { ... the same unsigned }
  82. TConstExprUInt = {$ifdef fpc}qword{$else}int64{$endif};
  83. var
  84. { specified inputfile }
  85. inputdir : dirstr;
  86. inputfile : namestr;
  87. inputextension : extstr;
  88. { specified outputfile with -o parameter }
  89. outputfile : namestr;
  90. { specified with -FE or -FU }
  91. outputexedir : dirstr;
  92. outputunitdir : dirstr;
  93. { things specified with parameters }
  94. paralinkoptions,
  95. paradynamiclinker : string;
  96. parapreprocess : boolean;
  97. { directory where the utils can be found (options -FD) }
  98. utilsdirectory : dirstr;
  99. { some flags for global compiler switches }
  100. do_build,
  101. do_release,
  102. do_make : boolean;
  103. not_unit_proc : boolean;
  104. { path for searching units, different paths can be seperated by ; }
  105. exepath : dirstr; { Path to ppc }
  106. librarysearchpath,
  107. unitsearchpath,
  108. objectsearchpath,
  109. includesearchpath : TSearchPathList;
  110. { deffile }
  111. usewindowapi : boolean;
  112. description : string;
  113. dllversion : string;
  114. dllmajor,dllminor,dllrevision : word; { revision only for netware }
  115. akttokenpos, { position of the last token }
  116. aktfilepos : tfileposinfo; { current position }
  117. { ad 18.05.2001: Screen and Threadname for Netware }
  118. nwscreenname : string;
  119. nwthreadname : string;
  120. nwcopyright : string;
  121. block_type : tblock_type; { type of currently parsed block }
  122. in_args : boolean; { arguments must be checked especially }
  123. parsing_para_level : integer; { parameter level, used to convert
  124. proc calls to proc loads in firstcalln }
  125. compile_level : word;
  126. make_ref : boolean;
  127. resolving_forward : boolean; { used to add forward reference as second ref }
  128. use_esp_stackframe : boolean; { to test for call with ESP as stack frame }
  129. inlining_procedure : boolean; { are we inlining a procedure }
  130. statement_level : integer;
  131. exceptblockcounter : integer; { each except block gets a unique number check gotos }
  132. aktexceptblock : integer; { the exceptblock number of the current block (0 if none) }
  133. have_local_threadvars : boolean; { set if a table of local threadvars-tables is present and has to be initialized }
  134. { commandline values }
  135. initdefines : tstringlist;
  136. initglobalswitches : tglobalswitches;
  137. initmoduleswitches : tmoduleswitches;
  138. initlocalswitches : tlocalswitches;
  139. initmodeswitches : tmodeswitches;
  140. {$IFDEF testvarsets}
  141. Initsetalloc, {0=fixed, 1 =var}
  142. {$ENDIF}
  143. initpackenum : longint;
  144. initalignment : talignmentinfo;
  145. initoptprocessor,
  146. initspecificoptprocessor : tprocessors;
  147. initasmmode : tasmmode;
  148. initinterfacetype : tinterfacetypes;
  149. initoutputformat : tasm;
  150. initdefproccall : tproccalloption;
  151. initsourcecodepage : tcodepagestring;
  152. { current state values }
  153. aktglobalswitches : tglobalswitches;
  154. aktmoduleswitches : tmoduleswitches;
  155. aktlocalswitches : tlocalswitches;
  156. nextaktlocalswitches : tlocalswitches;
  157. localswitcheschanged : boolean;
  158. aktmodeswitches : tmodeswitches;
  159. {$IFDEF testvarsets}
  160. aktsetalloc,
  161. {$ENDIF}
  162. aktpackenum : longint;
  163. aktmaxfpuregisters : longint;
  164. aktalignment : talignmentinfo;
  165. aktoptprocessor,
  166. aktspecificoptprocessor : tprocessors;
  167. aktasmmode : tasmmode;
  168. aktinterfacetype : tinterfacetypes;
  169. aktoutputformat : tasm;
  170. aktdefproccall : tproccalloption;
  171. aktsourcecodepage : tcodepagestring;
  172. { Memory sizes }
  173. heapsize,
  174. stacksize : longint;
  175. {$Ifdef EXTDEBUG}
  176. { parameter switches }
  177. debugstop : boolean;
  178. {$EndIf EXTDEBUG}
  179. { windows / OS/2 application type }
  180. apptype : tapptype;
  181. const
  182. RelocSection : boolean = true;
  183. RelocSectionSetExplicitly : boolean = false;
  184. LinkTypeSetExplicitly : boolean = false;
  185. DLLsource : boolean = false;
  186. DLLImageBase : pstring = nil;
  187. UseDeffileForExport : boolean = true;
  188. ForceDeffileForExport : boolean = false;
  189. { used to set all registers used for each global function
  190. this should dramatically decrease the number of
  191. recompilations needed PM }
  192. simplify_ppu : boolean = true;
  193. { should we allow non static members ? }
  194. allow_only_static : boolean = false;
  195. Inside_asm_statement : boolean = false;
  196. global_unit_count : word = 0;
  197. { for error info in pp.pas }
  198. parser_current_file : string = '';
  199. {$ifdef m68k}
  200. { PalmOS resources }
  201. palmos_applicationname : string = 'FPC Application';
  202. palmos_applicationid : string[4] = 'FPCA';
  203. {$endif m68k}
  204. procedure abstract;
  205. function bstoslash(const s : string) : string;
  206. function getdatestr:string;
  207. function gettimestr:string;
  208. function filetimestring( t : longint) : string;
  209. procedure DefaultReplacements(var s:string);
  210. function GetCurrentDir:string;
  211. function path_absolute(const s : string) : boolean;
  212. Function PathExists ( F : String) : Boolean;
  213. Function FileExists ( Const F : String) : Boolean;
  214. Function RemoveFile(const f:string):boolean;
  215. Function RemoveDir(d:string):boolean;
  216. Function GetFileTime ( Var F : File) : Longint;
  217. Function GetNamedFileTime ( Const F : String) : Longint;
  218. Function SplitPath(const s:string):string;
  219. Function SplitFileName(const s:string):string;
  220. Function SplitName(const s:string):string;
  221. Function SplitExtension(Const HStr:String):String;
  222. Function AddExtension(Const HStr,ext:String):String;
  223. Function ForceExtension(Const HStr,ext:String):String;
  224. Function FixPath(s:string;allowdot:boolean):string;
  225. function FixFileName(const s:string):string;
  226. function TargetFixPath(s:string;allowdot:boolean):string;
  227. function TargetFixFileName(const s:string):string;
  228. procedure SplitBinCmd(const s:string;var bstr,cstr:string);
  229. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  230. function FindExe(const bin:string;var foundfile:string):boolean;
  231. function GetShortName(const n:string):string;
  232. Procedure Shell(const command:string);
  233. function GetEnvPChar(const envname:string):pchar;
  234. procedure FreeEnvPChar(p:pchar);
  235. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  236. function SetAktProcCall(const s:string; changeInit: boolean):boolean;
  237. procedure InitGlobals;
  238. procedure DoneGlobals;
  239. function string2guid(const s: string; var GUID: TGUID): boolean;
  240. function guid2string(const GUID: TGUID): string;
  241. procedure swap_qword(var q : qword);
  242. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  243. {# Routine to get the required alignment for size of data, which will
  244. be placed in bss segment, according to the current alignment requirements }
  245. function var_align(siz: longint): longint;
  246. {# Routine to get the required alignment for size of data, which will
  247. be placed in data/const segment, according to the current alignment requirements }
  248. function const_align(siz: longint): longint;
  249. implementation
  250. uses
  251. comphook;
  252. procedure abstract;
  253. begin
  254. do_internalerror(255);
  255. end;
  256. procedure WarnNonExistingPath(const path : string);
  257. begin
  258. if assigned({$ifndef FPCPROCVAR}@{$endif}do_comment) then
  259. do_comment(V_Hint,'Path "'+path+'" not found');
  260. end;
  261. function bstoslash(const s : string) : string;
  262. {
  263. return string s with all \ changed into /
  264. }
  265. var
  266. i : longint;
  267. begin
  268. for i:=1to length(s) do
  269. if s[i]='\' then
  270. bstoslash[i]:='/'
  271. else
  272. bstoslash[i]:=s[i];
  273. bstoslash[0]:=s[0];
  274. end;
  275. {****************************************************************************
  276. Time Handling
  277. ****************************************************************************}
  278. Function L0(l:longint):string;
  279. {
  280. return the string of value l, if l<10 then insert a zero, so
  281. the string is always at least 2 chars '01','02',etc
  282. }
  283. var
  284. s : string;
  285. begin
  286. Str(l,s);
  287. if l<10 then
  288. s:='0'+s;
  289. L0:=s;
  290. end;
  291. function gettimestr:string;
  292. {
  293. get the current time in a string HH:MM:SS
  294. }
  295. var
  296. hour,min,sec,hsec : word;
  297. begin
  298. {$ifdef delphi}
  299. dmisc.gettime(hour,min,sec,hsec);
  300. {$else delphi}
  301. dos.gettime(hour,min,sec,hsec);
  302. {$endif delphi}
  303. gettimestr:=L0(Hour)+':'+L0(min)+':'+L0(sec);
  304. end;
  305. function getdatestr:string;
  306. {
  307. get the current date in a string YY/MM/DD
  308. }
  309. var
  310. Year,Month,Day,Wday : Word;
  311. begin
  312. {$ifdef delphi}
  313. dmisc.getdate(year,month,day,wday);
  314. {$else}
  315. dos.getdate(year,month,day,wday);
  316. {$endif}
  317. getdatestr:=L0(Year)+'/'+L0(Month)+'/'+L0(Day);
  318. end;
  319. function filetimestring( t : longint) : string;
  320. {
  321. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  322. }
  323. var
  324. DT : DateTime;
  325. begin
  326. if t=-1 then
  327. begin
  328. FileTimeString:='Not Found';
  329. exit;
  330. end;
  331. unpacktime(t,DT);
  332. filetimestring:=L0(dt.Year)+'/'+L0(dt.Month)+'/'+L0(dt.Day)+' '+L0(dt.Hour)+':'+L0(dt.min)+':'+L0(dt.sec);
  333. end;
  334. {****************************************************************************
  335. Default Macro Handling
  336. ****************************************************************************}
  337. procedure DefaultReplacements(var s:string);
  338. begin
  339. { Replace some macro's }
  340. Replace(s,'$FPCVER',version_string);
  341. Replace(s,'$VERSION',version_string);
  342. Replace(s,'$FULLVERSION',full_version_string);
  343. Replace(s,'$FPCDATE',date_string);
  344. Replace(s,'$FPCTARGET',target_cpu_string);
  345. Replace(s,'$FPCCPU',target_cpu_string);
  346. Replace(s,'$TARGET',target_path);
  347. Replace(s,'$FPCOS',target_path);
  348. end;
  349. {****************************************************************************
  350. File Handling
  351. ****************************************************************************}
  352. function GetCurrentDir:string;
  353. var
  354. CurrentDir : string;
  355. begin
  356. GetDir(0,CurrentDir);
  357. GetCurrentDir:=FixPath(CurrentDir,false);
  358. end;
  359. function path_absolute(const s : string) : boolean;
  360. {
  361. is path s an absolute path?
  362. }
  363. begin
  364. path_absolute:=false;
  365. {$ifdef unix}
  366. if (length(s)>0) and (s[1]='/') then
  367. path_absolute:=true;
  368. {$else unix}
  369. {$ifdef amiga}
  370. if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or (Pos(':',s) = length(s)) then
  371. path_absolute:=true;
  372. {$else}
  373. if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or
  374. ((length(s)>2) and (s[2]=':') and ((s[3]='\') or (s[3]='/'))) then
  375. path_absolute:=true;
  376. {$endif amiga}
  377. {$endif unix}
  378. end;
  379. {$ifndef FPC}
  380. Procedure FindClose(var Info : SearchRec);
  381. Begin
  382. End;
  383. {$endif not FPC}
  384. Function FileExists ( Const F : String) : Boolean;
  385. Var
  386. res : boolean;
  387. {$ifndef delphi}
  388. Info : SearchRec;
  389. {$endif}
  390. begin
  391. {$ifdef delphi}
  392. res:=sysutils.FileExists(f);
  393. {$else}
  394. findfirst(F,readonly+archive+hidden,info);
  395. res:=(doserror=0);
  396. findclose(Info);
  397. {$endif delphi}
  398. if assigned({$ifndef FPCPROVCAR}@{$endif}do_comment) then
  399. begin
  400. if res then
  401. do_comment(V_Tried,'Searching file '+F+'... found')
  402. else
  403. do_comment(V_Tried,'Searching file '+F+'... not found');
  404. end;
  405. FileExists:=res;
  406. end;
  407. Function PathExists ( F : String) : Boolean;
  408. Var
  409. Info : SearchRec;
  410. {$ifdef i386}
  411. disk : byte;
  412. {$endif i386}
  413. begin
  414. {$ifdef i386}
  415. if (Length(f)=3) and (F[2]=':') and (F[3] in ['/','\']) then
  416. begin
  417. if F[1] in ['A'..'Z'] then
  418. disk:=ord(F[1])-ord('A')+1
  419. else if F[1] in ['a'..'z'] then
  420. disk:=ord(F[1])-ord('a')+1
  421. else
  422. disk:=255;
  423. if disk=255 then
  424. PathExists:=false
  425. else
  426. PathExists:=(DiskSize(disk)<>-1);
  427. exit;
  428. end;
  429. {$endif i386}
  430. if F[Length(f)] in ['/','\'] then
  431. Delete(f,length(f),1);
  432. findfirst(F,readonly+archive+hidden+directory,info);
  433. PathExists:=(doserror=0) and ((info.attr and directory)=directory);
  434. findclose(Info);
  435. end;
  436. Function RemoveFile(const f:string):boolean;
  437. var
  438. g : file;
  439. begin
  440. assign(g,f);
  441. {$I-}
  442. erase(g);
  443. {$I+}
  444. RemoveFile:=(ioresult=0);
  445. end;
  446. Function RemoveDir(d:string):boolean;
  447. begin
  448. if d[length(d)]=source_info.DirSep then
  449. Delete(d,length(d),1);
  450. {$I-}
  451. rmdir(d);
  452. {$I+}
  453. RemoveDir:=(ioresult=0);
  454. end;
  455. Function SplitPath(const s:string):string;
  456. var
  457. i : longint;
  458. begin
  459. i:=Length(s);
  460. while (i>0) and not(s[i] in ['/','\']) do
  461. dec(i);
  462. SplitPath:=Copy(s,1,i);
  463. end;
  464. Function SplitFileName(const s:string):string;
  465. var
  466. p : dirstr;
  467. n : namestr;
  468. e : extstr;
  469. begin
  470. FSplit(s,p,n,e);
  471. SplitFileName:=n+e;
  472. end;
  473. Function SplitName(const s:string):string;
  474. var
  475. i,j : longint;
  476. begin
  477. i:=Length(s);
  478. j:=Length(s);
  479. while (i>0) and not(s[i] in ['/','\']) do
  480. dec(i);
  481. while (j>0) and (s[j]<>'.') do
  482. dec(j);
  483. if j<=i then
  484. j:=255;
  485. SplitName:=Copy(s,i+1,j-(i+1));
  486. end;
  487. Function SplitExtension(Const HStr:String):String;
  488. var
  489. j : longint;
  490. begin
  491. j:=length(Hstr);
  492. while (j>0) and (Hstr[j]<>'.') do
  493. begin
  494. if hstr[j]=source_info.DirSep then
  495. j:=0
  496. else
  497. dec(j);
  498. end;
  499. if j=0 then
  500. j:=254;
  501. SplitExtension:=Copy(Hstr,j,255);
  502. end;
  503. Function AddExtension(Const HStr,ext:String):String;
  504. begin
  505. if (Ext<>'') and (SplitExtension(HStr)='') then
  506. AddExtension:=Hstr+Ext
  507. else
  508. AddExtension:=Hstr;
  509. end;
  510. Function ForceExtension(Const HStr,ext:String):String;
  511. var
  512. j : longint;
  513. begin
  514. j:=length(Hstr);
  515. while (j>0) and (Hstr[j]<>'.') do
  516. dec(j);
  517. if j=0 then
  518. j:=255;
  519. ForceExtension:=Copy(Hstr,1,j-1)+Ext;
  520. end;
  521. Function FixPath(s:string;allowdot:boolean):string;
  522. var
  523. i : longint;
  524. begin
  525. { Fix separator }
  526. for i:=1 to length(s) do
  527. if s[i] in ['/','\'] then
  528. s[i]:=source_info.DirSep;
  529. { Fix ending / }
  530. if (length(s)>0) and (s[length(s)]<>source_info.DirSep) and
  531. (s[length(s)]<>':') then
  532. s:=s+source_info.DirSep;
  533. { Remove ./ }
  534. if (not allowdot) and (s='.'+source_info.DirSep) then
  535. s:='';
  536. { return }
  537. if source_info.files_case_relevent then
  538. FixPath:=s
  539. else
  540. FixPath:=Lower(s);
  541. end;
  542. function FixFileName(const s:string):string;
  543. var
  544. i : longint;
  545. begin
  546. if source_info.files_case_relevent then
  547. begin
  548. for i:=1 to length(s) do
  549. begin
  550. case s[i] of
  551. '/','\' :
  552. FixFileName[i]:=source_info.dirsep;
  553. else
  554. FixFileName[i]:=s[i];
  555. end;
  556. end;
  557. end
  558. else
  559. begin
  560. for i:=1 to length(s) do
  561. begin
  562. case s[i] of
  563. '/','\' :
  564. FixFileName[i]:=source_info.dirsep;
  565. 'A'..'Z' :
  566. FixFileName[i]:=char(byte(s[i])+32);
  567. else
  568. FixFileName[i]:=s[i];
  569. end;
  570. end;
  571. end;
  572. FixFileName[0]:=s[0];
  573. end;
  574. Function TargetFixPath(s:string;allowdot:boolean):string;
  575. var
  576. i : longint;
  577. begin
  578. { Fix separator }
  579. for i:=1 to length(s) do
  580. if s[i] in ['/','\'] then
  581. s[i]:=target_info.DirSep;
  582. { Fix ending / }
  583. if (length(s)>0) and (s[length(s)]<>target_info.DirSep) and
  584. (s[length(s)]<>':') then
  585. s:=s+target_info.DirSep;
  586. { Remove ./ }
  587. if (not allowdot) and (s='.'+target_info.DirSep) then
  588. s:='';
  589. { return }
  590. if target_info.files_case_relevent then
  591. TargetFixPath:=s
  592. else
  593. TargetFixPath:=Lower(s);
  594. end;
  595. function TargetFixFileName(const s:string):string;
  596. var
  597. i : longint;
  598. begin
  599. if target_info.files_case_relevent then
  600. begin
  601. for i:=1 to length(s) do
  602. begin
  603. case s[i] of
  604. '/','\' :
  605. TargetFixFileName[i]:=target_info.dirsep;
  606. else
  607. TargetFixFileName[i]:=s[i];
  608. end;
  609. end;
  610. end
  611. else
  612. begin
  613. for i:=1 to length(s) do
  614. begin
  615. case s[i] of
  616. '/','\' :
  617. TargetFixFileName[i]:=target_info.dirsep;
  618. 'A'..'Z' :
  619. TargetFixFileName[i]:=char(byte(s[i])+32);
  620. else
  621. TargetFixFileName[i]:=s[i];
  622. end;
  623. end;
  624. end;
  625. TargetFixFileName[0]:=s[0];
  626. end;
  627. procedure SplitBinCmd(const s:string;var bstr,cstr:string);
  628. var
  629. i : longint;
  630. begin
  631. i:=pos(' ',s);
  632. if i>0 then
  633. begin
  634. bstr:=Copy(s,1,i-1);
  635. cstr:=Copy(s,i+1,length(s)-i);
  636. end
  637. else
  638. begin
  639. bstr:=s;
  640. cstr:='';
  641. end;
  642. end;
  643. procedure TSearchPathList.AddPath(s:string;addfirst:boolean);
  644. begin
  645. AddPath('',s,AddFirst);
  646. end;
  647. procedure TSearchPathList.AddPath(SrcPath,s:string;addfirst:boolean);
  648. var
  649. j : longint;
  650. hs,hsd,
  651. CurrentDir,
  652. CurrPath : string;
  653. subdirfound : boolean;
  654. dir : searchrec;
  655. hp : TStringListItem;
  656. procedure addcurrpath;
  657. begin
  658. if addfirst then
  659. begin
  660. Remove(currPath);
  661. Insert(currPath);
  662. end
  663. else
  664. begin
  665. { Check if already in path, then we don't add it }
  666. hp:=Find(currPath);
  667. if not assigned(hp) then
  668. Concat(currPath);
  669. end;
  670. end;
  671. begin
  672. if s='' then
  673. exit;
  674. { Support default macro's }
  675. DefaultReplacements(s);
  676. { get current dir }
  677. CurrentDir:=GetCurrentDir;
  678. repeat
  679. { get currpath }
  680. if addfirst then
  681. begin
  682. j:=length(s);
  683. while (j>0) and (s[j]<>';') do
  684. dec(j);
  685. CurrPath:=FixPath(Copy(s,j+1,length(s)-j),false);
  686. if j=0 then
  687. s:=''
  688. else
  689. System.Delete(s,j,length(s)-j+1);
  690. end
  691. else
  692. begin
  693. j:=Pos(';',s);
  694. if j=0 then
  695. j:=255;
  696. CurrPath:=SrcPath+FixPath(Copy(s,1,j-1),false);
  697. System.Delete(s,1,j);
  698. end;
  699. { fix pathname }
  700. if CurrPath='' then
  701. CurrPath:='.'+source_info.DirSep
  702. else
  703. begin
  704. CurrPath:=FixPath(FExpand(CurrPath),false);
  705. if (CurrentDir<>'') and (Copy(CurrPath,1,length(CurrentDir))=CurrentDir) then
  706. CurrPath:='.'+source_info.DirSep+Copy(CurrPath,length(CurrentDir)+1,255);
  707. end;
  708. { wildcard adding ? }
  709. if pos('*',currpath)>0 then
  710. begin
  711. if currpath[length(currpath)]=source_info.dirsep then
  712. hs:=Copy(currpath,1,length(CurrPath)-1)
  713. else
  714. hs:=currpath;
  715. hsd:=SplitPath(hs);
  716. findfirst(hs,directory,dir);
  717. subdirfound:=false;
  718. while doserror=0 do
  719. begin
  720. if (dir.name<>'.') and
  721. (dir.name<>'..') and
  722. ((dir.attr and directory)<>0) then
  723. begin
  724. subdirfound:=true;
  725. currpath:=hsd+dir.name+source_info.dirsep;
  726. hp:=Find(currPath);
  727. if not assigned(hp) then
  728. AddCurrPath;
  729. end;
  730. findnext(dir);
  731. if not subdirfound then
  732. WarnNonExistingPath(currpath);
  733. end;
  734. FindClose(dir);
  735. end
  736. else
  737. begin
  738. if PathExists(currpath) then
  739. addcurrpath
  740. else
  741. WarnNonExistingPath(currpath);
  742. end;
  743. until (s='');
  744. end;
  745. procedure TSearchPathList.AddList(list:TSearchPathList;addfirst:boolean);
  746. var
  747. s : string;
  748. hl : TSearchPathList;
  749. hp,hp2 : TStringListItem;
  750. begin
  751. if list.empty then
  752. exit;
  753. { create temp and reverse the list }
  754. if addfirst then
  755. begin
  756. hl:=TSearchPathList.Create;
  757. hp:=TStringListItem(list.first);
  758. while assigned(hp) do
  759. begin
  760. hl.insert(hp.Str);
  761. hp:=TStringListItem(hp.next);
  762. end;
  763. while not hl.empty do
  764. begin
  765. s:=hl.GetFirst;
  766. Remove(s);
  767. Insert(s);
  768. end;
  769. hl.Free;
  770. end
  771. else
  772. begin
  773. hp:=TStringListItem(list.first);
  774. while assigned(hp) do
  775. begin
  776. hp2:=Find(hp.Str);
  777. { Check if already in path, then we don't add it }
  778. if not assigned(hp2) then
  779. Concat(hp.Str);
  780. hp:=TStringListItem(hp.next);
  781. end;
  782. end;
  783. end;
  784. function TSearchPathList.FindFile(const f : string;var foundfile:string):boolean;
  785. Var
  786. p : TStringListItem;
  787. begin
  788. FindFile:=false;
  789. p:=TStringListItem(first);
  790. while assigned(p) do
  791. begin
  792. {
  793. Search order for case sensitive systems:
  794. 1. lowercase
  795. 2. NormalCase
  796. 3. UPPERCASE
  797. None case sensitive only lowercase
  798. }
  799. FoundFile:=p.Str+Lower(f);
  800. If FileExists(FoundFile) then
  801. begin
  802. FindFile:=true;
  803. exit;
  804. end;
  805. {$ifdef UNIX}
  806. FoundFile:=p.Str+f;
  807. If FileExists(FoundFile) then
  808. begin
  809. FindFile:=true;
  810. exit;
  811. end;
  812. FoundFile:=p.Str+Upper(f);
  813. If FileExists(FoundFile) then
  814. begin
  815. FindFile:=true;
  816. exit;
  817. end;
  818. {$endif UNIX}
  819. p:=TStringListItem(p.next);
  820. end;
  821. { Return original filename if not found }
  822. FoundFile:=f;
  823. end;
  824. Function GetFileTime ( Var F : File) : Longint;
  825. Var
  826. {$ifdef unix}
  827. Info : Stat;
  828. {$endif}
  829. L : longint;
  830. begin
  831. {$ifdef unix}
  832. FStat (F,Info);
  833. L:=Info.Mtime;
  834. {$else}
  835. GetFTime(f,l);
  836. {$endif}
  837. GetFileTime:=L;
  838. end;
  839. Function GetNamedFileTime (Const F : String) : Longint;
  840. begin
  841. GetNamedFileTime:=do_getnamedfiletime(F);
  842. end;
  843. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  844. Var
  845. singlepathstring : string;
  846. i : longint;
  847. begin
  848. {$ifdef Unix}
  849. for i:=1 to length(path) do
  850. if path[i]=':' then
  851. path[i]:=';';
  852. {$endif Unix}
  853. FindFile:=false;
  854. repeat
  855. i:=pos(';',path);
  856. if i=0 then
  857. i:=256;
  858. singlepathstring:=FixPath(copy(path,1,i-1),false);
  859. delete(path,1,i);
  860. {
  861. Search order for case sensitive systems:
  862. 1. lowercase
  863. 2. NormalCase
  864. 3. UPPERCASE
  865. None case sensitive only lowercase
  866. }
  867. FoundFile:=singlepathstring+Lower(f);
  868. If FileExists(FoundFile) then
  869. begin
  870. FindFile:=true;
  871. exit;
  872. end;
  873. {$ifdef UNIX}
  874. FoundFile:=singlepathstring+f;
  875. If FileExists(FoundFile) then
  876. begin
  877. FindFile:=true;
  878. exit;
  879. end;
  880. FoundFile:=singlepathstring+Upper(f);
  881. If FileExists(FoundFile) then
  882. begin
  883. FindFile:=true;
  884. exit;
  885. end;
  886. {$endif UNIX}
  887. until path='';
  888. FoundFile:=f;
  889. end;
  890. function FindExe(const bin:string;var foundfile:string):boolean;
  891. begin
  892. {$ifdef delphi}
  893. FindExe:=FindFile(FixFileName(AddExtension(bin,source_info.exeext)),'.;'+exepath+';'+dmisc.getenv('PATH'),foundfile);
  894. {$else delphi}
  895. FindExe:=FindFile(FixFileName(AddExtension(bin,source_info.exeext)),'.;'+exepath+';'+dos.getenv('PATH'),foundfile);
  896. {$endif delphi}
  897. end;
  898. function GetShortName(const n:string):string;
  899. {$ifdef win32}
  900. var
  901. hs,hs2 : string;
  902. i : longint;
  903. {$endif}
  904. {$ifdef go32v2}
  905. var
  906. hs : string;
  907. {$endif}
  908. begin
  909. GetShortName:=n;
  910. {$ifdef win32}
  911. hs:=n+#0;
  912. i:=Windows.GetShortPathName(@hs[1],@hs2[1],high(hs2));
  913. if (i>0) and (i<=high(hs2)) then
  914. begin
  915. hs2[0]:=chr(strlen(@hs2[1]));
  916. GetShortName:=hs2;
  917. end;
  918. {$endif}
  919. {$ifdef go32v2}
  920. hs:=n;
  921. if Dos.GetShortName(hs) then
  922. GetShortName:=hs;
  923. {$endif}
  924. end;
  925. {****************************************************************************
  926. OS Dependent things
  927. ****************************************************************************}
  928. function GetEnvPChar(const envname:string):pchar;
  929. {$ifdef win32}
  930. var
  931. s : string;
  932. i,len : longint;
  933. hp,p,p2 : pchar;
  934. {$endif}
  935. {$ifdef os2}
  936. var
  937. P1, P2: PChar;
  938. {$endif}
  939. begin
  940. {$ifdef unix}
  941. GetEnvPchar:={$ifdef ver1_0}Linux{$else}Unix{$endif}.Getenv(envname);
  942. {$define GETENVOK}
  943. {$endif}
  944. {$ifdef win32}
  945. GetEnvPchar:=nil;
  946. p:=GetEnvironmentStrings;
  947. hp:=p;
  948. while hp^<>#0 do
  949. begin
  950. s:=strpas(hp);
  951. i:=pos('=',s);
  952. len:=strlen(hp);
  953. if upper(copy(s,1,i-1))=upper(envname) then
  954. begin
  955. GetMem(p2,len-length(envname));
  956. Move(hp[i],p2^,len-length(envname));
  957. GetEnvPchar:=p2;
  958. break;
  959. end;
  960. { next string entry}
  961. hp:=hp+len+1;
  962. end;
  963. FreeEnvironmentStrings(p);
  964. {$define GETENVOK}
  965. {$endif}
  966. {$ifdef os2}
  967. P1 := StrPNew (EnvName);
  968. if Assigned (P1) then
  969. begin
  970. if DosCalls.DosScanEnv (P1, P2) = 0 then
  971. GetEnvPChar := P2
  972. else
  973. GetEnvPChar := nil;
  974. StrDispose (P1);
  975. end else GetEnvPChar := nil;
  976. {$define GETENVOK}
  977. {$endif}
  978. {$ifdef GETENVOK}
  979. {$undef GETENVOK}
  980. {$else}
  981. GetEnvPchar:=StrPNew({$ifdef delphi}DMisc{$else}Dos{$endif}.Getenv(envname));
  982. {$endif}
  983. end;
  984. procedure FreeEnvPChar(p:pchar);
  985. begin
  986. {$ifndef unix}
  987. {$ifndef os2}
  988. StrDispose(p);
  989. {$endif}
  990. {$endif}
  991. end;
  992. Procedure Shell(const command:string);
  993. { This is already defined in the linux.ppu for linux, need for the *
  994. expansion under linux }
  995. {$ifdef unix}
  996. begin
  997. {$ifdef ver1_0}Linux{$else}Unix{$endif}.Shell(command);
  998. end;
  999. {$else}
  1000. var
  1001. comspec : string;
  1002. begin
  1003. comspec:=getenv('COMSPEC');
  1004. Exec(comspec,' /C '+command);
  1005. end;
  1006. {$endif}
  1007. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  1008. var
  1009. b : boolean;
  1010. begin
  1011. b:=true;
  1012. if s='DEFAULT' then
  1013. aktmodeswitches:=initmodeswitches
  1014. else
  1015. if s='DELPHI' then
  1016. aktmodeswitches:=delphimodeswitches
  1017. else
  1018. if s='TP' then
  1019. aktmodeswitches:=tpmodeswitches
  1020. else
  1021. if s='FPC' then
  1022. aktmodeswitches:=fpcmodeswitches
  1023. else
  1024. if s='OBJFPC' then
  1025. aktmodeswitches:=objfpcmodeswitches
  1026. else
  1027. if s='GPC' then
  1028. aktmodeswitches:=gpcmodeswitches
  1029. else
  1030. b:=false;
  1031. if b and changeInit then
  1032. initmodeswitches := aktmodeswitches;
  1033. if b then
  1034. begin
  1035. { turn ansistrings on by default ? }
  1036. if (m_delphi in aktmodeswitches) then
  1037. begin
  1038. include(aktlocalswitches,cs_ansistrings);
  1039. if changeinit then
  1040. include(initlocalswitches,cs_ansistrings);
  1041. end
  1042. else
  1043. begin
  1044. exclude(aktlocalswitches,cs_ansistrings);
  1045. if changeinit then
  1046. exclude(initlocalswitches,cs_ansistrings);
  1047. end;
  1048. { enum packing }
  1049. if (m_tp7 in aktmodeswitches) then
  1050. aktpackenum:=1
  1051. else
  1052. aktpackenum:=4;
  1053. if changeinit then
  1054. initpackenum:=aktpackenum;
  1055. end;
  1056. SetCompileMode:=b;
  1057. end;
  1058. function SetAktProcCall(const s:string; changeInit:boolean):boolean;
  1059. const
  1060. DefProcCallName : array[tproccalloption] of string[12] = ('',
  1061. 'CDECL',
  1062. 'CPPDECL',
  1063. '', { compilerproc }
  1064. 'FAR16',
  1065. 'FPCCALL',
  1066. 'INLINE',
  1067. '', { internproc }
  1068. '', { palmossyscall }
  1069. 'PASCAL',
  1070. 'REGISTER',
  1071. 'SAFECALL',
  1072. 'STDCALL',
  1073. 'SYSTEM'
  1074. );
  1075. var
  1076. t : tproccalloption;
  1077. begin
  1078. SetAktProcCall:=false;
  1079. for t:=low(tproccalloption) to high(tproccalloption) do
  1080. if DefProcCallName[t]=s then
  1081. begin
  1082. AktDefProcCall:=t;
  1083. SetAktProcCall:=true;
  1084. break;
  1085. end;
  1086. if changeinit then
  1087. InitDefProcCall:=AktDefProcCall;
  1088. end;
  1089. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  1090. function string2guid(const s: string; var GUID: TGUID): boolean;
  1091. function ishexstr(const hs: string): boolean;
  1092. var
  1093. i: integer;
  1094. begin
  1095. ishexstr:=false;
  1096. for i:=1 to Length(hs) do begin
  1097. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  1098. exit;
  1099. end;
  1100. ishexstr:=true;
  1101. end;
  1102. function hexstr2longint(const hexs: string): longint;
  1103. var
  1104. i: integer;
  1105. rl: longint;
  1106. begin
  1107. rl:=0;
  1108. for i:=1 to length(hexs) do begin
  1109. rl:=rl shl 4;
  1110. case hexs[i] of
  1111. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  1112. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  1113. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  1114. end
  1115. end;
  1116. hexstr2longint:=rl;
  1117. end;
  1118. var
  1119. i: integer;
  1120. begin
  1121. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  1122. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  1123. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  1124. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  1125. ishexstr(copy(s,26,12)) then begin
  1126. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  1127. GUID.D2:=hexstr2longint(copy(s,11,4));
  1128. GUID.D3:=hexstr2longint(copy(s,16,4));
  1129. for i:=0 to 1 do
  1130. GUID.D4[i]:=hexstr2longint(copy(s,21+i*2,2));
  1131. for i:=2 to 7 do
  1132. GUID.D4[i]:=hexstr2longint(copy(s,22+i*2,2));
  1133. string2guid:=true;
  1134. end
  1135. else
  1136. string2guid:=false;
  1137. end;
  1138. function guid2string(const GUID: TGUID): string;
  1139. function long2hex(l, len: longint): string;
  1140. const
  1141. hextbl: array[0..15] of char = '0123456789ABCDEF';
  1142. var
  1143. rs: string;
  1144. i: integer;
  1145. begin
  1146. rs[0]:=chr(len);
  1147. for i:=len downto 1 do begin
  1148. rs[i]:=hextbl[l and $F];
  1149. l:=l shr 4;
  1150. end;
  1151. long2hex:=rs;
  1152. end;
  1153. begin
  1154. guid2string:=
  1155. '{'+long2hex(GUID.D1,8)+
  1156. '-'+long2hex(GUID.D2,4)+
  1157. '-'+long2hex(GUID.D3,4)+
  1158. '-'+long2hex(GUID.D4[0],2)+long2hex(GUID.D4[1],2)+
  1159. '-'+long2hex(GUID.D4[2],2)+long2hex(GUID.D4[3],2)+
  1160. long2hex(GUID.D4[4],2)+long2hex(GUID.D4[5],2)+
  1161. long2hex(GUID.D4[6],2)+long2hex(GUID.D4[7],2)+
  1162. '}';
  1163. end;
  1164. procedure swap_qword(var q : qword);
  1165. begin
  1166. q:=(qword(lo(q)) shl 32) or hi(q);
  1167. end;
  1168. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  1169. var
  1170. tok : string;
  1171. vstr : string;
  1172. l : longint;
  1173. code : integer;
  1174. b : talignmentinfo;
  1175. begin
  1176. UpdateAlignmentStr:=true;
  1177. uppervar(s);
  1178. fillchar(b,sizeof(b),0);
  1179. repeat
  1180. tok:=GetToken(s,'=');
  1181. if tok='' then
  1182. break;
  1183. vstr:=GetToken(s,',');
  1184. val(vstr,l,code);
  1185. if tok='PROC' then
  1186. b.procalign:=l
  1187. else if tok='JUMP' then
  1188. b.jumpalign:=l
  1189. else if tok='LOOP' then
  1190. b.loopalign:=l
  1191. else if tok='CONSTMIN' then
  1192. b.constalignmin:=l
  1193. else if tok='CONSTMAX' then
  1194. b.constalignmax:=l
  1195. else if tok='VARMIN' then
  1196. b.varalignmin:=l
  1197. else if tok='VARMAX' then
  1198. b.varalignmax:=l
  1199. else if tok='LOCALMIN' then
  1200. b.localalignmin:=l
  1201. else if tok='LOCALMAX' then
  1202. b.localalignmax:=l
  1203. else if tok='RECORDMIN' then
  1204. b.recordalignmin:=l
  1205. else if tok='RECORDMAX' then
  1206. b.recordalignmax:=l
  1207. else if tok='PARAALIGN' then
  1208. b.paraalign:=l
  1209. else { Error }
  1210. UpdateAlignmentStr:=false;
  1211. until false;
  1212. UpdateAlignment(a,b);
  1213. end;
  1214. function var_align(siz: longint): longint;
  1215. begin
  1216. siz := size_2_align(siz);
  1217. var_align := used_align(siz,aktalignment.varalignmin,aktalignment.varalignmax);
  1218. end;
  1219. function const_align(siz: longint): longint;
  1220. begin
  1221. siz := size_2_align(siz);
  1222. const_align := used_align(siz,aktalignment.constalignmin,aktalignment.constalignmax);
  1223. end;
  1224. {****************************************************************************
  1225. Init
  1226. ****************************************************************************}
  1227. {$ifdef unix}
  1228. {$define need_path_search}
  1229. {$endif unix}
  1230. {$ifdef os2}
  1231. {$define need_path_search}
  1232. {$endif os2}
  1233. procedure get_exepath;
  1234. var
  1235. hs1 : namestr;
  1236. hs2 : extstr;
  1237. begin
  1238. {$ifdef delphi}
  1239. exepath:=dmisc.getenv('PPC_EXEC_PATH');
  1240. {$else delphi}
  1241. exepath:=dos.getenv('PPC_EXEC_PATH');
  1242. {$endif delphi}
  1243. if exepath='' then
  1244. fsplit(FixFileName(system.paramstr(0)),exepath,hs1,hs2);
  1245. {$ifdef need_path_search}
  1246. if exepath='' then
  1247. begin
  1248. if pos(source_info.exeext,hs1) <>
  1249. (length(hs1) - length(source_info.exeext)+1) then
  1250. hs1 := hs1 + source_info.exeext;
  1251. {$ifdef delphi}
  1252. findfile(hs1,dmisc.getenv('PATH'),exepath);
  1253. {$else delphi}
  1254. findfile(hs1,dos.getenv('PATH'),exepath);
  1255. {$endif delphi}
  1256. exepath:=SplitPath(exepath);
  1257. end;
  1258. {$endif need_path_search}
  1259. exepath:=FixPath(exepath,false);
  1260. end;
  1261. procedure DoneGlobals;
  1262. begin
  1263. initdefines.free;
  1264. if assigned(DLLImageBase) then
  1265. StringDispose(DLLImageBase);
  1266. RelocSection:=true;
  1267. RelocSectionSetExplicitly:=false;
  1268. UseDeffileForExport:=true;
  1269. librarysearchpath.Free;
  1270. unitsearchpath.Free;
  1271. objectsearchpath.Free;
  1272. includesearchpath.Free;
  1273. end;
  1274. procedure InitGlobals;
  1275. begin
  1276. get_exepath;
  1277. { reset globals }
  1278. do_build:=false;
  1279. do_release:=false;
  1280. do_make:=true;
  1281. compile_level:=0;
  1282. DLLsource:=false;
  1283. inlining_procedure:=false;
  1284. resolving_forward:=false;
  1285. in_args:=false;
  1286. make_ref:=false;
  1287. { Output }
  1288. OutputFile:='';
  1289. OutputExeDir:='';
  1290. OutputUnitDir:='';
  1291. { Utils directory }
  1292. utilsdirectory:='';
  1293. { Search Paths }
  1294. librarysearchpath:=TSearchPathList.Create;
  1295. unitsearchpath:=TSearchPathList.Create;
  1296. includesearchpath:=TSearchPathList.Create;
  1297. objectsearchpath:=TSearchPathList.Create;
  1298. { Def file }
  1299. usewindowapi:=false;
  1300. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1301. dllversion:='';
  1302. nwscreenname := '';
  1303. nwthreadname := '';
  1304. nwcopyright := '';
  1305. { Init values }
  1306. initmodeswitches:=fpcmodeswitches;
  1307. initlocalswitches:=[cs_check_io,cs_typed_const_writable];
  1308. initmoduleswitches:=[cs_extsyntax,cs_implicit_exceptions];
  1309. initsourcecodepage:='8859-1';
  1310. initglobalswitches:=[cs_check_unit_name,cs_link_static{$ifdef INTERNALLINKER},cs_link_internal,cs_link_map{$endif}];
  1311. initoutputformat:=target_asm.id;
  1312. fillchar(initalignment,sizeof(talignmentinfo),0);
  1313. {$ifdef i386}
  1314. initoptprocessor:=Class386;
  1315. initspecificoptprocessor:=Class386;
  1316. initpackenum:=4;
  1317. {$IFDEF testvarsets}
  1318. initsetalloc:=0;
  1319. {$ENDIF}
  1320. initasmmode:=asmmode_i386_att;
  1321. {$endif i386}
  1322. {$ifdef m68k}
  1323. initoptprocessor:=MC68020;
  1324. include(initmoduleswitches,cs_fp_emulation);
  1325. initpackenum:=4;
  1326. {$IFDEF testvarsets}
  1327. initsetalloc:=0;
  1328. {$ENDIF}
  1329. initasmmode:=asmmode_standard;
  1330. {$endif m68k}
  1331. {$ifdef powerpc}
  1332. initoptprocessor:=PPC604;
  1333. initpackenum:=4;
  1334. {$IFDEF testvarsets}
  1335. initsetalloc:=0;
  1336. {$ENDIF}
  1337. initasmmode:=asmmode_direct;
  1338. {$endif powerpc}
  1339. initinterfacetype:=it_interfacecom;
  1340. initdefproccall:=pocall_none;
  1341. initdefines:=TStringList.Create;
  1342. { memory sizes, will be overriden by parameter or default for target
  1343. in options or init_parser }
  1344. stacksize:=0;
  1345. heapsize:=0;
  1346. { compile state }
  1347. in_args:=false;
  1348. { must_be_valid:=true; obsolete PM }
  1349. not_unit_proc:=true;
  1350. apptype:=app_cui;
  1351. have_local_threadvars := false;
  1352. end;
  1353. end.
  1354. {
  1355. $Log$
  1356. Revision 1.71 2002-11-20 10:11:46 mazen
  1357. + TSearchPathList.AddPath supports a local path in addition to file name
  1358. Revision 1.70 2002/11/16 14:49:12 carl
  1359. - browser information is off by default
  1360. Revision 1.69 2002/11/15 01:58:47 peter
  1361. * merged changes from 1.0.7 up to 04-11
  1362. - -V option for generating bug report tracing
  1363. - more tracing for option parsing
  1364. - errors for cdecl and high()
  1365. - win32 import stabs
  1366. - win32 records<=8 are returned in eax:edx (turned off by default)
  1367. - heaptrc update
  1368. - more info for temp management in .s file with EXTDEBUG
  1369. Revision 1.68 2002/11/09 15:38:39 carl
  1370. + added var_align/const_align routines
  1371. Revision 1.67 2002/10/16 19:01:43 peter
  1372. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  1373. implicit exception frames for procedures with initialized variables
  1374. and for constructors. The default is on for compatibility
  1375. Revision 1.66 2002/09/05 19:28:29 peter
  1376. * removed repetitive pass counting
  1377. * display heapsize also for extdebug
  1378. Revision 1.65 2002/08/19 19:36:42 peter
  1379. * More fixes for cross unit inlining, all tnodes are now implemented
  1380. * Moved pocall_internconst to po_internconst because it is not a
  1381. calling type at all and it conflicted when inlining of these small
  1382. functions was requested
  1383. Revision 1.64 2002/08/12 15:08:39 carl
  1384. + stab register indexes for powerpc (moved from gdb to cpubase)
  1385. + tprocessor enumeration moved to cpuinfo
  1386. + linker in target_info is now a class
  1387. * many many updates for m68k (will soon start to compile)
  1388. - removed some ifdef or correct them for correct cpu
  1389. Revision 1.63 2002/08/10 14:46:29 carl
  1390. + moved target_cpu_string to cpuinfo
  1391. * renamed asmmode enum.
  1392. * assembler reader has now less ifdef's
  1393. * move from nppcmem.pas -> ncgmem.pas vec. node.
  1394. Revision 1.62 2002/07/28 20:45:22 florian
  1395. + added direct assembler reader for PowerPC
  1396. Revision 1.61 2002/07/20 17:12:42 florian
  1397. + source code page support
  1398. Revision 1.60 2002/07/01 18:46:22 peter
  1399. * internal linker
  1400. * reorganized aasm layer
  1401. Revision 1.59 2002/07/01 16:23:52 peter
  1402. * cg64 patch
  1403. * basics for currency
  1404. * asnode updates for class and interface (not finished)
  1405. Revision 1.58 2002/05/18 13:34:08 peter
  1406. * readded missing revisions
  1407. Revision 1.57 2002/05/16 19:46:36 carl
  1408. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1409. + try to fix temp allocation (still in ifdef)
  1410. + generic constructor calls
  1411. + start of tassembler / tmodulebase class cleanup
  1412. Revision 1.55 2002/04/20 21:32:23 carl
  1413. + generic FPC_CHECKPOINTER
  1414. + first parameter offset in stack now portable
  1415. * rename some constants
  1416. + move some cpu stuff to other units
  1417. - remove unused constents
  1418. * fix stacksize for some targets
  1419. * fix generic size problems which depend now on EXTEND_SIZE constant
  1420. Revision 1.54 2002/04/07 13:24:30 carl
  1421. + moved constant from cpuinfo, these are NOT cpu specific
  1422. constant, but more related to compiler functionality.
  1423. Revision 1.53 2002/04/02 17:11:28 peter
  1424. * tlocation,treference update
  1425. * LOC_CONSTANT added for better constant handling
  1426. * secondadd splitted in multiple routines
  1427. * location_force_reg added for loading a location to a register
  1428. of a specified size
  1429. * secondassignment parses now first the right and then the left node
  1430. (this is compatible with Kylix). This saves a lot of push/pop especially
  1431. with string operations
  1432. * adapted some routines to use the new cg methods
  1433. Revision 1.52 2002/03/28 16:07:52 armin
  1434. + initialize threadvars defined local in units
  1435. Revision 1.51 2002/01/24 18:25:48 peter
  1436. * implicit result variable generation for assembler routines
  1437. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1438. }