options.pas 91 KB

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