options.pas 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl and Peter Vreman
  3. Reads command line options and config files
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit options;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,globals,verbose,systems,cpuinfo;
  22. type
  23. TOption=class
  24. FirstPass,
  25. ParaLogo,
  26. NoPressEnter,
  27. LogoWritten : boolean;
  28. FileLevel : longint;
  29. QuickInfo : string;
  30. ParaIncludePath,
  31. ParaUnitPath,
  32. ParaObjectPath,
  33. ParaLibraryPath : TSearchPathList;
  34. ParaAlignment : TAlignmentInfo;
  35. Constructor Create;
  36. Destructor Destroy;override;
  37. procedure WriteLogo;
  38. procedure WriteInfo;
  39. procedure WriteHelpPages;
  40. procedure WriteQuickInfo;
  41. procedure IllegalPara(const opt:string);
  42. function Unsetbool(var Opts:string; Pos: Longint):boolean;
  43. procedure interpret_option(const opt :string;ispara:boolean);
  44. procedure Interpret_envvar(const envname : string);
  45. procedure Interpret_file(const filename : string);
  46. procedure Read_Parameters;
  47. procedure parsecmd(cmd:string);
  48. procedure TargetDefines(def:boolean);
  49. end;
  50. TOptionClass=class of toption;
  51. var
  52. coption : TOptionClass;
  53. procedure read_arguments(cmd:string);
  54. implementation
  55. uses
  56. widestr,
  57. {$IFDEF USE_SYSUTILS}
  58. SysUtils,
  59. {$ELSE USE_SYSUTILS}
  60. dos,
  61. {$ENDIF USE_SYSUTILS}
  62. version,
  63. cutils,cmsgs,
  64. comphook,
  65. symtable,scanner,rabase
  66. {$ifdef BrowserLog}
  67. ,browlog
  68. {$endif BrowserLog}
  69. ;
  70. const
  71. page_size = 24;
  72. var
  73. option : toption;
  74. read_configfile, { read config file, set when a cfgfile is found }
  75. disable_configfile : boolean;
  76. fpcdir,
  77. ppccfg,
  78. ppcaltcfg,
  79. param_file : string; { file to compile specified on the commandline }
  80. {****************************************************************************
  81. Defines
  82. ****************************************************************************}
  83. procedure set_default_link_type;
  84. begin
  85. { win32 and wdosx need smartlinking by default to prevent including too much
  86. dll dependencies }
  87. if not(cs_link_internal in initglobalswitches) and
  88. (target_info.system in [system_i386_win32,system_i386_wdosx]) then
  89. begin
  90. def_system_macro('FPC_LINK_SMART');
  91. undef_system_macro('FPC_LINK_STATIC');
  92. undef_system_macro('FPC_LINK_DYNAMIC');
  93. initglobalswitches:=initglobalswitches+[cs_link_smart];
  94. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_static];
  95. end
  96. else
  97. begin
  98. undef_system_macro('FPC_LINK_SMART');
  99. def_system_macro('FPC_LINK_STATIC');
  100. undef_system_macro('FPC_LINK_DYNAMIC');
  101. initglobalswitches:=initglobalswitches+[cs_link_static];
  102. initglobalswitches:=initglobalswitches-[cs_link_shared,cs_link_smart];
  103. end;
  104. end;
  105. {****************************************************************************
  106. Toption
  107. ****************************************************************************}
  108. procedure StopOptions(err:longint);
  109. begin
  110. if assigned(Option) then
  111. begin
  112. Option.free;
  113. Option:=nil;
  114. end;
  115. raise ECompilerAbortSilent.Create;
  116. end;
  117. procedure Toption.WriteLogo;
  118. var
  119. p : pchar;
  120. begin
  121. if not LogoWritten then
  122. begin
  123. p:=MessagePchar(option_logo);
  124. while assigned(p) do
  125. Comment(V_Normal,GetMsgLine(p));
  126. LogoWritten:= true;
  127. end;
  128. end;
  129. procedure Toption.WriteInfo;
  130. var
  131. p : pchar;
  132. hs,hs1,s : TCmdStr;
  133. target : tsystem;
  134. cpu : tcputype;
  135. fpu : tfputype;
  136. opt : toptimizerswitch;
  137. begin
  138. p:=MessagePchar(option_info);
  139. while assigned(p) do
  140. begin
  141. s:=GetMsgLine(p);
  142. { list OS Targets }
  143. if pos('$OSTARGETS',s)>0 then
  144. begin
  145. for target:=low(tsystem) to high(tsystem) do
  146. if assigned(targetinfos[target]) then
  147. begin
  148. hs:=s;
  149. hs1:=targetinfos[target]^.name;
  150. if tf_under_development in targetinfos[target]^.flags then
  151. hs1:=hs1+' (under development)';
  152. Replace(hs,'$OSTARGETS',hs1);
  153. Comment(V_Normal,hs);
  154. end;
  155. end
  156. else if pos('$INSTRUCTIONSETS',s)>0 then
  157. begin
  158. for cpu:=low(tcputype) to high(tcputype) do
  159. begin
  160. hs:=s;
  161. hs1:=cputypestr[cpu];
  162. if hs1<>'' then
  163. begin
  164. Replace(hs,'$INSTRUCTIONSETS',hs1);
  165. Comment(V_Normal,hs);
  166. end;
  167. end;
  168. end
  169. else if pos('$FPUINSTRUCTIONSETS',s)>0 then
  170. begin
  171. for fpu:=low(tfputype) to high(tfputype) do
  172. begin
  173. hs:=s;
  174. hs1:=fputypestr[fpu];
  175. if hs1<>'' then
  176. begin
  177. Replace(hs,'$FPUINSTRUCTIONSETS',hs1);
  178. Comment(V_Normal,hs);
  179. end;
  180. end;
  181. end
  182. else if pos('$OPTIMIZATIONS',s)>0 then
  183. begin
  184. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  185. begin
  186. if opt in supported_optimizerswitches then
  187. begin
  188. hs:=s;
  189. hs1:=OptimizerSwitchStr[opt];
  190. if hs1<>'' then
  191. begin
  192. Replace(hs,'$OPTIMIZATIONS',hs1);
  193. Comment(V_Normal,hs);
  194. end;
  195. end;
  196. end;
  197. end
  198. else
  199. Comment(V_Normal,s);
  200. end;
  201. StopOptions(0);
  202. end;
  203. procedure Toption.WriteHelpPages;
  204. function PadEnd(s:string;i:longint):string;
  205. begin
  206. while (length(s)<i) do
  207. s:=s+' ';
  208. PadEnd:=s;
  209. end;
  210. var
  211. lastident,
  212. j,outline,
  213. ident,
  214. lines : longint;
  215. show : boolean;
  216. opt : string[32];
  217. input,
  218. s : string;
  219. p : pchar;
  220. begin
  221. WriteLogo;
  222. Lines:=4;
  223. Message1(option_usage,FixFileName(system.paramstr(0)));
  224. lastident:=0;
  225. p:=MessagePChar(option_help_pages);
  226. while assigned(p) do
  227. begin
  228. { get a line and reset }
  229. s:=GetMsgLine(p);
  230. ident:=0;
  231. show:=false;
  232. { parse options }
  233. case s[1] of
  234. {$ifdef UNITALIASES}
  235. 'a',
  236. {$endif}
  237. {$ifdef EXTDEBUG}
  238. 'e',
  239. {$endif EXTDEBUG}
  240. {$ifdef i386}
  241. '3',
  242. {$endif}
  243. {$ifdef x86_64}
  244. '4',
  245. {$endif}
  246. {$ifdef m68k}
  247. '6',
  248. {$endif}
  249. {$ifdef arm}
  250. 'A',
  251. {$endif}
  252. {$ifdef powerpc}
  253. 'P',
  254. {$endif}
  255. {$ifdef sparc}
  256. 'S',
  257. {$endif}
  258. {$ifdef vis}
  259. 'V',
  260. {$endif}
  261. '*' : show:=true;
  262. end;
  263. if show then
  264. begin
  265. case s[2] of
  266. 'g',
  267. {$ifdef Unix}
  268. 'L',
  269. {$endif}
  270. {$ifdef os2}
  271. 'O',
  272. {$endif}
  273. '*' : show:=true;
  274. else
  275. show:=false;
  276. end;
  277. end;
  278. { now we may show the message or not }
  279. if show then
  280. begin
  281. case s[3] of
  282. '0' : begin
  283. ident:=0;
  284. outline:=0;
  285. end;
  286. '1' : begin
  287. ident:=2;
  288. outline:=7;
  289. end;
  290. '2' : begin
  291. ident:=6;
  292. outline:=11;
  293. end;
  294. '3' : begin
  295. ident:=9;
  296. outline:=11;
  297. end;
  298. end;
  299. j:=pos('_',s);
  300. opt:=Copy(s,4,j-4);
  301. if opt='*' then
  302. opt:=''
  303. else
  304. if opt=' ' then
  305. opt:=PadEnd(opt,outline)
  306. else
  307. opt:=PadEnd('-'+opt,outline);
  308. if (ident=0) and (lastident<>0) then
  309. begin
  310. Comment(V_Normal,'');
  311. inc(Lines);
  312. end;
  313. { page full ? }
  314. if (lines >= page_size - 1) then
  315. begin
  316. if not NoPressEnter then
  317. begin
  318. Message(option_help_press_enter);
  319. readln(input);
  320. if upper(input)='Q' then
  321. StopOptions(0);
  322. end;
  323. lines:=0;
  324. end;
  325. Comment(V_Normal,PadEnd('',ident)+opt+Copy(s,j+1,255));
  326. LastIdent:=Ident;
  327. inc(Lines);
  328. end;
  329. end;
  330. StopOptions(0);
  331. end;
  332. procedure Toption.IllegalPara(const opt:string);
  333. begin
  334. Message1(option_illegal_para,opt);
  335. Message(option_help_pages_para);
  336. StopOptions(1);
  337. end;
  338. function Toption.Unsetbool(var Opts:string; Pos: Longint):boolean;
  339. { checks if the character after pos in Opts is a + or a - and returns resp.
  340. false or true. If it is another character (or none), it also returns false }
  341. begin
  342. UnsetBool := false;
  343. if Length(Opts)>Pos then
  344. begin
  345. inc(Pos);
  346. UnsetBool := Opts[Pos] = '-';
  347. if Opts[Pos] in ['-','+']then
  348. delete(Opts,Pos,1);
  349. end;
  350. end;
  351. procedure TOption.interpret_option(const opt:string;ispara:boolean);
  352. var
  353. code : integer;
  354. c : char;
  355. more : string;
  356. major,minor : longint;
  357. error : integer;
  358. j,l : longint;
  359. d : DirStr;
  360. s : string;
  361. begin
  362. if opt='' then
  363. exit;
  364. { only parse define,undef,target,verbosity,link etc options the firsttime }
  365. if firstpass and
  366. not(
  367. (opt[1]='-') and
  368. (
  369. ((length(opt)>1) and (opt[2] in ['i','d','v','T','u','n','X','l'])) or
  370. ((length(opt)>3) and (opt[2]='F') and (opt[3]='e'))
  371. )
  372. ) then
  373. exit;
  374. Message1(option_handling_option,opt);
  375. case opt[1] of
  376. '-' :
  377. begin
  378. more:=Copy(opt,3,255);
  379. if firstpass then
  380. Message1(option_interpreting_firstpass_option,opt)
  381. else
  382. Message1(option_interpreting_option,opt);
  383. case opt[2] of
  384. '?' :
  385. WriteHelpPages;
  386. 'a' :
  387. begin
  388. include(initglobalswitches,cs_asm_leave);
  389. j:=1;
  390. while j<=length(more) do
  391. begin
  392. case more[j] of
  393. 'l' :
  394. include(initglobalswitches,cs_asm_source);
  395. 'r' :
  396. include(initglobalswitches,cs_asm_regalloc);
  397. 't' :
  398. include(initglobalswitches,cs_asm_tempalloc);
  399. 'n' :
  400. include(initglobalswitches,cs_asm_nodes);
  401. 'p' :
  402. begin
  403. exclude(initglobalswitches,cs_asm_leave);
  404. if UnsetBool(More, 0) then
  405. exclude(initglobalswitches,cs_asm_pipe)
  406. else
  407. include(initglobalswitches,cs_asm_pipe);
  408. end;
  409. '-' :
  410. initglobalswitches:=initglobalswitches -
  411. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc,
  412. cs_asm_nodes, cs_asm_pipe];
  413. else
  414. IllegalPara(opt);
  415. end;
  416. inc(j);
  417. end;
  418. end;
  419. 'A' :
  420. begin
  421. paratargetasm:=find_asm_by_string(More);
  422. if paratargetasm=as_none then
  423. IllegalPara(opt);
  424. end;
  425. 'b' :
  426. begin
  427. {$ifdef supportbrowser}
  428. if UnsetBool(More,0) then
  429. begin
  430. exclude(initmoduleswitches,cs_browser);
  431. exclude(initmoduleswitches,cs_local_browser);
  432. {$ifdef BrowserLog}
  433. exclude(initglobalswitches,cs_browser_log);
  434. {$endif}
  435. end
  436. else
  437. begin
  438. include(initmoduleswitches,cs_browser);
  439. {$ifdef BrowserLog}
  440. include(initglobalswitches,cs_browser_log);
  441. {$endif}
  442. end;
  443. if More<>'' then
  444. if (More='l') or (More='l+') then
  445. include(initmoduleswitches,cs_local_browser)
  446. else
  447. if More='l-' then
  448. exclude(initmoduleswitches,cs_local_browser)
  449. else
  450. {$ifdef BrowserLog}
  451. browserlog.elements_to_list.insert(more);
  452. {$else}
  453. IllegalPara(opt);
  454. {$endif}
  455. {$endif supportbrowser}
  456. end;
  457. 'B' :
  458. do_build:=not UnSetBool(more,0);
  459. 'C' :
  460. begin
  461. j:=1;
  462. while j<=length(more) do
  463. begin
  464. case more[j] of
  465. 'c' :
  466. begin
  467. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),initdefproccall) then
  468. IllegalPara(opt);
  469. break;
  470. end;
  471. {$ifdef cpufpemu}
  472. 'e' :
  473. begin
  474. If UnsetBool(More, j) then
  475. exclude(initmoduleswitches,cs_fp_emulation)
  476. Else
  477. include(initmoduleswitches,cs_fp_emulation);
  478. end;
  479. {$endif cpufpemu}
  480. 'f' :
  481. begin
  482. s:=upper(copy(more,j+1,length(more)-j));
  483. if not(SetFpuType(s,initfputype)) then
  484. IllegalPara(opt);
  485. break;
  486. end;
  487. 'g' :
  488. include(initmoduleswitches,cs_create_pic);
  489. 'h' :
  490. begin
  491. val(copy(more,j+1,length(more)-j),heapsize,code);
  492. if (code<>0) or (heapsize<1024) then
  493. IllegalPara(opt);
  494. break;
  495. end;
  496. 'i' :
  497. If UnsetBool(More, j) then
  498. exclude(initlocalswitches,cs_check_io)
  499. else
  500. include(initlocalswitches,cs_check_io);
  501. 'n' :
  502. If UnsetBool(More, j) then
  503. exclude(initglobalswitches,cs_link_extern)
  504. Else
  505. include(initglobalswitches,cs_link_extern);
  506. 'o' :
  507. If UnsetBool(More, j) then
  508. exclude(initlocalswitches,cs_check_overflow)
  509. Else
  510. include(initlocalswitches,cs_check_overflow);
  511. 'p' :
  512. begin
  513. s:=upper(copy(more,j+1,length(more)-j));
  514. if not(Setcputype(s,initcputype)) then
  515. IllegalPara(opt);
  516. break;
  517. end;
  518. 'r' :
  519. If UnsetBool(More, j) then
  520. exclude(initlocalswitches,cs_check_range)
  521. Else
  522. include(initlocalswitches,cs_check_range);
  523. 'R' :
  524. If UnsetBool(More, j) then
  525. begin
  526. exclude(initlocalswitches,cs_check_range);
  527. exclude(initlocalswitches,cs_check_object);
  528. end
  529. Else
  530. begin
  531. include(initlocalswitches,cs_check_range);
  532. include(initlocalswitches,cs_check_object);
  533. end;
  534. 's' :
  535. begin
  536. val(copy(more,j+1,length(more)-j),stacksize,code);
  537. if (code<>0) or (stacksize>=67107840) or (stacksize<1024) then
  538. IllegalPara(opt);
  539. break;
  540. end;
  541. 't' :
  542. If UnsetBool(More, j) then
  543. exclude(initlocalswitches,cs_check_stack)
  544. Else
  545. include(initlocalswitches,cs_check_stack);
  546. 'D' :
  547. If UnsetBool(More, j) then
  548. exclude(initmoduleswitches,cs_create_dynamic)
  549. Else
  550. include(initmoduleswitches,cs_create_dynamic);
  551. 'X' :
  552. If UnsetBool(More, j) then
  553. exclude(initmoduleswitches,cs_create_smart)
  554. Else
  555. include(initmoduleswitches,cs_create_smart);
  556. else
  557. IllegalPara(opt);
  558. end;
  559. inc(j);
  560. end;
  561. end;
  562. 'd' :
  563. if more <> '' then
  564. begin
  565. l:=Pos(':=',more);
  566. if l>0 then
  567. set_system_compvar(Copy(more,1,l-1),Copy(more,l+2,255))
  568. else
  569. def_system_macro(more);
  570. end;
  571. 'D' :
  572. begin
  573. include(initglobalswitches,cs_link_deffile);
  574. j:=1;
  575. while j<=length(more) do
  576. begin
  577. case more[j] of
  578. 'd' :
  579. begin
  580. description:=Copy(more,j+1,255);
  581. break;
  582. end;
  583. 'v' :
  584. begin
  585. dllversion:=Copy(more,j+1,255);
  586. l:=pos('.',dllversion);
  587. dllminor:=0;
  588. error:=0;
  589. if l>0 then
  590. begin
  591. val(copy(dllversion,l+1,255),minor,error);
  592. if (error=0) and
  593. (minor>=0) and (minor<=$ffff) then
  594. dllminor:=minor
  595. else
  596. if error=0 then
  597. error:=1;
  598. end;
  599. if l=0 then
  600. l:=256;
  601. dllmajor:=1;
  602. if error=0 then
  603. val(copy(dllversion,1,l-1),major,error);
  604. if (error=0) and (major>=0) and (major<=$ffff) then
  605. dllmajor:=major
  606. else
  607. if error=0 then
  608. error:=1;
  609. if error<>0 then
  610. Message1(scan_w_wrong_version_ignored,dllversion);
  611. break;
  612. end;
  613. 'w' :
  614. usewindowapi:=true;
  615. '-' :
  616. begin
  617. exclude(initglobalswitches,cs_link_deffile);
  618. usewindowapi:=false;
  619. end;
  620. else
  621. IllegalPara(opt);
  622. end;
  623. inc(j);
  624. end;
  625. end;
  626. 'e' :
  627. exepath:=FixPath(More,true);
  628. 'E' :
  629. begin
  630. if UnsetBool(More, 0) then
  631. exclude(initglobalswitches,cs_link_extern)
  632. else
  633. include(initglobalswitches,cs_link_extern);
  634. end;
  635. 'F' :
  636. begin
  637. c:=more[1];
  638. Delete(more,1,1);
  639. DefaultReplacements(More);
  640. case c of
  641. 'a' :
  642. autoloadunits:=more;
  643. 'c' :
  644. begin
  645. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  646. initsourcecodepage:='utf8'
  647. else if not(cpavailable(more)) then
  648. Message1(option_code_page_not_available,more)
  649. else
  650. initsourcecodepage:=more;
  651. end;
  652. 'D' :
  653. utilsdirectory:=FixPath(More,true);
  654. 'e' :
  655. SetRedirectFile(More);
  656. 'E' :
  657. OutputExeDir:=FixPath(More,true);
  658. 'i' :
  659. begin
  660. if ispara then
  661. ParaIncludePath.AddPath(More,false)
  662. else
  663. includesearchpath.AddPath(More,true);
  664. end;
  665. 'g' :
  666. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  667. 'l' :
  668. begin
  669. if ispara then
  670. ParaLibraryPath.AddPath(More,false)
  671. else
  672. LibrarySearchPath.AddPath(More,true);
  673. end;
  674. 'L' :
  675. begin
  676. if More<>'' then
  677. ParaDynamicLinker:=More
  678. else
  679. IllegalPara(opt);
  680. end;
  681. 'o' :
  682. begin
  683. if ispara then
  684. ParaObjectPath.AddPath(More,false)
  685. else
  686. ObjectSearchPath.AddPath(More,true);
  687. end;
  688. 'r' :
  689. Msgfilename:=More;
  690. 'u' :
  691. begin
  692. if ispara then
  693. ParaUnitPath.AddPath(More,false)
  694. else
  695. unitsearchpath.AddPath(More,true);
  696. end;
  697. 'U' :
  698. OutputUnitDir:=FixPath(More,true);
  699. else
  700. IllegalPara(opt);
  701. end;
  702. end;
  703. 'g' : begin
  704. if UnsetBool(More, 0) then
  705. begin
  706. exclude(initmoduleswitches,cs_debuginfo);
  707. exclude(initglobalswitches,cs_use_heaptrc);
  708. exclude(initglobalswitches,cs_use_lineinfo);
  709. exclude(initlocalswitches,cs_checkpointer);
  710. end
  711. else
  712. begin
  713. include(initmoduleswitches,cs_debuginfo);
  714. end;
  715. if not RelocSectionSetExplicitly then
  716. RelocSection:=false;
  717. j:=1;
  718. while j<=length(more) do
  719. begin
  720. case more[j] of
  721. 'c' :
  722. begin
  723. if UnsetBool(More, j) then
  724. exclude(initlocalswitches,cs_checkpointer)
  725. else
  726. include(initlocalswitches,cs_checkpointer);
  727. end;
  728. 'd' :
  729. begin
  730. paratargetdbg:=dbg_dwarf;
  731. end;
  732. 'h' :
  733. begin
  734. if UnsetBool(More, j) then
  735. exclude(initglobalswitches,cs_use_heaptrc)
  736. else
  737. include(initglobalswitches,cs_use_heaptrc);
  738. end;
  739. 'l' :
  740. begin
  741. if UnsetBool(More, j) then
  742. exclude(initglobalswitches,cs_use_lineinfo)
  743. else
  744. include(initglobalswitches,cs_use_lineinfo);
  745. end;
  746. 's' :
  747. begin
  748. paratargetdbg:=dbg_stabs;
  749. end;
  750. 'v' :
  751. begin
  752. if UnsetBool(More, j) then
  753. exclude(initglobalswitches,cs_gdb_valgrind)
  754. else
  755. include(initglobalswitches,cs_gdb_valgrind);
  756. end;
  757. 'w' :
  758. begin
  759. paratargetdbg:=dbg_dwarf;
  760. end;
  761. else
  762. IllegalPara(opt);
  763. end;
  764. inc(j);
  765. end;
  766. end;
  767. 'h' :
  768. begin
  769. NoPressEnter:=true;
  770. WriteHelpPages;
  771. end;
  772. 'i' :
  773. begin
  774. if More='' then
  775. WriteInfo
  776. else
  777. QuickInfo:=QuickInfo+More;
  778. end;
  779. 'I' :
  780. begin
  781. if ispara then
  782. ParaIncludePath.AddPath(More,false)
  783. else
  784. includesearchpath.AddPath(More,false);
  785. end;
  786. 'k' :
  787. begin
  788. if more<>'' then
  789. ParaLinkOptions:=ParaLinkOptions+' '+More
  790. else
  791. IllegalPara(opt);
  792. end;
  793. 'l' :
  794. if not UnSetBool(more,0) then
  795. ParaLogo:=true;
  796. 'm' :
  797. parapreprocess:=not UnSetBool(more,0);
  798. 'M' :
  799. begin
  800. more:=Upper(more);
  801. if not SetCompileMode(more, true) then
  802. IllegalPara(opt);
  803. end;
  804. 'n' :
  805. begin
  806. if More='' then
  807. disable_configfile:=true
  808. else
  809. IllegalPara(opt);
  810. end;
  811. 'o' :
  812. begin
  813. if More<>'' then
  814. begin
  815. {$IFDEF USE_SYSUTILS}
  816. D:=SplitPath(More);
  817. OutputFile:=SplitFileName(More);
  818. OutputExtension:=SplitExtension(More);
  819. {$ELSE USE_SYSUTILS}
  820. FSplit(More,D,OutputFile,OutputExtension);
  821. {$ENDIF USE_SYSUTILS}
  822. if (D<>'') then
  823. OutputExeDir:=FixPath(D,True);
  824. end
  825. else
  826. IllegalPara(opt);
  827. end;
  828. 'O' :
  829. begin
  830. j:=1;
  831. while j<=length(more) do
  832. begin
  833. case more[j] of
  834. '1' :
  835. initoptimizerswitches:=initoptimizerswitches+level1optimizerswitches;
  836. '2' :
  837. initoptimizerswitches:=initoptimizerswitches+level2optimizerswitches;
  838. '3' :
  839. initoptimizerswitches:=initoptimizerswitches+level3optimizerswitches;
  840. 'a' :
  841. begin
  842. if not(UpdateAlignmentStr(Copy(Opt,j+1,255),ParaAlignment)) then
  843. IllegalPara(opt);
  844. break;
  845. end;
  846. 's' :
  847. include(initoptimizerswitches,cs_opt_size);
  848. 'p' :
  849. begin
  850. if not Setcputype(copy(more,j+1,length(more)),initoptimizecputype) then
  851. begin
  852. { Give warning for old i386 switches }
  853. if (Length(More)-j=1) and
  854. (More[j+1]>='1') and (More[j+1]<='5')then
  855. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  856. else
  857. IllegalPara(opt);
  858. end;
  859. break;
  860. end;
  861. 'o' :
  862. begin
  863. if not UpdateOptimizerStr(copy(more,j+1,length(more)),initoptimizerswitches) then
  864. IllegalPara(opt);
  865. break;
  866. end;
  867. '-' :
  868. begin
  869. initoptimizerswitches:=[];
  870. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  871. end;
  872. { Obsolete switches }
  873. 'g' :
  874. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  875. 'G' :
  876. Message1(option_obsolete_switch,'-OG');
  877. 'r' :
  878. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  879. 'u' :
  880. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  881. else
  882. IllegalPara(opt);
  883. end;
  884. inc(j);
  885. end;
  886. end;
  887. 'p' :
  888. begin
  889. if UnsetBool(More, 0) then
  890. begin
  891. initmoduleswitches:=initmoduleswitches-[cs_profile];
  892. undef_system_macro('FPC_PROFILE');
  893. end
  894. else
  895. if Length(More)=0 then
  896. IllegalPara(opt)
  897. else
  898. case more[1] of
  899. 'g' : if UnsetBool(more, 1) then
  900. begin
  901. exclude(initmoduleswitches,cs_profile);
  902. undef_system_macro('FPC_PROFILE');
  903. end
  904. else
  905. begin
  906. include(initmoduleswitches,cs_profile);
  907. def_system_macro('FPC_PROFILE');
  908. end;
  909. else
  910. IllegalPara(opt);
  911. end;
  912. end;
  913. 'P' : ; { Ignore used by fpc.pp }
  914. 'R' :
  915. begin
  916. if not SetAsmReadMode(More,initasmmode) then
  917. IllegalPara(opt);
  918. end;
  919. 's' :
  920. begin
  921. if UnsetBool(More, 0) then
  922. begin
  923. initglobalswitches:=initglobalswitches-[cs_asm_extern,cs_link_extern];
  924. if more<>'' then
  925. IllegalPara(opt);
  926. end
  927. else
  928. begin
  929. initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern];
  930. if more='h' then
  931. initglobalswitches:=initglobalswitches-[cs_link_on_target]
  932. else if more='t' then
  933. initglobalswitches:=initglobalswitches+[cs_link_on_target]
  934. else if more='r' then
  935. initglobalswitches:=initglobalswitches+[cs_asm_leave,cs_no_regalloc]
  936. else if more<>'' then
  937. IllegalPara(opt);
  938. end;
  939. end;
  940. 'S' :
  941. begin
  942. if more[1]='I' then
  943. begin
  944. if upper(more)='ICOM' then
  945. initinterfacetype:=it_interfacecom
  946. else if upper(more)='ICORBA' then
  947. initinterfacetype:=it_interfacecorba
  948. else
  949. IllegalPara(opt);
  950. end
  951. else
  952. begin
  953. j:=1;
  954. while j<=length(more) do
  955. begin
  956. case more[j] of
  957. '2' : //an alternative to -Mobjfpc
  958. SetCompileMode('OBJFPC',true);
  959. 'a' :
  960. include(initlocalswitches,cs_do_assertion);
  961. 'c' :
  962. include(initmoduleswitches,cs_support_c_operators);
  963. 'd' : //an alternative to -Mdelphi
  964. SetCompileMode('DELPHI',true);
  965. 'e' :
  966. begin
  967. SetErrorFlags(copy(more,j+1,length(more)));
  968. break;
  969. end;
  970. 'g' :
  971. include(initmoduleswitches,cs_support_goto);
  972. 'h' :
  973. include(initlocalswitches,cs_ansistrings);
  974. 'i' :
  975. include(initmoduleswitches,cs_support_inline);
  976. 'k' :
  977. include(initglobalswitches,cs_load_fpcylix_unit);
  978. 'm' :
  979. include(initmoduleswitches,cs_support_macro);
  980. 'o' : //an alternative to -Mtp
  981. SetCompileMode('TP',true);
  982. 'p' : //an alternative to -Mgpc
  983. SetCompileMode('GPC',true);
  984. 's' :
  985. include(initglobalswitches,cs_constructor_name);
  986. 't' :
  987. include(initmoduleswitches,cs_static_keyword);
  988. '-' :
  989. begin
  990. exclude(initglobalswitches,cs_constructor_name);
  991. initlocalswitches:=InitLocalswitches - [cs_do_assertion, cs_ansistrings];
  992. initmoduleswitches:=initmoduleswitches - [cs_support_c_operators, cs_support_goto,
  993. cs_support_inline, cs_support_macro,
  994. cs_static_keyword];
  995. end;
  996. else
  997. IllegalPara(opt);
  998. end;
  999. inc(j);
  1000. end;
  1001. end;
  1002. end;
  1003. 'T' :
  1004. begin
  1005. more:=Upper(More);
  1006. if paratarget=system_none then
  1007. begin
  1008. { remove old target define }
  1009. TargetDefines(false);
  1010. { load new target }
  1011. paratarget:=find_system_by_string(More);
  1012. if paratarget<>system_none then
  1013. set_target(paratarget)
  1014. else
  1015. IllegalPara(opt);
  1016. { set new define }
  1017. TargetDefines(true);
  1018. end
  1019. else
  1020. if More<>upper(target_info.shortname) then
  1021. Message1(option_target_is_already_set,target_info.shortname);
  1022. end;
  1023. 'u' :
  1024. if more <> '' then
  1025. undef_system_macro(more);
  1026. 'U' :
  1027. begin
  1028. j:=1;
  1029. while j<=length(more) do
  1030. begin
  1031. case more[j] of
  1032. {$ifdef UNITALIASES}
  1033. 'a' :
  1034. begin
  1035. AddUnitAlias(Copy(More,j+1,255));
  1036. break;
  1037. end;
  1038. {$endif UNITALIASES}
  1039. 'n' :
  1040. exclude(initglobalswitches,cs_check_unit_name);
  1041. 'p' :
  1042. begin
  1043. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1044. break;
  1045. end;
  1046. 'r' :
  1047. do_release:=true;
  1048. 's' :
  1049. include(initmoduleswitches,cs_compilesystem);
  1050. '-' :
  1051. begin
  1052. exclude(initmoduleswitches,cs_compilesystem);
  1053. exclude(initglobalswitches,cs_check_unit_name);
  1054. end;
  1055. else
  1056. IllegalPara(opt);
  1057. end;
  1058. inc(j);
  1059. end;
  1060. end;
  1061. 'v' :
  1062. begin
  1063. if not setverbosity(More) then
  1064. IllegalPara(opt);
  1065. end;
  1066. 'V' : ; { Ignore used by fpc }
  1067. 'W' :
  1068. begin
  1069. j:=1;
  1070. while j<=length(More) do
  1071. begin
  1072. case More[j] of
  1073. 'A':
  1074. begin
  1075. if UnsetBool(More, j) then
  1076. apptype:=app_native
  1077. else
  1078. apptype:=app_cui;
  1079. end;
  1080. 'B':
  1081. begin
  1082. { -WB200000 means set trefered base address
  1083. to $200000, but does not change relocsection boolean
  1084. this way we can create both relocatble and
  1085. non relocatable DLL at a specific base address PM }
  1086. if (length(More)>j) then
  1087. begin
  1088. if DLLImageBase=nil then
  1089. DLLImageBase:=StringDup(Copy(More,j+1,255));
  1090. end
  1091. else
  1092. begin
  1093. RelocSection:=true;
  1094. RelocSectionSetExplicitly:=true;
  1095. end;
  1096. break;
  1097. end;
  1098. 'C':
  1099. begin
  1100. if UnsetBool(More, j) then
  1101. apptype:=app_gui
  1102. else
  1103. apptype:=app_cui;
  1104. end;
  1105. 'D':
  1106. begin
  1107. UseDeffileForExports:=not UnsetBool(More, j);
  1108. UseDeffileForExportsSetExplicitly:=true;
  1109. end;
  1110. 'F':
  1111. begin
  1112. if UnsetBool(More, j) then
  1113. apptype:=app_cui
  1114. else
  1115. apptype:=app_fs;
  1116. end;
  1117. 'G':
  1118. begin
  1119. if UnsetBool(More, j) then
  1120. apptype:=app_cui
  1121. else
  1122. apptype:=app_gui;
  1123. end;
  1124. 'I':
  1125. begin
  1126. GenerateImportSection:=not UnsetBool(More,j);
  1127. GenerateImportSectionSetExplicitly:=true;
  1128. end;
  1129. 'N':
  1130. begin
  1131. RelocSection:=UnsetBool(More,j);
  1132. RelocSectionSetExplicitly:=true;
  1133. end;
  1134. 'R':
  1135. begin
  1136. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1137. RelocSection:=not UnsetBool(More,j);
  1138. RelocSectionSetExplicitly:=true;
  1139. end;
  1140. 'T':
  1141. begin
  1142. if UnsetBool(More, j) then
  1143. apptype:=app_cui
  1144. else
  1145. apptype:=app_tool;
  1146. end;
  1147. else
  1148. IllegalPara(opt);
  1149. end;
  1150. inc(j);
  1151. end;
  1152. end;
  1153. 'X' :
  1154. begin
  1155. j:=1;
  1156. while j<=length(more) do
  1157. begin
  1158. case More[j] of
  1159. 'i' :
  1160. begin
  1161. If UnsetBool(More, j) then
  1162. exclude(initglobalswitches,cs_link_internal)
  1163. else
  1164. include(initglobalswitches,cs_link_internal);
  1165. end;
  1166. 'm' :
  1167. begin
  1168. If UnsetBool(More, j) then
  1169. exclude(initglobalswitches,cs_link_map)
  1170. else
  1171. include(initglobalswitches,cs_link_map);
  1172. end;
  1173. 'f' :
  1174. include(initglobalswitches,cs_link_pthread);
  1175. 's' :
  1176. begin
  1177. If UnsetBool(More, j) then
  1178. exclude(initglobalswitches,cs_link_strip)
  1179. else
  1180. include(initglobalswitches,cs_link_strip);
  1181. end;
  1182. 'c' : Cshared:=TRUE;
  1183. 't' :
  1184. include(initglobalswitches,cs_link_staticflag);
  1185. 'D' :
  1186. begin
  1187. def_system_macro('FPC_LINK_DYNAMIC');
  1188. undef_system_macro('FPC_LINK_SMART');
  1189. undef_system_macro('FPC_LINK_STATIC');
  1190. exclude(initglobalswitches,cs_link_static);
  1191. exclude(initglobalswitches,cs_link_smart);
  1192. include(initglobalswitches,cs_link_shared);
  1193. LinkTypeSetExplicitly:=true;
  1194. end;
  1195. 'd' : Dontlinkstdlibpath:=TRUE;
  1196. 'P' : Begin
  1197. utilsprefix:=Copy(more,2,length(More)-1);
  1198. DefaultReplacements(utilsprefix);
  1199. More:='';
  1200. End;
  1201. 'r' : Begin
  1202. rlinkpath:=Copy(more,2,length(More)-1);
  1203. DefaultReplacements(rlinkpath);
  1204. More:='';
  1205. end;
  1206. 'S' :
  1207. begin
  1208. def_system_macro('FPC_LINK_STATIC');
  1209. undef_system_macro('FPC_LINK_SMART');
  1210. undef_system_macro('FPC_LINK_DYNAMIC');
  1211. include(initglobalswitches,cs_link_static);
  1212. exclude(initglobalswitches,cs_link_smart);
  1213. exclude(initglobalswitches,cs_link_shared);
  1214. LinkTypeSetExplicitly:=true;
  1215. end;
  1216. 'X' :
  1217. begin
  1218. def_system_macro('FPC_LINK_SMART');
  1219. undef_system_macro('FPC_LINK_STATIC');
  1220. undef_system_macro('FPC_LINK_DYNAMIC');
  1221. exclude(initglobalswitches,cs_link_static);
  1222. include(initglobalswitches,cs_link_smart);
  1223. exclude(initglobalswitches,cs_link_shared);
  1224. LinkTypeSetExplicitly:=true;
  1225. end;
  1226. 'M' :
  1227. begin
  1228. mainaliasname:=Copy(more,2,length(More)-1);
  1229. More:='';
  1230. end;
  1231. '-' :
  1232. begin
  1233. exclude(initglobalswitches,cs_link_staticflag);
  1234. exclude(initglobalswitches,cs_link_strip);
  1235. exclude(initglobalswitches,cs_link_map);
  1236. set_default_link_type;
  1237. end;
  1238. else
  1239. IllegalPara(opt);
  1240. end;
  1241. inc(j);
  1242. end;
  1243. end;
  1244. end;
  1245. end;
  1246. '@' :
  1247. begin
  1248. Message(option_no_nested_response_file);
  1249. StopOptions(1);
  1250. end;
  1251. else
  1252. begin
  1253. if (length(param_file)<>0) then
  1254. Message(option_only_one_source_support);
  1255. param_file:=opt;
  1256. Message1(option_found_file,opt);
  1257. end;
  1258. end;
  1259. end;
  1260. procedure Toption.Interpret_file(const filename : string);
  1261. procedure RemoveSep(var fn:string);
  1262. var
  1263. i : longint;
  1264. begin
  1265. i:=0;
  1266. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1267. inc(i);
  1268. Delete(fn,1,i);
  1269. i:=length(fn);
  1270. while (i>0) and (fn[i] in [',',' ',#9]) do
  1271. dec(i);
  1272. fn:=copy(fn,1,i);
  1273. end;
  1274. function GetName(var fn:string):string;
  1275. var
  1276. i : longint;
  1277. begin
  1278. i:=0;
  1279. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1280. inc(i);
  1281. GetName:=Copy(fn,1,i);
  1282. Delete(fn,1,i);
  1283. end;
  1284. const
  1285. maxlevel=16;
  1286. var
  1287. f : text;
  1288. s, tmp,
  1289. opts : string;
  1290. skip : array[0..maxlevel-1] of boolean;
  1291. level : longint;
  1292. option_read : boolean;
  1293. begin
  1294. { avoid infinite loop }
  1295. Inc(FileLevel);
  1296. Option_read:=false;
  1297. If FileLevel>MaxLevel then
  1298. Message(option_too_many_cfg_files);
  1299. { Maybe It's Directory ?} //Jaro Change:
  1300. if DirectoryExists(filename) then
  1301. begin
  1302. Message1(option_config_is_dir,filename);
  1303. exit;
  1304. end;
  1305. { open file }
  1306. Message1(option_using_file,filename);
  1307. {$ifdef USE_SYSUTILS}
  1308. assign(f,ExpandFileName(filename));
  1309. {$else USE_SYSUTILS}
  1310. assign(f,FExpand(filename));
  1311. {$endif USE_SYsUTILS}
  1312. {$I-}
  1313. reset(f);
  1314. {$I+}
  1315. if ioresult<>0 then
  1316. begin
  1317. Message1(option_unable_open_file,filename);
  1318. exit;
  1319. end;
  1320. Message1(option_start_reading_configfile,filename);
  1321. fillchar(skip,sizeof(skip),0);
  1322. level:=0;
  1323. while not eof(f) do
  1324. begin
  1325. readln(f,opts);
  1326. RemoveSep(opts);
  1327. if (opts<>'') and (opts[1]<>';') then
  1328. begin
  1329. if opts[1]='#' then
  1330. begin
  1331. Message1(option_interpreting_file_option,opts);
  1332. Delete(opts,1,1);
  1333. s:=upper(GetName(opts));
  1334. if (s='SECTION') then
  1335. begin
  1336. RemoveSep(opts);
  1337. s:=upper(GetName(opts));
  1338. if level=0 then
  1339. skip[level]:=not (assigned(search_macro(s)) or (s='COMMON'));
  1340. end
  1341. else
  1342. if (s='IFDEF') then
  1343. begin
  1344. RemoveSep(opts);
  1345. if Level>=maxlevel then
  1346. begin
  1347. Message(option_too_many_ifdef);
  1348. stopOptions(1);
  1349. end;
  1350. inc(Level);
  1351. skip[level]:=(skip[level-1] or not assigned(search_macro(upper(GetName(opts)))));
  1352. end
  1353. else
  1354. if (s='IFNDEF') then
  1355. begin
  1356. RemoveSep(opts);
  1357. if Level>=maxlevel then
  1358. begin
  1359. Message(option_too_many_ifdef);
  1360. stopOptions(1);
  1361. end;
  1362. inc(Level);
  1363. skip[level]:=(skip[level-1] or assigned(search_macro(upper(GetName(opts)))));
  1364. end
  1365. else
  1366. if (s='ELSE') then
  1367. skip[level]:=skip[level-1] or (not skip[level])
  1368. else
  1369. if (s='ENDIF') then
  1370. begin
  1371. skip[level]:=false;
  1372. if Level=0 then
  1373. begin
  1374. Message(option_too_many_endif);
  1375. stopOptions(1);
  1376. end;
  1377. dec(level);
  1378. end
  1379. else
  1380. if (not skip[level]) then
  1381. begin
  1382. if (s='DEFINE') then
  1383. begin
  1384. RemoveSep(opts);
  1385. tmp:= GetName(opts);
  1386. if tmp <> '' then
  1387. def_system_macro(tmp);
  1388. end
  1389. else
  1390. if (s='UNDEF') then
  1391. begin
  1392. RemoveSep(opts);
  1393. tmp:= GetName(opts);
  1394. if tmp <> '' then
  1395. undef_system_macro(tmp);
  1396. end
  1397. else
  1398. if (s='WRITE') then
  1399. begin
  1400. Delete(opts,1,1);
  1401. WriteLn(opts);
  1402. end
  1403. else
  1404. if (s='INCLUDE') then
  1405. begin
  1406. Delete(opts,1,1);
  1407. Interpret_file(opts);
  1408. end;
  1409. end;
  1410. end
  1411. else
  1412. begin
  1413. if (opts[1]='-') or (opts[1]='@') then
  1414. begin
  1415. if (not skip[level]) then
  1416. interpret_option(opts,false);
  1417. Option_read:=true;
  1418. end
  1419. else
  1420. Message1(option_illegal_para,opts);
  1421. end;
  1422. end;
  1423. end;
  1424. if Level>0 then
  1425. Message(option_too_less_endif);
  1426. if Not Option_read then
  1427. Message1(option_no_option_found,filename)
  1428. else
  1429. Message1(option_end_reading_configfile,filename);
  1430. Close(f);
  1431. Dec(FileLevel);
  1432. end;
  1433. procedure Toption.Interpret_envvar(const envname : string);
  1434. var
  1435. argstart,
  1436. env,
  1437. pc : pchar;
  1438. arglen : longint;
  1439. quote : set of char;
  1440. hs : string;
  1441. begin
  1442. Message1(option_using_env,envname);
  1443. env:=GetEnvPChar(envname);
  1444. pc:=env;
  1445. if assigned(pc) then
  1446. begin
  1447. repeat
  1448. { skip leading spaces }
  1449. while pc^ in [' ',#9,#13] do
  1450. inc(pc);
  1451. case pc^ of
  1452. #0 :
  1453. break;
  1454. '"' :
  1455. begin
  1456. quote:=['"'];
  1457. inc(pc);
  1458. end;
  1459. '''' :
  1460. begin
  1461. quote:=[''''];
  1462. inc(pc);
  1463. end;
  1464. else
  1465. quote:=[' ',#9,#13];
  1466. end;
  1467. { scan until the end of the argument }
  1468. argstart:=pc;
  1469. while (pc^<>#0) and not(pc^ in quote) do
  1470. inc(pc);
  1471. { create argument }
  1472. arglen:=pc-argstart;
  1473. hs[0]:=chr(arglen);
  1474. move(argstart^,hs[1],arglen);
  1475. interpret_option(hs,true);
  1476. { skip quote }
  1477. if pc^ in quote then
  1478. inc(pc);
  1479. until false;
  1480. end
  1481. else
  1482. Message1(option_no_option_found,'(env) '+envname);
  1483. FreeEnvPChar(env);
  1484. end;
  1485. procedure toption.read_parameters;
  1486. var
  1487. opts : string;
  1488. paramindex : longint;
  1489. begin
  1490. paramindex:=0;
  1491. while paramindex<paramcount do
  1492. begin
  1493. inc(paramindex);
  1494. opts:=system.paramstr(paramindex);
  1495. case opts[1] of
  1496. '@' :
  1497. if not firstpass then
  1498. begin
  1499. Delete(opts,1,1);
  1500. Message1(option_reading_further_from,opts);
  1501. interpret_file(opts);
  1502. end;
  1503. '!' :
  1504. if not firstpass then
  1505. begin
  1506. Delete(opts,1,1);
  1507. Message1(option_reading_further_from,'(env) '+opts);
  1508. interpret_envvar(opts);
  1509. end;
  1510. else
  1511. interpret_option(opts,true);
  1512. end;
  1513. end;
  1514. end;
  1515. procedure toption.parsecmd(cmd:string);
  1516. var
  1517. i,ps : longint;
  1518. opts : string;
  1519. begin
  1520. while (cmd<>'') do
  1521. begin
  1522. while cmd[1]=' ' do
  1523. delete(cmd,1,1);
  1524. i:=pos(' ',cmd);
  1525. if i=0 then
  1526. i:=256;
  1527. opts:=Copy(cmd,1,i-1);
  1528. Delete(cmd,1,i);
  1529. case opts[1] of
  1530. '@' :
  1531. if not firstpass then
  1532. begin
  1533. Delete(opts,1,1);
  1534. Message1(option_reading_further_from,opts);
  1535. interpret_file(opts);
  1536. end;
  1537. '!' :
  1538. if not firstpass then
  1539. begin
  1540. Delete(opts,1,1);
  1541. Message1(option_reading_further_from,'(env) '+opts);
  1542. interpret_envvar(opts);
  1543. end;
  1544. '"' :
  1545. begin
  1546. Delete(opts,1,1);
  1547. ps:=pos('"',cmd);
  1548. if (i<>256) and (ps>0) then
  1549. begin
  1550. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1551. cmd:=copy(cmd,ps+1,255);
  1552. end;
  1553. interpret_option(opts,true);
  1554. end;
  1555. else
  1556. interpret_option(opts,true);
  1557. end;
  1558. end;
  1559. end;
  1560. procedure toption.writequickinfo;
  1561. var
  1562. s : string;
  1563. i : longint;
  1564. procedure addinfo(const hs:string);
  1565. begin
  1566. if s<>'' then
  1567. s:=s+' '+hs
  1568. else
  1569. s:=hs;
  1570. end;
  1571. begin
  1572. s:='';
  1573. i:=0;
  1574. while (i<length(quickinfo)) do
  1575. begin
  1576. inc(i);
  1577. case quickinfo[i] of
  1578. 'S' :
  1579. begin
  1580. inc(i);
  1581. case quickinfo[i] of
  1582. 'O' :
  1583. addinfo(lower(source_info.shortname));
  1584. 'P' :
  1585. addinfo(source_cpu_string);
  1586. else
  1587. IllegalPara('-i'+QuickInfo);
  1588. end;
  1589. end;
  1590. 'T' :
  1591. begin
  1592. inc(i);
  1593. case quickinfo[i] of
  1594. 'O' :
  1595. addinfo(lower(target_info.shortname));
  1596. 'P' :
  1597. AddInfo(target_cpu_string);
  1598. else
  1599. IllegalPara('-i'+QuickInfo);
  1600. end;
  1601. end;
  1602. 'V' :
  1603. AddInfo(version_string);
  1604. 'D' :
  1605. AddInfo(date_string);
  1606. '_' :
  1607. ;
  1608. else
  1609. IllegalPara('-i'+QuickInfo);
  1610. end;
  1611. end;
  1612. if s<>'' then
  1613. begin
  1614. writeln(s);
  1615. stopoptions(0);
  1616. end;
  1617. end;
  1618. procedure TOption.TargetDefines(def:boolean);
  1619. var
  1620. s : string;
  1621. i : integer;
  1622. begin
  1623. if def then
  1624. def_system_macro(target_info.shortname)
  1625. else
  1626. undef_system_macro(target_info.shortname);
  1627. s:=target_info.extradefines;
  1628. while (s<>'') do
  1629. begin
  1630. i:=pos(';',s);
  1631. if i=0 then
  1632. i:=length(s)+1;
  1633. if def then
  1634. def_system_macro(Copy(s,1,i-1))
  1635. else
  1636. undef_system_macro(Copy(s,1,i-1));
  1637. delete(s,1,i);
  1638. end;
  1639. end;
  1640. constructor TOption.create;
  1641. begin
  1642. LogoWritten:=false;
  1643. NoPressEnter:=false;
  1644. FirstPass:=false;
  1645. FileLevel:=0;
  1646. Quickinfo:='';
  1647. ParaIncludePath:=TSearchPathList.Create;
  1648. ParaObjectPath:=TSearchPathList.Create;
  1649. ParaUnitPath:=TSearchPathList.Create;
  1650. ParaLibraryPath:=TSearchPathList.Create;
  1651. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1652. end;
  1653. destructor TOption.destroy;
  1654. begin
  1655. ParaIncludePath.Free;
  1656. ParaObjectPath.Free;
  1657. ParaUnitPath.Free;
  1658. ParaLibraryPath.Free;
  1659. end;
  1660. {****************************************************************************
  1661. Callable Routines
  1662. ****************************************************************************}
  1663. function check_configfile(const fn:string;var foundfn:string):boolean;
  1664. function CfgFileExists(const fn:string):boolean;
  1665. begin
  1666. Comment(V_Tried,'Configfile search: '+fn);
  1667. CfgFileExists:=FileExists(fn);
  1668. end;
  1669. var
  1670. configpath : pathstr;
  1671. begin
  1672. foundfn:=fn;
  1673. check_configfile:=true;
  1674. { retrieve configpath }
  1675. {$IFDEF USE_SYSUTILS}
  1676. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  1677. {$ELSE USE_SYSUTILS}
  1678. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1679. {$ENDIF USE_SYSUTILS}
  1680. {$ifdef Unix}
  1681. if configpath='' then
  1682. configpath:=CleanPath(FixPath(exepath+'../etc/',false));
  1683. {$endif}
  1684. {
  1685. Order to read configuration file :
  1686. try reading fpc.cfg in :
  1687. 1 - current dir
  1688. 2 - configpath
  1689. 3 - compiler path
  1690. }
  1691. if not FileExists(fn) then
  1692. begin
  1693. {$ifdef Unix}
  1694. {$IFDEF USE_SYSUTILS}
  1695. if (GetEnvironmentVariable('HOME')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn) then
  1696. foundfn:=FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn
  1697. {$ELSE USE_SYSUTILS}
  1698. if (dos.getenv('HOME')<>'') and CfgFileExists(FixPath(dos.getenv('HOME'),false)+'.'+fn) then
  1699. foundfn:=FixPath(dos.getenv('HOME'),false)+'.'+fn
  1700. {$ENDIF USE_SYSUTILS}
  1701. else
  1702. {$endif}
  1703. if CfgFileExists(configpath+fn) then
  1704. foundfn:=configpath+fn
  1705. else
  1706. {$ifndef Unix}
  1707. if CfgFileExists(exepath+fn) then
  1708. foundfn:=exepath+fn
  1709. else
  1710. {$else}
  1711. if CfgFileExists('/etc/'+fn) then
  1712. foundfn:='/etc/'+fn
  1713. else
  1714. {$endif}
  1715. check_configfile:=false;
  1716. end;
  1717. end;
  1718. procedure read_arguments(cmd:string);
  1719. begin
  1720. option:=coption.create;
  1721. disable_configfile:=false;
  1722. { get default messagefile }
  1723. {$IFDEF USE_SYSUTILS}
  1724. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  1725. {$ELSE USE_SYSUTILS}
  1726. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1727. {$ENDIF USE_SYSUTILS}
  1728. { default configfile can be specified on the commandline,
  1729. remove it first }
  1730. if (cmd<>'') and (cmd[1]='[') then
  1731. begin
  1732. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1733. Delete(cmd,1,pos(']',cmd));
  1734. end
  1735. else
  1736. begin
  1737. ppccfg:='fpc.cfg';
  1738. ppcaltcfg:='ppc386.cfg';
  1739. end;
  1740. { first pass reading of parameters, only -i -v -T etc.}
  1741. option.firstpass:=true;
  1742. if cmd<>'' then
  1743. option.parsecmd(cmd)
  1744. else
  1745. begin
  1746. option.read_parameters;
  1747. { Write only quickinfo }
  1748. if option.quickinfo<>'' then
  1749. option.writequickinfo;
  1750. end;
  1751. option.firstpass:=false;
  1752. { target is set here, for wince the default app type is gui }
  1753. if target_info.system in system_wince then
  1754. apptype:=app_gui;
  1755. { default defines }
  1756. def_system_macro(target_info.shortname);
  1757. def_system_macro('FPC');
  1758. def_system_macro('VER'+version_nr);
  1759. def_system_macro('VER'+version_nr+'_'+release_nr);
  1760. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1761. { Temporary defines, until things settle down }
  1762. { "main" symbol is generated in the main program, and left out of the system unit }
  1763. def_system_macro('FPC_DARWIN_PASCALMAIN');
  1764. def_system_macro('FPC_DARWIN_JMP_MAIN');
  1765. def_system_macro('COMPPROCINLINEFIXED');
  1766. def_system_macro('PARAOUTFILE');
  1767. if pocall_default = pocall_register then
  1768. def_system_macro('REGCALL');
  1769. { using a case is pretty useless here (FK) }
  1770. { some stuff for TP compatibility }
  1771. {$ifdef i386}
  1772. def_system_macro('CPU86');
  1773. def_system_macro('CPU87');
  1774. {$endif}
  1775. {$ifdef m68k}
  1776. def_system_macro('CPU68');
  1777. {$endif}
  1778. { new processor stuff }
  1779. {$ifdef i386}
  1780. def_system_macro('CPUI386');
  1781. def_system_macro('CPU32');
  1782. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  1783. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1784. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1785. def_system_macro('FPC_HAS_RESOURCES');
  1786. {$endif}
  1787. {$ifdef m68k}
  1788. def_system_macro('CPU68K');
  1789. def_system_macro('CPUM68K');
  1790. def_system_macro('CPU32');
  1791. def_system_macro('FPC_CURRENCY_IS_INT64');
  1792. def_system_macro('FPC_COMP_IS_INT64');
  1793. {$endif}
  1794. {$ifdef ALPHA}
  1795. def_system_macro('CPUALPHA');
  1796. def_system_macro('CPU64');
  1797. {$endif}
  1798. {$ifdef powerpc}
  1799. def_system_macro('CPUPOWERPC');
  1800. def_system_macro('CPUPOWERPC32');
  1801. def_system_macro('CPU32');
  1802. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1803. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1804. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1805. def_system_macro('FPC_CURRENCY_IS_INT64');
  1806. def_system_macro('FPC_COMP_IS_INT64');
  1807. {$endif}
  1808. {$ifdef POWERPC64}
  1809. def_system_macro('CPUPOWERPC');
  1810. def_system_macro('CPUPOWERPC64');
  1811. def_system_macro('CPU64');
  1812. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1813. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1814. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1815. def_system_macro('FPC_CURRENCY_IS_INT64');
  1816. def_system_macro('FPC_COMP_IS_INT64');
  1817. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1818. {$endif}
  1819. {$ifdef iA64}
  1820. def_system_macro('CPUIA64');
  1821. def_system_macro('CPU64');
  1822. {$endif}
  1823. {$ifdef x86_64}
  1824. def_system_macro('CPUX86_64');
  1825. def_system_macro('CPUAMD64');
  1826. def_system_macro('CPU64');
  1827. { not supported for now, afaik (FK)
  1828. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  1829. { win64 doesn't support the legacy fpu }
  1830. if target_info.system<>system_x86_64_win64 then
  1831. def_system_macro('FPC_HAS_TYPE_EXTENDED')
  1832. else
  1833. begin
  1834. def_system_macro('FPC_CURRENCY_IS_INT64');
  1835. def_system_macro('FPC_COMP_IS_INT64');
  1836. undef_system_macro('FPC_HAS_TYPE_EXTENDED');
  1837. end;
  1838. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1839. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1840. {$endif}
  1841. {$ifdef sparc}
  1842. def_system_macro('CPUSPARC');
  1843. def_system_macro('CPUSPARC32');
  1844. def_system_macro('CPU32');
  1845. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1846. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1847. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1848. def_system_macro('FPC_CURRENCY_IS_INT64');
  1849. def_system_macro('FPC_COMP_IS_INT64');
  1850. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1851. {$endif}
  1852. {$ifdef vis}
  1853. def_system_macro('CPUVIS');
  1854. def_system_macro('CPU32');
  1855. {$endif}
  1856. {$ifdef arm}
  1857. def_system_macro('CPUARM');
  1858. def_system_macro('FPUFPA');
  1859. def_system_macro('CPU32');
  1860. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1861. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1862. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1863. def_system_macro('FPC_CURRENCY_IS_INT64');
  1864. def_system_macro('FPC_COMP_IS_INT64');
  1865. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1866. {$endif arm}
  1867. if source_info.system<>target_info.system then
  1868. def_system_macro('FPC_CROSSCOMPILING');
  1869. if source_info.cpu<>target_info.cpu then
  1870. def_system_macro('FPC_CPUCROSSCOMPILING');
  1871. { read configuration file }
  1872. if (not disable_configfile) and
  1873. (ppccfg<>'') then
  1874. begin
  1875. read_configfile:=check_configfile(ppccfg,ppccfg);
  1876. { Maybe alternative configfile ? }
  1877. if (not read_configfile) and
  1878. (ppcaltcfg<>'') then
  1879. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  1880. end
  1881. else
  1882. read_configfile := false;
  1883. { Read commandline and configfile }
  1884. param_file:='';
  1885. { read configfile }
  1886. if read_configfile then
  1887. option.interpret_file(ppccfg);
  1888. { read parameters again to override config file }
  1889. if cmd<>'' then
  1890. option.parsecmd(cmd)
  1891. else
  1892. begin
  1893. { Write help pages if no parameters are passed }
  1894. if (paramcount=0) then
  1895. Option.WriteHelpPages;
  1896. option.read_parameters;
  1897. { Write only quickinfo }
  1898. if option.quickinfo<>'' then
  1899. option.writequickinfo;
  1900. end;
  1901. { Stop if errors in options }
  1902. if ErrorCount>0 then
  1903. StopOptions(1);
  1904. { Write logo }
  1905. if option.ParaLogo then
  1906. option.writelogo;
  1907. { Non-core target defines }
  1908. Option.TargetDefines(true);
  1909. { endian define }
  1910. case target_info.endian of
  1911. endian_little :
  1912. begin
  1913. def_system_macro('ENDIAN_LITTLE');
  1914. def_system_macro('FPC_LITTLE_ENDIAN');
  1915. end;
  1916. endian_big :
  1917. begin
  1918. def_system_macro('ENDIAN_BIG');
  1919. def_system_macro('FPC_BIG_ENDIAN');
  1920. end;
  1921. end;
  1922. { abi define }
  1923. case target_info.abi of
  1924. abi_powerpc_sysv :
  1925. def_system_macro('FPC_ABI_SYSV');
  1926. abi_powerpc_aix :
  1927. def_system_macro('FPC_ABI_AIX');
  1928. end;
  1929. { CPU Define }
  1930. def_system_macro('CPU'+Cputypestr[initcputype]);
  1931. { Check file to compile }
  1932. if param_file='' then
  1933. begin
  1934. Message(option_no_source_found);
  1935. StopOptions(1);
  1936. end;
  1937. {$ifndef Unix}
  1938. param_file:=FixFileName(param_file);
  1939. {$endif}
  1940. {$IFDEF USE_SYSUTILS}
  1941. inputdir := SplitPath(param_file);
  1942. inputfile := SplitName(param_file);
  1943. inputextension := SplitExtension(param_file);
  1944. {$ELSE USE_SYSUTILS}
  1945. fsplit(param_file,inputdir,inputfile,inputextension);
  1946. {$ENDIF USE_SYSUTILS}
  1947. if inputextension='' then
  1948. begin
  1949. if FileExists(inputdir+inputfile+sourceext) then
  1950. inputextension:=sourceext
  1951. else if FileExists(inputdir+inputfile+pasext) then
  1952. inputextension:=pasext
  1953. else if ((m_mac in aktmodeswitches) or
  1954. (tf_p_ext_support in target_info.flags))
  1955. and FileExists(inputdir+inputfile+pext) then
  1956. inputextension:=pext;
  1957. end;
  1958. { Check output dir }
  1959. if (OutputExeDir<>'') and
  1960. not PathExists(OutputExeDir) then
  1961. begin
  1962. Message1(general_e_path_does_not_exist,OutputExeDir);
  1963. StopOptions(1);
  1964. end;
  1965. { Add paths specified with parameters to the searchpaths }
  1966. UnitSearchPath.AddList(option.ParaUnitPath,true);
  1967. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  1968. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  1969. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  1970. { add unit environment and exepath to the unit search path }
  1971. if inputdir<>'' then
  1972. Unitsearchpath.AddPath(inputdir,true);
  1973. if not disable_configfile then
  1974. begin
  1975. {$IFDEF USE_SYSUTILS}
  1976. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  1977. {$ELSE USE_SYSUTILS}
  1978. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1979. {$ENDIF USE_SYSUTILS}
  1980. end;
  1981. {$ifdef Unix}
  1982. {$IFDEF USE_SYSUTILS}
  1983. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  1984. {$ELSE USE_SYSUTILS}
  1985. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1986. {$ENDIF USE_SYSUTILS}
  1987. if fpcdir='' then
  1988. begin
  1989. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1990. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1991. else
  1992. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  1993. end;
  1994. {$else}
  1995. {$IFDEF USE_SYSUTILS}
  1996. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  1997. {$ELSE USE_SYSUTILS}
  1998. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1999. {$ENDIF USE_SYSUTILS}
  2000. if fpcdir='' then
  2001. begin
  2002. fpcdir:=ExePath+'../';
  2003. if not(PathExists(fpcdir+'/units')) and
  2004. not(PathExists(fpcdir+'/rtl')) then
  2005. fpcdir:=fpcdir+'../';
  2006. end;
  2007. {$endif}
  2008. { first try development RTL, else use the default installation path }
  2009. if not disable_configfile then
  2010. begin
  2011. if PathExists(FpcDir+'rtl') then
  2012. if tf_use_8_3 in Source_Info.Flags then
  2013. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2014. else
  2015. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2016. else
  2017. if tf_use_8_3 in Source_Info.Flags then
  2018. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2019. else
  2020. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2021. end;
  2022. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2023. Do not add it when linking on the target because then we can maybe already find
  2024. .o files that are not for the target }
  2025. if (ExePath<>GetCurrentDir) and
  2026. not(cs_link_on_target in initglobalswitches) then
  2027. UnitSearchPath.AddPath(ExePath,false);
  2028. { Add unit dir to the object and library path }
  2029. objectsearchpath.AddList(unitsearchpath,false);
  2030. librarysearchpath.AddList(unitsearchpath,false);
  2031. { maybe override debug info format }
  2032. if (paratargetdbg<>dbg_none) then
  2033. set_target_dbg(paratargetdbg);
  2034. { maybe override assembler }
  2035. if (paratargetasm<>as_none) then
  2036. set_target_asm(paratargetasm);
  2037. { switch assembler if it's binary and we got -a on the cmdline }
  2038. if (cs_asm_leave in initglobalswitches) and
  2039. (af_outputbinary in target_asm.flags) then
  2040. begin
  2041. Message(option_switch_bin_to_src_assembler);
  2042. set_target_asm(target_info.assemextern);
  2043. end;
  2044. if (target_asm.supported_target <> system_any) and
  2045. (target_asm.supported_target <> target_info.system) then
  2046. begin
  2047. Message2(option_incompatible_asm,target_asm.idtxt,target_info.name);
  2048. set_target_asm(target_info.assemextern);
  2049. Message1(option_asm_forced,target_asm.idtxt);
  2050. end;
  2051. { turn off stripping if compiling with debuginfo or profile }
  2052. if (cs_debuginfo in initmoduleswitches) or
  2053. (cs_profile in initmoduleswitches) then
  2054. exclude(initglobalswitches,cs_link_strip);
  2055. { force fpu emulation on arm/wince }
  2056. if target_info.system=system_arm_wince then
  2057. include(initmoduleswitches,cs_fp_emulation);
  2058. { Section smartlinking conflicts with import sections on Windows }
  2059. if GenerateImportSection and
  2060. (target_info.system in [system_i386_win32]) then
  2061. exclude(target_info.flags,tf_smartlink_sections);
  2062. if (cs_link_extern in initglobalswitches) then
  2063. exclude(initglobalswitches,cs_link_internal);
  2064. if (cs_link_internal in initglobalswitches) then
  2065. begin
  2066. { By default don't create import section if we use the internal linker }
  2067. if not GenerateImportSectionSetExplicitly then
  2068. GenerateImportSection:=false;
  2069. { Enable section smartlinking }
  2070. include(target_info.flags,tf_smartlink_sections);
  2071. end;
  2072. {$ifdef x86_64}
  2073. {$warning HACK: turn off smartlinking}
  2074. exclude(initmoduleswitches,cs_create_smart);
  2075. {$endif}
  2076. if not LinkTypeSetExplicitly then
  2077. set_default_link_type;
  2078. { Default alignment settings,
  2079. 1. load the defaults for the target
  2080. 2. override with generic optimizer setting (little size)
  2081. 3. override with the user specified -Oa }
  2082. UpdateAlignment(initalignment,target_info.alignment);
  2083. if (cs_opt_size in aktoptimizerswitches) then
  2084. begin
  2085. initalignment.procalign:=1;
  2086. initalignment.jumpalign:=1;
  2087. initalignment.loopalign:=1;
  2088. end;
  2089. UpdateAlignment(initalignment,option.paraalignment);
  2090. set_system_macro('FPC_VERSION',version_nr);
  2091. set_system_macro('FPC_RELEASE',release_nr);
  2092. set_system_macro('FPC_PATCH',patch_nr);
  2093. option.free;
  2094. Option:=nil;
  2095. end;
  2096. initialization
  2097. coption:=toption;
  2098. finalization
  2099. if assigned(option) then
  2100. option.free;
  2101. end.