globals.pas 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231
  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. heapsize,
  202. stacksize : longint;
  203. {$Ifdef EXTDEBUG}
  204. { parameter switches }
  205. debugstop : boolean;
  206. {$EndIf EXTDEBUG}
  207. { windows / OS/2 application type }
  208. apptype : tapptype;
  209. const
  210. DLLsource : boolean = false;
  211. DLLImageBase : pstring = nil;
  212. { used to set all registers used for each global function
  213. this should dramatically decrease the number of
  214. recompilations needed PM }
  215. simplify_ppu : boolean = true;
  216. { should we allow non static members ? }
  217. allow_only_static : boolean = false;
  218. Inside_asm_statement : boolean = false;
  219. global_unit_count : word = 0;
  220. { for error info in pp.pas }
  221. parser_current_file : string = '';
  222. {$ifdef m68k}
  223. { PalmOS resources }
  224. palmos_applicationname : string = 'FPC Application';
  225. palmos_applicationid : string[4] = 'FPCA';
  226. {$endif m68k}
  227. procedure abstract;
  228. function bstoslash(const s : string) : string;
  229. function getdatestr:string;
  230. function gettimestr:string;
  231. function filetimestring( t : longint) : string;
  232. procedure DefaultReplacements(var s:string);
  233. {Gives the absolute path to the current directory}
  234. function GetCurrentDir:string;
  235. {Gives the relative path to the current directory,
  236. with a trailing dir separator. E. g. on unix ./ }
  237. function CurDirRelPath(systeminfo: tsysteminfo): string;
  238. function path_absolute(const s : string) : boolean;
  239. Function PathExists ( F : String) : Boolean;
  240. Function FileExists ( Const F : String) : Boolean;
  241. function FileExistsNonCase(const path,fn:string;var foundfile:string):boolean;
  242. Function RemoveFile(const f:string):boolean;
  243. Function RemoveDir(d:string):boolean;
  244. Function GetFileTime ( Var F : File) : Longint;
  245. Function GetNamedFileTime ( Const F : String) : Longint;
  246. {Extracts the path without its filename, from a path.}
  247. Function SplitPath(const s:string):string;
  248. Function SplitFileName(const s:string):string;
  249. Function SplitName(const s:string):string;
  250. Function SplitExtension(Const HStr:String):String;
  251. Function AddExtension(Const HStr,ext:String):String;
  252. Function ForceExtension(Const HStr,ext:String):String;
  253. Function FixPath(s:string;allowdot:boolean):string;
  254. function FixFileName(const s:string):string;
  255. function TargetFixPath(s:string;allowdot:boolean):string;
  256. function TargetFixFileName(const s:string):string;
  257. procedure SplitBinCmd(const s:string;var bstr: String;var cstr:TCmdStr);
  258. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  259. function FindFilePchar(const f : string;path : pchar;var foundfile:string):boolean;
  260. function FindExe(const bin:string;var foundfile:string):boolean;
  261. function GetShortName(const n:string):string;
  262. function Shell(const command:string): longint;
  263. function GetEnvPChar(const envname:string):pchar;
  264. procedure FreeEnvPChar(p:pchar);
  265. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  266. function is_number_float(d : double) : boolean;
  267. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  268. function SetAktProcCall(const s:string; changeInit: boolean):boolean;
  269. function SetProcessor(const s:string; changeInit: boolean):boolean;
  270. function SetFpuType(const s:string; changeInit: boolean):boolean;
  271. procedure InitGlobals;
  272. procedure DoneGlobals;
  273. function string2guid(const s: string; var GUID: TGUID): boolean;
  274. function guid2string(const GUID: TGUID): string;
  275. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  276. {# Routine to get the required alignment for size of data, which will
  277. be placed in bss segment, according to the current alignment requirements }
  278. function var_align(siz: longint): longint;
  279. {# Routine to get the required alignment for size of data, which will
  280. be placed in data/const segment, according to the current alignment requirements }
  281. function const_align(siz: longint): longint;
  282. implementation
  283. uses
  284. {$ifdef macos}
  285. macutils,
  286. {$endif}
  287. comphook;
  288. procedure abstract;
  289. begin
  290. do_internalerror(255);
  291. end;
  292. procedure WarnNonExistingPath(const path : string);
  293. begin
  294. if assigned(do_comment) then
  295. do_comment(V_Tried,'Path "'+path+'" not found');
  296. end;
  297. function bstoslash(const s : string) : string;
  298. {
  299. return string s with all \ changed into /
  300. }
  301. var
  302. i : longint;
  303. begin
  304. for i:=1to length(s) do
  305. if s[i]='\' then
  306. bstoslash[i]:='/'
  307. else
  308. bstoslash[i]:=s[i];
  309. bstoslash[0]:=s[0];
  310. end;
  311. {****************************************************************************
  312. Time Handling
  313. ****************************************************************************}
  314. Function L0(l:longint):string;
  315. {
  316. return the string of value l, if l<10 then insert a zero, so
  317. the string is always at least 2 chars '01','02',etc
  318. }
  319. var
  320. s : string;
  321. begin
  322. Str(l,s);
  323. if l<10 then
  324. s:='0'+s;
  325. L0:=s;
  326. end;
  327. function gettimestr:string;
  328. {
  329. get the current time in a string HH:MM:SS
  330. }
  331. var
  332. hour,min,sec,hsec : word;
  333. begin
  334. {$IFDEF USE_SYSUTILS}
  335. DecodeTime(Time,hour,min,sec,hsec);
  336. {$ELSE USE_SYSUTILS}
  337. dos.gettime(hour,min,sec,hsec);
  338. {$ENDIF USE_SYSUTILS}
  339. gettimestr:=L0(Hour)+':'+L0(min)+':'+L0(sec);
  340. end;
  341. function getdatestr:string;
  342. {
  343. get the current date in a string YY/MM/DD
  344. }
  345. var
  346. {$IFDEF USE_SYSUTILS}
  347. Year,Month,Day: Word;
  348. {$ELSE USE_SYSUTILS}
  349. Year,Month,Day,Wday : Word;
  350. {$ENDIF USE_SYSUTILS}
  351. begin
  352. {$IFDEF USE_SYSUTILS}
  353. DecodeDate(Date,year,month,day);
  354. {$ELSE USE_SYSUTILS}
  355. dos.getdate(year,month,day,wday);
  356. {$ENDIF USE_SYSUTILS}
  357. getdatestr:=L0(Year)+'/'+L0(Month)+'/'+L0(Day);
  358. end;
  359. function filetimestring( t : longint) : string;
  360. {
  361. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  362. }
  363. var
  364. {$IFDEF USE_SYSUTILS}
  365. DT : TDateTime;
  366. hsec : word;
  367. {$ELSE USE_SYSUTILS}
  368. DT : DateTime;
  369. {$ENDIF USE_SYSUTILS}
  370. Year,Month,Day: Word;
  371. hour,min,sec : word;
  372. begin
  373. if t=-1 then
  374. begin
  375. Result := 'Not Found';
  376. exit;
  377. end;
  378. {$IFDEF USE_SYSUTILS}
  379. DT := FileDateToDateTime(t);
  380. DecodeTime(DT,hour,min,sec,hsec);
  381. DecodeDate(DT,year,month,day);
  382. {$ELSE USE_SYSUTILS}
  383. unpacktime(t,DT);
  384. year := DT.year;
  385. month := DT.month;
  386. day := DT.day;
  387. hour := DT.hour;
  388. min := DT.min;
  389. sec := DT.sec;
  390. {$ENDIF USE_SYSUTILS}
  391. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  392. end;
  393. {****************************************************************************
  394. Default Macro Handling
  395. ****************************************************************************}
  396. procedure DefaultReplacements(var s:string);
  397. begin
  398. { Replace some macros }
  399. Replace(s,'$FPCVERSION',version_string);
  400. Replace(s,'$FPCFULLVERSION',full_version_string);
  401. Replace(s,'$FPCDATE',date_string);
  402. Replace(s,'$FPCCPU',target_cpu_string);
  403. Replace(s,'$FPCOS',target_path);
  404. Replace(s,'$FPCTARGET',target_cpu_string+'-'+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(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. staridx,
  910. j : longint;
  911. prefix,
  912. suffix,
  913. CurrentDir,
  914. currPath : string;
  915. subdirfound : boolean;
  916. {$IFDEF USE_SYSUTILS}
  917. dir : TSearchRec;
  918. {$ELSE USE_SYSUTILS}
  919. dir : searchrec;
  920. {$ENDIF USE_SYSUTILS}
  921. hp : TStringListItem;
  922. procedure AddCurrPath;
  923. begin
  924. if addfirst then
  925. begin
  926. Remove(currPath);
  927. Insert(currPath);
  928. end
  929. else
  930. begin
  931. { Check if already in path, then we don't add it }
  932. hp:=Find(currPath);
  933. if not assigned(hp) then
  934. Concat(currPath);
  935. end;
  936. end;
  937. begin
  938. if s='' then
  939. exit;
  940. { Support default macro's }
  941. DefaultReplacements(s);
  942. { get current dir }
  943. CurrentDir:=GetCurrentDir;
  944. repeat
  945. { get currpath }
  946. if addfirst then
  947. begin
  948. j:=length(s);
  949. while (j>0) and (s[j]<>';') do
  950. dec(j);
  951. currPath:= TrimSpace(Copy(s,j+1,length(s)-j));
  952. DePascalQuote(currPath);
  953. currPath:=FixPath(currPath,false);
  954. if j=0 then
  955. s:=''
  956. else
  957. System.Delete(s,j,length(s)-j+1);
  958. end
  959. else
  960. begin
  961. j:=Pos(';',s);
  962. if j=0 then
  963. j:=255;
  964. currPath:= TrimSpace(Copy(s,1,j-1));
  965. DePascalQuote(currPath);
  966. currPath:=SrcPath+FixPath(currPath,false);
  967. System.Delete(s,1,j);
  968. end;
  969. { fix pathname }
  970. if currPath='' then
  971. currPath:= CurDirRelPath(source_info)
  972. else
  973. begin
  974. currPath:=FixPath(FExpand(currPath),false);
  975. if (CurrentDir<>'') and (Copy(currPath,1,length(CurrentDir))=CurrentDir) then
  976. begin
  977. {$ifdef AMIGA}
  978. currPath:= CurrentDir+Copy(currPath,length(CurrentDir)+1,255);
  979. {$else}
  980. currPath:= CurDirRelPath(source_info)+Copy(currPath,length(CurrentDir)+1,255);
  981. {$endif}
  982. end;
  983. end;
  984. { wildcard adding ? }
  985. staridx:=pos('*',currpath);
  986. if staridx>0 then
  987. begin
  988. prefix:=SplitPath(Copy(currpath,1,staridx));
  989. suffix:=Copy(currpath,staridx+1,length(currpath));
  990. subdirfound:=false;
  991. {$IFDEF USE_SYSUTILS}
  992. if findfirst(prefix+'*',faDirectory,dir) = 0 then
  993. begin
  994. repeat
  995. if (dir.name<>'.') and
  996. (dir.name<>'..') and
  997. ((dir.attr and faDirectory)<>0) then
  998. begin
  999. subdirfound:=true;
  1000. currpath:=prefix+dir.name+suffix;
  1001. if (suffix='') or PathExists(currpath) then
  1002. begin
  1003. hp:=Find(currPath);
  1004. if not assigned(hp) then
  1005. AddCurrPath;
  1006. end;
  1007. end;
  1008. until findnext(dir) <> 0;
  1009. end
  1010. {$ELSE USE_SYSUTILS}
  1011. findfirst(prefix+'*',directory,dir);
  1012. while doserror=0 do
  1013. begin
  1014. if (dir.name<>'.') and
  1015. (dir.name<>'..') and
  1016. ((dir.attr and directory)<>0) then
  1017. begin
  1018. subdirfound:=true;
  1019. currpath:=prefix+dir.name+suffix;
  1020. if (suffix='') or PathExists(currpath) then
  1021. begin
  1022. hp:=Find(currPath);
  1023. if not assigned(hp) then
  1024. AddCurrPath;
  1025. end;
  1026. end;
  1027. findnext(dir);
  1028. end;
  1029. {$ENDIF USE_SYSUTILS}
  1030. FindClose(dir);
  1031. if not subdirfound then
  1032. WarnNonExistingPath(currpath);
  1033. end
  1034. else
  1035. begin
  1036. if PathExists(currpath) then
  1037. AddCurrPath
  1038. else
  1039. WarnNonExistingPath(currpath);
  1040. end;
  1041. until (s='');
  1042. end;
  1043. procedure TSearchPathList.AddList(list:TSearchPathList;addfirst:boolean);
  1044. var
  1045. s : string;
  1046. hl : TSearchPathList;
  1047. hp,hp2 : TStringListItem;
  1048. begin
  1049. if list.empty then
  1050. exit;
  1051. { create temp and reverse the list }
  1052. if addfirst then
  1053. begin
  1054. hl:=TSearchPathList.Create;
  1055. hp:=TStringListItem(list.first);
  1056. while assigned(hp) do
  1057. begin
  1058. hl.insert(hp.Str);
  1059. hp:=TStringListItem(hp.next);
  1060. end;
  1061. while not hl.empty do
  1062. begin
  1063. s:=hl.GetFirst;
  1064. Remove(s);
  1065. Insert(s);
  1066. end;
  1067. hl.Free;
  1068. end
  1069. else
  1070. begin
  1071. hp:=TStringListItem(list.first);
  1072. while assigned(hp) do
  1073. begin
  1074. hp2:=Find(hp.Str);
  1075. { Check if already in path, then we don't add it }
  1076. if not assigned(hp2) then
  1077. Concat(hp.Str);
  1078. hp:=TStringListItem(hp.next);
  1079. end;
  1080. end;
  1081. end;
  1082. function TSearchPathList.FindFile(const f : string;var foundfile:string):boolean;
  1083. Var
  1084. p : TStringListItem;
  1085. begin
  1086. FindFile:=false;
  1087. p:=TStringListItem(first);
  1088. while assigned(p) do
  1089. begin
  1090. result:=FileExistsNonCase(p.Str,f,FoundFile);
  1091. if result then
  1092. exit;
  1093. p:=TStringListItem(p.next);
  1094. end;
  1095. { Return original filename if not found }
  1096. FoundFile:=f;
  1097. end;
  1098. Function GetFileTime ( Var F : File) : Longint;
  1099. Var
  1100. {$ifdef hasunix}
  1101. info: Stat;
  1102. {$endif}
  1103. L : longint;
  1104. begin
  1105. {$ifdef hasunix}
  1106. {$IFDEF havelinuxrtl10}
  1107. FStat (F,Info);
  1108. L:=Info.Mtime;
  1109. {$ELSE}
  1110. FPFStat (F,Info);
  1111. L:=Info.st_Mtime;
  1112. {$ENDIF}
  1113. {$else}
  1114. GetFTime(f,l);
  1115. {$endif}
  1116. GetFileTime:=L;
  1117. end;
  1118. Function GetNamedFileTime (Const F : String) : Longint;
  1119. begin
  1120. GetNamedFileTime:=do_getnamedfiletime(F);
  1121. end;
  1122. function FindFile(const f : string;path : string;var foundfile:string):boolean;
  1123. Var
  1124. singlepathstring : string;
  1125. i : longint;
  1126. begin
  1127. {$ifdef Unix}
  1128. for i:=1 to length(path) do
  1129. if path[i]=':' then
  1130. path[i]:=';';
  1131. {$endif Unix}
  1132. FindFile:=false;
  1133. repeat
  1134. i:=pos(';',path);
  1135. if i=0 then
  1136. i:=256;
  1137. singlepathstring:=FixPath(copy(path,1,i-1),false);
  1138. delete(path,1,i);
  1139. result:=FileExistsNonCase(singlepathstring,f,FoundFile);
  1140. if result then
  1141. exit;
  1142. until path='';
  1143. FoundFile:=f;
  1144. end;
  1145. function FindFilePchar(const f : string;path : pchar;var foundfile:string):boolean;
  1146. Var
  1147. singlepathstring : string;
  1148. startpc,pc : pchar;
  1149. sepch : char;
  1150. begin
  1151. {$ifdef Unix}
  1152. sepch:=':';
  1153. {$else}
  1154. {$ifdef macos}
  1155. sepch:=',';
  1156. {$else}
  1157. sepch:=';';
  1158. {$endif macos}
  1159. {$endif Unix}
  1160. FindFilePchar:=false;
  1161. pc:=path;
  1162. repeat
  1163. startpc:=pc;
  1164. while (pc^<>sepch) and (pc^<>';') and (pc^<>#0) do
  1165. inc(pc);
  1166. move(startpc^,singlepathstring[1],pc-startpc);
  1167. singlepathstring[0]:=char(longint(pc-startpc));
  1168. singlepathstring:=FixPath(singlepathstring,false);
  1169. result:=FileExistsNonCase(singlepathstring,f,FoundFile);
  1170. if result then
  1171. exit;
  1172. if (pc^=#0) then
  1173. break;
  1174. inc(pc);
  1175. until false;
  1176. foundfile:=f;
  1177. end;
  1178. function FindExe(const bin:string;var foundfile:string):boolean;
  1179. var
  1180. p : pchar;
  1181. found : boolean;
  1182. begin
  1183. found:=FindFile(FixFileName(AddExtension(bin,source_info.exeext)),'.;'+exepath,foundfile);
  1184. if not found then
  1185. begin
  1186. {$ifdef macos}
  1187. p:=GetEnvPchar('Commands');
  1188. {$else}
  1189. p:=GetEnvPchar('PATH');
  1190. {$endif}
  1191. found:=FindFilePChar(FixFileName(AddExtension(bin,source_info.exeext)),p,foundfile);
  1192. FreeEnvPChar(p);
  1193. end;
  1194. FindExe:=found;
  1195. end;
  1196. function GetShortName(const n:string):string;
  1197. {$ifdef win32}
  1198. var
  1199. hs,hs2 : string;
  1200. i : longint;
  1201. {$endif}
  1202. {$ifdef go32v2}
  1203. var
  1204. hs : string;
  1205. {$endif}
  1206. {$ifdef watcom}
  1207. var
  1208. hs : string;
  1209. {$endif}
  1210. begin
  1211. GetShortName:=n;
  1212. {$ifdef win32}
  1213. hs:=n+#0;
  1214. i:=Windows.GetShortPathName(@hs[1],@hs2[1],high(hs2));
  1215. if (i>0) and (i<=high(hs2)) then
  1216. begin
  1217. hs2[0]:=chr(strlen(@hs2[1]));
  1218. GetShortName:=hs2;
  1219. end;
  1220. {$endif}
  1221. {$ifdef go32v2}
  1222. hs:=n;
  1223. if Dos.GetShortName(hs) then
  1224. GetShortName:=hs;
  1225. {$endif}
  1226. {$ifdef watcom}
  1227. hs:=n;
  1228. if Dos.GetShortName(hs) then
  1229. GetShortName:=hs;
  1230. {$endif}
  1231. end;
  1232. {****************************************************************************
  1233. OS Dependent things
  1234. ****************************************************************************}
  1235. function GetEnvPChar(const envname:string):pchar;
  1236. {$ifdef win32}
  1237. var
  1238. s : string;
  1239. i,len : longint;
  1240. hp,p,p2 : pchar;
  1241. {$endif}
  1242. begin
  1243. {$ifdef hasunix}
  1244. GetEnvPchar:={$ifdef havelinuxrtl10}Linux.getenv{$else}BaseUnix.fpGetEnv{$endif}(envname);
  1245. {$define GETENVOK}
  1246. {$endif}
  1247. {$ifdef win32}
  1248. GetEnvPchar:=nil;
  1249. p:=GetEnvironmentStrings;
  1250. hp:=p;
  1251. while hp^<>#0 do
  1252. begin
  1253. s:=strpas(hp);
  1254. i:=pos('=',s);
  1255. len:=strlen(hp);
  1256. if upper(copy(s,1,i-1))=upper(envname) then
  1257. begin
  1258. GetMem(p2,len-length(envname));
  1259. Move(hp[i],p2^,len-length(envname));
  1260. GetEnvPchar:=p2;
  1261. break;
  1262. end;
  1263. { next string entry}
  1264. hp:=hp+len+1;
  1265. end;
  1266. FreeEnvironmentStrings(p);
  1267. {$define GETENVOK}
  1268. {$endif}
  1269. {$ifdef os2}
  1270. GetEnvPChar := Dos.GetEnvPChar (EnvName);
  1271. {$define GETENVOK}
  1272. {$endif}
  1273. {$ifdef GETENVOK}
  1274. {$undef GETENVOK}
  1275. {$else}
  1276. GetEnvPchar:=StrPNew(Dos.Getenv(envname));
  1277. {$endif}
  1278. end;
  1279. procedure FreeEnvPChar(p:pchar);
  1280. begin
  1281. {$ifndef hasunix}
  1282. {$ifndef os2}
  1283. StrDispose(p);
  1284. {$endif}
  1285. {$endif}
  1286. end;
  1287. function Shell(const command:string): longint;
  1288. { This is already defined in the linux.ppu for linux, need for the *
  1289. expansion under linux }
  1290. {$ifdef hasunix}
  1291. begin
  1292. result := {$ifdef havelinuxrtl10}Linux{$else}Unix{$endif}.Shell(command);
  1293. end;
  1294. {$else}
  1295. {$ifdef amiga}
  1296. begin
  1297. {$IFDEF USE_SYSUTILS}
  1298. result := ExecuteProcess('',command);
  1299. {$ELSE USE_SYSUTILS}
  1300. exec('',command);
  1301. if (doserror <> 0) then
  1302. result := doserror
  1303. else
  1304. result := dosexitcode;
  1305. end;
  1306. {$ENDIF USE_SYSUTILS}
  1307. {$else}
  1308. var
  1309. comspec : string;
  1310. begin
  1311. comspec:=getenv('COMSPEC');
  1312. {$IFDEF USE_SYSUTILS}
  1313. result := ExecuteProcess(comspec,' /C '+command);
  1314. {$ELSE USE_SYSUTILS}
  1315. Exec(comspec,' /C '+command);
  1316. if (doserror <> 0) then
  1317. result := doserror
  1318. else
  1319. result := dosexitcode;
  1320. end;
  1321. {$ENDIF USE_SYSUTILS}
  1322. {$endif}
  1323. {$endif}
  1324. {$ifdef CPUI386}
  1325. {$define HASSETFPUEXCEPTIONMASK}
  1326. { later, this should be replaced by the math unit }
  1327. const
  1328. Default8087CW : word = $1332;
  1329. procedure Set8087CW(cw:word);assembler;
  1330. asm
  1331. movw cw,%ax
  1332. movw %ax,default8087cw
  1333. fnclex
  1334. fldcw default8087cw
  1335. end;
  1336. function Get8087CW:word;assembler;
  1337. asm
  1338. pushl $0
  1339. fnstcw (%esp)
  1340. popl %eax
  1341. end;
  1342. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1343. var
  1344. CtlWord: Word;
  1345. begin
  1346. CtlWord:=Get8087CW;
  1347. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  1348. end;
  1349. {$endif CPUI386}
  1350. {$ifdef CPUX86_64}
  1351. {$define HASSETFPUEXCEPTIONMASK}
  1352. { later, this should be replaced by the math unit }
  1353. const
  1354. Default8087CW : word = $1332;
  1355. procedure Set8087CW(cw:word);assembler;
  1356. asm
  1357. movw cw,%ax
  1358. movw %ax,default8087cw
  1359. fnclex
  1360. fldcw default8087cw
  1361. end;
  1362. function Get8087CW:word;assembler;
  1363. asm
  1364. pushq $0
  1365. fnstcw (%rsp)
  1366. popq %rax
  1367. end;
  1368. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1369. var
  1370. CtlWord: Word;
  1371. begin
  1372. CtlWord:=Get8087CW;
  1373. Set8087CW( (CtlWord and $FFC0) or Byte(Longint(Mask)) );
  1374. end;
  1375. {$endif CPUX86_64}
  1376. {$ifdef CPUPOWERPC}
  1377. {$define HASSETFPUEXCEPTIONMASK}
  1378. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1379. var
  1380. newmask: record
  1381. case byte of
  1382. 1: (d: double);
  1383. 2: (a,b: cardinal);
  1384. end;
  1385. begin
  1386. { load current control register contents }
  1387. asm
  1388. mffs f0
  1389. stfd f0,newmask.d
  1390. end;
  1391. { invalid operation: bit 24 (big endian, bit 0 = left-most bit) }
  1392. if (exInvalidOp in mask) then
  1393. newmask.b := newmask.b and not(1 shl (31-24))
  1394. else
  1395. newmask.b := newmask.b or (1 shl (31-24));
  1396. { denormals can not cause exceptions on the PPC }
  1397. { zero divide: bit 27 }
  1398. if (exZeroDivide in mask) then
  1399. newmask.b := newmask.b and not(1 shl (31-27))
  1400. else
  1401. newmask.b := newmask.b or (1 shl (31-27));
  1402. { overflow: bit 25 }
  1403. if (exOverflow in mask) then
  1404. newmask.b := newmask.b and not(1 shl (31-25))
  1405. else
  1406. newmask.b := newmask.b or (1 shl (31-25));
  1407. { underflow: bit 26 }
  1408. if (exUnderflow in mask) then
  1409. newmask.b := newmask.b and not(1 shl (31-26))
  1410. else
  1411. newmask.b := newmask.b or (1 shl (31-26));
  1412. { Precision (inexact result): bit 28 }
  1413. if (exPrecision in mask) then
  1414. newmask.b := newmask.b and not(1 shl (31-28))
  1415. else
  1416. newmask.b := newmask.b or (1 shl (31-28));
  1417. { update control register contents }
  1418. asm
  1419. lfd f0, newmask.d
  1420. mtfsf 255,f0
  1421. end;
  1422. end;
  1423. {$endif CPUPOWERPC}
  1424. {$ifdef CPUSPARC}
  1425. {$define HASSETFPUEXCEPTIONMASK}
  1426. procedure SetFPUExceptionMask(const Mask: TFPUExceptionMask);
  1427. var
  1428. fsr : cardinal;
  1429. begin
  1430. { load current control register contents }
  1431. asm
  1432. st %fsr,fsr
  1433. end;
  1434. { invalid operation: bit 27 }
  1435. if (exInvalidOp in mask) then
  1436. fsr:=fsr and not(1 shl 27)
  1437. else
  1438. fsr:=fsr or (1 shl 27);
  1439. { zero divide: bit 24 }
  1440. if (exZeroDivide in mask) then
  1441. fsr:=fsr and not(1 shl 24)
  1442. else
  1443. fsr:=fsr or (1 shl 24);
  1444. { overflow: bit 26 }
  1445. if (exOverflow in mask) then
  1446. fsr:=fsr and not(1 shl 26)
  1447. else
  1448. fsr:=fsr or (1 shl 26);
  1449. { underflow: bit 25 }
  1450. if (exUnderflow in mask) then
  1451. fsr:=fsr and not(1 shl 25)
  1452. else
  1453. fsr:=fsr or (1 shl 25);
  1454. { Precision (inexact result): bit 23 }
  1455. if (exPrecision in mask) then
  1456. fsr:=fsr and not(1 shl 23)
  1457. else
  1458. fsr:=fsr or (1 shl 23);
  1459. { update control register contents }
  1460. asm
  1461. ld fsr,%fsr
  1462. end;
  1463. end;
  1464. {$endif CPUSPARC}
  1465. {$ifndef HASSETFPUEXCEPTIONMASK}
  1466. function SetFPUExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;
  1467. begin
  1468. end;
  1469. {$endif HASSETFPUEXCEPTIONMASK}
  1470. function is_number_float(d : double) : boolean;
  1471. var
  1472. bytearray : array[0..7] of byte;
  1473. begin
  1474. move(d,bytearray,8);
  1475. { only 1.1 save, 1.0.x will use always little endian }
  1476. {$ifdef FPC_BIG_ENDIAN}
  1477. result:=((bytearray[0] and $7f)<>$7f) or ((bytearray[1] and $f0)<>$f0);
  1478. {$else FPC_BIG_ENDIAN}
  1479. result:=((bytearray[7] and $7f)<>$7f) or ((bytearray[6] and $f0)<>$f0);
  1480. {$endif FPC_BIG_ENDIAN}
  1481. end;
  1482. Function SetCompileMode(const s:string; changeInit: boolean):boolean;
  1483. var
  1484. b : boolean;
  1485. begin
  1486. b:=true;
  1487. if s='DEFAULT' then
  1488. aktmodeswitches:=initmodeswitches
  1489. else
  1490. if s='DELPHI' then
  1491. aktmodeswitches:=delphimodeswitches
  1492. else
  1493. if s='TP' then
  1494. aktmodeswitches:=tpmodeswitches
  1495. else
  1496. if s='FPC' then
  1497. aktmodeswitches:=fpcmodeswitches
  1498. else
  1499. if s='OBJFPC' then
  1500. aktmodeswitches:=objfpcmodeswitches
  1501. else
  1502. if s='GPC' then
  1503. aktmodeswitches:=gpcmodeswitches
  1504. else
  1505. if s='MACPAS' then
  1506. aktmodeswitches:=macmodeswitches
  1507. else
  1508. b:=false;
  1509. if b and changeInit then
  1510. initmodeswitches := aktmodeswitches;
  1511. if b then
  1512. begin
  1513. { turn ansistrings on by default ? }
  1514. if (m_delphi in aktmodeswitches) then
  1515. begin
  1516. include(aktlocalswitches,cs_ansistrings);
  1517. if changeinit then
  1518. include(initlocalswitches,cs_ansistrings);
  1519. end
  1520. else
  1521. begin
  1522. exclude(aktlocalswitches,cs_ansistrings);
  1523. if changeinit then
  1524. exclude(initlocalswitches,cs_ansistrings);
  1525. end;
  1526. { Default enum packing for delphi/tp7 }
  1527. if (m_tp7 in aktmodeswitches) or
  1528. (m_delphi in aktmodeswitches) then
  1529. aktpackenum:=1
  1530. else
  1531. aktpackenum:=4;
  1532. if changeinit then
  1533. initpackenum:=aktpackenum;
  1534. {$ifdef i386}
  1535. { Default to intel assembler for delphi/tp7 on i386 }
  1536. if (m_delphi in aktmodeswitches) or
  1537. (m_tp7 in aktmodeswitches) then
  1538. aktasmmode:=asmmode_i386_intel;
  1539. if changeinit then
  1540. initasmmode:=aktasmmode;
  1541. {$endif i386}
  1542. end;
  1543. SetCompileMode:=b;
  1544. end;
  1545. function SetAktProcCall(const s:string; changeInit:boolean):boolean;
  1546. const
  1547. DefProcCallName : array[tproccalloption] of string[12] = ('',
  1548. 'CDECL',
  1549. 'CPPDECL',
  1550. '', { compilerproc }
  1551. 'FAR16',
  1552. 'FPCCALL',
  1553. 'INLINE',
  1554. '', { internproc }
  1555. '', { syscall }
  1556. 'PASCAL',
  1557. 'REGISTER',
  1558. 'SAFECALL',
  1559. 'STDCALL',
  1560. 'SOFTFLOAT'
  1561. );
  1562. var
  1563. t : tproccalloption;
  1564. begin
  1565. result:=false;
  1566. for t:=low(tproccalloption) to high(tproccalloption) do
  1567. if DefProcCallName[t]=s then
  1568. begin
  1569. AktDefProcCall:=t;
  1570. result:=true;
  1571. break;
  1572. end;
  1573. if changeinit then
  1574. InitDefProcCall:=AktDefProcCall;
  1575. end;
  1576. function SetProcessor(const s:string; changeInit: boolean):boolean;
  1577. var
  1578. t : tprocessors;
  1579. begin
  1580. SetProcessor:=false;
  1581. for t:=low(tprocessors) to high(tprocessors) do
  1582. if processorsstr[t]=s then
  1583. begin
  1584. aktspecificoptprocessor:=t;
  1585. SetProcessor:=true;
  1586. break;
  1587. end;
  1588. if changeinit then
  1589. initspecificoptprocessor:=aktspecificoptprocessor;
  1590. end;
  1591. function SetFpuType(const s:string; changeInit: boolean):boolean;
  1592. var
  1593. t : tfputype;
  1594. begin
  1595. SetFpuType:=false;
  1596. for t:=low(tfputype) to high(tfputype) do
  1597. if fputypestr[t]=s then
  1598. begin
  1599. aktfputype:=t;
  1600. SetFpuType:=true;
  1601. break;
  1602. end;
  1603. if changeinit then
  1604. initfputype:=aktfputype;
  1605. end;
  1606. { '('D1:'00000000-'D2:'0000-'D3:'0000-'D4:'0000-000000000000)' }
  1607. function string2guid(const s: string; var GUID: TGUID): boolean;
  1608. function ishexstr(const hs: string): boolean;
  1609. var
  1610. i: integer;
  1611. begin
  1612. ishexstr:=false;
  1613. for i:=1 to Length(hs) do begin
  1614. if not (hs[i] in ['0'..'9','A'..'F','a'..'f']) then
  1615. exit;
  1616. end;
  1617. ishexstr:=true;
  1618. end;
  1619. function hexstr2longint(const hexs: string): longint;
  1620. var
  1621. i: integer;
  1622. rl: longint;
  1623. begin
  1624. rl:=0;
  1625. for i:=1 to length(hexs) do begin
  1626. rl:=rl shl 4;
  1627. case hexs[i] of
  1628. '0'..'9' : inc(rl,ord(hexs[i])-ord('0'));
  1629. 'A'..'F' : inc(rl,ord(hexs[i])-ord('A')+10);
  1630. 'a'..'f' : inc(rl,ord(hexs[i])-ord('a')+10);
  1631. end
  1632. end;
  1633. hexstr2longint:=rl;
  1634. end;
  1635. var
  1636. i: integer;
  1637. begin
  1638. if (Length(s)=38) and (s[1]='{') and (s[38]='}') and
  1639. (s[10]='-') and (s[15]='-') and (s[20]='-') and (s[25]='-') and
  1640. ishexstr(copy(s,2,8)) and ishexstr(copy(s,11,4)) and
  1641. ishexstr(copy(s,16,4)) and ishexstr(copy(s,21,4)) and
  1642. ishexstr(copy(s,26,12)) then begin
  1643. GUID.D1:=dword(hexstr2longint(copy(s,2,8)));
  1644. { these values are arealdy in the correct range (4 chars = word) }
  1645. GUID.D2:=word(hexstr2longint(copy(s,11,4)));
  1646. GUID.D3:=word(hexstr2longint(copy(s,16,4)));
  1647. for i:=0 to 1 do
  1648. GUID.D4[i]:=byte(hexstr2longint(copy(s,21+i*2,2)));
  1649. for i:=2 to 7 do
  1650. GUID.D4[i]:=byte(hexstr2longint(copy(s,22+i*2,2)));
  1651. string2guid:=true;
  1652. end
  1653. else
  1654. string2guid:=false;
  1655. end;
  1656. function guid2string(const GUID: TGUID): string;
  1657. function long2hex(l, len: longint): string;
  1658. const
  1659. hextbl: array[0..15] of char = '0123456789ABCDEF';
  1660. var
  1661. rs: string;
  1662. i: integer;
  1663. begin
  1664. rs[0]:=chr(len);
  1665. for i:=len downto 1 do begin
  1666. rs[i]:=hextbl[l and $F];
  1667. l:=l shr 4;
  1668. end;
  1669. long2hex:=rs;
  1670. end;
  1671. begin
  1672. guid2string:=
  1673. '{'+long2hex(GUID.D1,8)+
  1674. '-'+long2hex(GUID.D2,4)+
  1675. '-'+long2hex(GUID.D3,4)+
  1676. '-'+long2hex(GUID.D4[0],2)+long2hex(GUID.D4[1],2)+
  1677. '-'+long2hex(GUID.D4[2],2)+long2hex(GUID.D4[3],2)+
  1678. long2hex(GUID.D4[4],2)+long2hex(GUID.D4[5],2)+
  1679. long2hex(GUID.D4[6],2)+long2hex(GUID.D4[7],2)+
  1680. '}';
  1681. end;
  1682. function UpdateAlignmentStr(s:string;var a:talignmentinfo):boolean;
  1683. var
  1684. tok : string;
  1685. vstr : string;
  1686. l : longint;
  1687. code : integer;
  1688. b : talignmentinfo;
  1689. begin
  1690. UpdateAlignmentStr:=true;
  1691. uppervar(s);
  1692. fillchar(b,sizeof(b),0);
  1693. repeat
  1694. tok:=GetToken(s,'=');
  1695. if tok='' then
  1696. break;
  1697. vstr:=GetToken(s,',');
  1698. val(vstr,l,code);
  1699. if tok='PROC' then
  1700. b.procalign:=l
  1701. else if tok='JUMP' then
  1702. b.jumpalign:=l
  1703. else if tok='LOOP' then
  1704. b.loopalign:=l
  1705. else if tok='CONSTMIN' then
  1706. b.constalignmin:=l
  1707. else if tok='CONSTMAX' then
  1708. b.constalignmax:=l
  1709. else if tok='VARMIN' then
  1710. b.varalignmin:=l
  1711. else if tok='VARMAX' then
  1712. b.varalignmax:=l
  1713. else if tok='LOCALMIN' then
  1714. b.localalignmin:=l
  1715. else if tok='LOCALMAX' then
  1716. b.localalignmax:=l
  1717. else if tok='RECORDMIN' then
  1718. b.recordalignmin:=l
  1719. else if tok='RECORDMAX' then
  1720. b.recordalignmax:=l
  1721. else { Error }
  1722. UpdateAlignmentStr:=false;
  1723. until false;
  1724. UpdateAlignment(a,b);
  1725. end;
  1726. function var_align(siz: longint): longint;
  1727. begin
  1728. siz := size_2_align(siz);
  1729. var_align := used_align(siz,aktalignment.varalignmin,aktalignment.varalignmax);
  1730. end;
  1731. function const_align(siz: longint): longint;
  1732. begin
  1733. siz := size_2_align(siz);
  1734. const_align := used_align(siz,aktalignment.constalignmin,aktalignment.constalignmax);
  1735. end;
  1736. {****************************************************************************
  1737. Init
  1738. ****************************************************************************}
  1739. {$ifdef unix}
  1740. {$define need_path_search}
  1741. {$endif unix}
  1742. {$ifdef os2}
  1743. {$define need_path_search}
  1744. {$endif os2}
  1745. {$ifdef macos}
  1746. {$define need_path_search}
  1747. {$endif macos}
  1748. procedure get_exepath;
  1749. var
  1750. hs1 : namestr;
  1751. hs2 : extstr;
  1752. {$IFDEF USE_SYSUTILS}
  1753. exeName:String;
  1754. {$ENDIF USE_SYSUTILS}
  1755. {$ifdef need_path_search}
  1756. p : pchar;
  1757. {$endif need_path_search}
  1758. begin
  1759. {$IFDEF USE_SYSUTILS}
  1760. exepath:=GetEnvironmentVariable('PPC_EXEC_PATH');
  1761. {$ELSE USE_SYSUTILS}
  1762. exepath:=dos.getenv('PPC_EXEC_PATH');
  1763. {$ENDIF USE_SYSUTILS}
  1764. if exepath='' then
  1765. {$IFDEF USE_SYSUTILS}
  1766. exeName := FixFileName(system.paramstr(0));
  1767. exepath := ExtractFilePath(exeName);
  1768. hs1 := ExtractFileName(exeName);
  1769. hs2 := ExtractFileExt(exeName);
  1770. {$ELSE USE_SYSUTILS}
  1771. fsplit(FixFileName(system.paramstr(0)),exepath,hs1,hs2);
  1772. {$ENDIF USE_SYSUTILS}
  1773. {$ifdef need_path_search}
  1774. if exepath='' then
  1775. begin
  1776. if pos(source_info.exeext,hs1) <>
  1777. (length(hs1) - length(source_info.exeext)+1) then
  1778. hs1 := hs1 + source_info.exeext;
  1779. {$ifdef macos}
  1780. p:=GetEnvPchar('Commands');
  1781. {$else macos}
  1782. p:=GetEnvPchar('PATH');
  1783. {$endif macos}
  1784. FindFilePChar(hs1,p,exepath);
  1785. FreeEnvPChar(p);
  1786. exepath:=SplitPath(exepath);
  1787. end;
  1788. {$endif need_path_search}
  1789. exepath:=FixPath(exepath,false);
  1790. end;
  1791. procedure DoneGlobals;
  1792. begin
  1793. initdefines.free;
  1794. if assigned(DLLImageBase) then
  1795. StringDispose(DLLImageBase);
  1796. librarysearchpath.Free;
  1797. unitsearchpath.Free;
  1798. objectsearchpath.Free;
  1799. includesearchpath.Free;
  1800. end;
  1801. procedure InitGlobals;
  1802. begin
  1803. get_exepath;
  1804. { reset globals }
  1805. do_build:=false;
  1806. do_release:=false;
  1807. do_make:=true;
  1808. compile_level:=0;
  1809. DLLsource:=false;
  1810. inlining_procedure:=false;
  1811. resolving_forward:=false;
  1812. make_ref:=false;
  1813. LinkTypeSetExplicitly:=false;
  1814. { Output }
  1815. OutputFile:='';
  1816. OutputPrefix:=Nil;
  1817. OutputSuffix:=Nil;
  1818. OutputExtension:='';
  1819. OutputExeDir:='';
  1820. OutputUnitDir:='';
  1821. { Utils directory }
  1822. utilsdirectory:='';
  1823. utilsprefix:='';
  1824. cshared:=false;
  1825. rlinkpath:='';
  1826. { Search Paths }
  1827. librarysearchpath:=TSearchPathList.Create;
  1828. unitsearchpath:=TSearchPathList.Create;
  1829. includesearchpath:=TSearchPathList.Create;
  1830. objectsearchpath:=TSearchPathList.Create;
  1831. { Def file }
  1832. usewindowapi:=false;
  1833. description:='Compiled by FPC '+version_string+' - '+target_cpu_string;
  1834. DescriptionSetExplicity:=false;
  1835. dllversion:='';
  1836. dllmajor:=1;
  1837. dllminor:=0;
  1838. dllrevision:=0;
  1839. nwscreenname := '';
  1840. nwthreadname := '';
  1841. nwcopyright := '';
  1842. UseDeffileForExports:=false;
  1843. UseDeffileForExportsSetExplicitly:=false;
  1844. RelocSection:=false;
  1845. RelocSectionSetExplicitly:=false;
  1846. LinkTypeSetExplicitly:=false;
  1847. { Init values }
  1848. initmodeswitches:=fpcmodeswitches;
  1849. initlocalswitches:=[cs_check_io,cs_typed_const_writable];
  1850. initmoduleswitches:=[cs_extsyntax,cs_implicit_exceptions];
  1851. initsourcecodepage:='8859-1';
  1852. initglobalswitches:=[cs_check_unit_name,cs_link_static{$ifdef INTERNALLINKER},cs_link_internal,cs_link_map{$endif}];
  1853. initoutputformat:=target_asm.id;
  1854. fillchar(initalignment,sizeof(talignmentinfo),0);
  1855. { might be overridden later }
  1856. initasmmode:=asmmode_standard;
  1857. {$ifdef i386}
  1858. initoptprocessor:=ClassPentium3;
  1859. initspecificoptprocessor:=Class386;
  1860. initfputype:=fpu_x87;
  1861. initpackenum:=4;
  1862. {$IFDEF testvarsets}
  1863. initsetalloc:=0;
  1864. {$ENDIF}
  1865. initasmmode:=asmmode_i386_att;
  1866. {$endif i386}
  1867. {$ifdef m68k}
  1868. initoptprocessor:=MC68020;
  1869. initpackenum:=4;
  1870. {$IFDEF testvarsets}
  1871. initsetalloc:=0;
  1872. {$ENDIF}
  1873. {$endif m68k}
  1874. {$ifdef powerpc}
  1875. initoptprocessor:=PPC604;
  1876. initpackenum:=4;
  1877. {$IFDEF testvarsets}
  1878. initsetalloc:=0;
  1879. {$ENDIF}
  1880. initfputype:=fpu_standard;
  1881. {$endif powerpc}
  1882. {$ifdef sparc}
  1883. initoptprocessor:=SPARC_V8;
  1884. initpackenum:=4;
  1885. {$IFDEF testvarsets}
  1886. initsetalloc:=0;
  1887. {$ENDIF}
  1888. {$endif sparc}
  1889. {$ifdef arm}
  1890. initpackenum:=4;
  1891. {$IFDEF testvarsets}
  1892. initsetalloc:=0;
  1893. {$ENDIF}
  1894. initfputype:=fpu_fpa;
  1895. {$endif arm}
  1896. {$ifdef x86_64}
  1897. initoptprocessor:=ClassAthlon64;
  1898. initspecificoptprocessor:=ClassAthlon64;
  1899. initfputype:=fpu_sse64;
  1900. initpackenum:=4;
  1901. {$IFDEF testvarsets}
  1902. initsetalloc:=0;
  1903. {$ENDIF}
  1904. initasmmode:=asmmode_x86_64_gas;
  1905. {$endif x86_64}
  1906. initinterfacetype:=it_interfacecom;
  1907. initdefproccall:=pocall_default;
  1908. initdefines:=TStringList.Create;
  1909. { memory sizes, will be overriden by parameter or default for target
  1910. in options or init_parser }
  1911. stacksize:=0;
  1912. apptype:=app_cui;
  1913. end;
  1914. end.
  1915. {
  1916. $Log$
  1917. Revision 1.150 2004-10-31 18:54:24 peter
  1918. * $fpctarget expands to <cpu>-<os>
  1919. * allow * in middle of the path to support ../*/units/$fpctarget
  1920. Revision 1.149 2004/10/26 15:11:01 peter
  1921. * -Ch for heapsize added again
  1922. * __heapsize contains the heapsize
  1923. Revision 1.148 2004/10/25 15:38:41 peter
  1924. * heap and heapsize removed
  1925. * checkpointer fixes
  1926. Revision 1.147 2004/10/16 22:46:14 olle
  1927. * Fixed printing of filedates
  1928. Revision 1.146 2004/10/16 13:03:13 olle
  1929. + added more support for macos
  1930. Revision 1.145 2004/10/15 09:14:16 mazen
  1931. - remove $IFDEF DELPHI and related code
  1932. - remove $IFDEF FPCPROCVAR and related code
  1933. Revision 1.144 2004/10/14 18:16:17 mazen
  1934. * USE_SYSUTILS merged successfully : cycles with and without defines
  1935. * Need to be optimized in performance
  1936. Revision 1.143 2004/10/10 15:42:22 peter
  1937. * default optimization cpu changed to CLassPentium3
  1938. Revision 1.142 2004/10/09 11:27:59 olle
  1939. + Added CurDirRelPath
  1940. * Exchanged hardcoded "./" to CurDirRelPath
  1941. Revision 1.141 2004/09/21 23:33:43 hajny
  1942. * better PathExists, fix for too long command line, correction of message
  1943. Revision 1.140 2004/09/21 19:59:51 peter
  1944. * x86_64 fixes
  1945. * cleanup of fpcdefs.icn
  1946. Revision 1.139 2004/09/21 17:25:12 peter
  1947. * paraloc branch merged
  1948. Revision 1.138 2004/09/08 11:23:31 michael
  1949. + Check if outputdir exists, Fix exitcode when displaying help pages
  1950. Revision 1.137 2004/08/31 22:02:30 olle
  1951. + support for quoting of paths in TSearchPathList.AddPath so that
  1952. compiler directives which take paths, will support quotes.
  1953. * uppdated TranslateMacPath
  1954. Revision 1.136.4.2 2004/09/12 18:31:26 peter
  1955. * fpu exception support for sparc and x86_64
  1956. Revision 1.136.4.1 2004/09/12 15:30:16 peter
  1957. * cache currentdir
  1958. Revision 1.136 2004/08/28 20:25:25 peter
  1959. * optimized search for noncasesensitive names. It now searches
  1960. first for NormalCase and skips double tests
  1961. Revision 1.135 2004/08/20 10:29:31 olle
  1962. + made fpc work as an MPW tool, by itself calling asm and link.
  1963. * bugfix in fp exception flag settings routine
  1964. Revision 1.134 2004/08/02 07:15:54 michael
  1965. + Patch from Christian Iversen to implement LIBPREFIX/SUFFIX/EXTENSION directives
  1966. Revision 1.133 2004/07/17 15:51:57 jonas
  1967. * shell now returns an exitcode
  1968. * print an error if linking failed when linking was done using a script
  1969. Revision 1.132 2004/07/05 23:28:24 olle
  1970. + FixFileName now handles Mac OS paths
  1971. Revision 1.131 2004/06/20 08:55:29 florian
  1972. * logs truncated
  1973. Revision 1.130 2004/06/16 20:07:07 florian
  1974. * dwarf branch merged
  1975. Revision 1.129 2004/05/11 18:20:52 olle
  1976. * changed $mode mac to $mode macpas
  1977. * changed macmodeswitches to be more faithful to the mac dialect
  1978. Revision 1.128 2004/04/29 19:56:36 daniel
  1979. * Prepare compiler infrastructure for multiple ansistring types
  1980. Revision 1.127 2004/04/28 15:19:03 florian
  1981. + syscall directive support for MorphOS added
  1982. Revision 1.126.2.4 2004/05/09 15:47:21 peter
  1983. * fix typecast from word->set
  1984. }