options.pas 108 KB

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