options.pas 82 KB

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