options.pas 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831
  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. Message1(option_obsolete_switch,'-St');
  1273. 'v' :
  1274. If UnsetBool(More, j) then
  1275. exclude(init_settings.globalswitches,cs_support_vectors)
  1276. else
  1277. include(init_settings.globalswitches,cs_support_vectors);
  1278. 'x' :
  1279. If UnsetBool(More, j) then
  1280. exclude(init_settings.globalswitches,cs_support_exceptions)
  1281. else
  1282. include(init_settings.globalswitches,cs_support_exceptions);
  1283. '-' :
  1284. begin
  1285. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions];
  1286. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion, cs_do_inline, cs_ansistrings];
  1287. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1288. cs_support_macro];
  1289. end;
  1290. else
  1291. IllegalPara(opt);
  1292. end;
  1293. inc(j);
  1294. end;
  1295. end;
  1296. end;
  1297. 'T' :
  1298. begin
  1299. more:=Upper(More);
  1300. if paratarget=system_none then
  1301. begin
  1302. { remove old target define }
  1303. TargetOptions(false);
  1304. { load new target }
  1305. paratarget:=find_system_by_string(More);
  1306. if paratarget<>system_none then
  1307. set_target(paratarget)
  1308. else
  1309. IllegalPara(opt);
  1310. { set new define }
  1311. TargetOptions(true);
  1312. end
  1313. else
  1314. if More<>upper(target_info.shortname) then
  1315. Message1(option_target_is_already_set,target_info.shortname);
  1316. end;
  1317. 'u' :
  1318. if more <> '' then
  1319. undef_system_macro(more);
  1320. 'U' :
  1321. begin
  1322. j:=1;
  1323. while j<=length(more) do
  1324. begin
  1325. case more[j] of
  1326. {$ifdef UNITALIASES}
  1327. 'a' :
  1328. begin
  1329. AddUnitAlias(Copy(More,j+1,255));
  1330. break;
  1331. end;
  1332. {$endif UNITALIASES}
  1333. 'n' :
  1334. exclude(init_settings.globalswitches,cs_check_unit_name);
  1335. 'p' :
  1336. begin
  1337. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1338. break;
  1339. end;
  1340. 'r' :
  1341. do_release:=true;
  1342. 's' :
  1343. include(init_settings.moduleswitches,cs_compilesystem);
  1344. '-' :
  1345. begin
  1346. exclude(init_settings.moduleswitches,cs_compilesystem);
  1347. exclude(init_settings.globalswitches,cs_check_unit_name);
  1348. end;
  1349. else
  1350. IllegalPara(opt);
  1351. end;
  1352. inc(j);
  1353. end;
  1354. end;
  1355. 'v' :
  1356. begin
  1357. if not setverbosity(More) then
  1358. IllegalPara(opt);
  1359. end;
  1360. 'V' : ; { Ignore used by fpc }
  1361. 'W' :
  1362. begin
  1363. j:=1;
  1364. while j<=length(More) do
  1365. begin
  1366. case More[j] of
  1367. 'A':
  1368. begin
  1369. if UnsetBool(More, j) then
  1370. apptype:=app_native
  1371. else
  1372. apptype:=app_cui;
  1373. end;
  1374. 'b':
  1375. begin
  1376. if (target_info.system in systems_darwin) then
  1377. begin
  1378. if not UnsetBool(More, j) then
  1379. apptype:=app_bundle
  1380. else
  1381. apptype:=app_cui
  1382. end
  1383. else
  1384. IllegalPara(opt);
  1385. end;
  1386. 'B':
  1387. begin
  1388. { -WB200000 means set trefered base address
  1389. to $200000, but does not change relocsection boolean
  1390. this way we can create both relocatble and
  1391. non relocatable DLL at a specific base address PM }
  1392. if (length(More)>j) then
  1393. begin
  1394. val('$'+Copy(More,j+1,255),imagebase,code);
  1395. if code<>0 then
  1396. IllegalPara(opt);
  1397. ImageBaseSetExplicity:=true;
  1398. end
  1399. else
  1400. begin
  1401. RelocSection:=true;
  1402. RelocSectionSetExplicitly:=true;
  1403. end;
  1404. break;
  1405. end;
  1406. 'C':
  1407. begin
  1408. if UnsetBool(More, j) then
  1409. apptype:=app_gui
  1410. else
  1411. apptype:=app_cui;
  1412. end;
  1413. 'D':
  1414. begin
  1415. UseDeffileForExports:=not UnsetBool(More, j);
  1416. UseDeffileForExportsSetExplicitly:=true;
  1417. end;
  1418. 'e':
  1419. begin
  1420. if (target_info.system in systems_darwin) then
  1421. begin
  1422. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  1423. set_target_res(res_ext);
  1424. target_info.resobjext:='.fpcres';
  1425. end
  1426. else
  1427. IllegalPara(opt);
  1428. end;
  1429. 'F':
  1430. begin
  1431. if UnsetBool(More, j) then
  1432. apptype:=app_cui
  1433. else
  1434. apptype:=app_fs;
  1435. end;
  1436. 'G':
  1437. begin
  1438. if UnsetBool(More, j) then
  1439. apptype:=app_cui
  1440. else
  1441. apptype:=app_gui;
  1442. end;
  1443. 'I':
  1444. begin
  1445. GenerateImportSection:=not UnsetBool(More,j);
  1446. GenerateImportSectionSetExplicitly:=true;
  1447. end;
  1448. 'i':
  1449. begin
  1450. if (target_info.system in systems_darwin) then
  1451. begin
  1452. set_target_res(res_macho);
  1453. target_info.resobjext:=
  1454. targetinfos[target_info.system]^.resobjext;
  1455. end
  1456. else
  1457. IllegalPara(opt);
  1458. end;
  1459. 'N':
  1460. begin
  1461. RelocSection:=UnsetBool(More,j);
  1462. RelocSectionSetExplicitly:=true;
  1463. end;
  1464. 'p':
  1465. begin
  1466. {$if defined(arm) or defined(avr)}
  1467. if (target_info.system in systems_embedded) then
  1468. begin
  1469. s:=upper(copy(more,j+1,length(more)-j));
  1470. if not(SetControllerType(s,init_settings.controllertype)) then
  1471. IllegalPara(opt);
  1472. break;
  1473. end
  1474. else
  1475. {$endif defined(arm) or defined(avr)}
  1476. IllegalPara(opt);
  1477. end;
  1478. 'R':
  1479. begin
  1480. { support -WR+ / -WR- as synonyms to -WR / -WN }
  1481. RelocSection:=not UnsetBool(More,j);
  1482. RelocSectionSetExplicitly:=true;
  1483. end;
  1484. 'T':
  1485. begin
  1486. if UnsetBool(More, j) then
  1487. apptype:=app_cui
  1488. else
  1489. apptype:=app_tool;
  1490. end;
  1491. 'X':
  1492. begin
  1493. if (target_info.system in systems_linux) then
  1494. begin
  1495. if UnsetBool(More, j) then
  1496. exclude(init_settings.moduleswitches,cs_executable_stack)
  1497. else
  1498. include(init_settings.moduleswitches,cs_executable_stack)
  1499. end
  1500. else
  1501. IllegalPara(opt);
  1502. end
  1503. else
  1504. IllegalPara(opt);
  1505. end;
  1506. inc(j);
  1507. end;
  1508. end;
  1509. 'X' :
  1510. begin
  1511. j:=1;
  1512. while j<=length(more) do
  1513. begin
  1514. case More[j] of
  1515. 'c' : Cshared:=TRUE;
  1516. 'd' : Dontlinkstdlibpath:=TRUE;
  1517. 'e' :
  1518. begin
  1519. If UnsetBool(More, j) then
  1520. exclude(init_settings.globalswitches,cs_link_extern)
  1521. else
  1522. include(init_settings.globalswitches,cs_link_extern);
  1523. end;
  1524. 'f' :
  1525. include(init_settings.globalswitches,cs_link_pthread);
  1526. 'g' :
  1527. begin
  1528. If UnsetBool(More, j) then
  1529. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  1530. else
  1531. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  1532. end;
  1533. 'i' :
  1534. begin
  1535. If UnsetBool(More, j) then
  1536. include(init_settings.globalswitches,cs_link_extern)
  1537. else
  1538. exclude(init_settings.globalswitches,cs_link_extern);
  1539. end;
  1540. 'n' :
  1541. begin
  1542. If UnsetBool(More, j) then
  1543. exclude(init_settings.globalswitches,cs_link_native)
  1544. else
  1545. include(init_settings.globalswitches,cs_link_native);
  1546. end;
  1547. 'm' :
  1548. begin
  1549. If UnsetBool(More, j) then
  1550. exclude(init_settings.globalswitches,cs_link_map)
  1551. else
  1552. include(init_settings.globalswitches,cs_link_map);
  1553. end;
  1554. 'p' : ; { Ignore used by fpc.pp }
  1555. 'r' :
  1556. begin
  1557. if (target_info.system in suppported_targets_x_smallr) then
  1558. begin
  1559. rlinkpath:=Copy(more,2,length(More)-1);
  1560. DefaultReplacements(rlinkpath);
  1561. end
  1562. else
  1563. IgnoredPara('-Xr');
  1564. more:='';
  1565. end;
  1566. 'R' :
  1567. begin
  1568. sysrootpath:=copy(more,2,length(more)-1);
  1569. defaultreplacements(sysrootpath);
  1570. more:='';
  1571. end;
  1572. 's' :
  1573. begin
  1574. If UnsetBool(More, j) then
  1575. exclude(init_settings.globalswitches,cs_link_strip)
  1576. else
  1577. include(init_settings.globalswitches,cs_link_strip);
  1578. end;
  1579. 't' :
  1580. include(init_settings.globalswitches,cs_link_staticflag);
  1581. 'v' :
  1582. begin
  1583. If UnsetBool(More, j) then
  1584. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  1585. else
  1586. include(init_settings.globalswitches,cs_link_opt_vtable);
  1587. end;
  1588. 'D' :
  1589. begin
  1590. def_system_macro('FPC_LINK_DYNAMIC');
  1591. undef_system_macro('FPC_LINK_SMART');
  1592. undef_system_macro('FPC_LINK_STATIC');
  1593. exclude(init_settings.globalswitches,cs_link_static);
  1594. exclude(init_settings.globalswitches,cs_link_smart);
  1595. include(init_settings.globalswitches,cs_link_shared);
  1596. LinkTypeSetExplicitly:=true;
  1597. end;
  1598. 'M' :
  1599. begin
  1600. mainaliasname:=Copy(more,2,length(More)-1);
  1601. More:='';
  1602. end;
  1603. 'P' :
  1604. begin
  1605. utilsprefix:=Copy(more,2,length(More)-1);
  1606. DefaultReplacements(utilsprefix);
  1607. More:='';
  1608. end;
  1609. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  1610. // these are not aggregable.
  1611. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  1612. IllegalPara(opt)
  1613. else
  1614. begin
  1615. case more[j+1] of
  1616. 'A' : begin
  1617. s:=Copy(more,3,length(More)-2);
  1618. if not LinkLibraryAliases.AddDep(s) Then
  1619. IllegalPara(opt);
  1620. end;
  1621. 'O' : begin
  1622. s:=Copy(more,3,length(More)-2);
  1623. if not LinkLibraryOrder.AddWeight(s) Then
  1624. IllegalPara(opt);
  1625. end;
  1626. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  1627. else
  1628. IllegalPara(opt);
  1629. end; {case}
  1630. j:=length(more);
  1631. end; {else begin}
  1632. end;
  1633. 'S' :
  1634. begin
  1635. ForceStaticLinking;
  1636. end;
  1637. 'X' :
  1638. begin
  1639. def_system_macro('FPC_LINK_SMART');
  1640. undef_system_macro('FPC_LINK_STATIC');
  1641. undef_system_macro('FPC_LINK_DYNAMIC');
  1642. exclude(init_settings.globalswitches,cs_link_static);
  1643. include(init_settings.globalswitches,cs_link_smart);
  1644. exclude(init_settings.globalswitches,cs_link_shared);
  1645. LinkTypeSetExplicitly:=true;
  1646. end;
  1647. '-' :
  1648. begin
  1649. exclude(init_settings.globalswitches,cs_link_staticflag);
  1650. exclude(init_settings.globalswitches,cs_link_strip);
  1651. exclude(init_settings.globalswitches,cs_link_map);
  1652. set_default_link_type;
  1653. end;
  1654. else
  1655. IllegalPara(opt);
  1656. end;
  1657. inc(j);
  1658. end;
  1659. end;
  1660. else
  1661. IllegalPara(opt);
  1662. end;
  1663. end;
  1664. '@' :
  1665. begin
  1666. Message(option_no_nested_response_file);
  1667. StopOptions(1);
  1668. end;
  1669. else
  1670. begin
  1671. if (length(param_file)<>0) then
  1672. Message2(option_only_one_source_support,param_file,opt);
  1673. param_file:=opt;
  1674. Message1(option_found_file,opt);
  1675. end;
  1676. end;
  1677. end;
  1678. procedure Toption.Interpret_file(const filename : string);
  1679. procedure RemoveSep(var fn:string);
  1680. var
  1681. i : longint;
  1682. begin
  1683. i:=0;
  1684. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  1685. inc(i);
  1686. Delete(fn,1,i);
  1687. i:=length(fn);
  1688. while (i>0) and (fn[i] in [',',' ',#9]) do
  1689. dec(i);
  1690. fn:=copy(fn,1,i);
  1691. end;
  1692. function GetName(var fn:string):string;
  1693. var
  1694. i : longint;
  1695. begin
  1696. i:=0;
  1697. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  1698. inc(i);
  1699. GetName:=Copy(fn,1,i);
  1700. Delete(fn,1,i);
  1701. end;
  1702. const
  1703. maxlevel = 15;
  1704. var
  1705. f : text;
  1706. s, tmp,
  1707. opts : string;
  1708. skip : array[0..maxlevel] of boolean;
  1709. line,
  1710. level : longint;
  1711. option_read : boolean;
  1712. begin
  1713. { avoid infinite loop }
  1714. Inc(FileLevel);
  1715. Option_read:=false;
  1716. If FileLevel>MaxLevel then
  1717. Message(option_too_many_cfg_files);
  1718. { Maybe It's Directory ?} //Jaro Change:
  1719. if PathExists(filename,false) then
  1720. begin
  1721. Message1(option_config_is_dir,filename);
  1722. exit;
  1723. end;
  1724. { open file }
  1725. Message1(option_using_file,filename);
  1726. assign(f,ExpandFileName(filename));
  1727. {$I-}
  1728. reset(f);
  1729. {$I+}
  1730. if ioresult<>0 then
  1731. begin
  1732. Message1(option_unable_open_file,filename);
  1733. exit;
  1734. end;
  1735. Message1(option_start_reading_configfile,filename);
  1736. fillchar(skip,sizeof(skip),0);
  1737. level:=0;
  1738. line:=0;
  1739. while not eof(f) do
  1740. begin
  1741. readln(f,opts);
  1742. inc(line);
  1743. RemoveSep(opts);
  1744. if (opts<>'') and (opts[1]<>';') then
  1745. begin
  1746. if opts[1]='#' then
  1747. begin
  1748. Message1(option_interpreting_file_option,opts);
  1749. Delete(opts,1,1);
  1750. s:=upper(GetName(opts));
  1751. if (s='SECTION') then
  1752. begin
  1753. RemoveSep(opts);
  1754. s:=upper(GetName(opts));
  1755. if level=0 then
  1756. skip[level]:=not defined_macro(s) or (s='COMMON');
  1757. end
  1758. else
  1759. if (s='IFDEF') then
  1760. begin
  1761. RemoveSep(opts);
  1762. if Level>=maxlevel then
  1763. begin
  1764. Message2(option_too_many_ifdef,filename,tostr(line));
  1765. stopOptions(1);
  1766. end;
  1767. inc(Level);
  1768. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  1769. end
  1770. else
  1771. if (s='IFNDEF') then
  1772. begin
  1773. RemoveSep(opts);
  1774. if Level>=maxlevel then
  1775. begin
  1776. Message2(option_too_many_ifdef,filename,tostr(line));
  1777. stopOptions(1);
  1778. end;
  1779. inc(Level);
  1780. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  1781. end
  1782. else
  1783. if (s='ELSE') then
  1784. begin
  1785. if Level=0 then
  1786. begin
  1787. Message2(option_else_without_if,filename,tostr(line));
  1788. stopOptions(1);
  1789. end
  1790. else
  1791. skip[level]:=skip[level-1] or (not skip[level])
  1792. end
  1793. else
  1794. if (s='ENDIF') then
  1795. begin
  1796. skip[level]:=false;
  1797. if Level=0 then
  1798. begin
  1799. Message2(option_too_many_endif,filename,tostr(line));
  1800. stopOptions(1);
  1801. end;
  1802. dec(level);
  1803. end
  1804. else
  1805. if (not skip[level]) then
  1806. begin
  1807. if (s='DEFINE') then
  1808. begin
  1809. RemoveSep(opts);
  1810. tmp:= GetName(opts);
  1811. if tmp <> '' then
  1812. def_system_macro(tmp);
  1813. end
  1814. else
  1815. if (s='UNDEF') then
  1816. begin
  1817. RemoveSep(opts);
  1818. tmp:= GetName(opts);
  1819. if tmp <> '' then
  1820. undef_system_macro(tmp);
  1821. end
  1822. else
  1823. if (s='WRITE') then
  1824. begin
  1825. Delete(opts,1,1);
  1826. WriteLn(opts);
  1827. end
  1828. else
  1829. if (s='INCLUDE') then
  1830. begin
  1831. Delete(opts,1,1);
  1832. Interpret_file(opts);
  1833. end;
  1834. end;
  1835. end
  1836. else
  1837. begin
  1838. if (opts[1]='-') or (opts[1]='@') then
  1839. begin
  1840. if (not skip[level]) then
  1841. interpret_option(opts,false);
  1842. Option_read:=true;
  1843. end
  1844. else
  1845. Message1(option_illegal_para,opts);
  1846. end;
  1847. end;
  1848. end;
  1849. if Level>0 then
  1850. Message(option_too_less_endif);
  1851. if Not Option_read then
  1852. Message1(option_no_option_found,filename)
  1853. else
  1854. Message1(option_end_reading_configfile,filename);
  1855. Close(f);
  1856. Dec(FileLevel);
  1857. end;
  1858. procedure Toption.Interpret_envvar(const envname : string);
  1859. var
  1860. argstart,
  1861. env,
  1862. pc : pchar;
  1863. arglen : longint;
  1864. quote : set of char;
  1865. hs : string;
  1866. begin
  1867. Message1(option_using_env,envname);
  1868. env:=GetEnvPChar(envname);
  1869. pc:=env;
  1870. if assigned(pc) then
  1871. begin
  1872. repeat
  1873. { skip leading spaces }
  1874. while pc^ in [' ',#9,#13] do
  1875. inc(pc);
  1876. case pc^ of
  1877. #0 :
  1878. break;
  1879. '"' :
  1880. begin
  1881. quote:=['"'];
  1882. inc(pc);
  1883. end;
  1884. '''' :
  1885. begin
  1886. quote:=[''''];
  1887. inc(pc);
  1888. end;
  1889. else
  1890. quote:=[' ',#9,#13];
  1891. end;
  1892. { scan until the end of the argument }
  1893. argstart:=pc;
  1894. while (pc^<>#0) and not(pc^ in quote) do
  1895. inc(pc);
  1896. { create argument }
  1897. arglen:=pc-argstart;
  1898. { TODO: FIXME: silent truncation of environment parameters }
  1899. if (arglen > 255) then
  1900. arglen := 255;
  1901. setlength(hs,arglen);
  1902. move(argstart^,hs[1],arglen);
  1903. interpret_option(hs,true);
  1904. { skip quote }
  1905. if pc^ in quote then
  1906. inc(pc);
  1907. until false;
  1908. end
  1909. else
  1910. Message1(option_no_option_found,'(env) '+envname);
  1911. FreeEnvPChar(env);
  1912. end;
  1913. procedure toption.read_parameters;
  1914. var
  1915. opts : string;
  1916. paramindex : longint;
  1917. begin
  1918. paramindex:=0;
  1919. while paramindex<paramcount do
  1920. begin
  1921. inc(paramindex);
  1922. opts:=system.paramstr(paramindex);
  1923. case opts[1] of
  1924. '@' :
  1925. if not firstpass then
  1926. begin
  1927. Delete(opts,1,1);
  1928. Message1(option_reading_further_from,opts);
  1929. interpret_file(opts);
  1930. end;
  1931. '!' :
  1932. if not firstpass then
  1933. begin
  1934. Delete(opts,1,1);
  1935. Message1(option_reading_further_from,'(env) '+opts);
  1936. interpret_envvar(opts);
  1937. end;
  1938. else
  1939. interpret_option(opts,true);
  1940. end;
  1941. end;
  1942. end;
  1943. procedure toption.parsecmd(cmd:string);
  1944. var
  1945. i,ps : longint;
  1946. opts : string;
  1947. begin
  1948. while (cmd<>'') do
  1949. begin
  1950. while cmd[1]=' ' do
  1951. delete(cmd,1,1);
  1952. i:=pos(' ',cmd);
  1953. if i=0 then
  1954. i:=256;
  1955. opts:=Copy(cmd,1,i-1);
  1956. Delete(cmd,1,i);
  1957. case opts[1] of
  1958. '@' :
  1959. if not firstpass then
  1960. begin
  1961. Delete(opts,1,1);
  1962. Message1(option_reading_further_from,opts);
  1963. interpret_file(opts);
  1964. end;
  1965. '!' :
  1966. if not firstpass then
  1967. begin
  1968. Delete(opts,1,1);
  1969. Message1(option_reading_further_from,'(env) '+opts);
  1970. interpret_envvar(opts);
  1971. end;
  1972. '"' :
  1973. begin
  1974. Delete(opts,1,1);
  1975. ps:=pos('"',cmd);
  1976. if (i<>256) and (ps>0) then
  1977. begin
  1978. opts:=opts + ' '+ copy(cmd,1,ps-1);
  1979. cmd:=copy(cmd,ps+1,255);
  1980. end;
  1981. interpret_option(opts,true);
  1982. end;
  1983. else
  1984. interpret_option(opts,true);
  1985. end;
  1986. end;
  1987. end;
  1988. procedure toption.writequickinfo;
  1989. var
  1990. s : string;
  1991. i : longint;
  1992. procedure addinfo(const hs:string);
  1993. begin
  1994. if s<>'' then
  1995. s:=s+' '+hs
  1996. else
  1997. s:=hs;
  1998. end;
  1999. begin
  2000. s:='';
  2001. i:=0;
  2002. while (i<length(quickinfo)) do
  2003. begin
  2004. inc(i);
  2005. case quickinfo[i] of
  2006. 'S' :
  2007. begin
  2008. inc(i);
  2009. case quickinfo[i] of
  2010. 'O' :
  2011. addinfo(lower(source_info.shortname));
  2012. 'P' :
  2013. addinfo(source_cpu_string);
  2014. else
  2015. IllegalPara('-i'+QuickInfo);
  2016. end;
  2017. end;
  2018. 'T' :
  2019. begin
  2020. inc(i);
  2021. case quickinfo[i] of
  2022. 'O' :
  2023. addinfo(lower(target_info.shortname));
  2024. 'P' :
  2025. AddInfo(target_cpu_string);
  2026. else
  2027. IllegalPara('-i'+QuickInfo);
  2028. end;
  2029. end;
  2030. 'V' :
  2031. AddInfo(version_string);
  2032. 'W' :
  2033. AddInfo(full_version_string);
  2034. 'D' :
  2035. AddInfo(date_string);
  2036. '_' :
  2037. ;
  2038. else
  2039. IllegalPara('-i'+QuickInfo);
  2040. end;
  2041. end;
  2042. if s<>'' then
  2043. begin
  2044. writeln(s);
  2045. stopoptions(0);
  2046. end;
  2047. end;
  2048. procedure TOption.TargetOptions(def:boolean);
  2049. var
  2050. s : string;
  2051. i : integer;
  2052. target_unsup_features : tfeatures;
  2053. begin
  2054. if def then
  2055. def_system_macro(target_info.shortname)
  2056. else
  2057. undef_system_macro(target_info.shortname);
  2058. s:=target_info.extradefines;
  2059. while (s<>'') do
  2060. begin
  2061. i:=pos(';',s);
  2062. if i=0 then
  2063. i:=length(s)+1;
  2064. if def then
  2065. def_system_macro(Copy(s,1,i-1))
  2066. else
  2067. undef_system_macro(Copy(s,1,i-1));
  2068. delete(s,1,i);
  2069. end;
  2070. if (tf_winlikewidestring in target_info.flags) then
  2071. if def then
  2072. def_system_macro('FPC_WINLIKEWIDESTRING')
  2073. else
  2074. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2075. if (tf_requires_proper_alignment in target_info.flags) then
  2076. if def then
  2077. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2078. else
  2079. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2080. if source_info.system<>target_info.system then
  2081. if def then
  2082. def_system_macro('FPC_CROSSCOMPILING')
  2083. else
  2084. undef_system_macro('FPC_CROSSCOMPILING');
  2085. if source_info.cpu<>target_info.cpu then
  2086. if def then
  2087. def_system_macro('FPC_CPUCROSSCOMPILING')
  2088. else
  2089. def_system_macro('FPC_CPUCROSSCOMPILING');
  2090. if (tf_no_generic_stackcheck in target_info.flags) then
  2091. if def then
  2092. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2093. else
  2094. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2095. { Code generation flags }
  2096. if def and
  2097. (tf_pic_default in target_info.flags) then
  2098. include(init_settings.moduleswitches,cs_create_pic)
  2099. else
  2100. exclude(init_settings.moduleswitches,cs_create_pic);
  2101. { Resources support }
  2102. if (tf_has_winlike_resources in target_info.flags) then
  2103. if def then
  2104. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2105. else
  2106. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2107. { Features }
  2108. case target_info.system of
  2109. system_arm_gba:
  2110. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2111. system_arm_nds:
  2112. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2113. system_i386_nativent:
  2114. // until these features are implemented, they are disabled in the compiler
  2115. target_unsup_features:=[f_threading,f_processes,f_fileio,f_textio,f_consoleio,f_commandargs,f_stackcheck];
  2116. else
  2117. target_unsup_features:=[];
  2118. end;
  2119. if def then
  2120. features:=features-target_unsup_features
  2121. else
  2122. features:=features+target_unsup_features;
  2123. end;
  2124. procedure TOption.checkoptionscompatibility;
  2125. begin
  2126. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  2127. not(target_info.system in systems_darwin) then
  2128. begin
  2129. { smart linking does not yet work with DWARF debug info on most targets }
  2130. if (cs_link_smart in init_settings.globalswitches) then
  2131. begin
  2132. Message(option_dwarf_smart_linking);
  2133. ForceStaticLinking;
  2134. end;
  2135. end;
  2136. { external debug info is only supported for DWARF on darwin }
  2137. if (target_info.system in systems_darwin) and
  2138. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  2139. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  2140. begin
  2141. Message(option_debug_external_unsupported);
  2142. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  2143. end;
  2144. end;
  2145. constructor TOption.create;
  2146. begin
  2147. LogoWritten:=false;
  2148. NoPressEnter:=false;
  2149. FirstPass:=false;
  2150. FPUSetExplicitly:=false;
  2151. CPUSetExplicitly:=false;
  2152. OptCPUSetExplicitly:=false;
  2153. FileLevel:=0;
  2154. Quickinfo:='';
  2155. ParaIncludePath:=TSearchPathList.Create;
  2156. ParaObjectPath:=TSearchPathList.Create;
  2157. ParaUnitPath:=TSearchPathList.Create;
  2158. ParaLibraryPath:=TSearchPathList.Create;
  2159. ParaFrameworkPath:=TSearchPathList.Create;
  2160. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2161. end;
  2162. destructor TOption.destroy;
  2163. begin
  2164. ParaIncludePath.Free;
  2165. ParaObjectPath.Free;
  2166. ParaUnitPath.Free;
  2167. ParaLibraryPath.Free;
  2168. ParaFrameworkPath.Free;
  2169. end;
  2170. {****************************************************************************
  2171. Callable Routines
  2172. ****************************************************************************}
  2173. function check_configfile(const fn:string;var foundfn:string):boolean;
  2174. function CfgFileExists(const fn:string):boolean;
  2175. begin
  2176. Comment(V_Tried,'Configfile search: '+fn);
  2177. CfgFileExists:=FileExists(fn);
  2178. end;
  2179. var
  2180. {$ifdef Unix}
  2181. hs,
  2182. {$endif Unix}
  2183. configpath : string;
  2184. begin
  2185. foundfn:=fn;
  2186. check_configfile:=true;
  2187. { retrieve configpath }
  2188. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  2189. {$ifdef Unix}
  2190. if configpath='' then
  2191. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  2192. {$endif}
  2193. {
  2194. Order to read configuration file :
  2195. try reading fpc.cfg in :
  2196. 1 - current dir
  2197. 2 - configpath
  2198. 3 - compiler path
  2199. }
  2200. if not FileExists(fn) then
  2201. begin
  2202. {$ifdef Unix}
  2203. hs:=GetEnvironmentVariable('HOME');
  2204. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  2205. foundfn:=FixPath(hs,false)+'.'+fn
  2206. else
  2207. {$endif}
  2208. if CfgFileExists(configpath+fn) then
  2209. foundfn:=configpath+fn
  2210. else
  2211. {$ifndef Unix}
  2212. if CfgFileExists(exepath+fn) then
  2213. foundfn:=exepath+fn
  2214. else
  2215. {$else}
  2216. if CfgFileExists('/etc/'+fn) then
  2217. foundfn:='/etc/'+fn
  2218. else
  2219. {$endif}
  2220. check_configfile:=false;
  2221. end;
  2222. end;
  2223. procedure read_arguments(cmd:string);
  2224. var
  2225. env: ansistring;
  2226. i : tfeature;
  2227. abi : tabi;
  2228. begin
  2229. option:=coption.create;
  2230. disable_configfile:=false;
  2231. { Non-core target defines }
  2232. Option.TargetOptions(true);
  2233. { get default messagefile }
  2234. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  2235. { default configfile can be specified on the commandline,
  2236. remove it first }
  2237. if (cmd<>'') and (cmd[1]='[') then
  2238. begin
  2239. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  2240. Delete(cmd,1,pos(']',cmd));
  2241. end
  2242. else
  2243. ppccfg:='fpc.cfg';
  2244. { first pass reading of parameters, only -i -v -T etc.}
  2245. option.firstpass:=true;
  2246. if cmd<>'' then
  2247. option.parsecmd(cmd)
  2248. else
  2249. begin
  2250. option.read_parameters;
  2251. { Write only quickinfo }
  2252. if option.quickinfo<>'' then
  2253. option.writequickinfo;
  2254. end;
  2255. option.firstpass:=false;
  2256. { target is set here, for wince the default app type is gui }
  2257. if target_info.system in systems_wince then
  2258. apptype:=app_gui;
  2259. { default defines }
  2260. def_system_macro(target_info.shortname);
  2261. def_system_macro('FPC');
  2262. def_system_macro('VER'+version_nr);
  2263. def_system_macro('VER'+version_nr+'_'+release_nr);
  2264. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  2265. { Temporary defines, until things settle down }
  2266. def_system_macro('RESSTRSECTIONS');
  2267. def_system_macro('FPC_HASFIXED64BITVARIANT');
  2268. def_system_macro('FPC_HASINTERNALOLEVARIANT2VARIANTCAST');
  2269. def_system_macro('FPC_HAS_VARSETS');
  2270. def_system_macro('FPC_HAS_VALGRINDBOOL');
  2271. def_system_macro('FPC_HAS_STR_CURRENCY');
  2272. def_system_macro('FPC_REAL2REAL_FIXED');
  2273. def_system_macro('FPC_STRTOCHARARRAYPROC');
  2274. def_system_macro('FPC_STRTOSHORTSTRINGPROC');
  2275. def_system_macro('FPC_OBJFPC_EXTENDED_IF');
  2276. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  2277. {$if defined(x86) or defined(powerpc) or defined(powerpc64)}
  2278. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  2279. {$endif}
  2280. def_system_macro('FPC_HAS_UNICODESTRING');
  2281. def_system_macro('FPC_RTTI_PACKSET1');
  2282. {$ifdef x86_64}
  2283. def_system_macro('FPC_HAS_RIP_RELATIVE');
  2284. {$endif x86_64}
  2285. def_system_macro('FPC_HAS_CEXTENDED');
  2286. { these cpus have an inline rol/ror implementaion }
  2287. {$if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64)}
  2288. def_system_macro('FPC_HAS_INTERNAL_ROX');
  2289. {$endif}
  2290. { these cpus have an inline sar implementaion }
  2291. { currently, all supported CPUs have an internal sar implementation }
  2292. { $if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64) or defined(sparc)}
  2293. def_system_macro('FPC_HAS_INTERNAL_SAR');
  2294. { $endif}
  2295. {$ifdef powerpc64}
  2296. def_system_macro('FPC_HAS_LWSYNC');
  2297. {$endif}
  2298. def_system_macro('FPC_HAS_MEMBAR');
  2299. def_system_macro('FPC_SETBASE_USED');
  2300. {$if defined(x86) or defined(arm)}
  2301. def_system_macro('INTERNAL_BACKTRACE');
  2302. {$endif}
  2303. def_system_macro('STR_CONCAT_PROCS');
  2304. {$warnings off}
  2305. if pocall_default = pocall_register then
  2306. def_system_macro('REGCALL');
  2307. {$warnings on}
  2308. { don't remove this, it's also for fpdoc necessary (FK) }
  2309. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  2310. { using a case is pretty useless here (FK) }
  2311. { some stuff for TP compatibility }
  2312. {$ifdef i386}
  2313. def_system_macro('CPU86');
  2314. def_system_macro('CPU87');
  2315. def_system_macro('CPU386');
  2316. {$endif}
  2317. { new processor stuff }
  2318. {$ifdef i386}
  2319. def_system_macro('CPUI386');
  2320. def_system_macro('CPU32');
  2321. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2322. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2323. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2324. {$endif}
  2325. {$ifdef m68k}
  2326. def_system_macro('CPU68');
  2327. def_system_macro('CPU68K');
  2328. def_system_macro('CPUM68K');
  2329. def_system_macro('CPU32');
  2330. def_system_macro('FPC_CURRENCY_IS_INT64');
  2331. def_system_macro('FPC_COMP_IS_INT64');
  2332. {$endif}
  2333. {$ifdef ALPHA}
  2334. def_system_macro('CPUALPHA');
  2335. def_system_macro('CPU64');
  2336. {$endif}
  2337. {$ifdef powerpc}
  2338. def_system_macro('CPUPOWERPC');
  2339. def_system_macro('CPUPOWERPC32');
  2340. def_system_macro('CPU32');
  2341. def_system_macro('FPC_CURRENCY_IS_INT64');
  2342. def_system_macro('FPC_COMP_IS_INT64');
  2343. {$endif}
  2344. {$ifdef POWERPC64}
  2345. def_system_macro('CPUPOWERPC');
  2346. def_system_macro('CPUPOWERPC64');
  2347. def_system_macro('CPU64');
  2348. def_system_macro('FPC_CURRENCY_IS_INT64');
  2349. def_system_macro('FPC_COMP_IS_INT64');
  2350. {$endif}
  2351. {$ifdef iA64}
  2352. def_system_macro('CPUIA64');
  2353. def_system_macro('CPU64');
  2354. {$endif}
  2355. {$ifdef x86_64}
  2356. def_system_macro('CPUX86_64');
  2357. def_system_macro('CPUAMD64');
  2358. def_system_macro('CPU64');
  2359. { not supported for now, afaik (FK)
  2360. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  2361. { win64 doesn't support the legacy fpu }
  2362. if target_info.system=system_x86_64_win64 then
  2363. begin
  2364. def_system_macro('FPC_CURRENCY_IS_INT64');
  2365. def_system_macro('FPC_COMP_IS_INT64');
  2366. end;
  2367. {$endif}
  2368. {$ifdef sparc}
  2369. def_system_macro('CPUSPARC');
  2370. def_system_macro('CPUSPARC32');
  2371. def_system_macro('CPU32');
  2372. def_system_macro('FPC_CURRENCY_IS_INT64');
  2373. def_system_macro('FPC_COMP_IS_INT64');
  2374. {$endif}
  2375. {$ifdef vis}
  2376. def_system_macro('CPUVIS');
  2377. def_system_macro('CPU32');
  2378. {$endif}
  2379. {$ifdef arm}
  2380. def_system_macro('CPUARM');
  2381. def_system_macro('CPU32');
  2382. def_system_macro('FPC_CURRENCY_IS_INT64');
  2383. def_system_macro('FPC_COMP_IS_INT64');
  2384. {$endif arm}
  2385. {$ifdef avr}
  2386. def_system_macro('CPUAVR');
  2387. def_system_macro('CPU16');
  2388. def_system_macro('FPC_CURRENCY_IS_INT64');
  2389. def_system_macro('FPC_COMP_IS_INT64');
  2390. {$endif avr}
  2391. { read configuration file }
  2392. if (not disable_configfile) and
  2393. (ppccfg<>'') then
  2394. read_configfile:=check_configfile(ppccfg,ppccfg)
  2395. else
  2396. read_configfile := false;
  2397. { Read commandline and configfile }
  2398. param_file:='';
  2399. { read configfile }
  2400. if read_configfile then
  2401. option.interpret_file(ppccfg);
  2402. { read parameters again to override config file }
  2403. if cmd<>'' then
  2404. option.parsecmd(cmd)
  2405. else
  2406. begin
  2407. { Write help pages if no parameters are passed }
  2408. if (paramcount=0) then
  2409. Option.WriteHelpPages;
  2410. option.read_parameters;
  2411. { Write only quickinfo }
  2412. if option.quickinfo<>'' then
  2413. option.writequickinfo;
  2414. end;
  2415. { check the compatibility of different options and adjust them if necessary
  2416. (and print possible errors)
  2417. }
  2418. option.checkoptionscompatibility;
  2419. { Stop if errors in options }
  2420. if ErrorCount>0 then
  2421. StopOptions(1);
  2422. { endian define }
  2423. case target_info.endian of
  2424. endian_little :
  2425. begin
  2426. def_system_macro('ENDIAN_LITTLE');
  2427. def_system_macro('FPC_LITTLE_ENDIAN');
  2428. end;
  2429. endian_big :
  2430. begin
  2431. def_system_macro('ENDIAN_BIG');
  2432. def_system_macro('FPC_BIG_ENDIAN');
  2433. end;
  2434. end;
  2435. { define abi }
  2436. for abi:=low(tabi) to high(tabi) do
  2437. undef_system_macro('FPC_ABI_'+abi2str[abi]);
  2438. def_system_macro('FPC_ABI_'+abi2str[target_info.abi]);
  2439. { Write logo }
  2440. if option.ParaLogo then
  2441. option.writelogo;
  2442. { Check file to compile }
  2443. if param_file='' then
  2444. begin
  2445. Message(option_no_source_found);
  2446. StopOptions(1);
  2447. end;
  2448. {$ifndef Unix}
  2449. param_file:=FixFileName(param_file);
  2450. {$endif not unix}
  2451. inputfilepath:=ExtractFilePath(param_file);
  2452. inputfilename:=ExtractFileName(param_file);
  2453. if ExtractFileExt(inputfilename)='' then
  2454. begin
  2455. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  2456. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  2457. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  2458. inputfilename:=ChangeFileExt(inputfilename,pasext)
  2459. else if ((m_mac in current_settings.modeswitches) or
  2460. (tf_p_ext_support in target_info.flags))
  2461. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  2462. inputfilename:=ChangeFileExt(inputfilename,pext);
  2463. end;
  2464. { Check output dir }
  2465. if (OutputExeDir<>'') and
  2466. not PathExists(OutputExeDir,false) then
  2467. begin
  2468. Message1(general_e_path_does_not_exist,OutputExeDir);
  2469. StopOptions(1);
  2470. end;
  2471. { Add paths specified with parameters to the searchpaths }
  2472. UnitSearchPath.AddList(option.ParaUnitPath,true);
  2473. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  2474. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  2475. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  2476. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  2477. { add unit environment and exepath to the unit search path }
  2478. if inputfilepath<>'' then
  2479. Unitsearchpath.AddPath(inputfilepath,true);
  2480. if not disable_configfile then
  2481. begin
  2482. env:=GetEnvironmentVariable(target_info.unit_env);
  2483. if env<>'' then
  2484. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  2485. end;
  2486. {$ifdef Unix}
  2487. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2488. if fpcdir='' then
  2489. begin
  2490. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  2491. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  2492. else
  2493. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  2494. end;
  2495. {$else unix}
  2496. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  2497. if fpcdir='' then
  2498. begin
  2499. fpcdir:=ExePath+'../';
  2500. if not(PathExists(fpcdir+'units',true)) and
  2501. not(PathExists(fpcdir+'rtl',true)) then
  2502. fpcdir:=fpcdir+'../';
  2503. end;
  2504. {$endif unix}
  2505. { first try development RTL, else use the default installation path }
  2506. if not disable_configfile then
  2507. begin
  2508. if PathExists(FpcDir+'rtl',true) then
  2509. if tf_use_8_3 in Source_Info.Flags then
  2510. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  2511. else
  2512. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  2513. else
  2514. if tf_use_8_3 in Source_Info.Flags then
  2515. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  2516. else
  2517. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  2518. end;
  2519. { Add exepath if the exe is not in the current dir, because that is always searched already.
  2520. Do not add it when linking on the target because then we can maybe already find
  2521. .o files that are not for the target }
  2522. if (ExePath<>GetCurrentDir) and
  2523. not(cs_link_on_target in init_settings.globalswitches) then
  2524. UnitSearchPath.AddPath(ExePath,false);
  2525. { Add unit dir to the object and library path }
  2526. objectsearchpath.AddList(unitsearchpath,false);
  2527. librarysearchpath.AddList(unitsearchpath,false);
  2528. { maybe override assembler }
  2529. if (paratargetasm<>as_none) then
  2530. begin
  2531. if not set_target_asm(paratargetasm) then
  2532. begin
  2533. Message2(option_incompatible_asm,asminfos[paratargetasm]^.idtxt,target_info.name);
  2534. set_target_asm(target_info.assemextern);
  2535. Message1(option_asm_forced,target_asm.idtxt);
  2536. end;
  2537. if (af_no_debug in asminfos[paratargetasm]^.flags) and
  2538. (paratargetdbg<>dbg_none) then
  2539. begin
  2540. Message1(option_confict_asm_debug,
  2541. asminfos[paratargetasm]^.idtxt);
  2542. paratargetdbg:=dbg_none;
  2543. exclude(init_settings.moduleswitches,cs_debuginfo);
  2544. end;
  2545. end;
  2546. { maybe override debug info format }
  2547. if (paratargetdbg<>dbg_none) then
  2548. set_target_dbg(paratargetdbg);
  2549. { switch assembler if it's binary and we got -a on the cmdline }
  2550. if (cs_asm_leave in init_settings.globalswitches) and
  2551. (af_outputbinary in target_asm.flags) then
  2552. begin
  2553. Message(option_switch_bin_to_src_assembler);
  2554. set_target_asm(target_info.assemextern);
  2555. end;
  2556. { Force use of external linker if there is no
  2557. internal linker or the linking is skipped }
  2558. if not(cs_link_extern in init_settings.globalswitches) and
  2559. (not assigned(target_info.link) or
  2560. (cs_link_nolink in init_settings.globalswitches)) then
  2561. include(init_settings.globalswitches,cs_link_extern);
  2562. { turn off stripping if compiling with debuginfo or profile }
  2563. if (
  2564. (cs_debuginfo in init_settings.moduleswitches) or
  2565. (cs_profile in init_settings.moduleswitches)
  2566. ) and
  2567. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  2568. exclude(init_settings.globalswitches,cs_link_strip);
  2569. { force fpu emulation on arm/wince, arm/gba, arm/embedded, arm/nds and
  2570. arm/darwin if fpu type not explicitly set }
  2571. if not(option.FPUSetExplicitly) and
  2572. ((target_info.system in [system_arm_wince,system_arm_gba,system_m68k_amiga,
  2573. system_m68k_linux,system_arm_nds,system_arm_embedded,system_arm_darwin])
  2574. {$ifdef arm}
  2575. or (target_info.abi=abi_eabi)
  2576. {$endif arm}
  2577. )
  2578. {$ifdef arm}
  2579. or (init_settings.fputype=fpu_soft)
  2580. {$endif arm}
  2581. then
  2582. begin
  2583. {$ifdef cpufpemu}
  2584. include(init_settings.moduleswitches,cs_fp_emulation);
  2585. { cs_fp_emulation and fpu_soft are equal on arm }
  2586. init_settings.fputype:=fpu_soft;
  2587. {$endif cpufpemu}
  2588. end;
  2589. {$ifdef arm}
  2590. { set default cpu type to ARMv6 for Darwin unless specified otherwise }
  2591. if (target_info.system=system_arm_darwin) then
  2592. begin
  2593. if not option.CPUSetExplicitly then
  2594. init_settings.cputype:=cpu_armv6;
  2595. if not option.OptCPUSetExplicitly then
  2596. init_settings.optimizecputype:=cpu_armv6;
  2597. end;
  2598. {$endif arm}
  2599. { now we can define cpu and fpu type }
  2600. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  2601. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  2602. if init_settings.fputype<>fpu_none then
  2603. begin
  2604. {$if defined(i386)}
  2605. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2606. {$endif}
  2607. def_system_macro('FPC_HAS_TYPE_SINGLE');
  2608. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  2609. {$if not defined(i386) and not defined(x86_64)}
  2610. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  2611. {$endif}
  2612. {$ifdef x86_64}
  2613. { win64 doesn't support the legacy fpu }
  2614. if target_info.system=system_x86_64_win64 then
  2615. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  2616. else
  2617. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  2618. {$endif}
  2619. end;
  2620. {$ifdef ARM}
  2621. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  2622. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  2623. not(cs_fp_emulation in init_settings.moduleswitches) then
  2624. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  2625. {$endif ARM}
  2626. { Section smartlinking conflicts with import sections on Windows }
  2627. if GenerateImportSection and
  2628. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  2629. exclude(target_info.flags,tf_smartlink_sections);
  2630. if not LinkTypeSetExplicitly then
  2631. set_default_link_type;
  2632. { Default alignment settings,
  2633. 1. load the defaults for the target
  2634. 2. override with generic optimizer setting (little size)
  2635. 3. override with the user specified -Oa }
  2636. UpdateAlignment(init_settings.alignment,target_info.alignment);
  2637. if (cs_opt_size in current_settings.optimizerswitches) then
  2638. begin
  2639. init_settings.alignment.procalign:=1;
  2640. init_settings.alignment.jumpalign:=1;
  2641. init_settings.alignment.loopalign:=1;
  2642. end;
  2643. UpdateAlignment(init_settings.alignment,option.paraalignment);
  2644. set_system_macro('FPC_VERSION',version_nr);
  2645. set_system_macro('FPC_RELEASE',release_nr);
  2646. set_system_macro('FPC_PATCH',patch_nr);
  2647. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  2648. if not(target_info.system in systems_windows) then
  2649. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  2650. for i:=low(tfeature) to high(tfeature) do
  2651. if i in features then
  2652. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  2653. option.free;
  2654. Option:=nil;
  2655. end;
  2656. initialization
  2657. coption:=toption;
  2658. finalization
  2659. if assigned(option) then
  2660. option.free;
  2661. end.