globals.pas 62 KB

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