options.pas 79 KB

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