options.pas 68 KB

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