options.pas 90 KB

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