options.pas 71 KB

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