options.pas 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294
  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' :
  690. begin
  691. if UnsetBool(More, 0) then
  692. begin
  693. exclude(initmoduleswitches,cs_debuginfo);
  694. exclude(initglobalswitches,cs_use_heaptrc);
  695. exclude(initglobalswitches,cs_use_lineinfo);
  696. exclude(initlocalswitches,cs_checkpointer);
  697. localvartrashing := -1;
  698. end
  699. else
  700. begin
  701. include(initmoduleswitches,cs_debuginfo);
  702. end;
  703. if not RelocSectionSetExplicitly then
  704. RelocSection:=false;
  705. j:=1;
  706. while j<=length(more) do
  707. begin
  708. case more[j] of
  709. 'c' :
  710. begin
  711. if UnsetBool(More, j) then
  712. exclude(initlocalswitches,cs_checkpointer)
  713. else
  714. include(initlocalswitches,cs_checkpointer);
  715. end;
  716. 'd' :
  717. begin
  718. paratargetdbg:=dbg_dwarf2;
  719. end;
  720. 'h' :
  721. begin
  722. if UnsetBool(More, j) then
  723. exclude(initglobalswitches,cs_use_heaptrc)
  724. else
  725. include(initglobalswitches,cs_use_heaptrc);
  726. end;
  727. 'l' :
  728. begin
  729. if UnsetBool(More, j) then
  730. exclude(initglobalswitches,cs_use_lineinfo)
  731. else
  732. include(initglobalswitches,cs_use_lineinfo);
  733. end;
  734. 's' :
  735. begin
  736. paratargetdbg:=dbg_stabs;
  737. end;
  738. 't' :
  739. begin
  740. if UnsetBool(More, j) then
  741. localvartrashing := -1
  742. else
  743. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  744. end;
  745. 'v' :
  746. begin
  747. if UnsetBool(More, j) then
  748. exclude(initglobalswitches,cs_gdb_valgrind)
  749. else
  750. include(initglobalswitches,cs_gdb_valgrind);
  751. end;
  752. 'w' :
  753. begin
  754. if (j<length(more)) and (more[j+1] in ['2','3']) then
  755. begin
  756. case more[j+1] of
  757. '2': paratargetdbg:=dbg_dwarf2;
  758. '3': paratargetdbg:=dbg_dwarf3;
  759. end;
  760. inc(j);
  761. end
  762. else
  763. paratargetdbg:=dbg_dwarf2;
  764. end;
  765. else
  766. IllegalPara(opt);
  767. end;
  768. inc(j);
  769. end;
  770. end;
  771. 'h' :
  772. begin
  773. NoPressEnter:=true;
  774. WriteHelpPages;
  775. end;
  776. 'i' :
  777. begin
  778. if More='' then
  779. WriteInfo
  780. else
  781. QuickInfo:=QuickInfo+More;
  782. end;
  783. 'I' :
  784. begin
  785. if ispara then
  786. ParaIncludePath.AddPath(More,false)
  787. else
  788. includesearchpath.AddPath(More,false);
  789. end;
  790. 'k' :
  791. begin
  792. if more<>'' then
  793. ParaLinkOptions:=ParaLinkOptions+' '+More
  794. else
  795. IllegalPara(opt);
  796. end;
  797. 'l' :
  798. if not UnSetBool(more,0) then
  799. ParaLogo:=true;
  800. 'm' :
  801. parapreprocess:=not UnSetBool(more,0);
  802. 'M' :
  803. begin
  804. more:=Upper(more);
  805. if not SetCompileMode(more, true) then
  806. IllegalPara(opt);
  807. end;
  808. 'n' :
  809. begin
  810. if More='' then
  811. disable_configfile:=true
  812. else
  813. IllegalPara(opt);
  814. end;
  815. 'o' :
  816. begin
  817. if More<>'' then
  818. begin
  819. DefaultReplacements(More);
  820. {$IFDEF USE_SYSUTILS}
  821. D:=SplitPath(More);
  822. OutputFile:=SplitFileName(More);
  823. OutputExtension:=SplitExtension(More);
  824. {$ELSE USE_SYSUTILS}
  825. FSplit(More,D,OutputFile,OutputExtension);
  826. {$ENDIF USE_SYSUTILS}
  827. if (D<>'') then
  828. OutputExeDir:=FixPath(D,True);
  829. end
  830. else
  831. IllegalPara(opt);
  832. end;
  833. 'O' :
  834. begin
  835. j:=1;
  836. while j<=length(more) do
  837. begin
  838. case more[j] of
  839. '1' :
  840. initoptimizerswitches:=initoptimizerswitches+level1optimizerswitches;
  841. '2' :
  842. initoptimizerswitches:=initoptimizerswitches+level2optimizerswitches;
  843. '3' :
  844. initoptimizerswitches:=initoptimizerswitches+level3optimizerswitches;
  845. 'a' :
  846. begin
  847. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  848. IllegalPara(opt);
  849. break;
  850. end;
  851. 's' :
  852. include(initoptimizerswitches,cs_opt_size);
  853. 'p' :
  854. begin
  855. if not Setcputype(copy(more,j+1,length(more)),initoptimizecputype) then
  856. begin
  857. { Give warning for old i386 switches }
  858. if (Length(More)-j=1) and
  859. (More[j+1]>='1') and (More[j+1]<='5')then
  860. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  861. else
  862. IllegalPara(opt);
  863. end;
  864. break;
  865. end;
  866. 'o' :
  867. begin
  868. if not UpdateOptimizerStr(copy(more,j+1,length(more)),initoptimizerswitches) then
  869. IllegalPara(opt);
  870. break;
  871. end;
  872. '-' :
  873. begin
  874. initoptimizerswitches:=[];
  875. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  876. end;
  877. { Obsolete switches }
  878. 'g' :
  879. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  880. 'G' :
  881. Message1(option_obsolete_switch,'-OG');
  882. 'r' :
  883. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  884. 'u' :
  885. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  886. else
  887. IllegalPara(opt);
  888. end;
  889. inc(j);
  890. end;
  891. end;
  892. 'p' :
  893. begin
  894. if UnsetBool(More, 0) then
  895. begin
  896. initmoduleswitches:=initmoduleswitches-[cs_profile];
  897. undef_system_macro('FPC_PROFILE');
  898. end
  899. else
  900. if Length(More)=0 then
  901. IllegalPara(opt)
  902. else
  903. case more[1] of
  904. 'g' : if UnsetBool(more, 1) then
  905. begin
  906. exclude(initmoduleswitches,cs_profile);
  907. undef_system_macro('FPC_PROFILE');
  908. end
  909. else
  910. begin
  911. include(initmoduleswitches,cs_profile);
  912. def_system_macro('FPC_PROFILE');
  913. end;
  914. else
  915. IllegalPara(opt);
  916. end;
  917. end;
  918. 'P' : ; { Ignore used by fpc.pp }
  919. 'R' :
  920. begin
  921. if not SetAsmReadMode(More,initasmmode) then
  922. IllegalPara(opt);
  923. end;
  924. 's' :
  925. begin
  926. if UnsetBool(More, 0) then
  927. begin
  928. initglobalswitches:=initglobalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  929. if more<>'' then
  930. IllegalPara(opt);
  931. end
  932. else
  933. begin
  934. initglobalswitches:=initglobalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  935. if more='h' then
  936. initglobalswitches:=initglobalswitches-[cs_link_on_target]
  937. else if more='t' then
  938. initglobalswitches:=initglobalswitches+[cs_link_on_target]
  939. else if more='r' then
  940. initglobalswitches:=initglobalswitches+[cs_asm_leave,cs_no_regalloc]
  941. else if more<>'' then
  942. IllegalPara(opt);
  943. end;
  944. end;
  945. 'S' :
  946. begin
  947. if more[1]='I' then
  948. begin
  949. if upper(more)='ICOM' then
  950. initinterfacetype:=it_interfacecom
  951. else if upper(more)='ICORBA' then
  952. initinterfacetype:=it_interfacecorba
  953. else
  954. IllegalPara(opt);
  955. end
  956. else
  957. begin
  958. j:=1;
  959. while j<=length(more) do
  960. begin
  961. case more[j] of
  962. '2' : //an alternative to -Mobjfpc
  963. SetCompileMode('OBJFPC',true);
  964. 'a' :
  965. include(initlocalswitches,cs_do_assertion);
  966. 'c' :
  967. include(initmoduleswitches,cs_support_c_operators);
  968. 'd' : //an alternative to -Mdelphi
  969. SetCompileMode('DELPHI',true);
  970. 'e' :
  971. begin
  972. SetErrorFlags(copy(more,j+1,length(more)));
  973. break;
  974. end;
  975. 'g' :
  976. include(initmoduleswitches,cs_support_goto);
  977. 'h' :
  978. include(initlocalswitches,cs_ansistrings);
  979. 'i' :
  980. include(initlocalswitches,cs_do_inline);
  981. 'k' :
  982. include(initglobalswitches,cs_load_fpcylix_unit);
  983. 'm' :
  984. include(initmoduleswitches,cs_support_macro);
  985. 'o' : //an alternative to -Mtp
  986. SetCompileMode('TP',true);
  987. 'p' : //an alternative to -Mgpc
  988. SetCompileMode('GPC',true);
  989. 's' :
  990. include(initglobalswitches,cs_constructor_name);
  991. 't' :
  992. include(initmoduleswitches,cs_static_keyword);
  993. '-' :
  994. begin
  995. exclude(initglobalswitches,cs_constructor_name);
  996. initlocalswitches:=InitLocalswitches - [cs_do_assertion, cs_do_inline, cs_ansistrings];
  997. initmoduleswitches:=initmoduleswitches - [cs_support_c_operators, cs_support_goto,
  998. cs_support_macro,
  999. cs_static_keyword];
  1000. end;
  1001. else
  1002. IllegalPara(opt);
  1003. end;
  1004. inc(j);
  1005. end;
  1006. end;
  1007. end;
  1008. 'T' :
  1009. begin
  1010. more:=Upper(More);
  1011. if paratarget=system_none then
  1012. begin
  1013. { remove old target define }
  1014. TargetDefines(false);
  1015. { load new target }
  1016. paratarget:=find_system_by_string(More);
  1017. if paratarget<>system_none then
  1018. set_target(paratarget)
  1019. else
  1020. IllegalPara(opt);
  1021. { set new define }
  1022. TargetDefines(true);
  1023. end
  1024. else
  1025. if More<>upper(target_info.shortname) then
  1026. Message1(option_target_is_already_set,target_info.shortname);
  1027. end;
  1028. 'u' :
  1029. if more <> '' then
  1030. undef_system_macro(more);
  1031. 'U' :
  1032. begin
  1033. j:=1;
  1034. while j<=length(more) do
  1035. begin
  1036. case more[j] of
  1037. {$ifdef UNITALIASES}
  1038. 'a' :
  1039. begin
  1040. AddUnitAlias(Copy(More,j+1,255));
  1041. break;
  1042. end;
  1043. {$endif UNITALIASES}
  1044. 'n' :
  1045. exclude(initglobalswitches,cs_check_unit_name);
  1046. 'p' :
  1047. begin
  1048. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1049. break;
  1050. end;
  1051. 'r' :
  1052. do_release:=true;
  1053. 's' :
  1054. include(initmoduleswitches,cs_compilesystem);
  1055. '-' :
  1056. begin
  1057. exclude(initmoduleswitches,cs_compilesystem);
  1058. exclude(initglobalswitches,cs_check_unit_name);
  1059. end;
  1060. else
  1061. IllegalPara(opt);
  1062. end;
  1063. inc(j);
  1064. end;
  1065. end;
  1066. 'v' :
  1067. begin
  1068. if not setverbosity(More) then
  1069. IllegalPara(opt);
  1070. end;
  1071. 'V' : ; { Ignore used by fpc }
  1072. 'W' :
  1073. begin
  1074. j:=1;
  1075. while j<=length(More) do
  1076. begin
  1077. case More[j] of
  1078. 'A':
  1079. begin
  1080. if UnsetBool(More, j) then
  1081. apptype:=app_native
  1082. else
  1083. apptype:=app_cui;
  1084. end;
  1085. 'B':
  1086. begin
  1087. { -WB200000 means set trefered base address
  1088. to $200000, but does not change relocsection boolean
  1089. this way we can create both relocatble and
  1090. non relocatable DLL at a specific base address PM }
  1091. if (length(More)>j) then
  1092. begin
  1093. if DLLImageBase=nil then
  1094. DLLImageBase:=StringDup(Copy(More,j+1,255));
  1095. end
  1096. else
  1097. begin
  1098. RelocSection:=true;
  1099. RelocSectionSetExplicitly:=true;
  1100. end;
  1101. break;
  1102. end;
  1103. 'C':
  1104. begin
  1105. if UnsetBool(More, j) then
  1106. apptype:=app_gui
  1107. else
  1108. apptype:=app_cui;
  1109. end;
  1110. 'D':
  1111. begin
  1112. UseDeffileForExports:=not UnsetBool(More, j);
  1113. UseDeffileForExportsSetExplicitly:=true;
  1114. end;
  1115. 'F':
  1116. begin
  1117. if UnsetBool(More, j) then
  1118. apptype:=app_cui
  1119. else
  1120. apptype:=app_fs;
  1121. end;
  1122. 'G':
  1123. begin
  1124. if UnsetBool(More, j) then
  1125. apptype:=app_cui
  1126. else
  1127. apptype:=app_gui;
  1128. end;
  1129. 'I':
  1130. begin
  1131. GenerateImportSection:=not UnsetBool(More,j);
  1132. GenerateImportSectionSetExplicitly:=true;
  1133. end;
  1134. 'N':
  1135. begin
  1136. RelocSection:=UnsetBool(More,j);
  1137. RelocSectionSetExplicitly:=true;
  1138. end;
  1139. 'R':
  1140. begin
  1141. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1142. RelocSection:=not UnsetBool(More,j);
  1143. RelocSectionSetExplicitly:=true;
  1144. end;
  1145. 'T':
  1146. begin
  1147. if UnsetBool(More, j) then
  1148. apptype:=app_cui
  1149. else
  1150. apptype:=app_tool;
  1151. end;
  1152. else
  1153. IllegalPara(opt);
  1154. end;
  1155. inc(j);
  1156. end;
  1157. end;
  1158. 'X' :
  1159. begin
  1160. j:=1;
  1161. while j<=length(more) do
  1162. begin
  1163. case More[j] of
  1164. 'c' : Cshared:=TRUE;
  1165. 'd' : Dontlinkstdlibpath:=TRUE;
  1166. 'e' :
  1167. begin
  1168. If UnsetBool(More, j) then
  1169. exclude(initglobalswitches,cs_link_extern)
  1170. else
  1171. include(initglobalswitches,cs_link_extern);
  1172. end;
  1173. 'f' :
  1174. include(initglobalswitches,cs_link_pthread);
  1175. 'i' :
  1176. begin
  1177. If UnsetBool(More, j) then
  1178. include(initglobalswitches,cs_link_extern)
  1179. else
  1180. exclude(initglobalswitches,cs_link_extern);
  1181. end;
  1182. 'm' :
  1183. begin
  1184. If UnsetBool(More, j) then
  1185. exclude(initglobalswitches,cs_link_map)
  1186. else
  1187. include(initglobalswitches,cs_link_map);
  1188. end;
  1189. 'r' :
  1190. begin
  1191. rlinkpath:=Copy(more,2,length(More)-1);
  1192. DefaultReplacements(rlinkpath);
  1193. More:='';
  1194. end;
  1195. 's' :
  1196. begin
  1197. If UnsetBool(More, j) then
  1198. exclude(initglobalswitches,cs_link_strip)
  1199. else
  1200. include(initglobalswitches,cs_link_strip);
  1201. end;
  1202. 't' :
  1203. include(initglobalswitches,cs_link_staticflag);
  1204. 'v' :
  1205. begin
  1206. If UnsetBool(More, j) then
  1207. exclude(initglobalswitches,cs_link_opt_vtable)
  1208. else
  1209. include(initglobalswitches,cs_link_opt_vtable);
  1210. end;
  1211. 'D' :
  1212. begin
  1213. def_system_macro('FPC_LINK_DYNAMIC');
  1214. undef_system_macro('FPC_LINK_SMART');
  1215. undef_system_macro('FPC_LINK_STATIC');
  1216. exclude(initglobalswitches,cs_link_static);
  1217. exclude(initglobalswitches,cs_link_smart);
  1218. include(initglobalswitches,cs_link_shared);
  1219. LinkTypeSetExplicitly:=true;
  1220. end;
  1221. 'M' :
  1222. begin
  1223. mainaliasname:=Copy(more,2,length(More)-1);
  1224. More:='';
  1225. end;
  1226. 'P' :
  1227. begin
  1228. utilsprefix:=Copy(more,2,length(More)-1);
  1229. DefaultReplacements(utilsprefix);
  1230. More:='';
  1231. end;
  1232. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1233. // these are not aggregable.
  1234. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1235. IllegalPara(opt)
  1236. else
  1237. begin
  1238. case more[j+1] of
  1239. 'A' : begin
  1240. s:=Copy(more,3,length(More)-2);
  1241. if not LinkLibraryAliases.AddDep(s) Then
  1242. IllegalPara(opt);
  1243. end;
  1244. 'O' : begin
  1245. s:=Copy(more,3,length(More)-2);
  1246. if not LinkLibraryOrder.AddWeight(s) Then
  1247. IllegalPara(opt);
  1248. end;
  1249. 'D' : include(initglobalswitches,cs_link_no_default_lib_order)
  1250. else
  1251. IllegalPara(opt);
  1252. end; {case}
  1253. j:=length(more);
  1254. end; {else begin}
  1255. end;
  1256. 'S' :
  1257. begin
  1258. def_system_macro('FPC_LINK_STATIC');
  1259. undef_system_macro('FPC_LINK_SMART');
  1260. undef_system_macro('FPC_LINK_DYNAMIC');
  1261. include(initglobalswitches,cs_link_static);
  1262. exclude(initglobalswitches,cs_link_smart);
  1263. exclude(initglobalswitches,cs_link_shared);
  1264. LinkTypeSetExplicitly:=true;
  1265. end;
  1266. 'X' :
  1267. begin
  1268. def_system_macro('FPC_LINK_SMART');
  1269. undef_system_macro('FPC_LINK_STATIC');
  1270. undef_system_macro('FPC_LINK_DYNAMIC');
  1271. exclude(initglobalswitches,cs_link_static);
  1272. include(initglobalswitches,cs_link_smart);
  1273. exclude(initglobalswitches,cs_link_shared);
  1274. LinkTypeSetExplicitly:=true;
  1275. end;
  1276. '-' :
  1277. begin
  1278. exclude(initglobalswitches,cs_link_staticflag);
  1279. exclude(initglobalswitches,cs_link_strip);
  1280. exclude(initglobalswitches,cs_link_map);
  1281. set_default_link_type;
  1282. end;
  1283. else
  1284. IllegalPara(opt);
  1285. end;
  1286. inc(j);
  1287. end;
  1288. end;
  1289. end;
  1290. end;
  1291. '@' :
  1292. begin
  1293. Message(option_no_nested_response_file);
  1294. StopOptions(1);
  1295. end;
  1296. else
  1297. begin
  1298. if (length(param_file)<>0) then
  1299. Message(option_only_one_source_support);
  1300. param_file:=opt;
  1301. Message1(option_found_file,opt);
  1302. end;
  1303. end;
  1304. end;
  1305. procedure Toption.Interpret_file(const filename : string);
  1306. procedure RemoveSep(var fn:string);
  1307. var
  1308. i : longint;
  1309. begin
  1310. i:=0;
  1311. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1312. inc(i);
  1313. Delete(fn,1,i);
  1314. i:=length(fn);
  1315. while (i>0) and (fn[i] in [',',' ',#9]) do
  1316. dec(i);
  1317. fn:=copy(fn,1,i);
  1318. end;
  1319. function GetName(var fn:string):string;
  1320. var
  1321. i : longint;
  1322. begin
  1323. i:=0;
  1324. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1325. inc(i);
  1326. GetName:=Copy(fn,1,i);
  1327. Delete(fn,1,i);
  1328. end;
  1329. const
  1330. maxlevel=16;
  1331. var
  1332. f : text;
  1333. s, tmp,
  1334. opts : string;
  1335. skip : array[0..maxlevel-1] of boolean;
  1336. level : longint;
  1337. option_read : boolean;
  1338. begin
  1339. { avoid infinite loop }
  1340. Inc(FileLevel);
  1341. Option_read:=false;
  1342. If FileLevel>MaxLevel then
  1343. Message(option_too_many_cfg_files);
  1344. { Maybe It's Directory ?} //Jaro Change:
  1345. if DirectoryExists(filename) then
  1346. begin
  1347. Message1(option_config_is_dir,filename);
  1348. exit;
  1349. end;
  1350. { open file }
  1351. Message1(option_using_file,filename);
  1352. {$ifdef USE_SYSUTILS}
  1353. assign(f,ExpandFileName(filename));
  1354. {$else USE_SYSUTILS}
  1355. assign(f,FExpand(filename));
  1356. {$endif USE_SYsUTILS}
  1357. {$I-}
  1358. reset(f);
  1359. {$I+}
  1360. if ioresult<>0 then
  1361. begin
  1362. Message1(option_unable_open_file,filename);
  1363. exit;
  1364. end;
  1365. Message1(option_start_reading_configfile,filename);
  1366. fillchar(skip,sizeof(skip),0);
  1367. level:=0;
  1368. while not eof(f) do
  1369. begin
  1370. readln(f,opts);
  1371. RemoveSep(opts);
  1372. if (opts<>'') and (opts[1]<>';') then
  1373. begin
  1374. if opts[1]='#' then
  1375. begin
  1376. Message1(option_interpreting_file_option,opts);
  1377. Delete(opts,1,1);
  1378. s:=upper(GetName(opts));
  1379. if (s='SECTION') then
  1380. begin
  1381. RemoveSep(opts);
  1382. s:=upper(GetName(opts));
  1383. if level=0 then
  1384. skip[level]:=not (assigned(search_macro(s)) or (s='COMMON'));
  1385. end
  1386. else
  1387. if (s='IFDEF') then
  1388. begin
  1389. RemoveSep(opts);
  1390. if Level>=maxlevel then
  1391. begin
  1392. Message(option_too_many_ifdef);
  1393. stopOptions(1);
  1394. end;
  1395. inc(Level);
  1396. skip[level]:=(skip[level-1] or not assigned(search_macro(upper(GetName(opts)))));
  1397. end
  1398. else
  1399. if (s='IFNDEF') then
  1400. begin
  1401. RemoveSep(opts);
  1402. if Level>=maxlevel then
  1403. begin
  1404. Message(option_too_many_ifdef);
  1405. stopOptions(1);
  1406. end;
  1407. inc(Level);
  1408. skip[level]:=(skip[level-1] or assigned(search_macro(upper(GetName(opts)))));
  1409. end
  1410. else
  1411. if (s='ELSE') then
  1412. skip[level]:=skip[level-1] or (not skip[level])
  1413. else
  1414. if (s='ENDIF') then
  1415. begin
  1416. skip[level]:=false;
  1417. if Level=0 then
  1418. begin
  1419. Message(option_too_many_endif);
  1420. stopOptions(1);
  1421. end;
  1422. dec(level);
  1423. end
  1424. else
  1425. if (not skip[level]) then
  1426. begin
  1427. if (s='DEFINE') then
  1428. begin
  1429. RemoveSep(opts);
  1430. tmp:= GetName(opts);
  1431. if tmp <> '' then
  1432. def_system_macro(tmp);
  1433. end
  1434. else
  1435. if (s='UNDEF') then
  1436. begin
  1437. RemoveSep(opts);
  1438. tmp:= GetName(opts);
  1439. if tmp <> '' then
  1440. undef_system_macro(tmp);
  1441. end
  1442. else
  1443. if (s='WRITE') then
  1444. begin
  1445. Delete(opts,1,1);
  1446. WriteLn(opts);
  1447. end
  1448. else
  1449. if (s='INCLUDE') then
  1450. begin
  1451. Delete(opts,1,1);
  1452. Interpret_file(opts);
  1453. end;
  1454. end;
  1455. end
  1456. else
  1457. begin
  1458. if (opts[1]='-') or (opts[1]='@') then
  1459. begin
  1460. if (not skip[level]) then
  1461. interpret_option(opts,false);
  1462. Option_read:=true;
  1463. end
  1464. else
  1465. Message1(option_illegal_para,opts);
  1466. end;
  1467. end;
  1468. end;
  1469. if Level>0 then
  1470. Message(option_too_less_endif);
  1471. if Not Option_read then
  1472. Message1(option_no_option_found,filename)
  1473. else
  1474. Message1(option_end_reading_configfile,filename);
  1475. Close(f);
  1476. Dec(FileLevel);
  1477. end;
  1478. procedure Toption.Interpret_envvar(const envname : string);
  1479. var
  1480. argstart,
  1481. env,
  1482. pc : pchar;
  1483. arglen : longint;
  1484. quote : set of char;
  1485. hs : string;
  1486. begin
  1487. Message1(option_using_env,envname);
  1488. env:=GetEnvPChar(envname);
  1489. pc:=env;
  1490. if assigned(pc) then
  1491. begin
  1492. repeat
  1493. { skip leading spaces }
  1494. while pc^ in [' ',#9,#13] do
  1495. inc(pc);
  1496. case pc^ of
  1497. #0 :
  1498. break;
  1499. '"' :
  1500. begin
  1501. quote:=['"'];
  1502. inc(pc);
  1503. end;
  1504. '''' :
  1505. begin
  1506. quote:=[''''];
  1507. inc(pc);
  1508. end;
  1509. else
  1510. quote:=[' ',#9,#13];
  1511. end;
  1512. { scan until the end of the argument }
  1513. argstart:=pc;
  1514. while (pc^<>#0) and not(pc^ in quote) do
  1515. inc(pc);
  1516. { create argument }
  1517. arglen:=pc-argstart;
  1518. hs[0]:=chr(arglen);
  1519. move(argstart^,hs[1],arglen);
  1520. interpret_option(hs,true);
  1521. { skip quote }
  1522. if pc^ in quote then
  1523. inc(pc);
  1524. until false;
  1525. end
  1526. else
  1527. Message1(option_no_option_found,'(env) '+envname);
  1528. FreeEnvPChar(env);
  1529. end;
  1530. procedure toption.read_parameters;
  1531. var
  1532. opts : string;
  1533. paramindex : longint;
  1534. begin
  1535. paramindex:=0;
  1536. while paramindex<paramcount do
  1537. begin
  1538. inc(paramindex);
  1539. opts:=system.paramstr(paramindex);
  1540. case opts[1] of
  1541. '@' :
  1542. if not firstpass then
  1543. begin
  1544. Delete(opts,1,1);
  1545. Message1(option_reading_further_from,opts);
  1546. interpret_file(opts);
  1547. end;
  1548. '!' :
  1549. if not firstpass then
  1550. begin
  1551. Delete(opts,1,1);
  1552. Message1(option_reading_further_from,'(env) '+opts);
  1553. interpret_envvar(opts);
  1554. end;
  1555. else
  1556. interpret_option(opts,true);
  1557. end;
  1558. end;
  1559. end;
  1560. procedure toption.parsecmd(cmd:string);
  1561. var
  1562. i,ps : longint;
  1563. opts : string;
  1564. begin
  1565. while (cmd<>'') do
  1566. begin
  1567. while cmd[1]=' ' do
  1568. delete(cmd,1,1);
  1569. i:=pos(' ',cmd);
  1570. if i=0 then
  1571. i:=256;
  1572. opts:=Copy(cmd,1,i-1);
  1573. Delete(cmd,1,i);
  1574. case opts[1] of
  1575. '@' :
  1576. if not firstpass then
  1577. begin
  1578. Delete(opts,1,1);
  1579. Message1(option_reading_further_from,opts);
  1580. interpret_file(opts);
  1581. end;
  1582. '!' :
  1583. if not firstpass then
  1584. begin
  1585. Delete(opts,1,1);
  1586. Message1(option_reading_further_from,'(env) '+opts);
  1587. interpret_envvar(opts);
  1588. end;
  1589. '"' :
  1590. begin
  1591. Delete(opts,1,1);
  1592. ps:=pos('"',cmd);
  1593. if (i<>256) and (ps>0) then
  1594. begin
  1595. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1596. cmd:=copy(cmd,ps+1,255);
  1597. end;
  1598. interpret_option(opts,true);
  1599. end;
  1600. else
  1601. interpret_option(opts,true);
  1602. end;
  1603. end;
  1604. end;
  1605. procedure toption.writequickinfo;
  1606. var
  1607. s : string;
  1608. i : longint;
  1609. procedure addinfo(const hs:string);
  1610. begin
  1611. if s<>'' then
  1612. s:=s+' '+hs
  1613. else
  1614. s:=hs;
  1615. end;
  1616. begin
  1617. s:='';
  1618. i:=0;
  1619. while (i<length(quickinfo)) do
  1620. begin
  1621. inc(i);
  1622. case quickinfo[i] of
  1623. 'S' :
  1624. begin
  1625. inc(i);
  1626. case quickinfo[i] of
  1627. 'O' :
  1628. addinfo(lower(source_info.shortname));
  1629. 'P' :
  1630. addinfo(source_cpu_string);
  1631. else
  1632. IllegalPara('-i'+QuickInfo);
  1633. end;
  1634. end;
  1635. 'T' :
  1636. begin
  1637. inc(i);
  1638. case quickinfo[i] of
  1639. 'O' :
  1640. addinfo(lower(target_info.shortname));
  1641. 'P' :
  1642. AddInfo(target_cpu_string);
  1643. else
  1644. IllegalPara('-i'+QuickInfo);
  1645. end;
  1646. end;
  1647. 'V' :
  1648. AddInfo(version_string);
  1649. 'W' :
  1650. AddInfo(full_version_string);
  1651. 'D' :
  1652. AddInfo(date_string);
  1653. '_' :
  1654. ;
  1655. else
  1656. IllegalPara('-i'+QuickInfo);
  1657. end;
  1658. end;
  1659. if s<>'' then
  1660. begin
  1661. writeln(s);
  1662. stopoptions(0);
  1663. end;
  1664. end;
  1665. procedure TOption.TargetDefines(def:boolean);
  1666. var
  1667. s : string;
  1668. i : integer;
  1669. begin
  1670. if def then
  1671. def_system_macro(target_info.shortname)
  1672. else
  1673. undef_system_macro(target_info.shortname);
  1674. s:=target_info.extradefines;
  1675. while (s<>'') do
  1676. begin
  1677. i:=pos(';',s);
  1678. if i=0 then
  1679. i:=length(s)+1;
  1680. if def then
  1681. def_system_macro(Copy(s,1,i-1))
  1682. else
  1683. undef_system_macro(Copy(s,1,i-1));
  1684. delete(s,1,i);
  1685. end;
  1686. end;
  1687. constructor TOption.create;
  1688. begin
  1689. LogoWritten:=false;
  1690. NoPressEnter:=false;
  1691. FirstPass:=false;
  1692. FileLevel:=0;
  1693. Quickinfo:='';
  1694. ParaIncludePath:=TSearchPathList.Create;
  1695. ParaObjectPath:=TSearchPathList.Create;
  1696. ParaUnitPath:=TSearchPathList.Create;
  1697. ParaLibraryPath:=TSearchPathList.Create;
  1698. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1699. end;
  1700. destructor TOption.destroy;
  1701. begin
  1702. ParaIncludePath.Free;
  1703. ParaObjectPath.Free;
  1704. ParaUnitPath.Free;
  1705. ParaLibraryPath.Free;
  1706. end;
  1707. {****************************************************************************
  1708. Callable Routines
  1709. ****************************************************************************}
  1710. function check_configfile(const fn:string;var foundfn:string):boolean;
  1711. function CfgFileExists(const fn:string):boolean;
  1712. begin
  1713. Comment(V_Tried,'Configfile search: '+fn);
  1714. CfgFileExists:=FileExists(fn);
  1715. end;
  1716. var
  1717. configpath : pathstr;
  1718. begin
  1719. foundfn:=fn;
  1720. check_configfile:=true;
  1721. { retrieve configpath }
  1722. {$IFDEF USE_SYSUTILS}
  1723. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  1724. {$ELSE USE_SYSUTILS}
  1725. configpath:=FixPath(dos.getenv('PPC_CONFIG_PATH'),false);
  1726. {$ENDIF USE_SYSUTILS}
  1727. {$ifdef Unix}
  1728. if configpath='' then
  1729. configpath:=CleanPath(FixPath(exepath+'../etc/',false));
  1730. {$endif}
  1731. {
  1732. Order to read configuration file :
  1733. try reading fpc.cfg in :
  1734. 1 - current dir
  1735. 2 - configpath
  1736. 3 - compiler path
  1737. }
  1738. if not FileExists(fn) then
  1739. begin
  1740. {$ifdef Unix}
  1741. {$IFDEF USE_SYSUTILS}
  1742. if (GetEnvironmentVariable('HOME')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn) then
  1743. foundfn:=FixPath(GetEnvironmentVariable('HOME'),false)+'.'+fn
  1744. {$ELSE USE_SYSUTILS}
  1745. if (dos.getenv('HOME')<>'') and CfgFileExists(FixPath(dos.getenv('HOME'),false)+'.'+fn) then
  1746. foundfn:=FixPath(dos.getenv('HOME'),false)+'.'+fn
  1747. {$ENDIF USE_SYSUTILS}
  1748. else
  1749. {$endif}
  1750. if CfgFileExists(configpath+fn) then
  1751. foundfn:=configpath+fn
  1752. else
  1753. {$ifndef Unix}
  1754. if CfgFileExists(exepath+fn) then
  1755. foundfn:=exepath+fn
  1756. else
  1757. {$else}
  1758. if CfgFileExists('/etc/'+fn) then
  1759. foundfn:='/etc/'+fn
  1760. else
  1761. {$endif}
  1762. check_configfile:=false;
  1763. end;
  1764. end;
  1765. procedure read_arguments(cmd:string);
  1766. begin
  1767. option:=coption.create;
  1768. disable_configfile:=false;
  1769. { get default messagefile }
  1770. {$IFDEF USE_SYSUTILS}
  1771. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  1772. {$ELSE USE_SYSUTILS}
  1773. msgfilename:=dos.getenv('PPC_ERROR_FILE');
  1774. {$ENDIF USE_SYSUTILS}
  1775. { default configfile can be specified on the commandline,
  1776. remove it first }
  1777. if (cmd<>'') and (cmd[1]='[') then
  1778. begin
  1779. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  1780. Delete(cmd,1,pos(']',cmd));
  1781. end
  1782. else
  1783. begin
  1784. ppccfg:='fpc.cfg';
  1785. ppcaltcfg:='ppc386.cfg';
  1786. end;
  1787. { first pass reading of parameters, only -i -v -T etc.}
  1788. option.firstpass:=true;
  1789. if cmd<>'' then
  1790. option.parsecmd(cmd)
  1791. else
  1792. begin
  1793. option.read_parameters;
  1794. { Write only quickinfo }
  1795. if option.quickinfo<>'' then
  1796. option.writequickinfo;
  1797. end;
  1798. option.firstpass:=false;
  1799. { target is set here, for wince the default app type is gui }
  1800. if target_info.system in system_wince then
  1801. apptype:=app_gui;
  1802. { default defines }
  1803. def_system_macro(target_info.shortname);
  1804. def_system_macro('FPC');
  1805. def_system_macro('VER'+version_nr);
  1806. def_system_macro('VER'+version_nr+'_'+release_nr);
  1807. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  1808. { Temporary defines, until things settle down }
  1809. { "main" symbol is generated in the main program, and left out of the system unit }
  1810. def_system_macro('FPC_DARWIN_PASCALMAIN');
  1811. def_system_macro('FPC_DARWIN_JMP_MAIN');
  1812. def_system_macro('COMPPROCINLINEFIXED');
  1813. def_system_macro('PARAOUTFILE');
  1814. def_system_macro('RESSTRSECTIONS');
  1815. def_system_macro('FPC_HASFIXED64BITVARIANT');
  1816. {$ifdef x86}
  1817. { def_system_macro('INTERNAL_BACKTRACE');}
  1818. {$endif}
  1819. def_system_macro('STR_CONCAT_PROCS');
  1820. if pocall_default = pocall_register then
  1821. def_system_macro('REGCALL');
  1822. { using a case is pretty useless here (FK) }
  1823. { some stuff for TP compatibility }
  1824. {$ifdef i386}
  1825. def_system_macro('CPU86');
  1826. def_system_macro('CPU87');
  1827. def_system_macro('CPU386');
  1828. {$endif}
  1829. {$ifdef m68k}
  1830. def_system_macro('CPU68');
  1831. {$endif}
  1832. { new processor stuff }
  1833. {$ifdef i386}
  1834. def_system_macro('CPUI386');
  1835. def_system_macro('CPU32');
  1836. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  1837. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1838. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1839. def_system_macro('FPC_HAS_RESOURCES');
  1840. {$endif}
  1841. {$ifdef m68k}
  1842. def_system_macro('CPU68K');
  1843. def_system_macro('CPUM68K');
  1844. def_system_macro('CPU32');
  1845. def_system_macro('FPC_CURRENCY_IS_INT64');
  1846. def_system_macro('FPC_COMP_IS_INT64');
  1847. {$endif}
  1848. {$ifdef ALPHA}
  1849. def_system_macro('CPUALPHA');
  1850. def_system_macro('CPU64');
  1851. {$endif}
  1852. {$ifdef powerpc}
  1853. def_system_macro('CPUPOWERPC');
  1854. def_system_macro('CPUPOWERPC32');
  1855. def_system_macro('CPU32');
  1856. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1857. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1858. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1859. def_system_macro('FPC_CURRENCY_IS_INT64');
  1860. def_system_macro('FPC_COMP_IS_INT64');
  1861. {$endif}
  1862. {$ifdef POWERPC64}
  1863. def_system_macro('CPUPOWERPC');
  1864. def_system_macro('CPUPOWERPC64');
  1865. def_system_macro('CPU64');
  1866. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1867. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1868. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1869. def_system_macro('FPC_CURRENCY_IS_INT64');
  1870. def_system_macro('FPC_COMP_IS_INT64');
  1871. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1872. {$endif}
  1873. {$ifdef iA64}
  1874. def_system_macro('CPUIA64');
  1875. def_system_macro('CPU64');
  1876. {$endif}
  1877. {$ifdef x86_64}
  1878. def_system_macro('CPUX86_64');
  1879. def_system_macro('CPUAMD64');
  1880. def_system_macro('CPU64');
  1881. { not supported for now, afaik (FK)
  1882. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  1883. { win64 doesn't support the legacy fpu }
  1884. if target_info.system<>system_x86_64_win64 then
  1885. def_system_macro('FPC_HAS_TYPE_EXTENDED')
  1886. else
  1887. begin
  1888. def_system_macro('FPC_CURRENCY_IS_INT64');
  1889. def_system_macro('FPC_COMP_IS_INT64');
  1890. undef_system_macro('FPC_HAS_TYPE_EXTENDED');
  1891. end;
  1892. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1893. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1894. {$endif}
  1895. {$ifdef sparc}
  1896. def_system_macro('CPUSPARC');
  1897. def_system_macro('CPUSPARC32');
  1898. def_system_macro('CPU32');
  1899. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1900. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1901. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1902. def_system_macro('FPC_CURRENCY_IS_INT64');
  1903. def_system_macro('FPC_COMP_IS_INT64');
  1904. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1905. {$endif}
  1906. {$ifdef vis}
  1907. def_system_macro('CPUVIS');
  1908. def_system_macro('CPU32');
  1909. {$endif}
  1910. {$ifdef arm}
  1911. def_system_macro('CPUARM');
  1912. def_system_macro('FPUFPA');
  1913. def_system_macro('CPU32');
  1914. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  1915. def_system_macro('FPC_HAS_TYPE_SINGLE');
  1916. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  1917. def_system_macro('FPC_CURRENCY_IS_INT64');
  1918. def_system_macro('FPC_COMP_IS_INT64');
  1919. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  1920. {$endif arm}
  1921. if source_info.system<>target_info.system then
  1922. def_system_macro('FPC_CROSSCOMPILING');
  1923. if source_info.cpu<>target_info.cpu then
  1924. def_system_macro('FPC_CPUCROSSCOMPILING');
  1925. if tf_winlikewidestring in target_info.flags then
  1926. def_system_macro('FPC_WINLIKEWIDESTRING');
  1927. { read configuration file }
  1928. if (not disable_configfile) and
  1929. (ppccfg<>'') then
  1930. begin
  1931. read_configfile:=check_configfile(ppccfg,ppccfg);
  1932. { Maybe alternative configfile ? }
  1933. if (not read_configfile) and
  1934. (ppcaltcfg<>'') then
  1935. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  1936. end
  1937. else
  1938. read_configfile := false;
  1939. { Read commandline and configfile }
  1940. param_file:='';
  1941. { read configfile }
  1942. if read_configfile then
  1943. option.interpret_file(ppccfg);
  1944. { read parameters again to override config file }
  1945. if cmd<>'' then
  1946. option.parsecmd(cmd)
  1947. else
  1948. begin
  1949. { Write help pages if no parameters are passed }
  1950. if (paramcount=0) then
  1951. Option.WriteHelpPages;
  1952. option.read_parameters;
  1953. { Write only quickinfo }
  1954. if option.quickinfo<>'' then
  1955. option.writequickinfo;
  1956. end;
  1957. { Stop if errors in options }
  1958. if ErrorCount>0 then
  1959. StopOptions(1);
  1960. { Write logo }
  1961. if option.ParaLogo then
  1962. option.writelogo;
  1963. { Non-core target defines }
  1964. Option.TargetDefines(true);
  1965. { endian define }
  1966. case target_info.endian of
  1967. endian_little :
  1968. begin
  1969. def_system_macro('ENDIAN_LITTLE');
  1970. def_system_macro('FPC_LITTLE_ENDIAN');
  1971. end;
  1972. endian_big :
  1973. begin
  1974. def_system_macro('ENDIAN_BIG');
  1975. def_system_macro('FPC_BIG_ENDIAN');
  1976. end;
  1977. end;
  1978. { abi define }
  1979. case target_info.abi of
  1980. abi_powerpc_sysv :
  1981. def_system_macro('FPC_ABI_SYSV');
  1982. abi_powerpc_aix :
  1983. def_system_macro('FPC_ABI_AIX');
  1984. end;
  1985. { CPU Define }
  1986. def_system_macro('CPU'+Cputypestr[initcputype]);
  1987. { Check file to compile }
  1988. if param_file='' then
  1989. begin
  1990. Message(option_no_source_found);
  1991. StopOptions(1);
  1992. end;
  1993. {$ifndef Unix}
  1994. param_file:=FixFileName(param_file);
  1995. {$endif}
  1996. {$IFDEF USE_SYSUTILS}
  1997. inputdir := SplitPath(param_file);
  1998. inputfile := SplitName(param_file);
  1999. inputextension := SplitExtension(param_file);
  2000. {$ELSE USE_SYSUTILS}
  2001. fsplit(param_file,inputdir,inputfile,inputextension);
  2002. {$ENDIF USE_SYSUTILS}
  2003. if inputextension='' then
  2004. begin
  2005. if FileExists(inputdir+inputfile+sourceext) then
  2006. inputextension:=sourceext
  2007. else if FileExists(inputdir+inputfile+pasext) then
  2008. inputextension:=pasext
  2009. else if ((m_mac in aktmodeswitches) or
  2010. (tf_p_ext_support in target_info.flags))
  2011. and FileExists(inputdir+inputfile+pext) then
  2012. inputextension:=pext;
  2013. end;
  2014. { Check output dir }
  2015. if (OutputExeDir<>'') and
  2016. not PathExists(OutputExeDir) then
  2017. begin
  2018. Message1(general_e_path_does_not_exist,OutputExeDir);
  2019. StopOptions(1);
  2020. end;
  2021. { Add paths specified with parameters to the searchpaths }
  2022. UnitSearchPath.AddList(option.ParaUnitPath,true);
  2023. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  2024. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  2025. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  2026. { add unit environment and exepath to the unit search path }
  2027. if inputdir<>'' then
  2028. Unitsearchpath.AddPath(inputdir,true);
  2029. if not disable_configfile then
  2030. begin
  2031. {$IFDEF USE_SYSUTILS}
  2032. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  2033. {$ELSE USE_SYSUTILS}
  2034. UnitSearchPath.AddPath(dos.getenv(target_info.unit_env),false);
  2035. {$ENDIF USE_SYSUTILS}
  2036. end;
  2037. {$ifdef Unix}
  2038. {$IFDEF USE_SYSUTILS}
  2039. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2040. {$ELSE USE_SYSUTILS}
  2041. fpcdir:=FixPath(getenv('FPCDIR'),false);
  2042. {$ENDIF USE_SYSUTILS}
  2043. if fpcdir='' then
  2044. begin
  2045. if PathExists('/usr/local/lib/fpc/'+version_string) then
  2046. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  2047. else
  2048. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2049. end;
  2050. {$else}
  2051. {$IFDEF USE_SYSUTILS}
  2052. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2053. {$ELSE USE_SYSUTILS}
  2054. fpcdir:=FixPath(getenv('FPCDIR'),false);
  2055. {$ENDIF USE_SYSUTILS}
  2056. if fpcdir='' then
  2057. begin
  2058. fpcdir:=ExePath+'../';
  2059. if not(PathExists(fpcdir+'/units')) and
  2060. not(PathExists(fpcdir+'/rtl')) then
  2061. fpcdir:=fpcdir+'../';
  2062. end;
  2063. {$endif}
  2064. { first try development RTL, else use the default installation path }
  2065. if not disable_configfile then
  2066. begin
  2067. if PathExists(FpcDir+'rtl') then
  2068. if tf_use_8_3 in Source_Info.Flags then
  2069. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2070. else
  2071. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2072. else
  2073. if tf_use_8_3 in Source_Info.Flags then
  2074. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2075. else
  2076. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2077. end;
  2078. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2079. Do not add it when linking on the target because then we can maybe already find
  2080. .o files that are not for the target }
  2081. if (ExePath<>GetCurrentDir) and
  2082. not(cs_link_on_target in initglobalswitches) then
  2083. UnitSearchPath.AddPath(ExePath,false);
  2084. { Add unit dir to the object and library path }
  2085. objectsearchpath.AddList(unitsearchpath,false);
  2086. librarysearchpath.AddList(unitsearchpath,false);
  2087. { maybe override debug info format }
  2088. if (paratargetdbg<>dbg_none) then
  2089. set_target_dbg(paratargetdbg);
  2090. { maybe override assembler }
  2091. if (paratargetasm<>as_none) then
  2092. begin
  2093. if not set_target_asm(paratargetasm) then
  2094. begin
  2095. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2096. set_target_asm(target_info.assemextern);
  2097. Message1(option_asm_forced,target_asm.idtxt);
  2098. end;
  2099. end;
  2100. { switch assembler if it's binary and we got -a on the cmdline }
  2101. if (cs_asm_leave in initglobalswitches) and
  2102. (af_outputbinary in target_asm.flags) then
  2103. begin
  2104. Message(option_switch_bin_to_src_assembler);
  2105. set_target_asm(target_info.assemextern);
  2106. end;
  2107. { Force use of external linker if there is no
  2108. internal linker or the linking is skipped }
  2109. if not(cs_link_extern in initglobalswitches) and
  2110. (not assigned(target_info.link) or
  2111. (cs_link_nolink in initglobalswitches)) then
  2112. include(initglobalswitches,cs_link_extern);
  2113. { turn off stripping if compiling with debuginfo or profile }
  2114. if (cs_debuginfo in initmoduleswitches) or
  2115. (cs_profile in initmoduleswitches) then
  2116. exclude(initglobalswitches,cs_link_strip);
  2117. { force fpu emulation on arm/wince }
  2118. if target_info.system=system_arm_wince then
  2119. include(initmoduleswitches,cs_fp_emulation);
  2120. { Section smartlinking conflicts with import sections on Windows }
  2121. if GenerateImportSection and
  2122. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  2123. exclude(target_info.flags,tf_smartlink_sections);
  2124. {$ifdef x86_64}
  2125. {$warning HACK: turn off smartlinking}
  2126. exclude(initmoduleswitches,cs_create_smart);
  2127. {$endif}
  2128. if not LinkTypeSetExplicitly then
  2129. set_default_link_type;
  2130. { Default alignment settings,
  2131. 1. load the defaults for the target
  2132. 2. override with generic optimizer setting (little size)
  2133. 3. override with the user specified -Oa }
  2134. UpdateAlignment(initalignment,target_info.alignment);
  2135. if (cs_opt_size in aktoptimizerswitches) then
  2136. begin
  2137. initalignment.procalign:=1;
  2138. initalignment.jumpalign:=1;
  2139. initalignment.loopalign:=1;
  2140. end;
  2141. UpdateAlignment(initalignment,option.paraalignment);
  2142. set_system_macro('FPC_VERSION',version_nr);
  2143. set_system_macro('FPC_RELEASE',release_nr);
  2144. set_system_macro('FPC_PATCH',patch_nr);
  2145. option.free;
  2146. Option:=nil;
  2147. end;
  2148. initialization
  2149. coption:=toption;
  2150. finalization
  2151. if assigned(option) then
  2152. option.free;
  2153. end.