globals.pas 45 KB

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