options.pas 121 KB

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