options.pas 184 KB

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