options.pas 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786
  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. if UnsetBool(more, 0) then
  800. init_settings.disabledircache:=false
  801. else
  802. init_settings.disabledircache:=true;
  803. 'D' :
  804. utilsdirectory:=FixPath(More,true);
  805. 'e' :
  806. SetRedirectFile(More);
  807. 'E' :
  808. OutputExeDir:=FixPath(More,true);
  809. 'f' :
  810. if (target_info.system in systems_darwin) then
  811. if ispara then
  812. ParaFrameworkPath.AddPath(More,false)
  813. else
  814. frameworksearchpath.AddPath(More,true)
  815. else
  816. IllegalPara(opt);
  817. 'i' :
  818. begin
  819. if ispara then
  820. ParaIncludePath.AddPath(More,false)
  821. else
  822. includesearchpath.AddPath(More,true);
  823. end;
  824. 'm' :
  825. begin
  826. unicodemapping:=loadunicodemapping(More,More+'.txt');
  827. if assigned(unicodemapping) then
  828. registermapping(unicodemapping)
  829. else
  830. IllegalPara(opt);
  831. end;
  832. 'g' :
  833. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  834. 'l' :
  835. begin
  836. if ispara then
  837. ParaLibraryPath.AddPath(sysrootpath,More,false)
  838. else
  839. LibrarySearchPath.AddPath(sysrootpath,More,true);
  840. end;
  841. 'L' :
  842. begin
  843. if More<>'' then
  844. ParaDynamicLinker:=More
  845. else
  846. IllegalPara(opt);
  847. end;
  848. 'o' :
  849. begin
  850. if ispara then
  851. ParaObjectPath.AddPath(More,false)
  852. else
  853. ObjectSearchPath.AddPath(More,true);
  854. end;
  855. 'r' :
  856. Msgfilename:=More;
  857. 'R' :
  858. ResCompiler := More;
  859. 'u' :
  860. begin
  861. if ispara then
  862. ParaUnitPath.AddPath(More,false)
  863. else
  864. unitsearchpath.AddPath(More,true);
  865. end;
  866. 'U' :
  867. OutputUnitDir:=FixPath(More,true);
  868. 'W',
  869. 'w':
  870. begin
  871. if More<>'' then
  872. begin
  873. DefaultReplacements(More);
  874. D:=ExtractFilePath(More);
  875. if (D<>'') then
  876. D:=FixPath(D,True);
  877. D:=D+ExtractFileName(More);
  878. if (c='W') then
  879. WpoFeedbackOutput:=D
  880. else
  881. WpoFeedbackInput:=D;
  882. end
  883. else
  884. IllegalPara(opt);
  885. end;
  886. else
  887. IllegalPara(opt);
  888. end;
  889. end;
  890. 'g' :
  891. begin
  892. if UnsetBool(More, 0) then
  893. begin
  894. exclude(init_settings.moduleswitches,cs_debuginfo);
  895. exclude(init_settings.globalswitches,cs_use_heaptrc);
  896. exclude(init_settings.globalswitches,cs_use_lineinfo);
  897. exclude(init_settings.localswitches,cs_checkpointer);
  898. localvartrashing := -1;
  899. end
  900. else
  901. begin
  902. include(init_settings.moduleswitches,cs_debuginfo);
  903. if paratargetdbg=dbg_none then
  904. paratargetdbg:=target_info.dbg;
  905. end;
  906. if not RelocSectionSetExplicitly then
  907. RelocSection:=false;
  908. j:=1;
  909. while j<=length(more) do
  910. begin
  911. case more[j] of
  912. 'c' :
  913. begin
  914. if UnsetBool(More, j) then
  915. exclude(init_settings.localswitches,cs_checkpointer)
  916. else if (target_info.system in supported_targets_gc) then
  917. include(init_settings.localswitches,cs_checkpointer)
  918. else
  919. UnsupportedPara('-gc');
  920. end;
  921. 'h' :
  922. begin
  923. if UnsetBool(More, j) then
  924. exclude(init_settings.globalswitches,cs_use_heaptrc)
  925. else
  926. include(init_settings.globalswitches,cs_use_heaptrc);
  927. end;
  928. 'l' :
  929. begin
  930. if UnsetBool(More, j) then
  931. exclude(init_settings.globalswitches,cs_use_lineinfo)
  932. else
  933. include(init_settings.globalswitches,cs_use_lineinfo);
  934. end;
  935. 'o' :
  936. begin
  937. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  938. IllegalPara(opt);
  939. break;
  940. end;
  941. 'p' :
  942. begin
  943. if UnsetBool(More, j) then
  944. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  945. else
  946. include(init_settings.globalswitches,cs_stabs_preservecase);
  947. end;
  948. 's' :
  949. begin
  950. paratargetdbg:=dbg_stabs;
  951. end;
  952. 't' :
  953. begin
  954. if UnsetBool(More, j) then
  955. localvartrashing := -1
  956. else
  957. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  958. end;
  959. 'v' :
  960. begin
  961. if UnsetBool(More, j) then
  962. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  963. else
  964. include(init_settings.globalswitches,cs_gdb_valgrind);
  965. end;
  966. 'w' :
  967. begin
  968. if (j<length(more)) and (more[j+1] in ['2','3']) then
  969. begin
  970. case more[j+1] of
  971. '2': paratargetdbg:=dbg_dwarf2;
  972. '3': paratargetdbg:=dbg_dwarf3;
  973. end;
  974. inc(j);
  975. end
  976. else
  977. paratargetdbg:=dbg_dwarf2;
  978. end;
  979. else
  980. IllegalPara(opt);
  981. end;
  982. inc(j);
  983. end;
  984. end;
  985. 'h' :
  986. begin
  987. NoPressEnter:=true;
  988. WriteHelpPages;
  989. end;
  990. 'i' :
  991. begin
  992. if More='' then
  993. WriteInfo
  994. else
  995. QuickInfo:=QuickInfo+More;
  996. end;
  997. 'I' :
  998. begin
  999. if ispara then
  1000. ParaIncludePath.AddPath(More,false)
  1001. else
  1002. includesearchpath.AddPath(More,false);
  1003. end;
  1004. 'k' :
  1005. begin
  1006. if more<>'' then
  1007. ParaLinkOptions:=ParaLinkOptions+' '+More
  1008. else
  1009. IllegalPara(opt);
  1010. end;
  1011. 'l' :
  1012. ParaLogo:=not UnSetBool(more,0);
  1013. 'm' :
  1014. parapreprocess:=not UnSetBool(more,0);
  1015. 'M' :
  1016. begin
  1017. more:=Upper(more);
  1018. if not SetCompileMode(more, true) then
  1019. if not SetCompileModeSwitch(more, true) then
  1020. IllegalPara(opt);
  1021. end;
  1022. 'n' :
  1023. begin
  1024. if More='' then
  1025. disable_configfile:=true
  1026. else
  1027. IllegalPara(opt);
  1028. end;
  1029. 'o' :
  1030. begin
  1031. if More<>'' then
  1032. begin
  1033. DefaultReplacements(More);
  1034. D:=ExtractFilePath(More);
  1035. if (D<>'') then
  1036. OutputExeDir:=FixPath(D,True);
  1037. OutputFileName:=ExtractFileName(More);
  1038. end
  1039. else
  1040. IllegalPara(opt);
  1041. end;
  1042. 'O' :
  1043. begin
  1044. j:=1;
  1045. while j<=length(more) do
  1046. begin
  1047. case more[j] of
  1048. '1' :
  1049. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1050. '2' :
  1051. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1052. '3' :
  1053. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1054. 'a' :
  1055. begin
  1056. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1057. IllegalPara(opt);
  1058. break;
  1059. end;
  1060. 's' :
  1061. include(init_settings.optimizerswitches,cs_opt_size);
  1062. 'p' :
  1063. begin
  1064. if not Setcputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1065. begin
  1066. { Give warning for old i386 switches }
  1067. if (Length(More)-j=1) and
  1068. (More[j+1]>='1') and (More[j+1]<='5')then
  1069. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1070. else
  1071. IllegalPara(opt);
  1072. end;
  1073. break;
  1074. end;
  1075. 'o' :
  1076. begin
  1077. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  1078. IllegalPara(opt);
  1079. break;
  1080. end;
  1081. '-' :
  1082. begin
  1083. init_settings.optimizerswitches:=[];
  1084. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1085. end;
  1086. { Obsolete switches }
  1087. 'g' :
  1088. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  1089. 'G' :
  1090. Message1(option_obsolete_switch,'-OG');
  1091. 'r' :
  1092. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  1093. 'u' :
  1094. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  1095. 'w' :
  1096. begin
  1097. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  1098. IllegalPara(opt);
  1099. break;
  1100. end;
  1101. 'W' :
  1102. begin
  1103. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  1104. IllegalPara(opt);
  1105. break;
  1106. end;
  1107. else
  1108. IllegalPara(opt);
  1109. end;
  1110. inc(j);
  1111. end;
  1112. end;
  1113. 'p' :
  1114. begin
  1115. if UnsetBool(More, 0) then
  1116. begin
  1117. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  1118. undef_system_macro('FPC_PROFILE');
  1119. end
  1120. else
  1121. if Length(More)=0 then
  1122. IllegalPara(opt)
  1123. else
  1124. case more[1] of
  1125. 'g' : if UnsetBool(more, 1) then
  1126. begin
  1127. exclude(init_settings.moduleswitches,cs_profile);
  1128. undef_system_macro('FPC_PROFILE');
  1129. end
  1130. else if (target_info.system in supported_targets_pg) then
  1131. begin
  1132. include(init_settings.moduleswitches,cs_profile);
  1133. def_system_macro('FPC_PROFILE');
  1134. end
  1135. else
  1136. UnsupportedPara('-pg');
  1137. else
  1138. IllegalPara(opt);
  1139. end;
  1140. end;
  1141. 'P' : ; { Ignore used by fpc.pp }
  1142. 'R' :
  1143. begin
  1144. if not SetAsmReadMode(More,init_settings.asmmode) then
  1145. IllegalPara(opt);
  1146. end;
  1147. 's' :
  1148. begin
  1149. if UnsetBool(More, 0) then
  1150. begin
  1151. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1152. if more<>'' then
  1153. IllegalPara(opt);
  1154. end
  1155. else
  1156. begin
  1157. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1158. if more='h' then
  1159. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target]
  1160. else if more='t' then
  1161. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]
  1162. else if more='r' then
  1163. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  1164. else if more<>'' then
  1165. IllegalPara(opt);
  1166. end;
  1167. end;
  1168. 'S' :
  1169. begin
  1170. if more='' then
  1171. IllegalPara(opt);
  1172. if more[1]='I' then
  1173. begin
  1174. if upper(more)='ICOM' then
  1175. init_settings.interfacetype:=it_interfacecom
  1176. else if upper(more)='ICORBA' then
  1177. init_settings.interfacetype:=it_interfacecorba
  1178. else
  1179. IllegalPara(opt);
  1180. end
  1181. else
  1182. begin
  1183. j:=1;
  1184. while j<=length(more) do
  1185. begin
  1186. case more[j] of
  1187. '2' : //an alternative to -Mobjfpc
  1188. SetCompileMode('OBJFPC',true);
  1189. 'a' :
  1190. If UnsetBool(More, j) then
  1191. exclude(init_settings.localswitches,cs_do_assertion)
  1192. else
  1193. include(init_settings.localswitches,cs_do_assertion);
  1194. 'c' :
  1195. If UnsetBool(More, j) then
  1196. include(init_settings.moduleswitches,cs_support_c_operators)
  1197. else
  1198. include(init_settings.moduleswitches,cs_support_c_operators);
  1199. 'd' : //an alternative to -Mdelphi
  1200. SetCompileMode('DELPHI',true);
  1201. 'e' :
  1202. begin
  1203. SetErrorFlags(copy(more,j+1,length(more)));
  1204. break;
  1205. end;
  1206. 'f' :
  1207. begin
  1208. inc(j);
  1209. if more[j]='-' then
  1210. begin
  1211. features:=[];
  1212. if length(more)>j then
  1213. IllegalPara(opt);
  1214. end
  1215. else
  1216. begin
  1217. if (IncludeFeature(upper(copy(more,j,length(more)-j+1)))) then
  1218. j:=length(more)
  1219. else
  1220. IllegalPara(opt);
  1221. end;
  1222. end;
  1223. 'g' :
  1224. If UnsetBool(More, j) then
  1225. exclude(init_settings.moduleswitches,cs_support_goto)
  1226. else
  1227. include(init_settings.moduleswitches,cs_support_goto);
  1228. 'h' :
  1229. If UnsetBool(More, j) then
  1230. exclude(init_settings.localswitches,cs_ansistrings)
  1231. else
  1232. include(init_settings.localswitches,cs_ansistrings);
  1233. 'i' :
  1234. If UnsetBool(More, j) then
  1235. exclude(init_settings.localswitches,cs_do_inline)
  1236. else
  1237. include(init_settings.localswitches,cs_do_inline);
  1238. 'k' :
  1239. If UnsetBool(More, j) then
  1240. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1241. else
  1242. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1243. 'm' :
  1244. If UnsetBool(More, j) then
  1245. exclude(init_settings.moduleswitches,cs_support_macro)
  1246. else
  1247. include(init_settings.moduleswitches,cs_support_macro);
  1248. 'o' : //an alternative to -Mtp
  1249. SetCompileMode('TP',true);
  1250. {$ifdef gpc_mode}
  1251. 'p' : //an alternative to -Mgpc
  1252. SetCompileMode('GPC',true);
  1253. {$endif}
  1254. 's' :
  1255. If UnsetBool(More, j) then
  1256. exclude(init_settings.globalswitches,cs_constructor_name)
  1257. else
  1258. include(init_settings.globalswitches,cs_constructor_name);
  1259. 't' :
  1260. If UnsetBool(More, j) then
  1261. exclude(init_settings.moduleswitches,cs_static_keyword)
  1262. else
  1263. include(init_settings.moduleswitches,cs_static_keyword);
  1264. 'v' :
  1265. If UnsetBool(More, j) then
  1266. exclude(init_settings.globalswitches,cs_support_vectors)
  1267. else
  1268. include(init_settings.globalswitches,cs_support_vectors);
  1269. 'x' :
  1270. If UnsetBool(More, j) then
  1271. exclude(init_settings.globalswitches,cs_support_exceptions)
  1272. else
  1273. include(init_settings.globalswitches,cs_support_exceptions);
  1274. '-' :
  1275. begin
  1276. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions];
  1277. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion, cs_do_inline, cs_ansistrings];
  1278. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1279. cs_support_macro,
  1280. cs_static_keyword];
  1281. end;
  1282. else
  1283. IllegalPara(opt);
  1284. end;
  1285. inc(j);
  1286. end;
  1287. end;
  1288. end;
  1289. 'T' :
  1290. begin
  1291. more:=Upper(More);
  1292. if paratarget=system_none then
  1293. begin
  1294. { remove old target define }
  1295. TargetOptions(false);
  1296. { load new target }
  1297. paratarget:=find_system_by_string(More);
  1298. if paratarget<>system_none then
  1299. set_target(paratarget)
  1300. else
  1301. IllegalPara(opt);
  1302. { set new define }
  1303. TargetOptions(true);
  1304. end
  1305. else
  1306. if More<>upper(target_info.shortname) then
  1307. Message1(option_target_is_already_set,target_info.shortname);
  1308. end;
  1309. 'u' :
  1310. if more <> '' then
  1311. undef_system_macro(more);
  1312. 'U' :
  1313. begin
  1314. j:=1;
  1315. while j<=length(more) do
  1316. begin
  1317. case more[j] of
  1318. {$ifdef UNITALIASES}
  1319. 'a' :
  1320. begin
  1321. AddUnitAlias(Copy(More,j+1,255));
  1322. break;
  1323. end;
  1324. {$endif UNITALIASES}
  1325. 'n' :
  1326. exclude(init_settings.globalswitches,cs_check_unit_name);
  1327. 'p' :
  1328. begin
  1329. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1330. break;
  1331. end;
  1332. 'r' :
  1333. do_release:=true;
  1334. 's' :
  1335. include(init_settings.moduleswitches,cs_compilesystem);
  1336. '-' :
  1337. begin
  1338. exclude(init_settings.moduleswitches,cs_compilesystem);
  1339. exclude(init_settings.globalswitches,cs_check_unit_name);
  1340. end;
  1341. else
  1342. IllegalPara(opt);
  1343. end;
  1344. inc(j);
  1345. end;
  1346. end;
  1347. 'v' :
  1348. begin
  1349. if not setverbosity(More) then
  1350. IllegalPara(opt);
  1351. end;
  1352. 'V' : ; { Ignore used by fpc }
  1353. 'W' :
  1354. begin
  1355. j:=1;
  1356. while j<=length(More) do
  1357. begin
  1358. case More[j] of
  1359. 'A':
  1360. begin
  1361. if UnsetBool(More, j) then
  1362. apptype:=app_native
  1363. else
  1364. apptype:=app_cui;
  1365. end;
  1366. 'b':
  1367. begin
  1368. if (target_info.system in systems_darwin) then
  1369. begin
  1370. if not UnsetBool(More, j) then
  1371. apptype:=app_bundle
  1372. else
  1373. apptype:=app_cui
  1374. end
  1375. else
  1376. IllegalPara(opt);
  1377. end;
  1378. 'B':
  1379. begin
  1380. { -WB200000 means set trefered base address
  1381. to $200000, but does not change relocsection boolean
  1382. this way we can create both relocatble and
  1383. non relocatable DLL at a specific base address PM }
  1384. if (length(More)>j) then
  1385. begin
  1386. val('$'+Copy(More,j+1,255),imagebase,code);
  1387. if code<>0 then
  1388. IllegalPara(opt);
  1389. ImageBaseSetExplicity:=true;
  1390. end
  1391. else
  1392. begin
  1393. RelocSection:=true;
  1394. RelocSectionSetExplicitly:=true;
  1395. end;
  1396. break;
  1397. end;
  1398. 'C':
  1399. begin
  1400. if UnsetBool(More, j) then
  1401. apptype:=app_gui
  1402. else
  1403. apptype:=app_cui;
  1404. end;
  1405. 'D':
  1406. begin
  1407. UseDeffileForExports:=not UnsetBool(More, j);
  1408. UseDeffileForExportsSetExplicitly:=true;
  1409. end;
  1410. 'e':
  1411. begin
  1412. if (target_info.system in systems_darwin) then
  1413. begin
  1414. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  1415. set_target_res(res_ext);
  1416. target_info.resobjext:='.fpcres';
  1417. end
  1418. else
  1419. IllegalPara(opt);
  1420. end;
  1421. 'F':
  1422. begin
  1423. if UnsetBool(More, j) then
  1424. apptype:=app_cui
  1425. else
  1426. apptype:=app_fs;
  1427. end;
  1428. 'G':
  1429. begin
  1430. if UnsetBool(More, j) then
  1431. apptype:=app_cui
  1432. else
  1433. apptype:=app_gui;
  1434. end;
  1435. 'I':
  1436. begin
  1437. GenerateImportSection:=not UnsetBool(More,j);
  1438. GenerateImportSectionSetExplicitly:=true;
  1439. end;
  1440. 'i':
  1441. begin
  1442. if (target_info.system in systems_darwin) then
  1443. begin
  1444. set_target_res(res_macho);
  1445. target_info.resobjext:=
  1446. targetinfos[target_info.system]^.resobjext;
  1447. end
  1448. else
  1449. IllegalPara(opt);
  1450. end;
  1451. 'N':
  1452. begin
  1453. RelocSection:=UnsetBool(More,j);
  1454. RelocSectionSetExplicitly:=true;
  1455. end;
  1456. 'p':
  1457. begin
  1458. {$if defined(arm) or defined(avr)}
  1459. if (target_info.system in systems_embedded) then
  1460. begin
  1461. s:=upper(copy(more,j+1,length(more)-j));
  1462. if not(SetControllerType(s,init_settings.controllertype)) then
  1463. IllegalPara(opt);
  1464. break;
  1465. end
  1466. else
  1467. {$endif defined(arm) or defined(avr)}
  1468. IllegalPara(opt);
  1469. end;
  1470. 'R':
  1471. begin
  1472. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1473. RelocSection:=not UnsetBool(More,j);
  1474. RelocSectionSetExplicitly:=true;
  1475. end;
  1476. 'T':
  1477. begin
  1478. if UnsetBool(More, j) then
  1479. apptype:=app_cui
  1480. else
  1481. apptype:=app_tool;
  1482. end;
  1483. 'X':
  1484. begin
  1485. if (target_info.system in system_linux) then
  1486. begin
  1487. if UnsetBool(More, j) then
  1488. exclude(init_settings.moduleswitches,cs_executable_stack)
  1489. else
  1490. include(init_settings.moduleswitches,cs_executable_stack)
  1491. end
  1492. else
  1493. IllegalPara(opt);
  1494. end
  1495. else
  1496. IllegalPara(opt);
  1497. end;
  1498. inc(j);
  1499. end;
  1500. end;
  1501. 'X' :
  1502. begin
  1503. j:=1;
  1504. while j<=length(more) do
  1505. begin
  1506. case More[j] of
  1507. 'c' : Cshared:=TRUE;
  1508. 'd' : Dontlinkstdlibpath:=TRUE;
  1509. 'e' :
  1510. begin
  1511. If UnsetBool(More, j) then
  1512. exclude(init_settings.globalswitches,cs_link_extern)
  1513. else
  1514. include(init_settings.globalswitches,cs_link_extern);
  1515. end;
  1516. 'f' :
  1517. include(init_settings.globalswitches,cs_link_pthread);
  1518. 'g' :
  1519. begin
  1520. If UnsetBool(More, j) then
  1521. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  1522. else
  1523. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  1524. end;
  1525. 'i' :
  1526. begin
  1527. If UnsetBool(More, j) then
  1528. include(init_settings.globalswitches,cs_link_extern)
  1529. else
  1530. exclude(init_settings.globalswitches,cs_link_extern);
  1531. end;
  1532. 'm' :
  1533. begin
  1534. If UnsetBool(More, j) then
  1535. exclude(init_settings.globalswitches,cs_link_map)
  1536. else
  1537. include(init_settings.globalswitches,cs_link_map);
  1538. end;
  1539. 'p' : ; { Ignore used by fpc.pp }
  1540. 'r' :
  1541. begin
  1542. rlinkpath:=Copy(more,2,length(More)-1);
  1543. DefaultReplacements(rlinkpath);
  1544. More:='';
  1545. end;
  1546. 'R' :
  1547. begin
  1548. sysrootpath:=copy(more,2,length(more)-1);
  1549. defaultreplacements(sysrootpath);
  1550. more:='';
  1551. end;
  1552. 's' :
  1553. begin
  1554. If UnsetBool(More, j) then
  1555. exclude(init_settings.globalswitches,cs_link_strip)
  1556. else
  1557. include(init_settings.globalswitches,cs_link_strip);
  1558. end;
  1559. 't' :
  1560. include(init_settings.globalswitches,cs_link_staticflag);
  1561. 'v' :
  1562. begin
  1563. If UnsetBool(More, j) then
  1564. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  1565. else
  1566. include(init_settings.globalswitches,cs_link_opt_vtable);
  1567. end;
  1568. 'D' :
  1569. begin
  1570. def_system_macro('FPC_LINK_DYNAMIC');
  1571. undef_system_macro('FPC_LINK_SMART');
  1572. undef_system_macro('FPC_LINK_STATIC');
  1573. exclude(init_settings.globalswitches,cs_link_static);
  1574. exclude(init_settings.globalswitches,cs_link_smart);
  1575. include(init_settings.globalswitches,cs_link_shared);
  1576. LinkTypeSetExplicitly:=true;
  1577. end;
  1578. 'M' :
  1579. begin
  1580. mainaliasname:=Copy(more,2,length(More)-1);
  1581. More:='';
  1582. end;
  1583. 'P' :
  1584. begin
  1585. utilsprefix:=Copy(more,2,length(More)-1);
  1586. DefaultReplacements(utilsprefix);
  1587. More:='';
  1588. end;
  1589. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1590. // these are not aggregable.
  1591. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1592. IllegalPara(opt)
  1593. else
  1594. begin
  1595. case more[j+1] of
  1596. 'A' : begin
  1597. s:=Copy(more,3,length(More)-2);
  1598. if not LinkLibraryAliases.AddDep(s) Then
  1599. IllegalPara(opt);
  1600. end;
  1601. 'O' : begin
  1602. s:=Copy(more,3,length(More)-2);
  1603. if not LinkLibraryOrder.AddWeight(s) Then
  1604. IllegalPara(opt);
  1605. end;
  1606. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  1607. else
  1608. IllegalPara(opt);
  1609. end; {case}
  1610. j:=length(more);
  1611. end; {else begin}
  1612. end;
  1613. 'S' :
  1614. begin
  1615. ForceStaticLinking;
  1616. end;
  1617. 'X' :
  1618. begin
  1619. def_system_macro('FPC_LINK_SMART');
  1620. undef_system_macro('FPC_LINK_STATIC');
  1621. undef_system_macro('FPC_LINK_DYNAMIC');
  1622. exclude(init_settings.globalswitches,cs_link_static);
  1623. include(init_settings.globalswitches,cs_link_smart);
  1624. exclude(init_settings.globalswitches,cs_link_shared);
  1625. LinkTypeSetExplicitly:=true;
  1626. end;
  1627. '-' :
  1628. begin
  1629. exclude(init_settings.globalswitches,cs_link_staticflag);
  1630. exclude(init_settings.globalswitches,cs_link_strip);
  1631. exclude(init_settings.globalswitches,cs_link_map);
  1632. set_default_link_type;
  1633. end;
  1634. else
  1635. IllegalPara(opt);
  1636. end;
  1637. inc(j);
  1638. end;
  1639. end;
  1640. else
  1641. IllegalPara(opt);
  1642. end;
  1643. end;
  1644. '@' :
  1645. begin
  1646. Message(option_no_nested_response_file);
  1647. StopOptions(1);
  1648. end;
  1649. else
  1650. begin
  1651. if (length(param_file)<>0) then
  1652. Message2(option_only_one_source_support,param_file,opt);
  1653. param_file:=opt;
  1654. Message1(option_found_file,opt);
  1655. end;
  1656. end;
  1657. end;
  1658. procedure Toption.Interpret_file(const filename : string);
  1659. procedure RemoveSep(var fn:string);
  1660. var
  1661. i : longint;
  1662. begin
  1663. i:=0;
  1664. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1665. inc(i);
  1666. Delete(fn,1,i);
  1667. i:=length(fn);
  1668. while (i>0) and (fn[i] in [',',' ',#9]) do
  1669. dec(i);
  1670. fn:=copy(fn,1,i);
  1671. end;
  1672. function GetName(var fn:string):string;
  1673. var
  1674. i : longint;
  1675. begin
  1676. i:=0;
  1677. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1678. inc(i);
  1679. GetName:=Copy(fn,1,i);
  1680. Delete(fn,1,i);
  1681. end;
  1682. const
  1683. maxlevel = 15;
  1684. var
  1685. f : text;
  1686. s, tmp,
  1687. opts : string;
  1688. skip : array[0..maxlevel] of boolean;
  1689. line,
  1690. level : longint;
  1691. option_read : boolean;
  1692. begin
  1693. { avoid infinite loop }
  1694. Inc(FileLevel);
  1695. Option_read:=false;
  1696. If FileLevel>MaxLevel then
  1697. Message(option_too_many_cfg_files);
  1698. { Maybe It's Directory ?} //Jaro Change:
  1699. if PathExists(filename,false) then
  1700. begin
  1701. Message1(option_config_is_dir,filename);
  1702. exit;
  1703. end;
  1704. { open file }
  1705. Message1(option_using_file,filename);
  1706. assign(f,ExpandFileName(filename));
  1707. {$I-}
  1708. reset(f);
  1709. {$I+}
  1710. if ioresult<>0 then
  1711. begin
  1712. Message1(option_unable_open_file,filename);
  1713. exit;
  1714. end;
  1715. Message1(option_start_reading_configfile,filename);
  1716. fillchar(skip,sizeof(skip),0);
  1717. level:=0;
  1718. line:=0;
  1719. while not eof(f) do
  1720. begin
  1721. readln(f,opts);
  1722. inc(line);
  1723. RemoveSep(opts);
  1724. if (opts<>'') and (opts[1]<>';') then
  1725. begin
  1726. if opts[1]='#' then
  1727. begin
  1728. Message1(option_interpreting_file_option,opts);
  1729. Delete(opts,1,1);
  1730. s:=upper(GetName(opts));
  1731. if (s='SECTION') then
  1732. begin
  1733. RemoveSep(opts);
  1734. s:=upper(GetName(opts));
  1735. if level=0 then
  1736. skip[level]:=not defined_macro(s) or (s='COMMON');
  1737. end
  1738. else
  1739. if (s='IFDEF') then
  1740. begin
  1741. RemoveSep(opts);
  1742. if Level>=maxlevel then
  1743. begin
  1744. Message2(option_too_many_ifdef,filename,tostr(line));
  1745. stopOptions(1);
  1746. end;
  1747. inc(Level);
  1748. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  1749. end
  1750. else
  1751. if (s='IFNDEF') then
  1752. begin
  1753. RemoveSep(opts);
  1754. if Level>=maxlevel then
  1755. begin
  1756. Message2(option_too_many_ifdef,filename,tostr(line));
  1757. stopOptions(1);
  1758. end;
  1759. inc(Level);
  1760. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  1761. end
  1762. else
  1763. if (s='ELSE') then
  1764. begin
  1765. if Level=0 then
  1766. begin
  1767. Message2(option_else_without_if,filename,tostr(line));
  1768. stopOptions(1);
  1769. end
  1770. else
  1771. skip[level]:=skip[level-1] or (not skip[level])
  1772. end
  1773. else
  1774. if (s='ENDIF') then
  1775. begin
  1776. skip[level]:=false;
  1777. if Level=0 then
  1778. begin
  1779. Message2(option_too_many_endif,filename,tostr(line));
  1780. stopOptions(1);
  1781. end;
  1782. dec(level);
  1783. end
  1784. else
  1785. if (not skip[level]) then
  1786. begin
  1787. if (s='DEFINE') then
  1788. begin
  1789. RemoveSep(opts);
  1790. tmp:= GetName(opts);
  1791. if tmp <> '' then
  1792. def_system_macro(tmp);
  1793. end
  1794. else
  1795. if (s='UNDEF') then
  1796. begin
  1797. RemoveSep(opts);
  1798. tmp:= GetName(opts);
  1799. if tmp <> '' then
  1800. undef_system_macro(tmp);
  1801. end
  1802. else
  1803. if (s='WRITE') then
  1804. begin
  1805. Delete(opts,1,1);
  1806. WriteLn(opts);
  1807. end
  1808. else
  1809. if (s='INCLUDE') then
  1810. begin
  1811. Delete(opts,1,1);
  1812. Interpret_file(opts);
  1813. end;
  1814. end;
  1815. end
  1816. else
  1817. begin
  1818. if (opts[1]='-') or (opts[1]='@') then
  1819. begin
  1820. if (not skip[level]) then
  1821. interpret_option(opts,false);
  1822. Option_read:=true;
  1823. end
  1824. else
  1825. Message1(option_illegal_para,opts);
  1826. end;
  1827. end;
  1828. end;
  1829. if Level>0 then
  1830. Message(option_too_less_endif);
  1831. if Not Option_read then
  1832. Message1(option_no_option_found,filename)
  1833. else
  1834. Message1(option_end_reading_configfile,filename);
  1835. Close(f);
  1836. Dec(FileLevel);
  1837. end;
  1838. procedure Toption.Interpret_envvar(const envname : string);
  1839. var
  1840. argstart,
  1841. env,
  1842. pc : pchar;
  1843. arglen : longint;
  1844. quote : set of char;
  1845. hs : string;
  1846. begin
  1847. Message1(option_using_env,envname);
  1848. env:=GetEnvPChar(envname);
  1849. pc:=env;
  1850. if assigned(pc) then
  1851. begin
  1852. repeat
  1853. { skip leading spaces }
  1854. while pc^ in [' ',#9,#13] do
  1855. inc(pc);
  1856. case pc^ of
  1857. #0 :
  1858. break;
  1859. '"' :
  1860. begin
  1861. quote:=['"'];
  1862. inc(pc);
  1863. end;
  1864. '''' :
  1865. begin
  1866. quote:=[''''];
  1867. inc(pc);
  1868. end;
  1869. else
  1870. quote:=[' ',#9,#13];
  1871. end;
  1872. { scan until the end of the argument }
  1873. argstart:=pc;
  1874. while (pc^<>#0) and not(pc^ in quote) do
  1875. inc(pc);
  1876. { create argument }
  1877. arglen:=pc-argstart;
  1878. { TODO: FIXME: silent truncation of environment parameters }
  1879. if (arglen > 255) then
  1880. arglen := 255;
  1881. setlength(hs,arglen);
  1882. move(argstart^,hs[1],arglen);
  1883. interpret_option(hs,true);
  1884. { skip quote }
  1885. if pc^ in quote then
  1886. inc(pc);
  1887. until false;
  1888. end
  1889. else
  1890. Message1(option_no_option_found,'(env) '+envname);
  1891. FreeEnvPChar(env);
  1892. end;
  1893. procedure toption.read_parameters;
  1894. var
  1895. opts : string;
  1896. paramindex : longint;
  1897. begin
  1898. paramindex:=0;
  1899. while paramindex<paramcount do
  1900. begin
  1901. inc(paramindex);
  1902. opts:=system.paramstr(paramindex);
  1903. case opts[1] of
  1904. '@' :
  1905. if not firstpass then
  1906. begin
  1907. Delete(opts,1,1);
  1908. Message1(option_reading_further_from,opts);
  1909. interpret_file(opts);
  1910. end;
  1911. '!' :
  1912. if not firstpass then
  1913. begin
  1914. Delete(opts,1,1);
  1915. Message1(option_reading_further_from,'(env) '+opts);
  1916. interpret_envvar(opts);
  1917. end;
  1918. else
  1919. interpret_option(opts,true);
  1920. end;
  1921. end;
  1922. end;
  1923. procedure toption.parsecmd(cmd:string);
  1924. var
  1925. i,ps : longint;
  1926. opts : string;
  1927. begin
  1928. while (cmd<>'') do
  1929. begin
  1930. while cmd[1]=' ' do
  1931. delete(cmd,1,1);
  1932. i:=pos(' ',cmd);
  1933. if i=0 then
  1934. i:=256;
  1935. opts:=Copy(cmd,1,i-1);
  1936. Delete(cmd,1,i);
  1937. case opts[1] of
  1938. '@' :
  1939. if not firstpass then
  1940. begin
  1941. Delete(opts,1,1);
  1942. Message1(option_reading_further_from,opts);
  1943. interpret_file(opts);
  1944. end;
  1945. '!' :
  1946. if not firstpass then
  1947. begin
  1948. Delete(opts,1,1);
  1949. Message1(option_reading_further_from,'(env) '+opts);
  1950. interpret_envvar(opts);
  1951. end;
  1952. '"' :
  1953. begin
  1954. Delete(opts,1,1);
  1955. ps:=pos('"',cmd);
  1956. if (i<>256) and (ps>0) then
  1957. begin
  1958. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1959. cmd:=copy(cmd,ps+1,255);
  1960. end;
  1961. interpret_option(opts,true);
  1962. end;
  1963. else
  1964. interpret_option(opts,true);
  1965. end;
  1966. end;
  1967. end;
  1968. procedure toption.writequickinfo;
  1969. var
  1970. s : string;
  1971. i : longint;
  1972. procedure addinfo(const hs:string);
  1973. begin
  1974. if s<>'' then
  1975. s:=s+' '+hs
  1976. else
  1977. s:=hs;
  1978. end;
  1979. begin
  1980. s:='';
  1981. i:=0;
  1982. while (i<length(quickinfo)) do
  1983. begin
  1984. inc(i);
  1985. case quickinfo[i] of
  1986. 'S' :
  1987. begin
  1988. inc(i);
  1989. case quickinfo[i] of
  1990. 'O' :
  1991. addinfo(lower(source_info.shortname));
  1992. 'P' :
  1993. addinfo(source_cpu_string);
  1994. else
  1995. IllegalPara('-i'+QuickInfo);
  1996. end;
  1997. end;
  1998. 'T' :
  1999. begin
  2000. inc(i);
  2001. case quickinfo[i] of
  2002. 'O' :
  2003. addinfo(lower(target_info.shortname));
  2004. 'P' :
  2005. AddInfo(target_cpu_string);
  2006. else
  2007. IllegalPara('-i'+QuickInfo);
  2008. end;
  2009. end;
  2010. 'V' :
  2011. AddInfo(version_string);
  2012. 'W' :
  2013. AddInfo(full_version_string);
  2014. 'D' :
  2015. AddInfo(date_string);
  2016. '_' :
  2017. ;
  2018. else
  2019. IllegalPara('-i'+QuickInfo);
  2020. end;
  2021. end;
  2022. if s<>'' then
  2023. begin
  2024. writeln(s);
  2025. stopoptions(0);
  2026. end;
  2027. end;
  2028. procedure TOption.TargetOptions(def:boolean);
  2029. var
  2030. s : string;
  2031. i : integer;
  2032. target_unsup_features : tfeatures;
  2033. begin
  2034. if def then
  2035. def_system_macro(target_info.shortname)
  2036. else
  2037. undef_system_macro(target_info.shortname);
  2038. s:=target_info.extradefines;
  2039. while (s<>'') do
  2040. begin
  2041. i:=pos(';',s);
  2042. if i=0 then
  2043. i:=length(s)+1;
  2044. if def then
  2045. def_system_macro(Copy(s,1,i-1))
  2046. else
  2047. undef_system_macro(Copy(s,1,i-1));
  2048. delete(s,1,i);
  2049. end;
  2050. if (tf_winlikewidestring in target_info.flags) then
  2051. if def then
  2052. def_system_macro('FPC_WINLIKEWIDESTRING')
  2053. else
  2054. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2055. if (tf_requires_proper_alignment in target_info.flags) then
  2056. if def then
  2057. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2058. else
  2059. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2060. if source_info.system<>target_info.system then
  2061. if def then
  2062. def_system_macro('FPC_CROSSCOMPILING')
  2063. else
  2064. undef_system_macro('FPC_CROSSCOMPILING');
  2065. if source_info.cpu<>target_info.cpu then
  2066. if def then
  2067. def_system_macro('FPC_CPUCROSSCOMPILING')
  2068. else
  2069. def_system_macro('FPC_CPUCROSSCOMPILING');
  2070. if (tf_no_generic_stackcheck in target_info.flags) then
  2071. if def then
  2072. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2073. else
  2074. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2075. { Code generation flags }
  2076. if def and
  2077. (tf_pic_default in target_info.flags) then
  2078. include(init_settings.moduleswitches,cs_create_pic)
  2079. else
  2080. exclude(init_settings.moduleswitches,cs_create_pic);
  2081. { Resources support }
  2082. if (tf_has_winlike_resources in target_info.flags) then
  2083. if def then
  2084. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2085. else
  2086. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2087. { Features }
  2088. case target_info.system of
  2089. system_arm_gba:
  2090. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2091. system_arm_nds:
  2092. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs]
  2093. else
  2094. target_unsup_features:=[];
  2095. end;
  2096. if def then
  2097. features:=features-target_unsup_features
  2098. else
  2099. features:=features+target_unsup_features;
  2100. end;
  2101. procedure TOption.checkoptionscompatibility;
  2102. begin
  2103. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  2104. not(target_info.system in systems_darwin) then
  2105. begin
  2106. { smart linking does not yet work with DWARF debug info on most targets }
  2107. if (cs_link_smart in init_settings.globalswitches) then
  2108. begin
  2109. Message(option_dwarf_smart_linking);
  2110. ForceStaticLinking;
  2111. end;
  2112. end;
  2113. end;
  2114. constructor TOption.create;
  2115. begin
  2116. LogoWritten:=false;
  2117. NoPressEnter:=false;
  2118. FirstPass:=false;
  2119. FileLevel:=0;
  2120. Quickinfo:='';
  2121. ParaIncludePath:=TSearchPathList.Create;
  2122. ParaObjectPath:=TSearchPathList.Create;
  2123. ParaUnitPath:=TSearchPathList.Create;
  2124. ParaLibraryPath:=TSearchPathList.Create;
  2125. ParaFrameworkPath:=TSearchPathList.Create;
  2126. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2127. end;
  2128. destructor TOption.destroy;
  2129. begin
  2130. ParaIncludePath.Free;
  2131. ParaObjectPath.Free;
  2132. ParaUnitPath.Free;
  2133. ParaLibraryPath.Free;
  2134. ParaFrameworkPath.Free;
  2135. end;
  2136. {****************************************************************************
  2137. Callable Routines
  2138. ****************************************************************************}
  2139. function check_configfile(const fn:string;var foundfn:string):boolean;
  2140. function CfgFileExists(const fn:string):boolean;
  2141. begin
  2142. Comment(V_Tried,'Configfile search: '+fn);
  2143. CfgFileExists:=FileExists(fn);
  2144. end;
  2145. var
  2146. {$ifdef Unix}
  2147. hs,
  2148. {$endif Unix}
  2149. configpath : string;
  2150. begin
  2151. foundfn:=fn;
  2152. check_configfile:=true;
  2153. { retrieve configpath }
  2154. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  2155. {$ifdef Unix}
  2156. if configpath='' then
  2157. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  2158. {$endif}
  2159. {
  2160. Order to read configuration file :
  2161. try reading fpc.cfg in :
  2162. 1 - current dir
  2163. 2 - configpath
  2164. 3 - compiler path
  2165. }
  2166. if not FileExists(fn) then
  2167. begin
  2168. {$ifdef Unix}
  2169. hs:=GetEnvironmentVariable('HOME');
  2170. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  2171. foundfn:=FixPath(hs,false)+'.'+fn
  2172. else
  2173. {$endif}
  2174. if CfgFileExists(configpath+fn) then
  2175. foundfn:=configpath+fn
  2176. else
  2177. {$ifndef Unix}
  2178. if CfgFileExists(exepath+fn) then
  2179. foundfn:=exepath+fn
  2180. else
  2181. {$else}
  2182. if CfgFileExists('/etc/'+fn) then
  2183. foundfn:='/etc/'+fn
  2184. else
  2185. {$endif}
  2186. check_configfile:=false;
  2187. end;
  2188. end;
  2189. procedure read_arguments(cmd:string);
  2190. var
  2191. env: ansistring;
  2192. i : tfeature;
  2193. abi : tabi;
  2194. begin
  2195. option:=coption.create;
  2196. disable_configfile:=false;
  2197. { Non-core target defines }
  2198. Option.TargetOptions(true);
  2199. { get default messagefile }
  2200. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  2201. { default configfile can be specified on the commandline,
  2202. remove it first }
  2203. if (cmd<>'') and (cmd[1]='[') then
  2204. begin
  2205. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  2206. Delete(cmd,1,pos(']',cmd));
  2207. end
  2208. else
  2209. begin
  2210. ppccfg:='fpc.cfg';
  2211. ppcaltcfg:='ppc386.cfg';
  2212. end;
  2213. { first pass reading of parameters, only -i -v -T etc.}
  2214. option.firstpass:=true;
  2215. if cmd<>'' then
  2216. option.parsecmd(cmd)
  2217. else
  2218. begin
  2219. option.read_parameters;
  2220. { Write only quickinfo }
  2221. if option.quickinfo<>'' then
  2222. option.writequickinfo;
  2223. end;
  2224. option.firstpass:=false;
  2225. { target is set here, for wince the default app type is gui }
  2226. if target_info.system in system_wince then
  2227. apptype:=app_gui;
  2228. { default defines }
  2229. def_system_macro(target_info.shortname);
  2230. def_system_macro('FPC');
  2231. def_system_macro('VER'+version_nr);
  2232. def_system_macro('VER'+version_nr+'_'+release_nr);
  2233. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  2234. { Temporary defines, until things settle down }
  2235. def_system_macro('RESSTRSECTIONS');
  2236. def_system_macro('FPC_HASFIXED64BITVARIANT');
  2237. def_system_macro('FPC_HASINTERNALOLEVARIANT2VARIANTCAST');
  2238. def_system_macro('FPC_HAS_VARSETS');
  2239. def_system_macro('FPC_HAS_VALGRINDBOOL');
  2240. def_system_macro('FPC_HAS_STR_CURRENCY');
  2241. def_system_macro('FPC_REAL2REAL_FIXED');
  2242. def_system_macro('FPC_STRTOCHARARRAYPROC');
  2243. def_system_macro('FPC_NEW_BIGENDIAN_SETS');
  2244. def_system_macro('FPC_STRTOSHORTSTRINGPROC');
  2245. def_system_macro('FPC_OBJFPC_EXTENDED_IF');
  2246. {$if defined(x86) or defined(powerpc) or defined(powerpc64)}
  2247. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  2248. {$endif}
  2249. def_system_macro('FPC_HAS_UNICODESTRING');
  2250. def_system_macro('FPC_RTTI_PACKSET1');
  2251. {$ifdef x86_64}
  2252. def_system_macro('FPC_HAS_RIP_RELATIVE');
  2253. {$endif x86_64}
  2254. { these cpus have an inline rol/ror implementaion }
  2255. {$if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64)}
  2256. def_system_macro('FPC_HAS_INTERNAL_ROX');
  2257. {$endif}
  2258. {$ifdef SUPPORT_UNALIGNED}
  2259. def_system_macro('FPC_SUPPORTS_UNALIGNED');
  2260. def_system_macro('FPC_UNALIGNED_FIXED');
  2261. {$endif SUPPORT_UNALIGNED}
  2262. {$ifdef powerpc64}
  2263. def_system_macro('FPC_HAS_LWSYNC');
  2264. {$endif}
  2265. def_system_macro('FPC_HAS_MEMBAR');
  2266. def_system_macro('FPC_SETBASE_USED');
  2267. {$if defined(x86) or defined(arm)}
  2268. def_system_macro('INTERNAL_BACKTRACE');
  2269. {$endif}
  2270. def_system_macro('STR_CONCAT_PROCS');
  2271. {$warnings off}
  2272. if pocall_default = pocall_register then
  2273. def_system_macro('REGCALL');
  2274. {$warnings on}
  2275. { don't remove this, it's also for fpdoc necessary (FK) }
  2276. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  2277. { using a case is pretty useless here (FK) }
  2278. { some stuff for TP compatibility }
  2279. {$ifdef i386}
  2280. def_system_macro('CPU86');
  2281. def_system_macro('CPU87');
  2282. def_system_macro('CPU386');
  2283. {$endif}
  2284. { new processor stuff }
  2285. {$ifdef i386}
  2286. def_system_macro('CPUI386');
  2287. def_system_macro('CPU32');
  2288. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2289. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2290. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2291. {$endif}
  2292. {$ifdef m68k}
  2293. def_system_macro('CPU68');
  2294. def_system_macro('CPU68K');
  2295. def_system_macro('CPUM68K');
  2296. def_system_macro('CPU32');
  2297. def_system_macro('FPC_CURRENCY_IS_INT64');
  2298. def_system_macro('FPC_COMP_IS_INT64');
  2299. {$endif}
  2300. {$ifdef ALPHA}
  2301. def_system_macro('CPUALPHA');
  2302. def_system_macro('CPU64');
  2303. {$endif}
  2304. {$ifdef powerpc}
  2305. def_system_macro('CPUPOWERPC');
  2306. def_system_macro('CPUPOWERPC32');
  2307. def_system_macro('CPU32');
  2308. def_system_macro('FPC_CURRENCY_IS_INT64');
  2309. def_system_macro('FPC_COMP_IS_INT64');
  2310. {$endif}
  2311. {$ifdef POWERPC64}
  2312. def_system_macro('CPUPOWERPC');
  2313. def_system_macro('CPUPOWERPC64');
  2314. def_system_macro('CPU64');
  2315. def_system_macro('FPC_CURRENCY_IS_INT64');
  2316. def_system_macro('FPC_COMP_IS_INT64');
  2317. {$endif}
  2318. {$ifdef iA64}
  2319. def_system_macro('CPUIA64');
  2320. def_system_macro('CPU64');
  2321. {$endif}
  2322. {$ifdef x86_64}
  2323. def_system_macro('CPUX86_64');
  2324. def_system_macro('CPUAMD64');
  2325. def_system_macro('CPU64');
  2326. { not supported for now, afaik (FK)
  2327. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  2328. { win64 doesn't support the legacy fpu }
  2329. if target_info.system=system_x86_64_win64 then
  2330. begin
  2331. def_system_macro('FPC_CURRENCY_IS_INT64');
  2332. def_system_macro('FPC_COMP_IS_INT64');
  2333. end;
  2334. {$endif}
  2335. {$ifdef sparc}
  2336. def_system_macro('CPUSPARC');
  2337. def_system_macro('CPUSPARC32');
  2338. def_system_macro('CPU32');
  2339. def_system_macro('FPC_CURRENCY_IS_INT64');
  2340. def_system_macro('FPC_COMP_IS_INT64');
  2341. {$endif}
  2342. {$ifdef vis}
  2343. def_system_macro('CPUVIS');
  2344. def_system_macro('CPU32');
  2345. {$endif}
  2346. {$ifdef arm}
  2347. def_system_macro('CPUARM');
  2348. def_system_macro('CPU32');
  2349. def_system_macro('FPC_CURRENCY_IS_INT64');
  2350. def_system_macro('FPC_COMP_IS_INT64');
  2351. {$endif arm}
  2352. {$ifdef avr}
  2353. def_system_macro('CPUAVR');
  2354. def_system_macro('CPU16');
  2355. def_system_macro('FPC_CURRENCY_IS_INT64');
  2356. def_system_macro('FPC_COMP_IS_INT64');
  2357. {$endif avr}
  2358. { read configuration file }
  2359. if (not disable_configfile) and
  2360. (ppccfg<>'') then
  2361. begin
  2362. read_configfile:=check_configfile(ppccfg,ppccfg);
  2363. { Maybe alternative configfile ? }
  2364. if (not read_configfile) and
  2365. (ppcaltcfg<>'') then
  2366. begin
  2367. read_configfile:=check_configfile(ppcaltcfg,ppccfg);
  2368. if read_configfile then
  2369. message(option_ppc386_deprecated);
  2370. end;
  2371. end
  2372. else
  2373. read_configfile := false;
  2374. { Read commandline and configfile }
  2375. param_file:='';
  2376. { read configfile }
  2377. if read_configfile then
  2378. option.interpret_file(ppccfg);
  2379. { read parameters again to override config file }
  2380. if cmd<>'' then
  2381. option.parsecmd(cmd)
  2382. else
  2383. begin
  2384. { Write help pages if no parameters are passed }
  2385. if (paramcount=0) then
  2386. Option.WriteHelpPages;
  2387. option.read_parameters;
  2388. { Write only quickinfo }
  2389. if option.quickinfo<>'' then
  2390. option.writequickinfo;
  2391. end;
  2392. { check the compatibility of different options and adjust them if necessary
  2393. (and print possible errors)
  2394. }
  2395. option.checkoptionscompatibility;
  2396. { Stop if errors in options }
  2397. if ErrorCount>0 then
  2398. StopOptions(1);
  2399. { endian define }
  2400. case target_info.endian of
  2401. endian_little :
  2402. begin
  2403. def_system_macro('ENDIAN_LITTLE');
  2404. def_system_macro('FPC_LITTLE_ENDIAN');
  2405. end;
  2406. endian_big :
  2407. begin
  2408. def_system_macro('ENDIAN_BIG');
  2409. def_system_macro('FPC_BIG_ENDIAN');
  2410. end;
  2411. end;
  2412. { define abi }
  2413. for abi:=low(tabi) to high(tabi) do
  2414. undef_system_macro('FPC_ABI_'+abi2str[abi]);
  2415. def_system_macro('FPC_ABI_'+abi2str[target_info.abi]);
  2416. { Write logo }
  2417. if option.ParaLogo then
  2418. option.writelogo;
  2419. { Check file to compile }
  2420. if param_file='' then
  2421. begin
  2422. Message(option_no_source_found);
  2423. StopOptions(1);
  2424. end;
  2425. {$ifndef Unix}
  2426. param_file:=FixFileName(param_file);
  2427. {$endif not unix}
  2428. inputfilepath:=ExtractFilePath(param_file);
  2429. inputfilename:=ExtractFileName(param_file);
  2430. if ExtractFileExt(inputfilename)='' then
  2431. begin
  2432. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  2433. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  2434. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  2435. inputfilename:=ChangeFileExt(inputfilename,pasext)
  2436. else if ((m_mac in current_settings.modeswitches) or
  2437. (tf_p_ext_support in target_info.flags))
  2438. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  2439. inputfilename:=ChangeFileExt(inputfilename,pext);
  2440. end;
  2441. { Check output dir }
  2442. if (OutputExeDir<>'') and
  2443. not PathExists(OutputExeDir,false) then
  2444. begin
  2445. Message1(general_e_path_does_not_exist,OutputExeDir);
  2446. StopOptions(1);
  2447. end;
  2448. { Add paths specified with parameters to the searchpaths }
  2449. UnitSearchPath.AddList(option.ParaUnitPath,true);
  2450. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  2451. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  2452. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  2453. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  2454. { add unit environment and exepath to the unit search path }
  2455. if inputfilepath<>'' then
  2456. Unitsearchpath.AddPath(inputfilepath,true);
  2457. if not disable_configfile then
  2458. begin
  2459. env:=GetEnvironmentVariable(target_info.unit_env);
  2460. if env<>'' then
  2461. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  2462. end;
  2463. {$ifdef Unix}
  2464. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2465. if fpcdir='' then
  2466. begin
  2467. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  2468. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  2469. else
  2470. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2471. end;
  2472. {$else unix}
  2473. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2474. if fpcdir='' then
  2475. begin
  2476. fpcdir:=ExePath+'../';
  2477. if not(PathExists(fpcdir+'units',true)) and
  2478. not(PathExists(fpcdir+'rtl',true)) then
  2479. fpcdir:=fpcdir+'../';
  2480. end;
  2481. {$endif unix}
  2482. { first try development RTL, else use the default installation path }
  2483. if not disable_configfile then
  2484. begin
  2485. if PathExists(FpcDir+'rtl',true) then
  2486. if tf_use_8_3 in Source_Info.Flags then
  2487. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2488. else
  2489. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2490. else
  2491. if tf_use_8_3 in Source_Info.Flags then
  2492. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2493. else
  2494. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2495. end;
  2496. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2497. Do not add it when linking on the target because then we can maybe already find
  2498. .o files that are not for the target }
  2499. if (ExePath<>GetCurrentDir) and
  2500. not(cs_link_on_target in init_settings.globalswitches) then
  2501. UnitSearchPath.AddPath(ExePath,false);
  2502. { Add unit dir to the object and library path }
  2503. objectsearchpath.AddList(unitsearchpath,false);
  2504. librarysearchpath.AddList(unitsearchpath,false);
  2505. { maybe override assembler }
  2506. if (paratargetasm<>as_none) then
  2507. begin
  2508. if not set_target_asm(paratargetasm) then
  2509. begin
  2510. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2511. set_target_asm(target_info.assemextern);
  2512. Message1(option_asm_forced,target_asm.idtxt);
  2513. end;
  2514. if (af_no_debug in asminfos[paratargetasm]^.flags) and
  2515. (paratargetdbg<>dbg_none) then
  2516. begin
  2517. Message1(option_confict_asm_debug,
  2518. asminfos[paratargetasm]^.idtxt);
  2519. paratargetdbg:=dbg_none;
  2520. exclude(init_settings.moduleswitches,cs_debuginfo);
  2521. end;
  2522. end;
  2523. { maybe override debug info format }
  2524. if (paratargetdbg<>dbg_none) then
  2525. set_target_dbg(paratargetdbg);
  2526. { switch assembler if it's binary and we got -a on the cmdline }
  2527. if (cs_asm_leave in init_settings.globalswitches) and
  2528. (af_outputbinary in target_asm.flags) then
  2529. begin
  2530. Message(option_switch_bin_to_src_assembler);
  2531. set_target_asm(target_info.assemextern);
  2532. end;
  2533. { Force use of external linker if there is no
  2534. internal linker or the linking is skipped }
  2535. if not(cs_link_extern in init_settings.globalswitches) and
  2536. (not assigned(target_info.link) or
  2537. (cs_link_nolink in init_settings.globalswitches)) then
  2538. include(init_settings.globalswitches,cs_link_extern);
  2539. { turn off stripping if compiling with debuginfo or profile }
  2540. if (
  2541. (cs_debuginfo in init_settings.moduleswitches) or
  2542. (cs_profile in init_settings.moduleswitches)
  2543. ) and
  2544. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  2545. exclude(init_settings.globalswitches,cs_link_strip);
  2546. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds}
  2547. if (target_info.system in [system_arm_wince,system_arm_gba,system_m68k_amiga,
  2548. system_m68k_linux,system_arm_nds,system_arm_darwin,system_arm_embedded])
  2549. {$ifdef arm}
  2550. or (init_settings.fputype=fpu_soft)
  2551. or (target_info.abi=abi_eabi)
  2552. {$endif arm}
  2553. then
  2554. begin
  2555. {$ifdef cpufpemu}
  2556. include(init_settings.moduleswitches,cs_fp_emulation);
  2557. { cs_fp_emulation and fpu_soft are equal on arm }
  2558. init_settings.fputype:=fpu_soft;
  2559. {$endif cpufpemu}
  2560. end;
  2561. { now we can define cpu and fpu type }
  2562. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  2563. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  2564. if init_settings.fputype<>fpu_none then
  2565. begin
  2566. {$if defined(i386)}
  2567. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2568. {$endif}
  2569. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2570. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2571. {$if not defined(i386) and not defined(x86_64)}
  2572. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2573. {$endif}
  2574. {$ifdef x86_64}
  2575. { win64 doesn't support the legacy fpu }
  2576. if target_info.system=system_x86_64_win64 then
  2577. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  2578. else
  2579. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2580. {$endif}
  2581. end;
  2582. {$ifdef ARM}
  2583. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  2584. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  2585. not(cs_fp_emulation in init_settings.moduleswitches) then
  2586. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  2587. {$endif ARM}
  2588. { Section smartlinking conflicts with import sections on Windows }
  2589. if GenerateImportSection and
  2590. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  2591. exclude(target_info.flags,tf_smartlink_sections);
  2592. if not LinkTypeSetExplicitly then
  2593. set_default_link_type;
  2594. { Default alignment settings,
  2595. 1. load the defaults for the target
  2596. 2. override with generic optimizer setting (little size)
  2597. 3. override with the user specified -Oa }
  2598. UpdateAlignment(init_settings.alignment,target_info.alignment);
  2599. if (cs_opt_size in current_settings.optimizerswitches) then
  2600. begin
  2601. init_settings.alignment.procalign:=1;
  2602. init_settings.alignment.jumpalign:=1;
  2603. init_settings.alignment.loopalign:=1;
  2604. end;
  2605. UpdateAlignment(init_settings.alignment,option.paraalignment);
  2606. set_system_macro('FPC_VERSION',version_nr);
  2607. set_system_macro('FPC_RELEASE',release_nr);
  2608. set_system_macro('FPC_PATCH',patch_nr);
  2609. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  2610. if not(target_info.system in system_all_windows) then
  2611. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  2612. for i:=low(tfeature) to high(tfeature) do
  2613. if i in features then
  2614. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  2615. option.free;
  2616. Option:=nil;
  2617. end;
  2618. initialization
  2619. coption:=toption;
  2620. finalization
  2621. if assigned(option) then
  2622. option.free;
  2623. end.