globals.pas 63 KB

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