options.pas 74 KB

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