options.pas 181 KB

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