options.pas 118 KB

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