options.pas 164 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841
  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. localvartrashing := -1;
  1751. end
  1752. else
  1753. begin
  1754. include(init_settings.moduleswitches,cs_debuginfo);
  1755. if paratargetdbg=dbg_none then
  1756. paratargetdbg:=target_info.dbg;
  1757. end;
  1758. if not RelocSectionSetExplicitly then
  1759. RelocSection:=false;
  1760. j:=1;
  1761. while j<=length(more) do
  1762. begin
  1763. case more[j] of
  1764. 'c' :
  1765. begin
  1766. if UnsetBool(More, j, opt, false) then
  1767. exclude(init_settings.localswitches,cs_checkpointer)
  1768. else if (target_info.system in systems_support_checkpointer) then
  1769. begin
  1770. if do_release then
  1771. Message(option_gc_incompatible_with_release_flag)
  1772. else
  1773. include(init_settings.localswitches,cs_checkpointer);
  1774. end
  1775. else
  1776. UnsupportedPara('-gc');
  1777. end;
  1778. 'h' :
  1779. begin
  1780. if UnsetBool(More, j, opt, false) then
  1781. exclude(init_settings.globalswitches,cs_use_heaptrc)
  1782. else
  1783. begin
  1784. if cs_gdb_valgrind in init_settings.globalswitches then
  1785. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  1786. include(init_settings.globalswitches,cs_use_heaptrc);
  1787. end;
  1788. end;
  1789. 'l' :
  1790. begin
  1791. if UnsetBool(More, j, opt, false) then
  1792. exclude(init_settings.globalswitches,cs_use_lineinfo)
  1793. else
  1794. include(init_settings.globalswitches,cs_use_lineinfo);
  1795. end;
  1796. 'm' :
  1797. begin
  1798. paratargetdbg:=dbg_codeview;
  1799. end;
  1800. 'o' :
  1801. begin
  1802. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  1803. IllegalPara(opt);
  1804. break;
  1805. end;
  1806. 'p' :
  1807. begin
  1808. if UnsetBool(More, j, opt, false) then
  1809. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  1810. else
  1811. include(init_settings.globalswitches,cs_stabs_preservecase);
  1812. end;
  1813. 's' :
  1814. begin
  1815. paratargetdbg:=dbg_stabs;
  1816. end;
  1817. 't' :
  1818. begin
  1819. if UnsetBool(More, j, opt, false) then
  1820. localvartrashing := -1
  1821. else
  1822. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  1823. end;
  1824. 'v' :
  1825. begin
  1826. if UnsetBool(More, j, opt, false) then
  1827. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  1828. else
  1829. begin
  1830. if cs_use_heaptrc in init_settings.globalswitches then
  1831. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  1832. include(init_settings.globalswitches,cs_gdb_valgrind);
  1833. end;
  1834. end;
  1835. 'w' :
  1836. begin
  1837. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  1838. begin
  1839. case more[j+1] of
  1840. '2': paratargetdbg:=dbg_dwarf2;
  1841. '3': paratargetdbg:=dbg_dwarf3;
  1842. '4': paratargetdbg:=dbg_dwarf4;
  1843. end;
  1844. inc(j);
  1845. end
  1846. else
  1847. paratargetdbg:=dbg_dwarf2;
  1848. end;
  1849. else
  1850. IllegalPara(opt);
  1851. end;
  1852. inc(j);
  1853. end;
  1854. end;
  1855. 'h' :
  1856. begin
  1857. NoPressEnter:=true;
  1858. if (More <> '') and (More [1] = 'F') then
  1859. begin
  1860. FPCHelpLines := true;
  1861. Delete (More, 1, 1);
  1862. FPCBinaryPath := More;
  1863. end;
  1864. WriteHelpPages;
  1865. end;
  1866. 'i' :
  1867. begin
  1868. if (More='') or
  1869. (More [1] in ['a', 'b', 'c', 'f', 'i', 'm', 'o', 'r', 't', 'u', 'w']) then
  1870. WriteInfo (More)
  1871. else
  1872. QuickInfo:=QuickInfo+More;
  1873. end;
  1874. 'I' :
  1875. begin
  1876. if ispara then
  1877. ParaIncludePath.AddPath(More,false)
  1878. else
  1879. includesearchpath.AddPath(More,false);
  1880. end;
  1881. 'k' :
  1882. begin
  1883. if more<>'' then
  1884. ParaLinkOptions:=ParaLinkOptions+' '+More
  1885. else
  1886. IllegalPara(opt);
  1887. end;
  1888. 'l' :
  1889. ParaLogo:=not UnSetBool(more,0,opt,true);
  1890. {$ifdef PREPROCWRITE}
  1891. 'm' :
  1892. parapreprocess:=not UnSetBool(more,0,opt,true);
  1893. {$endif PREPROCWRITE}
  1894. 'M' :
  1895. begin
  1896. more:=Upper(more);
  1897. if not SetCompileMode(more, true) then
  1898. if not SetCompileModeSwitch(more, true) then
  1899. IllegalPara(opt);
  1900. end;
  1901. 'n' :
  1902. begin
  1903. if More='' then
  1904. disable_configfile:=true
  1905. else
  1906. IllegalPara(opt);
  1907. end;
  1908. 'o' :
  1909. begin
  1910. if More<>'' then
  1911. begin
  1912. DefaultReplacements(More);
  1913. D:=ExtractFilePath(More);
  1914. if (D<>'') then
  1915. OutputExeDir:=FixPath(D,True);
  1916. OutputFileName:=ExtractFileName(More);
  1917. end
  1918. else
  1919. IllegalPara(opt);
  1920. end;
  1921. 'O' :
  1922. begin
  1923. j:=1;
  1924. while j<=length(more) do
  1925. begin
  1926. case more[j] of
  1927. '1' :
  1928. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1929. '2' :
  1930. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1931. '3' :
  1932. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1933. '4' :
  1934. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  1935. 'a' :
  1936. begin
  1937. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1938. IllegalPara(opt);
  1939. break;
  1940. end;
  1941. 's' :
  1942. include(init_settings.optimizerswitches,cs_opt_size);
  1943. 'p' :
  1944. begin
  1945. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1946. begin
  1947. OptCPUSetExplicitly:=true;
  1948. { Give warning for old i386 switches }
  1949. if (Length(More)-j=1) and
  1950. (More[j+1]>='1') and (More[j+1]<='5')then
  1951. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1952. else
  1953. IllegalPara(opt);
  1954. end;
  1955. break;
  1956. end;
  1957. 'o' :
  1958. begin
  1959. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  1960. IllegalPara(opt);
  1961. break;
  1962. end;
  1963. '-' :
  1964. begin
  1965. init_settings.optimizerswitches:=[];
  1966. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1967. end;
  1968. { Obsolete switches }
  1969. 'g' :
  1970. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  1971. 'G' :
  1972. Message1(option_obsolete_switch,'-OG');
  1973. 'r' :
  1974. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  1975. 'u' :
  1976. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  1977. 'w' :
  1978. begin
  1979. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  1980. IllegalPara(opt);
  1981. break;
  1982. end;
  1983. 'W' :
  1984. begin
  1985. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  1986. IllegalPara(opt);
  1987. break;
  1988. end;
  1989. else
  1990. IllegalPara(opt);
  1991. end;
  1992. inc(j);
  1993. end;
  1994. end;
  1995. 'p' :
  1996. begin
  1997. if UnsetBool(More, 0, opt, false) then
  1998. begin
  1999. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  2000. undef_system_macro('FPC_PROFILE');
  2001. end
  2002. else
  2003. if Length(More)=0 then
  2004. IllegalPara(opt)
  2005. else
  2006. case more[1] of
  2007. 'g' : if UnsetBool(more, 1, opt, false) then
  2008. begin
  2009. exclude(init_settings.moduleswitches,cs_profile);
  2010. undef_system_macro('FPC_PROFILE');
  2011. end
  2012. else if (target_info.system in supported_targets_pg) then
  2013. begin
  2014. include(init_settings.moduleswitches,cs_profile);
  2015. def_system_macro('FPC_PROFILE');
  2016. end
  2017. else
  2018. UnsupportedPara('-pg');
  2019. else
  2020. IllegalPara(opt);
  2021. end;
  2022. end;
  2023. 'P' :
  2024. begin
  2025. { used to select the target processor with the "fpc" binary;
  2026. give an error if it's not the target architecture supported by
  2027. this compiler binary (will be verified after the target_info
  2028. is set) }
  2029. processorstr:=More;
  2030. end;
  2031. 'R' :
  2032. begin
  2033. if not SetAsmReadMode(More,init_settings.asmmode) then
  2034. IllegalPara(opt);
  2035. end;
  2036. 's' :
  2037. begin
  2038. if UnsetBool(More, 0, opt, false) then
  2039. begin
  2040. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  2041. if more<>'' then
  2042. IllegalPara(opt);
  2043. end
  2044. else
  2045. begin
  2046. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  2047. if more='h' then
  2048. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target,cs_assemble_on_target]
  2049. else if more='t' then
  2050. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target,cs_assemble_on_target]
  2051. else if more='T' then
  2052. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]-[cs_asm_extern]
  2053. else if more='r' then
  2054. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  2055. else if more<>'' then
  2056. IllegalPara(opt);
  2057. end;
  2058. end;
  2059. 'S' :
  2060. begin
  2061. if more='' then
  2062. IllegalPara(opt);
  2063. if more[1]='I' then
  2064. begin
  2065. {$ifdef jvm}
  2066. UnsupportedPara('-SI');
  2067. {$endif}
  2068. if upper(more)='ICOM' then
  2069. init_settings.interfacetype:=it_interfacecom
  2070. else if upper(more)='ICORBA' then
  2071. init_settings.interfacetype:=it_interfacecorba
  2072. else
  2073. IllegalPara(opt);
  2074. end
  2075. else
  2076. begin
  2077. j:=1;
  2078. while j<=length(more) do
  2079. begin
  2080. case more[j] of
  2081. '2' : //an alternative to -Mobjfpc
  2082. SetCompileMode('OBJFPC',true);
  2083. 'a' :
  2084. If UnsetBool(More, j, opt, false) then
  2085. exclude(init_settings.localswitches,cs_do_assertion)
  2086. else
  2087. include(init_settings.localswitches,cs_do_assertion);
  2088. 'c' :
  2089. If UnsetBool(More, j, opt, false) then
  2090. exclude(init_settings.moduleswitches,cs_support_c_operators)
  2091. else
  2092. include(init_settings.moduleswitches,cs_support_c_operators);
  2093. 'C':
  2094. If UnsetBool(More, j, opt, false) then
  2095. exclude(init_settings.localswitches,cs_check_all_case_coverage)
  2096. else
  2097. include(init_settings.localswitches,cs_check_all_case_coverage);
  2098. 'd' : //an alternative to -Mdelphi
  2099. SetCompileMode('DELPHI',true);
  2100. 'e' :
  2101. begin
  2102. SetErrorFlags(copy(more,j+1,length(more)));
  2103. break;
  2104. end;
  2105. 'f' :
  2106. begin
  2107. if not(cs_compilesystem in init_settings.moduleswitches) then
  2108. Message(option_features_only_for_system_unit);
  2109. inc(j);
  2110. if more[j]='-' then
  2111. begin
  2112. if length(more)>j then
  2113. IllegalPara(opt)
  2114. else
  2115. features:=[];
  2116. end
  2117. else
  2118. begin
  2119. if (HandleFeature(upper(copy(more,j,length(more)-j+1)))) then
  2120. j:=length(more)
  2121. else
  2122. IllegalPara(opt);
  2123. end;
  2124. end;
  2125. 'g' :
  2126. If UnsetBool(More, j, opt, false) then
  2127. exclude(init_settings.moduleswitches,cs_support_goto)
  2128. else
  2129. include(init_settings.moduleswitches,cs_support_goto);
  2130. 'h' :
  2131. If UnsetBool(More, j, opt, false) then
  2132. exclude(init_settings.localswitches,cs_refcountedstrings)
  2133. else
  2134. include(init_settings.localswitches,cs_refcountedstrings);
  2135. 'i' :
  2136. If UnsetBool(More, j, opt, false) then
  2137. exclude(init_settings.localswitches,cs_do_inline)
  2138. else
  2139. include(init_settings.localswitches,cs_do_inline);
  2140. 'j' :
  2141. If UnsetBool(More, j, opt, false) then
  2142. exclude(init_settings.localswitches,cs_typed_const_writable)
  2143. else
  2144. include(init_settings.localswitches,cs_typed_const_writable);
  2145. 'k' :
  2146. If UnsetBool(More, j, opt, false) then
  2147. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  2148. else
  2149. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  2150. 'm' :
  2151. If UnsetBool(More, j, opt, false) then
  2152. exclude(init_settings.moduleswitches,cs_support_macro)
  2153. else
  2154. include(init_settings.moduleswitches,cs_support_macro);
  2155. 'o' : //an alternative to -Mtp
  2156. SetCompileMode('TP',true);
  2157. 'r' :
  2158. If UnsetBool(More, j, opt, false) then
  2159. exclude(init_settings.globalswitches,cs_transparent_file_names)
  2160. else
  2161. include(init_settings.globalswitches,cs_transparent_file_names);
  2162. {$ifdef gpc_mode}
  2163. 'p' : //an alternative to -Mgpc
  2164. SetCompileMode('GPC',true);
  2165. {$endif}
  2166. 's' :
  2167. If UnsetBool(More, j, opt, false) then
  2168. exclude(init_settings.globalswitches,cs_constructor_name)
  2169. else
  2170. include(init_settings.globalswitches,cs_constructor_name);
  2171. 't' :
  2172. Message1(option_obsolete_switch,'-St');
  2173. 'v' :
  2174. If UnsetBool(More, j, opt, false) then
  2175. exclude(init_settings.globalswitches,cs_support_vectors)
  2176. else
  2177. include(init_settings.globalswitches,cs_support_vectors);
  2178. 'x' :
  2179. If UnsetBool(More, j, opt, false) then
  2180. SetCompileModeSwitch('EXCEPTIONS-',true)
  2181. else
  2182. SetCompileModeSwitch('EXCEPTIONS',true);
  2183. 'y' :
  2184. If UnsetBool(More, j, opt, false) then
  2185. exclude(init_settings.localswitches,cs_typed_addresses)
  2186. else
  2187. include(init_settings.localswitches,cs_typed_addresses);
  2188. '-' :
  2189. begin
  2190. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  2191. cs_support_vectors,cs_load_fpcylix_unit];
  2192. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  2193. cs_typed_addresses];
  2194. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  2195. cs_support_macro];
  2196. end;
  2197. else
  2198. IllegalPara(opt);
  2199. end;
  2200. inc(j);
  2201. end;
  2202. end;
  2203. end;
  2204. 'T' :
  2205. begin
  2206. more:=Upper(More);
  2207. if paratarget=system_none then
  2208. begin
  2209. { remove old target define }
  2210. TargetOptions(false);
  2211. { load new target }
  2212. paratarget:=find_system_by_string(More);
  2213. if paratarget<>system_none then
  2214. set_target(paratarget)
  2215. else
  2216. IllegalPara(opt);
  2217. { set new define }
  2218. TargetOptions(true);
  2219. end
  2220. else
  2221. if More<>upper(target_info.shortname) then
  2222. Message1(option_target_is_already_set,target_info.shortname);
  2223. end;
  2224. 'u' :
  2225. if is_identifier(more) then
  2226. undef_system_macro(more)
  2227. else
  2228. begin
  2229. if (more='') then
  2230. Message1(option_missing_arg,'-u')
  2231. else
  2232. Message1(option_malformed_para,opt);
  2233. StopOptions(1);
  2234. end;
  2235. 'U' :
  2236. begin
  2237. j:=1;
  2238. while j<=length(more) do
  2239. begin
  2240. case more[j] of
  2241. {$ifdef UNITALIASES}
  2242. 'a' :
  2243. begin
  2244. AddUnitAlias(Copy(More,j+1,255));
  2245. break;
  2246. end;
  2247. {$endif UNITALIASES}
  2248. 'n' :
  2249. exclude(init_settings.globalswitches,cs_check_unit_name);
  2250. 'p' :
  2251. begin
  2252. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  2253. break;
  2254. end;
  2255. 'r' :
  2256. begin
  2257. do_release:=true;
  2258. if (cs_checkpointer in init_settings.localswitches) then
  2259. begin
  2260. Message(option_gc_incompatible_with_release_flag);
  2261. exclude(init_settings.localswitches,cs_checkpointer);
  2262. end;
  2263. end;
  2264. 's' :
  2265. include(init_settings.moduleswitches,cs_compilesystem);
  2266. '-' :
  2267. begin
  2268. exclude(init_settings.moduleswitches,cs_compilesystem);
  2269. exclude(init_settings.globalswitches,cs_check_unit_name);
  2270. end;
  2271. else
  2272. IllegalPara(opt);
  2273. end;
  2274. inc(j);
  2275. end;
  2276. end;
  2277. 'v' :
  2278. begin
  2279. if not setverbosity(More) then
  2280. IllegalPara(opt);
  2281. end;
  2282. 'V' : ; { Ignore used by fpc }
  2283. 'W' :
  2284. begin
  2285. j:=1;
  2286. while j<=length(More) do
  2287. begin
  2288. case More[j] of
  2289. 'A':
  2290. begin
  2291. if target_info.system in systems_all_windows then
  2292. begin
  2293. if UnsetBool(More, j, opt, false) then
  2294. SetApptype(app_cui)
  2295. else
  2296. SetApptype(app_native);
  2297. end
  2298. else
  2299. IllegalPara(opt);
  2300. end;
  2301. 'b':
  2302. begin
  2303. if target_info.system in systems_darwin then
  2304. begin
  2305. if UnsetBool(More, j, opt, false) then
  2306. SetApptype(app_cui)
  2307. else
  2308. SetApptype(app_bundle)
  2309. end
  2310. else
  2311. IllegalPara(opt);
  2312. end;
  2313. 'B':
  2314. begin
  2315. if target_info.system in systems_all_windows+systems_symbian+[system_z80_zxspectrum] then
  2316. begin
  2317. { -WB200000 means set trefered base address
  2318. to $200000, but does not change relocsection boolean
  2319. this way we can create both relocatble and
  2320. non relocatable DLL at a specific base address PM }
  2321. if (length(More)>j) then
  2322. begin
  2323. val('$'+Copy(More,j+1,255),imagebase,code);
  2324. if code<>0 then
  2325. IllegalPara(opt);
  2326. ImageBaseSetExplicity:=true;
  2327. end
  2328. else
  2329. begin
  2330. RelocSection:=true;
  2331. RelocSectionSetExplicitly:=true;
  2332. end;
  2333. break;
  2334. end
  2335. else
  2336. IllegalPara(opt);
  2337. end;
  2338. 'C':
  2339. begin
  2340. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2341. begin
  2342. if UnsetBool(More, j, opt, false) then
  2343. SetApptype(app_gui)
  2344. else
  2345. SetApptype(app_cui);
  2346. end
  2347. else
  2348. IllegalPara(opt);
  2349. end;
  2350. 'D':
  2351. begin
  2352. if target_info.system in systems_all_windows then
  2353. begin
  2354. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2355. UseDeffileForExportsSetExplicitly:=true;
  2356. end
  2357. else
  2358. IllegalPara(opt);
  2359. end;
  2360. 'e':
  2361. begin
  2362. if (target_info.system in systems_darwin) then
  2363. begin
  2364. set_target_res(res_ext);
  2365. target_info.resobjext:='.fpcres';
  2366. end
  2367. else
  2368. IllegalPara(opt);
  2369. end;
  2370. 'F':
  2371. begin
  2372. if target_info.system in systems_os2 then
  2373. begin
  2374. if UnsetBool(More, j, opt, false) then
  2375. SetApptype(app_cui)
  2376. else
  2377. SetApptype(app_fs);
  2378. end
  2379. else
  2380. IllegalPara(opt);
  2381. end;
  2382. 'G':
  2383. begin
  2384. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2385. begin
  2386. if UnsetBool(More, j, opt, false) then
  2387. SetApptype(app_cui)
  2388. else
  2389. SetApptype(app_gui);
  2390. end
  2391. else
  2392. IllegalPara(opt);
  2393. end;
  2394. {$if defined(i8086)}
  2395. 'h':
  2396. begin
  2397. if UnsetBool(More, j, opt, false) then
  2398. exclude(init_settings.moduleswitches,cs_huge_code)
  2399. else
  2400. include(init_settings.moduleswitches,cs_huge_code);
  2401. end;
  2402. {$endif defined(i8086)}
  2403. 'I':
  2404. begin
  2405. if target_info.system in systems_all_windows then
  2406. begin
  2407. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2408. GenerateImportSectionSetExplicitly:=true;
  2409. end
  2410. else
  2411. IllegalPara(opt);
  2412. end;
  2413. 'i':
  2414. begin
  2415. if (target_info.system in systems_darwin) then
  2416. begin
  2417. set_target_res(res_macho);
  2418. target_info.resobjext:=
  2419. targetinfos[target_info.system]^.resobjext;
  2420. end
  2421. else
  2422. IllegalPara(opt);
  2423. end;
  2424. 'm':
  2425. begin
  2426. {$if defined(i8086)}
  2427. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  2428. begin
  2429. case Upper(Copy(More,j+1,255)) of
  2430. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2431. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2432. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2433. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2434. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2435. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2436. else
  2437. IllegalPara(opt);
  2438. end;
  2439. break;
  2440. end
  2441. else
  2442. {$endif defined(i8086)}
  2443. IllegalPara(opt);
  2444. end;
  2445. 'M':
  2446. begin
  2447. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim])) and
  2448. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2449. begin
  2450. break;
  2451. end
  2452. else
  2453. IllegalPara(opt);
  2454. end;
  2455. 'N':
  2456. begin
  2457. if target_info.system in systems_all_windows then
  2458. begin
  2459. RelocSection:=UnsetBool(More,j,opt,false);
  2460. RelocSectionSetExplicitly:=true;
  2461. end
  2462. else
  2463. IllegalPara(opt);
  2464. end;
  2465. 'p':
  2466. begin
  2467. {$push}
  2468. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  2469. if ((target_info.system in systems_embedded) or (target_info.system in systems_freertos)) and
  2470. ControllerSupport then
  2471. begin
  2472. s:=upper(copy(more,j+1,length(more)-j));
  2473. if not(SetControllerType(s,init_settings.controllertype)) then
  2474. IllegalPara(opt)
  2475. else
  2476. begin
  2477. if init_settings.cputype<>embedded_controllers[init_settings.controllertype].cputype then
  2478. begin
  2479. Message(scan_n_changecputype);
  2480. init_settings.cputype:=embedded_controllers[init_settings.controllertype].cputype;
  2481. end;
  2482. end;
  2483. break;
  2484. end
  2485. else
  2486. IllegalPara(opt);
  2487. {$pop}
  2488. end;
  2489. 'P':
  2490. begin
  2491. if (target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim]) and
  2492. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2493. begin
  2494. break;
  2495. end
  2496. else
  2497. IllegalPara(opt);
  2498. end;
  2499. {$if defined(m68k)}
  2500. 'Q':
  2501. begin
  2502. if (target_info.system in [system_m68k_sinclairql]) then
  2503. begin
  2504. sinclairql_metadata_format:=Upper(Copy(More,j+1,255));
  2505. case sinclairql_metadata_format of
  2506. 'QHDR', 'XTCC': ; { allowed formats }
  2507. else
  2508. IllegalPara(opt);
  2509. end;
  2510. break;
  2511. end
  2512. else
  2513. IllegalPara(opt);
  2514. end;
  2515. {$endif defined(m68k)}
  2516. 'R':
  2517. begin
  2518. if target_info.system in systems_all_windows then
  2519. begin
  2520. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2521. RelocSection:=not UnsetBool(More,j,opt,false);
  2522. RelocSectionSetExplicitly:=true;
  2523. end
  2524. else
  2525. IllegalPara(opt);
  2526. end;
  2527. 't':
  2528. begin
  2529. {$if defined(i8086)}
  2530. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  2531. begin
  2532. case Upper(Copy(More,j+1,255)) of
  2533. 'EXE': SetAppType(app_cui);
  2534. 'COM': SetAppType(app_com);
  2535. else
  2536. IllegalPara(opt);
  2537. end;
  2538. break;
  2539. end
  2540. else
  2541. {$endif defined(i8086)}
  2542. IllegalPara(opt);
  2543. end;
  2544. 'T':
  2545. begin
  2546. if target_info.system in systems_macos then
  2547. begin
  2548. if UnsetBool(More, j, opt, false) then
  2549. SetApptype(app_cui)
  2550. else
  2551. SetApptype(app_tool);
  2552. end
  2553. else
  2554. IllegalPara(opt);
  2555. end;
  2556. 'X':
  2557. begin
  2558. if (target_info.system in systems_linux) then
  2559. begin
  2560. if UnsetBool(More, j, opt, false) then
  2561. exclude(init_settings.moduleswitches,cs_executable_stack)
  2562. else
  2563. include(init_settings.moduleswitches,cs_executable_stack)
  2564. end
  2565. else
  2566. IllegalPara(opt);
  2567. end;
  2568. else
  2569. IllegalPara(opt);
  2570. end;
  2571. inc(j);
  2572. end;
  2573. end;
  2574. 'X' :
  2575. begin
  2576. j:=1;
  2577. while j<=length(more) do
  2578. begin
  2579. case More[j] of
  2580. '9' :
  2581. begin
  2582. if target_info.system in systems_linux then
  2583. begin
  2584. if UnsetBool(More, j, opt, false) then
  2585. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2586. else
  2587. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2588. end
  2589. else
  2590. IllegalPara(opt);
  2591. end;
  2592. 'a' :
  2593. begin
  2594. If UnsetBool(More, j, opt, false) then
  2595. exclude(init_settings.globalswitches,cs_large)
  2596. else
  2597. include(init_settings.globalswitches,cs_large);
  2598. end;
  2599. 'c' : Cshared:=TRUE;
  2600. 'd' : Dontlinkstdlibpath:=TRUE;
  2601. 'e' :
  2602. begin
  2603. If UnsetBool(More, j, opt, false) then
  2604. exclude(init_settings.globalswitches,cs_link_extern)
  2605. else
  2606. include(init_settings.globalswitches,cs_link_extern);
  2607. end;
  2608. 'f' :
  2609. include(init_settings.globalswitches,cs_link_pthread);
  2610. 'g' :
  2611. begin
  2612. If UnsetBool(More, j, opt, false) then
  2613. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2614. else
  2615. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2616. end;
  2617. 'i' :
  2618. begin
  2619. If UnsetBool(More, j, opt, false) then
  2620. include(init_settings.globalswitches,cs_link_extern)
  2621. else
  2622. exclude(init_settings.globalswitches,cs_link_extern);
  2623. end;
  2624. 'n' :
  2625. begin
  2626. If UnsetBool(More, j, opt, false) then
  2627. exclude(init_settings.globalswitches,cs_link_native)
  2628. else
  2629. include(init_settings.globalswitches,cs_link_native);
  2630. end;
  2631. {$ifdef llvm}
  2632. 'l' :
  2633. begin
  2634. if j=length(more) then
  2635. IllegalPara(opt)
  2636. else
  2637. begin
  2638. case more[j+1] of
  2639. 'S':
  2640. begin
  2641. llvmutilssuffix:=copy(more,j+2,length(more));
  2642. j:=length(more);
  2643. end
  2644. else
  2645. IllegalPara(opt);
  2646. end;
  2647. end;
  2648. end;
  2649. {$endif}
  2650. 'm' :
  2651. begin
  2652. If UnsetBool(More, j, opt, false) then
  2653. exclude(init_settings.globalswitches,cs_link_map)
  2654. else
  2655. include(init_settings.globalswitches,cs_link_map);
  2656. end;
  2657. 'p' : ; { Ignore used by fpc.pp }
  2658. 'r' :
  2659. begin
  2660. if (target_info.system in suppported_targets_x_smallr) then
  2661. begin
  2662. rlinkpath:=Copy(more,2,length(More)-1);
  2663. DefaultReplacements(rlinkpath);
  2664. end
  2665. else
  2666. IgnoredPara('-Xr');
  2667. more:='';
  2668. end;
  2669. 'R' :
  2670. begin
  2671. sysrootpath:=copy(more,2,length(more)-1);
  2672. defaultreplacements(sysrootpath);
  2673. more:='';
  2674. end;
  2675. 's' :
  2676. begin
  2677. If UnsetBool(More, j, opt, false) then
  2678. exclude(init_settings.globalswitches,cs_link_strip)
  2679. else
  2680. include(init_settings.globalswitches,cs_link_strip);
  2681. end;
  2682. 't' :
  2683. include(init_settings.globalswitches,cs_link_staticflag);
  2684. 'v' :
  2685. begin
  2686. If UnsetBool(More, j, opt, false) then
  2687. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2688. else
  2689. include(init_settings.globalswitches,cs_link_opt_vtable);
  2690. end;
  2691. 'D' :
  2692. begin
  2693. def_system_macro('FPC_LINK_DYNAMIC');
  2694. undef_system_macro('FPC_LINK_SMART');
  2695. undef_system_macro('FPC_LINK_STATIC');
  2696. exclude(init_settings.globalswitches,cs_link_static);
  2697. exclude(init_settings.globalswitches,cs_link_smart);
  2698. include(init_settings.globalswitches,cs_link_shared);
  2699. LinkTypeSetExplicitly:=true;
  2700. end;
  2701. 'M' :
  2702. begin
  2703. mainaliasname:=Copy(more,2,length(More)-1);
  2704. More:='';
  2705. end;
  2706. 'P' :
  2707. begin
  2708. utilsprefix:=Copy(more,2,length(More)-1);
  2709. DefaultReplacements(utilsprefix);
  2710. More:='';
  2711. end;
  2712. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2713. // these are not aggregable.
  2714. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2715. IllegalPara(opt)
  2716. else
  2717. begin
  2718. case more[j+1] of
  2719. 'A' : begin
  2720. s:=Copy(more,3,length(More)-2);
  2721. if not LinkLibraryAliases.AddDep(s) Then
  2722. IllegalPara(opt);
  2723. end;
  2724. 'O' : begin
  2725. s:=Copy(more,3,length(More)-2);
  2726. if not LinkLibraryOrder.AddWeight(s) Then
  2727. IllegalPara(opt);
  2728. end;
  2729. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2730. else
  2731. IllegalPara(opt);
  2732. end; {case}
  2733. j:=length(more);
  2734. end; {else begin}
  2735. end;
  2736. 'S' :
  2737. begin
  2738. ForceStaticLinking;
  2739. end;
  2740. 'V' :
  2741. begin
  2742. if UnsetBool(More, j, opt, false) then
  2743. exclude(init_settings.globalswitches,cs_link_vlink)
  2744. else
  2745. begin
  2746. include(init_settings.globalswitches,cs_link_vlink);
  2747. include(init_settings.globalswitches,cs_link_extern);
  2748. end;
  2749. LinkerSetExplicitly:=true;
  2750. end;
  2751. 'X' :
  2752. begin
  2753. def_system_macro('FPC_LINK_SMART');
  2754. undef_system_macro('FPC_LINK_STATIC');
  2755. undef_system_macro('FPC_LINK_DYNAMIC');
  2756. exclude(init_settings.globalswitches,cs_link_static);
  2757. include(init_settings.globalswitches,cs_link_smart);
  2758. exclude(init_settings.globalswitches,cs_link_shared);
  2759. LinkTypeSetExplicitly:=true;
  2760. end;
  2761. '-' :
  2762. begin
  2763. exclude(init_settings.globalswitches,cs_link_staticflag);
  2764. exclude(init_settings.globalswitches,cs_link_strip);
  2765. exclude(init_settings.globalswitches,cs_link_map);
  2766. set_default_link_type;
  2767. end;
  2768. else
  2769. IllegalPara(opt);
  2770. end;
  2771. inc(j);
  2772. end;
  2773. end;
  2774. else
  2775. IllegalPara(opt);
  2776. end;
  2777. end;
  2778. '@' :
  2779. begin
  2780. Message(option_no_nested_response_file);
  2781. StopOptions(1);
  2782. end;
  2783. else
  2784. begin
  2785. if (length(param_file)<>0) then
  2786. Message2(option_only_one_source_support,param_file,opt);
  2787. param_file:=opt;
  2788. Message1(option_found_file,opt);
  2789. end;
  2790. end;
  2791. end;
  2792. procedure Toption.Interpret_file(const filename : TPathStr);
  2793. procedure RemoveSep(var fn:TPathStr);
  2794. var
  2795. i : longint;
  2796. begin
  2797. i:=0;
  2798. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2799. inc(i);
  2800. Delete(fn,1,i);
  2801. i:=length(fn);
  2802. while (i>0) and (fn[i] in [',',' ',#9]) do
  2803. dec(i);
  2804. fn:=copy(fn,1,i);
  2805. end;
  2806. function GetName(var fn:TPathStr):TPathStr;
  2807. var
  2808. i : longint;
  2809. begin
  2810. i:=0;
  2811. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2812. inc(i);
  2813. GetName:=Copy(fn,1,i);
  2814. Delete(fn,1,i);
  2815. end;
  2816. const
  2817. maxlevel = 15;
  2818. var
  2819. f : text;
  2820. s, tmp,
  2821. opts : TCmdStr;
  2822. skip : array[0..maxlevel] of boolean;
  2823. line,
  2824. level : longint;
  2825. option_read : boolean;
  2826. oldfilemode : byte;
  2827. ConfigFile: TPathStr;
  2828. begin
  2829. { avoid infinite loop }
  2830. Inc(FileLevel);
  2831. Option_read:=false;
  2832. If FileLevel>MaxLevel then
  2833. Message(option_too_many_cfg_files);
  2834. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2835. ConfigFile := ExpandFileName(filename);
  2836. { Maybe It's Directory ?} //Jaro Change:
  2837. if PathExists(ConfigFile,false) then
  2838. begin
  2839. Message1(option_config_is_dir,filename);
  2840. exit;
  2841. end;
  2842. { open file }
  2843. Message1(option_using_file,filename);
  2844. oldfilemode:=filemode;
  2845. filemode:=0;
  2846. assign(f,ConfigFile);
  2847. {$push}{$I-}
  2848. reset(f);
  2849. {$pop}
  2850. filemode:=oldfilemode;
  2851. if ioresult<>0 then
  2852. begin
  2853. Message1(option_unable_open_file,filename);
  2854. exit;
  2855. end;
  2856. Message1(option_start_reading_configfile,filename);
  2857. fillchar(skip,sizeof(skip),0);
  2858. level:=0;
  2859. line:=0;
  2860. while not eof(f) do
  2861. begin
  2862. readln(f,opts);
  2863. inc(line);
  2864. RemoveSep(opts);
  2865. if (opts<>'') and (opts[1]<>';') then
  2866. begin
  2867. if opts[1]='#' then
  2868. begin
  2869. Message1(option_interpreting_file_option,opts);
  2870. Delete(opts,1,1);
  2871. s:=upper(GetName(opts));
  2872. if (s='SECTION') then
  2873. begin
  2874. RemoveSep(opts);
  2875. s:=upper(GetName(opts));
  2876. if level=0 then
  2877. skip[level]:=not defined_macro(s) or (s='COMMON');
  2878. end
  2879. else
  2880. if (s='IFDEF') then
  2881. begin
  2882. RemoveSep(opts);
  2883. if Level>=maxlevel then
  2884. begin
  2885. Message2(option_too_many_ifdef,filename,tostr(line));
  2886. stopOptions(1);
  2887. end;
  2888. inc(Level);
  2889. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2890. end
  2891. else
  2892. if (s='IFNDEF') then
  2893. begin
  2894. RemoveSep(opts);
  2895. if Level>=maxlevel then
  2896. begin
  2897. Message2(option_too_many_ifdef,filename,tostr(line));
  2898. stopOptions(1);
  2899. end;
  2900. inc(Level);
  2901. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2902. end
  2903. else
  2904. if (s='ELSE') then
  2905. begin
  2906. if Level=0 then
  2907. begin
  2908. Message2(option_else_without_if,filename,tostr(line));
  2909. stopOptions(1);
  2910. end
  2911. else
  2912. skip[level]:=skip[level-1] or (not skip[level])
  2913. end
  2914. else
  2915. if (s='ENDIF') then
  2916. begin
  2917. skip[level]:=false;
  2918. if Level=0 then
  2919. begin
  2920. Message2(option_too_many_endif,filename,tostr(line));
  2921. stopOptions(1);
  2922. end;
  2923. dec(level);
  2924. end
  2925. else
  2926. if (not skip[level]) then
  2927. begin
  2928. if (s='DEFINE') then
  2929. begin
  2930. RemoveSep(opts);
  2931. tmp:= GetName(opts);
  2932. if tmp <> '' then
  2933. def_system_macro(tmp);
  2934. Option_read:=true;
  2935. end
  2936. else
  2937. if (s='UNDEF') then
  2938. begin
  2939. RemoveSep(opts);
  2940. tmp:= GetName(opts);
  2941. if tmp <> '' then
  2942. undef_system_macro(tmp);
  2943. Option_read:=true;
  2944. end
  2945. else
  2946. if (s='WRITE') then
  2947. begin
  2948. Delete(opts,1,1);
  2949. DefaultReplacements(opts);
  2950. WriteLn(opts);
  2951. Option_read:=true;
  2952. end
  2953. else
  2954. if (s='INCLUDE') then
  2955. begin
  2956. Delete(opts,1,1);
  2957. DefaultReplacements(opts);
  2958. Interpret_file(opts);
  2959. Option_read:=true;
  2960. end
  2961. else
  2962. if (s='CFGDIR') then
  2963. begin
  2964. Delete(opts,1,1);
  2965. DefaultReplacements(opts);
  2966. ParaIncludeCfgPath.AddPath(opts,false);
  2967. Option_read:=true;
  2968. end;
  2969. end;
  2970. end
  2971. else
  2972. begin
  2973. if (opts[1]='-') or (opts[1]='@') then
  2974. begin
  2975. if (not skip[level]) then
  2976. interpret_option(opts,false);
  2977. Option_read:=true;
  2978. end
  2979. else
  2980. Message1(option_illegal_para,opts);
  2981. end;
  2982. end;
  2983. end;
  2984. if Level>0 then
  2985. Message(option_too_less_endif);
  2986. if Not Option_read then
  2987. Message1(option_no_option_found,filename)
  2988. else
  2989. Message1(option_end_reading_configfile,filename);
  2990. Close(f);
  2991. Dec(FileLevel);
  2992. end;
  2993. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  2994. var
  2995. argstart,
  2996. env,
  2997. pc : pchar;
  2998. arglen : longint;
  2999. quote : set of char;
  3000. hs : TCmdStr;
  3001. begin
  3002. Message1(option_using_env,envname);
  3003. env:=GetEnvPChar(envname);
  3004. pc:=env;
  3005. hs:='';
  3006. if assigned(pc) then
  3007. begin
  3008. repeat
  3009. { skip leading spaces }
  3010. while pc^ in [' ',#9,#13] do
  3011. inc(pc);
  3012. case pc^ of
  3013. #0 :
  3014. break;
  3015. '"' :
  3016. begin
  3017. quote:=['"'];
  3018. inc(pc);
  3019. end;
  3020. '''' :
  3021. begin
  3022. quote:=[''''];
  3023. inc(pc);
  3024. end;
  3025. else
  3026. quote:=[' ',#9,#13];
  3027. end;
  3028. { scan until the end of the argument }
  3029. argstart:=pc;
  3030. while (pc^<>#0) and not(pc^ in quote) do
  3031. inc(pc);
  3032. { create argument }
  3033. arglen:=pc-argstart;
  3034. { TODO: FIXME: silent truncation of environment parameters }
  3035. if (arglen > 255) then
  3036. arglen := 255;
  3037. setlength(hs,arglen);
  3038. move(argstart^,hs[1],arglen);
  3039. interpret_option(hs,true);
  3040. { skip quote }
  3041. if pc^ in quote then
  3042. inc(pc);
  3043. until false;
  3044. end
  3045. else
  3046. Message1(option_no_option_found,'(env) '+envname);
  3047. FreeEnvPChar(env);
  3048. end;
  3049. procedure toption.read_parameters;
  3050. var
  3051. opts : TCmdStr;
  3052. paramindex : longint;
  3053. begin
  3054. paramindex:=0;
  3055. while paramindex<paramcount do
  3056. begin
  3057. inc(paramindex);
  3058. opts:=objpas.paramstr(paramindex);
  3059. if length(opts)>0 then
  3060. case opts[1] of
  3061. '@' :
  3062. if not firstpass then
  3063. begin
  3064. Delete(opts,1,1);
  3065. Message1(option_reading_further_from,opts);
  3066. interpret_file(opts);
  3067. end;
  3068. '!' :
  3069. if not firstpass then
  3070. begin
  3071. Delete(opts,1,1);
  3072. Message1(option_reading_further_from,'(env) '+opts);
  3073. interpret_envvar(opts);
  3074. end;
  3075. else
  3076. interpret_option(opts,true);
  3077. end;
  3078. end;
  3079. end;
  3080. procedure toption.parsecmd(cmd:TCmdStr);
  3081. var
  3082. i,ps : longint;
  3083. opts : TCmdStr;
  3084. begin
  3085. while (cmd<>'') do
  3086. begin
  3087. while cmd[1]=' ' do
  3088. delete(cmd,1,1);
  3089. i:=pos(' ',cmd);
  3090. if i=0 then
  3091. i:=2147483647;
  3092. opts:=Copy(cmd,1,i-1);
  3093. Delete(cmd,1,i);
  3094. case opts[1] of
  3095. '@' :
  3096. if not firstpass then
  3097. begin
  3098. Delete(opts,1,1);
  3099. Message1(option_reading_further_from,opts);
  3100. interpret_file(opts);
  3101. end;
  3102. '!' :
  3103. if not firstpass then
  3104. begin
  3105. Delete(opts,1,1);
  3106. Message1(option_reading_further_from,'(env) '+opts);
  3107. interpret_envvar(opts);
  3108. end;
  3109. '"' :
  3110. begin
  3111. Delete(opts,1,1);
  3112. ps:=pos('"',cmd);
  3113. if (i<>256) and (ps>0) then
  3114. begin
  3115. opts:=opts + ' '+ copy(cmd,1,ps-1);
  3116. cmd:=copy(cmd,ps+1,255);
  3117. end;
  3118. interpret_option(opts,true);
  3119. end;
  3120. else
  3121. interpret_option(opts,true);
  3122. end;
  3123. end;
  3124. end;
  3125. procedure toption.writequickinfo;
  3126. var
  3127. s : string;
  3128. i : longint;
  3129. procedure addinfo(const hs:string);
  3130. begin
  3131. if s<>'' then
  3132. s:=s+' '+hs
  3133. else
  3134. s:=hs;
  3135. end;
  3136. begin
  3137. s:='';
  3138. i:=0;
  3139. while (i<length(quickinfo)) do
  3140. begin
  3141. inc(i);
  3142. case quickinfo[i] of
  3143. 'S' :
  3144. begin
  3145. inc(i);
  3146. case quickinfo[i] of
  3147. 'O' :
  3148. addinfo(lower(source_info.shortname));
  3149. 'P' :
  3150. addinfo(source_cpu_string);
  3151. else
  3152. IllegalPara('-i'+QuickInfo);
  3153. end;
  3154. end;
  3155. 'T' :
  3156. begin
  3157. inc(i);
  3158. case quickinfo[i] of
  3159. 'O' :
  3160. addinfo(lower(target_info.shortname));
  3161. 'P' :
  3162. AddInfo(target_cpu_string);
  3163. else
  3164. IllegalPara('-i'+QuickInfo);
  3165. end;
  3166. end;
  3167. 'V' :
  3168. AddInfo(version_string);
  3169. 'W' :
  3170. AddInfo(full_version_string);
  3171. 'D' :
  3172. AddInfo(date_string);
  3173. '_' :
  3174. ;
  3175. else
  3176. IllegalPara('-i'+QuickInfo);
  3177. end;
  3178. end;
  3179. if s<>'' then
  3180. begin
  3181. writeln(s);
  3182. stopoptions(0);
  3183. end;
  3184. end;
  3185. procedure TOption.TargetOptions(def:boolean);
  3186. var
  3187. s : string;
  3188. i : integer;
  3189. target_unsup_features : tfeatures;
  3190. begin
  3191. if def then
  3192. def_system_macro(target_info.shortname)
  3193. else
  3194. undef_system_macro(target_info.shortname);
  3195. s:=target_info.extradefines;
  3196. while (s<>'') do
  3197. begin
  3198. i:=pos(';',s);
  3199. if i=0 then
  3200. i:=length(s)+1;
  3201. if def then
  3202. def_system_macro(Copy(s,1,i-1))
  3203. else
  3204. undef_system_macro(Copy(s,1,i-1));
  3205. delete(s,1,i);
  3206. end;
  3207. if (tf_winlikewidestring in target_info.flags) then
  3208. if def then
  3209. def_system_macro('FPC_WINLIKEWIDESTRING')
  3210. else
  3211. undef_system_macro('FPC_WINLIKEWIDESTRING');
  3212. if (tf_requires_proper_alignment in target_info.flags) then
  3213. if def then
  3214. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  3215. else
  3216. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3217. if (tf_init_final_units_by_calls in target_info.flags) then
  3218. if def then
  3219. def_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS')
  3220. else
  3221. undef_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS');
  3222. if source_info.system<>target_info.system then
  3223. if def then
  3224. def_system_macro('FPC_CROSSCOMPILING')
  3225. else
  3226. undef_system_macro('FPC_CROSSCOMPILING');
  3227. if source_info.cpu<>target_info.cpu then
  3228. if def then
  3229. def_system_macro('FPC_CPUCROSSCOMPILING')
  3230. else
  3231. def_system_macro('FPC_CPUCROSSCOMPILING');
  3232. if (tf_no_generic_stackcheck in target_info.flags) then
  3233. if def then
  3234. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  3235. else
  3236. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  3237. if (tf_section_threadvars in target_info.flags) then
  3238. if def then
  3239. def_system_macro('FPC_SECTION_THREADVARS')
  3240. else
  3241. undef_system_macro('FPC_SECTION_THREADVARS');
  3242. if (tf_use_psabieh in target_info.flags) then
  3243. if def then
  3244. def_system_macro('FPC_USE_PSABIEH')
  3245. else
  3246. undef_system_macro('FPC_USE_PSABIEH');
  3247. { Code generation flags }
  3248. if (tf_pic_default in target_info.flags) then
  3249. if def then
  3250. include(init_settings.moduleswitches,cs_create_pic)
  3251. else
  3252. exclude(init_settings.moduleswitches,cs_create_pic);
  3253. { Resources support }
  3254. if (tf_has_winlike_resources in target_info.flags) then
  3255. if def then
  3256. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  3257. else
  3258. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  3259. { Features }
  3260. case target_info.system of
  3261. system_arm_gba:
  3262. target_unsup_features:=[f_dynlibs];
  3263. system_arm_nds:
  3264. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  3265. system_i386_nativent:
  3266. // until these features are implemented, they are disabled in the compiler
  3267. target_unsup_features:=[f_stackcheck];
  3268. system_i8086_msdos:
  3269. target_unsup_features:=[f_threading,f_dynlibs];
  3270. system_i8086_win16:
  3271. target_unsup_features:=[f_threading];
  3272. system_jvm_java32,
  3273. system_jvm_android32:
  3274. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  3275. f_variants,f_objects,f_commandargs,
  3276. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  3277. system_arm_palmos,
  3278. system_m68k_palmos:
  3279. target_unsup_features:=[f_threading];
  3280. system_m68k_atari:
  3281. target_unsup_features:=[f_threading];
  3282. { classic amiga has dynamic libraries, but they cannot be integrated in the
  3283. normal dynlibs infrastructure due to architectural differences, so therefore
  3284. lets disable the feature. }
  3285. system_m68k_amiga:
  3286. target_unsup_features:=[f_dynlibs];
  3287. system_m68k_sinclairql:
  3288. target_unsup_features:=[f_threading,f_dynlibs,f_commandargs,f_exitcode];
  3289. system_z80_zxspectrum:
  3290. target_unsup_features:=[f_threading,f_dynlibs{,f_fileio,f_textio},f_commandargs,f_exitcode];
  3291. system_z80_msxdos:
  3292. target_unsup_features:=[f_threading,f_dynlibs];
  3293. else
  3294. target_unsup_features:=[];
  3295. end;
  3296. if def then
  3297. features:=features-target_unsup_features
  3298. else
  3299. features:=features+target_unsup_features;
  3300. {$if defined(atari) or defined(hasamiga)}
  3301. { enable vlink as default linker on Atari and Amiga but not for cross compilers (for now) }
  3302. if (target_info.system in [system_m68k_amiga,system_m68k_atari,system_powerpc_amiga]) and
  3303. not LinkerSetExplicitly then
  3304. include(init_settings.globalswitches,cs_link_vlink);
  3305. {$endif}
  3306. {$ifdef m68k}
  3307. if (target_info.system in [system_m68k_sinclairql]) and
  3308. not LinkerSetExplicitly then
  3309. include(init_settings.globalswitches,cs_link_vlink);
  3310. {$endif m68k}
  3311. end;
  3312. procedure TOption.checkoptionscompatibility;
  3313. begin
  3314. {$ifdef i8086}
  3315. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  3316. begin
  3317. Message(option_com_files_require_tiny_model);
  3318. StopOptions(1);
  3319. end;
  3320. {$endif i8086}
  3321. {$ifndef i8086_link_intern_debuginfo}
  3322. if (cs_debuginfo in init_settings.moduleswitches) and
  3323. (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) and
  3324. not (cs_link_extern in init_settings.globalswitches) then
  3325. begin
  3326. Message(option_debug_info_requires_external_linker);
  3327. include(init_settings.globalswitches,cs_link_extern);
  3328. end;
  3329. {$endif i8086_link_intern_debuginfo}
  3330. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  3331. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  3332. begin
  3333. { smartlink creation does not yet work with DWARF
  3334. debug info on most targets, but it works in internal assembler }
  3335. if (cs_create_smart in init_settings.moduleswitches) and
  3336. not (af_outputbinary in target_asm.flags) then
  3337. begin
  3338. Message(option_dwarf_smartlink_creation);
  3339. exclude(init_settings.moduleswitches,cs_create_smart);
  3340. end;
  3341. { smart linking does not yet work with DWARF debug info on most targets }
  3342. if (cs_link_smart in init_settings.globalswitches) then
  3343. begin
  3344. Message(option_dwarf_smart_linking);
  3345. ForceStaticLinking;
  3346. end;
  3347. end;
  3348. { external debug info is only supported for DWARF on darwin }
  3349. if (target_info.system in systems_darwin) and
  3350. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  3351. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  3352. begin
  3353. Message(option_debug_external_unsupported);
  3354. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  3355. end;
  3356. { Also create a smartlinked version, on an assembler that
  3357. does not support smartlink sections like nasm?
  3358. This is not compatible with using internal linker. }
  3359. if ((cs_link_smart in init_settings.globalswitches) or
  3360. (cs_create_smart in init_settings.moduleswitches)) and
  3361. (af_needar in target_asm.flags) and
  3362. not (af_smartlink_sections in target_asm.flags) and
  3363. not (cs_link_extern in init_settings.globalswitches) and
  3364. (target_info.link<>ld_none) and
  3365. not (cs_link_nolink in init_settings.globalswitches) then
  3366. begin
  3367. Message(option_smart_link_requires_external_linker);
  3368. include(init_settings.globalswitches,cs_link_extern);
  3369. end;
  3370. end;
  3371. constructor TOption.create;
  3372. begin
  3373. LogoWritten:=false;
  3374. NoPressEnter:=false;
  3375. FirstPass:=false;
  3376. ABISetExplicitly:=false;
  3377. FPUSetExplicitly:=false;
  3378. CPUSetExplicitly:=false;
  3379. OptCPUSetExplicitly:=false;
  3380. FileLevel:=0;
  3381. Quickinfo:='';
  3382. ParaIncludeCfgPath:=TSearchPathList.Create;
  3383. ParaIncludePath:=TSearchPathList.Create;
  3384. ParaObjectPath:=TSearchPathList.Create;
  3385. ParaUnitPath:=TSearchPathList.Create;
  3386. ParaLibraryPath:=TSearchPathList.Create;
  3387. ParaFrameworkPath:=TSearchPathList.Create;
  3388. parapackagepath:=TSearchPathList.Create;
  3389. parapackages:=TFPHashObjectList.Create;
  3390. paranamespaces:=TCmdStrList.Create;
  3391. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3392. MacVersionSet:=false;
  3393. paratarget:=system_none;
  3394. paratargetasm:=as_none;
  3395. paratargetdbg:=dbg_none;
  3396. LinkTypeSetExplicitly:=false;
  3397. LinkerSetExplicitly:=false;
  3398. end;
  3399. destructor TOption.destroy;
  3400. begin
  3401. ParaIncludeCfgPath.Free;
  3402. ParaIncludePath.Free;
  3403. ParaObjectPath.Free;
  3404. ParaUnitPath.Free;
  3405. ParaLibraryPath.Free;
  3406. ParaFrameworkPath.Free;
  3407. parapackagepath.Free;
  3408. ParaPackages.Free;
  3409. paranamespaces.free;
  3410. end;
  3411. {****************************************************************************
  3412. Callable Routines
  3413. ****************************************************************************}
  3414. function check_configfile(fn:string; var foundfn:string):boolean;
  3415. function CfgFileExists(const fn:string):boolean;
  3416. begin
  3417. Comment(V_Tried,'Configfile search: '+fn);
  3418. CfgFileExists:=FileExists(fn);
  3419. end;
  3420. var
  3421. {$ifdef Unix}
  3422. hs,
  3423. {$endif Unix}
  3424. configpath : string;
  3425. begin
  3426. foundfn:=fn;
  3427. check_configfile:=true;
  3428. { retrieve configpath }
  3429. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3430. {$ifdef Unix}
  3431. if configpath='' then
  3432. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3433. {$endif}
  3434. {
  3435. Order to read configuration file :
  3436. try reading fpc.cfg in :
  3437. 1 - current dir
  3438. 2 - configpath
  3439. 3 - compiler path
  3440. }
  3441. if not FileExists(fn) then
  3442. begin
  3443. {$ifdef Unix}
  3444. hs:=GetEnvironmentVariable('HOME');
  3445. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3446. foundfn:=FixPath(hs,false)+'.'+fn
  3447. else
  3448. {$endif}
  3449. if CfgFileExists(configpath+fn) then
  3450. foundfn:=configpath+fn
  3451. else
  3452. {$ifdef WINDOWS}
  3453. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3454. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3455. else
  3456. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3457. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3458. else
  3459. {$endif WINDOWS}
  3460. {$ifndef Unix}
  3461. if CfgFileExists(exepath+fn) then
  3462. foundfn:=exepath+fn
  3463. else
  3464. {$else}
  3465. if CfgFileExists('/etc/'+fn) then
  3466. foundfn:='/etc/'+fn
  3467. else
  3468. {$endif}
  3469. check_configfile:=false;
  3470. end;
  3471. end;
  3472. procedure read_arguments(cmd:TCmdStr);
  3473. procedure def_cpu_macros;
  3474. var
  3475. abi : tabi;
  3476. fputype : tfputype;
  3477. cputype : tcputype;
  3478. controller: tcontrollertype;
  3479. s: string;
  3480. begin
  3481. {$ifdef llvm}
  3482. def_system_macro('CPULLVM');
  3483. {$endif}
  3484. for cputype:=low(tcputype) to high(tcputype) do
  3485. undef_system_macro('CPU'+Cputypestr[cputype]);
  3486. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3487. for fputype:=low(tfputype) to high(tfputype) do
  3488. undef_system_macro('FPU'+fputypestr[fputype]);
  3489. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3490. {$PUSH}
  3491. {$WARN 6018 OFF} { Unreachable code due to compile time evaluation }
  3492. if ControllerSupport then
  3493. begin
  3494. for controller:=low(tcontrollertype) to high(tcontrollertype) do
  3495. begin
  3496. s:=embedded_controllers[controller].controllertypestr;
  3497. if s<>'' then
  3498. undef_system_macro('FPC_MCU_'+s);
  3499. end;
  3500. s:=embedded_controllers[init_settings.controllertype].controllertypestr;
  3501. if s<>'' then
  3502. def_system_macro('FPC_MCU_'+s);
  3503. end;
  3504. {$POP}
  3505. { define abi }
  3506. for abi:=low(tabi) to high(tabi) do
  3507. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3508. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3509. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3510. systems since most code needs to behave the same on both}
  3511. if target_info.abi = abi_eabihf then
  3512. def_system_macro('FPC_ABI_EABI');
  3513. { using a case is pretty useless here (FK) }
  3514. { some stuff for TP compatibility }
  3515. {$ifdef i386}
  3516. def_system_macro('CPU86');
  3517. def_system_macro('CPU87');
  3518. def_system_macro('CPU386');
  3519. {$endif}
  3520. { new processor stuff }
  3521. {$ifdef i386}
  3522. def_system_macro('CPUI386');
  3523. def_system_macro('CPU32');
  3524. def_system_macro('CPUX86');
  3525. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3526. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3527. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3528. {$endif}
  3529. {$ifdef m68k}
  3530. def_system_macro('CPU68');
  3531. def_system_macro('CPU68K');
  3532. def_system_macro('CPUM68K');
  3533. def_system_macro('CPU32');
  3534. def_system_macro('FPC_CURRENCY_IS_INT64');
  3535. def_system_macro('FPC_COMP_IS_INT64');
  3536. {$endif}
  3537. {$ifdef powerpc}
  3538. def_system_macro('CPUPOWERPC');
  3539. def_system_macro('CPUPOWERPC32');
  3540. def_system_macro('CPU32');
  3541. def_system_macro('FPC_CURRENCY_IS_INT64');
  3542. def_system_macro('FPC_COMP_IS_INT64');
  3543. {$endif}
  3544. {$ifdef POWERPC64}
  3545. def_system_macro('CPUPOWERPC');
  3546. def_system_macro('CPUPOWERPC64');
  3547. def_system_macro('CPU64');
  3548. def_system_macro('FPC_CURRENCY_IS_INT64');
  3549. def_system_macro('FPC_COMP_IS_INT64');
  3550. {$endif}
  3551. {$ifdef x86_64}
  3552. def_system_macro('CPUX86_64');
  3553. def_system_macro('CPUAMD64');
  3554. def_system_macro('CPU64');
  3555. def_system_macro('CPUX64');
  3556. { not supported for now, afaik (FK)
  3557. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3558. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3559. { normally, win64 doesn't support the legacy fpu }
  3560. if target_info.system=system_x86_64_win64 then
  3561. begin
  3562. def_system_macro('FPC_CURRENCY_IS_INT64');
  3563. def_system_macro('FPC_COMP_IS_INT64');
  3564. end;
  3565. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3566. {$endif}
  3567. {$ifdef sparc}
  3568. def_system_macro('CPUSPARCGEN');
  3569. def_system_macro('CPUSPARC');
  3570. def_system_macro('CPUSPARC32');
  3571. def_system_macro('CPU32');
  3572. def_system_macro('FPC_CURRENCY_IS_INT64');
  3573. def_system_macro('FPC_COMP_IS_INT64');
  3574. {$endif}
  3575. {$ifdef sparc64}
  3576. def_system_macro('CPUSPARCGEN');
  3577. def_system_macro('CPUSPARC64');
  3578. def_system_macro('CPU64');
  3579. def_system_macro('FPC_CURRENCY_IS_INT64');
  3580. def_system_macro('FPC_COMP_IS_INT64');
  3581. {$endif}
  3582. {$ifdef arm}
  3583. def_system_macro('CPUARM');
  3584. def_system_macro('CPU32');
  3585. def_system_macro('FPC_CURRENCY_IS_INT64');
  3586. def_system_macro('FPC_COMP_IS_INT64');
  3587. {$endif arm}
  3588. {$ifdef avr}
  3589. def_system_macro('CPUAVR');
  3590. def_system_macro('CPU16');
  3591. def_system_macro('FPC_CURRENCY_IS_INT64');
  3592. def_system_macro('FPC_COMP_IS_INT64');
  3593. {$endif avr}
  3594. {$ifdef jvm}
  3595. def_system_macro('CPUJVM');
  3596. def_system_macro('CPU32');
  3597. def_system_macro('FPC_CURRENCY_IS_INT64');
  3598. def_system_macro('FPC_COMP_IS_INT64');
  3599. {$endif jvm}
  3600. {$ifdef mipsel}
  3601. def_system_macro('CPUMIPS');
  3602. def_system_macro('CPUMIPS32');
  3603. def_system_macro('CPUMIPSEL');
  3604. def_system_macro('CPUMIPSEL32');
  3605. def_system_macro('CPU32');
  3606. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3607. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3608. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3609. def_system_macro('FPC_CURRENCY_IS_INT64');
  3610. def_system_macro('FPC_COMP_IS_INT64');
  3611. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3612. { On most systems, locals are accessed relative to base pointer,
  3613. but for MIPS cpu, they are accessed relative to stack pointer.
  3614. This needs adaptation for so low level routines,
  3615. like MethodPointerLocal and related objects unit functions. }
  3616. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3617. {$endif mipsel}
  3618. {$ifdef mipseb}
  3619. def_system_macro('CPUMIPS');
  3620. def_system_macro('CPUMIPS32');
  3621. def_system_macro('CPUMIPSEB');
  3622. def_system_macro('CPUMIPSEB32');
  3623. def_system_macro('CPU32');
  3624. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3625. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3626. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3627. def_system_macro('FPC_CURRENCY_IS_INT64');
  3628. def_system_macro('FPC_COMP_IS_INT64');
  3629. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3630. { See comment above for mipsel }
  3631. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3632. {$endif}
  3633. {$ifdef i8086}
  3634. def_system_macro('CPU86'); { Borland compatibility }
  3635. def_system_macro('CPU87'); { Borland compatibility }
  3636. def_system_macro('CPUI8086');
  3637. def_system_macro('CPU16');
  3638. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3639. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3640. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3641. case init_settings.x86memorymodel of
  3642. mm_tiny: def_system_macro('FPC_MM_TINY');
  3643. mm_small: def_system_macro('FPC_MM_SMALL');
  3644. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3645. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3646. mm_large: def_system_macro('FPC_MM_LARGE');
  3647. mm_huge: def_system_macro('FPC_MM_HUGE');
  3648. end;
  3649. {$endif i8086}
  3650. {$ifdef aarch64}
  3651. def_system_macro('CPUAARCH64');
  3652. def_system_macro('CPU64');
  3653. def_system_macro('FPC_CURRENCY_IS_INT64');
  3654. def_system_macro('FPC_COMP_IS_INT64');
  3655. {$endif aarch64}
  3656. {$ifdef riscv32}
  3657. def_system_macro('CPURISCV');
  3658. def_system_macro('CPURISCV32');
  3659. def_system_macro('CPU32');
  3660. def_system_macro('FPC_CURRENCY_IS_INT64');
  3661. def_system_macro('FPC_COMP_IS_INT64');
  3662. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3663. {$endif riscv32}
  3664. {$ifdef riscv64}
  3665. def_system_macro('CPURISCV');
  3666. def_system_macro('CPURISCV64');
  3667. def_system_macro('CPU64');
  3668. def_system_macro('FPC_CURRENCY_IS_INT64');
  3669. def_system_macro('FPC_COMP_IS_INT64');
  3670. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3671. {$endif riscv64}
  3672. {$ifdef xtensa}
  3673. def_system_macro('CPUXTENSA');
  3674. def_system_macro('CPU32');
  3675. def_system_macro('FPC_CURRENCY_IS_INT64');
  3676. def_system_macro('FPC_COMP_IS_INT64');
  3677. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3678. {$endif xtensa}
  3679. {$ifdef z80}
  3680. def_system_macro('CPUZ80');
  3681. def_system_macro('CPU16');
  3682. def_system_macro('FPC_CURRENCY_IS_INT64');
  3683. def_system_macro('FPC_COMP_IS_INT64');
  3684. {$endif z80}
  3685. {$ifdef wasm}
  3686. def_system_macro('CPUWASM');
  3687. def_system_macro('CPU32');
  3688. def_system_macro('FPC_CURRENCY_IS_INT64');
  3689. def_system_macro('FPC_COMP_IS_INT64');
  3690. {$endif wasm}
  3691. {$if defined(cpu8bitalu)}
  3692. def_system_macro('CPUINT8');
  3693. {$elseif defined(cpu16bitalu)}
  3694. def_system_macro('CPUINT16');
  3695. {$elseif defined(cpu32bitalu)}
  3696. def_system_macro('CPUINT32');
  3697. {$elseif defined(cpu64bitalu)}
  3698. def_system_macro('CPUINT64');
  3699. {$endif defined(cpu64bitalu)}
  3700. {$if defined(avr)}
  3701. def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
  3702. {$endif}
  3703. {$if defined(i8086) or defined(avr)}
  3704. def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
  3705. {$endif i8086 or avr}
  3706. { abs(long) is handled internally on all CPUs }
  3707. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  3708. {$if defined(i8086) or defined(i386) or defined(x86_64) or defined(powerpc64) or defined(aarch64)}
  3709. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  3710. {$endif i8086 or i386 or x86_64 or powerpc64 or aarch64}
  3711. def_system_macro('FPC_HAS_UNICODESTRING');
  3712. def_system_macro('FPC_RTTI_PACKSET1');
  3713. def_system_macro('FPC_HAS_CPSTRING');
  3714. {$ifdef x86_64}
  3715. def_system_macro('FPC_HAS_RIP_RELATIVE');
  3716. {$endif x86_64}
  3717. def_system_macro('FPC_HAS_CEXTENDED');
  3718. def_system_macro('FPC_HAS_RESSTRINITS');
  3719. { these cpus have an inline rol/ror implementaion }
  3720. {$ifdef cpurox}
  3721. {$ifdef m68k}
  3722. if CPUM68K_HAS_ROLROR in cpu_capabilities[init_settings.cputype] then
  3723. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3724. {$else}
  3725. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3726. {$endif}
  3727. {$endif}
  3728. {$ifdef powerpc64}
  3729. def_system_macro('FPC_HAS_LWSYNC');
  3730. {$endif}
  3731. { currently, all supported CPUs have an internal sar implementation }
  3732. def_system_macro('FPC_HAS_INTERNAL_SAR');
  3733. {$ifdef SUPPORT_GET_FRAME}
  3734. def_system_macro('INTERNAL_BACKTRACE');
  3735. {$endif SUPPORT_GET_FRAME}
  3736. def_system_macro('STR_CONCAT_PROCS');
  3737. {$warnings off}
  3738. if pocall_default = pocall_register then
  3739. def_system_macro('REGCALL');
  3740. {$warnings on}
  3741. end;
  3742. var
  3743. env: ansistring;
  3744. i : tfeature;
  3745. j : longint;
  3746. tmplist : TCmdStrList;
  3747. cmditem,
  3748. tmpcmditem : TCmdStrListItem;
  3749. cmdstr : TCmdStr;
  3750. {$if defined(cpucapabilities)}
  3751. cpuflag : tcpuflags;
  3752. {$endif defined(cpucapabilities)}
  3753. {$if defined(fpucapabilities)}
  3754. fpuflag : tfpuflags;
  3755. {$endif defined(fpucapabilities)}
  3756. {$if defined(cpucapabilities) or defined(fpucapabilities)}
  3757. hs : string;
  3758. {$endif defined(cpucapabilities) or defined(fpucapabilities)}
  3759. begin
  3760. option:=coption.create;
  3761. disable_configfile:=false;
  3762. { Non-core target defines }
  3763. Option.TargetOptions(true);
  3764. { get default messagefile }
  3765. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  3766. { default configfile can be specified on the commandline,
  3767. remove it first }
  3768. if (cmd<>'') and (cmd[1]='[') then
  3769. begin
  3770. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  3771. Delete(cmd,1,pos(']',cmd));
  3772. end
  3773. else
  3774. ppccfg:='fpc.cfg';
  3775. { first pass reading of parameters, only -i -v -T etc.}
  3776. option.firstpass:=true;
  3777. if cmd<>'' then
  3778. option.parsecmd(cmd)
  3779. else
  3780. begin
  3781. option.read_parameters;
  3782. { Write only quickinfo }
  3783. if option.quickinfo<>'' then
  3784. option.writequickinfo;
  3785. end;
  3786. option.firstpass:=false;
  3787. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  3788. Option.TargetOptions(true);
  3789. { target is set here, for wince the default app type is gui }
  3790. if target_info.system in systems_wince then
  3791. SetApptype(app_gui)
  3792. else
  3793. SetApptype(apptype);
  3794. { default defines }
  3795. def_system_macro(target_info.shortname);
  3796. def_system_macro('FPC');
  3797. def_system_macro('VER'+version_nr);
  3798. def_system_macro('VER'+version_nr+'_'+release_nr);
  3799. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  3800. { Temporary defines, until things settle down }
  3801. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  3802. def_system_macro('FPC_HAS_CONSTREF');
  3803. def_system_macro('FPC_STATICRIPFIXED');
  3804. def_system_macro('FPC_VARIANTCOPY_FIXED');
  3805. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  3806. def_system_macro('FPC_HAS_MEMBAR');
  3807. def_system_macro('FPC_SETBASE_USED');
  3808. def_system_macro('FPC_ALIGNED_THREADVARTABLES');
  3809. { don't remove this, it's also for fpdoc necessary (FK) }
  3810. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  3811. { make cpu makros available when reading the config files the second time }
  3812. def_cpu_macros;
  3813. if tf_cld in target_info.flags then
  3814. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  3815. InternalError(2013092801);
  3816. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  3817. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  3818. InternalError(2013092802);
  3819. { Use standard Android NDK prefixes when cross-compiling }
  3820. if (source_info.system<>target_info.system) and (target_info.system in systems_android) then
  3821. case target_info.system of
  3822. system_arm_android:
  3823. utilsprefix:='arm-linux-androideabi-';
  3824. system_i386_android:
  3825. utilsprefix:='i686-linux-android-';
  3826. else
  3827. utilsprefix:=target_cpu_string + '-linux-android-';
  3828. end;
  3829. { Set up default value for the heap }
  3830. if target_info.system in (systems_embedded+systems_freertos+[system_z80_zxspectrum,system_z80_msxdos]) then
  3831. begin
  3832. case target_info.system of
  3833. {$ifdef AVR}
  3834. system_avr_embedded:
  3835. if init_settings.controllertype=ct_avrsim then
  3836. heapsize:=8192
  3837. else
  3838. heapsize:=128;
  3839. {$endif AVR}
  3840. system_arm_freertos:
  3841. heapsize:=8192;
  3842. system_xtensa_freertos:
  3843. { keep default value }
  3844. ;
  3845. system_arm_embedded:
  3846. heapsize:=256;
  3847. system_mipsel_embedded:
  3848. heapsize:=256;
  3849. else
  3850. heapsize:=256;
  3851. end;
  3852. end;
  3853. { read configuration file }
  3854. if (not disable_configfile) and
  3855. (ppccfg<>'') then
  3856. read_configfile:=check_configfile(ppccfg,ppccfg)
  3857. else
  3858. read_configfile := false;
  3859. { Read commandline and configfile }
  3860. param_file:='';
  3861. { read configfile }
  3862. if read_configfile then
  3863. option.interpret_file(ppccfg);
  3864. { read parameters again to override config file }
  3865. if cmd<>'' then
  3866. option.parsecmd(cmd)
  3867. else
  3868. begin
  3869. { Write help pages if no parameters are passed }
  3870. if (paramcount=0) then
  3871. Option.WriteHelpPages;
  3872. option.read_parameters;
  3873. { Write only quickinfo }
  3874. if option.quickinfo<>'' then
  3875. option.writequickinfo;
  3876. end;
  3877. { check the compatibility of different options and adjust them if necessary
  3878. (and print possible errors)
  3879. }
  3880. option.checkoptionscompatibility;
  3881. { uses the CPUXXX-defines and target_info to determine whether the selected
  3882. target processor, if any, is supported }
  3883. Option.VerifyTargetProcessor;
  3884. { Stop if errors in options }
  3885. if ErrorCount>0 then
  3886. StopOptions(1);
  3887. { endian define }
  3888. case target_info.endian of
  3889. endian_little :
  3890. begin
  3891. def_system_macro('ENDIAN_LITTLE');
  3892. def_system_macro('FPC_LITTLE_ENDIAN');
  3893. end;
  3894. endian_big :
  3895. begin
  3896. def_system_macro('ENDIAN_BIG');
  3897. def_system_macro('FPC_BIG_ENDIAN');
  3898. end;
  3899. end;
  3900. { Write logo }
  3901. if option.ParaLogo then
  3902. option.writelogo;
  3903. { Check file to compile }
  3904. if param_file='' then
  3905. begin
  3906. Message(option_no_source_found);
  3907. StopOptions(1);
  3908. end;
  3909. {$ifndef Unix}
  3910. param_file:=FixFileName(param_file);
  3911. {$endif not unix}
  3912. inputfilepath:=ExtractFilePath(param_file);
  3913. inputfilename:=ExtractFileName(param_file);
  3914. if ExtractFileExt(inputfilename)='' then
  3915. begin
  3916. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  3917. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  3918. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  3919. inputfilename:=ChangeFileExt(inputfilename,pasext)
  3920. else if ((m_mac in current_settings.modeswitches) or
  3921. (tf_p_ext_support in target_info.flags))
  3922. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  3923. inputfilename:=ChangeFileExt(inputfilename,pext);
  3924. end;
  3925. { Check output dir }
  3926. if (OutputExeDir<>'') and
  3927. not PathExists(OutputExeDir,false) then
  3928. begin
  3929. Message1(general_e_path_does_not_exist,OutputExeDir);
  3930. StopOptions(1);
  3931. end;
  3932. { Add paths specified with parameters to the searchpaths }
  3933. UnitSearchPath.AddList(option.ParaUnitPath,true);
  3934. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  3935. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  3936. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  3937. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  3938. packagesearchpath.addlist(option.parapackagepath,true);
  3939. for j:=0 to option.parapackages.count-1 do
  3940. add_package(option.parapackages.NameOfIndex(j),true,true);
  3941. { add default namespaces }
  3942. tmplist:=TCmdStrList.Create;
  3943. cmditem:=TCmdStrListItem(option.paranamespaces.First);
  3944. while assigned(cmditem) do
  3945. begin
  3946. { use a temporary list cause if ";" are involved we need to reverse the
  3947. order due to how TCmdStrList behaves }
  3948. cmdstr:=cmditem.str;
  3949. repeat
  3950. j:=Pos(';',cmdstr);
  3951. if j>0 then
  3952. begin
  3953. tmplist.insert(copy(cmdstr,1,j-1));
  3954. delete(cmdstr,1,j);
  3955. end
  3956. else
  3957. tmplist.insert(cmdstr);
  3958. until j=0;
  3959. tmpcmditem:=TCmdStrListItem(tmplist.First);
  3960. while assigned(tmpcmditem) do
  3961. begin
  3962. namespacelist.insert(tmpcmditem.Str);
  3963. tmpcmditem:=TCmdStrListItem(tmpcmditem.Next);
  3964. end;
  3965. tmplist.clear;
  3966. cmditem:=TCmdStrListItem(cmditem.Next);
  3967. end;
  3968. tmplist.Free;
  3969. { add unit environment and exepath to the unit search path }
  3970. if inputfilepath<>'' then
  3971. Unitsearchpath.AddPath(inputfilepath,true);
  3972. if not disable_configfile then
  3973. begin
  3974. env:=GetEnvironmentVariable(target_info.unit_env);
  3975. if env<>'' then
  3976. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  3977. end;
  3978. {$ifdef Unix}
  3979. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3980. if fpcdir='' then
  3981. begin
  3982. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  3983. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  3984. else
  3985. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  3986. end;
  3987. {$else unix}
  3988. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3989. if fpcdir='' then
  3990. begin
  3991. fpcdir:=ExePath+'../';
  3992. if not(PathExists(fpcdir+'units',true)) and
  3993. not(PathExists(fpcdir+'rtl',true)) then
  3994. fpcdir:=fpcdir+'../';
  3995. end;
  3996. {$endif unix}
  3997. { first try development RTL, else use the default installation path }
  3998. if not disable_configfile then
  3999. begin
  4000. if PathExists(FpcDir+'rtl',true) then
  4001. if (tf_use_8_3 in Source_Info.Flags) or
  4002. (tf_use_8_3 in Target_Info.Flags) then
  4003. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  4004. else
  4005. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  4006. else
  4007. if (tf_use_8_3 in Source_Info.Flags) or
  4008. (tf_use_8_3 in Target_Info.Flags) then
  4009. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  4010. else
  4011. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  4012. end;
  4013. { Add exepath if the exe is not in the current dir, because that is always searched already.
  4014. Do not add it when linking on the target because then we can maybe already find
  4015. .o files that are not for the target }
  4016. if (ExePath<>cfileutl.GetCurrentDir) and
  4017. not(cs_link_on_target in init_settings.globalswitches) then
  4018. UnitSearchPath.AddPath(ExePath,false);
  4019. { Add unit dir to the object and library path }
  4020. objectsearchpath.AddList(unitsearchpath,false);
  4021. librarysearchpath.AddList(unitsearchpath,false);
  4022. {$ifdef llvm}
  4023. { default to clang }
  4024. if (option.paratargetasm=as_none) then
  4025. begin
  4026. option.paratargetasm:=as_clang_llvm;
  4027. end;
  4028. {$endif llvm}
  4029. { maybe override assembler }
  4030. if (option.paratargetasm<>as_none) then
  4031. begin
  4032. if not set_target_asm(option.paratargetasm) then
  4033. begin
  4034. if assigned(asminfos[option.paratargetasm]) then
  4035. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name)
  4036. else
  4037. Message2(option_incompatible_asm,'<invalid assembler>',target_info.name);
  4038. set_target_asm(target_info.assemextern);
  4039. Message1(option_asm_forced,target_asm.idtxt);
  4040. end;
  4041. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  4042. (option.paratargetdbg<>dbg_none) then
  4043. begin
  4044. Message1(option_confict_asm_debug,
  4045. asminfos[option.paratargetasm]^.idtxt);
  4046. option.paratargetdbg:=dbg_none;
  4047. exclude(init_settings.moduleswitches,cs_debuginfo);
  4048. end;
  4049. { Some assemblers, like clang, do not support
  4050. stabs debugging format, switch to dwardé in that case }
  4051. if (af_no_stabs in asminfos[option.paratargetasm]^.flags) and
  4052. (option.paratargetdbg=dbg_stabs) then
  4053. begin
  4054. option.paratargetdbg:=dbg_dwarf2;
  4055. end;
  4056. end;
  4057. {TOptionheck a second time as we might have changed assembler just above }
  4058. option.checkoptionscompatibility;
  4059. { maybe override debug info format }
  4060. if (option.paratargetdbg<>dbg_none) then
  4061. if not set_target_dbg(option.paratargetdbg) then
  4062. Message(option_w_unsupported_debug_format);
  4063. { switch assembler if it's binary and we got -a on the cmdline }
  4064. if ((cs_asm_leave in init_settings.globalswitches) and
  4065. (af_outputbinary in target_asm.flags)) or
  4066. { if -s is passed, we shouldn't call the internal assembler }
  4067. (cs_asm_extern in init_settings.globalswitches) then
  4068. begin
  4069. Message(option_switch_bin_to_src_assembler);
  4070. {$ifdef llvm}
  4071. set_target_asm(as_clang_llvm);
  4072. {$else}
  4073. set_target_asm(target_info.assemextern);
  4074. {$endif}
  4075. { At least i8086 needs that for nasm and -CX
  4076. which is incompatible with internal linker }
  4077. option.checkoptionscompatibility;
  4078. end;
  4079. { Force use of external linker if there is no
  4080. internal linker or the linking is skipped }
  4081. if not(cs_link_extern in init_settings.globalswitches) and
  4082. ((target_info.link=ld_none) or
  4083. (cs_link_nolink in init_settings.globalswitches)) then
  4084. begin
  4085. include(init_settings.globalswitches,cs_link_extern);
  4086. end;
  4087. { turn off stripping if compiling with debuginfo or profile }
  4088. if (
  4089. (cs_debuginfo in init_settings.moduleswitches) or
  4090. (cs_profile in init_settings.moduleswitches)
  4091. ) and
  4092. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  4093. exclude(init_settings.globalswitches,cs_link_strip);
  4094. { choose a reasonable tls model }
  4095. if (tf_section_threadvars in target_info.flags) and (init_settings.tlsmodel=tlsm_none) then
  4096. begin
  4097. if cs_create_pic in init_settings.moduleswitches then
  4098. init_settings.tlsmodel:=tlsm_global_dynamic
  4099. else
  4100. init_settings.tlsmodel:=tlsm_local_exec;
  4101. end;
  4102. { set Mac OS X version default macros if not specified explicitly }
  4103. option.MaybeSetDefaultMacVersionMacro;
  4104. {$ifdef cpufpemu}
  4105. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  4106. if fpu type not explicitly set }
  4107. if not(option.FPUSetExplicitly) and
  4108. ((target_info.system in [system_arm_wince,system_arm_gba,
  4109. system_m68k_amiga,system_m68k_atari,
  4110. system_arm_nds,system_arm_embedded,system_arm_freertos,
  4111. system_riscv32_embedded,system_riscv64_embedded,system_xtensa_linux,
  4112. system_z80_embedded,system_z80_zxspectrum])
  4113. {$ifdef arm}
  4114. or (target_info.abi=abi_eabi)
  4115. {$endif arm}
  4116. )
  4117. or (init_settings.fputype=fpu_soft)
  4118. then
  4119. begin
  4120. include(init_settings.moduleswitches,cs_fp_emulation);
  4121. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  4122. init_settings.fputype:=fpu_soft;
  4123. end;
  4124. {$endif cpufpemu}
  4125. {$ifdef i386}
  4126. if target_info.system in systems_i386_default_486 then
  4127. begin
  4128. { Avoid use of MMX/CMOVcc instructions on older systems.
  4129. Some systems might not handle these instructions correctly,
  4130. Used emulators might also be problematic. PM }
  4131. if not option.CPUSetExplicitly then
  4132. init_settings.cputype:=cpu_486;
  4133. end;
  4134. case target_info.system of
  4135. system_i386_android:
  4136. begin
  4137. { set default cpu type to PentiumM for Android unless specified otherwise }
  4138. if not option.CPUSetExplicitly then
  4139. init_settings.cputype:=cpu_PentiumM;
  4140. if not option.OptCPUSetExplicitly then
  4141. init_settings.optimizecputype:=cpu_PentiumM;
  4142. { set default fpu type to SSSE3 for Android unless specified otherwise }
  4143. if not option.FPUSetExplicitly then
  4144. init_settings.fputype:=fpu_ssse3;
  4145. end;
  4146. else
  4147. ;
  4148. end;
  4149. {$endif i386}
  4150. {$ifdef xtensa}
  4151. { xtensa-linux target does not support controller setting option -Wp }
  4152. if not(option.FPUSetExplicitly) and not(target_info.system = system_xtensa_linux) then
  4153. begin
  4154. init_settings.fputype:=embedded_controllers[init_settings.controllertype].fputype;
  4155. if (init_settings.fputype=fpu_soft) then
  4156. include(init_settings.moduleswitches,cs_fp_emulation);
  4157. end;
  4158. if not(option.CPUSetExplicitly) and (target_info.system=system_xtensa_linux) then
  4159. init_settings.cputype:=cpu_lx6;
  4160. if (target_info.system in [system_xtensa_embedded,system_xtensa_freertos]) and not(option.ABISetExplicitly) then
  4161. begin
  4162. if CPUXTENSA_REGWINDOW in cpu_capabilities[init_settings.cputype] then
  4163. target_info.abi:=abi_xtensa_windowed
  4164. else
  4165. target_info.abi:=abi_xtensa_call0;
  4166. end;
  4167. {$endif xtensa}
  4168. {$ifdef arm}
  4169. case target_info.system of
  4170. system_arm_ios:
  4171. begin
  4172. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  4173. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  4174. }
  4175. if not option.CPUSetExplicitly then
  4176. init_settings.cputype:=cpu_armv7;
  4177. if not option.OptCPUSetExplicitly then
  4178. init_settings.optimizecputype:=cpu_armv7;
  4179. if not option.FPUSetExplicitly then
  4180. init_settings.fputype:=fpu_vfpv3;
  4181. end;
  4182. system_arm_android:
  4183. begin
  4184. { set default cpu type to ARMv5T for Android unless specified otherwise }
  4185. if not option.CPUSetExplicitly then
  4186. init_settings.cputype:=cpu_armv5t;
  4187. if not option.OptCPUSetExplicitly then
  4188. init_settings.optimizecputype:=cpu_armv5t;
  4189. end;
  4190. else
  4191. ;
  4192. end;
  4193. { set ABI defaults }
  4194. case target_info.abi of
  4195. abi_eabihf:
  4196. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  4197. begin
  4198. {$ifdef CPUARMV6}
  4199. { if the compiler is built for armv6, then
  4200. inherit this setting, e.g. Raspian is armhf but
  4201. only armv6, this makes rebuilds of the compiler
  4202. easier }
  4203. if not option.CPUSetExplicitly then
  4204. init_settings.cputype:=cpu_armv6;
  4205. if not option.OptCPUSetExplicitly then
  4206. init_settings.optimizecputype:=cpu_armv6;
  4207. {$else CPUARMV6}
  4208. if not option.CPUSetExplicitly then
  4209. init_settings.cputype:=cpu_armv7a;
  4210. if not option.OptCPUSetExplicitly then
  4211. init_settings.optimizecputype:=cpu_armv7a;
  4212. {$endif CPUARMV6}
  4213. { Set FPU type }
  4214. if not(option.FPUSetExplicitly) then
  4215. begin
  4216. if init_settings.cputype < cpu_armv7 then
  4217. init_settings.fputype:=fpu_vfpv2
  4218. else
  4219. init_settings.fputype:=fpu_vfpv3_d16;
  4220. end
  4221. else
  4222. begin
  4223. if (not(FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[init_settings.fputype]))
  4224. or (target_info.system = system_arm_ios) then
  4225. begin
  4226. Message(option_illegal_fpu_eabihf);
  4227. StopOptions(1);
  4228. end;
  4229. end;
  4230. end;
  4231. abi_eabi:
  4232. begin
  4233. if target_info.system=system_arm_linux then
  4234. begin
  4235. { this is what Debian uses }
  4236. if not option.CPUSetExplicitly then
  4237. init_settings.cputype:=cpu_armv4t;
  4238. if not option.OptCPUSetExplicitly then
  4239. init_settings.optimizecputype:=cpu_armv4t;
  4240. if not(option.FPUSetExplicitly) then
  4241. init_settings.fputype:=fpu_soft;
  4242. end;
  4243. end;
  4244. else
  4245. ;
  4246. end;
  4247. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4248. begin
  4249. def_system_macro('CPUTHUMB');
  4250. if not option.FPUSetExplicitly then
  4251. init_settings.fputype:=fpu_soft;
  4252. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  4253. 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';
  4254. {$else FPC_ARMAL or FPC_ARMHF}
  4255. if target_info.endian=endian_little then
  4256. 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';
  4257. {$endif FPC_ARMAL or FPC_ARMHF}
  4258. end;
  4259. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4260. def_system_macro('CPUTHUMB2');
  4261. {$endif arm}
  4262. {$if defined(riscv32) or defined(riscv64)}
  4263. { RISC-V defaults }
  4264. if (target_info.abi = abi_riscv_hf) then
  4265. begin
  4266. {$ifdef riscv32}
  4267. if not option.CPUSetExplicitly then
  4268. init_settings.cputype:=cpu_rv32ima;
  4269. if not option.OptCPUSetExplicitly then
  4270. init_settings.optimizecputype:=cpu_rv32ima;
  4271. {$else}
  4272. if not option.CPUSetExplicitly then
  4273. init_settings.cputype:=cpu_rv64imac;
  4274. if not option.OptCPUSetExplicitly then
  4275. init_settings.optimizecputype:=cpu_rv64imac;
  4276. {$endif}
  4277. { Set FPU type }
  4278. if not(option.FPUSetExplicitly) then
  4279. init_settings.fputype:=fpu_fd
  4280. else
  4281. begin
  4282. if not (init_settings.fputype in [fpu_fd]) then
  4283. begin
  4284. Message(option_illegal_fpu_eabihf);
  4285. StopOptions(1);
  4286. end;
  4287. end;
  4288. end;
  4289. {$endif defined(riscv32) or defined(riscv64)}
  4290. {$ifdef jvm}
  4291. { set default CPU type to Dalvik when targeting Android }
  4292. if target_info.system=system_jvm_android32 then
  4293. begin
  4294. if not option.CPUSetExplicitly then
  4295. init_settings.cputype:=cpu_dalvik;
  4296. end;
  4297. {$endif jvm}
  4298. {$ifdef llvm}
  4299. { standard extension for llvm bitcode files }
  4300. target_info.asmext:='.ll';
  4301. { don't generate dwarf cfi, llvm will do that }
  4302. exclude(target_info.flags,tf_needs_dwarf_cfi);
  4303. {$endif llvm}
  4304. {$ifdef mipsel}
  4305. case target_info.system of
  4306. system_mipsel_android:
  4307. begin
  4308. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  4309. if not option.CPUSetExplicitly then
  4310. init_settings.cputype:=cpu_mips32;
  4311. if not option.OptCPUSetExplicitly then
  4312. init_settings.optimizecputype:=cpu_mips32;
  4313. if not option.FPUSetExplicitly then
  4314. init_settings.fputype:=fpu_mips2;
  4315. end;
  4316. system_mipsel_embedded:
  4317. begin
  4318. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  4319. if not option.CPUSetExplicitly then
  4320. init_settings.cputype:=cpu_pic32mx;
  4321. if not option.OptCPUSetExplicitly then
  4322. init_settings.optimizecputype:=cpu_pic32mx;
  4323. if not option.FPUSetExplicitly then
  4324. init_settings.fputype:=fpu_soft;
  4325. end;
  4326. else
  4327. ;
  4328. end;
  4329. {$endif mipsel}
  4330. {$ifdef m68k}
  4331. if init_settings.cputype in cpu_coldfire then
  4332. def_system_macro('CPUCOLDFIRE');
  4333. case target_info.system of
  4334. system_m68k_linux,
  4335. system_m68k_netbsd:
  4336. begin
  4337. if not (option.FPUSetExplicitly) and
  4338. not (init_settings.cputype in cpu_coldfire) then
  4339. begin
  4340. { enable HW FPU for UNIX by default, but only for
  4341. original 68k, not Coldfire }
  4342. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4343. init_settings.fputype:=fpu_68881;
  4344. end;
  4345. end;
  4346. system_m68k_sinclairql:
  4347. begin
  4348. if not option.CPUSetExplicitly then
  4349. init_settings.cputype:=cpu_mc68000;
  4350. end;
  4351. system_m68k_palmos:
  4352. begin
  4353. if not option.CPUSetExplicitly then
  4354. init_settings.cputype:=cpu_mc68000;
  4355. if not (option.FPUSetExplicitly) then
  4356. begin
  4357. { No FPU for PalmOS by default }
  4358. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4359. init_settings.fputype:=fpu_none;
  4360. end;
  4361. end;
  4362. else
  4363. ;
  4364. end;
  4365. {$endif m68k}
  4366. { now we can define cpu and fpu type }
  4367. def_cpu_macros;
  4368. { Use init_settings cpu type for asm cpu type,
  4369. if asmcputype is cpu_none,
  4370. at least as long as there is no explicit
  4371. option to set it on command line PM }
  4372. if init_settings.asmcputype = cpu_none then
  4373. init_settings.asmcputype:=init_settings.cputype;
  4374. {$ifdef llvm}
  4375. def_system_macro('CPULLVM');
  4376. {$endif llvm}
  4377. {$if defined(cpucapabilities)}
  4378. for cpuflag:=low(cpuflag) to high(cpuflag) do
  4379. begin
  4380. str(cpuflag,hs);
  4381. if cpuflag in cpu_capabilities[init_settings.cputype] then
  4382. def_system_macro(hs)
  4383. else
  4384. undef_system_macro(hs);
  4385. end;
  4386. {$endif defined(cpucapabilities)}
  4387. {$if defined(fpucapabilities)}
  4388. for fpuflag:=low(fpuflag) to high(fpuflag) do
  4389. begin
  4390. str(fpuflag,hs);
  4391. if fpuflag in fpu_capabilities[init_settings.fputype] then
  4392. def_system_macro(hs)
  4393. else
  4394. undef_system_macro(hs);
  4395. end;
  4396. {$endif defined(fpucapabilities)}
  4397. if init_settings.fputype<>fpu_none then
  4398. begin
  4399. {$if defined(i386) or defined(i8086)}
  4400. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4401. {$endif}
  4402. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4403. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4404. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  4405. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4406. {$endif}
  4407. {$if defined(m68k)}
  4408. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  4409. {$endif}
  4410. {$ifdef x86_64}
  4411. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4412. { normally, win64 doesn't support the legacy fpu }
  4413. if target_info.system=system_x86_64_win64 then
  4414. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  4415. else
  4416. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4417. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4418. {$endif}
  4419. end;
  4420. { Enable now for testing }
  4421. {$ifndef DISABLE_TLS_DIRECTORY}
  4422. if target_info.system in systems_windows then
  4423. def_system_macro('FPC_USE_TLS_DIRECTORY');
  4424. {$endif not DISABLE_TLS_DIRECTORY}
  4425. {$ifndef DISABLE_WIN64_SEH}
  4426. if target_info.system=system_x86_64_win64 then
  4427. def_system_macro('FPC_USE_WIN64_SEH');
  4428. {$endif DISABLE_WIN64_SEH}
  4429. {$ifndef DISABLE_WIN32_SEH}
  4430. if target_info.system=system_i386_win32 then
  4431. def_system_macro('FPC_USE_WIN32_SEH');
  4432. {$endif not DISABLE_WIN32_SEH}
  4433. {$ifdef ARM}
  4434. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  4435. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  4436. not(cs_fp_emulation in init_settings.moduleswitches) then
  4437. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  4438. {$endif ARM}
  4439. { inline bsf/bsr implementation }
  4440. {$if defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64)}
  4441. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4442. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4443. {$endif}
  4444. { hardware FMA support }
  4445. {$if defined(i386) or defined(x86_64)}
  4446. if (cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[] then
  4447. begin
  4448. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  4449. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  4450. end;
  4451. {$endif defined(i386) or defined(x86_64)}
  4452. {$if defined(arm)}
  4453. { it is determined during system unit compilation if clz is used for bsf or not,
  4454. this is not perfect but the current implementation bsf/bsr does not allow another
  4455. solution }
  4456. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  4457. ((init_settings.instructionset=is_arm) or
  4458. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  4459. begin
  4460. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4461. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  4462. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4463. end;
  4464. {$endif}
  4465. {$if defined(xtensa)}
  4466. { it is determined during system unit compilation if nsau is used for bsr or not,
  4467. this is not perfect but the current implementation bsf/bsr does not allow another
  4468. solution }
  4469. if CPUXTENSA_HAS_NSAx in cpu_capabilities[init_settings.cputype] then
  4470. begin
  4471. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4472. end;
  4473. {$endif}
  4474. {$if defined(powerpc64)}
  4475. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  4476. big endian (unless specified otherwise). As the gcc man page says:
  4477. "Overriding the default ABI requires special system support and is
  4478. likely to fail in spectacular ways" }
  4479. if not option.ABISetExplicitly then
  4480. begin
  4481. if (target_info.abi=abi_powerpc_sysv) and
  4482. (target_info.endian=endian_little) then
  4483. target_info.abi:=abi_powerpc_elfv2
  4484. else
  4485. if (target_info.abi=abi_powerpc_elfv2) and
  4486. (target_info.endian=endian_big) then
  4487. target_info.abi:=abi_powerpc_sysv
  4488. end;
  4489. {$endif}
  4490. {$if defined(powerpc) or defined(powerpc64)}
  4491. { define _CALL_ELF symbol like gcc }
  4492. case target_info.abi of
  4493. abi_powerpc_sysv:
  4494. set_system_compvar('_CALL_ELF','1');
  4495. abi_powerpc_elfv2:
  4496. set_system_compvar('_CALL_ELF','2');
  4497. else
  4498. ;
  4499. end;
  4500. {$endif}
  4501. { Section smartlinking conflicts with import sections on Windows }
  4502. if GenerateImportSection and
  4503. (target_info.system in [system_i386_win32,system_x86_64_win64,system_aarch64_win64]) then
  4504. exclude(target_info.flags,tf_smartlink_sections);
  4505. if not option.LinkTypeSetExplicitly then
  4506. set_default_link_type;
  4507. { Default alignment settings,
  4508. 1. load the defaults for the target
  4509. 2. override with generic optimizer setting (little size)
  4510. 3. override with the user specified -Oa }
  4511. UpdateAlignment(init_settings.alignment,target_info.alignment);
  4512. if (cs_opt_size in init_settings.optimizerswitches) then
  4513. begin
  4514. init_settings.alignment.procalign:=1;
  4515. init_settings.alignment.jumpalign:=1;
  4516. init_settings.alignment.coalescealign:=1;
  4517. init_settings.alignment.loopalign:=1;
  4518. {$ifdef x86}
  4519. { constalignmax=1 keeps the executable and thus the memory foot print small but
  4520. all processors except x86 are really hurt by this or might even crash }
  4521. init_settings.alignment.constalignmax:=1;
  4522. {$endif x86}
  4523. end;
  4524. UpdateAlignment(init_settings.alignment,option.paraalignment);
  4525. set_system_macro('FPC_VERSION',version_nr);
  4526. set_system_macro('FPC_RELEASE',release_nr);
  4527. set_system_macro('FPC_PATCH',patch_nr);
  4528. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  4529. if target_info.system in systems_indirect_entry_information then
  4530. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  4531. if not (tf_winlikewidestring in target_info.flags) then
  4532. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  4533. if tf_supports_packages in target_info.flags then
  4534. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  4535. if target_info.system in systems_indirect_var_imports then
  4536. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  4537. if cs_compilesystem in init_settings.moduleswitches then
  4538. for i:=low(tfeature) to high(tfeature) do
  4539. if i in features then
  4540. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  4541. {$push}
  4542. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  4543. if ControllerSupport and (target_info.system in (systems_embedded+systems_freertos)) and
  4544. (init_settings.controllertype<>ct_none) then
  4545. begin
  4546. with embedded_controllers[init_settings.controllertype] do
  4547. begin
  4548. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  4549. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  4550. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  4551. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  4552. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  4553. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  4554. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  4555. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  4556. end;
  4557. end;
  4558. {$pop}
  4559. { as stackalign is not part of the alignment record, we do not need to define the others alignments for symmetry yet }
  4560. set_system_macro('FPC_STACKALIGNMENT',tostr(target_info.stackalign));
  4561. option.free;
  4562. Option:=nil;
  4563. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl{$ifdef z80},pocall_stdcall{$endif}];
  4564. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  4565. if (tf_safecall_clearstack in target_info.flags) then
  4566. begin
  4567. include (cdecl_pocalls, pocall_safecall);
  4568. include (clearstack_pocalls, pocall_safecall)
  4569. end;
  4570. end;
  4571. initialization
  4572. coption:=toption;
  4573. finalization
  4574. if assigned(option) then
  4575. option.free;
  4576. end.