options.pas 110 KB

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