options.pas 78 KB

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