globals.pas 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217
  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 hasunix}
  28. {$ifdef havelinuxrtl10}
  29. linux,
  30. {$else}
  31. Baseunix,unix,
  32. {$endif}
  33. {$endif}
  34. {$IFDEF USE_SYSUTILS}
  35. SysUtils,
  36. {$ELSE USE_SYSUTILS}
  37. strings,
  38. dos,
  39. {$ENDIF USE_SYSUTILS}
  40. cutils,cclasses,
  41. globtype,version,systems,cpuinfo;
  42. const
  43. delphimodeswitches : tmodeswitches=
  44. [m_delphi,m_all,m_class,m_objpas,m_result,m_string_pchar,
  45. m_pointer_2_procedure,m_autoderef,m_tp_procvar,m_initfinal,m_default_ansistring,
  46. m_out,m_default_para,m_duplicate_names,m_hintdirective,m_add_pointer];
  47. fpcmodeswitches : tmodeswitches=
  48. [m_fpc,m_all,m_string_pchar,m_nested_comment,m_repeat_forward,
  49. m_cvar_support,m_initfinal,m_add_pointer,m_hintdirective];
  50. objfpcmodeswitches : tmodeswitches=
  51. [m_objfpc,m_fpc,m_all,m_class,m_objpas,m_result,m_string_pchar,m_nested_comment,
  52. m_repeat_forward,m_cvar_support,m_initfinal,m_add_pointer,m_out,m_default_para,m_hintdirective];
  53. tpmodeswitches : tmodeswitches=
  54. [m_tp7,m_all,m_tp_procvar,m_duplicate_names];
  55. gpcmodeswitches : tmodeswitches=
  56. [m_gpc,m_all];
  57. macmodeswitches : tmodeswitches=
  58. [m_mac,m_all,m_result,m_repeat_forward,m_cvar_support];
  59. { maximum number of locals in bytes before warning is emitted }
  60. maxlocalsize = high(smallint);
  61. { maximum number of paras in bytes before warning is emitted }
  62. maxparasize = high(word);
  63. { maximum nesting of routines }
  64. maxnesting = 32;
  65. treelogfilename = 'tree.log';
  66. { I don't know if this endian dependend }
  67. MathQNaN : array[0..7] of byte = (0,0,0,0,0,0,252,255);
  68. MathInf : array[0..7] of byte = (0,0,0,0,0,0,240,127);
  69. MathNegInf : array[0..7] of byte = (0,0,0,0,0,0,240,255);
  70. type
  71. TFPUException = (exInvalidOp, exDenormalized, exZeroDivide,
  72. exOverflow, exUnderflow, exPrecision);
  73. TFPUExceptionMask = set of TFPUException;
  74. pfileposinfo = ^tfileposinfo;
  75. tfileposinfo = record
  76. line : longint;
  77. column : word;
  78. fileindex : word;
  79. { moduleindex : word; }
  80. end;
  81. TSearchPathList = class(TStringList)
  82. procedure AddPath(s:string;addfirst:boolean);overload;
  83. procedure AddPath(SrcPath,s:string;addfirst:boolean);overload;
  84. procedure AddList(list:TSearchPathList;addfirst:boolean);
  85. function FindFile(const f : string;var foundfile:string):boolean;
  86. end;
  87. tcodepagestring = string[20];
  88. var
  89. { specified inputfile }
  90. inputdir : dirstr;
  91. inputfile : namestr;
  92. inputextension : extstr;
  93. { specified outputfile with -o parameter }
  94. outputfile : namestr;
  95. outputprefix : pstring;
  96. outputsuffix : pstring;
  97. outputextension : namestr;
  98. { specified with -FE or -FU }
  99. outputexedir : dirstr;
  100. outputunitdir : dirstr;
  101. { things specified with parameters }
  102. paralinkoptions,
  103. paradynamiclinker : string;
  104. paraprintnodetree : byte;
  105. parapreprocess : boolean;
  106. printnodefile : text;
  107. { typical cross compiling params}
  108. { directory where the utils can be found (options -FD) }
  109. utilsdirectory : dirstr;
  110. { targetname specific prefix used by these utils (options -XP<path>) }
  111. utilsprefix : dirstr;
  112. cshared : boolean; { pass --shared to ld to link C libs shared}
  113. Dontlinkstdlibpath: Boolean; { Don't add std paths to linkpath}
  114. rlinkpath : dirstr; { rpath-link linkdir override}
  115. { some flags for global compiler switches }
  116. do_build,
  117. do_release,
  118. do_make : boolean;
  119. { path for searching units, different paths can be seperated by ; }
  120. exepath : dirstr; { Path to ppc }
  121. librarysearchpath,
  122. unitsearchpath,
  123. objectsearchpath,
  124. includesearchpath : TSearchPathList;
  125. { linking }
  126. usewindowapi : boolean;
  127. description : string;
  128. DescriptionSetExplicity : boolean;
  129. dllversion : string;
  130. dllmajor,
  131. dllminor,
  132. dllrevision : word; { revision only for netware }
  133. UseDeffileForExports : boolean;
  134. UseDeffileForExportsSetExplicitly : boolean;
  135. RelocSection : boolean;
  136. RelocSectionSetExplicitly : boolean;
  137. LinkTypeSetExplicitly : boolean;
  138. akttokenpos, { position of the last token }
  139. aktfilepos : tfileposinfo; { current position }
  140. nwscreenname : string;
  141. nwthreadname : string;
  142. nwcopyright : string;
  143. codegenerror : boolean; { true if there is an error reported }
  144. block_type : tblock_type; { type of currently parsed block }
  145. parsing_para_level : integer; { parameter level, used to convert
  146. proc calls to proc loads in firstcalln }
  147. compile_level : word;
  148. make_ref : boolean;
  149. resolving_forward : boolean; { used to add forward reference as second ref }
  150. inlining_procedure : boolean; { are we inlining a procedure }
  151. exceptblockcounter : integer; { each except block gets a unique number check gotos }
  152. aktexceptblock : integer; { the exceptblock number of the current block (0 if none) }
  153. { commandline values }
  154. initdefines : tstringlist;
  155. initglobalswitches : tglobalswitches;
  156. initmoduleswitches : tmoduleswitches;
  157. initlocalswitches : tlocalswitches;
  158. initmodeswitches : tmodeswitches;
  159. {$IFDEF testvarsets}
  160. Initsetalloc, {0=fixed, 1 =var}
  161. {$ENDIF}
  162. initpackenum : shortint;
  163. {$ifdef ansistring_bits}
  164. initansistring_bits: Tstringbits;
  165. {$endif}
  166. initalignment : talignmentinfo;
  167. initoptprocessor,
  168. initspecificoptprocessor : tprocessors;
  169. initfputype : tfputype;
  170. initasmmode : tasmmode;
  171. initinterfacetype : tinterfacetypes;
  172. initoutputformat : tasm;
  173. initdefproccall : tproccalloption;
  174. initsourcecodepage : tcodepagestring;
  175. { current state values }
  176. aktglobalswitches : tglobalswitches;
  177. aktmoduleswitches : tmoduleswitches;
  178. aktlocalswitches : tlocalswitches;
  179. nextaktlocalswitches : tlocalswitches;
  180. localswitcheschanged : boolean;
  181. aktmodeswitches : tmodeswitches;
  182. {$IFDEF testvarsets}
  183. aktsetalloc,
  184. {$ENDIF}
  185. aktpackrecords,
  186. aktpackenum : longint;
  187. {$ifdef ansistring_bits}
  188. aktansistring_bits : Tstringbits;
  189. {$endif}
  190. aktmaxfpuregisters : longint;
  191. aktalignment : talignmentinfo;
  192. aktoptprocessor,
  193. aktspecificoptprocessor : tprocessors;
  194. aktfputype : tfputype;
  195. aktasmmode : tasmmode;
  196. aktinterfacetype : tinterfacetypes;
  197. aktoutputformat : tasm;
  198. aktdefproccall : tproccalloption;
  199. aktsourcecodepage : tcodepagestring;
  200. { Memory sizes }
  201. stacksize : longint;
  202. {$Ifdef EXTDEBUG}
  203. { parameter switches }
  204. debugstop : boolean;
  205. {$EndIf EXTDEBUG}
  206. { windows / OS/2 application type }
  207. apptype : tapptype;
  208. const
  209. DLLsource : boolean = false;
  210. DLLImageBase : pstring = nil;
  211. { used to set all registers used for each global function
  212. this should dramatically decrease the number of
  213. recompilations needed PM }
  214. simplify_ppu : boolean = true;
  215. { should we allow non static members ? }
  216. allow_only_static : boolean = false;
  217. Inside_asm_statement : boolean = false;
  218. global_unit_count : word = 0;
  219. { for error info in pp.pas }
  220. parser_current_file : string = '';
  221. {$ifdef m68k}
  222. { PalmOS resources }
  223. palmos_applicationname : string = 'FPC Application';
  224. palmos_applicationid : string[4] = 'FPCA';
  225. {$endif m68k}
  226. procedure abstract;
  227. function bstoslash(const s : string) : string;
  228. function getdatestr:string;
  229. function gettimestr:string;
  230. function filetimestring( t : longint) : string;
  231. procedure DefaultReplacements(var s:string);
  232. {Gives the absolute path to the current directory}
  233. function GetCurrentDir:string;
  234. {Gives the relative path to the current directory,
  235. with a trailing dir separator. E. g. on unix ./ }
  236. function CurDirRelPath(systeminfo: tsysteminfo): string;
  237. function path_absolute(const s : string) : boolean;
  238. Function PathExists ( F : String) : Boolean;
  239. Function FileExists ( Const F : String) : Boolean;
  240. function FileExistsNonCase(const path,fn:string;var foundfile:string):boolean;
  241. Function RemoveFile(const f:string):boolean;
  242. Function RemoveDir(d:string):boolean;
  243. Function GetFileTime ( Var F : File) : Longint;
  244. Function GetNamedFileTime ( Const F : String) : Longint;
  245. {Extracts the path without its filename, from a path.}
  246. Function SplitPath(const s:string):string;
  247. Function SplitFileName(const s:string):string;
  248. Function SplitName(const s:string):string;
  249. Function SplitExtension(Const HStr:String):String;
  250. Function AddExtension(Const HStr,ext:String):String;
  251. Function ForceExtension(Const HStr,ext:String):String;
  252. Function FixPath(s:string;allowdot:boolean):string;
  253. function FixFileName(const s:string):string;
  254. function TargetFixPath(s:string;allowdot:boolean):string;
  255. function TargetFixFileName(const s:string):string;
  256. procedure SplitBinCmd(const s:string;var bstr: String;var cstr:TCmdStr);
  257. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  258. function FindFilePchar(const f : string;path : pchar;var foundfile:string):boolean;
  259. function FindExe(const bin:string;var foundfile:string):boolean;
  260. function GetShortName(const n:string):string;
  261. function Shell(const command:string): longint;
  262. function GetEnvPChar(const envname:string):pchar;
  263. procedure FreeEnvPChar(p:pchar);
  264. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  265. function is_number_float(d : double) : boolean;
  266. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  267. function SetAktProcCall(const s:string; changeInit: boolean):boolean;
  268. function SetProcessor(const s:string; changeInit: boolean):boolean;
  269. function SetFpuType(const s:string; changeInit: boolean):boolean;
  270. procedure InitGlobals;
  271. procedure DoneGlobals;
  272. function string2guid(const s: string; var GUID: TGUID): boolean;
  273. function guid2string(const GUID: TGUID): string;
  274. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  275. {# Routine to get the required alignment for size of data, which will
  276. be placed in bss segment, according to the current alignment requirements }
  277. function var_align(siz: longint): longint;
  278. {# Routine to get the required alignment for size of data, which will
  279. be placed in data/const segment, according to the current alignment requirements }
  280. function const_align(siz: longint): longint;
  281. implementation
  282. uses
  283. {$ifdef macos}
  284. macutils,
  285. {$endif}
  286. comphook;
  287. procedure abstract;
  288. begin
  289. do_internalerror(255);
  290. end;
  291. procedure WarnNonExistingPath(const path : string);
  292. begin
  293. if assigned({$ifndef FPCPROCVAR}@{$endif}do_comment) then
  294. do_comment(V_Hint,'Path "'+path+'" not found');
  295. end;
  296. function bstoslash(const s : string) : string;
  297. {
  298. return string s with all \ changed into /
  299. }
  300. var
  301. i : longint;
  302. begin
  303. for i:=1to length(s) do
  304. if s[i]='\' then
  305. bstoslash[i]:='/'
  306. else
  307. bstoslash[i]:=s[i];
  308. bstoslash[0]:=s[0];
  309. end;
  310. {****************************************************************************
  311. Time Handling
  312. ****************************************************************************}
  313. Function L0(l:longint):string;
  314. {
  315. return the string of value l, if l<10 then insert a zero, so
  316. the string is always at least 2 chars '01','02',etc
  317. }
  318. var
  319. s : string;
  320. begin
  321. Str(l,s);
  322. if l<10 then
  323. s:='0'+s;
  324. L0:=s;
  325. end;
  326. function gettimestr:string;
  327. {
  328. get the current time in a string HH:MM:SS
  329. }
  330. var
  331. hour,min,sec,hsec : word;
  332. begin
  333. {$IFDEF USE_SYSUTILS}
  334. DecodeTime(Time,hour,min,sec,hsec);
  335. {$ELSE USE_SYSUTILS}
  336. dos.gettime(hour,min,sec,hsec);
  337. {$ENDIF USE_SYSUTILS}
  338. gettimestr:=L0(Hour)+':'+L0(min)+':'+L0(sec);
  339. end;
  340. function getdatestr:string;
  341. {
  342. get the current date in a string YY/MM/DD
  343. }
  344. var
  345. {$IFDEF USE_SYSUTILS}
  346. Year,Month,Day: Word;
  347. {$ELSE USE_SYSUTILS}
  348. Year,Month,Day,Wday : Word;
  349. {$ENDIF USE_SYSUTILS}
  350. begin
  351. {$IFDEF USE_SYSUTILS}
  352. DecodeDate(Date,year,month,day);
  353. {$ELSE USE_SYSUTILS}
  354. dos.getdate(year,month,day,wday);
  355. {$ENDIF USE_SYSUTILS}
  356. getdatestr:=L0(Year)+'/'+L0(Month)+'/'+L0(Day);
  357. end;
  358. function filetimestring( t : longint) : string;
  359. {
  360. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  361. }
  362. var
  363. {$IFDEF USE_SYSUTILS}
  364. DT : TDateTime;
  365. {$ELSE USE_SYSUTILS}
  366. DT : DateTime;
  367. {$ENDIF USE_SYSUTILS}
  368. Year,Month,Day: Word;
  369. hour,min,sec,hsec : word;
  370. begin
  371. if t=-1 then
  372. begin
  373. Result := 'Not Found';
  374. exit;
  375. end;
  376. {$IFDEF USE_SYSUTILS}
  377. DT := FileDateToDateTime(t);
  378. DecodeTime(DT,hour,min,sec,hsec);
  379. DecodeDate(DT,year,month,day);
  380. {$ELSE USE_SYSUTILS}
  381. unpacktime(t,DT);
  382. year := DT.year;
  383. month := DT.month;
  384. day := DT.day;
  385. hour := DT.hour;
  386. min := DT.min;
  387. sec := DT.sec;
  388. {$ENDIF USE_SYSUTILS}
  389. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  390. end;
  391. {****************************************************************************
  392. Default Macro Handling
  393. ****************************************************************************}
  394. procedure DefaultReplacements(var s:string);
  395. begin
  396. { Replace some macros }
  397. Replace(s,'$FPCVER',version_string);
  398. Replace(s,'$VERSION',version_string);
  399. Replace(s,'$FULLVERSION',full_version_string);
  400. Replace(s,'$FPCDATE',date_string);
  401. Replace(s,'$FPCTARGET',target_cpu_string);
  402. Replace(s,'$FPCCPU',target_cpu_string);
  403. Replace(s,'$TARGET',target_path);
  404. Replace(s,'$FPCOS',target_path);
  405. end;
  406. {****************************************************************************
  407. File Handling
  408. ****************************************************************************}
  409. var
  410. CachedCurrentDir : string;
  411. {Gives the absolute path to the current directory}
  412. function GetCurrentDir:string;
  413. begin
  414. if CachedCurrentDir='' then
  415. begin
  416. GetDir(0,CachedCurrentDir);
  417. CachedCurrentDir:=FixPath(CachedCurrentDir,false);
  418. end;
  419. result:=CachedCurrentDir;
  420. end;
  421. {Gives the relative path to the current directory,
  422. with a trailing dir separator. E. g. on unix ./ }
  423. function CurDirRelPath(systeminfo: tsysteminfo): string;
  424. begin
  425. if systeminfo.system <> system_powerpc_macos then
  426. CurDirRelPath:= '.'+systeminfo.DirSep
  427. else
  428. CurDirRelPath:= ':'
  429. end;
  430. function path_absolute(const s : string) : boolean;
  431. {
  432. is path s an absolute path?
  433. }
  434. begin
  435. path_absolute:=false;
  436. {$ifdef unix}
  437. if (length(s)>0) and (s[1]='/') then
  438. path_absolute:=true;
  439. {$else unix}
  440. {$ifdef amiga}
  441. if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or (Pos(':',s) = length(s)) then
  442. path_absolute:=true;
  443. {$else}
  444. {$ifdef macos}
  445. if IsMacFullPath(s) then
  446. path_absolute:=true;
  447. {$else}
  448. if ((length(s)>0) and ((s[1]='\') or (s[1]='/'))) or
  449. ((length(s)>2) and (s[2]=':') and ((s[3]='\') or (s[3]='/'))) then
  450. path_absolute:=true;
  451. {$endif macos}
  452. {$endif amiga}
  453. {$endif unix}
  454. end;
  455. {$ifndef FPC}
  456. Procedure FindClose(var Info : SearchRec);
  457. Begin
  458. End;
  459. {$endif not FPC}
  460. Function FileExists ( Const F : String) : Boolean;
  461. {$IFDEF USE_SYSUTILS}
  462. {$ELSE USE_SYSUTILS}
  463. var
  464. Info : SearchRec;
  465. {$ENDIF USE_SYSUTILS}
  466. begin
  467. {$IFDEF USE_SYSUTILS}
  468. Result:=SysUtils.FileExists(f);
  469. {$ELSE USE_SYSUTILS}
  470. findfirst(F,readonly+archive+hidden,info);
  471. result:=(doserror=0);
  472. findclose(Info);
  473. {$ENDIF USE_SYSUTILS}
  474. if assigned({$ifndef FPCPROVCAR}@{$endif}do_comment) then
  475. begin
  476. if Result then
  477. do_comment(V_Tried,'Searching file '+F+'... found')
  478. else
  479. do_comment(V_Tried,'Searching file '+F+'... not found');
  480. end;
  481. end;
  482. function FileExistsNonCase(const path,fn:string;var foundfile:string):boolean;
  483. var
  484. fn2 : string;
  485. begin
  486. result:=false;
  487. if source_info.files_case_relevent then
  488. begin
  489. {
  490. Search order for case sensitive systems:
  491. 1. NormalCase
  492. 2. lowercase
  493. 3. UPPERCASE
  494. }
  495. FoundFile:=path+fn;
  496. If FileExists(FoundFile) then
  497. begin
  498. result:=true;
  499. exit;
  500. end;
  501. fn2:=Lower(fn);
  502. if fn2<>fn then
  503. begin
  504. FoundFile:=path+fn2;
  505. If FileExists(FoundFile) then
  506. begin
  507. result:=true;
  508. exit;
  509. end;
  510. end;
  511. fn2:=Upper(fn);
  512. if fn2<>fn then
  513. begin
  514. FoundFile:=path+fn2;
  515. If FileExists(FoundFile) then
  516. begin
  517. result:=true;
  518. exit;
  519. end;
  520. end;
  521. end
  522. else
  523. begin
  524. { None case sensitive only lowercase }
  525. FoundFile:=path+Lower(fn);
  526. If FileExists(FoundFile) then
  527. begin
  528. result:=true;
  529. exit;
  530. end;
  531. end;
  532. { Set foundfile to something usefull }
  533. FoundFile:=fn;
  534. end;
  535. Function PathExists ( F : String) : Boolean;
  536. Var
  537. {$IFDEF USE_SYSUTILS}
  538. {$ELSE USE_SYSUTILS}
  539. FF : file;
  540. {$ENDIF USE_SYSUTILS}
  541. A: word;
  542. I: longint;
  543. begin
  544. if F = '' then
  545. begin
  546. PathExists := true;
  547. exit;
  548. end;
  549. F := FExpand (F);
  550. I := Pos (DriveSeparator, F);
  551. if (F [Length (F)] = DirectorySeparator)
  552. and (((I = 0) and (Length (F) > 1)) or (I <> Length (F) - 1))
  553. then
  554. Delete (F, Length (F), 1);
  555. {$IFDEF USE_SYSUTILS}
  556. PathExists := FileGetAttr(F) and faDirectory = faDirectory;
  557. {$ELSE USE_SYSUTILS}
  558. Assign (FF, FExpand (F));
  559. GetFAttr (FF, A);
  560. PathExists := (DosError = 0) and (A and Directory = Directory);
  561. {$ENDIF USE_SYSUTILS}
  562. end;
  563. Function RemoveFile(const f:string):boolean;
  564. var
  565. g : file;
  566. begin
  567. assign(g,f);
  568. {$I-}
  569. erase(g);
  570. {$I+}
  571. RemoveFile:=(ioresult=0);
  572. end;
  573. Function RemoveDir(d:string):boolean;
  574. begin
  575. if d[length(d)]=source_info.DirSep then
  576. Delete(d,length(d),1);
  577. {$I-}
  578. rmdir(d);
  579. {$I+}
  580. RemoveDir:=(ioresult=0);
  581. end;
  582. Function SplitPath(const s:string):string;
  583. var
  584. i : longint;
  585. begin
  586. i:=Length(s);
  587. {$ifdef macos}
  588. while (i>0) and not(s[i] in [':']) do
  589. dec(i);
  590. {$else macos}
  591. while (i>0) and not(s[i] in ['/','\']) do
  592. dec(i);
  593. {$endif macos}
  594. SplitPath:=Copy(s,1,i);
  595. end;
  596. Function SplitFileName(const s:string):string;
  597. {$IFDEF USE_SYSUTILS}
  598. {$ELSE USE_SYSUTILS}
  599. var
  600. p : dirstr;
  601. n : namestr;
  602. e : extstr;
  603. {$ENDIF USE_SYSUTILS}
  604. begin
  605. {$IFDEF USE_SYSUTILS}
  606. SplitFileName:=ExtractFileName(s);
  607. {$ELSE USE_SYSUTILS}
  608. FSplit(s,p,n,e);
  609. SplitFileName:=n+e;
  610. {$ENDIF USE_SYSUTILS}
  611. end;
  612. Function SplitName(const s:string):string;
  613. var
  614. i,j : longint;
  615. begin
  616. i:=Length(s);
  617. j:=Length(s);
  618. while (i>0) and not(s[i] in ['/','\']) do
  619. dec(i);
  620. while (j>0) and (s[j]<>'.') do
  621. dec(j);
  622. if j<=i then
  623. j:=255;
  624. SplitName:=Copy(s,i+1,j-(i+1));
  625. end;
  626. Function SplitExtension(Const HStr:String):String;
  627. var
  628. j : longint;
  629. begin
  630. j:=length(Hstr);
  631. while (j>0) and (Hstr[j]<>'.') do
  632. begin
  633. if hstr[j]=source_info.DirSep then
  634. j:=0
  635. else
  636. dec(j);
  637. end;
  638. if j=0 then
  639. j:=254;
  640. SplitExtension:=Copy(Hstr,j,255);
  641. end;
  642. Function AddExtension(Const HStr,ext:String):String;
  643. begin
  644. if (Ext<>'') and (SplitExtension(HStr)='') then
  645. AddExtension:=Hstr+Ext
  646. else
  647. AddExtension:=Hstr;
  648. end;
  649. Function ForceExtension(Const HStr,ext:String):String;
  650. var
  651. j : longint;
  652. begin
  653. j:=length(Hstr);
  654. while (j>0) and (Hstr[j]<>'.') do
  655. dec(j);
  656. if j=0 then
  657. j:=255;
  658. ForceExtension:=Copy(Hstr,1,j-1)+Ext;
  659. end;
  660. Function FixPath(s:string;allowdot:boolean):string;
  661. var
  662. i : longint;
  663. begin
  664. { Fix separator }
  665. for i:=1 to length(s) do
  666. if s[i] in ['/','\'] then
  667. s[i]:=source_info.DirSep;
  668. { Fix ending / }
  669. if (length(s)>0) and (s[length(s)]<>source_info.DirSep) and
  670. (s[length(s)]<>':') then
  671. s:=s+source_info.DirSep;
  672. { Remove ./ }
  673. if (not allowdot) and (s='.'+source_info.DirSep) then
  674. s:='';
  675. { return }
  676. if source_info.files_case_relevent then
  677. FixPath:=s
  678. else
  679. FixPath:=Lower(s);
  680. end;
  681. {Actually the version in macutils.pp could be used,
  682. but that would not work for crosscompiling, so this is a slightly modified
  683. version of it.}
  684. function TranslatePathToMac (const path: string; mpw: Boolean): string;
  685. function GetVolumeIdentifier: string;
  686. begin
  687. GetVolumeIdentifier := '{Boot}'
  688. (*
  689. if mpw then
  690. GetVolumeIdentifier := '{Boot}'
  691. else
  692. GetVolumeIdentifier := macosBootVolumeName;
  693. *)
  694. end;
  695. var
  696. slashPos, oldpos, newpos, oldlen, maxpos: Longint;
  697. begin
  698. oldpos := 1;
  699. slashPos := Pos('/', path);
  700. if (slashPos <> 0) then {its a unix path}
  701. begin
  702. if slashPos = 1 then
  703. begin {its a full path}
  704. oldpos := 2;
  705. TranslatePathToMac := GetVolumeIdentifier;
  706. end
  707. else {its a partial path}
  708. TranslatePathToMac := ':';
  709. end
  710. else
  711. begin
  712. slashPos := Pos('\', path);
  713. if (slashPos <> 0) then {its a dos path}
  714. begin
  715. if slashPos = 1 then
  716. begin {its a full path, without drive letter}
  717. oldpos := 2;
  718. TranslatePathToMac := GetVolumeIdentifier;
  719. end
  720. else if (Length(path) >= 2) and (path[2] = ':') then {its a full path, with drive letter}
  721. begin
  722. oldpos := 4;
  723. TranslatePathToMac := GetVolumeIdentifier;
  724. end
  725. else {its a partial path}
  726. TranslatePathToMac := ':';
  727. end;
  728. end;
  729. if (slashPos <> 0) then {its a unix or dos path}
  730. begin
  731. {Translate "/../" to "::" , "/./" to ":" and "/" to ":" }
  732. newpos := Length(TranslatePathToMac);
  733. oldlen := Length(path);
  734. SetLength(TranslatePathToMac, newpos + oldlen); {It will be no longer than what is already}
  735. {prepended plus length of path.}
  736. maxpos := Length(TranslatePathToMac); {Get real maxpos, can be short if String is ShortString}
  737. {There is never a slash in the beginning, because either it was an absolute path, and then the}
  738. {drive and slash was removed, or it was a relative path without a preceding slash.}
  739. while oldpos <= oldlen do
  740. begin
  741. {Check if special dirs, ./ or ../ }
  742. if path[oldPos] = '.' then
  743. if (oldpos + 1 <= oldlen) and (path[oldPos + 1] = '.') then
  744. begin
  745. if (oldpos + 2 > oldlen) or (path[oldPos + 2] in ['/', '\']) then
  746. begin
  747. {It is "../" or ".." translates to ":" }
  748. if newPos = maxPos then
  749. begin {Shouldn't actually happen, but..}
  750. Exit('');
  751. end;
  752. newPos := newPos + 1;
  753. TranslatePathToMac[newPos] := ':';
  754. oldPos := oldPos + 3;
  755. continue; {Start over again}
  756. end;
  757. end
  758. else if (oldpos + 1 > oldlen) or (path[oldPos + 1] in ['/', '\']) then
  759. begin
  760. {It is "./" or "." ignor it }
  761. oldPos := oldPos + 2;
  762. continue; {Start over again}
  763. end;
  764. {Collect file or dir name}
  765. while (oldpos <= oldlen) and not (path[oldPos] in ['/', '\']) do
  766. begin
  767. if newPos = maxPos then
  768. begin {Shouldn't actually happen, but..}
  769. Exit('');
  770. end;
  771. newPos := newPos + 1;
  772. TranslatePathToMac[newPos] := path[oldPos];
  773. oldPos := oldPos + 1;
  774. end;
  775. {When we come here there is either a slash or we are at the end.}
  776. if (oldpos <= oldlen) then
  777. begin
  778. if newPos = maxPos then
  779. begin {Shouldn't actually happen, but..}
  780. Exit('');
  781. end;
  782. newPos := newPos + 1;
  783. TranslatePathToMac[newPos] := ':';
  784. oldPos := oldPos + 1;
  785. end;
  786. end;
  787. SetLength(TranslatePathToMac, newpos);
  788. end
  789. else if (path = '.') then
  790. TranslatePathToMac := ':'
  791. else if (path = '..') then
  792. TranslatePathToMac := '::'
  793. else
  794. TranslatePathToMac := path; {its a mac path}
  795. end;
  796. function FixFileName(const s:string):string;
  797. var
  798. i : longint;
  799. begin
  800. if source_info.system = system_powerpc_MACOS then
  801. FixFileName:= TranslatePathToMac(s, true)
  802. else if source_info.files_case_relevent then
  803. begin
  804. for i:=1 to length(s) do
  805. begin
  806. case s[i] of
  807. '/','\' :
  808. FixFileName[i]:=source_info.dirsep;
  809. else
  810. FixFileName[i]:=s[i];
  811. end;
  812. end;
  813. FixFileName[0]:=s[0];
  814. end
  815. else
  816. begin
  817. for i:=1 to length(s) do
  818. begin
  819. case s[i] of
  820. '/','\' :
  821. FixFileName[i]:=source_info.dirsep;
  822. 'A'..'Z' :
  823. FixFileName[i]:=char(byte(s[i])+32);
  824. else
  825. FixFileName[i]:=s[i];
  826. end;
  827. end;
  828. FixFileName[0]:=s[0];
  829. end;
  830. end;
  831. Function TargetFixPath(s:string;allowdot:boolean):string;
  832. var
  833. i : longint;
  834. begin
  835. { Fix separator }
  836. for i:=1 to length(s) do
  837. if s[i] in ['/','\'] then
  838. s[i]:=target_info.DirSep;
  839. { Fix ending / }
  840. if (length(s)>0) and (s[length(s)]<>target_info.DirSep) and
  841. (s[length(s)]<>':') then
  842. s:=s+target_info.DirSep;
  843. { Remove ./ }
  844. if (not allowdot) and (s='.'+target_info.DirSep) then
  845. s:='';
  846. { return }
  847. if target_info.files_case_relevent then
  848. TargetFixPath:=s
  849. else
  850. TargetFixPath:=Lower(s);
  851. end;
  852. function TargetFixFileName(const s:string):string;
  853. var
  854. i : longint;
  855. begin
  856. if target_info.system = system_powerpc_MACOS then
  857. TargetFixFileName:= TranslatePathToMac(s, true)
  858. else if target_info.files_case_relevent then
  859. begin
  860. for i:=1 to length(s) do
  861. begin
  862. case s[i] of
  863. '/','\' :
  864. TargetFixFileName[i]:=target_info.dirsep;
  865. else
  866. TargetFixFileName[i]:=s[i];
  867. end;
  868. end;
  869. TargetFixFileName[0]:=s[0];
  870. end
  871. else
  872. begin
  873. for i:=1 to length(s) do
  874. begin
  875. case s[i] of
  876. '/','\' :
  877. TargetFixFileName[i]:=target_info.dirsep;
  878. 'A'..'Z' :
  879. TargetFixFileName[i]:=char(byte(s[i])+32);
  880. else
  881. TargetFixFileName[i]:=s[i];
  882. end;
  883. end;
  884. TargetFixFileName[0]:=s[0];
  885. end;
  886. end;
  887. procedure SplitBinCmd(const s:string;var bstr:String;var cstr:TCmdStr);
  888. var
  889. i : longint;
  890. begin
  891. i:=pos(' ',s);
  892. if i>0 then
  893. begin
  894. bstr:=Copy(s,1,i-1);
  895. cstr:=Copy(s,i+1,length(s)-i);
  896. end
  897. else
  898. begin
  899. bstr:=s;
  900. cstr:='';
  901. end;
  902. end;
  903. procedure TSearchPathList.AddPath(s:string;addfirst:boolean);
  904. begin
  905. AddPath('',s,AddFirst);
  906. end;
  907. procedure TSearchPathList.AddPath(SrcPath,s:string;addfirst:boolean);
  908. var
  909. j : longint;
  910. hs,hsd,
  911. CurrentDir,
  912. currPath : string;
  913. subdirfound : boolean;
  914. {$IFDEF USE_SYSUTILS}
  915. dir : TSearchRec;
  916. {$ELSE USE_SYSUTILS}
  917. dir : searchrec;
  918. {$ENDIF USE_SYSUTILS}
  919. hp : TStringListItem;
  920. procedure AddCurrPath;
  921. begin
  922. if addfirst then
  923. begin
  924. Remove(currPath);
  925. Insert(currPath);
  926. end
  927. else
  928. begin
  929. { Check if already in path, then we don't add it }
  930. hp:=Find(currPath);
  931. if not assigned(hp) then
  932. Concat(currPath);
  933. end;
  934. end;
  935. begin
  936. if s='' then
  937. exit;
  938. { Support default macro's }
  939. DefaultReplacements(s);
  940. { get current dir }
  941. CurrentDir:=GetCurrentDir;
  942. repeat
  943. { get currpath }
  944. if addfirst then
  945. begin
  946. j:=length(s);
  947. while (j>0) and (s[j]<>';') do
  948. dec(j);
  949. currPath:= TrimSpace(Copy(s,j+1,length(s)-j));
  950. DePascalQuote(currPath);
  951. currPath:=FixPath(currPath,false);
  952. if j=0 then
  953. s:=''
  954. else
  955. System.Delete(s,j,length(s)-j+1);
  956. end
  957. else
  958. begin
  959. j:=Pos(';',s);
  960. if j=0 then
  961. j:=255;
  962. currPath:= TrimSpace(Copy(s,1,j-1));
  963. DePascalQuote(currPath);
  964. currPath:=SrcPath+FixPath(currPath,false);
  965. System.Delete(s,1,j);
  966. end;
  967. { fix pathname }
  968. if currPath='' then
  969. currPath:= CurDirRelPath(source_info)
  970. else
  971. begin
  972. currPath:=FixPath(FExpand(currPath),false);
  973. if (CurrentDir<>'') and (Copy(currPath,1,length(CurrentDir))=CurrentDir) then
  974. begin
  975. {$ifdef AMIGA}
  976. currPath:= CurrentDir+Copy(currPath,length(CurrentDir)+1,255);
  977. {$else}
  978. currPath:= CurDirRelPath(source_info)+Copy(currPath,length(CurrentDir)+1,255);
  979. {$endif}
  980. end;
  981. end;
  982. { wildcard adding ? }
  983. if pos('*',currpath)>0 then
  984. begin
  985. if currpath[length(currpath)]=source_info.dirsep then
  986. hs:=Copy(currpath,1,length(currPath)-1)
  987. else
  988. hs:=currpath;
  989. hsd:=SplitPath(hs);
  990. subdirfound:=false;
  991. {$IFDEF USE_SYSUTILS}
  992. if findfirst(hs,faDirectory,dir) = 0
  993. then repeat
  994. if (dir.name<>'.') and
  995. (dir.name<>'..') and
  996. ((dir.attr and faDirectory)<>0) then
  997. begin
  998. subdirfound:=true;
  999. currpath:=hsd+dir.name+source_info.dirsep;
  1000. hp:=Find(currPath);
  1001. if not assigned(hp) then
  1002. AddCurrPath;
  1003. end;
  1004. if not subdirfound then
  1005. WarnNonExistingPath(currpath);
  1006. until findnext(dir) <> 0;
  1007. {$ELSE USE_SYSUTILS}
  1008. findfirst(hs,directory,dir);
  1009. while doserror=0 do
  1010. begin
  1011. if (dir.name<>'.') and
  1012. (dir.name<>'..') and
  1013. ((dir.attr and directory)<>0) then
  1014. begin
  1015. subdirfound:=true;
  1016. currpath:=hsd+dir.name+source_info.dirsep;
  1017. hp:=Find(currPath);
  1018. if not assigned(hp) then
  1019. AddCurrPath;
  1020. end;
  1021. findnext(dir);
  1022. if not subdirfound then
  1023. WarnNonExistingPath(currpath);
  1024. end;
  1025. {$ENDIF USE_SYSUTILS}
  1026. FindClose(dir);
  1027. end
  1028. else
  1029. begin
  1030. if PathExists(currpath) then
  1031. AddCurrPath
  1032. else
  1033. WarnNonExistingPath(currpath);
  1034. end;
  1035. until (s='');
  1036. end;
  1037. procedure TSearchPathList.AddList(list:TSearchPathList;addfirst:boolean);
  1038. var
  1039. s : string;
  1040. hl : TSearchPathList;
  1041. hp,hp2 : TStringListItem;
  1042. begin
  1043. if list.empty then
  1044. exit;
  1045. { create temp and reverse the list }
  1046. if addfirst then
  1047. begin
  1048. hl:=TSearchPathList.Create;
  1049. hp:=TStringListItem(list.first);
  1050. while assigned(hp) do
  1051. begin
  1052. hl.insert(hp.Str);
  1053. hp:=TStringListItem(hp.next);
  1054. end;
  1055. while not hl.empty do
  1056. begin
  1057. s:=hl.GetFirst;
  1058. Remove(s);
  1059. Insert(s);
  1060. end;
  1061. hl.Free;
  1062. end
  1063. else
  1064. begin
  1065. hp:=TStringListItem(list.first);
  1066. while assigned(hp) do
  1067. begin
  1068. hp2:=Find(hp.Str);
  1069. { Check if already in path, then we don't add it }
  1070. if not assigned(hp2) then
  1071. Concat(hp.Str);
  1072. hp:=TStringListItem(hp.next);
  1073. end;
  1074. end;
  1075. end;
  1076. function TSearchPathList.FindFile(const f : string;var foundfile:string):boolean;
  1077. Var
  1078. p : TStringListItem;
  1079. begin
  1080. FindFile:=false;
  1081. p:=TStringListItem(first);
  1082. while assigned(p) do
  1083. begin
  1084. result:=FileExistsNonCase(p.Str,f,FoundFile);
  1085. if result then
  1086. exit;
  1087. p:=TStringListItem(p.next);
  1088. end;
  1089. { Return original filename if not found }
  1090. FoundFile:=f;
  1091. end;
  1092. Function GetFileTime ( Var F : File) : Longint;
  1093. Var
  1094. {$ifdef hasunix}
  1095. info: Stat;
  1096. {$endif}
  1097. L : longint;
  1098. begin
  1099. {$ifdef hasunix}
  1100. {$IFDEF havelinuxrtl10}
  1101. FStat (F,Info);
  1102. L:=Info.Mtime;
  1103. {$ELSE}
  1104. FPFStat (F,Info);
  1105. L:=Info.st_Mtime;
  1106. {$ENDIF}
  1107. {$else}
  1108. GetFTime(f,l);
  1109. {$endif}
  1110. GetFileTime:=L;
  1111. end;
  1112. Function GetNamedFileTime (Const F : String) : Longint;
  1113. begin
  1114. GetNamedFileTime:=do_getnamedfiletime(F);
  1115. end;
  1116. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  1117. Var
  1118. singlepathstring : string;
  1119. i : longint;
  1120. begin
  1121. {$ifdef Unix}
  1122. for i:=1 to length(path) do
  1123. if path[i]=':' then
  1124. path[i]:=';';
  1125. {$endif Unix}
  1126. FindFile:=false;
  1127. repeat
  1128. i:=pos(';',path);
  1129. if i=0 then
  1130. i:=256;
  1131. singlepathstring:=FixPath(copy(path,1,i-1),false);
  1132. delete(path,1,i);
  1133. result:=FileExistsNonCase(singlepathstring,f,FoundFile);
  1134. if result then
  1135. exit;
  1136. until path='';
  1137. FoundFile:=f;
  1138. end;
  1139. function FindFilePchar(const f : string;path : pchar;var foundfile:string):boolean;
  1140. Var
  1141. singlepathstring : string;
  1142. startpc,pc : pchar;
  1143. sepch : char;
  1144. begin
  1145. {$ifdef Unix}
  1146. sepch:=':';
  1147. {$else}
  1148. {$ifdef macos}
  1149. sepch:=',';
  1150. {$else}
  1151. sepch:=';';
  1152. {$endif macos}
  1153. {$endif Unix}
  1154. FindFilePchar:=false;
  1155. pc:=path;
  1156. repeat
  1157. startpc:=pc;
  1158. while (pc^<>sepch) and (pc^<>';') and (pc^<>#0) do
  1159. inc(pc);
  1160. move(startpc^,singlepathstring[1],pc-startpc);
  1161. singlepathstring[0]:=char(longint(pc-startpc));
  1162. singlepathstring:=FixPath(singlepathstring,false);
  1163. result:=FileExistsNonCase(singlepathstring,f,FoundFile);
  1164. if result then
  1165. exit;
  1166. if (pc^=#0) then
  1167. break;
  1168. inc(pc);
  1169. until false;
  1170. foundfile:=f;
  1171. end;
  1172. function FindExe(const bin:string;var foundfile:string):boolean;
  1173. var
  1174. p : pchar;
  1175. found : boolean;
  1176. begin
  1177. found:=FindFile(FixFileName(AddExtension(bin,source_info.exeext)),'.;'+exepath,foundfile);
  1178. if not found then
  1179. begin
  1180. {$ifdef macos}
  1181. p:=GetEnvPchar('Commands');
  1182. {$else}
  1183. p:=GetEnvPchar('PATH');
  1184. {$endif}
  1185. found:=FindFilePChar(FixFileName(AddExtension(bin,source_info.exeext)),p,foundfile);
  1186. FreeEnvPChar(p);
  1187. end;
  1188. FindExe:=found;
  1189. end;
  1190. function GetShortName(const n:string):string;
  1191. {$ifdef win32}
  1192. var
  1193. hs,hs2 : string;
  1194. i : longint;
  1195. {$endif}
  1196. {$ifdef go32v2}
  1197. var
  1198. hs : string;
  1199. {$endif}
  1200. {$ifdef watcom}
  1201. var
  1202. hs : string;
  1203. {$endif}
  1204. begin
  1205. GetShortName:=n;
  1206. {$ifdef win32}
  1207. hs:=n+#0;
  1208. i:=Windows.GetShortPathName(@hs[1],@hs2[1],high(hs2));
  1209. if (i>0) and (i<=high(hs2)) then
  1210. begin
  1211. hs2[0]:=chr(strlen(@hs2[1]));
  1212. GetShortName:=hs2;
  1213. end;
  1214. {$endif}
  1215. {$ifdef go32v2}
  1216. hs:=n;
  1217. if Dos.GetShortName(hs) then
  1218. GetShortName:=hs;
  1219. {$endif}
  1220. {$ifdef watcom}
  1221. hs:=n;
  1222. if Dos.GetShortName(hs) then
  1223. GetShortName:=hs;
  1224. {$endif}
  1225. end;
  1226. {****************************************************************************
  1227. OS Dependent things
  1228. ****************************************************************************}
  1229. function GetEnvPChar(const envname:string):pchar;
  1230. {$ifdef win32}
  1231. var
  1232. s : string;
  1233. i,len : longint;
  1234. hp,p,p2 : pchar;
  1235. {$endif}
  1236. begin
  1237. {$ifdef hasunix}
  1238. GetEnvPchar:={$ifdef havelinuxrtl10}Linux.getenv{$else}BaseUnix.fpGetEnv{$endif}(envname);
  1239. {$define GETENVOK}
  1240. {$endif}
  1241. {$ifdef win32}
  1242. GetEnvPchar:=nil;
  1243. p:=GetEnvironmentStrings;
  1244. hp:=p;
  1245. while hp^<>#0 do
  1246. begin
  1247. s:=strpas(hp);
  1248. i:=pos('=',s);
  1249. len:=strlen(hp);
  1250. if upper(copy(s,1,i-1))=upper(envname) then
  1251. begin
  1252. GetMem(p2,len-length(envname));
  1253. Move(hp[i],p2^,len-length(envname));
  1254. GetEnvPchar:=p2;
  1255. break;
  1256. end;
  1257. { next string entry}
  1258. hp:=hp+len+1;
  1259. end;
  1260. FreeEnvironmentStrings(p);
  1261. {$define GETENVOK}
  1262. {$endif}
  1263. {$ifdef os2}
  1264. GetEnvPChar := Dos.GetEnvPChar (EnvName);
  1265. {$define GETENVOK}
  1266. {$endif}
  1267. {$ifdef GETENVOK}
  1268. {$undef GETENVOK}
  1269. {$else}
  1270. GetEnvPchar:=StrPNew(Dos.Getenv(envname));
  1271. {$endif}
  1272. end;
  1273. procedure FreeEnvPChar(p:pchar);
  1274. begin
  1275. {$ifndef hasunix}
  1276. {$ifndef os2}
  1277. StrDispose(p);
  1278. {$endif}
  1279. {$endif}
  1280. end;
  1281. function Shell(const command:string): longint;
  1282. { This is already defined in the linux.ppu for linux, need for the *
  1283. expansion under linux }
  1284. {$ifdef hasunix}
  1285. begin
  1286. result := {$ifdef havelinuxrtl10}Linux{$else}Unix{$endif}.Shell(command);
  1287. end;
  1288. {$else}
  1289. {$ifdef amiga}
  1290. begin
  1291. {$IFDEF USE_SYSUTILS}
  1292. result := ExecuteProcess('',command);
  1293. {$ELSE USE_SYSUTILS}
  1294. exec('',command);
  1295. if (doserror <> 0) then
  1296. result := doserror
  1297. else
  1298. result := dosexitcode;
  1299. end;
  1300. {$ENDIF USE_SYSUTILS}
  1301. {$else}
  1302. var
  1303. comspec : string;
  1304. begin
  1305. comspec:=getenv('COMSPEC');
  1306. {$IFDEF USE_SYSUTILS}
  1307. result := ExecuteProcess(comspec,' /C '+command);
  1308. {$ELSE USE_SYSUTILS}
  1309. Exec(comspec,' /C '+command);
  1310. if (doserror <> 0) then
  1311. result := doserror
  1312. else
  1313. result := dosexitcode;
  1314. end;
  1315. {$ENDIF USE_SYSUTILS}
  1316. {$endif}
  1317. {$endif}
  1318. {$ifdef CPUI386}
  1319. {$define HASSETFPUEXCEPTIONMASK}
  1320. { later, this should be replaced by the math unit }
  1321. const
  1322. Default8087CW : word = $1332;
  1323. procedure Set8087CW(cw:word);assembler;
  1324. asm
  1325. movw cw,%ax
  1326. movw %ax,default8087cw
  1327. fnclex
  1328. fldcw default8087cw
  1329. end;
  1330. function Get8087CW:word;assembler;
  1331. asm
  1332. pushl $0
  1333. fnstcw (%esp)
  1334. popl %eax
  1335. end;
  1336. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1337. var
  1338. CtlWord: Word;
  1339. begin
  1340. CtlWord:=Get8087CW;
  1341. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  1342. end;
  1343. {$endif CPUI386}
  1344. {$ifdef CPUX86_64}
  1345. {$define HASSETFPUEXCEPTIONMASK}
  1346. { later, this should be replaced by the math unit }
  1347. const
  1348. Default8087CW : word = $1332;
  1349. procedure Set8087CW(cw:word);assembler;
  1350. asm
  1351. movw cw,%ax
  1352. movw %ax,default8087cw
  1353. fnclex
  1354. fldcw default8087cw
  1355. end;
  1356. function Get8087CW:word;assembler;
  1357. asm
  1358. pushq $0
  1359. fnstcw (%rsp)
  1360. popq %rax
  1361. end;
  1362. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1363. var
  1364. CtlWord: Word;
  1365. begin
  1366. CtlWord:=Get8087CW;
  1367. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  1368. end;
  1369. {$endif CPUX86_64}
  1370. {$ifdef CPUPOWERPC}
  1371. {$define HASSETFPUEXCEPTIONMASK}
  1372. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1373. var
  1374. newmask: record
  1375. case byte of
  1376. 1: (d: double);
  1377. 2: (a,b: cardinal);
  1378. end;
  1379. begin
  1380. { load current control register contents }
  1381. asm
  1382. mffs f0
  1383. stfd f0,newmask.d
  1384. end;
  1385. { invalid operation: bit 24 (big endian, bit 0 = left-most bit) }
  1386. if (exInvalidOp in mask) then
  1387. newmask.b := newmask.b and not(1 shl (31-24))
  1388. else
  1389. newmask.b := newmask.b or (1 shl (31-24));
  1390. { denormals can not cause exceptions on the PPC }
  1391. { zero divide: bit 27 }
  1392. if (exZeroDivide in mask) then
  1393. newmask.b := newmask.b and not(1 shl (31-27))
  1394. else
  1395. newmask.b := newmask.b or (1 shl (31-27));
  1396. { overflow: bit 25 }
  1397. if (exOverflow in mask) then
  1398. newmask.b := newmask.b and not(1 shl (31-25))
  1399. else
  1400. newmask.b := newmask.b or (1 shl (31-25));
  1401. { underflow: bit 26 }
  1402. if (exUnderflow in mask) then
  1403. newmask.b := newmask.b and not(1 shl (31-26))
  1404. else
  1405. newmask.b := newmask.b or (1 shl (31-26));
  1406. { Precision (inexact result): bit 28 }
  1407. if (exPrecision in mask) then
  1408. newmask.b := newmask.b and not(1 shl (31-28))
  1409. else
  1410. newmask.b := newmask.b or (1 shl (31-28));
  1411. { update control register contents }
  1412. asm
  1413. lfd f0, newmask.d
  1414. mtfsf 255,f0
  1415. end;
  1416. end;
  1417. {$endif CPUPOWERPC}
  1418. {$ifdef CPUSPARC}
  1419. {$define HASSETFPUEXCEPTIONMASK}
  1420. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1421. var
  1422. fsr : cardinal;
  1423. begin
  1424. { load current control register contents }
  1425. asm
  1426. st %fsr,fsr
  1427. end;
  1428. { invalid operation: bit 27 }
  1429. if (exInvalidOp in mask) then
  1430. fsr:=fsr and not(1 shl 27)
  1431. else
  1432. fsr:=fsr or (1 shl 27);
  1433. { zero divide: bit 24 }
  1434. if (exZeroDivide in mask) then
  1435. fsr:=fsr and not(1 shl 24)
  1436. else
  1437. fsr:=fsr or (1 shl 24);
  1438. { overflow: bit 26 }
  1439. if (exOverflow in mask) then
  1440. fsr:=fsr and not(1 shl 26)
  1441. else
  1442. fsr:=fsr or (1 shl 26);
  1443. { underflow: bit 25 }
  1444. if (exUnderflow in mask) then
  1445. fsr:=fsr and not(1 shl 25)
  1446. else
  1447. fsr:=fsr or (1 shl 25);
  1448. { Precision (inexact result): bit 23 }
  1449. if (exPrecision in mask) then
  1450. fsr:=fsr and not(1 shl 23)
  1451. else
  1452. fsr:=fsr or (1 shl 23);
  1453. { update control register contents }
  1454. asm
  1455. ld fsr,%fsr
  1456. end;
  1457. end;
  1458. {$endif CPUSPARC}
  1459. {$ifndef HASSETFPUEXCEPTIONMASK}
  1460. function SetFPUExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
  1461. begin
  1462. end;
  1463. {$endif HASSETFPUEXCEPTIONMASK}
  1464. function is_number_float(d : double) : boolean;
  1465. var
  1466. bytearray : array[0..7] of byte;
  1467. begin
  1468. move(d,bytearray,8);
  1469. { only 1.1 save, 1.0.x will use always little endian }
  1470. {$ifdef FPC_BIG_ENDIAN}
  1471. result:=((bytearray[0] and $7f)<>$7f) or ((bytearray[1] and $f0)<>$f0);
  1472. {$else FPC_BIG_ENDIAN}
  1473. result:=((bytearray[7] and $7f)<>$7f) or ((bytearray[6] and $f0)<>$f0);
  1474. {$endif FPC_BIG_ENDIAN}
  1475. end;
  1476. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  1477. var
  1478. b : boolean;
  1479. begin
  1480. b:=true;
  1481. if s='DEFAULT' then
  1482. aktmodeswitches:=initmodeswitches
  1483. else
  1484. if s='DELPHI' then
  1485. aktmodeswitches:=delphimodeswitches
  1486. else
  1487. if s='TP' then
  1488. aktmodeswitches:=tpmodeswitches
  1489. else
  1490. if s='FPC' then
  1491. aktmodeswitches:=fpcmodeswitches
  1492. else
  1493. if s='OBJFPC' then
  1494. aktmodeswitches:=objfpcmodeswitches
  1495. else
  1496. if s='GPC' then
  1497. aktmodeswitches:=gpcmodeswitches
  1498. else
  1499. if s='MACPAS' then
  1500. aktmodeswitches:=macmodeswitches
  1501. else
  1502. b:=false;
  1503. if b and changeInit then
  1504. initmodeswitches := aktmodeswitches;
  1505. if b then
  1506. begin
  1507. { turn ansistrings on by default ? }
  1508. if (m_delphi in aktmodeswitches) then
  1509. begin
  1510. include(aktlocalswitches,cs_ansistrings);
  1511. if changeinit then
  1512. include(initlocalswitches,cs_ansistrings);
  1513. end
  1514. else
  1515. begin
  1516. exclude(aktlocalswitches,cs_ansistrings);
  1517. if changeinit then
  1518. exclude(initlocalswitches,cs_ansistrings);
  1519. end;
  1520. { Default enum packing for delphi/tp7 }
  1521. if (m_tp7 in aktmodeswitches) or
  1522. (m_delphi in aktmodeswitches) then
  1523. aktpackenum:=1
  1524. else
  1525. aktpackenum:=4;
  1526. if changeinit then
  1527. initpackenum:=aktpackenum;
  1528. {$ifdef i386}
  1529. { Default to intel assembler for delphi/tp7 on i386 }
  1530. if (m_delphi in aktmodeswitches) or
  1531. (m_tp7 in aktmodeswitches) then
  1532. aktasmmode:=asmmode_i386_intel;
  1533. if changeinit then
  1534. initasmmode:=aktasmmode;
  1535. {$endif i386}
  1536. end;
  1537. SetCompileMode:=b;
  1538. end;
  1539. function SetAktProcCall(const s:string; changeInit:boolean):boolean;
  1540. const
  1541. DefProcCallName : array[tproccalloption] of string[12] = ('',
  1542. 'CDECL',
  1543. 'CPPDECL',
  1544. '', { compilerproc }
  1545. 'FAR16',
  1546. 'FPCCALL',
  1547. 'INLINE',
  1548. '', { internproc }
  1549. '', { syscall }
  1550. 'PASCAL',
  1551. 'REGISTER',
  1552. 'SAFECALL',
  1553. 'STDCALL',
  1554. 'SOFTFLOAT'
  1555. );
  1556. var
  1557. t : tproccalloption;
  1558. begin
  1559. result:=false;
  1560. for t:=low(tproccalloption) to high(tproccalloption) do
  1561. if DefProcCallName[t]=s then
  1562. begin
  1563. AktDefProcCall:=t;
  1564. result:=true;
  1565. break;
  1566. end;
  1567. if changeinit then
  1568. InitDefProcCall:=AktDefProcCall;
  1569. end;
  1570. function SetProcessor(const s:string; changeInit: boolean):boolean;
  1571. var
  1572. t : tprocessors;
  1573. begin
  1574. SetProcessor:=false;
  1575. for t:=low(tprocessors) to high(tprocessors) do
  1576. if processorsstr[t]=s then
  1577. begin
  1578. aktspecificoptprocessor:=t;
  1579. SetProcessor:=true;
  1580. break;
  1581. end;
  1582. if changeinit then
  1583. initspecificoptprocessor:=aktspecificoptprocessor;
  1584. end;
  1585. function SetFpuType(const s:string; changeInit: boolean):boolean;
  1586. var
  1587. t : tfputype;
  1588. begin
  1589. SetFpuType:=false;
  1590. for t:=low(tfputype) to high(tfputype) do
  1591. if fputypestr[t]=s then
  1592. begin
  1593. aktfputype:=t;
  1594. SetFpuType:=true;
  1595. break;
  1596. end;
  1597. if changeinit then
  1598. initfputype:=aktfputype;
  1599. end;
  1600. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  1601. function string2guid(const s: string; var GUID: TGUID): boolean;
  1602. function ishexstr(const hs: string): boolean;
  1603. var
  1604. i: integer;
  1605. begin
  1606. ishexstr:=false;
  1607. for i:=1 to Length(hs) do begin
  1608. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  1609. exit;
  1610. end;
  1611. ishexstr:=true;
  1612. end;
  1613. function hexstr2longint(const hexs: string): longint;
  1614. var
  1615. i: integer;
  1616. rl: longint;
  1617. begin
  1618. rl:=0;
  1619. for i:=1 to length(hexs) do begin
  1620. rl:=rl shl 4;
  1621. case hexs[i] of
  1622. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  1623. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  1624. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  1625. end
  1626. end;
  1627. hexstr2longint:=rl;
  1628. end;
  1629. var
  1630. i: integer;
  1631. begin
  1632. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  1633. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  1634. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  1635. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  1636. ishexstr(copy(s,26,12)) then begin
  1637. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  1638. { these values are arealdy in the correct range (4 chars = word) }
  1639. GUID.D2:=word(hexstr2longint(copy(s,11,4)));
  1640. GUID.D3:=word(hexstr2longint(copy(s,16,4)));
  1641. for i:=0 to 1 do
  1642. GUID.D4[i]:=byte(hexstr2longint(copy(s,21+i*2,2)));
  1643. for i:=2 to 7 do
  1644. GUID.D4[i]:=byte(hexstr2longint(copy(s,22+i*2,2)));
  1645. string2guid:=true;
  1646. end
  1647. else
  1648. string2guid:=false;
  1649. end;
  1650. function guid2string(const GUID: TGUID): string;
  1651. function long2hex(l, len: longint): string;
  1652. const
  1653. hextbl: array[0..15] of char = '0123456789ABCDEF';
  1654. var
  1655. rs: string;
  1656. i: integer;
  1657. begin
  1658. rs[0]:=chr(len);
  1659. for i:=len downto 1 do begin
  1660. rs[i]:=hextbl[l and $F];
  1661. l:=l shr 4;
  1662. end;
  1663. long2hex:=rs;
  1664. end;
  1665. begin
  1666. guid2string:=
  1667. '{'+long2hex(GUID.D1,8)+
  1668. '-'+long2hex(GUID.D2,4)+
  1669. '-'+long2hex(GUID.D3,4)+
  1670. '-'+long2hex(GUID.D4[0],2)+long2hex(GUID.D4[1],2)+
  1671. '-'+long2hex(GUID.D4[2],2)+long2hex(GUID.D4[3],2)+
  1672. long2hex(GUID.D4[4],2)+long2hex(GUID.D4[5],2)+
  1673. long2hex(GUID.D4[6],2)+long2hex(GUID.D4[7],2)+
  1674. '}';
  1675. end;
  1676. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  1677. var
  1678. tok : string;
  1679. vstr : string;
  1680. l : longint;
  1681. code : integer;
  1682. b : talignmentinfo;
  1683. begin
  1684. UpdateAlignmentStr:=true;
  1685. uppervar(s);
  1686. fillchar(b,sizeof(b),0);
  1687. repeat
  1688. tok:=GetToken(s,'=');
  1689. if tok='' then
  1690. break;
  1691. vstr:=GetToken(s,',');
  1692. val(vstr,l,code);
  1693. if tok='PROC' then
  1694. b.procalign:=l
  1695. else if tok='JUMP' then
  1696. b.jumpalign:=l
  1697. else if tok='LOOP' then
  1698. b.loopalign:=l
  1699. else if tok='CONSTMIN' then
  1700. b.constalignmin:=l
  1701. else if tok='CONSTMAX' then
  1702. b.constalignmax:=l
  1703. else if tok='VARMIN' then
  1704. b.varalignmin:=l
  1705. else if tok='VARMAX' then
  1706. b.varalignmax:=l
  1707. else if tok='LOCALMIN' then
  1708. b.localalignmin:=l
  1709. else if tok='LOCALMAX' then
  1710. b.localalignmax:=l
  1711. else if tok='RECORDMIN' then
  1712. b.recordalignmin:=l
  1713. else if tok='RECORDMAX' then
  1714. b.recordalignmax:=l
  1715. else { Error }
  1716. UpdateAlignmentStr:=false;
  1717. until false;
  1718. UpdateAlignment(a,b);
  1719. end;
  1720. function var_align(siz: longint): longint;
  1721. begin
  1722. siz := size_2_align(siz);
  1723. var_align := used_align(siz,aktalignment.varalignmin,aktalignment.varalignmax);
  1724. end;
  1725. function const_align(siz: longint): longint;
  1726. begin
  1727. siz := size_2_align(siz);
  1728. const_align := used_align(siz,aktalignment.constalignmin,aktalignment.constalignmax);
  1729. end;
  1730. {****************************************************************************
  1731. Init
  1732. ****************************************************************************}
  1733. {$ifdef unix}
  1734. {$define need_path_search}
  1735. {$endif unix}
  1736. {$ifdef os2}
  1737. {$define need_path_search}
  1738. {$endif os2}
  1739. {$ifdef macos}
  1740. {$define need_path_search}
  1741. {$endif macos}
  1742. procedure get_exepath;
  1743. var
  1744. hs1 : namestr;
  1745. hs2 : extstr;
  1746. {$IFDEF USE_SYSUTILS}
  1747. exeName:String;
  1748. {$ENDIF USE_SYSUTILS}
  1749. {$ifdef need_path_search}
  1750. p : pchar;
  1751. {$endif need_path_search}
  1752. begin
  1753. {$IFDEF USE_SYSUTILS}
  1754. exepath:=GetEnvironmentVariable('PPC_EXEC_PATH');
  1755. {$ELSE USE_SYSUTILS}
  1756. exepath:=dos.getenv('PPC_EXEC_PATH');
  1757. {$ENDIF USE_SYSUTILS}
  1758. if exepath='' then
  1759. {$IFDEF USE_SYSUTILS}
  1760. exeName := FixFileName(system.paramstr(0));
  1761. exepath := ExtractFilePath(exeName);
  1762. hs1 := ExtractFileName(exeName);
  1763. hs2 := ExtractFileExt(exeName);
  1764. {$ELSE USE_SYSUTILS}
  1765. fsplit(FixFileName(system.paramstr(0)),exepath,hs1,hs2);
  1766. {$ENDIF USE_SYSUTILS}
  1767. {$ifdef need_path_search}
  1768. if exepath='' then
  1769. begin
  1770. if pos(source_info.exeext,hs1) <>
  1771. (length(hs1) - length(source_info.exeext)+1) then
  1772. hs1 := hs1 + source_info.exeext;
  1773. {$ifdef macos}
  1774. p:=GetEnvPchar('Commands');
  1775. {$else macos}
  1776. p:=GetEnvPchar('PATH');
  1777. {$endif macos}
  1778. FindFilePChar(hs1,p,exepath);
  1779. FreeEnvPChar(p);
  1780. exepath:=SplitPath(exepath);
  1781. end;
  1782. {$endif need_path_search}
  1783. exepath:=FixPath(exepath,false);
  1784. end;
  1785. procedure DoneGlobals;
  1786. begin
  1787. initdefines.free;
  1788. if assigned(DLLImageBase) then
  1789. StringDispose(DLLImageBase);
  1790. librarysearchpath.Free;
  1791. unitsearchpath.Free;
  1792. objectsearchpath.Free;
  1793. includesearchpath.Free;
  1794. end;
  1795. procedure InitGlobals;
  1796. begin
  1797. get_exepath;
  1798. { reset globals }
  1799. do_build:=false;
  1800. do_release:=false;
  1801. do_make:=true;
  1802. compile_level:=0;
  1803. DLLsource:=false;
  1804. inlining_procedure:=false;
  1805. resolving_forward:=false;
  1806. make_ref:=false;
  1807. LinkTypeSetExplicitly:=false;
  1808. { Output }
  1809. OutputFile:='';
  1810. OutputPrefix:=Nil;
  1811. OutputSuffix:=Nil;
  1812. OutputExtension:='';
  1813. OutputExeDir:='';
  1814. OutputUnitDir:='';
  1815. { Utils directory }
  1816. utilsdirectory:='';
  1817. utilsprefix:='';
  1818. cshared:=false;
  1819. rlinkpath:='';
  1820. { Search Paths }
  1821. librarysearchpath:=TSearchPathList.Create;
  1822. unitsearchpath:=TSearchPathList.Create;
  1823. includesearchpath:=TSearchPathList.Create;
  1824. objectsearchpath:=TSearchPathList.Create;
  1825. { Def file }
  1826. usewindowapi:=false;
  1827. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1828. DescriptionSetExplicity:=false;
  1829. dllversion:='';
  1830. dllmajor:=1;
  1831. dllminor:=0;
  1832. dllrevision:=0;
  1833. nwscreenname := '';
  1834. nwthreadname := '';
  1835. nwcopyright := '';
  1836. UseDeffileForExports:=false;
  1837. UseDeffileForExportsSetExplicitly:=false;
  1838. RelocSection:=false;
  1839. RelocSectionSetExplicitly:=false;
  1840. LinkTypeSetExplicitly:=false;
  1841. { Init values }
  1842. initmodeswitches:=fpcmodeswitches;
  1843. initlocalswitches:=[cs_check_io,cs_typed_const_writable];
  1844. initmoduleswitches:=[cs_extsyntax,cs_implicit_exceptions];
  1845. initsourcecodepage:='8859-1';
  1846. initglobalswitches:=[cs_check_unit_name,cs_link_static{$ifdef INTERNALLINKER},cs_link_internal,cs_link_map{$endif}];
  1847. initoutputformat:=target_asm.id;
  1848. fillchar(initalignment,sizeof(talignmentinfo),0);
  1849. { might be overridden later }
  1850. initasmmode:=asmmode_standard;
  1851. {$ifdef i386}
  1852. initoptprocessor:=ClassPentium3;
  1853. initspecificoptprocessor:=Class386;
  1854. initfputype:=fpu_x87;
  1855. initpackenum:=4;
  1856. {$IFDEF testvarsets}
  1857. initsetalloc:=0;
  1858. {$ENDIF}
  1859. initasmmode:=asmmode_i386_att;
  1860. {$endif i386}
  1861. {$ifdef m68k}
  1862. initoptprocessor:=MC68020;
  1863. initpackenum:=4;
  1864. {$IFDEF testvarsets}
  1865. initsetalloc:=0;
  1866. {$ENDIF}
  1867. {$endif m68k}
  1868. {$ifdef powerpc}
  1869. initoptprocessor:=PPC604;
  1870. initpackenum:=4;
  1871. {$IFDEF testvarsets}
  1872. initsetalloc:=0;
  1873. {$ENDIF}
  1874. initfputype:=fpu_standard;
  1875. {$endif powerpc}
  1876. {$ifdef sparc}
  1877. initoptprocessor:=SPARC_V8;
  1878. initpackenum:=4;
  1879. {$IFDEF testvarsets}
  1880. initsetalloc:=0;
  1881. {$ENDIF}
  1882. {$endif sparc}
  1883. {$ifdef arm}
  1884. initpackenum:=4;
  1885. {$IFDEF testvarsets}
  1886. initsetalloc:=0;
  1887. {$ENDIF}
  1888. initfputype:=fpu_fpa;
  1889. {$endif arm}
  1890. {$ifdef x86_64}
  1891. initoptprocessor:=ClassAthlon64;
  1892. initspecificoptprocessor:=ClassAthlon64;
  1893. initfputype:=fpu_sse64;
  1894. initpackenum:=4;
  1895. {$IFDEF testvarsets}
  1896. initsetalloc:=0;
  1897. {$ENDIF}
  1898. initasmmode:=asmmode_x86_64_gas;
  1899. {$endif x86_64}
  1900. initinterfacetype:=it_interfacecom;
  1901. initdefproccall:=pocall_default;
  1902. initdefines:=TStringList.Create;
  1903. { memory sizes, will be overriden by parameter or default for target
  1904. in options or init_parser }
  1905. stacksize:=0;
  1906. apptype:=app_cui;
  1907. end;
  1908. end.
  1909. {
  1910. $Log$
  1911. Revision 1.148 2004-10-25 15:38:41 peter
  1912. * heap and heapsize removed
  1913. * checkpointer fixes
  1914. Revision 1.147 2004/10/16 22:46:14 olle
  1915. * Fixed printing of filedates
  1916. Revision 1.146 2004/10/16 13:03:13 olle
  1917. + added more support for macos
  1918. Revision 1.145 2004/10/15 09:14:16 mazen
  1919. - remove $IFDEF DELPHI and related code
  1920. - remove $IFDEF FPCPROCVAR and related code
  1921. Revision 1.144 2004/10/14 18:16:17 mazen
  1922. * USE_SYSUTILS merged successfully : cycles with and without defines
  1923. * Need to be optimized in performance
  1924. Revision 1.143 2004/10/10 15:42:22 peter
  1925. * default optimization cpu changed to CLassPentium3
  1926. Revision 1.142 2004/10/09 11:27:59 olle
  1927. + Added CurDirRelPath
  1928. * Exchanged hardcoded "./" to CurDirRelPath
  1929. Revision 1.141 2004/09/21 23:33:43 hajny
  1930. * better PathExists, fix for too long command line, correction of message
  1931. Revision 1.140 2004/09/21 19:59:51 peter
  1932. * x86_64 fixes
  1933. * cleanup of fpcdefs.icn
  1934. Revision 1.139 2004/09/21 17:25:12 peter
  1935. * paraloc branch merged
  1936. Revision 1.138 2004/09/08 11:23:31 michael
  1937. + Check if outputdir exists, Fix exitcode when displaying help pages
  1938. Revision 1.137 2004/08/31 22:02:30 olle
  1939. + support for quoting of paths in TSearchPathList.AddPath so that
  1940. compiler directives which take paths, will support quotes.
  1941. * uppdated TranslateMacPath
  1942. Revision 1.136.4.2 2004/09/12 18:31:26 peter
  1943. * fpu exception support for sparc and x86_64
  1944. Revision 1.136.4.1 2004/09/12 15:30:16 peter
  1945. * cache currentdir
  1946. Revision 1.136 2004/08/28 20:25:25 peter
  1947. * optimized search for noncasesensitive names. It now searches
  1948. first for NormalCase and skips double tests
  1949. Revision 1.135 2004/08/20 10:29:31 olle
  1950. + made fpc work as an MPW tool, by itself calling asm and link.
  1951. * bugfix in fp exception flag settings routine
  1952. Revision 1.134 2004/08/02 07:15:54 michael
  1953. + Patch from Christian Iversen to implement LIBPREFIX/SUFFIX/EXTENSION directives
  1954. Revision 1.133 2004/07/17 15:51:57 jonas
  1955. * shell now returns an exitcode
  1956. * print an error if linking failed when linking was done using a script
  1957. Revision 1.132 2004/07/05 23:28:24 olle
  1958. + FixFileName now handles Mac OS paths
  1959. Revision 1.131 2004/06/20 08:55:29 florian
  1960. * logs truncated
  1961. Revision 1.130 2004/06/16 20:07:07 florian
  1962. * dwarf branch merged
  1963. Revision 1.129 2004/05/11 18:20:52 olle
  1964. * changed $mode mac to $mode macpas
  1965. * changed macmodeswitches to be more faithful to the mac dialect
  1966. Revision 1.128 2004/04/29 19:56:36 daniel
  1967. * Prepare compiler infrastructure for multiple ansistring types
  1968. Revision 1.127 2004/04/28 15:19:03 florian
  1969. + syscall directive support for MorphOS added
  1970. Revision 1.126.2.4 2004/05/09 15:47:21 peter
  1971. * fix typecast from word->set
  1972. }