2
0

options.pas 70 KB

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