options.pas 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257
  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. 'v' :
  1186. begin
  1187. If UnsetBool(More, j) then
  1188. exclude(initglobalswitches,cs_link_opt_vtable)
  1189. else
  1190. include(initglobalswitches,cs_link_opt_vtable);
  1191. end;
  1192. 'D' :
  1193. begin
  1194. def_system_macro('FPC_LINK_DYNAMIC');
  1195. undef_system_macro('FPC_LINK_SMART');
  1196. undef_system_macro('FPC_LINK_STATIC');
  1197. exclude(initglobalswitches,cs_link_static);
  1198. exclude(initglobalswitches,cs_link_smart);
  1199. include(initglobalswitches,cs_link_shared);
  1200. LinkTypeSetExplicitly:=true;
  1201. end;
  1202. 'd' : Dontlinkstdlibpath:=TRUE;
  1203. 'P' : Begin
  1204. utilsprefix:=Copy(more,2,length(More)-1);
  1205. DefaultReplacements(utilsprefix);
  1206. More:='';
  1207. End;
  1208. 'r' : Begin
  1209. rlinkpath:=Copy(more,2,length(More)-1);
  1210. DefaultReplacements(rlinkpath);
  1211. More:='';
  1212. end;
  1213. 'S' :
  1214. begin
  1215. def_system_macro('FPC_LINK_STATIC');
  1216. undef_system_macro('FPC_LINK_SMART');
  1217. undef_system_macro('FPC_LINK_DYNAMIC');
  1218. include(initglobalswitches,cs_link_static);
  1219. exclude(initglobalswitches,cs_link_smart);
  1220. exclude(initglobalswitches,cs_link_shared);
  1221. LinkTypeSetExplicitly:=true;
  1222. end;
  1223. 'X' :
  1224. begin
  1225. def_system_macro('FPC_LINK_SMART');
  1226. undef_system_macro('FPC_LINK_STATIC');
  1227. undef_system_macro('FPC_LINK_DYNAMIC');
  1228. exclude(initglobalswitches,cs_link_static);
  1229. include(initglobalswitches,cs_link_smart);
  1230. exclude(initglobalswitches,cs_link_shared);
  1231. LinkTypeSetExplicitly:=true;
  1232. end;
  1233. 'M' :
  1234. begin
  1235. mainaliasname:=Copy(more,2,length(More)-1);
  1236. More:='';
  1237. end;
  1238. '-' :
  1239. begin
  1240. exclude(initglobalswitches,cs_link_staticflag);
  1241. exclude(initglobalswitches,cs_link_strip);
  1242. exclude(initglobalswitches,cs_link_map);
  1243. set_default_link_type;
  1244. end;
  1245. else
  1246. IllegalPara(opt);
  1247. end;
  1248. inc(j);
  1249. end;
  1250. end;
  1251. end;
  1252. end;
  1253. '@' :
  1254. begin
  1255. Message(option_no_nested_response_file);
  1256. StopOptions(1);
  1257. end;
  1258. else
  1259. begin
  1260. if (length(param_file)<>0) then
  1261. Message(option_only_one_source_support);
  1262. param_file:=opt;
  1263. Message1(option_found_file,opt);
  1264. end;
  1265. end;
  1266. end;
  1267. procedure Toption.Interpret_file(const filename : string);
  1268. procedure RemoveSep(var fn:string);
  1269. var
  1270. i : longint;
  1271. begin
  1272. i:=0;
  1273. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1274. inc(i);
  1275. Delete(fn,1,i);
  1276. i:=length(fn);
  1277. while (i>0) and (fn[i] in [',',' ',#9]) do
  1278. dec(i);
  1279. fn:=copy(fn,1,i);
  1280. end;
  1281. function GetName(var fn:string):string;
  1282. var
  1283. i : longint;
  1284. begin
  1285. i:=0;
  1286. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1287. inc(i);
  1288. GetName:=Copy(fn,1,i);
  1289. Delete(fn,1,i);
  1290. end;
  1291. const
  1292. maxlevel=16;
  1293. var
  1294. f : text;
  1295. s, tmp,
  1296. opts : string;
  1297. skip : array[0..maxlevel-1] of boolean;
  1298. level : longint;
  1299. option_read : boolean;
  1300. begin
  1301. { avoid infinite loop }
  1302. Inc(FileLevel);
  1303. Option_read:=false;
  1304. If FileLevel>MaxLevel then
  1305. Message(option_too_many_cfg_files);
  1306. { Maybe It's Directory ?} //Jaro Change:
  1307. if DirectoryExists(filename) then
  1308. begin
  1309. Message1(option_config_is_dir,filename);
  1310. exit;
  1311. end;
  1312. { open file }
  1313. Message1(option_using_file,filename);
  1314. {$ifdef USE_SYSUTILS}
  1315. assign(f,ExpandFileName(filename));
  1316. {$else USE_SYSUTILS}
  1317. assign(f,FExpand(filename));
  1318. {$endif USE_SYsUTILS}
  1319. {$I-}
  1320. reset(f);
  1321. {$I+}
  1322. if ioresult<>0 then
  1323. begin
  1324. Message1(option_unable_open_file,filename);
  1325. exit;
  1326. end;
  1327. Message1(option_start_reading_configfile,filename);
  1328. fillchar(skip,sizeof(skip),0);
  1329. level:=0;
  1330. while not eof(f) do
  1331. begin
  1332. readln(f,opts);
  1333. RemoveSep(opts);
  1334. if (opts<>'') and (opts[1]<>';') then
  1335. begin
  1336. if opts[1]='#' then
  1337. begin
  1338. Message1(option_interpreting_file_option,opts);
  1339. Delete(opts,1,1);
  1340. s:=upper(GetName(opts));
  1341. if (s='SECTION') then
  1342. begin
  1343. RemoveSep(opts);
  1344. s:=upper(GetName(opts));
  1345. if level=0 then
  1346. skip[level]:=not (assigned(search_macro(s)) or (s='COMMON'));
  1347. end
  1348. else
  1349. if (s='IFDEF') then
  1350. begin
  1351. RemoveSep(opts);
  1352. if Level>=maxlevel then
  1353. begin
  1354. Message(option_too_many_ifdef);
  1355. stopOptions(1);
  1356. end;
  1357. inc(Level);
  1358. skip[level]:=(skip[level-1] or not assigned(search_macro(upper(GetName(opts)))));
  1359. end
  1360. else
  1361. if (s='IFNDEF') then
  1362. begin
  1363. RemoveSep(opts);
  1364. if Level>=maxlevel then
  1365. begin
  1366. Message(option_too_many_ifdef);
  1367. stopOptions(1);
  1368. end;
  1369. inc(Level);
  1370. skip[level]:=(skip[level-1] or assigned(search_macro(upper(GetName(opts)))));
  1371. end
  1372. else
  1373. if (s='ELSE') then
  1374. skip[level]:=skip[level-1] or (not skip[level])
  1375. else
  1376. if (s='ENDIF') then
  1377. begin
  1378. skip[level]:=false;
  1379. if Level=0 then
  1380. begin
  1381. Message(option_too_many_endif);
  1382. stopOptions(1);
  1383. end;
  1384. dec(level);
  1385. end
  1386. else
  1387. if (not skip[level]) then
  1388. begin
  1389. if (s='DEFINE') then
  1390. begin
  1391. RemoveSep(opts);
  1392. tmp:= GetName(opts);
  1393. if tmp <> '' then
  1394. def_system_macro(tmp);
  1395. end
  1396. else
  1397. if (s='UNDEF') then
  1398. begin
  1399. RemoveSep(opts);
  1400. tmp:= GetName(opts);
  1401. if tmp <> '' then
  1402. undef_system_macro(tmp);
  1403. end
  1404. else
  1405. if (s='WRITE') then
  1406. begin
  1407. Delete(opts,1,1);
  1408. WriteLn(opts);
  1409. end
  1410. else
  1411. if (s='INCLUDE') then
  1412. begin
  1413. Delete(opts,1,1);
  1414. Interpret_file(opts);
  1415. end;
  1416. end;
  1417. end
  1418. else
  1419. begin
  1420. if (opts[1]='-') or (opts[1]='@') then
  1421. begin
  1422. if (not skip[level]) then
  1423. interpret_option(opts,false);
  1424. Option_read:=true;
  1425. end
  1426. else
  1427. Message1(option_illegal_para,opts);
  1428. end;
  1429. end;
  1430. end;
  1431. if Level>0 then
  1432. Message(option_too_less_endif);
  1433. if Not Option_read then
  1434. Message1(option_no_option_found,filename)
  1435. else
  1436. Message1(option_end_reading_configfile,filename);
  1437. Close(f);
  1438. Dec(FileLevel);
  1439. end;
  1440. procedure Toption.Interpret_envvar(const envname : string);
  1441. var
  1442. argstart,
  1443. env,
  1444. pc : pchar;
  1445. arglen : longint;
  1446. quote : set of char;
  1447. hs : string;
  1448. begin
  1449. Message1(option_using_env,envname);
  1450. env:=GetEnvPChar(envname);
  1451. pc:=env;
  1452. if assigned(pc) then
  1453. begin
  1454. repeat
  1455. { skip leading spaces }
  1456. while pc^ in [' ',#9,#13] do
  1457. inc(pc);
  1458. case pc^ of
  1459. #0 :
  1460. break;
  1461. '"' :
  1462. begin
  1463. quote:=['"'];
  1464. inc(pc);
  1465. end;
  1466. '''' :
  1467. begin
  1468. quote:=[''''];
  1469. inc(pc);
  1470. end;
  1471. else
  1472. quote:=[' ',#9,#13];
  1473. end;
  1474. { scan until the end of the argument }
  1475. argstart:=pc;
  1476. while (pc^<>#0) and not(pc^ in quote) do
  1477. inc(pc);
  1478. { create argument }
  1479. arglen:=pc-argstart;
  1480. hs[0]:=chr(arglen);
  1481. move(argstart^,hs[1],arglen);
  1482. interpret_option(hs,true);
  1483. { skip quote }
  1484. if pc^ in quote then
  1485. inc(pc);
  1486. until false;
  1487. end
  1488. else
  1489. Message1(option_no_option_found,'(env) '+envname);
  1490. FreeEnvPChar(env);
  1491. end;
  1492. procedure toption.read_parameters;
  1493. var
  1494. opts : string;
  1495. paramindex : longint;
  1496. begin
  1497. paramindex:=0;
  1498. while paramindex<paramcount do
  1499. begin
  1500. inc(paramindex);
  1501. opts:=system.paramstr(paramindex);
  1502. case opts[1] of
  1503. '@' :
  1504. if not firstpass then
  1505. begin
  1506. Delete(opts,1,1);
  1507. Message1(option_reading_further_from,opts);
  1508. interpret_file(opts);
  1509. end;
  1510. '!' :
  1511. if not firstpass then
  1512. begin
  1513. Delete(opts,1,1);
  1514. Message1(option_reading_further_from,'(env) '+opts);
  1515. interpret_envvar(opts);
  1516. end;
  1517. else
  1518. interpret_option(opts,true);
  1519. end;
  1520. end;
  1521. end;
  1522. procedure toption.parsecmd(cmd:string);
  1523. var
  1524. i,ps : longint;
  1525. opts : string;
  1526. begin
  1527. while (cmd<>'') do
  1528. begin
  1529. while cmd[1]=' ' do
  1530. delete(cmd,1,1);
  1531. i:=pos(' ',cmd);
  1532. if i=0 then
  1533. i:=256;
  1534. opts:=Copy(cmd,1,i-1);
  1535. Delete(cmd,1,i);
  1536. case opts[1] of
  1537. '@' :
  1538. if not firstpass then
  1539. begin
  1540. Delete(opts,1,1);
  1541. Message1(option_reading_further_from,opts);
  1542. interpret_file(opts);
  1543. end;
  1544. '!' :
  1545. if not firstpass then
  1546. begin
  1547. Delete(opts,1,1);
  1548. Message1(option_reading_further_from,'(env) '+opts);
  1549. interpret_envvar(opts);
  1550. end;
  1551. '"' :
  1552. begin
  1553. Delete(opts,1,1);
  1554. ps:=pos('"',cmd);
  1555. if (i<>256) and (ps>0) then
  1556. begin
  1557. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1558. cmd:=copy(cmd,ps+1,255);
  1559. end;
  1560. interpret_option(opts,true);
  1561. end;
  1562. else
  1563. interpret_option(opts,true);
  1564. end;
  1565. end;
  1566. end;
  1567. procedure toption.writequickinfo;
  1568. var
  1569. s : string;
  1570. i : longint;
  1571. procedure addinfo(const hs:string);
  1572. begin
  1573. if s<>'' then
  1574. s:=s+' '+hs
  1575. else
  1576. s:=hs;
  1577. end;
  1578. begin
  1579. s:='';
  1580. i:=0;
  1581. while (i<length(quickinfo)) do
  1582. begin
  1583. inc(i);
  1584. case quickinfo[i] of
  1585. 'S' :
  1586. begin
  1587. inc(i);
  1588. case quickinfo[i] of
  1589. 'O' :
  1590. addinfo(lower(source_info.shortname));
  1591. 'P' :
  1592. addinfo(source_cpu_string);
  1593. else
  1594. IllegalPara('-i'+QuickInfo);
  1595. end;
  1596. end;
  1597. 'T' :
  1598. begin
  1599. inc(i);
  1600. case quickinfo[i] of
  1601. 'O' :
  1602. addinfo(lower(target_info.shortname));
  1603. 'P' :
  1604. AddInfo(target_cpu_string);
  1605. else
  1606. IllegalPara('-i'+QuickInfo);
  1607. end;
  1608. end;
  1609. 'V' :
  1610. AddInfo(version_string);
  1611. 'D' :
  1612. AddInfo(date_string);
  1613. '_' :
  1614. ;
  1615. else
  1616. IllegalPara('-i'+QuickInfo);
  1617. end;
  1618. end;
  1619. if s<>'' then
  1620. begin
  1621. writeln(s);
  1622. stopoptions(0);
  1623. end;
  1624. end;
  1625. procedure TOption.TargetDefines(def:boolean);
  1626. var
  1627. s : string;
  1628. i : integer;
  1629. begin
  1630. if def then
  1631. def_system_macro(target_info.shortname)
  1632. else
  1633. undef_system_macro(target_info.shortname);
  1634. s:=target_info.extradefines;
  1635. while (s<>'') do
  1636. begin
  1637. i:=pos(';',s);
  1638. if i=0 then
  1639. i:=length(s)+1;
  1640. if def then
  1641. def_system_macro(Copy(s,1,i-1))
  1642. else
  1643. undef_system_macro(Copy(s,1,i-1));
  1644. delete(s,1,i);
  1645. end;
  1646. end;
  1647. constructor TOption.create;
  1648. begin
  1649. LogoWritten:=false;
  1650. NoPressEnter:=false;
  1651. FirstPass:=false;
  1652. FileLevel:=0;
  1653. Quickinfo:='';
  1654. ParaIncludePath:=TSearchPathList.Create;
  1655. ParaObjectPath:=TSearchPathList.Create;
  1656. ParaUnitPath:=TSearchPathList.Create;
  1657. ParaLibraryPath:=TSearchPathList.Create;
  1658. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1659. end;
  1660. destructor TOption.destroy;
  1661. begin
  1662. ParaIncludePath.Free;
  1663. ParaObjectPath.Free;
  1664. ParaUnitPath.Free;
  1665. ParaLibraryPath.Free;
  1666. end;
  1667. {****************************************************************************
  1668. Callable Routines
  1669. ****************************************************************************}
  1670. function check_configfile(const fn:string;var foundfn:string):boolean;
  1671. function CfgFileExists(const fn:string):boolean;
  1672. begin
  1673. Comment(V_Tried,'Configfile search: '+fn);
  1674. CfgFileExists:=FileExists(fn);
  1675. end;
  1676. var
  1677. configpath : pathstr;
  1678. begin
  1679. foundfn:=fn;
  1680. check_configfile:=true;
  1681. { retrieve configpath }
  1682. {$IFDEF USE_SYSUTILS}
  1683. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  1684. {$ELSE USE_SYSUTILS}
  1685. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1686. {$ENDIF USE_SYSUTILS}
  1687. {$ifdef Unix}
  1688. if configpath='' then
  1689. configpath:=CleanPath(FixPath(exepath+'../etc/',false));
  1690. {$endif}
  1691. {
  1692. Order to read configuration file :
  1693. try reading fpc.cfg in :
  1694. 1 - current dir
  1695. 2 - configpath
  1696. 3 - compiler path
  1697. }
  1698. if not FileExists(fn) then
  1699. begin
  1700. {$ifdef Unix}
  1701. {$IFDEF USE_SYSUTILS}
  1702. if (GetEnvironmentVariable('HOME')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn) then
  1703. foundfn:=FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn
  1704. {$ELSE USE_SYSUTILS}
  1705. if (dos.getenv('HOME')<>'') and CfgFileExists(FixPath(dos.getenv('HOME'),false)+'.'+fn) then
  1706. foundfn:=FixPath(dos.getenv('HOME'),false)+'.'+fn
  1707. {$ENDIF USE_SYSUTILS}
  1708. else
  1709. {$endif}
  1710. if CfgFileExists(configpath+fn) then
  1711. foundfn:=configpath+fn
  1712. else
  1713. {$ifndef Unix}
  1714. if CfgFileExists(exepath+fn) then
  1715. foundfn:=exepath+fn
  1716. else
  1717. {$else}
  1718. if CfgFileExists('/etc/'+fn) then
  1719. foundfn:='/etc/'+fn
  1720. else
  1721. {$endif}
  1722. check_configfile:=false;
  1723. end;
  1724. end;
  1725. procedure read_arguments(cmd:string);
  1726. begin
  1727. option:=coption.create;
  1728. disable_configfile:=false;
  1729. { get default messagefile }
  1730. {$IFDEF USE_SYSUTILS}
  1731. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  1732. {$ELSE USE_SYSUTILS}
  1733. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1734. {$ENDIF USE_SYSUTILS}
  1735. { default configfile can be specified on the commandline,
  1736. remove it first }
  1737. if (cmd<>'') and (cmd[1]='[') then
  1738. begin
  1739. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1740. Delete(cmd,1,pos(']',cmd));
  1741. end
  1742. else
  1743. begin
  1744. ppccfg:='fpc.cfg';
  1745. ppcaltcfg:='ppc386.cfg';
  1746. end;
  1747. { first pass reading of parameters, only -i -v -T etc.}
  1748. option.firstpass:=true;
  1749. if cmd<>'' then
  1750. option.parsecmd(cmd)
  1751. else
  1752. begin
  1753. option.read_parameters;
  1754. { Write only quickinfo }
  1755. if option.quickinfo<>'' then
  1756. option.writequickinfo;
  1757. end;
  1758. option.firstpass:=false;
  1759. { target is set here, for wince the default app type is gui }
  1760. if target_info.system in system_wince then
  1761. apptype:=app_gui;
  1762. { default defines }
  1763. def_system_macro(target_info.shortname);
  1764. def_system_macro('FPC');
  1765. def_system_macro('VER'+version_nr);
  1766. def_system_macro('VER'+version_nr+'_'+release_nr);
  1767. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1768. { Temporary defines, until things settle down }
  1769. { "main" symbol is generated in the main program, and left out of the system unit }
  1770. def_system_macro('FPC_DARWIN_PASCALMAIN');
  1771. def_system_macro('FPC_DARWIN_JMP_MAIN');
  1772. def_system_macro('COMPPROCINLINEFIXED');
  1773. def_system_macro('PARAOUTFILE');
  1774. def_system_macro('RESSTRSECTIONS');
  1775. if pocall_default = pocall_register then
  1776. def_system_macro('REGCALL');
  1777. { using a case is pretty useless here (FK) }
  1778. { some stuff for TP compatibility }
  1779. {$ifdef i386}
  1780. def_system_macro('CPU86');
  1781. def_system_macro('CPU87');
  1782. {$endif}
  1783. {$ifdef m68k}
  1784. def_system_macro('CPU68');
  1785. {$endif}
  1786. { new processor stuff }
  1787. {$ifdef i386}
  1788. def_system_macro('CPUI386');
  1789. def_system_macro('CPU32');
  1790. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  1791. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1792. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1793. def_system_macro('FPC_HAS_RESOURCES');
  1794. {$endif}
  1795. {$ifdef m68k}
  1796. def_system_macro('CPU68K');
  1797. def_system_macro('CPUM68K');
  1798. def_system_macro('CPU32');
  1799. def_system_macro('FPC_CURRENCY_IS_INT64');
  1800. def_system_macro('FPC_COMP_IS_INT64');
  1801. {$endif}
  1802. {$ifdef ALPHA}
  1803. def_system_macro('CPUALPHA');
  1804. def_system_macro('CPU64');
  1805. {$endif}
  1806. {$ifdef powerpc}
  1807. def_system_macro('CPUPOWERPC');
  1808. def_system_macro('CPUPOWERPC32');
  1809. def_system_macro('CPU32');
  1810. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1811. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1812. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1813. def_system_macro('FPC_CURRENCY_IS_INT64');
  1814. def_system_macro('FPC_COMP_IS_INT64');
  1815. {$endif}
  1816. {$ifdef POWERPC64}
  1817. def_system_macro('CPUPOWERPC');
  1818. def_system_macro('CPUPOWERPC64');
  1819. def_system_macro('CPU64');
  1820. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1821. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1822. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1823. def_system_macro('FPC_CURRENCY_IS_INT64');
  1824. def_system_macro('FPC_COMP_IS_INT64');
  1825. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1826. {$endif}
  1827. {$ifdef iA64}
  1828. def_system_macro('CPUIA64');
  1829. def_system_macro('CPU64');
  1830. {$endif}
  1831. {$ifdef x86_64}
  1832. def_system_macro('CPUX86_64');
  1833. def_system_macro('CPUAMD64');
  1834. def_system_macro('CPU64');
  1835. { not supported for now, afaik (FK)
  1836. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  1837. { win64 doesn't support the legacy fpu }
  1838. if target_info.system<>system_x86_64_win64 then
  1839. def_system_macro('FPC_HAS_TYPE_EXTENDED')
  1840. else
  1841. begin
  1842. def_system_macro('FPC_CURRENCY_IS_INT64');
  1843. def_system_macro('FPC_COMP_IS_INT64');
  1844. undef_system_macro('FPC_HAS_TYPE_EXTENDED');
  1845. end;
  1846. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1847. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1848. {$endif}
  1849. {$ifdef sparc}
  1850. def_system_macro('CPUSPARC');
  1851. def_system_macro('CPUSPARC32');
  1852. def_system_macro('CPU32');
  1853. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1854. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1855. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1856. def_system_macro('FPC_CURRENCY_IS_INT64');
  1857. def_system_macro('FPC_COMP_IS_INT64');
  1858. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1859. {$endif}
  1860. {$ifdef vis}
  1861. def_system_macro('CPUVIS');
  1862. def_system_macro('CPU32');
  1863. {$endif}
  1864. {$ifdef arm}
  1865. def_system_macro('CPUARM');
  1866. def_system_macro('FPUFPA');
  1867. def_system_macro('CPU32');
  1868. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1869. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1870. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1871. def_system_macro('FPC_CURRENCY_IS_INT64');
  1872. def_system_macro('FPC_COMP_IS_INT64');
  1873. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1874. {$endif arm}
  1875. if source_info.system<>target_info.system then
  1876. def_system_macro('FPC_CROSSCOMPILING');
  1877. if source_info.cpu<>target_info.cpu then
  1878. def_system_macro('FPC_CPUCROSSCOMPILING');
  1879. { read configuration file }
  1880. if (not disable_configfile) and
  1881. (ppccfg<>'') then
  1882. begin
  1883. read_configfile:=check_configfile(ppccfg,ppccfg);
  1884. { Maybe alternative configfile ? }
  1885. if (not read_configfile) and
  1886. (ppcaltcfg<>'') then
  1887. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  1888. end
  1889. else
  1890. read_configfile := false;
  1891. { Read commandline and configfile }
  1892. param_file:='';
  1893. { read configfile }
  1894. if read_configfile then
  1895. option.interpret_file(ppccfg);
  1896. { read parameters again to override config file }
  1897. if cmd<>'' then
  1898. option.parsecmd(cmd)
  1899. else
  1900. begin
  1901. { Write help pages if no parameters are passed }
  1902. if (paramcount=0) then
  1903. Option.WriteHelpPages;
  1904. option.read_parameters;
  1905. { Write only quickinfo }
  1906. if option.quickinfo<>'' then
  1907. option.writequickinfo;
  1908. end;
  1909. { Stop if errors in options }
  1910. if ErrorCount>0 then
  1911. StopOptions(1);
  1912. { Write logo }
  1913. if option.ParaLogo then
  1914. option.writelogo;
  1915. { Non-core target defines }
  1916. Option.TargetDefines(true);
  1917. { endian define }
  1918. case target_info.endian of
  1919. endian_little :
  1920. begin
  1921. def_system_macro('ENDIAN_LITTLE');
  1922. def_system_macro('FPC_LITTLE_ENDIAN');
  1923. end;
  1924. endian_big :
  1925. begin
  1926. def_system_macro('ENDIAN_BIG');
  1927. def_system_macro('FPC_BIG_ENDIAN');
  1928. end;
  1929. end;
  1930. { abi define }
  1931. case target_info.abi of
  1932. abi_powerpc_sysv :
  1933. def_system_macro('FPC_ABI_SYSV');
  1934. abi_powerpc_aix :
  1935. def_system_macro('FPC_ABI_AIX');
  1936. end;
  1937. { CPU Define }
  1938. def_system_macro('CPU'+Cputypestr[initcputype]);
  1939. { Check file to compile }
  1940. if param_file='' then
  1941. begin
  1942. Message(option_no_source_found);
  1943. StopOptions(1);
  1944. end;
  1945. {$ifndef Unix}
  1946. param_file:=FixFileName(param_file);
  1947. {$endif}
  1948. {$IFDEF USE_SYSUTILS}
  1949. inputdir := SplitPath(param_file);
  1950. inputfile := SplitName(param_file);
  1951. inputextension := SplitExtension(param_file);
  1952. {$ELSE USE_SYSUTILS}
  1953. fsplit(param_file,inputdir,inputfile,inputextension);
  1954. {$ENDIF USE_SYSUTILS}
  1955. if inputextension='' then
  1956. begin
  1957. if FileExists(inputdir+inputfile+sourceext) then
  1958. inputextension:=sourceext
  1959. else if FileExists(inputdir+inputfile+pasext) then
  1960. inputextension:=pasext
  1961. else if ((m_mac in aktmodeswitches) or
  1962. (tf_p_ext_support in target_info.flags))
  1963. and FileExists(inputdir+inputfile+pext) then
  1964. inputextension:=pext;
  1965. end;
  1966. { Check output dir }
  1967. if (OutputExeDir<>'') and
  1968. not PathExists(OutputExeDir) then
  1969. begin
  1970. Message1(general_e_path_does_not_exist,OutputExeDir);
  1971. StopOptions(1);
  1972. end;
  1973. { Add paths specified with parameters to the searchpaths }
  1974. UnitSearchPath.AddList(option.ParaUnitPath,true);
  1975. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  1976. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  1977. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  1978. { add unit environment and exepath to the unit search path }
  1979. if inputdir<>'' then
  1980. Unitsearchpath.AddPath(inputdir,true);
  1981. if not disable_configfile then
  1982. begin
  1983. {$IFDEF USE_SYSUTILS}
  1984. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  1985. {$ELSE USE_SYSUTILS}
  1986. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  1987. {$ENDIF USE_SYSUTILS}
  1988. end;
  1989. {$ifdef Unix}
  1990. {$IFDEF USE_SYSUTILS}
  1991. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  1992. {$ELSE USE_SYSUTILS}
  1993. fpcdir:=FixPath(getenv('FPCDIR'),false);
  1994. {$ENDIF USE_SYSUTILS}
  1995. if fpcdir='' then
  1996. begin
  1997. if PathExists('/usr/local/lib/fpc/'+version_string) then
  1998. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  1999. else
  2000. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2001. end;
  2002. {$else}
  2003. {$IFDEF USE_SYSUTILS}
  2004. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2005. {$ELSE USE_SYSUTILS}
  2006. fpcdir:=FixPath(getenv('FPCDIR'),false);
  2007. {$ENDIF USE_SYSUTILS}
  2008. if fpcdir='' then
  2009. begin
  2010. fpcdir:=ExePath+'../';
  2011. if not(PathExists(fpcdir+'/units')) and
  2012. not(PathExists(fpcdir+'/rtl')) then
  2013. fpcdir:=fpcdir+'../';
  2014. end;
  2015. {$endif}
  2016. { first try development RTL, else use the default installation path }
  2017. if not disable_configfile then
  2018. begin
  2019. if PathExists(FpcDir+'rtl') then
  2020. if tf_use_8_3 in Source_Info.Flags then
  2021. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2022. else
  2023. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2024. else
  2025. if tf_use_8_3 in Source_Info.Flags then
  2026. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2027. else
  2028. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2029. end;
  2030. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2031. Do not add it when linking on the target because then we can maybe already find
  2032. .o files that are not for the target }
  2033. if (ExePath<>GetCurrentDir) and
  2034. not(cs_link_on_target in initglobalswitches) then
  2035. UnitSearchPath.AddPath(ExePath,false);
  2036. { Add unit dir to the object and library path }
  2037. objectsearchpath.AddList(unitsearchpath,false);
  2038. librarysearchpath.AddList(unitsearchpath,false);
  2039. { maybe override debug info format }
  2040. if (paratargetdbg<>dbg_none) then
  2041. set_target_dbg(paratargetdbg);
  2042. { maybe override assembler }
  2043. if (paratargetasm<>as_none) then
  2044. begin
  2045. if not set_target_asm(paratargetasm) then
  2046. begin
  2047. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2048. set_target_asm(target_info.assemextern);
  2049. Message1(option_asm_forced,target_asm.idtxt);
  2050. end;
  2051. end;
  2052. { switch assembler if it's binary and we got -a on the cmdline }
  2053. if (cs_asm_leave in initglobalswitches) and
  2054. (af_outputbinary in target_asm.flags) then
  2055. begin
  2056. Message(option_switch_bin_to_src_assembler);
  2057. set_target_asm(target_info.assemextern);
  2058. end;
  2059. { disable internal linker if it is not registered }
  2060. if not assigned(target_info.link) and
  2061. (cs_link_internal in initglobalswitches) then
  2062. exclude(initglobalswitches,cs_link_internal);
  2063. { turn off stripping if compiling with debuginfo or profile }
  2064. if (cs_debuginfo in initmoduleswitches) or
  2065. (cs_profile in initmoduleswitches) then
  2066. exclude(initglobalswitches,cs_link_strip);
  2067. { force fpu emulation on arm/wince }
  2068. if target_info.system=system_arm_wince then
  2069. include(initmoduleswitches,cs_fp_emulation);
  2070. { Section smartlinking conflicts with import sections on Windows }
  2071. if GenerateImportSection and
  2072. (target_info.system in [system_i386_win32]) then
  2073. exclude(target_info.flags,tf_smartlink_sections);
  2074. if (cs_link_extern in initglobalswitches) then
  2075. exclude(initglobalswitches,cs_link_internal);
  2076. if (cs_link_internal in initglobalswitches) then
  2077. begin
  2078. { By default don't create import section if we use the internal linker }
  2079. if not GenerateImportSectionSetExplicitly then
  2080. GenerateImportSection:=false;
  2081. { Enable section smartlinking }
  2082. include(target_info.flags,tf_smartlink_sections);
  2083. end;
  2084. {$ifdef x86_64}
  2085. {$warning HACK: turn off smartlinking}
  2086. exclude(initmoduleswitches,cs_create_smart);
  2087. {$endif}
  2088. if not LinkTypeSetExplicitly then
  2089. set_default_link_type;
  2090. { Default alignment settings,
  2091. 1. load the defaults for the target
  2092. 2. override with generic optimizer setting (little size)
  2093. 3. override with the user specified -Oa }
  2094. UpdateAlignment(initalignment,target_info.alignment);
  2095. if (cs_opt_size in aktoptimizerswitches) then
  2096. begin
  2097. initalignment.procalign:=1;
  2098. initalignment.jumpalign:=1;
  2099. initalignment.loopalign:=1;
  2100. end;
  2101. UpdateAlignment(initalignment,option.paraalignment);
  2102. set_system_macro('FPC_VERSION',version_nr);
  2103. set_system_macro('FPC_RELEASE',release_nr);
  2104. set_system_macro('FPC_PATCH',patch_nr);
  2105. option.free;
  2106. Option:=nil;
  2107. end;
  2108. initialization
  2109. coption:=toption;
  2110. finalization
  2111. if assigned(option) then
  2112. option.free;
  2113. end.