options.pas 89 KB

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