options.pas 68 KB

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