options.pas 165 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847
  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,cclasses,
  22. globtype,globals,verbose,systems,cpuinfo,comprsrc;
  23. Type
  24. TOption=class
  25. FirstPass,
  26. ParaLogo,
  27. NoPressEnter,
  28. FPCHelpLines,
  29. LogoWritten,
  30. ABISetExplicitly,
  31. FPUSetExplicitly,
  32. CPUSetExplicitly,
  33. OptCPUSetExplicitly: boolean;
  34. FileLevel : longint;
  35. QuickInfo : string;
  36. FPCBinaryPath: string;
  37. ParaIncludeCfgPath,
  38. ParaIncludePath,
  39. ParaUnitPath,
  40. ParaObjectPath,
  41. ParaLibraryPath,
  42. ParaFrameworkPath,
  43. parapackagepath : TSearchPathList;
  44. paranamespaces : TCmdStrList;
  45. ParaAlignment : TAlignmentInfo;
  46. parapackages : tfphashobjectlist;
  47. paratarget : tsystem;
  48. paratargetasm : tasm;
  49. paratargetdbg : tdbg;
  50. LinkTypeSetExplicitly : boolean;
  51. LinkerSetExplicitly : boolean;
  52. Constructor Create;
  53. Destructor Destroy;override;
  54. procedure WriteLogo;
  55. procedure WriteInfo (More: string);
  56. procedure WriteHelpPages;
  57. procedure WriteQuickInfo;
  58. procedure IllegalPara(const opt:TCmdStr);
  59. procedure UnsupportedPara(const opt:TCmdStr);
  60. procedure IgnoredPara(const opt:TCmdStr);
  61. function Unsetbool(var Opts:TCmdStr; Pos: Longint; const FullPara: TCmdStr; RequireBoolPara: Boolean):boolean;
  62. procedure interpret_option(const opt :TCmdStr;ispara:boolean);
  63. procedure Interpret_envvar(const envname : TCmdStr);
  64. procedure Interpret_file(const filename : TPathStr);
  65. procedure Read_Parameters;
  66. procedure parsecmd(cmd:TCmdStr);
  67. procedure TargetOptions(def:boolean);
  68. procedure CheckOptionsCompatibility;
  69. procedure ForceStaticLinking;
  70. protected
  71. MacVersionSet: boolean;
  72. processorstr: TCmdStr;
  73. function ParseMacVersionMin(out minstr, emptystr: string; const compvarname, value: string; ios: boolean): boolean;
  74. procedure MaybeSetDefaultMacVersionMacro;
  75. procedure VerifyTargetProcessor;
  76. end;
  77. TOptionClass=class of toption;
  78. var
  79. coption : TOptionClass;
  80. procedure read_arguments(cmd:TCmdStr);
  81. implementation
  82. uses
  83. widestr,
  84. {$if FPC_FULLVERSION<20700}ccharset{$else}charset{$endif},
  85. SysUtils,
  86. version,
  87. cutils,cmsgs,
  88. comphook,
  89. symtable,scanner,rabase,
  90. symconst,
  91. {$ifdef llvm}
  92. { override supported optimizer transformations at the compiler level }
  93. llvminfo,
  94. {$endif llvm}
  95. dirparse,
  96. pkgutil;
  97. const
  98. page_size = 24;
  99. page_width = 80;
  100. var
  101. option : toption;
  102. read_configfile, { read config file, set when a cfgfile is found }
  103. disable_configfile : boolean;
  104. fpcdir,
  105. ppccfg,
  106. param_file : string; { file to compile specified on the commandline }
  107. {****************************************************************************
  108. Options not supported on all platforms
  109. ****************************************************************************}
  110. const
  111. { gprof (requires implementation of g_profilecode in the code generator) }
  112. supported_targets_pg = [system_i386_linux,system_x86_64_linux,system_mipseb_linux,system_mipsel_linux,system_arm_linux]
  113. + [system_i386_win32]
  114. + [system_powerpc_darwin,system_x86_64_darwin]
  115. + [system_i386_GO32V2]
  116. + [system_i386_freebsd]
  117. + [system_i386_netbsd]
  118. + [system_i386_wdosx]
  119. + [system_riscv32_linux,system_riscv64_linux]
  120. + [system_aarch64_linux];
  121. suppported_targets_x_smallr = systems_linux + systems_solaris + systems_android
  122. + [system_i386_haiku,system_x86_64_haiku]
  123. + [system_i386_beos]
  124. + [system_m68k_amiga];
  125. {****************************************************************************
  126. Defines
  127. ****************************************************************************}
  128. procedure set_default_link_type;
  129. begin
  130. undef_system_macro('FPC_LINK_SMART');
  131. def_system_macro('FPC_LINK_STATIC');
  132. undef_system_macro('FPC_LINK_DYNAMIC');
  133. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_static];
  134. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_shared,cs_link_smart];
  135. {$ifdef AIX}
  136. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_native];
  137. {$endif}
  138. end;
  139. {****************************************************************************
  140. Toption
  141. ****************************************************************************}
  142. procedure StopOptions(err:longint);
  143. begin
  144. if assigned(Option) then
  145. begin
  146. Option.free;
  147. Option:=nil;
  148. end;
  149. raise ECompilerAbortSilent.Create;
  150. end;
  151. function is_identifier(const s: TCmdStr): boolean;
  152. var
  153. i: longint;
  154. begin
  155. result:=false;
  156. if (s='') or not (s[1] in ['A'..'Z','a'..'z','_']) then
  157. exit;
  158. for i:=2 to length(s) do
  159. if not (s[I] in ['A'..'Z','a'..'z','0'..'9','_']) then
  160. exit;
  161. result:=true;
  162. end;
  163. procedure Toption.WriteLogo;
  164. var
  165. msg : TMsgStr;
  166. p : pchar;
  167. begin
  168. if not LogoWritten then
  169. begin
  170. msg:=MessageStr(option_logo);
  171. p:=pchar(msg);
  172. while assigned(p) do
  173. Comment(V_Normal,GetMsgLine(p));
  174. LogoWritten:= true;
  175. end;
  176. end;
  177. procedure Toption.WriteInfo (More: string);
  178. var
  179. msg_str: TMsgStr;
  180. p : pchar;
  181. hs,hs1,hs3,s : TCmdStr;
  182. J: longint;
  183. const
  184. NewLineStr = '$\n';
  185. OSTargetsPlaceholder = '$OSTARGETS';
  186. CPUListPlaceholder = '$INSTRUCTIONSETS';
  187. FPUListPlaceholder = '$FPUINSTRUCTIONSETS';
  188. ABIListPlaceholder = '$ABITARGETS';
  189. OptListPlaceholder = '$OPTIMIZATIONS';
  190. WPOListPlaceholder = '$WPOPTIMIZATIONS';
  191. AsmModeListPlaceholder = '$ASMMODES';
  192. ControllerListPlaceholder = '$CONTROLLERTYPES';
  193. FeatureListPlaceholder = '$FEATURELIST';
  194. ModeSwitchListPlaceholder = '$MODESWITCHES';
  195. CodeGenerationBackendPlaceholder = '$CODEGENERATIONBACKEND';
  196. procedure SplitLine (var OrigString: TCmdStr; const Placeholder: TCmdStr;
  197. out RemainderString: TCmdStr);
  198. var
  199. I: longint;
  200. HS2: TCmdStr;
  201. begin
  202. RemainderString := '';
  203. if OrigString = '' then
  204. Exit;
  205. repeat
  206. I := Pos (NewLineStr, OrigString);
  207. if I > 0 then
  208. begin
  209. HS2 := Copy (OrigString, 1, Pred (I));
  210. { Stop if this line contains the placeholder for list replacement }
  211. if Pos (Placeholder, HS2) > 0 then
  212. begin
  213. RemainderString := Copy (OrigString, I + Length (NewLineStr),
  214. Length (OrigString) - I - Length (NewLineStr));
  215. { Special case - NewLineStr at the end of the line }
  216. if RemainderString = '' then
  217. RemainderString := NewLineStr;
  218. OrigString := HS2;
  219. Exit;
  220. end;
  221. Comment (V_Normal, HS2);
  222. Delete (OrigString, 1, Pred (I) + Length (NewLineStr));
  223. end;
  224. until I = 0;
  225. if (OrigString <> '') and (Pos (Placeholder, OrigString) = 0) then
  226. Comment (V_Normal, OrigString);
  227. end;
  228. procedure ListOSTargets (OrigString: TCmdStr);
  229. var
  230. target : tsystem;
  231. begin
  232. SplitLine (OrigString, OSTargetsPlaceholder, HS3);
  233. for target:=low(tsystem) to high(tsystem) do
  234. if assigned(targetinfos[target]) then
  235. begin
  236. hs1:=targetinfos[target]^.shortname;
  237. if OrigString = '' then
  238. Comment (V_Normal, hs1)
  239. else
  240. begin
  241. hs := OrigString;
  242. hs1:=hs1 + ': ' + targetinfos[target]^.name;
  243. if tf_under_development in targetinfos[target]^.flags then
  244. hs1:=hs1+' {*}';
  245. Replace(hs,OSTargetsPlaceholder,hs1);
  246. Comment(V_Normal,hs);
  247. end;
  248. end;
  249. end;
  250. procedure ListCPUInstructionSets (OrigString: TCmdStr);
  251. var
  252. cpu : tcputype;
  253. begin
  254. SplitLine (OrigString, CPUListPlaceholder, HS3);
  255. hs1:='';
  256. for cpu:=low(tcputype) to high(tcputype) do
  257. begin
  258. if (OrigString = '') then
  259. begin
  260. if CPUTypeStr [CPU] <> '' then
  261. Comment (V_Normal, CPUTypeStr [CPU]);
  262. end
  263. else
  264. begin
  265. if length(hs1+cputypestr[cpu])>70 then
  266. begin
  267. hs:=OrigString;
  268. HS1 := HS1 + ',';
  269. Replace(hs,CPUListPlaceholder,hs1);
  270. Comment(V_Normal,hs);
  271. hs1:=''
  272. end
  273. else if hs1<>'' then
  274. hs1:=hs1+',';
  275. if cputypestr[cpu]<>'' then
  276. hs1:=hs1+cputypestr[cpu];
  277. end;
  278. end;
  279. if (OrigString <> '') and (hs1 <> '') then
  280. begin
  281. hs:=OrigString;
  282. Replace(hs,CPUListPlaceholder,hs1);
  283. Comment(V_Normal,hs);
  284. hs1:=''
  285. end;
  286. end;
  287. procedure ListFPUInstructionSets (OrigString: TCmdStr);
  288. var
  289. fpu : tfputype;
  290. begin
  291. SplitLine (OrigString, FPUListPlaceholder, HS3);
  292. hs1:='';
  293. for fpu:=low(tfputype) to high(tfputype) do
  294. begin
  295. if (OrigString = '') then
  296. begin
  297. if FPUTypeStr [FPU] <> '' then
  298. Comment (V_Normal, FPUTypeStr [FPU]);
  299. end
  300. else
  301. begin
  302. if length(hs1+fputypestr[fpu])>70 then
  303. begin
  304. hs:=OrigString;
  305. HS1 := HS1 + ',';
  306. Replace(hs,FPUListPlaceholder,hs1);
  307. Comment(V_Normal,hs);
  308. hs1:=''
  309. end
  310. else if hs1<>'' then
  311. hs1:=hs1+',';
  312. if fputypestr[fpu]<>'' then
  313. hs1:=hs1+fputypestr[fpu];
  314. end;
  315. end;
  316. if (OrigString <> '') and (hs1 <> '') then
  317. begin
  318. hs:=OrigString;
  319. Replace(hs,FPUListPlaceholder,hs1);
  320. Comment(V_Normal,hs);
  321. hs1:=''
  322. end;
  323. end;
  324. procedure ListABITargets (OrigString: TCmdStr);
  325. var
  326. abi : tabi;
  327. begin
  328. SplitLine (OrigString, ABIListPlaceholder, HS3);
  329. for abi:=low(abi) to high(abi) do
  330. begin
  331. if not abiinfo[abi].supported then
  332. continue;
  333. hs1:=abiinfo[abi].name;
  334. if hs1<>'' then
  335. begin
  336. if OrigString = '' then
  337. Comment (V_Normal, HS1)
  338. else
  339. begin
  340. hs:=OrigString;
  341. Replace(hs,ABIListPlaceholder,hs1);
  342. Comment(V_Normal,hs);
  343. end;
  344. end;
  345. end;
  346. end;
  347. procedure ListOptimizations (OrigString: TCmdStr);
  348. var
  349. opt : toptimizerswitch;
  350. begin
  351. SplitLine (OrigString, OptListPlaceholder, HS3);
  352. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  353. begin
  354. if opt in supported_optimizerswitches then
  355. begin
  356. hs1:=OptimizerSwitchStr[opt];
  357. if hs1<>'' then
  358. begin
  359. if OrigString = '' then
  360. Comment (V_Normal, hs1)
  361. else
  362. begin
  363. hs:=OrigString;
  364. Replace(hs,OptListPlaceholder,hs1);
  365. Comment(V_Normal,hs);
  366. end;
  367. end;
  368. end;
  369. end;
  370. end;
  371. procedure ListWPOptimizations (OrigString: TCmdStr);
  372. var
  373. wpopt: twpoptimizerswitch;
  374. begin
  375. SplitLine (OrigString, WPOListPlaceholder, HS3);
  376. for wpopt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  377. begin
  378. { currently all whole program optimizations are platform-independent
  379. if opt in supported_wpoptimizerswitches then
  380. }
  381. begin
  382. hs1:=WPOptimizerSwitchStr[wpopt];
  383. if hs1<>'' then
  384. begin
  385. if OrigString = '' then
  386. Comment (V_Normal, hs1)
  387. else
  388. begin
  389. hs:=OrigString;
  390. Replace(hs,WPOListPlaceholder,hs1);
  391. Comment(V_Normal,hs);
  392. end;
  393. end;
  394. end;
  395. end;
  396. end;
  397. procedure ListAsmModes (OrigString: TCmdStr);
  398. var
  399. asmmode : tasmmode;
  400. begin
  401. SplitLine (OrigString, AsmModeListPlaceholder, HS3);
  402. for asmmode:=low(tasmmode) to high(tasmmode) do
  403. if assigned(asmmodeinfos[asmmode]) then
  404. begin
  405. hs1:=asmmodeinfos[asmmode]^.idtxt;
  406. if hs1<>'' then
  407. begin
  408. if OrigString = '' then
  409. Comment (V_Normal, hs1)
  410. else
  411. begin
  412. hs:=OrigString;
  413. Replace(hs,AsmModeListPlaceholder,hs1);
  414. Comment(V_Normal,hs);
  415. end;
  416. end;
  417. end;
  418. end;
  419. procedure ListControllerTypes (OrigString: TCmdStr);
  420. var
  421. controllertype : tcontrollertype;
  422. begin
  423. {$PUSH}
  424. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  425. if (ControllerSupport) then
  426. begin
  427. SplitLine (OrigString, ControllerListPlaceholder, HS3);
  428. hs1:='';
  429. for controllertype:=low(tcontrollertype) to high(tcontrollertype) do
  430. begin
  431. if (OrigString = '') then
  432. begin
  433. if Embedded_Controllers [ControllerType].ControllerTypeStr <> '' then
  434. Comment (V_Normal, Embedded_Controllers [ControllerType].ControllerTypeStr);
  435. end
  436. else
  437. begin
  438. if length(hs1+embedded_controllers[controllertype].ControllerTypeStr)
  439. >70 then
  440. begin
  441. hs:=OrigString;
  442. HS1 := HS1 + ',';
  443. Replace(hs,ControllerListPlaceholder,hs1);
  444. Comment(V_Normal,hs);
  445. hs1:=''
  446. end
  447. else if hs1<>'' then
  448. hs1:=hs1+',';
  449. if embedded_controllers[controllertype].ControllerTypeStr<>'' then
  450. hs1:=hs1+embedded_controllers[controllertype].ControllerTypeStr;
  451. end;
  452. end;
  453. if (OrigString <> '') and (hs1<>'') then
  454. begin
  455. hs:=OrigString;
  456. Replace(hs,ControllerListPlaceholder,hs1);
  457. Comment(V_Normal,hs);
  458. hs1:=''
  459. end;
  460. end;
  461. {$POP}
  462. end;
  463. procedure ListFeatures (OrigString: TCmdStr);
  464. var
  465. Feature: TFeature;
  466. begin
  467. SplitLine (OrigString, FeatureListPlaceholder, HS3);
  468. HS1 := '';
  469. for Feature := Low (TFeature) to High (TFeature) do
  470. begin
  471. if (OrigString = '') then
  472. begin
  473. if FeatureStr [Feature] <> '' then
  474. Comment (V_Normal, FeatureStr [Feature]);
  475. end
  476. else
  477. begin
  478. if Length (HS1 + FeatureStr [Feature]) > 70 then
  479. begin
  480. HS := OrigString;
  481. HS1 := HS1 + ',';
  482. Replace (HS, FeatureListPlaceholder, HS1);
  483. Comment (V_Normal, HS);
  484. HS1 := ''
  485. end
  486. else if HS1 <> '' then
  487. HS1 := HS1 + ',';
  488. if FeatureStr [Feature] <> '' then
  489. HS1 := HS1 + FeatureStr [Feature];
  490. end;
  491. end;
  492. if (OrigString <> '') and (HS1 <> '') then
  493. begin
  494. HS := OrigString;
  495. Replace (HS, FeatureListPlaceholder, HS1);
  496. Comment (V_Normal, HS);
  497. HS1 := ''
  498. end;
  499. end;
  500. procedure ListModeswitches (OrigString: TCmdStr);
  501. var
  502. Modeswitch: TModeswitch;
  503. begin
  504. SplitLine (OrigString, ModeswitchListPlaceholder, HS3);
  505. HS1 := '';
  506. for Modeswitch := Low (TModeswitch) to High (TModeswitch) do
  507. begin
  508. if (OrigString = '') then
  509. begin
  510. if ModeswitchStr [Modeswitch] <> '' then
  511. Comment (V_Normal, ModeswitchStr [Modeswitch]);
  512. end
  513. else
  514. begin
  515. if Length (HS1 + ModeswitchStr [Modeswitch]) > 60 then
  516. begin
  517. HS := OrigString;
  518. HS1 := HS1 + ',';
  519. Replace (HS, ModeswitchListPlaceholder, HS1);
  520. Comment (V_Normal, HS);
  521. HS1 := ''
  522. end
  523. else if HS1 <> '' then
  524. HS1 := HS1 + ',';
  525. if ModeswitchStr [Modeswitch] <> '' then
  526. HS1 := HS1 + ModeswitchStr [Modeswitch];
  527. end;
  528. end;
  529. if (OrigString <> '') and (HS1 <> '') then
  530. begin
  531. HS := OrigString;
  532. Replace (HS, ModeswitchListPlaceholder, HS1);
  533. Comment (V_Normal, HS);
  534. HS1 := ''
  535. end;
  536. end;
  537. procedure ListCodeGenerationBackend (OrigString: TCmdStr);
  538. begin
  539. SplitLine (OrigString, CodeGenerationBackendPlaceholder, HS3);
  540. hs1:=cgbackend2str[cgbackend];
  541. if OrigString = '' then
  542. Comment (V_Normal, hs1)
  543. else
  544. begin
  545. hs:=OrigString;
  546. Replace(hs,CodeGenerationBackendPlaceholder,hs1);
  547. Comment(V_Normal,hs);
  548. end;
  549. end;
  550. begin
  551. if More = '' then
  552. begin
  553. msg_str:=MessageStr(option_info);
  554. p:=pchar(msg_str);
  555. while assigned(p) do
  556. begin
  557. s:=GetMsgLine(p);
  558. { list permitted values for certain options }
  559. if pos(OSTargetsPlaceholder,s)>0 then
  560. ListOSTargets (S)
  561. else if pos(CPUListPlaceholder,s)>0 then
  562. ListCPUInstructionSets (S)
  563. else if pos(FPUListPlaceholder,s)>0 then
  564. ListFPUInstructionSets (S)
  565. else if pos(ABIListPlaceholder,s)>0 then
  566. ListABITargets (S)
  567. else if pos(OptListPlaceholder,s)>0 then
  568. ListOptimizations (S)
  569. else if pos(WPOListPlaceholder,s)>0 then
  570. ListWPOptimizations (S)
  571. else if Pos (ModeswitchListPlaceholder, S) > 0 then
  572. ListModeswitches (S)
  573. else if pos(AsmModeListPlaceholder,s)>0 then
  574. ListAsmModes (S)
  575. else if pos(ControllerListPlaceholder,s)>0 then
  576. ListControllerTypes (S)
  577. else if pos(FeatureListPlaceholder,s)>0 then
  578. ListFeatures (S)
  579. else if pos(CodeGenerationBackendPlaceholder,s)>0 then
  580. ListCodeGenerationBackend (S)
  581. else
  582. Comment(V_Normal,s);
  583. end;
  584. end
  585. else
  586. begin
  587. J := 1;
  588. while J <= Length (More) do
  589. begin
  590. if J > 1 then
  591. Comment(V_Normal,''); (* Put empty line between multiple sections *)
  592. case More [J] of
  593. 'a': ListABITargets ('');
  594. 'b': Comment(V_Normal, cgbackend2str[cgbackend]);
  595. 'c': ListCPUInstructionSets ('');
  596. 'f': ListFPUInstructionSets ('');
  597. 'i': ListAsmModes ('');
  598. 'm': ListModeswitches ('');
  599. 'o': ListOptimizations ('');
  600. 'r': ListFeatures ('');
  601. 't': ListOSTargets ('');
  602. 'u': ListControllerTypes ('');
  603. 'w': ListWPOptimizations ('');
  604. else
  605. IllegalPara ('-i' + More);
  606. end;
  607. Inc (J);
  608. end;
  609. end;
  610. StopOptions(0);
  611. end;
  612. procedure Toption.WriteHelpPages;
  613. function PadEnd(s:string;i:longint):string;
  614. begin
  615. if length(s) >= i then
  616. S := S + ' '
  617. else
  618. while (length(s)<i) do
  619. s:=s+' ';
  620. PadEnd:=s;
  621. end;
  622. var
  623. lastident,
  624. j,outline,
  625. ident,
  626. HelpLineHeight,
  627. lines : longint;
  628. show : boolean;
  629. opt : string[32];
  630. input,
  631. HelpLine,
  632. s : string;
  633. p : pchar;
  634. msg_str: TMsgStr;
  635. begin
  636. WriteLogo;
  637. Lines:=4;
  638. if FPCHelpLines then
  639. Message1(option_usage,FixFileName(FPCBinaryPath))
  640. else
  641. Message1(option_usage,FixFileName(system.paramstr(0)));
  642. lastident:=0;
  643. msg_str:=MessageStr(option_help_pages);
  644. p:=pchar(msg_str);
  645. while assigned(p) do
  646. begin
  647. { get a line and reset }
  648. s:=GetMsgLine(p);
  649. ident:=0;
  650. show:=false;
  651. { parse options }
  652. case s[1] of
  653. 'F': if FPCHelpLines then
  654. Show := true;
  655. {$ifdef UNITALIASES}
  656. 'a',
  657. {$endif}
  658. {$ifdef EXTDEBUG}
  659. 'e',
  660. {$endif EXTDEBUG}
  661. {$ifdef i386}
  662. '3',
  663. {$endif}
  664. {$ifdef x86_64}
  665. '4',
  666. {$endif}
  667. {$ifdef m68k}
  668. '6',
  669. {$endif}
  670. {$ifdef i8086}
  671. '8',
  672. {$endif}
  673. {$ifdef aarch64}
  674. 'a',
  675. {$endif}
  676. {$ifdef arm}
  677. 'A',
  678. {$endif}
  679. {$ifdef mipsel}
  680. 'm',
  681. {$endif}
  682. {$ifdef mipseb}
  683. 'M',
  684. {$endif}
  685. {$ifdef powerpc}
  686. 'P',
  687. {$endif}
  688. {$ifdef powerpc64}
  689. 'p',
  690. {$endif}
  691. {$ifdef sparc}
  692. 'S',
  693. {$endif}
  694. {$ifdef sparc64}
  695. 's',
  696. {$endif}
  697. {$ifdef riscv32}
  698. 'R',
  699. {$endif}
  700. {$ifdef riscv64}
  701. 'r',
  702. {$endif}
  703. {$ifdef avr}
  704. 'V',
  705. {$endif}
  706. {$ifdef jvm}
  707. 'J',
  708. {$endif}
  709. {$ifdef llvm}
  710. 'L',
  711. {$endif}
  712. {$ifdef xtensa}
  713. 'x',
  714. {$endif}
  715. {$ifdef z80}
  716. 'Z',
  717. {$endif}
  718. '*' : show:=true;
  719. end;
  720. if show then
  721. begin
  722. case s[2] of
  723. 'g',
  724. {$ifdef Unix}
  725. 'L',
  726. {$endif}
  727. {$ifdef os2}
  728. 'O',
  729. {$endif}
  730. '*' : show:=true;
  731. else
  732. show:=false;
  733. end;
  734. end;
  735. { now we may show the message or not }
  736. if show then
  737. begin
  738. case s[3] of
  739. '0' : begin
  740. ident:=0;
  741. outline:=0;
  742. end;
  743. '1' : begin
  744. ident:=2;
  745. outline:=7;
  746. end;
  747. '2' : begin
  748. ident:=6;
  749. outline:=11;
  750. end;
  751. '3' : begin
  752. ident:=9;
  753. outline:=11;
  754. end;
  755. else
  756. internalerror(2013112906);
  757. end;
  758. j:=pos('_',s);
  759. opt:=Copy(s,4,j-4);
  760. if opt='*' then
  761. opt:=''
  762. else
  763. if (opt=' ') or (opt[1]='@') then
  764. opt:=PadEnd(opt,outline)
  765. else
  766. opt:=PadEnd('-'+opt,outline);
  767. if (ident=0) and (lastident<>0) then
  768. begin
  769. Comment(V_Normal,'');
  770. inc(Lines);
  771. end;
  772. HelpLine := PadEnd('',ident)+opt+Copy(s,j+1,255);
  773. if HelpLine = '' then
  774. HelpLineHeight := 1
  775. else
  776. HelpLineHeight := Succ (CharLength (HelpLine) div Page_Width);
  777. { page full ? }
  778. if (lines + HelpLineHeight >= page_size - 1) then
  779. begin
  780. if not NoPressEnter then
  781. begin
  782. Message(option_help_press_enter);
  783. readln(input);
  784. if upper(input)='Q' then
  785. StopOptions(0);
  786. end;
  787. lines:=0;
  788. end;
  789. Comment(V_Normal,HelpLine);
  790. LastIdent:=Ident;
  791. Inc (Lines, HelpLineHeight);
  792. end;
  793. end;
  794. StopOptions(0);
  795. end;
  796. procedure Toption.IllegalPara(const opt:TCmdStr);
  797. begin
  798. Message1(option_illegal_para,opt);
  799. Message(option_help_pages_para);
  800. StopOptions(1);
  801. end;
  802. procedure toption.UnsupportedPara(const opt: TCmdStr);
  803. begin
  804. Message1(option_unsupported_target,opt);
  805. StopOptions(1);
  806. end;
  807. procedure toption.IgnoredPara(const opt: TCmdStr);
  808. begin
  809. Message1(option_ignored_target,opt);
  810. end;
  811. procedure toption.ForceStaticLinking;
  812. begin
  813. def_system_macro('FPC_LINK_STATIC');
  814. undef_system_macro('FPC_LINK_SMART');
  815. undef_system_macro('FPC_LINK_DYNAMIC');
  816. include(init_settings.globalswitches,cs_link_static);
  817. exclude(init_settings.globalswitches,cs_link_smart);
  818. exclude(init_settings.globalswitches,cs_link_shared);
  819. LinkTypeSetExplicitly:=true;
  820. end;
  821. function toption.ParseMacVersionMin(out minstr, emptystr: string; const compvarname, value: string; ios: boolean): boolean;
  822. function subval(start,maxlen: longint; out stop: longint): string;
  823. var
  824. i: longint;
  825. begin
  826. result:='';
  827. i:=start;
  828. while (i<=length(value)) and
  829. (value[i] in ['0'..'9']) do
  830. inc(i);
  831. { sufficient amount of digits? }
  832. if (i=start) or
  833. (i-start>maxlen) then
  834. exit;
  835. result:=copy(value,start,i-start);
  836. stop:=i;
  837. end;
  838. var
  839. temp,
  840. compvarvalue: string[15];
  841. i: longint;
  842. osx_minor_two_digits: boolean;
  843. begin
  844. minstr:=value;
  845. emptystr:='';
  846. MacVersionSet:=false;
  847. { check whether the value is a valid version number }
  848. if value='' then
  849. begin
  850. undef_system_macro(compvarname);
  851. exit(true);
  852. end;
  853. { major version number }
  854. compvarvalue:=subval(1,2,i);
  855. { not enough digits -> invalid }
  856. if compvarvalue='' then
  857. exit(false);
  858. { already end of string -> invalid }
  859. if (i>=length(value)) or
  860. (value[i]<>'.') then
  861. exit(false);
  862. { minor version number }
  863. temp:=subval(i+1,2,i);
  864. if temp='' then
  865. exit(false);
  866. { on Mac OS X, the minor version number was originally limited to 1 digit;
  867. with 10.10 the format changed and two digits were also supported; on iOS,
  868. the minor version number always takes up two digits }
  869. osx_minor_two_digits:=false;
  870. if not ios then
  871. begin
  872. { if the minor version number is two digits on OS X (the case since
  873. OS X 10.10), we also have to add two digits for the patch level}
  874. if length(temp)=2 then
  875. osx_minor_two_digits:=true;
  876. end
  877. { the minor version number always takes up two digits on iOS }
  878. else if length(temp)=1 then
  879. temp:='0'+temp;
  880. compvarvalue:=compvarvalue+temp;
  881. { optional patch level }
  882. if i<=length(value) then
  883. begin
  884. if value[i]<>'.' then
  885. exit(false);
  886. temp:=subval(i+1,2,i);
  887. if temp='' then
  888. exit(false);
  889. { there's only room for a single digit patch level in the version macro
  890. for Mac OS X. gcc sets it to zero if there are more digits, but that
  891. seems worse than clamping to 9 (don't declare as invalid like with
  892. minor version number, because there is a precedent like 10.4.11).
  893. As of OS X 10.10 there are two digits for the patch level
  894. }
  895. if not ios and
  896. not osx_minor_two_digits then
  897. begin
  898. if length(temp)<>1 then
  899. temp:='9';
  900. end
  901. else
  902. begin
  903. { on iOS, the patch level is always two digits }
  904. if length(temp)=1 then
  905. temp:='0'+temp;
  906. end;
  907. compvarvalue:=compvarvalue+temp;
  908. { must be the end }
  909. if i<=length(value) then
  910. exit(false);
  911. end
  912. else if not ios and
  913. not osx_minor_two_digits then
  914. begin
  915. compvarvalue:=compvarvalue+'0';
  916. minstr:=minstr+'.0'
  917. end
  918. else
  919. begin
  920. compvarvalue:=compvarvalue+'00';
  921. { command line versions still only use one 0 though }
  922. minstr:=minstr+'.0'
  923. end;
  924. set_system_compvar(compvarname,compvarvalue);
  925. MacVersionSet:=true;
  926. result:=true;
  927. end;
  928. procedure TOption.MaybeSetDefaultMacVersionMacro;
  929. var
  930. envstr: ansistring;
  931. begin
  932. if not(target_info.system in systems_darwin) then
  933. exit;
  934. if MacVersionSet then
  935. exit;
  936. { check for deployment target set via environment variable }
  937. if not(target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim]) then
  938. begin
  939. envstr:=GetEnvironmentVariable('MACOSX_DEPLOYMENT_TARGET');
  940. if envstr<>'' then
  941. if not ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',envstr,false) then
  942. Message1(option_invalid_macosx_deployment_target,envstr)
  943. else
  944. begin
  945. {$ifdef llvm}
  946. { We only support libunwind as part of libsystem, which happened in Mac OS X 10.6 }
  947. if CompareVersionStrings(MacOSXVersionMin,'10.6')<=0 then
  948. Message1(option_invalid_macosx_deployment_target,envstr);
  949. {$endif}
  950. exit;
  951. end;
  952. end
  953. else
  954. begin
  955. envstr:=GetEnvironmentVariable('IPHONEOS_DEPLOYMENT_TARGET');
  956. if envstr<>'' then
  957. if not ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',envstr,true) then
  958. Message1(option_invalid_iphoneos_deployment_target,envstr)
  959. else
  960. exit;
  961. end;
  962. { nothing specified -> defaults }
  963. case target_info.system of
  964. system_powerpc_darwin:
  965. begin
  966. set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1030');
  967. MacOSXVersionMin:='10.3.0';
  968. end;
  969. system_powerpc64_darwin:
  970. begin
  971. set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1040');
  972. MacOSXVersionMin:='10.4.0';
  973. end;
  974. system_i386_darwin,
  975. system_x86_64_darwin:
  976. begin
  977. set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1080');
  978. MacOSXVersionMin:='10.8.0';
  979. end;
  980. system_arm_ios,
  981. system_i386_iphonesim:
  982. begin
  983. set_system_compvar('IPHONE_OS_VERSION_MIN_REQUIRED','90000');
  984. iPhoneOSVersionMin:='9.0.0';
  985. end;
  986. system_aarch64_ios,
  987. system_x86_64_iphonesim:
  988. begin
  989. set_system_compvar('IPHONE_OS_VERSION_MIN_REQUIRED','90000');
  990. iPhoneOSVersionMin:='9.0.0';
  991. end;
  992. system_aarch64_darwin:
  993. begin
  994. set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','110000');
  995. MacOSXVersionMin:='11.0.0';
  996. end
  997. else
  998. internalerror(2012031001);
  999. end;
  1000. end;
  1001. procedure TOption.VerifyTargetProcessor;
  1002. begin
  1003. { no custom target processor specified -> ok }
  1004. if processorstr='' then
  1005. exit;
  1006. { custom target processor specified -> verify it's the one we support }
  1007. if upcase(processorstr)<>upcase(target_cpu_string) then
  1008. Message1(option_invalid_target_architecture,processorstr);
  1009. end;
  1010. function Toption.Unsetbool(var Opts:TCmdStr; Pos: Longint; const FullPara: TCmdStr; RequireBoolPara: boolean):boolean;
  1011. { checks if the character after pos in Opts is a + or a - and returns resp.
  1012. false or true. If it is another character (or none), it also returns false }
  1013. begin
  1014. UnsetBool := false;
  1015. if Length(Opts)>Pos then
  1016. begin
  1017. inc(Pos);
  1018. UnsetBool := Opts[Pos] = '-';
  1019. if Opts[Pos] in ['-','+']then
  1020. delete(Opts,Pos,1)
  1021. else if RequireBoolPara then
  1022. IllegalPara(FullPara);
  1023. end;
  1024. end;
  1025. procedure TOption.interpret_option(const opt:TCmdStr;ispara:boolean);
  1026. var
  1027. code : integer;
  1028. c : char;
  1029. more : TCmdStr;
  1030. major,minor : longint;
  1031. error : integer;
  1032. j,l : longint;
  1033. d,s : TCmdStr;
  1034. hs : TCmdStr;
  1035. unicodemapping : punicodemap;
  1036. {$ifdef llvm}
  1037. disable: boolean;
  1038. {$endif}
  1039. begin
  1040. if opt='' then
  1041. exit;
  1042. { only parse define,undef,target,verbosity,link etc options the firsttime
  1043. -Us must now also be first-passed to avoid rejection of -Sf options
  1044. earlier in command line }
  1045. if firstpass and
  1046. not(
  1047. (opt[1]='-') and
  1048. (
  1049. ((length(opt)>1) and (opt[2] in ['i','d','v','T','u','n','X','l','U'])) or
  1050. ((length(opt)>3) and (opt[2]='F') and (opt[3]='e')) or
  1051. ((length(opt)>3) and (opt[2]='C') and (opt[3]='p')) or
  1052. ((length(opt)>3) and (opt[2]='W') and (opt[3] in ['m','p']))
  1053. )
  1054. ) then
  1055. exit;
  1056. Message1(option_handling_option,opt);
  1057. case opt[1] of
  1058. '-' :
  1059. begin
  1060. more:=Copy(opt,3,2147483647);
  1061. if firstpass then
  1062. Message1(option_interpreting_firstpass_option,opt)
  1063. else
  1064. Message1(option_interpreting_option,opt);
  1065. case opt[2] of
  1066. '?' :
  1067. begin
  1068. if (More <> '') and (More [1] = 'F') then
  1069. begin
  1070. FPCHelpLines := true;
  1071. Delete (More, 1, 1);
  1072. FPCBinaryPath := More;
  1073. end;
  1074. WriteHelpPages;
  1075. end;
  1076. 'a' :
  1077. begin
  1078. include(init_settings.globalswitches,cs_asm_leave);
  1079. j:=1;
  1080. while j<=length(more) do
  1081. begin
  1082. case more[j] of
  1083. '5' :
  1084. if (target_info.system in systems_all_windows+systems_nativent-[system_i8086_win16])
  1085. or (target_info.cpu in [cpu_mipseb, cpu_mipsel]) then
  1086. begin
  1087. if UnsetBool(More, j, opt, false) then
  1088. exclude(init_settings.globalswitches,cs_asm_pre_binutils_2_25)
  1089. else
  1090. include(init_settings.globalswitches,cs_asm_pre_binutils_2_25);
  1091. end
  1092. else
  1093. IllegalPara(opt);
  1094. 'l' :
  1095. include(init_settings.globalswitches,cs_asm_source);
  1096. 'r' :
  1097. include(init_settings.globalswitches,cs_asm_regalloc);
  1098. 't' :
  1099. include(init_settings.globalswitches,cs_asm_tempalloc);
  1100. 'n' :
  1101. include(init_settings.globalswitches,cs_asm_nodes);
  1102. { -ao option must be the last, everything behind it is passed directly to
  1103. external assembler, it is ignored if internal assembler is used. }
  1104. 'o' :
  1105. begin
  1106. asmextraopt:=copy(more,j+1,length(more)-j);
  1107. break;
  1108. end;
  1109. 'p' :
  1110. begin
  1111. exclude(init_settings.globalswitches,cs_asm_leave);
  1112. if UnsetBool(More, 0, opt, false) then
  1113. exclude(init_settings.globalswitches,cs_asm_pipe)
  1114. else
  1115. include(init_settings.globalswitches,cs_asm_pipe);
  1116. end;
  1117. '-' :
  1118. init_settings.globalswitches:=init_settings.globalswitches -
  1119. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc,
  1120. cs_asm_nodes, cs_asm_pipe];
  1121. else
  1122. IllegalPara(opt);
  1123. end;
  1124. inc(j);
  1125. end;
  1126. end;
  1127. 'A' :
  1128. begin
  1129. paratargetasm:=find_asm_by_string(More);
  1130. if paratargetasm=as_none then
  1131. IllegalPara(opt);
  1132. end;
  1133. 'b' :
  1134. begin
  1135. // Message1(option_obsolete_switch,'-b');
  1136. if UnsetBool(More,0,opt,false) then
  1137. begin
  1138. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_browser];
  1139. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser];
  1140. end
  1141. else
  1142. begin
  1143. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_browser];
  1144. end;
  1145. if More<>'' then
  1146. if (More='l') or (More='l+') then
  1147. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_local_browser]
  1148. else if More='l-' then
  1149. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser]
  1150. else
  1151. IllegalPara(opt);
  1152. end;
  1153. 'B' :
  1154. do_build:=not UnSetBool(more,0,opt,true);
  1155. 'C' :
  1156. begin
  1157. j:=1;
  1158. while j<=length(more) do
  1159. begin
  1160. case more[j] of
  1161. '3' :
  1162. If UnsetBool(More, j, opt, false) then
  1163. exclude(init_settings.localswitches,cs_ieee_errors)
  1164. Else
  1165. include(init_settings.localswitches,cs_ieee_errors);
  1166. 'a' :
  1167. begin
  1168. s:=upper(copy(more,j+1,length(more)-j));
  1169. if not(SetAbiType(s,target_info.abi)) then
  1170. IllegalPara(opt);
  1171. ABISetExplicitly:=true;
  1172. break;
  1173. end;
  1174. 'b' :
  1175. begin
  1176. if UnsetBool(More, j, opt, false) then
  1177. target_info.endian:=endian_little
  1178. else
  1179. target_info.endian:=endian_big;
  1180. end;
  1181. 'c' :
  1182. begin
  1183. if not SetAktProcCall(upper(copy(more,j+1,length(more)-j)),init_settings.defproccall) then
  1184. IllegalPara(opt);
  1185. break;
  1186. end;
  1187. {$ifdef cpufpemu}
  1188. 'e' :
  1189. begin
  1190. If UnsetBool(More, j, opt, false) then
  1191. exclude(init_settings.moduleswitches,cs_fp_emulation)
  1192. Else
  1193. include(init_settings.moduleswitches,cs_fp_emulation);
  1194. end;
  1195. {$endif cpufpemu}
  1196. 'E' :
  1197. If UnsetBool(More, j, opt, false) then
  1198. exclude(init_settings.localswitches,cs_check_fpu_exceptions)
  1199. Else
  1200. include(init_settings.localswitches,cs_check_fpu_exceptions);
  1201. 'f' :
  1202. begin
  1203. s:=upper(copy(more,j+1,length(more)-j));
  1204. if not(SetFpuType(s,init_settings.fputype)) then
  1205. IllegalPara(opt);
  1206. FPUSetExplicitly:=True;
  1207. break;
  1208. end;
  1209. 'F' :
  1210. begin
  1211. if not SetMinFPConstPrec(copy(more,j+1,length(more)-j),init_settings.minfpconstprec) then
  1212. IllegalPara(opt);
  1213. break;
  1214. end;
  1215. 'g' :
  1216. begin
  1217. if tf_no_pic_supported in target_info.flags then
  1218. begin
  1219. { consume a possible '-' coming after it }
  1220. UnsetBool(More, j, opt, false);
  1221. message(scan_w_pic_ignored);
  1222. end
  1223. else if UnsetBool(More, j, opt, false) then
  1224. exclude(init_settings.moduleswitches,cs_create_pic)
  1225. else
  1226. include(init_settings.moduleswitches,cs_create_pic);
  1227. end;
  1228. 'h' :
  1229. begin
  1230. l:=pos(',',copy(more,j+1,length(more)-j));
  1231. if l=0 then
  1232. l:=length(more)-j+1;
  1233. val(copy(more,j+1,l-1),heapsize,code);
  1234. if (code<>0)
  1235. {$ifdef AVR}
  1236. or (heapsize<32)
  1237. {$else AVR}
  1238. or (heapsize<1024)
  1239. {$endif AVR}
  1240. then
  1241. IllegalPara(opt)
  1242. else if l<=length(more)-j then
  1243. begin
  1244. val(copy(more,j+l+1,length(more)),maxheapsize,code);
  1245. if code<>0 then
  1246. IllegalPara(opt)
  1247. else if (maxheapsize<heapsize) then
  1248. begin
  1249. message(scan_w_heapmax_lessthan_heapmin);
  1250. maxheapsize:=heapsize;
  1251. end;
  1252. end;
  1253. break;
  1254. end;
  1255. 'i' :
  1256. If UnsetBool(More, j, opt, false) then
  1257. exclude(init_settings.localswitches,cs_check_io)
  1258. else
  1259. include(init_settings.localswitches,cs_check_io);
  1260. {$ifdef arm}
  1261. 'I' :
  1262. begin
  1263. if (upper(copy(more,j+1,length(more)-j))='THUMB') and
  1264. { does selected CPU really understand thumb? }
  1265. (init_settings.cputype in cpu_has_thumb) then
  1266. init_settings.instructionset:=is_thumb
  1267. else if upper(copy(more,j+1,length(more)-j))='ARM' then
  1268. init_settings.instructionset:=is_arm
  1269. else
  1270. IllegalPara(opt);
  1271. break;
  1272. end;
  1273. {$endif arm}
  1274. {$ifdef llvm}
  1275. 'l':
  1276. begin
  1277. l:=j+1;
  1278. while l<=length(More) do
  1279. begin
  1280. case More[l] of
  1281. 'f':
  1282. begin
  1283. More:=copy(More,l+1,length(More));
  1284. disable:=Unsetbool(More,length(More)-1,opt,false);
  1285. case More of
  1286. 'lto':
  1287. begin
  1288. if not disable then
  1289. begin
  1290. include(init_settings.moduleswitches,cs_lto);
  1291. LTOExt:='.bc';
  1292. end
  1293. else
  1294. exclude(init_settings.moduleswitches,cs_lto);
  1295. end;
  1296. 'ltonosystem':
  1297. begin
  1298. if not disable then
  1299. begin
  1300. include(init_settings.globalswitches,cs_lto_nosystem);
  1301. end
  1302. else
  1303. exclude(init_settings.globalswitches,cs_lto_nosystem);
  1304. end;
  1305. else
  1306. begin
  1307. IllegalPara(opt);
  1308. end;
  1309. end;
  1310. l:=length(more)+1;
  1311. end;
  1312. 'v':
  1313. begin
  1314. init_settings.llvmversion:=llvmversion2enum(copy(More,l+1,length(More)));
  1315. if init_settings.llvmversion=llvmver_invalid then
  1316. begin
  1317. IllegalPara(opt);
  1318. end;
  1319. l:=length(More)+1;
  1320. end
  1321. else
  1322. begin
  1323. IllegalPara(opt);
  1324. end;
  1325. end;
  1326. end;
  1327. j:=l;
  1328. end;
  1329. {$endif llvm}
  1330. 'n' :
  1331. If UnsetBool(More, j, opt, false) then
  1332. exclude(init_settings.globalswitches,cs_link_nolink)
  1333. Else
  1334. include(init_settings.globalswitches,cs_link_nolink);
  1335. 'N' :
  1336. If UnsetBool(More, j, opt, false) then
  1337. exclude(init_settings.localswitches,cs_check_low_addr_load)
  1338. Else
  1339. include(init_settings.localswitches,cs_check_low_addr_load);
  1340. 'o' :
  1341. If UnsetBool(More, j, opt, false) then
  1342. exclude(init_settings.localswitches,cs_check_overflow)
  1343. Else
  1344. include(init_settings.localswitches,cs_check_overflow);
  1345. 'O' :
  1346. If UnsetBool(More, j, opt, false) then
  1347. exclude(init_settings.localswitches,cs_check_ordinal_size)
  1348. Else
  1349. include(init_settings.localswitches,cs_check_ordinal_size);
  1350. 'p' :
  1351. begin
  1352. s:=upper(copy(more,j+1,length(more)-j));
  1353. if not(Setcputype(s,init_settings)) then
  1354. IllegalPara(opt);
  1355. CPUSetExplicitly:=true;
  1356. break;
  1357. end;
  1358. 'P':
  1359. begin
  1360. delete(more,1,1);
  1361. case upper(copy(more,1,pos('=',more)-1)) of
  1362. 'PACKSET':
  1363. begin
  1364. delete(more,1,pos('=',more));
  1365. case more of
  1366. '0','DEFAULT','NORMAL':
  1367. init_settings.setalloc:=0;
  1368. '1','2','4','8':
  1369. init_settings.setalloc:=StrToInt(more);
  1370. else
  1371. IllegalPara(opt);
  1372. end
  1373. end;
  1374. 'PACKENUM':
  1375. begin
  1376. delete(more,1,pos('=',more));
  1377. case more of
  1378. '0','DEFAULT','NORMAL':
  1379. init_settings.packenum:=4;
  1380. '1','2','4':
  1381. init_settings.packenum:=StrToInt(more);
  1382. else
  1383. IllegalPara(opt);
  1384. end;
  1385. end;
  1386. 'PACKRECORD':
  1387. begin
  1388. delete(more,1,pos('=',more));
  1389. case more of
  1390. '0','DEFAULT','NORMAL':
  1391. init_settings.packrecords:=default_settings.packrecords;
  1392. '1','2','4','8','16','32':
  1393. init_settings.packrecords:=StrToInt(more);
  1394. else
  1395. IllegalPara(opt);
  1396. end;
  1397. end
  1398. else
  1399. IllegalPara(opt);
  1400. end;
  1401. end;
  1402. 'r' :
  1403. If UnsetBool(More, j, opt, false) then
  1404. exclude(init_settings.localswitches,cs_check_range)
  1405. Else
  1406. include(init_settings.localswitches,cs_check_range);
  1407. 'R' :
  1408. If UnsetBool(More, j, opt, false) then
  1409. begin
  1410. exclude(init_settings.localswitches,cs_check_range);
  1411. exclude(init_settings.localswitches,cs_check_object);
  1412. end
  1413. Else
  1414. begin
  1415. include(init_settings.localswitches,cs_check_range);
  1416. include(init_settings.localswitches,cs_check_object);
  1417. end;
  1418. 's' :
  1419. begin
  1420. val(copy(more,j+1,length(more)-j),stacksize,code);
  1421. if (code<>0)
  1422. {$ifdef cpu16bitaddr}
  1423. or (stacksize>=65521)
  1424. {$else cpu16bitaddr}
  1425. or (stacksize>=67107840)
  1426. {$endif cpu16bitaddr}
  1427. or (stacksize<1024) then
  1428. IllegalPara(opt);
  1429. break;
  1430. end;
  1431. 't' :
  1432. If UnsetBool(More, j, opt, false) then
  1433. exclude(init_settings.localswitches,cs_check_stack)
  1434. Else
  1435. include(init_settings.localswitches,cs_check_stack);
  1436. 'D' :
  1437. If UnsetBool(More, j, opt, false) then
  1438. exclude(init_settings.moduleswitches,cs_create_dynamic)
  1439. Else
  1440. include(init_settings.moduleswitches,cs_create_dynamic);
  1441. 'X' :
  1442. If UnsetBool(More, j, opt, false) then
  1443. exclude(init_settings.moduleswitches,cs_create_smart)
  1444. Else
  1445. include(init_settings.moduleswitches,cs_create_smart);
  1446. 'T' :
  1447. begin
  1448. if not UpdateTargetSwitchStr(copy(more,j+1,length(more)),init_settings.targetswitches,true) then
  1449. IllegalPara(opt);
  1450. break;
  1451. end;
  1452. 'v' :
  1453. If target_info.system in systems_jvm then
  1454. If UnsetBool(More, j, opt, false) then
  1455. exclude(init_settings.localswitches,cs_check_var_copyout)
  1456. Else
  1457. include(init_settings.localswitches,cs_check_var_copyout)
  1458. else
  1459. IllegalPara(opt);
  1460. 'V':
  1461. begin
  1462. s:=upper(copy(more,j+1,length(more)-j));
  1463. if s='GLOBAL-DYNAMIC' then
  1464. init_settings.tlsmodel:=tlsm_global_dynamic
  1465. else if s='LOCAL-EXEC' then
  1466. init_settings.tlsmodel:=tlsm_local_exec
  1467. else
  1468. IllegalPara(opt);
  1469. break;
  1470. end;
  1471. else
  1472. IllegalPara(opt);
  1473. end;
  1474. inc(j);
  1475. end;
  1476. end;
  1477. 'd' :
  1478. begin
  1479. l:=Pos(':=',more);
  1480. if l>0 then
  1481. hs:=copy(more,1,l-1)
  1482. else
  1483. hs:=more;
  1484. if (not is_identifier(hs)) then
  1485. begin
  1486. if hs='' then
  1487. Message1(option_missing_arg,'-d')
  1488. else
  1489. Message1(option_malformed_para,opt);
  1490. StopOptions(1);
  1491. end;
  1492. if l>0 then
  1493. begin
  1494. if cs_support_macro in init_settings.moduleswitches then
  1495. set_system_macro(hs,Copy(more,l+2,255))
  1496. else
  1497. set_system_compvar(hs,Copy(more,l+2,255));
  1498. end
  1499. else
  1500. def_system_macro(hs);
  1501. end;
  1502. 'D' :
  1503. begin
  1504. include(init_settings.globalswitches,cs_link_deffile);
  1505. j:=1;
  1506. while j<=length(more) do
  1507. begin
  1508. case more[j] of
  1509. 'd' :
  1510. begin
  1511. description:=Copy(more,j+1,255);
  1512. break;
  1513. end;
  1514. 'D' :
  1515. begin
  1516. datestr:=Copy(more,j+1,255);
  1517. break;
  1518. end;
  1519. 'T' :
  1520. begin
  1521. timestr:=Copy(more,j+1,255);
  1522. break;
  1523. end;
  1524. 'v' :
  1525. begin
  1526. dllversion:=Copy(more,j+1,255);
  1527. l:=pos('.',dllversion);
  1528. dllminor:=0;
  1529. error:=0;
  1530. if l>0 then
  1531. begin
  1532. val(copy(dllversion,l+1,255),minor,error);
  1533. if (error=0) and
  1534. (minor>=0) and (minor<=$ffff) then
  1535. dllminor:=minor
  1536. else
  1537. if error=0 then
  1538. error:=1;
  1539. end;
  1540. if l=0 then
  1541. l:=256;
  1542. dllmajor:=1;
  1543. major:=0;
  1544. if error=0 then
  1545. val(copy(dllversion,1,l-1),major,error);
  1546. if (error=0) and (major>=0) and (major<=$ffff) then
  1547. dllmajor:=major
  1548. else
  1549. if error=0 then
  1550. error:=1;
  1551. if error<>0 then
  1552. Message1(scan_w_wrong_version_ignored,dllversion);
  1553. break;
  1554. end;
  1555. 'w' :
  1556. usewindowapi:=true;
  1557. '-' :
  1558. begin
  1559. exclude(init_settings.globalswitches,cs_link_deffile);
  1560. usewindowapi:=false;
  1561. end;
  1562. else
  1563. IllegalPara(opt);
  1564. end;
  1565. inc(j);
  1566. end;
  1567. end;
  1568. 'e' :
  1569. exepath:=FixPath(More,true);
  1570. 'E' :
  1571. begin
  1572. if UnsetBool(More, 0, opt, true) then
  1573. exclude(init_settings.globalswitches,cs_link_nolink)
  1574. else
  1575. include(init_settings.globalswitches,cs_link_nolink);
  1576. end;
  1577. 'f' :
  1578. begin
  1579. if more='PIC' then
  1580. begin
  1581. if tf_no_pic_supported in target_info.flags then
  1582. message(scan_w_pic_ignored)
  1583. else
  1584. include(init_settings.moduleswitches,cs_create_pic)
  1585. end
  1586. else
  1587. IllegalPara(opt);
  1588. end;
  1589. 'F' :
  1590. begin
  1591. if more='' then
  1592. IllegalPara(opt);
  1593. c:=more[1];
  1594. Delete(more,1,1);
  1595. DefaultReplacements(More);
  1596. case c of
  1597. 'a' :
  1598. autoloadunits:=more;
  1599. 'c' :
  1600. begin
  1601. { if we first specify that the system code page should be
  1602. used and then explicitly specify a code page, unset the
  1603. flag that we're using the system code page again }
  1604. SetCompileModeSwitch('SYSTEMCODEPAGE-',true);
  1605. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  1606. init_settings.sourcecodepage:=CP_UTF8
  1607. else if not(cpavailable(more)) then
  1608. Message1(option_code_page_not_available,more)
  1609. else
  1610. init_settings.sourcecodepage:=codepagebyname(more);
  1611. include(init_settings.moduleswitches,cs_explicit_codepage);
  1612. end;
  1613. 'C' :
  1614. RCCompiler:=More;
  1615. 'd' :
  1616. if UnsetBool(more, 0, opt, true) then
  1617. init_settings.disabledircache:=false
  1618. else
  1619. init_settings.disabledircache:=true;
  1620. 'D' :
  1621. utilsdirectory:=FixPath(More,true);
  1622. 'e' :
  1623. SetRedirectFile(More);
  1624. 'E' :
  1625. OutputExeDir:=FixPath(More,true);
  1626. 'f' :
  1627. if (target_info.system in systems_darwin) then
  1628. if ispara then
  1629. ParaFrameworkPath.AddPath(More,false)
  1630. else
  1631. frameworksearchpath.AddPath(More,true)
  1632. {$ifdef XTENSA}
  1633. else if (target_info.system=system_xtensa_freertos) then
  1634. idfpath:=FixPath(More,true)
  1635. {$endif XTENSA}
  1636. else
  1637. IllegalPara(opt);
  1638. 'F' :
  1639. RCForceFPCRes:=true;
  1640. 'i' :
  1641. begin
  1642. if ispara then
  1643. ParaIncludePath.AddPath(More,false)
  1644. else
  1645. includesearchpath.AddPath(More,true);
  1646. end;
  1647. 'm' :
  1648. begin
  1649. s:=ExtractFileDir(more);
  1650. if TryStrToInt(ExtractFileName(more),j) then
  1651. begin
  1652. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  1653. if assigned(unicodemapping) then
  1654. registermapping(unicodemapping)
  1655. else
  1656. IllegalPara(opt);
  1657. end
  1658. else
  1659. IllegalPara(opt);
  1660. end;
  1661. 'M' :
  1662. unicodepath:=FixPath(More,true);
  1663. 'g' :
  1664. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  1665. 'l' :
  1666. begin
  1667. if ispara then
  1668. ParaLibraryPath.AddLibraryPath(sysrootpath,More,false)
  1669. else
  1670. LibrarySearchPath.AddLibraryPath(sysrootpath,More,true)
  1671. end;
  1672. 'L' :
  1673. begin
  1674. if More<>'' then
  1675. ParaDynamicLinker:=More
  1676. else
  1677. IllegalPara(opt);
  1678. end;
  1679. 'N' :
  1680. begin
  1681. if more<>'' then
  1682. paranamespaces.insert(more)
  1683. else
  1684. illegalpara(opt);
  1685. end;
  1686. 'o' :
  1687. begin
  1688. if ispara then
  1689. ParaObjectPath.AddPath(More,false)
  1690. else
  1691. ObjectSearchPath.AddPath(More,true);
  1692. end;
  1693. 'P' :
  1694. begin
  1695. if ispara then
  1696. parapackages.add(more,nil)
  1697. else
  1698. add_package(more,true,true);
  1699. end;
  1700. 'p' :
  1701. begin
  1702. if ispara then
  1703. parapackagepath.AddPath(More,false)
  1704. else
  1705. packagesearchpath.AddPath(More,true);
  1706. end;
  1707. 'r' :
  1708. Msgfilename:=More;
  1709. 'R' :
  1710. ResCompiler:=More;
  1711. 'u' :
  1712. begin
  1713. if ispara then
  1714. ParaUnitPath.AddPath(More,false)
  1715. else
  1716. unitsearchpath.AddPath(More,true);
  1717. end;
  1718. 'U' :
  1719. OutputUnitDir:=FixPath(More,true);
  1720. 'W',
  1721. 'w':
  1722. begin
  1723. if More<>'' then
  1724. begin
  1725. DefaultReplacements(More);
  1726. D:=ExtractFilePath(More);
  1727. if (D<>'') then
  1728. D:=FixPath(D,True);
  1729. D:=D+ExtractFileName(More);
  1730. if (c='W') then
  1731. WpoFeedbackOutput:=D
  1732. else
  1733. WpoFeedbackInput:=D;
  1734. end
  1735. else
  1736. IllegalPara(opt);
  1737. end;
  1738. else
  1739. IllegalPara(opt);
  1740. end;
  1741. end;
  1742. 'g' :
  1743. begin
  1744. if UnsetBool(More, 0, opt, false) then
  1745. begin
  1746. exclude(init_settings.moduleswitches,cs_debuginfo);
  1747. exclude(init_settings.globalswitches,cs_use_heaptrc);
  1748. exclude(init_settings.globalswitches,cs_use_lineinfo);
  1749. exclude(init_settings.localswitches,cs_checkpointer);
  1750. paratargetdbg:=dbg_none;
  1751. localvartrashing := -1;
  1752. end
  1753. else
  1754. begin
  1755. include(init_settings.moduleswitches,cs_debuginfo);
  1756. if paratargetdbg=dbg_none then
  1757. paratargetdbg:=target_info.dbg;
  1758. end;
  1759. if not RelocSectionSetExplicitly then
  1760. RelocSection:=false;
  1761. j:=1;
  1762. while j<=length(more) do
  1763. begin
  1764. case more[j] of
  1765. 'c' :
  1766. begin
  1767. if UnsetBool(More, j, opt, false) then
  1768. exclude(init_settings.localswitches,cs_checkpointer)
  1769. else if (target_info.system in systems_support_checkpointer) then
  1770. begin
  1771. if do_release then
  1772. Message(option_gc_incompatible_with_release_flag)
  1773. else
  1774. include(init_settings.localswitches,cs_checkpointer);
  1775. end
  1776. else
  1777. UnsupportedPara('-gc');
  1778. end;
  1779. 'h' :
  1780. begin
  1781. if UnsetBool(More, j, opt, false) then
  1782. exclude(init_settings.globalswitches,cs_use_heaptrc)
  1783. else
  1784. begin
  1785. if cs_gdb_valgrind in init_settings.globalswitches then
  1786. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  1787. include(init_settings.globalswitches,cs_use_heaptrc);
  1788. end;
  1789. end;
  1790. 'l' :
  1791. begin
  1792. if UnsetBool(More, j, opt, false) then
  1793. exclude(init_settings.globalswitches,cs_use_lineinfo)
  1794. else
  1795. include(init_settings.globalswitches,cs_use_lineinfo);
  1796. end;
  1797. 'm' :
  1798. begin
  1799. paratargetdbg:=dbg_codeview;
  1800. end;
  1801. 'o' :
  1802. begin
  1803. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  1804. IllegalPara(opt);
  1805. break;
  1806. end;
  1807. 'p' :
  1808. begin
  1809. if UnsetBool(More, j, opt, false) then
  1810. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  1811. else
  1812. include(init_settings.globalswitches,cs_stabs_preservecase);
  1813. end;
  1814. 's' :
  1815. begin
  1816. paratargetdbg:=dbg_stabs;
  1817. end;
  1818. 't' :
  1819. begin
  1820. if UnsetBool(More, j, opt, false) then
  1821. localvartrashing := -1
  1822. else
  1823. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  1824. end;
  1825. 'v' :
  1826. begin
  1827. if UnsetBool(More, j, opt, false) then
  1828. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  1829. else
  1830. begin
  1831. if cs_use_heaptrc in init_settings.globalswitches then
  1832. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  1833. include(init_settings.globalswitches,cs_gdb_valgrind);
  1834. end;
  1835. end;
  1836. 'w' :
  1837. begin
  1838. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  1839. begin
  1840. case more[j+1] of
  1841. '2': paratargetdbg:=dbg_dwarf2;
  1842. '3': paratargetdbg:=dbg_dwarf3;
  1843. '4': paratargetdbg:=dbg_dwarf4;
  1844. end;
  1845. inc(j);
  1846. end
  1847. else
  1848. paratargetdbg:=dbg_dwarf2;
  1849. end;
  1850. else
  1851. IllegalPara(opt);
  1852. end;
  1853. inc(j);
  1854. end;
  1855. end;
  1856. 'h' :
  1857. begin
  1858. NoPressEnter:=true;
  1859. if (More <> '') and (More [1] = 'F') then
  1860. begin
  1861. FPCHelpLines := true;
  1862. Delete (More, 1, 1);
  1863. FPCBinaryPath := More;
  1864. end;
  1865. WriteHelpPages;
  1866. end;
  1867. 'i' :
  1868. begin
  1869. if (More='') or
  1870. (More [1] in ['a', 'b', 'c', 'f', 'i', 'm', 'o', 'r', 't', 'u', 'w']) then
  1871. WriteInfo (More)
  1872. else
  1873. QuickInfo:=QuickInfo+More;
  1874. end;
  1875. 'I' :
  1876. begin
  1877. if ispara then
  1878. ParaIncludePath.AddPath(More,false)
  1879. else
  1880. includesearchpath.AddPath(More,false);
  1881. end;
  1882. 'k' :
  1883. begin
  1884. if more<>'' then
  1885. ParaLinkOptions:=ParaLinkOptions+' '+More
  1886. else
  1887. IllegalPara(opt);
  1888. end;
  1889. 'l' :
  1890. ParaLogo:=not UnSetBool(more,0,opt,true);
  1891. {$ifdef PREPROCWRITE}
  1892. 'm' :
  1893. parapreprocess:=not UnSetBool(more,0,opt,true);
  1894. {$endif PREPROCWRITE}
  1895. 'M' :
  1896. begin
  1897. more:=Upper(more);
  1898. if not SetCompileMode(more, true) then
  1899. if not SetCompileModeSwitch(more, true) then
  1900. IllegalPara(opt);
  1901. end;
  1902. 'n' :
  1903. begin
  1904. if More='' then
  1905. disable_configfile:=true
  1906. else
  1907. IllegalPara(opt);
  1908. end;
  1909. 'o' :
  1910. begin
  1911. if More<>'' then
  1912. begin
  1913. DefaultReplacements(More);
  1914. D:=ExtractFilePath(More);
  1915. if (D<>'') then
  1916. OutputExeDir:=FixPath(D,True);
  1917. OutputFileName:=ExtractFileName(More);
  1918. end
  1919. else
  1920. IllegalPara(opt);
  1921. end;
  1922. 'O' :
  1923. begin
  1924. j:=1;
  1925. while j<=length(more) do
  1926. begin
  1927. case more[j] of
  1928. '1' :
  1929. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1930. '2' :
  1931. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1932. '3' :
  1933. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1934. '4' :
  1935. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  1936. 'a' :
  1937. begin
  1938. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1939. IllegalPara(opt);
  1940. break;
  1941. end;
  1942. 's' :
  1943. include(init_settings.optimizerswitches,cs_opt_size);
  1944. 'p' :
  1945. begin
  1946. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1947. begin
  1948. OptCPUSetExplicitly:=true;
  1949. { Give warning for old i386 switches }
  1950. if (Length(More)-j=1) and
  1951. (More[j+1]>='1') and (More[j+1]<='5')then
  1952. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1953. else
  1954. IllegalPara(opt);
  1955. end;
  1956. break;
  1957. end;
  1958. 'o' :
  1959. begin
  1960. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  1961. IllegalPara(opt);
  1962. break;
  1963. end;
  1964. '-' :
  1965. begin
  1966. init_settings.optimizerswitches:=[];
  1967. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1968. end;
  1969. { Obsolete switches }
  1970. 'g' :
  1971. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  1972. 'G' :
  1973. Message1(option_obsolete_switch,'-OG');
  1974. 'r' :
  1975. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  1976. 'u' :
  1977. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  1978. 'w' :
  1979. begin
  1980. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  1981. IllegalPara(opt);
  1982. break;
  1983. end;
  1984. 'W' :
  1985. begin
  1986. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  1987. IllegalPara(opt);
  1988. break;
  1989. end;
  1990. else
  1991. IllegalPara(opt);
  1992. end;
  1993. inc(j);
  1994. end;
  1995. end;
  1996. 'p' :
  1997. begin
  1998. if UnsetBool(More, 0, opt, false) then
  1999. begin
  2000. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  2001. undef_system_macro('FPC_PROFILE');
  2002. end
  2003. else
  2004. if Length(More)=0 then
  2005. IllegalPara(opt)
  2006. else
  2007. case more[1] of
  2008. 'g' : if UnsetBool(more, 1, opt, false) then
  2009. begin
  2010. exclude(init_settings.moduleswitches,cs_profile);
  2011. undef_system_macro('FPC_PROFILE');
  2012. end
  2013. else if (target_info.system in supported_targets_pg) then
  2014. begin
  2015. include(init_settings.moduleswitches,cs_profile);
  2016. def_system_macro('FPC_PROFILE');
  2017. end
  2018. else
  2019. UnsupportedPara('-pg');
  2020. else
  2021. IllegalPara(opt);
  2022. end;
  2023. end;
  2024. 'P' :
  2025. begin
  2026. { used to select the target processor with the "fpc" binary;
  2027. give an error if it's not the target architecture supported by
  2028. this compiler binary (will be verified after the target_info
  2029. is set) }
  2030. processorstr:=More;
  2031. end;
  2032. 'R' :
  2033. begin
  2034. if not SetAsmReadMode(More,init_settings.asmmode) then
  2035. IllegalPara(opt);
  2036. end;
  2037. 's' :
  2038. begin
  2039. if UnsetBool(More, 0, opt, false) then
  2040. begin
  2041. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  2042. if more<>'' then
  2043. IllegalPara(opt);
  2044. end
  2045. else
  2046. begin
  2047. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  2048. if more='h' then
  2049. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target,cs_assemble_on_target]
  2050. else if more='t' then
  2051. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target,cs_assemble_on_target]
  2052. else if more='T' then
  2053. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]-[cs_asm_extern]
  2054. else if more='r' then
  2055. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  2056. else if more<>'' then
  2057. IllegalPara(opt);
  2058. end;
  2059. end;
  2060. 'S' :
  2061. begin
  2062. if more='' then
  2063. IllegalPara(opt);
  2064. if more[1]='I' then
  2065. begin
  2066. {$ifdef jvm}
  2067. UnsupportedPara('-SI');
  2068. {$endif}
  2069. if upper(more)='ICOM' then
  2070. init_settings.interfacetype:=it_interfacecom
  2071. else if upper(more)='ICORBA' then
  2072. init_settings.interfacetype:=it_interfacecorba
  2073. else
  2074. IllegalPara(opt);
  2075. end
  2076. else
  2077. begin
  2078. j:=1;
  2079. while j<=length(more) do
  2080. begin
  2081. case more[j] of
  2082. '2' : //an alternative to -Mobjfpc
  2083. SetCompileMode('OBJFPC',true);
  2084. 'a' :
  2085. If UnsetBool(More, j, opt, false) then
  2086. exclude(init_settings.localswitches,cs_do_assertion)
  2087. else
  2088. include(init_settings.localswitches,cs_do_assertion);
  2089. 'c' :
  2090. If UnsetBool(More, j, opt, false) then
  2091. exclude(init_settings.moduleswitches,cs_support_c_operators)
  2092. else
  2093. include(init_settings.moduleswitches,cs_support_c_operators);
  2094. 'C':
  2095. If UnsetBool(More, j, opt, false) then
  2096. exclude(init_settings.localswitches,cs_check_all_case_coverage)
  2097. else
  2098. include(init_settings.localswitches,cs_check_all_case_coverage);
  2099. 'd' : //an alternative to -Mdelphi
  2100. SetCompileMode('DELPHI',true);
  2101. 'e' :
  2102. begin
  2103. SetErrorFlags(copy(more,j+1,length(more)));
  2104. break;
  2105. end;
  2106. 'f' :
  2107. begin
  2108. if not(cs_compilesystem in init_settings.moduleswitches) then
  2109. Message(option_features_only_for_system_unit);
  2110. inc(j);
  2111. if more[j]='-' then
  2112. begin
  2113. if length(more)>j then
  2114. IllegalPara(opt)
  2115. else
  2116. features:=[];
  2117. end
  2118. else
  2119. begin
  2120. if (HandleFeature(upper(copy(more,j,length(more)-j+1)))) then
  2121. j:=length(more)
  2122. else
  2123. IllegalPara(opt);
  2124. end;
  2125. end;
  2126. 'g' :
  2127. If UnsetBool(More, j, opt, false) then
  2128. exclude(init_settings.moduleswitches,cs_support_goto)
  2129. else
  2130. include(init_settings.moduleswitches,cs_support_goto);
  2131. 'h' :
  2132. If UnsetBool(More, j, opt, false) then
  2133. exclude(init_settings.localswitches,cs_refcountedstrings)
  2134. else
  2135. include(init_settings.localswitches,cs_refcountedstrings);
  2136. 'i' :
  2137. If UnsetBool(More, j, opt, false) then
  2138. exclude(init_settings.localswitches,cs_do_inline)
  2139. else
  2140. include(init_settings.localswitches,cs_do_inline);
  2141. 'j' :
  2142. If UnsetBool(More, j, opt, false) then
  2143. exclude(init_settings.localswitches,cs_typed_const_writable)
  2144. else
  2145. include(init_settings.localswitches,cs_typed_const_writable);
  2146. 'k' :
  2147. If UnsetBool(More, j, opt, false) then
  2148. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  2149. else
  2150. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  2151. 'm' :
  2152. If UnsetBool(More, j, opt, false) then
  2153. exclude(init_settings.moduleswitches,cs_support_macro)
  2154. else
  2155. include(init_settings.moduleswitches,cs_support_macro);
  2156. 'o' : //an alternative to -Mtp
  2157. SetCompileMode('TP',true);
  2158. 'r' :
  2159. If UnsetBool(More, j, opt, false) then
  2160. exclude(init_settings.globalswitches,cs_transparent_file_names)
  2161. else
  2162. include(init_settings.globalswitches,cs_transparent_file_names);
  2163. {$ifdef gpc_mode}
  2164. 'p' : //an alternative to -Mgpc
  2165. SetCompileMode('GPC',true);
  2166. {$endif}
  2167. 's' :
  2168. If UnsetBool(More, j, opt, false) then
  2169. exclude(init_settings.globalswitches,cs_constructor_name)
  2170. else
  2171. include(init_settings.globalswitches,cs_constructor_name);
  2172. 't' :
  2173. Message1(option_obsolete_switch,'-St');
  2174. 'v' :
  2175. If UnsetBool(More, j, opt, false) then
  2176. exclude(init_settings.globalswitches,cs_support_vectors)
  2177. else
  2178. include(init_settings.globalswitches,cs_support_vectors);
  2179. 'x' :
  2180. If UnsetBool(More, j, opt, false) then
  2181. SetCompileModeSwitch('EXCEPTIONS-',true)
  2182. else
  2183. SetCompileModeSwitch('EXCEPTIONS',true);
  2184. 'y' :
  2185. If UnsetBool(More, j, opt, false) then
  2186. exclude(init_settings.localswitches,cs_typed_addresses)
  2187. else
  2188. include(init_settings.localswitches,cs_typed_addresses);
  2189. '-' :
  2190. begin
  2191. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  2192. cs_support_vectors,cs_load_fpcylix_unit];
  2193. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  2194. cs_typed_addresses];
  2195. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  2196. cs_support_macro];
  2197. end;
  2198. else
  2199. IllegalPara(opt);
  2200. end;
  2201. inc(j);
  2202. end;
  2203. end;
  2204. end;
  2205. 'T' :
  2206. begin
  2207. more:=Upper(More);
  2208. if paratarget=system_none then
  2209. begin
  2210. { remove old target define }
  2211. TargetOptions(false);
  2212. { load new target }
  2213. paratarget:=find_system_by_string(More);
  2214. if paratarget<>system_none then
  2215. set_target(paratarget)
  2216. else
  2217. IllegalPara(opt);
  2218. { set new define }
  2219. TargetOptions(true);
  2220. end
  2221. else
  2222. if More<>upper(target_info.shortname) then
  2223. Message1(option_target_is_already_set,target_info.shortname);
  2224. end;
  2225. 'u' :
  2226. if is_identifier(more) then
  2227. undef_system_macro(more)
  2228. else
  2229. begin
  2230. if (more='') then
  2231. Message1(option_missing_arg,'-u')
  2232. else
  2233. Message1(option_malformed_para,opt);
  2234. StopOptions(1);
  2235. end;
  2236. 'U' :
  2237. begin
  2238. j:=1;
  2239. while j<=length(more) do
  2240. begin
  2241. case more[j] of
  2242. {$ifdef UNITALIASES}
  2243. 'a' :
  2244. begin
  2245. AddUnitAlias(Copy(More,j+1,255));
  2246. break;
  2247. end;
  2248. {$endif UNITALIASES}
  2249. 'n' :
  2250. exclude(init_settings.globalswitches,cs_check_unit_name);
  2251. 'p' :
  2252. begin
  2253. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  2254. break;
  2255. end;
  2256. 'r' :
  2257. begin
  2258. do_release:=true;
  2259. if (cs_checkpointer in init_settings.localswitches) then
  2260. begin
  2261. Message(option_gc_incompatible_with_release_flag);
  2262. exclude(init_settings.localswitches,cs_checkpointer);
  2263. end;
  2264. end;
  2265. 's' :
  2266. include(init_settings.moduleswitches,cs_compilesystem);
  2267. '-' :
  2268. begin
  2269. exclude(init_settings.moduleswitches,cs_compilesystem);
  2270. exclude(init_settings.globalswitches,cs_check_unit_name);
  2271. end;
  2272. else
  2273. IllegalPara(opt);
  2274. end;
  2275. inc(j);
  2276. end;
  2277. end;
  2278. 'v' :
  2279. begin
  2280. if not setverbosity(More) then
  2281. IllegalPara(opt);
  2282. end;
  2283. 'V' : ; { Ignore used by fpc }
  2284. 'W' :
  2285. begin
  2286. j:=1;
  2287. while j<=length(More) do
  2288. begin
  2289. case More[j] of
  2290. 'A':
  2291. begin
  2292. if target_info.system in systems_all_windows then
  2293. begin
  2294. if UnsetBool(More, j, opt, false) then
  2295. SetApptype(app_cui)
  2296. else
  2297. SetApptype(app_native);
  2298. end
  2299. else
  2300. IllegalPara(opt);
  2301. end;
  2302. 'b':
  2303. begin
  2304. if target_info.system in systems_darwin then
  2305. begin
  2306. if UnsetBool(More, j, opt, false) then
  2307. SetApptype(app_cui)
  2308. else
  2309. SetApptype(app_bundle)
  2310. end
  2311. else
  2312. IllegalPara(opt);
  2313. end;
  2314. 'B':
  2315. begin
  2316. if target_info.system in systems_all_windows+systems_symbian+[system_z80_zxspectrum] then
  2317. begin
  2318. { -WB200000 means set trefered base address
  2319. to $200000, but does not change relocsection boolean
  2320. this way we can create both relocatble and
  2321. non relocatable DLL at a specific base address PM }
  2322. if (length(More)>j) then
  2323. begin
  2324. val('$'+Copy(More,j+1,255),imagebase,code);
  2325. if code<>0 then
  2326. IllegalPara(opt);
  2327. ImageBaseSetExplicity:=true;
  2328. end
  2329. else
  2330. begin
  2331. RelocSection:=true;
  2332. RelocSectionSetExplicitly:=true;
  2333. end;
  2334. break;
  2335. end
  2336. else
  2337. IllegalPara(opt);
  2338. end;
  2339. 'C':
  2340. begin
  2341. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2342. begin
  2343. if UnsetBool(More, j, opt, false) then
  2344. SetApptype(app_gui)
  2345. else
  2346. SetApptype(app_cui);
  2347. end
  2348. else
  2349. IllegalPara(opt);
  2350. end;
  2351. 'D':
  2352. begin
  2353. if target_info.system in systems_all_windows then
  2354. begin
  2355. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2356. UseDeffileForExportsSetExplicitly:=true;
  2357. end
  2358. else
  2359. IllegalPara(opt);
  2360. end;
  2361. 'e':
  2362. begin
  2363. if (target_info.system in systems_darwin) then
  2364. begin
  2365. set_target_res(res_ext);
  2366. target_info.resobjext:='.fpcres';
  2367. end
  2368. else
  2369. IllegalPara(opt);
  2370. end;
  2371. 'F':
  2372. begin
  2373. if target_info.system in systems_os2 then
  2374. begin
  2375. if UnsetBool(More, j, opt, false) then
  2376. SetApptype(app_cui)
  2377. else
  2378. SetApptype(app_fs);
  2379. end
  2380. else
  2381. IllegalPara(opt);
  2382. end;
  2383. 'G':
  2384. begin
  2385. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2386. begin
  2387. if UnsetBool(More, j, opt, false) then
  2388. SetApptype(app_cui)
  2389. else
  2390. SetApptype(app_gui);
  2391. end
  2392. else
  2393. IllegalPara(opt);
  2394. end;
  2395. {$if defined(i8086)}
  2396. 'h':
  2397. begin
  2398. if UnsetBool(More, j, opt, false) then
  2399. exclude(init_settings.moduleswitches,cs_huge_code)
  2400. else
  2401. include(init_settings.moduleswitches,cs_huge_code);
  2402. end;
  2403. {$endif defined(i8086)}
  2404. 'I':
  2405. begin
  2406. if target_info.system in systems_all_windows then
  2407. begin
  2408. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2409. GenerateImportSectionSetExplicitly:=true;
  2410. end
  2411. else
  2412. IllegalPara(opt);
  2413. end;
  2414. 'i':
  2415. begin
  2416. if (target_info.system in systems_darwin) then
  2417. begin
  2418. set_target_res(res_macho);
  2419. target_info.resobjext:=
  2420. targetinfos[target_info.system]^.resobjext;
  2421. end
  2422. else
  2423. IllegalPara(opt);
  2424. end;
  2425. 'm':
  2426. begin
  2427. {$if defined(i8086)}
  2428. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  2429. begin
  2430. case Upper(Copy(More,j+1,255)) of
  2431. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2432. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2433. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2434. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2435. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2436. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2437. else
  2438. IllegalPara(opt);
  2439. end;
  2440. break;
  2441. end
  2442. else
  2443. {$endif defined(i8086)}
  2444. IllegalPara(opt);
  2445. end;
  2446. 'M':
  2447. begin
  2448. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim])) and
  2449. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2450. begin
  2451. break;
  2452. end
  2453. else
  2454. IllegalPara(opt);
  2455. end;
  2456. 'N':
  2457. begin
  2458. if target_info.system in systems_all_windows then
  2459. begin
  2460. RelocSection:=UnsetBool(More,j,opt,false);
  2461. RelocSectionSetExplicitly:=true;
  2462. end
  2463. else
  2464. IllegalPara(opt);
  2465. end;
  2466. 'p':
  2467. begin
  2468. {$push}
  2469. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  2470. if ((target_info.system in systems_embedded) or (target_info.system in systems_freertos)) and
  2471. ControllerSupport then
  2472. begin
  2473. s:=upper(copy(more,j+1,length(more)-j));
  2474. if not(SetControllerType(s,init_settings.controllertype)) then
  2475. IllegalPara(opt)
  2476. else
  2477. begin
  2478. if init_settings.cputype<>embedded_controllers[init_settings.controllertype].cputype then
  2479. begin
  2480. Message(scan_n_changecputype);
  2481. init_settings.cputype:=embedded_controllers[init_settings.controllertype].cputype;
  2482. end;
  2483. end;
  2484. break;
  2485. end
  2486. else
  2487. IllegalPara(opt);
  2488. {$pop}
  2489. end;
  2490. 'P':
  2491. begin
  2492. if (target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim]) and
  2493. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2494. begin
  2495. break;
  2496. end
  2497. else
  2498. IllegalPara(opt);
  2499. end;
  2500. {$if defined(m68k)}
  2501. 'Q':
  2502. begin
  2503. if (target_info.system in [system_m68k_sinclairql]) then
  2504. begin
  2505. sinclairql_metadata_format:=Upper(Copy(More,j+1,255));
  2506. case sinclairql_metadata_format of
  2507. 'QHDR', 'XTCC': ; { allowed formats }
  2508. else
  2509. IllegalPara(opt);
  2510. end;
  2511. break;
  2512. end
  2513. else
  2514. IllegalPara(opt);
  2515. end;
  2516. {$endif defined(m68k)}
  2517. 'R':
  2518. begin
  2519. if target_info.system in systems_all_windows then
  2520. begin
  2521. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2522. RelocSection:=not UnsetBool(More,j,opt,false);
  2523. RelocSectionSetExplicitly:=true;
  2524. end
  2525. else
  2526. IllegalPara(opt);
  2527. end;
  2528. 't':
  2529. begin
  2530. {$if defined(i8086)}
  2531. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  2532. begin
  2533. case Upper(Copy(More,j+1,255)) of
  2534. 'EXE': SetAppType(app_cui);
  2535. 'COM': SetAppType(app_com);
  2536. else
  2537. IllegalPara(opt);
  2538. end;
  2539. break;
  2540. end
  2541. else
  2542. {$endif defined(i8086)}
  2543. IllegalPara(opt);
  2544. end;
  2545. 'T':
  2546. begin
  2547. if target_info.system in systems_macos then
  2548. begin
  2549. if UnsetBool(More, j, opt, false) then
  2550. SetApptype(app_cui)
  2551. else
  2552. SetApptype(app_tool);
  2553. end
  2554. else
  2555. IllegalPara(opt);
  2556. end;
  2557. 'X':
  2558. begin
  2559. if (target_info.system in systems_linux) then
  2560. begin
  2561. if UnsetBool(More, j, opt, false) then
  2562. exclude(init_settings.moduleswitches,cs_executable_stack)
  2563. else
  2564. include(init_settings.moduleswitches,cs_executable_stack)
  2565. end
  2566. else
  2567. IllegalPara(opt);
  2568. end;
  2569. else
  2570. IllegalPara(opt);
  2571. end;
  2572. inc(j);
  2573. end;
  2574. end;
  2575. 'X' :
  2576. begin
  2577. j:=1;
  2578. while j<=length(more) do
  2579. begin
  2580. case More[j] of
  2581. '9' :
  2582. begin
  2583. if target_info.system in systems_linux then
  2584. begin
  2585. if UnsetBool(More, j, opt, false) then
  2586. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2587. else
  2588. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2589. end
  2590. else
  2591. IllegalPara(opt);
  2592. end;
  2593. 'a' :
  2594. begin
  2595. If UnsetBool(More, j, opt, false) then
  2596. exclude(init_settings.globalswitches,cs_large)
  2597. else
  2598. include(init_settings.globalswitches,cs_large);
  2599. end;
  2600. 'c' : Cshared:=TRUE;
  2601. 'd' : Dontlinkstdlibpath:=TRUE;
  2602. 'e' :
  2603. begin
  2604. If UnsetBool(More, j, opt, false) then
  2605. exclude(init_settings.globalswitches,cs_link_extern)
  2606. else
  2607. include(init_settings.globalswitches,cs_link_extern);
  2608. end;
  2609. 'f' :
  2610. include(init_settings.globalswitches,cs_link_pthread);
  2611. 'g' :
  2612. begin
  2613. If UnsetBool(More, j, opt, false) then
  2614. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2615. else
  2616. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2617. end;
  2618. 'i' :
  2619. begin
  2620. If UnsetBool(More, j, opt, false) then
  2621. include(init_settings.globalswitches,cs_link_extern)
  2622. else
  2623. exclude(init_settings.globalswitches,cs_link_extern);
  2624. end;
  2625. 'n' :
  2626. begin
  2627. If UnsetBool(More, j, opt, false) then
  2628. exclude(init_settings.globalswitches,cs_link_native)
  2629. else
  2630. include(init_settings.globalswitches,cs_link_native);
  2631. end;
  2632. {$ifdef llvm}
  2633. 'l' :
  2634. begin
  2635. if j=length(more) then
  2636. IllegalPara(opt)
  2637. else
  2638. begin
  2639. case more[j+1] of
  2640. 'S':
  2641. begin
  2642. llvmutilssuffix:=copy(more,j+2,length(more));
  2643. j:=length(more);
  2644. end
  2645. else
  2646. IllegalPara(opt);
  2647. end;
  2648. end;
  2649. end;
  2650. {$endif}
  2651. 'm' :
  2652. begin
  2653. If UnsetBool(More, j, opt, false) then
  2654. exclude(init_settings.globalswitches,cs_link_map)
  2655. else
  2656. include(init_settings.globalswitches,cs_link_map);
  2657. end;
  2658. 'p' : ; { Ignore used by fpc.pp }
  2659. 'r' :
  2660. begin
  2661. if (target_info.system in suppported_targets_x_smallr) then
  2662. begin
  2663. rlinkpath:=Copy(more,2,length(More)-1);
  2664. DefaultReplacements(rlinkpath);
  2665. end
  2666. else
  2667. IgnoredPara('-Xr');
  2668. more:='';
  2669. end;
  2670. 'R' :
  2671. begin
  2672. sysrootpath:=copy(more,2,length(more)-1);
  2673. defaultreplacements(sysrootpath);
  2674. more:='';
  2675. end;
  2676. 's' :
  2677. begin
  2678. If UnsetBool(More, j, opt, false) then
  2679. exclude(init_settings.globalswitches,cs_link_strip)
  2680. else
  2681. include(init_settings.globalswitches,cs_link_strip);
  2682. end;
  2683. 't' :
  2684. include(init_settings.globalswitches,cs_link_staticflag);
  2685. 'u' :
  2686. begin
  2687. if target_info.system in systems_support_uf2 then
  2688. begin
  2689. if UnsetBool(More, j, opt, false) then
  2690. exclude(init_settings.globalswitches,cs_generate_uf2)
  2691. else
  2692. include(init_settings.globalswitches,cs_generate_uf2);
  2693. end
  2694. else
  2695. IgnoredPara('-Xu');
  2696. end;
  2697. 'v' :
  2698. begin
  2699. If UnsetBool(More, j, opt, false) then
  2700. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2701. else
  2702. include(init_settings.globalswitches,cs_link_opt_vtable);
  2703. end;
  2704. 'D' :
  2705. begin
  2706. def_system_macro('FPC_LINK_DYNAMIC');
  2707. undef_system_macro('FPC_LINK_SMART');
  2708. undef_system_macro('FPC_LINK_STATIC');
  2709. exclude(init_settings.globalswitches,cs_link_static);
  2710. exclude(init_settings.globalswitches,cs_link_smart);
  2711. include(init_settings.globalswitches,cs_link_shared);
  2712. LinkTypeSetExplicitly:=true;
  2713. end;
  2714. 'M' :
  2715. begin
  2716. mainaliasname:=Copy(more,2,length(More)-1);
  2717. More:='';
  2718. end;
  2719. 'P' :
  2720. begin
  2721. utilsprefix:=Copy(more,2,length(More)-1);
  2722. DefaultReplacements(utilsprefix);
  2723. More:='';
  2724. end;
  2725. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2726. // these are not aggregable.
  2727. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2728. IllegalPara(opt)
  2729. else
  2730. begin
  2731. case more[j+1] of
  2732. 'A' : begin
  2733. s:=Copy(more,3,length(More)-2);
  2734. if not LinkLibraryAliases.AddDep(s) Then
  2735. IllegalPara(opt);
  2736. end;
  2737. 'O' : begin
  2738. s:=Copy(more,3,length(More)-2);
  2739. if not LinkLibraryOrder.AddWeight(s) Then
  2740. IllegalPara(opt);
  2741. end;
  2742. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2743. else
  2744. IllegalPara(opt);
  2745. end; {case}
  2746. j:=length(more);
  2747. end; {else begin}
  2748. end;
  2749. 'S' :
  2750. begin
  2751. ForceStaticLinking;
  2752. end;
  2753. 'V' :
  2754. begin
  2755. if UnsetBool(More, j, opt, false) then
  2756. exclude(init_settings.globalswitches,cs_link_vlink)
  2757. else
  2758. begin
  2759. include(init_settings.globalswitches,cs_link_vlink);
  2760. include(init_settings.globalswitches,cs_link_extern);
  2761. end;
  2762. LinkerSetExplicitly:=true;
  2763. end;
  2764. 'X' :
  2765. begin
  2766. def_system_macro('FPC_LINK_SMART');
  2767. undef_system_macro('FPC_LINK_STATIC');
  2768. undef_system_macro('FPC_LINK_DYNAMIC');
  2769. exclude(init_settings.globalswitches,cs_link_static);
  2770. include(init_settings.globalswitches,cs_link_smart);
  2771. exclude(init_settings.globalswitches,cs_link_shared);
  2772. LinkTypeSetExplicitly:=true;
  2773. end;
  2774. '-' :
  2775. begin
  2776. exclude(init_settings.globalswitches,cs_link_staticflag);
  2777. exclude(init_settings.globalswitches,cs_link_strip);
  2778. exclude(init_settings.globalswitches,cs_link_map);
  2779. set_default_link_type;
  2780. end;
  2781. else
  2782. IllegalPara(opt);
  2783. end;
  2784. inc(j);
  2785. end;
  2786. end;
  2787. else
  2788. IllegalPara(opt);
  2789. end;
  2790. end;
  2791. '@' :
  2792. begin
  2793. Message(option_no_nested_response_file);
  2794. StopOptions(1);
  2795. end;
  2796. else
  2797. begin
  2798. if (length(param_file)<>0) then
  2799. Message2(option_only_one_source_support,param_file,opt);
  2800. param_file:=opt;
  2801. Message1(option_found_file,opt);
  2802. end;
  2803. end;
  2804. end;
  2805. procedure Toption.Interpret_file(const filename : TPathStr);
  2806. procedure RemoveSep(var fn:TPathStr);
  2807. var
  2808. i : longint;
  2809. begin
  2810. i:=0;
  2811. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2812. inc(i);
  2813. Delete(fn,1,i);
  2814. i:=length(fn);
  2815. while (i>0) and (fn[i] in [',',' ',#9]) do
  2816. dec(i);
  2817. fn:=copy(fn,1,i);
  2818. end;
  2819. function GetName(var fn:TPathStr):TPathStr;
  2820. var
  2821. i : longint;
  2822. begin
  2823. i:=0;
  2824. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2825. inc(i);
  2826. GetName:=Copy(fn,1,i);
  2827. Delete(fn,1,i);
  2828. end;
  2829. const
  2830. maxlevel = 15;
  2831. var
  2832. f : text;
  2833. s, tmp,
  2834. opts : TCmdStr;
  2835. skip : array[0..maxlevel] of boolean;
  2836. line,
  2837. level : longint;
  2838. option_read : boolean;
  2839. oldfilemode : byte;
  2840. ConfigFile: TPathStr;
  2841. begin
  2842. { avoid infinite loop }
  2843. Inc(FileLevel);
  2844. Option_read:=false;
  2845. If FileLevel>MaxLevel then
  2846. Message(option_too_many_cfg_files);
  2847. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2848. ConfigFile := ExpandFileName(filename);
  2849. { Maybe It's Directory ?} //Jaro Change:
  2850. if PathExists(ConfigFile,false) then
  2851. begin
  2852. Message1(option_config_is_dir,filename);
  2853. exit;
  2854. end;
  2855. { open file }
  2856. Message1(option_using_file,filename);
  2857. oldfilemode:=filemode;
  2858. filemode:=0;
  2859. assign(f,ConfigFile);
  2860. {$push}{$I-}
  2861. reset(f);
  2862. {$pop}
  2863. filemode:=oldfilemode;
  2864. if ioresult<>0 then
  2865. begin
  2866. Message1(option_unable_open_file,filename);
  2867. exit;
  2868. end;
  2869. Message1(option_start_reading_configfile,filename);
  2870. fillchar(skip,sizeof(skip),0);
  2871. level:=0;
  2872. line:=0;
  2873. while not eof(f) do
  2874. begin
  2875. readln(f,opts);
  2876. inc(line);
  2877. RemoveSep(opts);
  2878. if (opts<>'') and (opts[1]<>';') then
  2879. begin
  2880. if opts[1]='#' then
  2881. begin
  2882. Message1(option_interpreting_file_option,opts);
  2883. Delete(opts,1,1);
  2884. s:=upper(GetName(opts));
  2885. if (s='SECTION') then
  2886. begin
  2887. RemoveSep(opts);
  2888. s:=upper(GetName(opts));
  2889. if level=0 then
  2890. skip[level]:=not defined_macro(s) or (s='COMMON');
  2891. end
  2892. else
  2893. if (s='IFDEF') then
  2894. begin
  2895. RemoveSep(opts);
  2896. if Level>=maxlevel then
  2897. begin
  2898. Message2(option_too_many_ifdef,filename,tostr(line));
  2899. stopOptions(1);
  2900. end;
  2901. inc(Level);
  2902. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2903. end
  2904. else
  2905. if (s='IFNDEF') then
  2906. begin
  2907. RemoveSep(opts);
  2908. if Level>=maxlevel then
  2909. begin
  2910. Message2(option_too_many_ifdef,filename,tostr(line));
  2911. stopOptions(1);
  2912. end;
  2913. inc(Level);
  2914. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2915. end
  2916. else
  2917. if (s='ELSE') then
  2918. begin
  2919. if Level=0 then
  2920. begin
  2921. Message2(option_else_without_if,filename,tostr(line));
  2922. stopOptions(1);
  2923. end
  2924. else
  2925. skip[level]:=skip[level-1] or (not skip[level])
  2926. end
  2927. else
  2928. if (s='ENDIF') then
  2929. begin
  2930. skip[level]:=false;
  2931. if Level=0 then
  2932. begin
  2933. Message2(option_too_many_endif,filename,tostr(line));
  2934. stopOptions(1);
  2935. end;
  2936. dec(level);
  2937. end
  2938. else
  2939. if (not skip[level]) then
  2940. begin
  2941. if (s='DEFINE') then
  2942. begin
  2943. RemoveSep(opts);
  2944. tmp:= GetName(opts);
  2945. if tmp <> '' then
  2946. def_system_macro(tmp);
  2947. Option_read:=true;
  2948. end
  2949. else
  2950. if (s='UNDEF') then
  2951. begin
  2952. RemoveSep(opts);
  2953. tmp:= GetName(opts);
  2954. if tmp <> '' then
  2955. undef_system_macro(tmp);
  2956. Option_read:=true;
  2957. end
  2958. else
  2959. if (s='WRITE') then
  2960. begin
  2961. Delete(opts,1,1);
  2962. DefaultReplacements(opts);
  2963. WriteLn(opts);
  2964. Option_read:=true;
  2965. end
  2966. else
  2967. if (s='INCLUDE') then
  2968. begin
  2969. Delete(opts,1,1);
  2970. DefaultReplacements(opts);
  2971. Interpret_file(opts);
  2972. Option_read:=true;
  2973. end
  2974. else
  2975. if (s='CFGDIR') then
  2976. begin
  2977. Delete(opts,1,1);
  2978. DefaultReplacements(opts);
  2979. ParaIncludeCfgPath.AddPath(opts,false);
  2980. Option_read:=true;
  2981. end;
  2982. end;
  2983. end
  2984. else
  2985. begin
  2986. if (opts[1]='-') or (opts[1]='@') then
  2987. begin
  2988. if (not skip[level]) then
  2989. interpret_option(opts,false);
  2990. Option_read:=true;
  2991. end
  2992. else
  2993. Message1(option_illegal_para,opts);
  2994. end;
  2995. end;
  2996. end;
  2997. if Level>0 then
  2998. Message(option_too_less_endif);
  2999. if Not Option_read then
  3000. Message1(option_no_option_found,filename)
  3001. else
  3002. Message1(option_end_reading_configfile,filename);
  3003. Close(f);
  3004. Dec(FileLevel);
  3005. end;
  3006. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  3007. var
  3008. argstart,
  3009. env,
  3010. pc : pchar;
  3011. arglen : longint;
  3012. quote : set of char;
  3013. hs : TCmdStr;
  3014. begin
  3015. Message1(option_using_env,envname);
  3016. env:=GetEnvPChar(envname);
  3017. pc:=env;
  3018. hs:='';
  3019. if assigned(pc) then
  3020. begin
  3021. repeat
  3022. { skip leading spaces }
  3023. while pc^ in [' ',#9,#13] do
  3024. inc(pc);
  3025. case pc^ of
  3026. #0 :
  3027. break;
  3028. '"' :
  3029. begin
  3030. quote:=['"'];
  3031. inc(pc);
  3032. end;
  3033. '''' :
  3034. begin
  3035. quote:=[''''];
  3036. inc(pc);
  3037. end;
  3038. else
  3039. quote:=[' ',#9,#13];
  3040. end;
  3041. { scan until the end of the argument }
  3042. argstart:=pc;
  3043. while (pc^<>#0) and not(pc^ in quote) do
  3044. inc(pc);
  3045. { create argument }
  3046. arglen:=pc-argstart;
  3047. { TODO: FIXME: silent truncation of environment parameters }
  3048. if (arglen > 255) then
  3049. arglen := 255;
  3050. setlength(hs,arglen);
  3051. move(argstart^,hs[1],arglen);
  3052. interpret_option(hs,true);
  3053. { skip quote }
  3054. if pc^ in quote then
  3055. inc(pc);
  3056. until false;
  3057. end
  3058. else
  3059. Message1(option_no_option_found,'(env) '+envname);
  3060. FreeEnvPChar(env);
  3061. end;
  3062. procedure toption.read_parameters;
  3063. var
  3064. opts : TCmdStr;
  3065. paramindex : longint;
  3066. begin
  3067. paramindex:=0;
  3068. while paramindex<paramcount do
  3069. begin
  3070. inc(paramindex);
  3071. opts:=objpas.paramstr(paramindex);
  3072. if length(opts)>0 then
  3073. case opts[1] of
  3074. '@' :
  3075. if not firstpass then
  3076. begin
  3077. Delete(opts,1,1);
  3078. Message1(option_reading_further_from,opts);
  3079. interpret_file(opts);
  3080. end;
  3081. '!' :
  3082. if not firstpass then
  3083. begin
  3084. Delete(opts,1,1);
  3085. Message1(option_reading_further_from,'(env) '+opts);
  3086. interpret_envvar(opts);
  3087. end;
  3088. else
  3089. interpret_option(opts,true);
  3090. end;
  3091. end;
  3092. end;
  3093. procedure toption.parsecmd(cmd:TCmdStr);
  3094. var
  3095. i,ps : longint;
  3096. opts : TCmdStr;
  3097. begin
  3098. while (cmd<>'') do
  3099. begin
  3100. while cmd[1]=' ' do
  3101. delete(cmd,1,1);
  3102. i:=pos(' ',cmd);
  3103. if i=0 then
  3104. i:=2147483647;
  3105. opts:=Copy(cmd,1,i-1);
  3106. Delete(cmd,1,i);
  3107. case opts[1] of
  3108. '@' :
  3109. if not firstpass then
  3110. begin
  3111. Delete(opts,1,1);
  3112. Message1(option_reading_further_from,opts);
  3113. interpret_file(opts);
  3114. end;
  3115. '!' :
  3116. if not firstpass then
  3117. begin
  3118. Delete(opts,1,1);
  3119. Message1(option_reading_further_from,'(env) '+opts);
  3120. interpret_envvar(opts);
  3121. end;
  3122. '"' :
  3123. begin
  3124. Delete(opts,1,1);
  3125. ps:=pos('"',cmd);
  3126. if (i<>256) and (ps>0) then
  3127. begin
  3128. opts:=opts + ' '+ copy(cmd,1,ps-1);
  3129. cmd:=copy(cmd,ps+1,255);
  3130. end;
  3131. interpret_option(opts,true);
  3132. end;
  3133. else
  3134. interpret_option(opts,true);
  3135. end;
  3136. end;
  3137. end;
  3138. procedure toption.writequickinfo;
  3139. var
  3140. s : string;
  3141. i : longint;
  3142. procedure addinfo(const hs:string);
  3143. begin
  3144. if s<>'' then
  3145. s:=s+' '+hs
  3146. else
  3147. s:=hs;
  3148. end;
  3149. begin
  3150. s:='';
  3151. i:=0;
  3152. while (i<length(quickinfo)) do
  3153. begin
  3154. inc(i);
  3155. case quickinfo[i] of
  3156. 'S' :
  3157. begin
  3158. inc(i);
  3159. case quickinfo[i] of
  3160. 'O' :
  3161. addinfo(lower(source_info.shortname));
  3162. 'P' :
  3163. addinfo(source_cpu_string);
  3164. else
  3165. IllegalPara('-i'+QuickInfo);
  3166. end;
  3167. end;
  3168. 'T' :
  3169. begin
  3170. inc(i);
  3171. case quickinfo[i] of
  3172. 'O' :
  3173. addinfo(lower(target_info.shortname));
  3174. 'P' :
  3175. AddInfo(target_cpu_string);
  3176. else
  3177. IllegalPara('-i'+QuickInfo);
  3178. end;
  3179. end;
  3180. 'V' :
  3181. AddInfo(version_string);
  3182. 'W' :
  3183. AddInfo(full_version_string);
  3184. 'D' :
  3185. AddInfo(date_string);
  3186. '_' :
  3187. ;
  3188. else
  3189. IllegalPara('-i'+QuickInfo);
  3190. end;
  3191. end;
  3192. if s<>'' then
  3193. begin
  3194. writeln(s);
  3195. stopoptions(0);
  3196. end;
  3197. end;
  3198. procedure TOption.TargetOptions(def:boolean);
  3199. var
  3200. s : string;
  3201. i : integer;
  3202. target_unsup_features : tfeatures;
  3203. begin
  3204. if def then
  3205. def_system_macro(target_info.shortname)
  3206. else
  3207. undef_system_macro(target_info.shortname);
  3208. s:=target_info.extradefines;
  3209. while (s<>'') do
  3210. begin
  3211. i:=pos(';',s);
  3212. if i=0 then
  3213. i:=length(s)+1;
  3214. if def then
  3215. def_system_macro(Copy(s,1,i-1))
  3216. else
  3217. undef_system_macro(Copy(s,1,i-1));
  3218. delete(s,1,i);
  3219. end;
  3220. if (tf_winlikewidestring in target_info.flags) then
  3221. if def then
  3222. def_system_macro('FPC_WINLIKEWIDESTRING')
  3223. else
  3224. undef_system_macro('FPC_WINLIKEWIDESTRING');
  3225. if (tf_requires_proper_alignment in target_info.flags) then
  3226. if def then
  3227. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  3228. else
  3229. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3230. if (tf_init_final_units_by_calls in target_info.flags) then
  3231. if def then
  3232. def_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS')
  3233. else
  3234. undef_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS');
  3235. if source_info.system<>target_info.system then
  3236. if def then
  3237. def_system_macro('FPC_CROSSCOMPILING')
  3238. else
  3239. undef_system_macro('FPC_CROSSCOMPILING');
  3240. if source_info.cpu<>target_info.cpu then
  3241. if def then
  3242. def_system_macro('FPC_CPUCROSSCOMPILING')
  3243. else
  3244. def_system_macro('FPC_CPUCROSSCOMPILING');
  3245. if (tf_no_generic_stackcheck in target_info.flags) then
  3246. if def then
  3247. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  3248. else
  3249. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  3250. if (tf_section_threadvars in target_info.flags) then
  3251. if def then
  3252. def_system_macro('FPC_SECTION_THREADVARS')
  3253. else
  3254. undef_system_macro('FPC_SECTION_THREADVARS');
  3255. if (tf_use_psabieh in target_info.flags) then
  3256. if def then
  3257. def_system_macro('FPC_USE_PSABIEH')
  3258. else
  3259. undef_system_macro('FPC_USE_PSABIEH');
  3260. { Code generation flags }
  3261. if (tf_pic_default in target_info.flags) then
  3262. if def then
  3263. include(init_settings.moduleswitches,cs_create_pic)
  3264. else
  3265. exclude(init_settings.moduleswitches,cs_create_pic);
  3266. { Resources support }
  3267. if (tf_has_winlike_resources in target_info.flags) then
  3268. if def then
  3269. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  3270. else
  3271. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  3272. { Features }
  3273. case target_info.system of
  3274. system_arm_gba:
  3275. target_unsup_features:=[f_dynlibs];
  3276. system_arm_nds:
  3277. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  3278. system_i386_nativent:
  3279. // until these features are implemented, they are disabled in the compiler
  3280. target_unsup_features:=[f_stackcheck];
  3281. system_i8086_msdos:
  3282. target_unsup_features:=[f_threading,f_dynlibs];
  3283. system_i8086_win16:
  3284. target_unsup_features:=[f_threading];
  3285. system_jvm_java32,
  3286. system_jvm_android32:
  3287. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  3288. f_variants,f_objects,f_commandargs,
  3289. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  3290. system_arm_palmos,
  3291. system_m68k_palmos:
  3292. target_unsup_features:=[f_threading];
  3293. system_m68k_atari:
  3294. target_unsup_features:=[f_threading];
  3295. { classic amiga has dynamic libraries, but they cannot be integrated in the
  3296. normal dynlibs infrastructure due to architectural differences, so therefore
  3297. lets disable the feature. }
  3298. system_m68k_amiga:
  3299. target_unsup_features:=[f_dynlibs];
  3300. system_m68k_sinclairql:
  3301. target_unsup_features:=[f_threading,f_dynlibs,f_commandargs,f_exitcode];
  3302. system_z80_zxspectrum:
  3303. target_unsup_features:=[f_threading,f_dynlibs{,f_fileio,f_textio},f_commandargs,f_exitcode];
  3304. system_z80_msxdos:
  3305. target_unsup_features:=[f_threading,f_dynlibs];
  3306. else
  3307. target_unsup_features:=[];
  3308. end;
  3309. if def then
  3310. features:=features-target_unsup_features
  3311. else
  3312. features:=features+target_unsup_features;
  3313. {$if defined(atari) or defined(hasamiga)}
  3314. { enable vlink as default linker on Atari and Amiga but not for cross compilers (for now) }
  3315. if (target_info.system in [system_m68k_amiga,system_m68k_atari,system_powerpc_amiga]) and
  3316. not LinkerSetExplicitly then
  3317. include(init_settings.globalswitches,cs_link_vlink);
  3318. {$endif}
  3319. {$ifdef m68k}
  3320. if (target_info.system in [system_m68k_sinclairql]) and
  3321. not LinkerSetExplicitly then
  3322. include(init_settings.globalswitches,cs_link_vlink);
  3323. {$endif m68k}
  3324. end;
  3325. procedure TOption.checkoptionscompatibility;
  3326. begin
  3327. {$ifdef i8086}
  3328. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  3329. begin
  3330. Message(option_com_files_require_tiny_model);
  3331. StopOptions(1);
  3332. end;
  3333. {$endif i8086}
  3334. {$ifndef i8086_link_intern_debuginfo}
  3335. if (cs_debuginfo in init_settings.moduleswitches) and
  3336. (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) and
  3337. not (cs_link_extern in init_settings.globalswitches) then
  3338. begin
  3339. Message(option_debug_info_requires_external_linker);
  3340. include(init_settings.globalswitches,cs_link_extern);
  3341. end;
  3342. {$endif i8086_link_intern_debuginfo}
  3343. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  3344. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  3345. begin
  3346. { smartlink creation does not yet work with DWARF
  3347. debug info on most targets, but it works in internal assembler }
  3348. if (cs_create_smart in init_settings.moduleswitches) and
  3349. not (af_outputbinary in target_asm.flags) then
  3350. begin
  3351. Message(option_dwarf_smartlink_creation);
  3352. exclude(init_settings.moduleswitches,cs_create_smart);
  3353. end;
  3354. { smart linking does not yet work with DWARF debug info on most targets }
  3355. if (cs_link_smart in init_settings.globalswitches) then
  3356. begin
  3357. Message(option_dwarf_smart_linking);
  3358. ForceStaticLinking;
  3359. end;
  3360. end;
  3361. { external debug info is only supported for DWARF on darwin }
  3362. if (target_info.system in systems_darwin) and
  3363. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  3364. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  3365. begin
  3366. Message(option_debug_external_unsupported);
  3367. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  3368. end;
  3369. { Also create a smartlinked version, on an assembler that
  3370. does not support smartlink sections like nasm?
  3371. This is not compatible with using internal linker. }
  3372. if ((cs_link_smart in init_settings.globalswitches) or
  3373. (cs_create_smart in init_settings.moduleswitches)) and
  3374. (af_needar in target_asm.flags) and
  3375. not (af_smartlink_sections in target_asm.flags) and
  3376. not (cs_link_extern in init_settings.globalswitches) and
  3377. (target_info.link<>ld_none) and
  3378. not (cs_link_nolink in init_settings.globalswitches) then
  3379. begin
  3380. Message(option_smart_link_requires_external_linker);
  3381. include(init_settings.globalswitches,cs_link_extern);
  3382. end;
  3383. end;
  3384. constructor TOption.create;
  3385. begin
  3386. LogoWritten:=false;
  3387. NoPressEnter:=false;
  3388. FirstPass:=false;
  3389. ABISetExplicitly:=false;
  3390. FPUSetExplicitly:=false;
  3391. CPUSetExplicitly:=false;
  3392. OptCPUSetExplicitly:=false;
  3393. FileLevel:=0;
  3394. Quickinfo:='';
  3395. ParaIncludeCfgPath:=TSearchPathList.Create;
  3396. ParaIncludePath:=TSearchPathList.Create;
  3397. ParaObjectPath:=TSearchPathList.Create;
  3398. ParaUnitPath:=TSearchPathList.Create;
  3399. ParaLibraryPath:=TSearchPathList.Create;
  3400. ParaFrameworkPath:=TSearchPathList.Create;
  3401. parapackagepath:=TSearchPathList.Create;
  3402. parapackages:=TFPHashObjectList.Create;
  3403. paranamespaces:=TCmdStrList.Create;
  3404. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3405. MacVersionSet:=false;
  3406. paratarget:=system_none;
  3407. paratargetasm:=as_none;
  3408. paratargetdbg:=dbg_none;
  3409. LinkTypeSetExplicitly:=false;
  3410. LinkerSetExplicitly:=false;
  3411. end;
  3412. destructor TOption.destroy;
  3413. begin
  3414. ParaIncludeCfgPath.Free;
  3415. ParaIncludePath.Free;
  3416. ParaObjectPath.Free;
  3417. ParaUnitPath.Free;
  3418. ParaLibraryPath.Free;
  3419. ParaFrameworkPath.Free;
  3420. parapackagepath.Free;
  3421. ParaPackages.Free;
  3422. paranamespaces.free;
  3423. end;
  3424. {****************************************************************************
  3425. Callable Routines
  3426. ****************************************************************************}
  3427. function check_configfile(fn:string; var foundfn:string):boolean;
  3428. function CfgFileExists(const fn:string):boolean;
  3429. begin
  3430. Comment(V_Tried,'Configfile search: '+fn);
  3431. CfgFileExists:=FileExists(fn);
  3432. end;
  3433. var
  3434. {$ifdef Unix}
  3435. hs,
  3436. {$endif Unix}
  3437. configpath : string;
  3438. begin
  3439. foundfn:=fn;
  3440. check_configfile:=true;
  3441. { retrieve configpath }
  3442. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3443. {$ifdef Unix}
  3444. if configpath='' then
  3445. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3446. {$endif}
  3447. {
  3448. Order to read configuration file :
  3449. try reading fpc.cfg in :
  3450. 1 - current dir
  3451. 2 - configpath
  3452. 3 - compiler path
  3453. }
  3454. if not FileExists(fn) then
  3455. begin
  3456. {$ifdef Unix}
  3457. hs:=GetEnvironmentVariable('HOME');
  3458. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3459. foundfn:=FixPath(hs,false)+'.'+fn
  3460. else
  3461. {$endif}
  3462. if CfgFileExists(configpath+fn) then
  3463. foundfn:=configpath+fn
  3464. else
  3465. {$ifdef WINDOWS}
  3466. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3467. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3468. else
  3469. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3470. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3471. else
  3472. {$endif WINDOWS}
  3473. {$ifndef Unix}
  3474. if CfgFileExists(exepath+fn) then
  3475. foundfn:=exepath+fn
  3476. else
  3477. {$else}
  3478. if CfgFileExists('/etc/'+fn) then
  3479. foundfn:='/etc/'+fn
  3480. else
  3481. {$endif}
  3482. check_configfile:=false;
  3483. end;
  3484. end;
  3485. procedure read_arguments(cmd:TCmdStr);
  3486. procedure def_cpu_macros;
  3487. var
  3488. abi : tabi;
  3489. fputype : tfputype;
  3490. cputype : tcputype;
  3491. controller: tcontrollertype;
  3492. s: string;
  3493. begin
  3494. {$ifdef llvm}
  3495. def_system_macro('CPULLVM');
  3496. {$endif}
  3497. for cputype:=low(tcputype) to high(tcputype) do
  3498. undef_system_macro('CPU'+Cputypestr[cputype]);
  3499. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3500. for fputype:=low(tfputype) to high(tfputype) do
  3501. undef_system_macro('FPU'+fputypestr[fputype]);
  3502. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3503. {$PUSH}
  3504. {$WARN 6018 OFF} { Unreachable code due to compile time evaluation }
  3505. if ControllerSupport then
  3506. begin
  3507. for controller:=low(tcontrollertype) to high(tcontrollertype) do
  3508. begin
  3509. s:=embedded_controllers[controller].controllertypestr;
  3510. if s<>'' then
  3511. undef_system_macro('FPC_MCU_'+s);
  3512. end;
  3513. s:=embedded_controllers[init_settings.controllertype].controllertypestr;
  3514. if s<>'' then
  3515. def_system_macro('FPC_MCU_'+s);
  3516. end;
  3517. {$POP}
  3518. { define abi }
  3519. for abi:=low(tabi) to high(tabi) do
  3520. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3521. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3522. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3523. systems since most code needs to behave the same on both}
  3524. if target_info.abi = abi_eabihf then
  3525. def_system_macro('FPC_ABI_EABI');
  3526. { using a case is pretty useless here (FK) }
  3527. { some stuff for TP compatibility }
  3528. {$ifdef i386}
  3529. def_system_macro('CPU86');
  3530. def_system_macro('CPU87');
  3531. def_system_macro('CPU386');
  3532. {$endif}
  3533. { new processor stuff }
  3534. {$ifdef i386}
  3535. def_system_macro('CPUI386');
  3536. def_system_macro('CPU32');
  3537. def_system_macro('CPUX86');
  3538. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3539. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3540. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3541. {$endif}
  3542. {$ifdef m68k}
  3543. def_system_macro('CPU68');
  3544. def_system_macro('CPU68K');
  3545. def_system_macro('CPUM68K');
  3546. def_system_macro('CPU32');
  3547. def_system_macro('FPC_CURRENCY_IS_INT64');
  3548. def_system_macro('FPC_COMP_IS_INT64');
  3549. {$endif}
  3550. {$ifdef powerpc}
  3551. def_system_macro('CPUPOWERPC');
  3552. def_system_macro('CPUPOWERPC32');
  3553. def_system_macro('CPU32');
  3554. def_system_macro('FPC_CURRENCY_IS_INT64');
  3555. def_system_macro('FPC_COMP_IS_INT64');
  3556. {$endif}
  3557. {$ifdef POWERPC64}
  3558. def_system_macro('CPUPOWERPC');
  3559. def_system_macro('CPUPOWERPC64');
  3560. def_system_macro('CPU64');
  3561. def_system_macro('FPC_CURRENCY_IS_INT64');
  3562. def_system_macro('FPC_COMP_IS_INT64');
  3563. {$endif}
  3564. {$ifdef x86_64}
  3565. def_system_macro('CPUX86_64');
  3566. def_system_macro('CPUAMD64');
  3567. def_system_macro('CPU64');
  3568. def_system_macro('CPUX64');
  3569. { not supported for now, afaik (FK)
  3570. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3571. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3572. { normally, win64 doesn't support the legacy fpu }
  3573. if target_info.system=system_x86_64_win64 then
  3574. begin
  3575. def_system_macro('FPC_CURRENCY_IS_INT64');
  3576. def_system_macro('FPC_COMP_IS_INT64');
  3577. end;
  3578. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3579. {$endif}
  3580. {$ifdef sparc}
  3581. def_system_macro('CPUSPARCGEN');
  3582. def_system_macro('CPUSPARC');
  3583. def_system_macro('CPUSPARC32');
  3584. def_system_macro('CPU32');
  3585. def_system_macro('FPC_CURRENCY_IS_INT64');
  3586. def_system_macro('FPC_COMP_IS_INT64');
  3587. {$endif}
  3588. {$ifdef sparc64}
  3589. def_system_macro('CPUSPARCGEN');
  3590. def_system_macro('CPUSPARC64');
  3591. def_system_macro('CPU64');
  3592. def_system_macro('FPC_CURRENCY_IS_INT64');
  3593. def_system_macro('FPC_COMP_IS_INT64');
  3594. {$endif}
  3595. {$ifdef arm}
  3596. def_system_macro('CPUARM');
  3597. def_system_macro('CPU32');
  3598. def_system_macro('FPC_CURRENCY_IS_INT64');
  3599. def_system_macro('FPC_COMP_IS_INT64');
  3600. {$endif arm}
  3601. {$ifdef avr}
  3602. def_system_macro('CPUAVR');
  3603. def_system_macro('CPU16');
  3604. def_system_macro('FPC_CURRENCY_IS_INT64');
  3605. def_system_macro('FPC_COMP_IS_INT64');
  3606. {$endif avr}
  3607. {$ifdef jvm}
  3608. def_system_macro('CPUJVM');
  3609. def_system_macro('CPU32');
  3610. def_system_macro('FPC_CURRENCY_IS_INT64');
  3611. def_system_macro('FPC_COMP_IS_INT64');
  3612. {$endif jvm}
  3613. {$ifdef mipsel}
  3614. def_system_macro('CPUMIPS');
  3615. def_system_macro('CPUMIPS32');
  3616. def_system_macro('CPUMIPSEL');
  3617. def_system_macro('CPUMIPSEL32');
  3618. def_system_macro('CPU32');
  3619. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3620. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3621. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3622. def_system_macro('FPC_CURRENCY_IS_INT64');
  3623. def_system_macro('FPC_COMP_IS_INT64');
  3624. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3625. { On most systems, locals are accessed relative to base pointer,
  3626. but for MIPS cpu, they are accessed relative to stack pointer.
  3627. This needs adaptation for so low level routines,
  3628. like MethodPointerLocal and related objects unit functions. }
  3629. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3630. {$endif mipsel}
  3631. {$ifdef mipseb}
  3632. def_system_macro('CPUMIPS');
  3633. def_system_macro('CPUMIPS32');
  3634. def_system_macro('CPUMIPSEB');
  3635. def_system_macro('CPUMIPSEB32');
  3636. def_system_macro('CPU32');
  3637. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3638. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3639. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3640. def_system_macro('FPC_CURRENCY_IS_INT64');
  3641. def_system_macro('FPC_COMP_IS_INT64');
  3642. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3643. { See comment above for mipsel }
  3644. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3645. {$endif}
  3646. {$ifdef i8086}
  3647. def_system_macro('CPU86'); { Borland compatibility }
  3648. def_system_macro('CPU87'); { Borland compatibility }
  3649. def_system_macro('CPUI8086');
  3650. def_system_macro('CPU16');
  3651. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3652. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3653. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3654. case init_settings.x86memorymodel of
  3655. mm_tiny: def_system_macro('FPC_MM_TINY');
  3656. mm_small: def_system_macro('FPC_MM_SMALL');
  3657. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3658. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3659. mm_large: def_system_macro('FPC_MM_LARGE');
  3660. mm_huge: def_system_macro('FPC_MM_HUGE');
  3661. end;
  3662. {$endif i8086}
  3663. {$ifdef aarch64}
  3664. def_system_macro('CPUAARCH64');
  3665. def_system_macro('CPU64');
  3666. def_system_macro('FPC_CURRENCY_IS_INT64');
  3667. def_system_macro('FPC_COMP_IS_INT64');
  3668. {$endif aarch64}
  3669. {$ifdef riscv32}
  3670. def_system_macro('CPURISCV');
  3671. def_system_macro('CPURISCV32');
  3672. def_system_macro('CPU32');
  3673. def_system_macro('FPC_CURRENCY_IS_INT64');
  3674. def_system_macro('FPC_COMP_IS_INT64');
  3675. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3676. {$endif riscv32}
  3677. {$ifdef riscv64}
  3678. def_system_macro('CPURISCV');
  3679. def_system_macro('CPURISCV64');
  3680. def_system_macro('CPU64');
  3681. def_system_macro('FPC_CURRENCY_IS_INT64');
  3682. def_system_macro('FPC_COMP_IS_INT64');
  3683. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3684. {$endif riscv64}
  3685. {$ifdef xtensa}
  3686. def_system_macro('CPUXTENSA');
  3687. def_system_macro('CPU32');
  3688. def_system_macro('FPC_CURRENCY_IS_INT64');
  3689. def_system_macro('FPC_COMP_IS_INT64');
  3690. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3691. {$endif xtensa}
  3692. {$ifdef z80}
  3693. def_system_macro('CPUZ80');
  3694. def_system_macro('CPU16');
  3695. def_system_macro('FPC_CURRENCY_IS_INT64');
  3696. def_system_macro('FPC_COMP_IS_INT64');
  3697. {$endif z80}
  3698. {$if defined(cpu8bitalu)}
  3699. def_system_macro('CPUINT8');
  3700. {$elseif defined(cpu16bitalu)}
  3701. def_system_macro('CPUINT16');
  3702. {$elseif defined(cpu32bitalu)}
  3703. def_system_macro('CPUINT32');
  3704. {$elseif defined(cpu64bitalu)}
  3705. def_system_macro('CPUINT64');
  3706. {$endif defined(cpu64bitalu)}
  3707. {$if defined(avr)}
  3708. def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
  3709. {$endif}
  3710. {$if defined(i8086) or defined(avr)}
  3711. def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
  3712. {$endif i8086 or avr}
  3713. { abs(long) is handled internally on all CPUs }
  3714. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  3715. {$if defined(i8086) or defined(i386) or defined(x86_64) or defined(powerpc64) or defined(aarch64)}
  3716. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  3717. {$endif i8086 or i386 or x86_64 or powerpc64 or aarch64}
  3718. def_system_macro('FPC_HAS_UNICODESTRING');
  3719. def_system_macro('FPC_RTTI_PACKSET1');
  3720. def_system_macro('FPC_HAS_CPSTRING');
  3721. {$ifdef x86_64}
  3722. def_system_macro('FPC_HAS_RIP_RELATIVE');
  3723. {$endif x86_64}
  3724. def_system_macro('FPC_HAS_CEXTENDED');
  3725. def_system_macro('FPC_HAS_RESSTRINITS');
  3726. { these cpus have an inline rol/ror implementaion }
  3727. {$ifdef cpurox}
  3728. {$ifdef m68k}
  3729. if CPUM68K_HAS_ROLROR in cpu_capabilities[init_settings.cputype] then
  3730. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3731. {$else}
  3732. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3733. {$endif}
  3734. {$endif}
  3735. {$ifdef powerpc64}
  3736. def_system_macro('FPC_HAS_LWSYNC');
  3737. {$endif}
  3738. { currently, all supported CPUs have an internal sar implementation }
  3739. def_system_macro('FPC_HAS_INTERNAL_SAR');
  3740. {$ifdef SUPPORT_GET_FRAME}
  3741. def_system_macro('INTERNAL_BACKTRACE');
  3742. {$endif SUPPORT_GET_FRAME}
  3743. def_system_macro('STR_CONCAT_PROCS');
  3744. {$warnings off}
  3745. if pocall_default = pocall_register then
  3746. def_system_macro('REGCALL');
  3747. {$warnings on}
  3748. end;
  3749. var
  3750. env: ansistring;
  3751. i : tfeature;
  3752. j : longint;
  3753. tmplist : TCmdStrList;
  3754. cmditem,
  3755. tmpcmditem : TCmdStrListItem;
  3756. cmdstr : TCmdStr;
  3757. {$if defined(cpucapabilities)}
  3758. cpuflag : tcpuflags;
  3759. {$endif defined(cpucapabilities)}
  3760. {$if defined(fpucapabilities)}
  3761. fpuflag : tfpuflags;
  3762. {$endif defined(fpucapabilities)}
  3763. {$if defined(cpucapabilities) or defined(fpucapabilities)}
  3764. hs : string;
  3765. {$endif defined(cpucapabilities) or defined(fpucapabilities)}
  3766. begin
  3767. option:=coption.create;
  3768. disable_configfile:=false;
  3769. { Non-core target defines }
  3770. Option.TargetOptions(true);
  3771. { get default messagefile }
  3772. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  3773. { default configfile can be specified on the commandline,
  3774. remove it first }
  3775. if (cmd<>'') and (cmd[1]='[') then
  3776. begin
  3777. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  3778. Delete(cmd,1,pos(']',cmd));
  3779. end
  3780. else
  3781. ppccfg:='fpc.cfg';
  3782. { first pass reading of parameters, only -i -v -T etc.}
  3783. option.firstpass:=true;
  3784. if cmd<>'' then
  3785. option.parsecmd(cmd)
  3786. else
  3787. begin
  3788. option.read_parameters;
  3789. { Write only quickinfo }
  3790. if option.quickinfo<>'' then
  3791. option.writequickinfo;
  3792. end;
  3793. option.firstpass:=false;
  3794. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  3795. Option.TargetOptions(true);
  3796. { target is set here, for wince the default app type is gui }
  3797. if target_info.system in systems_wince then
  3798. SetApptype(app_gui)
  3799. else
  3800. SetApptype(apptype);
  3801. { default defines }
  3802. def_system_macro(target_info.shortname);
  3803. def_system_macro('FPC');
  3804. def_system_macro('VER'+version_nr);
  3805. def_system_macro('VER'+version_nr+'_'+release_nr);
  3806. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  3807. { Temporary defines, until things settle down }
  3808. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  3809. def_system_macro('FPC_HAS_CONSTREF');
  3810. def_system_macro('FPC_STATICRIPFIXED');
  3811. def_system_macro('FPC_VARIANTCOPY_FIXED');
  3812. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  3813. def_system_macro('FPC_HAS_MEMBAR');
  3814. def_system_macro('FPC_SETBASE_USED');
  3815. def_system_macro('FPC_ALIGNED_THREADVARTABLES');
  3816. { don't remove this, it's also for fpdoc necessary (FK) }
  3817. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  3818. { make cpu makros available when reading the config files the second time }
  3819. def_cpu_macros;
  3820. if tf_cld in target_info.flags then
  3821. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  3822. InternalError(2013092801);
  3823. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  3824. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  3825. InternalError(2013092802);
  3826. { Use standard Android NDK prefixes when cross-compiling }
  3827. if (source_info.system<>target_info.system) and (target_info.system in systems_android) then
  3828. case target_info.system of
  3829. system_arm_android:
  3830. utilsprefix:='arm-linux-androideabi-';
  3831. system_i386_android:
  3832. utilsprefix:='i686-linux-android-';
  3833. else
  3834. utilsprefix:=target_cpu_string + '-linux-android-';
  3835. end;
  3836. { Set up default value for the heap }
  3837. if target_info.system in (systems_embedded+systems_freertos+[system_z80_zxspectrum,system_z80_msxdos]) then
  3838. begin
  3839. case target_info.system of
  3840. {$ifdef AVR}
  3841. system_avr_embedded:
  3842. if init_settings.controllertype=ct_avrsim then
  3843. heapsize:=8192
  3844. else
  3845. heapsize:=128;
  3846. {$endif AVR}
  3847. system_arm_freertos:
  3848. heapsize:=8192;
  3849. system_xtensa_freertos:
  3850. { keep default value }
  3851. ;
  3852. system_arm_embedded:
  3853. heapsize:=256;
  3854. system_mipsel_embedded:
  3855. heapsize:=256;
  3856. else
  3857. heapsize:=256;
  3858. end;
  3859. end;
  3860. { read configuration file }
  3861. if (not disable_configfile) and
  3862. (ppccfg<>'') then
  3863. read_configfile:=check_configfile(ppccfg,ppccfg)
  3864. else
  3865. read_configfile := false;
  3866. { Read commandline and configfile }
  3867. param_file:='';
  3868. { read configfile }
  3869. if read_configfile then
  3870. option.interpret_file(ppccfg);
  3871. { read parameters again to override config file }
  3872. if cmd<>'' then
  3873. option.parsecmd(cmd)
  3874. else
  3875. begin
  3876. { Write help pages if no parameters are passed }
  3877. if (paramcount=0) then
  3878. Option.WriteHelpPages;
  3879. option.read_parameters;
  3880. { Write only quickinfo }
  3881. if option.quickinfo<>'' then
  3882. option.writequickinfo;
  3883. end;
  3884. { check the compatibility of different options and adjust them if necessary
  3885. (and print possible errors)
  3886. }
  3887. option.checkoptionscompatibility;
  3888. { uses the CPUXXX-defines and target_info to determine whether the selected
  3889. target processor, if any, is supported }
  3890. Option.VerifyTargetProcessor;
  3891. { Stop if errors in options }
  3892. if ErrorCount>0 then
  3893. StopOptions(1);
  3894. { endian define }
  3895. case target_info.endian of
  3896. endian_little :
  3897. begin
  3898. def_system_macro('ENDIAN_LITTLE');
  3899. def_system_macro('FPC_LITTLE_ENDIAN');
  3900. end;
  3901. endian_big :
  3902. begin
  3903. def_system_macro('ENDIAN_BIG');
  3904. def_system_macro('FPC_BIG_ENDIAN');
  3905. end;
  3906. end;
  3907. { Write logo }
  3908. if option.ParaLogo then
  3909. option.writelogo;
  3910. { Check file to compile }
  3911. if param_file='' then
  3912. begin
  3913. Message(option_no_source_found);
  3914. StopOptions(1);
  3915. end;
  3916. {$ifndef Unix}
  3917. param_file:=FixFileName(param_file);
  3918. {$endif not unix}
  3919. inputfilepath:=ExtractFilePath(param_file);
  3920. inputfilename:=ExtractFileName(param_file);
  3921. if ExtractFileExt(inputfilename)='' then
  3922. begin
  3923. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  3924. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  3925. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  3926. inputfilename:=ChangeFileExt(inputfilename,pasext)
  3927. else if ((m_mac in current_settings.modeswitches) or
  3928. (tf_p_ext_support in target_info.flags))
  3929. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  3930. inputfilename:=ChangeFileExt(inputfilename,pext);
  3931. end;
  3932. { Check output dir }
  3933. if (OutputExeDir<>'') and
  3934. not PathExists(OutputExeDir,false) then
  3935. begin
  3936. Message1(general_e_path_does_not_exist,OutputExeDir);
  3937. StopOptions(1);
  3938. end;
  3939. { Add paths specified with parameters to the searchpaths }
  3940. UnitSearchPath.AddList(option.ParaUnitPath,true);
  3941. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  3942. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  3943. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  3944. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  3945. packagesearchpath.addlist(option.parapackagepath,true);
  3946. for j:=0 to option.parapackages.count-1 do
  3947. add_package(option.parapackages.NameOfIndex(j),true,true);
  3948. { add default namespaces }
  3949. tmplist:=TCmdStrList.Create;
  3950. cmditem:=TCmdStrListItem(option.paranamespaces.First);
  3951. while assigned(cmditem) do
  3952. begin
  3953. { use a temporary list cause if ";" are involved we need to reverse the
  3954. order due to how TCmdStrList behaves }
  3955. cmdstr:=cmditem.str;
  3956. repeat
  3957. j:=Pos(';',cmdstr);
  3958. if j>0 then
  3959. begin
  3960. tmplist.insert(copy(cmdstr,1,j-1));
  3961. delete(cmdstr,1,j);
  3962. end
  3963. else
  3964. tmplist.insert(cmdstr);
  3965. until j=0;
  3966. tmpcmditem:=TCmdStrListItem(tmplist.First);
  3967. while assigned(tmpcmditem) do
  3968. begin
  3969. namespacelist.insert(tmpcmditem.Str);
  3970. tmpcmditem:=TCmdStrListItem(tmpcmditem.Next);
  3971. end;
  3972. tmplist.clear;
  3973. cmditem:=TCmdStrListItem(cmditem.Next);
  3974. end;
  3975. tmplist.Free;
  3976. { add unit environment and exepath to the unit search path }
  3977. if inputfilepath<>'' then
  3978. Unitsearchpath.AddPath(inputfilepath,true);
  3979. if not disable_configfile then
  3980. begin
  3981. env:=GetEnvironmentVariable(target_info.unit_env);
  3982. if env<>'' then
  3983. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  3984. end;
  3985. {$ifdef Unix}
  3986. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3987. if fpcdir='' then
  3988. begin
  3989. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  3990. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  3991. else
  3992. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  3993. end;
  3994. {$else unix}
  3995. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3996. if fpcdir='' then
  3997. begin
  3998. fpcdir:=ExePath+'../';
  3999. if not(PathExists(fpcdir+'units',true)) and
  4000. not(PathExists(fpcdir+'rtl',true)) then
  4001. fpcdir:=fpcdir+'../';
  4002. end;
  4003. {$endif unix}
  4004. { first try development RTL, else use the default installation path }
  4005. if not disable_configfile then
  4006. begin
  4007. if PathExists(FpcDir+'rtl',true) then
  4008. if (tf_use_8_3 in Source_Info.Flags) or
  4009. (tf_use_8_3 in Target_Info.Flags) then
  4010. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  4011. else
  4012. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  4013. else
  4014. if (tf_use_8_3 in Source_Info.Flags) or
  4015. (tf_use_8_3 in Target_Info.Flags) then
  4016. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  4017. else
  4018. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  4019. end;
  4020. { Add exepath if the exe is not in the current dir, because that is always searched already.
  4021. Do not add it when linking on the target because then we can maybe already find
  4022. .o files that are not for the target }
  4023. if (ExePath<>cfileutl.GetCurrentDir) and
  4024. not(cs_link_on_target in init_settings.globalswitches) then
  4025. UnitSearchPath.AddPath(ExePath,false);
  4026. { Add unit dir to the object and library path }
  4027. objectsearchpath.AddList(unitsearchpath,false);
  4028. librarysearchpath.AddList(unitsearchpath,false);
  4029. {$ifdef llvm}
  4030. { default to clang }
  4031. if (option.paratargetasm=as_none) then
  4032. begin
  4033. option.paratargetasm:=as_clang_llvm;
  4034. end;
  4035. {$endif llvm}
  4036. { maybe override assembler }
  4037. if (option.paratargetasm<>as_none) then
  4038. begin
  4039. if not set_target_asm(option.paratargetasm) then
  4040. begin
  4041. if assigned(asminfos[option.paratargetasm]) then
  4042. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name)
  4043. else
  4044. Message2(option_incompatible_asm,'<invalid assembler>',target_info.name);
  4045. set_target_asm(target_info.assemextern);
  4046. Message1(option_asm_forced,target_asm.idtxt);
  4047. end;
  4048. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  4049. (option.paratargetdbg<>dbg_none) then
  4050. begin
  4051. Message1(option_confict_asm_debug,
  4052. asminfos[option.paratargetasm]^.idtxt);
  4053. option.paratargetdbg:=dbg_none;
  4054. exclude(init_settings.moduleswitches,cs_debuginfo);
  4055. end;
  4056. { Some assemblers, like clang, do not support
  4057. stabs debugging format, switch to dwardé in that case }
  4058. if (af_no_stabs in asminfos[option.paratargetasm]^.flags) and
  4059. (option.paratargetdbg=dbg_stabs) then
  4060. begin
  4061. option.paratargetdbg:=dbg_dwarf2;
  4062. end;
  4063. end;
  4064. {TOptionheck a second time as we might have changed assembler just above }
  4065. option.checkoptionscompatibility;
  4066. { maybe override debug info format }
  4067. if (option.paratargetdbg<>dbg_none) then
  4068. if not set_target_dbg(option.paratargetdbg) then
  4069. Message(option_w_unsupported_debug_format);
  4070. { switch assembler if it's binary and we got -a on the cmdline }
  4071. if ((cs_asm_leave in init_settings.globalswitches) and
  4072. (af_outputbinary in target_asm.flags)) or
  4073. { if -s is passed, we shouldn't call the internal assembler }
  4074. (cs_asm_extern in init_settings.globalswitches) then
  4075. begin
  4076. Message(option_switch_bin_to_src_assembler);
  4077. {$ifdef llvm}
  4078. set_target_asm(as_clang_llvm);
  4079. {$else}
  4080. set_target_asm(target_info.assemextern);
  4081. {$endif}
  4082. { At least i8086 needs that for nasm and -CX
  4083. which is incompatible with internal linker }
  4084. option.checkoptionscompatibility;
  4085. end;
  4086. { Force use of external linker if there is no
  4087. internal linker or the linking is skipped }
  4088. if not(cs_link_extern in init_settings.globalswitches) and
  4089. ((target_info.link=ld_none) or
  4090. (cs_link_nolink in init_settings.globalswitches)) then
  4091. begin
  4092. include(init_settings.globalswitches,cs_link_extern);
  4093. end;
  4094. { turn off stripping if compiling with debuginfo or profile }
  4095. if (
  4096. (cs_debuginfo in init_settings.moduleswitches) or
  4097. (cs_profile in init_settings.moduleswitches)
  4098. ) and
  4099. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  4100. exclude(init_settings.globalswitches,cs_link_strip);
  4101. { choose a reasonable tls model }
  4102. if (tf_section_threadvars in target_info.flags) and (init_settings.tlsmodel=tlsm_none) then
  4103. begin
  4104. if cs_create_pic in init_settings.moduleswitches then
  4105. init_settings.tlsmodel:=tlsm_global_dynamic
  4106. else
  4107. init_settings.tlsmodel:=tlsm_local_exec;
  4108. end;
  4109. { set Mac OS X version default macros if not specified explicitly }
  4110. option.MaybeSetDefaultMacVersionMacro;
  4111. {$ifdef cpufpemu}
  4112. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  4113. if fpu type not explicitly set }
  4114. if not(option.FPUSetExplicitly) and
  4115. ((target_info.system in [system_arm_wince,system_arm_gba,
  4116. system_m68k_amiga,system_m68k_atari,
  4117. system_arm_nds,system_arm_embedded,system_arm_freertos,
  4118. system_riscv32_embedded,system_riscv64_embedded,system_xtensa_linux,
  4119. system_z80_embedded,system_z80_zxspectrum])
  4120. {$ifdef arm}
  4121. or (target_info.abi=abi_eabi)
  4122. {$endif arm}
  4123. )
  4124. or (init_settings.fputype=fpu_soft)
  4125. then
  4126. begin
  4127. include(init_settings.moduleswitches,cs_fp_emulation);
  4128. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  4129. init_settings.fputype:=fpu_soft;
  4130. end;
  4131. {$endif cpufpemu}
  4132. {$ifdef i386}
  4133. if target_info.system in systems_i386_default_486 then
  4134. begin
  4135. { Avoid use of MMX/CMOVcc instructions on older systems.
  4136. Some systems might not handle these instructions correctly,
  4137. Used emulators might also be problematic. PM }
  4138. if not option.CPUSetExplicitly then
  4139. init_settings.cputype:=cpu_486;
  4140. end;
  4141. case target_info.system of
  4142. system_i386_android:
  4143. begin
  4144. { set default cpu type to PentiumM for Android unless specified otherwise }
  4145. if not option.CPUSetExplicitly then
  4146. init_settings.cputype:=cpu_PentiumM;
  4147. if not option.OptCPUSetExplicitly then
  4148. init_settings.optimizecputype:=cpu_PentiumM;
  4149. { set default fpu type to SSSE3 for Android unless specified otherwise }
  4150. if not option.FPUSetExplicitly then
  4151. init_settings.fputype:=fpu_ssse3;
  4152. end;
  4153. else
  4154. ;
  4155. end;
  4156. {$endif i386}
  4157. {$ifdef xtensa}
  4158. { xtensa-linux target does not support controller setting option -Wp }
  4159. if not(option.FPUSetExplicitly) and not(target_info.system = system_xtensa_linux) then
  4160. begin
  4161. init_settings.fputype:=embedded_controllers[init_settings.controllertype].fputype;
  4162. if (init_settings.fputype=fpu_soft) then
  4163. include(init_settings.moduleswitches,cs_fp_emulation);
  4164. end;
  4165. if not(option.CPUSetExplicitly) and (target_info.system=system_xtensa_linux) then
  4166. init_settings.cputype:=cpu_lx6;
  4167. if (target_info.system in [system_xtensa_embedded,system_xtensa_freertos]) and not(option.ABISetExplicitly) then
  4168. begin
  4169. if CPUXTENSA_REGWINDOW in cpu_capabilities[init_settings.cputype] then
  4170. target_info.abi:=abi_xtensa_windowed
  4171. else
  4172. target_info.abi:=abi_xtensa_call0;
  4173. end;
  4174. {$endif xtensa}
  4175. {$ifdef arm}
  4176. case target_info.system of
  4177. system_arm_ios:
  4178. begin
  4179. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  4180. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  4181. }
  4182. if not option.CPUSetExplicitly then
  4183. init_settings.cputype:=cpu_armv7;
  4184. if not option.OptCPUSetExplicitly then
  4185. init_settings.optimizecputype:=cpu_armv7;
  4186. if not option.FPUSetExplicitly then
  4187. init_settings.fputype:=fpu_vfpv3;
  4188. end;
  4189. system_arm_android:
  4190. begin
  4191. { set default cpu type to ARMv5T for Android unless specified otherwise }
  4192. if not option.CPUSetExplicitly then
  4193. init_settings.cputype:=cpu_armv5t;
  4194. if not option.OptCPUSetExplicitly then
  4195. init_settings.optimizecputype:=cpu_armv5t;
  4196. end;
  4197. else
  4198. ;
  4199. end;
  4200. { set ABI defaults }
  4201. case target_info.abi of
  4202. abi_eabihf:
  4203. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  4204. begin
  4205. {$ifdef CPUARMV6}
  4206. { if the compiler is built for armv6, then
  4207. inherit this setting, e.g. Raspian is armhf but
  4208. only armv6, this makes rebuilds of the compiler
  4209. easier }
  4210. if not option.CPUSetExplicitly then
  4211. init_settings.cputype:=cpu_armv6;
  4212. if not option.OptCPUSetExplicitly then
  4213. init_settings.optimizecputype:=cpu_armv6;
  4214. {$else CPUARMV6}
  4215. if not option.CPUSetExplicitly then
  4216. init_settings.cputype:=cpu_armv7a;
  4217. if not option.OptCPUSetExplicitly then
  4218. init_settings.optimizecputype:=cpu_armv7a;
  4219. {$endif CPUARMV6}
  4220. { Set FPU type }
  4221. if not(option.FPUSetExplicitly) then
  4222. begin
  4223. if init_settings.cputype < cpu_armv7 then
  4224. init_settings.fputype:=fpu_vfpv2
  4225. else
  4226. init_settings.fputype:=fpu_vfpv3_d16;
  4227. end
  4228. else
  4229. begin
  4230. if (not(FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[init_settings.fputype]))
  4231. or (target_info.system = system_arm_ios) then
  4232. begin
  4233. Message(option_illegal_fpu_eabihf);
  4234. StopOptions(1);
  4235. end;
  4236. end;
  4237. end;
  4238. abi_eabi:
  4239. begin
  4240. if target_info.system=system_arm_linux then
  4241. begin
  4242. { this is what Debian uses }
  4243. if not option.CPUSetExplicitly then
  4244. init_settings.cputype:=cpu_armv4t;
  4245. if not option.OptCPUSetExplicitly then
  4246. init_settings.optimizecputype:=cpu_armv4t;
  4247. if not(option.FPUSetExplicitly) then
  4248. init_settings.fputype:=fpu_soft;
  4249. end;
  4250. end;
  4251. else
  4252. ;
  4253. end;
  4254. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4255. begin
  4256. def_system_macro('CPUTHUMB');
  4257. if not option.FPUSetExplicitly then
  4258. init_settings.fputype:=fpu_soft;
  4259. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  4260. 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';
  4261. {$else FPC_ARMAL or FPC_ARMHF}
  4262. if target_info.endian=endian_little then
  4263. 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';
  4264. {$endif FPC_ARMAL or FPC_ARMHF}
  4265. end;
  4266. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4267. def_system_macro('CPUTHUMB2');
  4268. {$endif arm}
  4269. {$if defined(riscv32) or defined(riscv64)}
  4270. { RISC-V defaults }
  4271. if (target_info.abi = abi_riscv_hf) then
  4272. begin
  4273. {$ifdef riscv32}
  4274. if not option.CPUSetExplicitly then
  4275. init_settings.cputype:=cpu_rv32ima;
  4276. if not option.OptCPUSetExplicitly then
  4277. init_settings.optimizecputype:=cpu_rv32ima;
  4278. {$else}
  4279. if not option.CPUSetExplicitly then
  4280. init_settings.cputype:=cpu_rv64imac;
  4281. if not option.OptCPUSetExplicitly then
  4282. init_settings.optimizecputype:=cpu_rv64imac;
  4283. {$endif}
  4284. { Set FPU type }
  4285. if not(option.FPUSetExplicitly) then
  4286. init_settings.fputype:=fpu_fd
  4287. else
  4288. begin
  4289. if not (init_settings.fputype in [fpu_fd]) then
  4290. begin
  4291. Message(option_illegal_fpu_eabihf);
  4292. StopOptions(1);
  4293. end;
  4294. end;
  4295. end;
  4296. {$endif defined(riscv32) or defined(riscv64)}
  4297. {$ifdef jvm}
  4298. { set default CPU type to Dalvik when targeting Android }
  4299. if target_info.system=system_jvm_android32 then
  4300. begin
  4301. if not option.CPUSetExplicitly then
  4302. init_settings.cputype:=cpu_dalvik;
  4303. end;
  4304. {$endif jvm}
  4305. {$ifdef llvm}
  4306. { standard extension for llvm bitcode files }
  4307. target_info.asmext:='.ll';
  4308. { don't generate dwarf cfi, llvm will do that }
  4309. exclude(target_info.flags,tf_needs_dwarf_cfi);
  4310. {$endif llvm}
  4311. {$ifdef mipsel}
  4312. case target_info.system of
  4313. system_mipsel_android:
  4314. begin
  4315. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  4316. if not option.CPUSetExplicitly then
  4317. init_settings.cputype:=cpu_mips32;
  4318. if not option.OptCPUSetExplicitly then
  4319. init_settings.optimizecputype:=cpu_mips32;
  4320. if not option.FPUSetExplicitly then
  4321. init_settings.fputype:=fpu_mips2;
  4322. end;
  4323. system_mipsel_embedded:
  4324. begin
  4325. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  4326. if not option.CPUSetExplicitly then
  4327. init_settings.cputype:=cpu_pic32mx;
  4328. if not option.OptCPUSetExplicitly then
  4329. init_settings.optimizecputype:=cpu_pic32mx;
  4330. if not option.FPUSetExplicitly then
  4331. init_settings.fputype:=fpu_soft;
  4332. end;
  4333. else
  4334. ;
  4335. end;
  4336. {$endif mipsel}
  4337. {$ifdef m68k}
  4338. if init_settings.cputype in cpu_coldfire then
  4339. def_system_macro('CPUCOLDFIRE');
  4340. case target_info.system of
  4341. system_m68k_linux,
  4342. system_m68k_netbsd:
  4343. begin
  4344. if not (option.FPUSetExplicitly) and
  4345. not (init_settings.cputype in cpu_coldfire) then
  4346. begin
  4347. { enable HW FPU for UNIX by default, but only for
  4348. original 68k, not Coldfire }
  4349. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4350. init_settings.fputype:=fpu_68881;
  4351. end;
  4352. end;
  4353. system_m68k_sinclairql:
  4354. begin
  4355. if not option.CPUSetExplicitly then
  4356. init_settings.cputype:=cpu_mc68000;
  4357. end;
  4358. system_m68k_palmos:
  4359. begin
  4360. if not option.CPUSetExplicitly then
  4361. init_settings.cputype:=cpu_mc68000;
  4362. if not (option.FPUSetExplicitly) then
  4363. begin
  4364. { No FPU for PalmOS by default }
  4365. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4366. init_settings.fputype:=fpu_none;
  4367. end;
  4368. end;
  4369. else
  4370. ;
  4371. end;
  4372. {$endif m68k}
  4373. { now we can define cpu and fpu type }
  4374. def_cpu_macros;
  4375. { Use init_settings cpu type for asm cpu type,
  4376. if asmcputype is cpu_none,
  4377. at least as long as there is no explicit
  4378. option to set it on command line PM }
  4379. if init_settings.asmcputype = cpu_none then
  4380. init_settings.asmcputype:=init_settings.cputype;
  4381. {$ifdef llvm}
  4382. def_system_macro('CPULLVM');
  4383. {$endif llvm}
  4384. {$if defined(cpucapabilities)}
  4385. for cpuflag:=low(cpuflag) to high(cpuflag) do
  4386. begin
  4387. str(cpuflag,hs);
  4388. if cpuflag in cpu_capabilities[init_settings.cputype] then
  4389. def_system_macro(hs)
  4390. else
  4391. undef_system_macro(hs);
  4392. end;
  4393. {$endif defined(cpucapabilities)}
  4394. {$if defined(fpucapabilities)}
  4395. for fpuflag:=low(fpuflag) to high(fpuflag) do
  4396. begin
  4397. str(fpuflag,hs);
  4398. if fpuflag in fpu_capabilities[init_settings.fputype] then
  4399. def_system_macro(hs)
  4400. else
  4401. undef_system_macro(hs);
  4402. end;
  4403. {$endif defined(fpucapabilities)}
  4404. if init_settings.fputype<>fpu_none then
  4405. begin
  4406. {$if defined(i386) or defined(i8086)}
  4407. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4408. {$endif}
  4409. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4410. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4411. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  4412. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4413. {$endif}
  4414. {$if defined(m68k)}
  4415. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  4416. {$endif}
  4417. {$ifdef x86_64}
  4418. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4419. { normally, win64 doesn't support the legacy fpu }
  4420. if target_info.system=system_x86_64_win64 then
  4421. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  4422. else
  4423. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4424. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4425. {$endif}
  4426. end;
  4427. { Enable now for testing }
  4428. {$ifndef DISABLE_TLS_DIRECTORY}
  4429. if target_info.system in systems_windows then
  4430. def_system_macro('FPC_USE_TLS_DIRECTORY');
  4431. {$endif not DISABLE_TLS_DIRECTORY}
  4432. {$ifndef DISABLE_WIN64_SEH}
  4433. if target_info.system=system_x86_64_win64 then
  4434. def_system_macro('FPC_USE_WIN64_SEH');
  4435. {$endif DISABLE_WIN64_SEH}
  4436. {$ifndef DISABLE_WIN32_SEH}
  4437. if target_info.system=system_i386_win32 then
  4438. def_system_macro('FPC_USE_WIN32_SEH');
  4439. {$endif not DISABLE_WIN32_SEH}
  4440. {$ifdef ARM}
  4441. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  4442. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  4443. not(cs_fp_emulation in init_settings.moduleswitches) then
  4444. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  4445. {$endif ARM}
  4446. { inline bsf/bsr implementation }
  4447. {$if defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64)}
  4448. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4449. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4450. {$endif}
  4451. { hardware FMA support }
  4452. {$if defined(i386) or defined(x86_64)}
  4453. if (cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[] then
  4454. begin
  4455. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  4456. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  4457. end;
  4458. {$endif defined(i386) or defined(x86_64)}
  4459. {$if defined(arm)}
  4460. { it is determined during system unit compilation if clz is used for bsf or not,
  4461. this is not perfect but the current implementation bsf/bsr does not allow another
  4462. solution }
  4463. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  4464. ((init_settings.instructionset=is_arm) or
  4465. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  4466. begin
  4467. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4468. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  4469. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4470. end;
  4471. {$endif}
  4472. {$if defined(xtensa)}
  4473. { it is determined during system unit compilation if nsau is used for bsr or not,
  4474. this is not perfect but the current implementation bsf/bsr does not allow another
  4475. solution }
  4476. if CPUXTENSA_HAS_NSAx in cpu_capabilities[init_settings.cputype] then
  4477. begin
  4478. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4479. end;
  4480. {$endif}
  4481. {$if defined(powerpc64)}
  4482. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  4483. big endian (unless specified otherwise). As the gcc man page says:
  4484. "Overriding the default ABI requires special system support and is
  4485. likely to fail in spectacular ways" }
  4486. if not option.ABISetExplicitly then
  4487. begin
  4488. if (target_info.abi=abi_powerpc_sysv) and
  4489. (target_info.endian=endian_little) then
  4490. target_info.abi:=abi_powerpc_elfv2
  4491. else
  4492. if (target_info.abi=abi_powerpc_elfv2) and
  4493. (target_info.endian=endian_big) then
  4494. target_info.abi:=abi_powerpc_sysv
  4495. end;
  4496. {$endif}
  4497. {$if defined(powerpc) or defined(powerpc64)}
  4498. { define _CALL_ELF symbol like gcc }
  4499. case target_info.abi of
  4500. abi_powerpc_sysv:
  4501. set_system_compvar('_CALL_ELF','1');
  4502. abi_powerpc_elfv2:
  4503. set_system_compvar('_CALL_ELF','2');
  4504. else
  4505. ;
  4506. end;
  4507. {$endif}
  4508. { Section smartlinking conflicts with import sections on Windows }
  4509. if GenerateImportSection and
  4510. (target_info.system in [system_i386_win32,system_x86_64_win64,system_aarch64_win64]) then
  4511. exclude(target_info.flags,tf_smartlink_sections);
  4512. if not option.LinkTypeSetExplicitly then
  4513. set_default_link_type;
  4514. { Default alignment settings,
  4515. 1. load the defaults for the target
  4516. 2. override with generic optimizer setting (little size)
  4517. 3. override with the user specified -Oa }
  4518. UpdateAlignment(init_settings.alignment,target_info.alignment);
  4519. if (cs_opt_size in init_settings.optimizerswitches) then
  4520. begin
  4521. init_settings.alignment.procalign:=1;
  4522. init_settings.alignment.jumpalign:=1;
  4523. init_settings.alignment.coalescealign:=1;
  4524. init_settings.alignment.loopalign:=1;
  4525. {$ifdef x86}
  4526. { constalignmax=1 keeps the executable and thus the memory foot print small but
  4527. all processors except x86 are really hurt by this or might even crash }
  4528. init_settings.alignment.constalignmax:=1;
  4529. {$endif x86}
  4530. end;
  4531. UpdateAlignment(init_settings.alignment,option.paraalignment);
  4532. set_system_macro('FPC_VERSION',version_nr);
  4533. set_system_macro('FPC_RELEASE',release_nr);
  4534. set_system_macro('FPC_PATCH',patch_nr);
  4535. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  4536. if target_info.system in systems_indirect_entry_information then
  4537. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  4538. if not (tf_winlikewidestring in target_info.flags) then
  4539. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  4540. if tf_supports_packages in target_info.flags then
  4541. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  4542. if target_info.system in systems_indirect_var_imports then
  4543. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  4544. if cs_compilesystem in init_settings.moduleswitches then
  4545. for i:=low(tfeature) to high(tfeature) do
  4546. if i in features then
  4547. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  4548. {$push}
  4549. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  4550. if ControllerSupport and (target_info.system in (systems_embedded+systems_freertos)) and
  4551. (init_settings.controllertype<>ct_none) then
  4552. begin
  4553. with embedded_controllers[init_settings.controllertype] do
  4554. begin
  4555. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  4556. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  4557. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  4558. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  4559. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  4560. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  4561. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  4562. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  4563. end;
  4564. end;
  4565. {$pop}
  4566. { as stackalign is not part of the alignment record, we do not need to define the others alignments for symmetry yet }
  4567. set_system_macro('FPC_STACKALIGNMENT',tostr(target_info.stackalign));
  4568. option.free;
  4569. Option:=nil;
  4570. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl{$ifdef z80},pocall_stdcall{$endif}];
  4571. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  4572. if (tf_safecall_clearstack in target_info.flags) then
  4573. begin
  4574. include (cdecl_pocalls, pocall_safecall);
  4575. include (clearstack_pocalls, pocall_safecall)
  4576. end;
  4577. end;
  4578. initialization
  4579. coption:=toption;
  4580. finalization
  4581. if assigned(option) then
  4582. option.free;
  4583. end.