options.pas 181 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023
  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. system_mos6502_oric:
  2092. target_unsup_features:=[f_threading,f_dynlibs{,f_fileio,f_textio},f_commandargs,f_exitcode];
  2093. else
  2094. target_unsup_features:=[];
  2095. end;
  2096. if def then
  2097. features:=features-target_unsup_features
  2098. else
  2099. features:=features+target_unsup_features;
  2100. {$if defined(hasamiga)}
  2101. { enable vlink as default linker on Amiga but not for cross compilers (for now) }
  2102. if (target_info.system in [system_m68k_amiga,system_powerpc_amiga]) and
  2103. not LinkerSetExplicitly then
  2104. include(init_settings.globalswitches,cs_link_vlink);
  2105. {$endif}
  2106. {$ifdef m68k}
  2107. { always enable vlink as default linker for the Sinclair QL, Atari, and Human 68k }
  2108. if (target_info.system in [system_m68k_sinclairql,system_m68k_atari,system_m68k_human68k]) and
  2109. not LinkerSetExplicitly then
  2110. include(init_settings.globalswitches,cs_link_vlink);
  2111. {$endif m68k}
  2112. end;
  2113. procedure TOption.CheckOptionsCompatibility;
  2114. begin
  2115. {$ifdef wasm}
  2116. if (Ord(ts_wasm_no_exceptions in init_settings.targetswitches)+
  2117. Ord(ts_wasm_native_exnref_exceptions in init_settings.targetswitches)+
  2118. Ord(ts_wasm_native_legacy_exceptions in init_settings.targetswitches)+
  2119. Ord(ts_wasm_bf_exceptions in init_settings.targetswitches))>1 then
  2120. begin
  2121. Message(option_too_many_exception_modes);
  2122. StopOptions(1);
  2123. end;
  2124. {$endif}
  2125. {$ifdef i8086}
  2126. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  2127. begin
  2128. Message(option_com_files_require_tiny_model);
  2129. StopOptions(1);
  2130. end;
  2131. if (target_info.system = system_i8086_win16) and
  2132. not (init_settings.x86memorymodel in [mm_large,mm_huge]) then
  2133. begin
  2134. if MemoryModelSetExplicitly then
  2135. Message1(option_e_win16_unsupported_memory_model,x86memorymodelstr[init_settings.x86memorymodel])
  2136. else
  2137. Message(option_n_win16_set_default_large_memory_model);
  2138. undef_system_macro('FPC_MM_'+x86memorymodelstr[init_settings.x86memorymodel]);
  2139. init_settings.x86memorymodel:=mm_large;
  2140. end;
  2141. {$endif i8086}
  2142. {$ifndef i8086_link_intern_debuginfo}
  2143. if (cs_debuginfo in init_settings.moduleswitches) and
  2144. (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) and
  2145. not (cs_link_extern in init_settings.globalswitches) then
  2146. begin
  2147. Message(option_debug_info_requires_external_linker);
  2148. include(init_settings.globalswitches,cs_link_extern);
  2149. end;
  2150. {$endif i8086_link_intern_debuginfo}
  2151. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3,dbg_dwarf4]) and
  2152. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  2153. begin
  2154. { smartlink creation does not yet work with DWARF
  2155. debug info on most targets, but it works in internal assembler }
  2156. if (cs_create_smart in init_settings.moduleswitches) and
  2157. not (af_outputbinary in target_asm.flags) then
  2158. begin
  2159. Message(option_dwarf_smartlink_creation);
  2160. exclude(init_settings.moduleswitches,cs_create_smart);
  2161. end;
  2162. { smart linking does not yet work with DWARF debug info on most targets }
  2163. if (cs_link_smart in init_settings.globalswitches) then
  2164. begin
  2165. Message(option_dwarf_smart_linking);
  2166. ForceStaticLinking;
  2167. end;
  2168. end;
  2169. { external debug info is only supported for DWARF on darwin }
  2170. if (target_info.system in systems_darwin) and
  2171. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  2172. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3,dbg_dwarf4]) then
  2173. begin
  2174. Message(option_debug_external_unsupported);
  2175. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  2176. end;
  2177. { Also create a smartlinked version, on an assembler that
  2178. does not support smartlink sections like nasm?
  2179. This is not compatible with using internal linker. }
  2180. if ((cs_link_smart in init_settings.globalswitches) or
  2181. (cs_create_smart in init_settings.moduleswitches)) and
  2182. (af_needar in target_asm.flags) and
  2183. not (af_smartlink_sections in target_asm.flags) and
  2184. not (cs_link_extern in init_settings.globalswitches) and
  2185. (target_info.link<>ld_none) and
  2186. not (cs_link_nolink in init_settings.globalswitches) then
  2187. begin
  2188. Message(option_smart_link_requires_external_linker);
  2189. include(init_settings.globalswitches,cs_link_extern);
  2190. end;
  2191. end;
  2192. constructor TOption.Create;
  2193. begin
  2194. LogoWritten:=false;
  2195. NoPressEnter:=false;
  2196. FirstPass:=false;
  2197. ABISetExplicitly:=false;
  2198. FPUSetExplicitly:=false;
  2199. CPUSetExplicitly:=false;
  2200. OptCPUSetExplicitly:=false;
  2201. FileLevel:=0;
  2202. Quickinfo:='';
  2203. ParaIncludeCfgPath:=TSearchPathList.Create;
  2204. ParaIncludePath:=TSearchPathList.Create;
  2205. ParaObjectPath:=TSearchPathList.Create;
  2206. ParaUnitPath:=TSearchPathList.Create;
  2207. ParaLibraryPath:=TSearchPathList.Create;
  2208. ParaFrameworkPath:=TSearchPathList.Create;
  2209. parapackagepath:=TSearchPathList.Create;
  2210. parapackages:=TFPHashObjectList.Create;
  2211. paranamespaces:=TCmdStrList.Create;
  2212. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2213. MacVersionSet:=false;
  2214. paratarget:=system_none;
  2215. paratargetasm:=as_none;
  2216. paratargetdbg:=dbg_none;
  2217. LinkTypeSetExplicitly:=false;
  2218. LinkerSetExplicitly:=false;
  2219. MemoryModelSetExplicitly:=false;
  2220. end;
  2221. destructor TOption.Destroy;
  2222. begin
  2223. ParaIncludeCfgPath.Free;
  2224. ParaIncludePath.Free;
  2225. ParaObjectPath.Free;
  2226. ParaUnitPath.Free;
  2227. ParaLibraryPath.Free;
  2228. ParaFrameworkPath.Free;
  2229. parapackagepath.Free;
  2230. ParaPackages.Free;
  2231. paranamespaces.free;
  2232. end;
  2233. procedure TOption.Interpret_A_l(opt, more: TCmdStr);
  2234. var
  2235. j : integer;
  2236. begin
  2237. include(init_settings.globalswitches,cs_asm_leave);
  2238. j:=1;
  2239. while j<=length(more) do
  2240. begin
  2241. case more[j] of
  2242. '5' :
  2243. if (target_info.system in systems_all_windows+systems_nativent-[system_i8086_win16])
  2244. or (target_info.cpu in [cpu_mipseb, cpu_mipsel]) then
  2245. begin
  2246. if UnsetBool(More, j, opt, false) then
  2247. exclude(init_settings.globalswitches,cs_asm_pre_binutils_2_25)
  2248. else
  2249. include(init_settings.globalswitches,cs_asm_pre_binutils_2_25);
  2250. end
  2251. else
  2252. IllegalPara(opt);
  2253. 'l' :
  2254. include(init_settings.globalswitches,cs_asm_source);
  2255. 'r' :
  2256. include(init_settings.globalswitches,cs_asm_regalloc);
  2257. 'R' :
  2258. include(init_settings.globalswitches,cs_asm_rtti_source);
  2259. 't' :
  2260. include(init_settings.globalswitches,cs_asm_tempalloc);
  2261. 'n' :
  2262. include(init_settings.globalswitches,cs_asm_nodes);
  2263. { -ao option must be the last, everything behind it is passed directly to
  2264. external assembler, it is ignored if internal assembler is used. }
  2265. 'o' :
  2266. begin
  2267. asmextraopt:=copy(more,j+1);
  2268. break;
  2269. end;
  2270. 'p' :
  2271. begin
  2272. exclude(init_settings.globalswitches,cs_asm_leave);
  2273. if UnsetBool(More, 0, opt, false) then
  2274. exclude(init_settings.globalswitches,cs_asm_pipe)
  2275. else
  2276. include(init_settings.globalswitches,cs_asm_pipe);
  2277. end;
  2278. '-' :
  2279. init_settings.globalswitches:=init_settings.globalswitches -
  2280. [cs_asm_leave, cs_asm_source,cs_asm_regalloc, cs_asm_tempalloc,
  2281. cs_asm_nodes, cs_asm_pipe];
  2282. else
  2283. IllegalPara(opt);
  2284. end;
  2285. inc(j);
  2286. end;
  2287. end;
  2288. procedure TOption.Interpret_A_U(opt, more: TCmdStr);
  2289. begin
  2290. if CompareText(More,'DEFAULT') = 0 then
  2291. paratargetasm:=as_default
  2292. else
  2293. paratargetasm:=find_asm_by_string(More);
  2294. if paratargetasm=as_none then
  2295. IllegalPara(opt);
  2296. end;
  2297. procedure TOption.Interpret_B_l(opt, more: TCmdStr);
  2298. begin
  2299. // Message1(option_obsolete_switch,'-b');
  2300. if UnsetBool(More,0,opt,false) then
  2301. begin
  2302. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_browser];
  2303. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser];
  2304. end
  2305. else
  2306. begin
  2307. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_browser];
  2308. end;
  2309. if More<>'' then
  2310. if (More='l') or (More='l+') then
  2311. init_settings.moduleswitches:=init_settings.moduleswitches+[cs_local_browser]
  2312. else if More='l-' then
  2313. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_local_browser]
  2314. else
  2315. IllegalPara(opt);
  2316. end;
  2317. procedure TOption.Interpret_B_U(opt, more: TCmdStr);
  2318. begin
  2319. do_build:=not UnSetBool(more,0,opt,true);
  2320. end;
  2321. procedure TOption.Interpret_C_U(opt, more: TCmdStr);
  2322. var
  2323. j,l,code,deletepos : integer;
  2324. s : string;
  2325. includecapability : Boolean;
  2326. {$ifdef llvm}
  2327. disable: boolean;
  2328. {$endif}
  2329. {$ifdef cpucapabilities}
  2330. cf : tcpuflags;
  2331. cpuflagsstr,
  2332. extrasettings : string;
  2333. {$endif cpucapabilities}
  2334. begin
  2335. j:=1;
  2336. while j<=length(more) do
  2337. begin
  2338. case more[j] of
  2339. '3' :
  2340. If UnsetBool(More, j, opt, false) then
  2341. exclude(init_settings.localswitches,cs_ieee_errors)
  2342. Else
  2343. include(init_settings.localswitches,cs_ieee_errors);
  2344. 'a' :
  2345. begin
  2346. s:=upper(copy(more,j+1));
  2347. if not(SetAbiType(s,target_info.abi)) then
  2348. IllegalPara(opt);
  2349. ABISetExplicitly:=true;
  2350. break;
  2351. end;
  2352. 'b' :
  2353. begin
  2354. if UnsetBool(More, j, opt, false) then
  2355. target_info.endian:=endian_little
  2356. else
  2357. target_info.endian:=endian_big;
  2358. set_endianess_macros;
  2359. end;
  2360. 'c' :
  2361. begin
  2362. if not SetAktProcCall(upper(copy(more,j+1)),init_settings.defproccall) then
  2363. IllegalPara(opt);
  2364. break;
  2365. end;
  2366. {$ifdef AVR}
  2367. 'd' :
  2368. begin
  2369. if not ParseLinkerDiscardOptions(more) then
  2370. IllegalPara(opt);
  2371. break;
  2372. end;
  2373. {$endif AVR}
  2374. {$ifdef cpufpemu}
  2375. 'e' :
  2376. begin
  2377. If UnsetBool(More, j, opt, false) then
  2378. exclude(init_settings.moduleswitches,cs_fp_emulation)
  2379. Else
  2380. include(init_settings.moduleswitches,cs_fp_emulation);
  2381. end;
  2382. {$endif cpufpemu}
  2383. 'E' :
  2384. If UnsetBool(More, j, opt, false) then
  2385. exclude(init_settings.localswitches,cs_check_fpu_exceptions)
  2386. Else
  2387. include(init_settings.localswitches,cs_check_fpu_exceptions);
  2388. 'f' :
  2389. begin
  2390. s:=upper(copy(more,j+1));
  2391. if not(SetFpuType(s,init_settings.fputype)) then
  2392. IllegalPara(opt);
  2393. FPUSetExplicitly:=True;
  2394. break;
  2395. end;
  2396. 'F' :
  2397. begin
  2398. if not SetMinFPConstPrec(copy(more,j+1),init_settings.minfpconstprec) then
  2399. IllegalPara(opt);
  2400. break;
  2401. end;
  2402. 'g' :
  2403. begin
  2404. if tf_no_pic_supported in target_info.flags then
  2405. begin
  2406. { consume a possible '-' coming after it }
  2407. UnsetBool(More, j, opt, false);
  2408. message(scan_w_pic_ignored);
  2409. end
  2410. else if UnsetBool(More, j, opt, false) then
  2411. exclude(init_settings.moduleswitches,cs_create_pic)
  2412. else
  2413. include(init_settings.moduleswitches,cs_create_pic);
  2414. end;
  2415. 'h' :
  2416. begin
  2417. l:=pos(',',copy(more,j+1));
  2418. if l=0 then
  2419. l:=length(more)-j+1;
  2420. val(copy(more,j+1,l-1),heapsize,code);
  2421. if (code<>0)
  2422. {$ifdef AVR}
  2423. or (heapsize<32)
  2424. {$else AVR}
  2425. or (heapsize<1024)
  2426. {$endif AVR}
  2427. then
  2428. IllegalPara(opt)
  2429. else if l<=length(more)-j then
  2430. begin
  2431. val(copy(more,j+l+1),maxheapsize,code);
  2432. if code<>0 then
  2433. IllegalPara(opt)
  2434. else if (maxheapsize<heapsize) then
  2435. begin
  2436. message(scan_w_heapmax_lessthan_heapmin);
  2437. maxheapsize:=heapsize;
  2438. end;
  2439. end;
  2440. break;
  2441. end;
  2442. 'i' :
  2443. If UnsetBool(More, j, opt, false) then
  2444. exclude(init_settings.localswitches,cs_check_io)
  2445. else
  2446. include(init_settings.localswitches,cs_check_io);
  2447. {$ifdef arm}
  2448. 'I' :
  2449. begin
  2450. if (upper(copy(more,j+1))='THUMB') and
  2451. { does selected CPU really understand thumb? }
  2452. (init_settings.cputype in cpu_has_thumb) then
  2453. init_settings.instructionset:=is_thumb
  2454. else if upper(copy(more,j+1))='ARM' then
  2455. init_settings.instructionset:=is_arm
  2456. else
  2457. IllegalPara(opt);
  2458. break;
  2459. end;
  2460. {$endif arm}
  2461. {$ifdef llvm}
  2462. 'l':
  2463. begin
  2464. l:=j+1;
  2465. while l<=length(More) do
  2466. begin
  2467. case More[l] of
  2468. 'f':
  2469. begin
  2470. delete(More,1,l);
  2471. disable:=Unsetbool(More,length(More)-1,opt,false);
  2472. case More of
  2473. 'lto':
  2474. begin
  2475. if not disable then
  2476. begin
  2477. include(init_settings.moduleswitches,cs_lto);
  2478. LTOExt:='.bc';
  2479. end
  2480. else
  2481. exclude(init_settings.moduleswitches,cs_lto);
  2482. end;
  2483. 'ltonosystem':
  2484. begin
  2485. if not disable then
  2486. begin
  2487. include(init_settings.globalswitches,cs_lto_nosystem);
  2488. end
  2489. else
  2490. exclude(init_settings.globalswitches,cs_lto_nosystem);
  2491. end;
  2492. else if More.StartsWith('sanitize=') then
  2493. begin
  2494. delete(More,1,length('sanitize='));
  2495. LLVMEnableSanitizers(more);
  2496. end
  2497. else
  2498. begin
  2499. IllegalPara(opt);
  2500. end;
  2501. end;
  2502. l:=length(more)+1;
  2503. end;
  2504. 'v':
  2505. begin
  2506. init_settings.llvmversion:=llvmversion2enum(copy(More,l+1));
  2507. if init_settings.llvmversion=llvmver_invalid then
  2508. begin
  2509. IllegalPara(opt);
  2510. end;
  2511. l:=length(More)+1;
  2512. end
  2513. else
  2514. begin
  2515. IllegalPara(opt);
  2516. end;
  2517. end;
  2518. end;
  2519. j:=l;
  2520. end;
  2521. {$endif llvm}
  2522. 'n' :
  2523. If UnsetBool(More, j, opt, false) then
  2524. exclude(init_settings.globalswitches,cs_link_nolink)
  2525. Else
  2526. include(init_settings.globalswitches,cs_link_nolink);
  2527. 'N' :
  2528. If UnsetBool(More, j, opt, false) then
  2529. exclude(init_settings.localswitches,cs_check_low_addr_load)
  2530. Else
  2531. include(init_settings.localswitches,cs_check_low_addr_load);
  2532. 'o' :
  2533. If UnsetBool(More, j, opt, false) then
  2534. exclude(init_settings.localswitches,cs_check_overflow)
  2535. Else
  2536. include(init_settings.localswitches,cs_check_overflow);
  2537. 'O' :
  2538. If UnsetBool(More, j, opt, false) then
  2539. exclude(init_settings.localswitches,cs_check_ordinal_size)
  2540. Else
  2541. include(init_settings.localswitches,cs_check_ordinal_size);
  2542. 'p' :
  2543. begin
  2544. s:=upper(copy(more,j+1));
  2545. {$ifdef cpucapabilities}
  2546. { find first occurrence of + or - }
  2547. {$ifdef x86_64}
  2548. { Workaround - don't remove the "-" signs from ICELAKE-CLIENT,
  2549. ICELAKE-SERVER, SKYLAKE-X, X86-64 and X86-64-V1 etc. }
  2550. if (Copy(s,1,8)='ICELAKE-') and
  2551. (
  2552. (Copy(s,9,6)='CLIENT') or
  2553. (Copy(s,9,6)='SERVER')
  2554. ) then
  2555. begin
  2556. extrasettings:=Copy(s,15,Length(s));
  2557. deletepos:=PosCharset(['+','-'],extrasettings);
  2558. end
  2559. else if (Copy(s,1,9)='SKYLAKE-X') or
  2560. ((Copy(s,1,8)='X86-64-V') and (s[9] in ['1','2','3','4'])) then
  2561. begin
  2562. extrasettings:=Copy(s,10,Length(s));
  2563. deletepos:=PosCharset(['+','-'],extrasettings);
  2564. end
  2565. else if (Copy(s,1,6)='X86-64') then
  2566. begin
  2567. extrasettings:=Copy(s,7,Length(s));
  2568. deletepos:=PosCharset(['+','-'],extrasettings);
  2569. end
  2570. else
  2571. {$endif x86_64}
  2572. deletepos:=PosCharset(['+','-'],s);
  2573. if deletepos<>0 then
  2574. begin
  2575. extrasettings:=Copy(s,deletepos,Length(s));
  2576. Delete(s,deletepos,Length(s));
  2577. end
  2578. else
  2579. extrasettings:='';
  2580. {$endif cpucapabilities}
  2581. if not(Setcputype(s,init_settings)) then
  2582. IllegalPara(opt);
  2583. {$ifdef cpucapabilities}
  2584. while extrasettings<>'' do
  2585. begin
  2586. Delete(extrasettings,1,1);
  2587. includecapability:=true;
  2588. deletepos:=PosCharset(['+','-'],extrasettings);
  2589. if deletepos<>0 then
  2590. begin
  2591. includecapability:=extrasettings[deletepos]='+';
  2592. s:=Copy(extrasettings,1,deletepos-1);
  2593. Delete(extrasettings,1,deletepos-1);
  2594. end
  2595. else
  2596. begin
  2597. s:=extrasettings;
  2598. extrasettings:='';
  2599. end;
  2600. for cf in tcpuflags do
  2601. begin
  2602. Str(cf,cpuflagsstr);
  2603. { expect that the cpuflagsstr i.e. the enum as well contains _HAS_ }
  2604. if Pos('_HAS_',cpuflagsstr)<>0 then
  2605. { get rid of prefix including _HAS_ }
  2606. Delete(cpuflagsstr,1,Pos('_HAS_',cpuflagsstr)+4)
  2607. else
  2608. Internalerror(2021110601);
  2609. if s=cpuflagsstr then
  2610. begin
  2611. if includecapability then
  2612. Include(cpu_capabilities[init_settings.cputype],cf)
  2613. else
  2614. Exclude(cpu_capabilities[init_settings.cputype],cf);
  2615. s:='';
  2616. break;
  2617. end;
  2618. end;
  2619. if s<>'' then
  2620. IllegalPara(opt);
  2621. end;
  2622. {$endif cpucapabilities}
  2623. CPUSetExplicitly:=true;
  2624. break;
  2625. end;
  2626. 'P':
  2627. begin
  2628. delete(more,1,1);
  2629. case upper(copy(more,1,pos('=',more)-1)) of
  2630. 'PACKSET':
  2631. begin
  2632. delete(more,1,pos('=',more));
  2633. case more of
  2634. '0','DEFAULT','NORMAL':
  2635. init_settings.setalloc:=0;
  2636. '1','2','4','8':
  2637. init_settings.setalloc:=StrToInt(more);
  2638. else
  2639. IllegalPara(opt);
  2640. end
  2641. end;
  2642. 'PACKENUM':
  2643. begin
  2644. delete(more,1,pos('=',more));
  2645. case more of
  2646. '0','DEFAULT','NORMAL':
  2647. init_settings.packenum:=4;
  2648. '1','2','4':
  2649. init_settings.packenum:=StrToInt(more);
  2650. else
  2651. IllegalPara(opt);
  2652. end;
  2653. end;
  2654. 'PACKRECORD':
  2655. begin
  2656. delete(more,1,pos('=',more));
  2657. case more of
  2658. '0','DEFAULT','NORMAL':
  2659. init_settings.packrecords:=default_settings.packrecords;
  2660. '1','2','4','8','16','32':
  2661. init_settings.packrecords:=StrToInt(more);
  2662. else
  2663. IllegalPara(opt);
  2664. end;
  2665. end
  2666. else
  2667. IllegalPara(opt);
  2668. end;
  2669. end;
  2670. 'r' :
  2671. If UnsetBool(More, j, opt, false) then
  2672. exclude(init_settings.localswitches,cs_check_range)
  2673. Else
  2674. include(init_settings.localswitches,cs_check_range);
  2675. 'R' :
  2676. If UnsetBool(More, j, opt, false) then
  2677. begin
  2678. exclude(init_settings.localswitches,cs_check_range);
  2679. exclude(init_settings.localswitches,cs_check_object);
  2680. end
  2681. Else
  2682. begin
  2683. include(init_settings.localswitches,cs_check_range);
  2684. include(init_settings.localswitches,cs_check_object);
  2685. end;
  2686. 's' :
  2687. begin
  2688. val(copy(more,j+1),stacksize,code);
  2689. if (code<>0)
  2690. {$ifdef cpu16bitaddr}
  2691. or (stacksize>=65521)
  2692. {$else cpu16bitaddr}
  2693. or (stacksize>=67107840)
  2694. {$endif cpu16bitaddr}
  2695. or (stacksize<1024) then
  2696. IllegalPara(opt);
  2697. break;
  2698. end;
  2699. 't' :
  2700. If UnsetBool(More, j, opt, false) then
  2701. exclude(init_settings.localswitches,cs_check_stack)
  2702. Else
  2703. include(init_settings.localswitches,cs_check_stack);
  2704. 'D' :
  2705. If UnsetBool(More, j, opt, false) then
  2706. exclude(init_settings.moduleswitches,cs_create_dynamic)
  2707. Else
  2708. include(init_settings.moduleswitches,cs_create_dynamic);
  2709. 'X' :
  2710. If UnsetBool(More, j, opt, false) then
  2711. exclude(init_settings.moduleswitches,cs_create_smart)
  2712. Else
  2713. include(init_settings.moduleswitches,cs_create_smart);
  2714. 'T' :
  2715. begin
  2716. if not UpdateTargetSwitchStr(copy(more,j+1),init_settings.targetswitches,true) then
  2717. IllegalPara(opt);
  2718. break;
  2719. end;
  2720. 'v' :
  2721. If target_info.system in systems_jvm then
  2722. If UnsetBool(More, j, opt, false) then
  2723. exclude(init_settings.localswitches,cs_check_var_copyout)
  2724. Else
  2725. include(init_settings.localswitches,cs_check_var_copyout)
  2726. else
  2727. IllegalPara(opt);
  2728. 'V':
  2729. begin
  2730. s:=upper(copy(more,j+1));
  2731. if s='GLOBAL-DYNAMIC' then
  2732. init_settings.tlsmodel:=tlsm_global_dynamic
  2733. else if s='LOCAL-EXEC' then
  2734. init_settings.tlsmodel:=tlsm_local_exec
  2735. else
  2736. IllegalPara(opt);
  2737. break;
  2738. end;
  2739. else
  2740. IllegalPara(opt);
  2741. end;
  2742. inc(j);
  2743. end;
  2744. end;
  2745. procedure TOption.Interpret_D_l(opt, more: TCmdStr);
  2746. Var
  2747. l : Integer;
  2748. hs : string;
  2749. begin
  2750. l:=Pos(':=',more);
  2751. DefaultReplacements(more);
  2752. if l>0 then
  2753. hs:=copy(more,1,l-1)
  2754. else
  2755. hs:=more;
  2756. if (not is_identifier(hs)) then
  2757. begin
  2758. if hs='' then
  2759. Message1(option_missing_arg,'-d')
  2760. else
  2761. Message1(option_malformed_para,opt);
  2762. StopOptions(1);
  2763. end;
  2764. if l>0 then
  2765. begin
  2766. if cs_support_macro in init_settings.moduleswitches then
  2767. set_system_macro(hs,Copy(more,l+2))
  2768. else
  2769. set_system_compvar(hs,Copy(more,l+2));
  2770. end
  2771. else
  2772. def_system_macro(hs);
  2773. end;
  2774. procedure TOption.Interpret_D_U(opt, more: TCmdStr);
  2775. var
  2776. major,minor : longint;
  2777. l,j,error : integer;
  2778. begin
  2779. j:=1;
  2780. if length(more)=0 then
  2781. include(init_settings.globalswitches,cs_link_deffile);
  2782. while j<=length(more) do
  2783. begin
  2784. case more[j] of
  2785. 'd' :
  2786. begin
  2787. include(init_settings.globalswitches,cs_link_deffile);
  2788. description:=Copy(more,j+1);
  2789. break;
  2790. end;
  2791. 'D' :
  2792. begin
  2793. datestr:=Copy(more,j+1);
  2794. break;
  2795. end;
  2796. 'T' :
  2797. begin
  2798. timestr:=Copy(more,j+1);
  2799. break;
  2800. end;
  2801. 'v' :
  2802. begin
  2803. include(init_settings.globalswitches,cs_link_deffile);
  2804. dllversion:=Copy(more,j+1);
  2805. l:=pos('.',dllversion);
  2806. dllminor:=0;
  2807. error:=0;
  2808. if l>0 then
  2809. begin
  2810. val(copy(dllversion,l+1,255),minor,error);
  2811. if (error=0) and
  2812. (minor>=0) and (minor<=$ffff) then
  2813. dllminor:=minor
  2814. else
  2815. if error=0 then
  2816. error:=1;
  2817. end;
  2818. if l=0 then
  2819. l:=256;
  2820. dllmajor:=1;
  2821. major:=0;
  2822. if error=0 then
  2823. val(copy(dllversion,1,l-1),major,error);
  2824. if (error=0) and (major>=0) and (major<=$ffff) then
  2825. dllmajor:=major
  2826. else
  2827. if error=0 then
  2828. error:=1;
  2829. if error<>0 then
  2830. Message1(scan_w_wrong_version_ignored,dllversion);
  2831. break;
  2832. end;
  2833. 'w' :
  2834. begin
  2835. include(init_settings.globalswitches,cs_link_deffile);
  2836. usewindowapi:=true;
  2837. end;
  2838. '-' :
  2839. begin
  2840. exclude(init_settings.globalswitches,cs_link_deffile);
  2841. usewindowapi:=false;
  2842. end;
  2843. else
  2844. IllegalPara(opt);
  2845. end;
  2846. inc(j);
  2847. end;
  2848. end;
  2849. procedure TOption.Interpret_E_l(opt, more: TCmdStr);
  2850. begin
  2851. exepath:=FixPath(More,true);
  2852. end;
  2853. procedure TOption.Interpret_E_U(opt, more: TCmdStr);
  2854. begin
  2855. if UnsetBool(More, 0, opt, true) then
  2856. exclude(init_settings.globalswitches,cs_link_nolink)
  2857. else
  2858. include(init_settings.globalswitches,cs_link_nolink);
  2859. end;
  2860. procedure TOption.Interpret_F_l(opt, more: TCmdStr);
  2861. begin
  2862. if more='PIC' then
  2863. begin
  2864. if tf_no_pic_supported in target_info.flags then
  2865. message(scan_w_pic_ignored)
  2866. else
  2867. include(init_settings.moduleswitches,cs_create_pic)
  2868. end
  2869. else
  2870. IllegalPara(opt);
  2871. end;
  2872. procedure TOption.Interpret_F_U(opt, more: TCmdStr; ispara: boolean);
  2873. var
  2874. c : char;
  2875. d : string;
  2876. j : integer;
  2877. unicodemapping : punicodemap;
  2878. begin
  2879. if more='' then
  2880. IllegalPara(opt);
  2881. c:=more[1];
  2882. Delete(more,1,1);
  2883. DefaultReplacements(More);
  2884. case c of
  2885. 'a' :
  2886. autoloadunits:=more;
  2887. 'c' :
  2888. begin
  2889. { if we first specify that the system code page should be
  2890. used and then explicitly specify a code page, unset the
  2891. flag that we're using the system code page again }
  2892. SetCompileModeSwitch('SYSTEMCODEPAGE-',true);
  2893. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  2894. init_settings.sourcecodepage:=CP_UTF8
  2895. else if not(cpavailable(more)) then
  2896. Message1(option_code_page_not_available,more)
  2897. else
  2898. init_settings.sourcecodepage:=codepagebyname(more);
  2899. include(init_settings.moduleswitches,cs_explicit_codepage);
  2900. end;
  2901. 'C' :
  2902. RCCompiler:=More;
  2903. 'd' :
  2904. if UnsetBool(more, 0, opt, true) then
  2905. init_settings.disabledircache:=false
  2906. else
  2907. init_settings.disabledircache:=true;
  2908. 'D' :
  2909. utilsdirectory:=FixPath(More,true);
  2910. 'e' :
  2911. SetRedirectFile(More);
  2912. 'E' :
  2913. OutputExeDir:=FixPath(More,true);
  2914. 'f' :
  2915. if (target_info.system in systems_darwin) then
  2916. if ispara then
  2917. ParaFrameworkPath.AddPath(More,false)
  2918. else
  2919. frameworksearchpath.AddPath(More,true)
  2920. {$if defined(XTENSA) or defined(RISCV32)}
  2921. else if (target_info.system in [system_xtensa_freertos,system_riscv32_freertos]) then
  2922. idfpath:=FixPath(More,true)
  2923. {$endif defined(XTENSA) or defined(RISCV32)}
  2924. else
  2925. IllegalPara(opt);
  2926. 'F' :
  2927. RCForceFPCRes:=true;
  2928. 'i' :
  2929. begin
  2930. if ispara then
  2931. ParaIncludePath.AddPath(More,false)
  2932. else
  2933. includesearchpath.AddPath(More,true);
  2934. end;
  2935. 'm' :
  2936. begin
  2937. if TryStrToInt(ExtractFileName(more),j) then
  2938. begin
  2939. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  2940. if assigned(unicodemapping) then
  2941. registermapping(unicodemapping)
  2942. else
  2943. IllegalPara(opt);
  2944. end
  2945. else
  2946. IllegalPara(opt);
  2947. end;
  2948. 'M' :
  2949. unicodepath:=FixPath(More,true);
  2950. 'g' :
  2951. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  2952. 'l' :
  2953. begin
  2954. if ispara then
  2955. ParaLibraryPath.AddLibraryPath(sysrootpath,More,false)
  2956. else
  2957. LibrarySearchPath.AddLibraryPath(sysrootpath,More,true)
  2958. end;
  2959. 'L' :
  2960. begin
  2961. if More<>'' then
  2962. ParaDynamicLinker:=More
  2963. else
  2964. IllegalPara(opt);
  2965. end;
  2966. 'N' :
  2967. begin
  2968. if more<>'' then
  2969. paranamespaces.insert(more)
  2970. else
  2971. illegalpara(opt);
  2972. end;
  2973. 'o' :
  2974. begin
  2975. if ispara then
  2976. ParaObjectPath.AddPath(More,false)
  2977. else
  2978. ObjectSearchPath.AddPath(More,true);
  2979. end;
  2980. 'P' :
  2981. begin
  2982. if ispara then
  2983. parapackages.add(more,nil)
  2984. else
  2985. add_package(more,true,true);
  2986. end;
  2987. 'p' :
  2988. begin
  2989. if ispara then
  2990. parapackagepath.AddPath(More,false)
  2991. else
  2992. packagesearchpath.AddPath(More,true);
  2993. end;
  2994. 'r' :
  2995. Msgfilename:=More;
  2996. 'R' :
  2997. ResCompiler:=More;
  2998. 't' :
  2999. begin
  3000. AllowedFilenameTransFormations:=[ftNone,ftLowerCase];
  3001. Message(general_i_reduced_filesearch);
  3002. end;
  3003. 'u' :
  3004. begin
  3005. if ispara then
  3006. ParaUnitPath.AddPath(More,false)
  3007. else
  3008. unitsearchpath.AddPath(More,true);
  3009. end;
  3010. 'U' :
  3011. OutputUnitDir:=FixPath(More,true);
  3012. 'W',
  3013. 'w':
  3014. begin
  3015. if More<>'' then
  3016. begin
  3017. DefaultReplacements(More);
  3018. D:=ExtractFilePath(More);
  3019. if (D<>'') then
  3020. D:=FixPath(D,True);
  3021. D:=D+ExtractFileName(More);
  3022. if (c='W') then
  3023. WpoFeedbackOutput:=D
  3024. else
  3025. WpoFeedbackInput:=D;
  3026. end
  3027. else
  3028. IllegalPara(opt);
  3029. end;
  3030. else
  3031. IllegalPara(opt);
  3032. end;
  3033. end;
  3034. procedure TOption.Interpret_G_l(opt, more: TCmdStr);
  3035. var
  3036. j : integer;
  3037. begin
  3038. if UnsetBool(More, 0, opt, false) then
  3039. begin
  3040. exclude(init_settings.moduleswitches,cs_debuginfo);
  3041. exclude(init_settings.globalswitches,cs_use_heaptrc);
  3042. exclude(init_settings.globalswitches,cs_use_lineinfo);
  3043. exclude(init_settings.localswitches,cs_checkpointer);
  3044. paratargetdbg:=dbg_none;
  3045. localvartrashing := -1;
  3046. end
  3047. else
  3048. begin
  3049. include(init_settings.moduleswitches,cs_debuginfo);
  3050. if paratargetdbg=dbg_none then
  3051. paratargetdbg:=target_info.dbg;
  3052. end;
  3053. if not RelocSectionSetExplicitly then
  3054. RelocSection:=false;
  3055. j:=1;
  3056. while j<=length(more) do
  3057. begin
  3058. case more[j] of
  3059. 'c' :
  3060. begin
  3061. if UnsetBool(More, j, opt, false) then
  3062. exclude(init_settings.localswitches,cs_checkpointer)
  3063. else if (target_info.system in systems_support_checkpointer) then
  3064. begin
  3065. if do_release then
  3066. Message(option_gc_incompatible_with_release_flag)
  3067. else
  3068. include(init_settings.localswitches,cs_checkpointer);
  3069. end
  3070. else
  3071. UnsupportedPara('-gc');
  3072. end;
  3073. 'h' :
  3074. begin
  3075. if UnsetBool(More, j, opt, false) then
  3076. exclude(init_settings.globalswitches,cs_use_heaptrc)
  3077. else
  3078. begin
  3079. if cs_gdb_valgrind in init_settings.globalswitches then
  3080. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  3081. include(init_settings.globalswitches,cs_use_heaptrc);
  3082. end;
  3083. end;
  3084. 'l' :
  3085. begin
  3086. if UnsetBool(More, j, opt, false) then
  3087. exclude(init_settings.globalswitches,cs_use_lineinfo)
  3088. else
  3089. begin
  3090. if target_info.system in (systems_wasm+systems_embedded) then
  3091. IgnoredPara('-gl')
  3092. else
  3093. include(init_settings.globalswitches,cs_use_lineinfo);
  3094. end;
  3095. end;
  3096. 'm' :
  3097. begin
  3098. paratargetdbg:=dbg_codeview;
  3099. end;
  3100. 'o' :
  3101. begin
  3102. if not UpdateDebugStr(copy(more,j+1),init_settings.debugswitches) then
  3103. IllegalPara(opt);
  3104. break;
  3105. end;
  3106. 'p' :
  3107. begin
  3108. if UnsetBool(More, j, opt, false) then
  3109. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  3110. else
  3111. include(init_settings.globalswitches,cs_stabs_preservecase);
  3112. end;
  3113. 's' :
  3114. begin
  3115. paratargetdbg:=dbg_stabs;
  3116. end;
  3117. 't' :
  3118. begin
  3119. if UnsetBool(More, j, opt, false) then
  3120. localvartrashing := -1
  3121. else
  3122. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  3123. end;
  3124. 'v' :
  3125. begin
  3126. if UnsetBool(More, j, opt, false) then
  3127. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  3128. else
  3129. begin
  3130. if cs_use_heaptrc in init_settings.globalswitches then
  3131. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  3132. include(init_settings.globalswitches,cs_gdb_valgrind);
  3133. end;
  3134. end;
  3135. 'w' :
  3136. begin
  3137. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  3138. begin
  3139. case more[j+1] of
  3140. '2': paratargetdbg:=dbg_dwarf2;
  3141. '3': paratargetdbg:=dbg_dwarf3;
  3142. '4': paratargetdbg:=dbg_dwarf4;
  3143. end;
  3144. inc(j);
  3145. end
  3146. else
  3147. paratargetdbg:=dbg_dwarf2;
  3148. end;
  3149. else
  3150. IllegalPara(opt);
  3151. end;
  3152. inc(j);
  3153. end;
  3154. end;
  3155. procedure TOption.Interpret_Help(more: TCmdStr);
  3156. begin
  3157. if (More <> '') and (More [1] = 'F') then
  3158. begin
  3159. FPCHelpLines := true;
  3160. Delete (More, 1, 1);
  3161. FPCBinaryPath := More;
  3162. end;
  3163. WriteHelpPages;
  3164. end;
  3165. procedure TOption.Interpret_H_l(more: TCmdStr);
  3166. begin
  3167. NoPressEnter:=true;
  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_I_l(more: TCmdStr);
  3177. begin
  3178. if (More='') or
  3179. (More [1] in ['a', 'b', 'c', 'f', 'i', {$ifdef LLVM}'l',{$endif} 'm', 'o', 'r', 't', 'u', 'w', 'x']) then
  3180. WriteInfo (More)
  3181. else
  3182. QuickInfo:=QuickInfo+More;
  3183. end;
  3184. procedure TOption.Interpret_I_U(more: TCmdStr; ispara: boolean);
  3185. begin
  3186. if ispara then
  3187. ParaIncludePath.AddPath(More,false)
  3188. else
  3189. includesearchpath.AddPath(More,false);
  3190. end;
  3191. procedure TOption.Interpret_K_l(opt, more: TCmdStr);
  3192. begin
  3193. if more<>'' then
  3194. ParaLinkOptions:=ParaLinkOptions+' '+More
  3195. else
  3196. IllegalPara(opt);
  3197. end;
  3198. procedure TOption.Interpret_L_l(opt, more: TCmdStr);
  3199. begin
  3200. ParaLogo:=not UnSetBool(more,0,opt,true);
  3201. end;
  3202. procedure TOption.Interpret_M_l(opt, more: TCmdStr);
  3203. begin
  3204. {$ifdef PREPROCWRITE}
  3205. parapreprocess:=not UnSetBool(more,0,opt,true);
  3206. {$endif PREPROCWRITE}
  3207. end;
  3208. procedure TOption.Interpret_M_U(opt, more: TCmdStr);
  3209. begin
  3210. more:=Upper(more);
  3211. if not SetCompileMode(more, true) then
  3212. if not SetCompileModeSwitch(more, true) then
  3213. IllegalPara(opt);
  3214. end;
  3215. procedure TOption.Interpret_N_l(opt, more: TCmdStr);
  3216. begin
  3217. if More='' then
  3218. disable_configfile:=true
  3219. else
  3220. IllegalPara(opt);
  3221. end;
  3222. procedure TOption.Interpret_O_l(opt, more: TCmdStr);
  3223. var
  3224. D : String;
  3225. begin
  3226. if More<>'' then
  3227. begin
  3228. DefaultReplacements(More);
  3229. D:=ExtractFilePath(More);
  3230. if (D<>'') then
  3231. OutputExeDir:=FixPath(D,True);
  3232. OutputFileName:=ExtractFileName(More);
  3233. end
  3234. else
  3235. IllegalPara(opt);
  3236. end;
  3237. procedure TOption.Interpret_O_U(opt, more: TCmdStr);
  3238. var
  3239. j : integer;
  3240. begin
  3241. j:=1;
  3242. while j<=length(more) do
  3243. begin
  3244. case more[j] of
  3245. '1' :
  3246. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  3247. '2' :
  3248. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  3249. '3' :
  3250. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  3251. '4' :
  3252. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  3253. 'a' :
  3254. begin
  3255. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  3256. IllegalPara(opt);
  3257. break;
  3258. end;
  3259. 's' :
  3260. include(init_settings.optimizerswitches,cs_opt_size);
  3261. 'p' :
  3262. begin
  3263. if not Setoptimizecputype(copy(more,j+1),init_settings.optimizecputype) then
  3264. begin
  3265. OptCPUSetExplicitly:=true;
  3266. { Give warning for old i386 switches }
  3267. if (Length(More)-j=1) and
  3268. (More[j+1]>='1') and (More[j+1]<='5')then
  3269. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  3270. else
  3271. IllegalPara(opt);
  3272. end;
  3273. break;
  3274. end;
  3275. 'o' :
  3276. begin
  3277. if not UpdateOptimizerStr(copy(more,j+1),init_settings.optimizerswitches) then
  3278. IllegalPara(opt);
  3279. break;
  3280. end;
  3281. '-' :
  3282. begin
  3283. init_settings.optimizerswitches:=[];
  3284. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3285. end;
  3286. { Obsolete switches }
  3287. 'g' :
  3288. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  3289. 'G' :
  3290. Message1(option_obsolete_switch,'-OG');
  3291. 'r' :
  3292. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  3293. 'u' :
  3294. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  3295. 'w' :
  3296. begin
  3297. if not UpdateWpoStr(copy(more,j+1),init_settings.dowpoptimizerswitches) then
  3298. IllegalPara(opt);
  3299. break;
  3300. end;
  3301. 'W' :
  3302. begin
  3303. if not UpdateWpoStr(copy(more,j+1),init_settings.genwpoptimizerswitches) then
  3304. IllegalPara(opt);
  3305. break;
  3306. end;
  3307. else
  3308. IllegalPara(opt);
  3309. end;
  3310. inc(j);
  3311. end;
  3312. end;
  3313. procedure TOption.Interpret_P_l(opt, more: TCmdStr);
  3314. begin
  3315. if UnsetBool(More, 0, opt, false) then
  3316. begin
  3317. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  3318. undef_system_macro('FPC_PROFILE');
  3319. end
  3320. else
  3321. if Length(More)=0 then
  3322. IllegalPara(opt)
  3323. else
  3324. case more[1] of
  3325. 'g' : if UnsetBool(more, 1, opt, false) then
  3326. begin
  3327. exclude(init_settings.moduleswitches,cs_profile);
  3328. undef_system_macro('FPC_PROFILE');
  3329. end
  3330. else if (target_info.system in supported_targets_pg) then
  3331. begin
  3332. include(init_settings.moduleswitches,cs_profile);
  3333. def_system_macro('FPC_PROFILE');
  3334. end
  3335. else
  3336. UnsupportedPara('-pg');
  3337. else
  3338. IllegalPara(opt);
  3339. end;
  3340. end;
  3341. procedure TOption.Interpret_P_U(opt, more: TCmdStr);
  3342. begin
  3343. { used to select the target processor with the "fpc" binary;
  3344. give an error if it's not the target architecture supported by
  3345. this compiler binary (will be verified after the target_info
  3346. is set) }
  3347. processorstr:=More;
  3348. end;
  3349. procedure TOption.Interpret_R_U(opt, more: TCmdStr);
  3350. begin
  3351. if not SetAsmReadMode(More,init_settings.asmmode) then
  3352. IllegalPara(opt);
  3353. end;
  3354. procedure TOption.Interpret_S_l(opt, more: TCmdStr);
  3355. begin
  3356. if UnsetBool(More, 0, opt, false) then
  3357. begin
  3358. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  3359. if more<>'' then
  3360. IllegalPara(opt);
  3361. end
  3362. else
  3363. begin
  3364. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  3365. if more='h' then
  3366. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target,cs_assemble_on_target]
  3367. else if more='t' then
  3368. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target,cs_assemble_on_target]
  3369. else if more='T' then
  3370. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]-[cs_asm_extern]
  3371. else if more='r' then
  3372. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  3373. else if more<>'' then
  3374. IllegalPara(opt);
  3375. end;
  3376. end;
  3377. procedure TOption.Interpret_S_U(opt, more: TCmdStr);
  3378. var
  3379. j : integer;
  3380. begin
  3381. if more='' then
  3382. IllegalPara(opt);
  3383. if more[1]='I' then
  3384. begin
  3385. {$ifdef jvm}
  3386. UnsupportedPara('-SI');
  3387. {$endif}
  3388. if upper(more)='ICOM' then
  3389. init_settings.interfacetype:=it_interfacecom
  3390. else if upper(more)='ICORBA' then
  3391. init_settings.interfacetype:=it_interfacecorba
  3392. else
  3393. IllegalPara(opt);
  3394. end
  3395. else
  3396. begin
  3397. j:=1;
  3398. while j<=length(more) do
  3399. begin
  3400. case more[j] of
  3401. '2' : //an alternative to -Mobjfpc
  3402. SetCompileMode('OBJFPC',true);
  3403. 'a' :
  3404. If UnsetBool(More, j, opt, false) then
  3405. exclude(init_settings.localswitches,cs_do_assertion)
  3406. else
  3407. include(init_settings.localswitches,cs_do_assertion);
  3408. 'c' :
  3409. If UnsetBool(More, j, opt, false) then
  3410. exclude(init_settings.moduleswitches,cs_support_c_operators)
  3411. else
  3412. include(init_settings.moduleswitches,cs_support_c_operators);
  3413. 'C':
  3414. If UnsetBool(More, j, opt, false) then
  3415. exclude(init_settings.localswitches,cs_check_all_case_coverage)
  3416. else
  3417. include(init_settings.localswitches,cs_check_all_case_coverage);
  3418. 'd' : //an alternative to -Mdelphi
  3419. SetCompileMode('DELPHI',true);
  3420. 'e' :
  3421. begin
  3422. SetErrorFlags(copy(more,j+1));
  3423. break;
  3424. end;
  3425. 'f' :
  3426. begin
  3427. if not(cs_compilesystem in init_settings.moduleswitches) then
  3428. Message(option_features_only_for_system_unit);
  3429. inc(j);
  3430. if more[j]='-' then
  3431. begin
  3432. if length(more)>j then
  3433. IllegalPara(opt)
  3434. else
  3435. features:=[];
  3436. end
  3437. else
  3438. begin
  3439. if (HandleFeature(upper(copy(more,j)))) then
  3440. j:=length(more)
  3441. else
  3442. IllegalPara(opt);
  3443. end;
  3444. end;
  3445. 'g' :
  3446. If UnsetBool(More, j, opt, false) then
  3447. exclude(init_settings.moduleswitches,cs_support_goto)
  3448. else
  3449. include(init_settings.moduleswitches,cs_support_goto);
  3450. 'h' :
  3451. If UnsetBool(More, j, opt, false) then
  3452. exclude(init_settings.localswitches,cs_refcountedstrings)
  3453. else
  3454. include(init_settings.localswitches,cs_refcountedstrings);
  3455. 'i' :
  3456. If UnsetBool(More, j, opt, false) then
  3457. exclude(init_settings.localswitches,cs_do_inline)
  3458. else
  3459. include(init_settings.localswitches,cs_do_inline);
  3460. 'j' :
  3461. If UnsetBool(More, j, opt, false) then
  3462. exclude(init_settings.localswitches,cs_typed_const_writable)
  3463. else
  3464. include(init_settings.localswitches,cs_typed_const_writable);
  3465. 'k' :
  3466. If UnsetBool(More, j, opt, false) then
  3467. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  3468. else
  3469. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  3470. 'm' :
  3471. If UnsetBool(More, j, opt, false) then
  3472. exclude(init_settings.moduleswitches,cs_support_macro)
  3473. else
  3474. include(init_settings.moduleswitches,cs_support_macro);
  3475. 'o' : //an alternative to -Mtp
  3476. SetCompileMode('TP',true);
  3477. 'r' :
  3478. If UnsetBool(More, j, opt, false) then
  3479. exclude(init_settings.globalswitches,cs_transparent_file_names)
  3480. else
  3481. include(init_settings.globalswitches,cs_transparent_file_names);
  3482. {$ifdef gpc_mode}
  3483. 'p' : //an alternative to -Mgpc
  3484. SetCompileMode('GPC',true);
  3485. {$endif}
  3486. 's' :
  3487. If UnsetBool(More, j, opt, false) then
  3488. exclude(init_settings.globalswitches,cs_constructor_name)
  3489. else
  3490. include(init_settings.globalswitches,cs_constructor_name);
  3491. 't' :
  3492. Message1(option_obsolete_switch,'-St');
  3493. 'v' :
  3494. If UnsetBool(More, j, opt, false) then
  3495. exclude(init_settings.globalswitches,cs_support_vectors)
  3496. else
  3497. include(init_settings.globalswitches,cs_support_vectors);
  3498. 'x' :
  3499. If UnsetBool(More, j, opt, false) then
  3500. SetCompileModeSwitch('EXCEPTIONS-',true)
  3501. else
  3502. SetCompileModeSwitch('EXCEPTIONS',true);
  3503. 'y' :
  3504. If UnsetBool(More, j, opt, false) then
  3505. exclude(init_settings.localswitches,cs_typed_addresses)
  3506. else
  3507. include(init_settings.localswitches,cs_typed_addresses);
  3508. '-' :
  3509. begin
  3510. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  3511. cs_support_vectors,cs_load_fpcylix_unit];
  3512. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  3513. cs_typed_addresses];
  3514. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  3515. cs_support_macro];
  3516. end;
  3517. else
  3518. IllegalPara(opt);
  3519. end;
  3520. inc(j);
  3521. end;
  3522. end;
  3523. end;
  3524. procedure TOption.Interpret_T_l(opt, more: TCmdStr);
  3525. begin
  3526. more:=Upper(More);
  3527. if (more='') then
  3528. Message1(option_missing_arg,'-t')
  3529. else
  3530. begin
  3531. if (self.parasubtarget<>'') and (More<>upper(self.parasubtarget)) then
  3532. Message1(option_subtarget_is_already_set,self.parasubtarget)
  3533. else
  3534. self.parasubtarget:=more;
  3535. end;
  3536. end;
  3537. procedure TOption.Interpret_T_U(opt, more: TCmdStr);
  3538. begin
  3539. more:=Upper(More);
  3540. if paratarget=system_none then
  3541. begin
  3542. { remove old target define }
  3543. TargetOptions(false);
  3544. { load new target }
  3545. paratarget:=find_system_by_string(More);
  3546. if paratarget<>system_none then
  3547. set_target(paratarget)
  3548. else
  3549. IllegalPara(opt);
  3550. { set new define }
  3551. TargetOptions(true);
  3552. end
  3553. else
  3554. if More<>upper(target_info.shortname) then
  3555. Message1(option_target_is_already_set,target_info.shortname);
  3556. end;
  3557. procedure TOption.Interpret_U_l(opt, more: TCmdStr);
  3558. begin
  3559. if is_identifier(more) then
  3560. undef_system_macro(more)
  3561. else
  3562. begin
  3563. if (more='') then
  3564. Message1(option_missing_arg,'-u')
  3565. else
  3566. Message1(option_malformed_para,opt);
  3567. StopOptions(1);
  3568. end;
  3569. end;
  3570. procedure TOption.Interpret_U_U(opt, more: TCmdStr);
  3571. var
  3572. j : integer;
  3573. begin
  3574. j:=1;
  3575. while j<=length(more) do
  3576. begin
  3577. case more[j] of
  3578. {$ifdef UNITALIASES}
  3579. 'a' :
  3580. begin
  3581. AddUnitAlias(Copy(More,j+1));
  3582. break;
  3583. end;
  3584. {$endif UNITALIASES}
  3585. 'n' :
  3586. exclude(init_settings.globalswitches,cs_check_unit_name);
  3587. 'p' :
  3588. begin
  3589. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  3590. break;
  3591. end;
  3592. 'r' :
  3593. begin
  3594. do_release:=true;
  3595. if (cs_checkpointer in init_settings.localswitches) then
  3596. begin
  3597. Message(option_gc_incompatible_with_release_flag);
  3598. exclude(init_settings.localswitches,cs_checkpointer);
  3599. end;
  3600. end;
  3601. 's' :
  3602. include(init_settings.moduleswitches,cs_compilesystem);
  3603. '-' :
  3604. begin
  3605. exclude(init_settings.moduleswitches,cs_compilesystem);
  3606. exclude(init_settings.globalswitches,cs_check_unit_name);
  3607. end;
  3608. else
  3609. IllegalPara(opt);
  3610. end;
  3611. inc(j);
  3612. end;
  3613. end;
  3614. procedure TOption.Interpret_V_l(opt, more: TCmdStr);
  3615. begin
  3616. if not setverbosity(More) then
  3617. IllegalPara(opt);
  3618. end;
  3619. procedure TOption.Interpret_V_U(opt, more: TCmdStr);
  3620. begin
  3621. ; { Ignore used by fpc }
  3622. end;
  3623. procedure TOption.Interpret_W_U(opt, more: TCmdStr);
  3624. var
  3625. j,code : integer;
  3626. s : string;
  3627. begin
  3628. j:=1;
  3629. while j<=length(More) do
  3630. begin
  3631. case More[j] of
  3632. 'A':
  3633. begin
  3634. if target_info.system in systems_all_windows then
  3635. begin
  3636. if UnsetBool(More, j, opt, false) then
  3637. SetApptype(app_cui)
  3638. else
  3639. SetApptype(app_native);
  3640. end
  3641. else
  3642. IllegalPara(opt);
  3643. end;
  3644. 'b':
  3645. begin
  3646. if target_info.system in systems_darwin then
  3647. begin
  3648. if UnsetBool(More, j, opt, false) then
  3649. SetApptype(app_cui)
  3650. else
  3651. SetApptype(app_bundle)
  3652. end
  3653. else
  3654. IllegalPara(opt);
  3655. end;
  3656. 'B':
  3657. begin
  3658. if target_info.system in systems_all_windows+systems_symbian+[system_z80_zxspectrum] then
  3659. begin
  3660. { -WB200000 means set trefered base address
  3661. to $200000, but does not change relocsection boolean
  3662. this way we can create both relocatble and
  3663. non relocatable DLL at a specific base address PM }
  3664. if (length(More)>j) then
  3665. begin
  3666. val('$'+Copy(More,j+1),imagebase,code);
  3667. if code<>0 then
  3668. IllegalPara(opt);
  3669. ImageBaseSetExplicity:=true;
  3670. end
  3671. else
  3672. begin
  3673. RelocSection:=true;
  3674. RelocSectionSetExplicitly:=true;
  3675. end;
  3676. break;
  3677. end
  3678. else
  3679. IllegalPara(opt);
  3680. end;
  3681. 'C':
  3682. begin
  3683. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  3684. begin
  3685. if UnsetBool(More, j, opt, false) then
  3686. SetApptype(app_gui)
  3687. else
  3688. SetApptype(app_cui);
  3689. end
  3690. else
  3691. IllegalPara(opt);
  3692. end;
  3693. 'D':
  3694. begin
  3695. if target_info.system in systems_all_windows then
  3696. begin
  3697. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  3698. UseDeffileForExportsSetExplicitly:=true;
  3699. end
  3700. else
  3701. IllegalPara(opt);
  3702. end;
  3703. 'e':
  3704. begin
  3705. if (target_info.system in systems_darwin) then
  3706. begin
  3707. set_target_res(res_ext);
  3708. target_info.resobjext:='.fpcres';
  3709. end
  3710. else
  3711. IllegalPara(opt);
  3712. end;
  3713. 'F':
  3714. begin
  3715. {$if defined(m68k)}
  3716. if target_info.system in [system_m68k_atari] then
  3717. begin
  3718. if (length(More)>j) then
  3719. begin
  3720. val(Copy(More,j+1),ataritos_exe_flags,code);
  3721. if code<>0 then
  3722. IllegalPara(opt);
  3723. end
  3724. else
  3725. IllegalPara(opt);
  3726. break;
  3727. end;
  3728. {$endif defined(m68k)}
  3729. if target_info.system in systems_os2 then
  3730. begin
  3731. if UnsetBool(More, j, opt, false) then
  3732. SetApptype(app_cui)
  3733. else
  3734. SetApptype(app_fs);
  3735. end
  3736. else
  3737. IllegalPara(opt);
  3738. end;
  3739. 'G':
  3740. begin
  3741. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  3742. begin
  3743. if UnsetBool(More, j, opt, false) then
  3744. SetApptype(app_cui)
  3745. else
  3746. SetApptype(app_gui);
  3747. end
  3748. else
  3749. IllegalPara(opt);
  3750. end;
  3751. {$if defined(i8086)}
  3752. 'h':
  3753. begin
  3754. if UnsetBool(More, j, opt, false) then
  3755. exclude(init_settings.moduleswitches,cs_huge_code)
  3756. else
  3757. include(init_settings.moduleswitches,cs_huge_code);
  3758. end;
  3759. {$endif defined(i8086)}
  3760. 'I':
  3761. begin
  3762. if target_info.system in systems_all_windows then
  3763. begin
  3764. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  3765. GenerateImportSectionSetExplicitly:=true;
  3766. end
  3767. else
  3768. IllegalPara(opt);
  3769. end;
  3770. 'i':
  3771. begin
  3772. if (target_info.system in systems_darwin) then
  3773. begin
  3774. set_target_res(res_macho);
  3775. target_info.resobjext:=
  3776. targetinfos[target_info.system]^.resobjext;
  3777. end
  3778. else
  3779. IllegalPara(opt);
  3780. end;
  3781. 'm':
  3782. begin
  3783. {$if defined(i8086)}
  3784. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  3785. begin
  3786. case Upper(Copy(More,j+1)) of
  3787. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  3788. 'SMALL': init_settings.x86memorymodel:=mm_small;
  3789. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  3790. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  3791. 'LARGE': init_settings.x86memorymodel:=mm_large;
  3792. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  3793. else
  3794. IllegalPara(opt);
  3795. end;
  3796. MemoryModelSetExplicitly:=true;
  3797. break;
  3798. end
  3799. else
  3800. {$endif defined(i8086)}
  3801. IllegalPara(opt);
  3802. end;
  3803. 'M':
  3804. begin
  3805. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim,system_aarch64_iphonesim])) and
  3806. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2),false) then
  3807. begin
  3808. break;
  3809. end
  3810. else
  3811. IllegalPara(opt);
  3812. end;
  3813. 'N':
  3814. begin
  3815. if target_info.system in systems_all_windows then
  3816. begin
  3817. RelocSection:=UnsetBool(More,j,opt,false);
  3818. RelocSectionSetExplicitly:=true;
  3819. end
  3820. else
  3821. IllegalPara(opt);
  3822. end;
  3823. 'p':
  3824. begin
  3825. {$push}
  3826. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  3827. if ((target_info.system in systems_embedded) or (target_info.system in systems_freertos)) and
  3828. ControllerSupport then
  3829. begin
  3830. s:=upper(copy(more,j+1));
  3831. if not(SetControllerType(s,init_settings.controllertype)) then
  3832. IllegalPara(opt)
  3833. else
  3834. begin
  3835. if init_settings.cputype<>embedded_controllers[init_settings.controllertype].cputype then
  3836. begin
  3837. Message(scan_n_changecputype);
  3838. init_settings.cputype:=embedded_controllers[init_settings.controllertype].cputype;
  3839. end;
  3840. end;
  3841. break;
  3842. end
  3843. else
  3844. IllegalPara(opt);
  3845. {$pop}
  3846. end;
  3847. 'P':
  3848. begin
  3849. if (target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim,system_aarch64_iphonesim]) and
  3850. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2),true) then
  3851. begin
  3852. break;
  3853. end
  3854. {$if defined(XTENSA) or defined(RISCV32)}
  3855. else if (target_info.system in [system_xtensa_freertos,system_riscv32_freertos]) and
  3856. ParseVersionStr(idf_version,'IDF_VERSION',copy(More,2)) then
  3857. begin
  3858. break;
  3859. end
  3860. {$endif XTENSA or RISCV32}
  3861. else
  3862. IllegalPara(opt);
  3863. end;
  3864. {$if defined(m68k)}
  3865. 'L':
  3866. begin
  3867. if (target_info.system in [system_m68k_sinclairql]) then
  3868. sinclairql_vlink_experimental:=false
  3869. else
  3870. IllegalPara(opt);
  3871. end;
  3872. 'Q':
  3873. begin
  3874. if (target_info.system in [system_m68k_sinclairql]) then
  3875. begin
  3876. sinclairql_metadata_format:=Upper(Copy(More,j+1));
  3877. case sinclairql_metadata_format of
  3878. 'QHDR', 'XTCC': ; { allowed formats }
  3879. else
  3880. IllegalPara(opt);
  3881. end;
  3882. break;
  3883. end
  3884. else
  3885. IllegalPara(opt);
  3886. end;
  3887. {$endif defined(m68k)}
  3888. 'R':
  3889. begin
  3890. if target_info.system in systems_all_windows then
  3891. begin
  3892. { support -WR+ / -WR- as synonyms to -WR / -WN }
  3893. RelocSection:=not UnsetBool(More,j,opt,false);
  3894. RelocSectionSetExplicitly:=true;
  3895. end
  3896. else
  3897. IllegalPara(opt);
  3898. end;
  3899. 't':
  3900. begin
  3901. {$if defined(i8086)}
  3902. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  3903. begin
  3904. case Upper(Copy(More,j+1)) of
  3905. 'EXE': SetAppType(app_cui);
  3906. 'COM': SetAppType(app_com);
  3907. else
  3908. IllegalPara(opt);
  3909. end;
  3910. break;
  3911. end
  3912. else
  3913. {$endif defined(i8086)}
  3914. {$if defined(m68k)}
  3915. if (target_info.system in [system_m68k_atari]) then
  3916. begin
  3917. case Upper(Copy(More,j+1)) of
  3918. 'TOS': ataritos_exe_format := 'ataritos';
  3919. 'MINT': ataritos_exe_format := 'aoutmint';
  3920. else
  3921. IllegalPara(opt);
  3922. end;
  3923. break;
  3924. end
  3925. else
  3926. {$endif defined(m68k)}
  3927. IllegalPara(opt);
  3928. end;
  3929. 'T':
  3930. begin
  3931. if target_info.system in systems_macos then
  3932. begin
  3933. if UnsetBool(More, j, opt, false) then
  3934. SetApptype(app_cui)
  3935. else
  3936. SetApptype(app_tool);
  3937. end
  3938. else
  3939. IllegalPara(opt);
  3940. end;
  3941. 'X':
  3942. begin
  3943. if (target_info.system in systems_linux) then
  3944. begin
  3945. if UnsetBool(More, j, opt, false) then
  3946. exclude(init_settings.moduleswitches,cs_executable_stack)
  3947. else
  3948. include(init_settings.moduleswitches,cs_executable_stack)
  3949. end
  3950. else
  3951. IllegalPara(opt);
  3952. end;
  3953. else
  3954. IllegalPara(opt);
  3955. end;
  3956. inc(j);
  3957. end;
  3958. end;
  3959. procedure TOption.Interpret_X_l(opt, more: TCmdStr);
  3960. begin
  3961. message1(option_x_ignored,more);
  3962. end;
  3963. procedure TOption.Interpret_X_U(opt, more: TCmdStr);
  3964. var
  3965. j : integer;
  3966. s : string;
  3967. begin
  3968. j:=1;
  3969. while j<=length(more) do
  3970. begin
  3971. case More[j] of
  3972. '9' :
  3973. begin
  3974. if target_info.system in systems_linux then
  3975. begin
  3976. if UnsetBool(More, j, opt, false) then
  3977. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  3978. else
  3979. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  3980. end
  3981. else
  3982. IllegalPara(opt);
  3983. end;
  3984. 'a' :
  3985. begin
  3986. If UnsetBool(More, j, opt, false) then
  3987. exclude(init_settings.globalswitches,cs_large)
  3988. else
  3989. include(init_settings.globalswitches,cs_large);
  3990. end;
  3991. 'c' : Cshared:=TRUE;
  3992. 'd' : Dontlinkstdlibpath:=TRUE;
  3993. 'e' :
  3994. begin
  3995. If UnsetBool(More, j, opt, false) then
  3996. begin
  3997. exclude(init_settings.globalswitches,cs_link_extern);
  3998. LinkInternSetExplicitly:=true;
  3999. end
  4000. else
  4001. include(init_settings.globalswitches,cs_link_extern);
  4002. end;
  4003. 'f' :
  4004. include(init_settings.globalswitches,cs_link_pthread);
  4005. 'g' :
  4006. begin
  4007. If UnsetBool(More, j, opt, false) then
  4008. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  4009. else
  4010. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  4011. end;
  4012. 'i' :
  4013. begin
  4014. If UnsetBool(More, j, opt, false) then
  4015. include(init_settings.globalswitches,cs_link_extern)
  4016. else
  4017. begin
  4018. exclude(init_settings.globalswitches,cs_link_extern);
  4019. LinkInternSetExplicitly:=true;
  4020. end;
  4021. end;
  4022. 'n' :
  4023. begin
  4024. If UnsetBool(More, j, opt, false) then
  4025. exclude(init_settings.globalswitches,cs_link_native)
  4026. else
  4027. include(init_settings.globalswitches,cs_link_native);
  4028. end;
  4029. {$ifdef llvm}
  4030. 'l' :
  4031. begin
  4032. if j=length(more) then
  4033. IllegalPara(opt)
  4034. else
  4035. begin
  4036. case more[j+1] of
  4037. 'S':
  4038. begin
  4039. llvmutilssuffix:=copy(more,j+2);
  4040. j:=length(more);
  4041. end
  4042. else
  4043. IllegalPara(opt);
  4044. end;
  4045. end;
  4046. end;
  4047. {$endif}
  4048. 'm' :
  4049. begin
  4050. If UnsetBool(More, j, opt, false) then
  4051. exclude(init_settings.globalswitches,cs_link_map)
  4052. else
  4053. include(init_settings.globalswitches,cs_link_map);
  4054. end;
  4055. 'p' : ; { Ignore used by fpc.pp }
  4056. 'r' :
  4057. begin
  4058. if (target_info.system in suppported_targets_x_smallr) then
  4059. begin
  4060. rlinkpath:=Copy(more,2);
  4061. DefaultReplacements(rlinkpath);
  4062. end
  4063. else
  4064. IgnoredPara('-Xr');
  4065. more:='';
  4066. end;
  4067. 'R' :
  4068. begin
  4069. sysrootpath:=copy(more,2);
  4070. defaultreplacements(sysrootpath);
  4071. more:='';
  4072. end;
  4073. 's' :
  4074. begin
  4075. If UnsetBool(More, j, opt, false) then
  4076. exclude(init_settings.globalswitches,cs_link_strip)
  4077. else
  4078. include(init_settings.globalswitches,cs_link_strip);
  4079. end;
  4080. 't' :
  4081. include(init_settings.globalswitches,cs_link_staticflag);
  4082. 'u' :
  4083. begin
  4084. if target_info.system in systems_support_uf2 then
  4085. begin
  4086. if UnsetBool(More, j, opt, false) then
  4087. exclude(init_settings.globalswitches,cs_generate_uf2)
  4088. else
  4089. include(init_settings.globalswitches,cs_generate_uf2);
  4090. end
  4091. else
  4092. IgnoredPara('-Xu');
  4093. end;
  4094. 'v' :
  4095. begin
  4096. If UnsetBool(More, j, opt, false) then
  4097. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  4098. else
  4099. include(init_settings.globalswitches,cs_link_opt_vtable);
  4100. end;
  4101. 'D' :
  4102. begin
  4103. def_system_macro('FPC_LINK_DYNAMIC');
  4104. undef_system_macro('FPC_LINK_SMART');
  4105. undef_system_macro('FPC_LINK_STATIC');
  4106. exclude(init_settings.globalswitches,cs_link_static);
  4107. exclude(init_settings.globalswitches,cs_link_smart);
  4108. include(init_settings.globalswitches,cs_link_shared);
  4109. LinkTypeSetExplicitly:=true;
  4110. end;
  4111. 'M' :
  4112. begin
  4113. mainaliasname:=Copy(more,2);
  4114. More:='';
  4115. end;
  4116. 'P' :
  4117. begin
  4118. utilsprefix:=Copy(more,2);
  4119. DefaultReplacements(utilsprefix);
  4120. More:='';
  4121. end;
  4122. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  4123. // these are not aggregable.
  4124. if (j=length(more)) or not (more[j+1] in ['O','A','D','L']) then
  4125. IllegalPara(opt)
  4126. else
  4127. begin
  4128. case more[j+1] of
  4129. 'A' : begin
  4130. s:=Copy(more,3);
  4131. if not LinkLibraryAliases.AddDep(s) Then
  4132. IllegalPara(opt);
  4133. end;
  4134. 'O' : begin
  4135. s:=Copy(more,3);
  4136. if not LinkLibraryOrder.AddWeight(s) Then
  4137. IllegalPara(opt);
  4138. end;
  4139. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order);
  4140. 'L' :
  4141. begin
  4142. if UnsetBool(More, j, opt, false) then
  4143. exclude(init_settings.globalswitches,cs_link_lld)
  4144. else
  4145. begin
  4146. include(init_settings.globalswitches,cs_link_lld);
  4147. include(init_settings.globalswitches,cs_link_extern);
  4148. end;
  4149. LinkerSetExplicitly:=true;
  4150. end
  4151. else
  4152. IllegalPara(opt);
  4153. end; {case}
  4154. j:=length(more);
  4155. end; {else begin}
  4156. end;
  4157. 'S' :
  4158. begin
  4159. ForceStaticLinking;
  4160. end;
  4161. 'V' :
  4162. begin
  4163. if UnsetBool(More, j, opt, false) then
  4164. exclude(init_settings.globalswitches,cs_link_vlink)
  4165. else
  4166. begin
  4167. include(init_settings.globalswitches,cs_link_vlink);
  4168. include(init_settings.globalswitches,cs_link_extern);
  4169. end;
  4170. LinkerSetExplicitly:=true;
  4171. end;
  4172. 'X' :
  4173. begin
  4174. def_system_macro('FPC_LINK_SMART');
  4175. undef_system_macro('FPC_LINK_STATIC');
  4176. undef_system_macro('FPC_LINK_DYNAMIC');
  4177. exclude(init_settings.globalswitches,cs_link_static);
  4178. include(init_settings.globalswitches,cs_link_smart);
  4179. exclude(init_settings.globalswitches,cs_link_shared);
  4180. LinkTypeSetExplicitly:=true;
  4181. end;
  4182. '-' :
  4183. begin
  4184. exclude(init_settings.globalswitches,cs_link_staticflag);
  4185. exclude(init_settings.globalswitches,cs_link_strip);
  4186. exclude(init_settings.globalswitches,cs_link_map);
  4187. set_default_link_type;
  4188. end;
  4189. else
  4190. IllegalPara(opt);
  4191. end;
  4192. inc(j);
  4193. end;
  4194. end;
  4195. {****************************************************************************
  4196. Callable Routines
  4197. ****************************************************************************}
  4198. function check_configfile(fn:string; var foundfn:string):boolean;
  4199. function CfgFileExists(const fn:string):boolean;
  4200. begin
  4201. Comment(V_Tried,'Configfile search: '+fn);
  4202. CfgFileExists:=FileExists(fn);
  4203. end;
  4204. var
  4205. {$ifdef Unix}
  4206. hs,
  4207. {$endif Unix}
  4208. configpath : string;
  4209. begin
  4210. foundfn:=fn;
  4211. check_configfile:=true;
  4212. { retrieve configpath }
  4213. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  4214. {$ifdef Unix}
  4215. if configpath='' then
  4216. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  4217. {$endif}
  4218. {
  4219. Order to read configuration file :
  4220. try reading fpc.cfg in :
  4221. 1 - current dir
  4222. 2 - configpath
  4223. 3 - compiler path
  4224. }
  4225. if not FileExists(fn) then
  4226. begin
  4227. {$ifdef Unix}
  4228. hs:=GetEnvironmentVariable('HOME');
  4229. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  4230. foundfn:=FixPath(hs,false)+'.'+fn
  4231. else
  4232. {$endif}
  4233. if CfgFileExists(configpath+fn) then
  4234. foundfn:=configpath+fn
  4235. else
  4236. {$ifdef WINDOWS}
  4237. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  4238. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  4239. else
  4240. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  4241. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  4242. else
  4243. {$endif WINDOWS}
  4244. {$ifndef Unix}
  4245. if CfgFileExists(exepath+fn) then
  4246. foundfn:=exepath+fn
  4247. else
  4248. {$else}
  4249. if CfgFileExists('/etc/'+fn) then
  4250. foundfn:='/etc/'+fn
  4251. else
  4252. {$endif}
  4253. check_configfile:=false;
  4254. end;
  4255. end;
  4256. procedure read_arguments(cmd:TCmdStr);
  4257. procedure def_cpu_macros;
  4258. var
  4259. abi : tabi;
  4260. fputype : tfputype;
  4261. cputype : tcputype;
  4262. controller: tcontrollertype;
  4263. s: string;
  4264. begin
  4265. {$ifdef llvm}
  4266. def_system_macro('CPULLVM');
  4267. {$endif}
  4268. for cputype:=low(tcputype) to high(tcputype) do
  4269. undef_system_macro('CPU'+Cputypestr[cputype]);
  4270. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  4271. for fputype:=low(tfputype) to high(tfputype) do
  4272. undef_system_macro('FPU'+fputypestr[fputype]);
  4273. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  4274. {$PUSH}
  4275. {$WARN 6018 OFF} { Unreachable code due to compile time evaluation }
  4276. if ControllerSupport then
  4277. begin
  4278. for controller:=low(tcontrollertype) to high(tcontrollertype) do
  4279. begin
  4280. s:=embedded_controllers[controller].controllertypestr;
  4281. if s<>'' then
  4282. undef_system_macro('FPC_MCU_'+s);
  4283. end;
  4284. s:=embedded_controllers[init_settings.controllertype].controllertypestr;
  4285. if s<>'' then
  4286. def_system_macro('FPC_MCU_'+s);
  4287. end;
  4288. {$POP}
  4289. { define abi }
  4290. for abi:=low(tabi) to high(tabi) do
  4291. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  4292. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  4293. { this is not a switchable ABI in the sense of tabi, but it's an ABI
  4294. nevertheless }
  4295. if target_info.system in systems_win64_abi then
  4296. def_system_macro('FPC_ABI_WIN64');
  4297. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  4298. systems since most code needs to behave the same on both}
  4299. if target_info.abi = abi_eabihf then
  4300. def_system_macro('FPC_ABI_EABI');
  4301. { using a case is pretty useless here (FK) }
  4302. { some stuff for TP compatibility }
  4303. {$ifdef i386}
  4304. def_system_macro('CPU86');
  4305. def_system_macro('CPU87');
  4306. def_system_macro('CPU386');
  4307. {$endif}
  4308. { new processor stuff }
  4309. {$ifdef i386}
  4310. def_system_macro('CPUI386');
  4311. def_system_macro('CPU32');
  4312. def_system_macro('CPUX86');
  4313. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4314. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4315. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4316. {$endif}
  4317. {$ifdef m68k}
  4318. def_system_macro('CPU68');
  4319. def_system_macro('CPU68K');
  4320. def_system_macro('CPUM68K');
  4321. def_system_macro('CPU32');
  4322. def_system_macro('FPC_CURRENCY_IS_INT64');
  4323. def_system_macro('FPC_COMP_IS_INT64');
  4324. {$endif}
  4325. {$ifdef powerpc}
  4326. def_system_macro('CPUPOWERPC');
  4327. def_system_macro('CPUPOWERPC32');
  4328. def_system_macro('CPU32');
  4329. def_system_macro('FPC_CURRENCY_IS_INT64');
  4330. def_system_macro('FPC_COMP_IS_INT64');
  4331. {$endif}
  4332. {$ifdef POWERPC64}
  4333. def_system_macro('CPUPOWERPC');
  4334. def_system_macro('CPUPOWERPC64');
  4335. def_system_macro('CPU64');
  4336. def_system_macro('FPC_CURRENCY_IS_INT64');
  4337. def_system_macro('FPC_COMP_IS_INT64');
  4338. {$endif}
  4339. {$ifdef x86_64}
  4340. def_system_macro('CPUX86_64');
  4341. def_system_macro('CPUAMD64');
  4342. def_system_macro('CPU64');
  4343. def_system_macro('CPUX64');
  4344. { not supported for now, afaik (FK)
  4345. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  4346. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4347. { normally, win64 doesn't support the legacy fpu }
  4348. if target_info.system=system_x86_64_win64 then
  4349. begin
  4350. def_system_macro('FPC_CURRENCY_IS_INT64');
  4351. def_system_macro('FPC_COMP_IS_INT64');
  4352. end;
  4353. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4354. {$endif}
  4355. {$ifdef sparc}
  4356. def_system_macro('CPUSPARCGEN');
  4357. def_system_macro('CPUSPARC');
  4358. def_system_macro('CPUSPARC32');
  4359. def_system_macro('CPU32');
  4360. def_system_macro('FPC_CURRENCY_IS_INT64');
  4361. def_system_macro('FPC_COMP_IS_INT64');
  4362. {$endif}
  4363. {$ifdef sparc64}
  4364. def_system_macro('CPUSPARCGEN');
  4365. def_system_macro('CPUSPARC64');
  4366. def_system_macro('CPU64');
  4367. def_system_macro('FPC_CURRENCY_IS_INT64');
  4368. def_system_macro('FPC_COMP_IS_INT64');
  4369. {$endif}
  4370. {$ifdef arm}
  4371. def_system_macro('CPUARM');
  4372. def_system_macro('CPU32');
  4373. def_system_macro('FPC_CURRENCY_IS_INT64');
  4374. def_system_macro('FPC_COMP_IS_INT64');
  4375. {$endif arm}
  4376. {$ifdef avr}
  4377. def_system_macro('CPUAVR');
  4378. def_system_macro('CPU16');
  4379. def_system_macro('FPC_CURRENCY_IS_INT64');
  4380. def_system_macro('FPC_COMP_IS_INT64');
  4381. {$endif avr}
  4382. {$ifdef jvm}
  4383. def_system_macro('CPUJVM');
  4384. def_system_macro('CPU32');
  4385. def_system_macro('FPC_CURRENCY_IS_INT64');
  4386. def_system_macro('FPC_COMP_IS_INT64');
  4387. {$endif jvm}
  4388. {$ifdef mipsel}
  4389. def_system_macro('CPUMIPS');
  4390. def_system_macro('CPUMIPSEL');
  4391. def_system_macro('CPUMIPS32');
  4392. def_system_macro('CPUMIPSEL32');
  4393. def_system_macro('CPU32');
  4394. if target_info.system <> system_mipsel_ps1 then begin
  4395. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4396. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4397. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4398. end;
  4399. def_system_macro('FPC_CURRENCY_IS_INT64');
  4400. def_system_macro('FPC_COMP_IS_INT64');
  4401. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4402. { On most systems, locals are accessed relative to base pointer,
  4403. but for MIPS cpu, they are accessed relative to stack pointer.
  4404. This needs adaptation for so low level routines,
  4405. like MethodPointerLocal and related objects unit functions. }
  4406. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  4407. {$endif mipsel}
  4408. {$ifdef mipseb}
  4409. def_system_macro('CPUMIPS');
  4410. def_system_macro('CPUMIPSEB');
  4411. def_system_macro('CPUMIPS32');
  4412. def_system_macro('CPUMIPSEB32');
  4413. def_system_macro('CPU32');
  4414. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4415. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4416. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4417. def_system_macro('FPC_CURRENCY_IS_INT64');
  4418. def_system_macro('FPC_COMP_IS_INT64');
  4419. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4420. { See comment above for mipsel }
  4421. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  4422. {$endif mipseb}
  4423. {$ifdef mips64eb}
  4424. def_system_macro('CPUMIPS');
  4425. def_system_macro('CPUMIPS64');
  4426. def_system_macro('CPUMIPSEB64');
  4427. def_system_macro('CPUMIPS64EB');
  4428. def_system_macro('CPU64');
  4429. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4430. def_system_macro('FPC_CURRENCY_IS_INT64');
  4431. def_system_macro('FPC_COMP_IS_INT64');
  4432. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4433. { See comment above for mipsel }
  4434. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  4435. {$endif mips64eb}
  4436. {$ifdef mips64el}
  4437. def_system_macro('CPUMIPS');
  4438. def_system_macro('CPUMIPS64');
  4439. def_system_macro('CPUMIPSEL64');
  4440. def_system_macro('CPUMIPS64EL');
  4441. def_system_macro('CPU64');
  4442. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4443. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4444. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4445. def_system_macro('FPC_CURRENCY_IS_INT64');
  4446. def_system_macro('FPC_COMP_IS_INT64');
  4447. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4448. { On most systems, locals are accessed relative to base pointer,
  4449. but for MIPS cpu, they are accessed relative to stack pointer.
  4450. This needs adaptation for so low level routines,
  4451. like MethodPointerLocal and related objects unit functions. }
  4452. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  4453. {$endif mips64el}
  4454. {$ifdef i8086}
  4455. def_system_macro('CPU86'); { Borland compatibility }
  4456. def_system_macro('CPU87'); { Borland compatibility }
  4457. def_system_macro('CPUI8086');
  4458. def_system_macro('CPU16');
  4459. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4460. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4461. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4462. case init_settings.x86memorymodel of
  4463. mm_tiny: def_system_macro('FPC_MM_TINY');
  4464. mm_small: def_system_macro('FPC_MM_SMALL');
  4465. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  4466. mm_compact: def_system_macro('FPC_MM_COMPACT');
  4467. mm_large: def_system_macro('FPC_MM_LARGE');
  4468. mm_huge: def_system_macro('FPC_MM_HUGE');
  4469. end;
  4470. {$endif i8086}
  4471. {$ifdef aarch64}
  4472. def_system_macro('CPUAARCH64');
  4473. def_system_macro('CPU64');
  4474. def_system_macro('FPC_CURRENCY_IS_INT64');
  4475. def_system_macro('FPC_COMP_IS_INT64');
  4476. {$endif aarch64}
  4477. {$ifdef riscv32}
  4478. def_system_macro('CPURISCV');
  4479. def_system_macro('CPURISCV32');
  4480. def_system_macro('CPU32');
  4481. def_system_macro('FPC_CURRENCY_IS_INT64');
  4482. def_system_macro('FPC_COMP_IS_INT64');
  4483. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4484. {$endif riscv32}
  4485. {$ifdef riscv64}
  4486. def_system_macro('CPURISCV');
  4487. def_system_macro('CPURISCV64');
  4488. def_system_macro('CPU64');
  4489. def_system_macro('FPC_CURRENCY_IS_INT64');
  4490. def_system_macro('FPC_COMP_IS_INT64');
  4491. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4492. {$endif riscv64}
  4493. {$ifdef xtensa}
  4494. def_system_macro('CPUXTENSA');
  4495. def_system_macro('CPU32');
  4496. def_system_macro('FPC_CURRENCY_IS_INT64');
  4497. def_system_macro('FPC_COMP_IS_INT64');
  4498. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4499. {$endif xtensa}
  4500. {$ifdef z80}
  4501. def_system_macro('CPUZ80');
  4502. def_system_macro('CPU16');
  4503. def_system_macro('FPC_CURRENCY_IS_INT64');
  4504. def_system_macro('FPC_COMP_IS_INT64');
  4505. {$endif z80}
  4506. {$ifdef mos6502}
  4507. def_system_macro('CPUMOS6502');
  4508. def_system_macro('CPU16');
  4509. def_system_macro('FPC_CURRENCY_IS_INT64');
  4510. def_system_macro('FPC_COMP_IS_INT64');
  4511. {$endif mos6502}
  4512. {$ifdef wasm32}
  4513. def_system_macro('CPUWASM');
  4514. def_system_macro('CPUWASM32');
  4515. def_system_macro('CPU32');
  4516. def_system_macro('FPC_CURRENCY_IS_INT64');
  4517. def_system_macro('FPC_COMP_IS_INT64');
  4518. {$endif wasm32}
  4519. {$ifdef loongarch64}
  4520. def_system_macro('CPULOONGARCH');
  4521. def_system_macro('CPULOONGARCH64');
  4522. def_system_macro('CPU64');
  4523. def_system_macro('FPC_CURRENCY_IS_INT64');
  4524. def_system_macro('FPC_COMP_IS_INT64');
  4525. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4526. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  4527. {$endif loongarch64}
  4528. {$if defined(cpu8bitalu)}
  4529. def_system_macro('CPUINT8');
  4530. {$elseif defined(cpu16bitalu)}
  4531. def_system_macro('CPUINT16');
  4532. {$elseif defined(cpu32bitalu)}
  4533. def_system_macro('CPUINT32');
  4534. {$elseif defined(cpu64bitalu)}
  4535. def_system_macro('CPUINT64');
  4536. {$endif defined(cpu64bitalu)}
  4537. {$if defined(avr)}
  4538. def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
  4539. {$endif}
  4540. {$if defined(i8086) or defined(avr)}
  4541. def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
  4542. {$endif i8086 or avr}
  4543. { abs(long) is handled internally on all CPUs }
  4544. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  4545. { abs(int64) is handled internally on all CPUs }
  4546. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  4547. def_system_macro('FPC_HAS_UNICODESTRING');
  4548. def_system_macro('FPC_RTTI_PACKSET1');
  4549. def_system_macro('FPC_HAS_CPSTRING');
  4550. {$ifdef x86_64}
  4551. def_system_macro('FPC_HAS_RIP_RELATIVE');
  4552. {$endif x86_64}
  4553. def_system_macro('FPC_HAS_CEXTENDED');
  4554. def_system_macro('FPC_HAS_RESSTRINITS');
  4555. { these cpus have an inline rol/ror implementation }
  4556. {$ifdef cpurox}
  4557. {$if defined(m68k)}
  4558. if CPUM68K_HAS_ROLROR in cpu_capabilities[init_settings.cputype] then
  4559. def_system_macro('FPC_HAS_INTERNAL_ROX');
  4560. {$elseif defined(riscv)}
  4561. if [CPURV_HAS_ZBB,CPURV_HAS_ZBKB]*cpu_capabilities[init_settings.cputype]<>[] then
  4562. def_system_macro('FPC_HAS_INTERNAL_ROX');
  4563. {$else}
  4564. def_system_macro('FPC_HAS_INTERNAL_ROX');
  4565. {$endif}
  4566. {$endif}
  4567. {$ifdef powerpc64}
  4568. def_system_macro('FPC_HAS_LWSYNC');
  4569. {$endif}
  4570. def_system_macro('FPC_HAS_ANSICHAR_CHAR');
  4571. { currently, all supported CPUs have an internal sar implementation }
  4572. def_system_macro('FPC_HAS_INTERNAL_SAR');
  4573. {$ifdef SUPPORT_GET_FRAME}
  4574. def_system_macro('INTERNAL_BACKTRACE');
  4575. {$endif SUPPORT_GET_FRAME}
  4576. def_system_macro('STR_CONCAT_PROCS');
  4577. {$warnings off}
  4578. if pocall_default = pocall_register then
  4579. def_system_macro('REGCALL');
  4580. {$warnings on}
  4581. end;
  4582. var
  4583. env: ansistring;
  4584. i : tfeature;
  4585. j : longint;
  4586. tmplist : TCmdStrList;
  4587. cmditem,
  4588. tmpcmditem : TCmdStrListItem;
  4589. cmdstr : TCmdStr;
  4590. {$if defined(cpucapabilities)}
  4591. cpuflag : tcpuflags;
  4592. {$endif defined(cpucapabilities)}
  4593. {$if defined(fpucapabilities)}
  4594. fpuflag : tfpuflags;
  4595. {$endif defined(fpucapabilities)}
  4596. {$if defined(cpucapabilities) or defined(fpucapabilities)}
  4597. hs : string;
  4598. {$endif defined(cpucapabilities) or defined(fpucapabilities)}
  4599. begin
  4600. option:=coption.create;
  4601. disable_configfile:=false;
  4602. { Non-core target defines }
  4603. Option.TargetOptions(true);
  4604. { get default messagefile }
  4605. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  4606. { default configfile can be specified on the commandline,
  4607. remove it first }
  4608. if (cmd<>'') and (cmd[1]='[') then
  4609. begin
  4610. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  4611. Delete(cmd,1,pos(']',cmd));
  4612. end
  4613. else
  4614. ppccfg:='fpc.cfg';
  4615. { first pass reading of parameters, only -i -v -T etc.}
  4616. option.firstpass:=true;
  4617. if cmd<>'' then
  4618. option.parsecmd(cmd)
  4619. else
  4620. begin
  4621. option.read_parameters;
  4622. { Write only quickinfo }
  4623. if option.quickinfo<>'' then
  4624. option.writequickinfo;
  4625. end;
  4626. option.firstpass:=false;
  4627. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  4628. Option.TargetOptions(true);
  4629. { target is set here, for wince the default app type is gui }
  4630. if target_info.system in systems_wince then
  4631. SetApptype(app_gui)
  4632. else
  4633. SetApptype(apptype);
  4634. { default defines }
  4635. def_system_macro(target_info.shortname);
  4636. def_system_macro('FPC');
  4637. def_system_macro('VER'+version_nr);
  4638. def_system_macro('VER'+version_nr+'_'+release_nr);
  4639. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  4640. { Temporary defines, until things settle down }
  4641. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  4642. def_system_macro('FPC_HAS_CONSTREF');
  4643. def_system_macro('FPC_STATICRIPFIXED');
  4644. def_system_macro('FPC_VARIANTCOPY_FIXED');
  4645. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  4646. def_system_macro('FPC_HAS_MEMBAR');
  4647. def_system_macro('FPC_SETBASE_USED');
  4648. def_system_macro('FPC_ALIGNED_THREADVARTABLES');
  4649. { don't remove this, it's also for fpdoc necessary (FK) }
  4650. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  4651. if (Option.parasubtarget<>'') then
  4652. begin
  4653. def_system_macro('FPC_SUBTARGET_'+Option.parasubtarget);
  4654. if cs_support_macro in init_settings.moduleswitches then
  4655. set_system_macro('FPC_SUBTARGET',Option.parasubtarget)
  4656. else
  4657. set_system_compvar('FPC_SUBTARGET',Option.parasubtarget);
  4658. // So it can be used in macro substitution.
  4659. globals.subtarget:=Option.parasubtarget;
  4660. end;
  4661. { make cpu makros available when reading the config files the second time }
  4662. def_cpu_macros;
  4663. set_endianess_macros;
  4664. if tf_cld in target_info.flags then
  4665. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  4666. InternalError(2013092801);
  4667. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  4668. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  4669. InternalError(2013092802);
  4670. if tf_wasm_threads in target_info.flags then
  4671. if not UpdateTargetSwitchStr('WASMTHREADS', init_settings.targetswitches, true) then
  4672. InternalError(2025022701);
  4673. { Use standard Android NDK prefixes when cross-compiling }
  4674. if (source_info.system<>target_info.system) and (target_info.system in systems_android) then
  4675. case target_info.system of
  4676. system_arm_android:
  4677. utilsprefix:='arm-linux-androideabi-';
  4678. system_i386_android:
  4679. utilsprefix:='i686-linux-android-';
  4680. else
  4681. utilsprefix:=target_cpu_string + '-linux-android-';
  4682. end;
  4683. { Set up default value for the heap on Amiga-likes (values only apply if the OSHeap allocator is used) }
  4684. if target_info.system in systems_amigalike then
  4685. begin
  4686. case target_info.system of
  4687. system_m68k_amiga:
  4688. heapsize:=256*1024;
  4689. system_powerpc_amiga,
  4690. system_powerpc_morphos,
  4691. system_arm_aros,
  4692. system_i386_aros,
  4693. system_x86_64_aros:
  4694. heapsize:=1024*1024;
  4695. else
  4696. heapsize:=256*1024;
  4697. end;
  4698. end;
  4699. if target_info.system in (systems_embedded+systems_freertos+[system_z80_zxspectrum,system_z80_msxdos]) then
  4700. begin
  4701. case target_info.system of
  4702. {$ifdef AVR}
  4703. system_avr_embedded:
  4704. if init_settings.controllertype in [ct_avrsim,ct_avrsim6] then
  4705. heapsize:=8192
  4706. else
  4707. heapsize:=128;
  4708. {$endif AVR}
  4709. system_arm_freertos:
  4710. heapsize:=8192;
  4711. system_xtensa_freertos:
  4712. { keep default value }
  4713. ;
  4714. system_arm_embedded:
  4715. heapsize:=256;
  4716. system_mipsel_embedded:
  4717. heapsize:=256;
  4718. else
  4719. heapsize:=256;
  4720. end;
  4721. end;
  4722. { read configuration file }
  4723. if (not disable_configfile) and
  4724. (ppccfg<>'') then
  4725. read_configfile:=check_configfile(ppccfg,ppccfg)
  4726. else
  4727. read_configfile := false;
  4728. if (option.parasubtarget<>'') then
  4729. begin
  4730. subcfg:='fpc-'+lower(option.parasubtarget)+'.cfg';
  4731. read_subfile:=check_configfile(subcfg,subcfg);
  4732. // Warn if we didn't find an architecture-specific file
  4733. if not read_subfile then
  4734. message2(option_subtarget_config_not_found,option.parasubtarget,subcfg);
  4735. end;
  4736. { Read commandline and configfile }
  4737. param_file:='';
  4738. { read configfile }
  4739. if read_configfile then
  4740. option.interpret_file(ppccfg);
  4741. if read_subfile then
  4742. option.interpret_file(subcfg);
  4743. { read parameters again to override config file }
  4744. if cmd<>'' then
  4745. option.parsecmd(cmd)
  4746. else
  4747. begin
  4748. { Write help pages if no parameters are passed }
  4749. if (paramcount=0) then
  4750. Option.WriteHelpPages;
  4751. option.read_parameters;
  4752. { Write only quickinfo }
  4753. if option.quickinfo<>'' then
  4754. option.writequickinfo;
  4755. end;
  4756. { check the compatibility of different options and adjust them if necessary
  4757. (and print possible errors)
  4758. }
  4759. option.checkoptionscompatibility;
  4760. { uses the CPUXXX-defines and target_info to determine whether the selected
  4761. target processor, if any, is supported }
  4762. Option.VerifyTargetProcessor;
  4763. { Stop if errors in options }
  4764. if ErrorCount>0 then
  4765. StopOptions(1);
  4766. { Write logo }
  4767. if option.ParaLogo then
  4768. option.writelogo;
  4769. { Check file to compile }
  4770. if param_file='' then
  4771. begin
  4772. Message(option_no_source_found);
  4773. StopOptions(1);
  4774. end;
  4775. {$ifndef Unix}
  4776. param_file:=FixFileName(param_file);
  4777. {$endif not unix}
  4778. inputfilepath:=ExtractFilePath(param_file);
  4779. inputfilename:=ExtractFileName(param_file);
  4780. if ExtractFileExt(inputfilename)='' then
  4781. begin
  4782. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  4783. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  4784. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  4785. inputfilename:=ChangeFileExt(inputfilename,pasext)
  4786. else if ((m_mac in current_settings.modeswitches) or
  4787. (tf_p_ext_support in target_info.flags))
  4788. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  4789. inputfilename:=ChangeFileExt(inputfilename,pext);
  4790. end;
  4791. { Check output dir }
  4792. if (OutputExeDir<>'') and
  4793. not PathExists(OutputExeDir,false) then
  4794. begin
  4795. Message1(general_e_path_does_not_exist,OutputExeDir);
  4796. StopOptions(1);
  4797. end;
  4798. { Add paths specified with parameters to the searchpaths }
  4799. UnitSearchPath.AddList(option.ParaUnitPath,true);
  4800. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  4801. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  4802. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  4803. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  4804. packagesearchpath.addlist(option.parapackagepath,true);
  4805. for j:=0 to option.parapackages.count-1 do
  4806. add_package(option.parapackages.NameOfIndex(j),true,true);
  4807. { add default namespaces }
  4808. tmplist:=TCmdStrList.Create;
  4809. cmditem:=TCmdStrListItem(option.paranamespaces.First);
  4810. while assigned(cmditem) do
  4811. begin
  4812. { use a temporary list cause if ";" are involved we need to reverse the
  4813. order due to how TCmdStrList behaves }
  4814. cmdstr:=cmditem.str;
  4815. repeat
  4816. j:=Pos(';',cmdstr);
  4817. if j>0 then
  4818. begin
  4819. tmplist.insert(copy(cmdstr,1,j-1));
  4820. delete(cmdstr,1,j);
  4821. end
  4822. else
  4823. tmplist.insert(cmdstr);
  4824. until j=0;
  4825. tmpcmditem:=TCmdStrListItem(tmplist.First);
  4826. while assigned(tmpcmditem) do
  4827. begin
  4828. namespacelist.insert(tmpcmditem.Str);
  4829. tmpcmditem:=TCmdStrListItem(tmpcmditem.Next);
  4830. end;
  4831. tmplist.clear;
  4832. cmditem:=TCmdStrListItem(cmditem.Next);
  4833. end;
  4834. tmplist.Free;
  4835. { add unit environment and exepath to the unit search path }
  4836. if inputfilepath<>'' then
  4837. Unitsearchpath.AddPath(inputfilepath,true);
  4838. if not disable_configfile then
  4839. begin
  4840. env:=GetEnvironmentVariable(target_info.unit_env);
  4841. if env<>'' then
  4842. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  4843. end;
  4844. {$ifdef Unix}
  4845. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  4846. if fpcdir='' then
  4847. begin
  4848. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  4849. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  4850. else
  4851. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  4852. end;
  4853. {$else unix}
  4854. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  4855. if fpcdir='' then
  4856. begin
  4857. fpcdir:=ExePath+'../';
  4858. if not(PathExists(fpcdir+'units',true)) and
  4859. not(PathExists(fpcdir+'rtl',true)) then
  4860. fpcdir:=fpcdir+'../';
  4861. end;
  4862. {$endif unix}
  4863. { first try development RTL, else use the default installation path }
  4864. if not disable_configfile then
  4865. begin
  4866. if PathExists(FpcDir+'rtl',true) then
  4867. if (tf_use_8_3 in Source_Info.Flags) or
  4868. (tf_use_8_3 in Target_Info.Flags) then
  4869. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  4870. else
  4871. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  4872. else
  4873. if (tf_use_8_3 in Source_Info.Flags) or
  4874. (tf_use_8_3 in Target_Info.Flags) then
  4875. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  4876. else
  4877. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  4878. end;
  4879. { Add exepath if the exe is not in the current dir, because that is always searched already.
  4880. Do not add it when linking on the target because then we can maybe already find
  4881. .o files that are not for the target }
  4882. if (ExePath<>cfileutl.GetCurrentDir) and
  4883. not(cs_link_on_target in init_settings.globalswitches) then
  4884. UnitSearchPath.AddPath(ExePath,false);
  4885. { Add unit dir to the object and library path }
  4886. objectsearchpath.AddList(unitsearchpath,false);
  4887. librarysearchpath.AddList(unitsearchpath,false);
  4888. {$ifdef llvm}
  4889. { default to clang }
  4890. if (option.paratargetasm=as_none) then
  4891. begin
  4892. if not(target_info.system in systems_darwin) then
  4893. option.paratargetasm:=as_clang_llvm
  4894. else
  4895. option.paratargetasm:=as_clang_llvm_darwin;
  4896. end;
  4897. {$endif llvm}
  4898. { maybe override assembler }
  4899. if (option.paratargetasm<>as_none) then
  4900. begin
  4901. if (option.paratargetasm=as_default) then
  4902. begin
  4903. if (target_info.endian<>source_info.endian) then
  4904. option.paratargetasm:=target_info.assemextern
  4905. else
  4906. option.paratargetasm:=target_info.assem;
  4907. end;
  4908. if not set_target_asm(option.paratargetasm) then
  4909. begin
  4910. if assigned(asminfos[option.paratargetasm]) then
  4911. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name)
  4912. else
  4913. Message2(option_incompatible_asm,'<invalid assembler>',target_info.name);
  4914. set_target_asm(target_info.assemextern);
  4915. Message1(option_asm_forced,target_asm.idtxt);
  4916. end;
  4917. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  4918. (option.paratargetdbg<>dbg_none) then
  4919. begin
  4920. Message1(option_confict_asm_debug,
  4921. asminfos[option.paratargetasm]^.idtxt);
  4922. option.paratargetdbg:=dbg_none;
  4923. exclude(init_settings.moduleswitches,cs_debuginfo);
  4924. end;
  4925. { Some assemblers, like clang, do not support
  4926. stabs debugging format, switch to dwardé in that case }
  4927. if (af_no_stabs in asminfos[option.paratargetasm]^.flags) and
  4928. (option.paratargetdbg=dbg_stabs) then
  4929. begin
  4930. option.paratargetdbg:=dbg_dwarf2;
  4931. end;
  4932. end;
  4933. {TOptionheck a second time as we might have changed assembler just above }
  4934. option.checkoptionscompatibility;
  4935. { maybe override debug info format }
  4936. if (option.paratargetdbg<>dbg_none) then
  4937. if not set_target_dbg(option.paratargetdbg) then
  4938. Message(option_w_unsupported_debug_format);
  4939. { switch assembler if it's binary and we got -a on the cmdline }
  4940. if (af_outputbinary in target_asm.flags) and
  4941. ((cs_asm_leave in init_settings.globalswitches) or
  4942. { if -s is passed, we shouldn't call the internal assembler }
  4943. (cs_asm_extern in init_settings.globalswitches)) or
  4944. ((option.paratargetasm=as_none) and (target_info.endian<>source_info.endian)) then
  4945. begin
  4946. if ((option.paratargetasm=as_none) and (target_info.endian<>source_info.endian)) then
  4947. begin
  4948. if not ((target_info.assem = target_info.assemextern) or (target_info.assem = as_none)) then
  4949. Message(option_switch_bin_to_src_assembler_cross_endian);
  4950. end
  4951. else
  4952. Message(option_switch_bin_to_src_assembler);
  4953. {$ifdef llvm}
  4954. if not(target_info.system in systems_darwin) then
  4955. set_target_asm(as_clang_llvm)
  4956. else
  4957. set_target_asm(as_clang_llvm_darwin);
  4958. {$else}
  4959. set_target_asm(target_info.assemextern);
  4960. {$endif}
  4961. { At least i8086 needs that for nasm and -CX
  4962. which is incompatible with internal linker }
  4963. option.checkoptionscompatibility;
  4964. end;
  4965. { Force use of external linker if there is no
  4966. internal linker or the linking is skipped }
  4967. if not(cs_link_extern in init_settings.globalswitches) and
  4968. ((target_info.link=ld_none) or
  4969. (cs_link_nolink in init_settings.globalswitches)) then
  4970. begin
  4971. include(init_settings.globalswitches,cs_link_extern);
  4972. end;
  4973. { turn off stripping if compiling with debuginfo or profile }
  4974. if (
  4975. (cs_debuginfo in init_settings.moduleswitches) or
  4976. (cs_profile in init_settings.moduleswitches)
  4977. ) and
  4978. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  4979. exclude(init_settings.globalswitches,cs_link_strip);
  4980. { choose a reasonable tls model }
  4981. if (tf_section_threadvars in target_info.flags) and (init_settings.tlsmodel=tlsm_none) then
  4982. begin
  4983. if cs_create_pic in init_settings.moduleswitches then
  4984. init_settings.tlsmodel:=tlsm_global_dynamic
  4985. else
  4986. init_settings.tlsmodel:=tlsm_local_exec;
  4987. end;
  4988. { set Mac OS X version default macros if not specified explicitly }
  4989. option.MaybeSetDefaultMacVersionMacro;
  4990. {$if defined(XTENSA) or defined(RISCV32)}
  4991. { set ESP32 or ESP8266 default SDK versions }
  4992. option.MaybeSetIdfVersionMacro;
  4993. {$endif defined(XTENSA) or defined(RISCV32)}
  4994. {$ifdef cpufpemu}
  4995. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds etc.
  4996. if fpu type not explicitly set }
  4997. if not(option.FPUSetExplicitly) and
  4998. ((target_info.system in [system_arm_wince,system_arm_gba,
  4999. system_m68k_amiga,system_m68k_atari,
  5000. system_arm_nds,system_arm_embedded,system_arm_freertos,
  5001. system_riscv32_embedded,system_riscv64_embedded,system_xtensa_linux,
  5002. system_z80_embedded,system_z80_zxspectrum,system_riscv32_freertos,
  5003. system_mipsel_ps1])
  5004. {$ifdef arm}
  5005. or (target_info.abi=abi_eabi)
  5006. {$endif arm}
  5007. )
  5008. or (init_settings.fputype=fpu_soft)
  5009. then
  5010. begin
  5011. include(init_settings.moduleswitches,cs_fp_emulation);
  5012. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  5013. init_settings.fputype:=fpu_soft;
  5014. end;
  5015. {$endif cpufpemu}
  5016. {$ifdef i386}
  5017. if target_info.system in systems_i386_default_486 then
  5018. begin
  5019. { Avoid use of MMX/CMOVcc instructions on older systems.
  5020. Some systems might not handle these instructions correctly,
  5021. Used emulators might also be problematic. PM }
  5022. if not option.CPUSetExplicitly then
  5023. init_settings.cputype:=cpu_486;
  5024. end;
  5025. case target_info.system of
  5026. system_i386_android:
  5027. begin
  5028. { set default cpu type to PentiumM for Android unless specified otherwise }
  5029. if not option.CPUSetExplicitly then
  5030. init_settings.cputype:=cpu_PentiumM;
  5031. if not option.OptCPUSetExplicitly then
  5032. init_settings.optimizecputype:=cpu_PentiumM;
  5033. { set default fpu type to SSSE3 for Android unless specified otherwise }
  5034. if not option.FPUSetExplicitly then
  5035. init_settings.fputype:=fpu_ssse3;
  5036. end;
  5037. else
  5038. ;
  5039. end;
  5040. {$endif i386}
  5041. {$ifdef xtensa}
  5042. { xtensa-linux target does not support controller setting option -Wp }
  5043. if not(option.FPUSetExplicitly) and not(target_info.system = system_xtensa_linux) then
  5044. begin
  5045. init_settings.fputype:=embedded_controllers[init_settings.controllertype].fputype;
  5046. if (init_settings.fputype=fpu_soft) then
  5047. include(init_settings.moduleswitches,cs_fp_emulation);
  5048. end;
  5049. if not(option.CPUSetExplicitly) and (target_info.system=system_xtensa_linux) then
  5050. init_settings.cputype:=cpu_lx6;
  5051. if (target_info.system in [system_xtensa_embedded,system_xtensa_freertos]) and not(option.ABISetExplicitly) then
  5052. begin
  5053. if CPUXTENSA_REGWINDOW in cpu_capabilities[init_settings.cputype] then
  5054. target_info.abi:=abi_xtensa_windowed
  5055. else
  5056. target_info.abi:=abi_xtensa_call0;
  5057. end;
  5058. {$endif xtensa}
  5059. {$ifdef arm}
  5060. case target_info.system of
  5061. system_arm_ios:
  5062. begin
  5063. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  5064. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  5065. }
  5066. if not option.CPUSetExplicitly then
  5067. init_settings.cputype:=cpu_armv7;
  5068. if not option.OptCPUSetExplicitly then
  5069. init_settings.optimizecputype:=cpu_armv7;
  5070. if not option.FPUSetExplicitly then
  5071. init_settings.fputype:=fpu_vfpv3;
  5072. end;
  5073. system_arm_android:
  5074. begin
  5075. { set default cpu type to ARMv5T for Android unless specified otherwise }
  5076. if not option.CPUSetExplicitly then
  5077. init_settings.cputype:=cpu_armv5t;
  5078. if not option.OptCPUSetExplicitly then
  5079. init_settings.optimizecputype:=cpu_armv5t;
  5080. end;
  5081. else
  5082. ;
  5083. end;
  5084. { set ABI defaults }
  5085. case target_info.abi of
  5086. abi_eabihf:
  5087. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  5088. begin
  5089. {$ifdef CPUARMV6}
  5090. { if the compiler is built for armv6, then
  5091. inherit this setting, e.g. Raspian is armhf but
  5092. only armv6, this makes rebuilds of the compiler
  5093. easier }
  5094. if not option.CPUSetExplicitly then
  5095. init_settings.cputype:=cpu_armv6;
  5096. if not option.OptCPUSetExplicitly then
  5097. init_settings.optimizecputype:=cpu_armv6;
  5098. {$else CPUARMV6}
  5099. if not option.CPUSetExplicitly then
  5100. init_settings.cputype:=cpu_armv7a;
  5101. if not option.OptCPUSetExplicitly then
  5102. init_settings.optimizecputype:=cpu_armv7a;
  5103. {$endif CPUARMV6}
  5104. { Set FPU type }
  5105. if not(option.FPUSetExplicitly) then
  5106. begin
  5107. if init_settings.cputype < cpu_armv7 then
  5108. init_settings.fputype:=fpu_vfpv2
  5109. else
  5110. init_settings.fputype:=fpu_vfpv3_d16;
  5111. end
  5112. else
  5113. begin
  5114. if (not(FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[init_settings.fputype]))
  5115. or (target_info.system = system_arm_ios) then
  5116. begin
  5117. Message(option_illegal_fpu_eabihf);
  5118. StopOptions(1);
  5119. end;
  5120. end;
  5121. end;
  5122. abi_eabi:
  5123. begin
  5124. if target_info.system=system_arm_linux then
  5125. begin
  5126. { this is what Debian uses }
  5127. if not option.CPUSetExplicitly then
  5128. init_settings.cputype:=cpu_armv4t;
  5129. if not option.OptCPUSetExplicitly then
  5130. init_settings.optimizecputype:=cpu_armv4t;
  5131. if not(option.FPUSetExplicitly) then
  5132. init_settings.fputype:=fpu_soft;
  5133. end;
  5134. end;
  5135. else
  5136. ;
  5137. end;
  5138. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  5139. begin
  5140. def_system_macro('CPUTHUMB');
  5141. if not option.FPUSetExplicitly then
  5142. init_settings.fputype:=fpu_soft;
  5143. if not(init_settings.fputype in [fpu_none,fpu_soft,fpu_libgcc]) then
  5144. Message2(option_unsupported_fpu,fputypestr[init_settings.fputype],'Thumb');
  5145. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  5146. 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';
  5147. {$else FPC_ARMAL or FPC_ARMHF}
  5148. if target_info.endian=endian_little then
  5149. 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';
  5150. {$endif FPC_ARMAL or FPC_ARMHF}
  5151. end;
  5152. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  5153. def_system_macro('CPUTHUMB2');
  5154. {$endif arm}
  5155. {$ifdef aarch64}
  5156. case target_info.system of
  5157. system_aarch64_darwin:
  5158. begin
  5159. if not option.CPUSetExplicitly then
  5160. init_settings.cputype:=cpu_armv84a;
  5161. if not option.OptCPUSetExplicitly then
  5162. init_settings.optimizecputype:=cpu_armv84a;
  5163. end;
  5164. else
  5165. ;
  5166. end;
  5167. {$endif aarch64}
  5168. {$if defined(riscv32) or defined(riscv64)}
  5169. { RISC-V defaults }
  5170. case target_info.abi of
  5171. {$ifdef RISCV32}
  5172. abi_riscv_ilp32f:
  5173. begin
  5174. if not option.CPUSetExplicitly then
  5175. init_settings.cputype:=cpu_rv32imaf;
  5176. if not option.OptCPUSetExplicitly then
  5177. init_settings.optimizecputype:=cpu_rv32imaf;
  5178. { Set FPU type }
  5179. if not(option.FPUSetExplicitly) then
  5180. init_settings.fputype:=fpu_fd
  5181. else
  5182. begin
  5183. if not (init_settings.fputype in [fpu_fd]) then
  5184. begin
  5185. Message(option_illegal_fpu_eabihf);
  5186. StopOptions(1);
  5187. end;
  5188. end;
  5189. end;
  5190. abi_riscv_ilp32d:
  5191. begin
  5192. if not option.CPUSetExplicitly then
  5193. init_settings.cputype:=cpu_rv32imafd;
  5194. if not option.OptCPUSetExplicitly then
  5195. init_settings.optimizecputype:=cpu_rv32imafd;
  5196. { Set FPU type }
  5197. if not(option.FPUSetExplicitly) then
  5198. init_settings.fputype:=fpu_fd
  5199. else
  5200. begin
  5201. if not (init_settings.fputype in [fpu_fd]) then
  5202. begin
  5203. Message(option_illegal_fpu_eabihf);
  5204. StopOptions(1);
  5205. end;
  5206. end;
  5207. end;
  5208. {$endif RISCV32}
  5209. {$ifdef RISCV64}
  5210. abi_riscv_lp64f:
  5211. begin
  5212. if not option.CPUSetExplicitly then
  5213. init_settings.cputype:=cpu_rv64imafdc;
  5214. if not option.OptCPUSetExplicitly then
  5215. init_settings.optimizecputype:=cpu_rv64imafdc;
  5216. { Set FPU type }
  5217. if not(option.FPUSetExplicitly) then
  5218. init_settings.fputype:=fpu_fd
  5219. else
  5220. begin
  5221. if not (init_settings.fputype in [fpu_fd]) then
  5222. begin
  5223. Message(option_illegal_fpu_eabihf);
  5224. StopOptions(1);
  5225. end;
  5226. end;
  5227. end;
  5228. abi_riscv_lp64d:
  5229. begin
  5230. if not option.CPUSetExplicitly then
  5231. init_settings.cputype:=cpu_rv64imafdc;
  5232. if not option.OptCPUSetExplicitly then
  5233. init_settings.optimizecputype:=cpu_rv64imafdc;
  5234. { Set FPU type }
  5235. if not(option.FPUSetExplicitly) then
  5236. init_settings.fputype:=fpu_fd
  5237. else
  5238. begin
  5239. if not (init_settings.fputype in [fpu_fd]) then
  5240. begin
  5241. Message(option_illegal_fpu_eabihf);
  5242. StopOptions(1);
  5243. end;
  5244. end;
  5245. end;
  5246. abi_riscv_lp64q:
  5247. begin
  5248. if not option.CPUSetExplicitly then
  5249. init_settings.cputype:=cpu_rv64imafdc;
  5250. if not option.OptCPUSetExplicitly then
  5251. init_settings.optimizecputype:=cpu_rv64imafdc;
  5252. { Set FPU type }
  5253. if not(option.FPUSetExplicitly) then
  5254. init_settings.fputype:=fpu_fd
  5255. else
  5256. begin
  5257. if not (init_settings.fputype in [fpu_fd]) then
  5258. begin
  5259. Message(option_illegal_fpu_eabihf);
  5260. StopOptions(1);
  5261. end;
  5262. end;
  5263. end;
  5264. {$endif RISCV64}
  5265. else
  5266. ;
  5267. end;
  5268. { check if the fpu type requires the F and D extension }
  5269. 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
  5270. Message2(option_unsupported_fpu,fputypestr[init_settings.fputype],cputypestr[init_settings.cputype]);
  5271. {$endif defined(riscv32) or defined(riscv64)}
  5272. {$ifdef jvm}
  5273. { set default CPU type to Dalvik when targeting Android }
  5274. if target_info.system=system_jvm_android32 then
  5275. begin
  5276. if not option.CPUSetExplicitly then
  5277. init_settings.cputype:=cpu_dalvik;
  5278. end;
  5279. {$endif jvm}
  5280. {$ifdef llvm}
  5281. { standard extension for llvm bitcode files }
  5282. target_info.asmext:='.ll';
  5283. { don't generate dwarf cfi, llvm will do that }
  5284. exclude(target_info.flags,tf_needs_dwarf_cfi);
  5285. {$endif llvm}
  5286. {$ifdef mipsel}
  5287. case target_info.system of
  5288. system_mipsel_android:
  5289. begin
  5290. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  5291. if not option.CPUSetExplicitly then
  5292. init_settings.cputype:=cpu_mips32;
  5293. if not option.OptCPUSetExplicitly then
  5294. init_settings.optimizecputype:=cpu_mips32;
  5295. if not option.FPUSetExplicitly then
  5296. init_settings.fputype:=fpu_mips2;
  5297. end;
  5298. system_mipsel_embedded:
  5299. begin
  5300. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  5301. if not option.CPUSetExplicitly then
  5302. init_settings.cputype:=cpu_pic32mx;
  5303. if not option.OptCPUSetExplicitly then
  5304. init_settings.optimizecputype:=cpu_pic32mx;
  5305. if not option.FPUSetExplicitly then
  5306. init_settings.fputype:=fpu_soft;
  5307. end;
  5308. system_mipsel_PS1:
  5309. begin
  5310. {
  5311. init_settings.optimizerswitches:=[
  5312. cs_opt_stackframe,
  5313. cs_opt_size, // makes smaller
  5314. cs_opt_uncertain,
  5315. cs_opt_peephole,
  5316. cs_opt_tailrecursion,
  5317. cs_opt_nodecse, // makes smaller - don't sets vars to 0
  5318. cs_opt_nodedfa,
  5319. cs_opt_loopstrength,
  5320. cs_opt_reorder_fields,
  5321. cs_opt_dead_values, // makes smaller
  5322. cs_opt_remove_empty_proc, // makes smaller
  5323. cs_opt_dead_store_eliminate,
  5324. cs_opt_forcenostackframe,
  5325. cs_opt_unused_para, // makes smaller
  5326. cs_opt_consts];
  5327. // dont work: cs_opt_regvar, cs_opt_constant_propagate
  5328. // dont compile: cs_opt_scheduler
  5329. // makes larger: cs_opt_autoinline
  5330. }
  5331. init_settings.optimizerswitches:=[];
  5332. init_settings.debugswitches:= [];
  5333. { set default cpu type to MIPS1 with SoftFPU }
  5334. if not option.CPUSetExplicitly then
  5335. init_settings.cputype:=cpu_mips1;
  5336. if not option.OptCPUSetExplicitly then
  5337. init_settings.optimizecputype:=cpu_mips1;
  5338. if not option.FPUSetExplicitly then
  5339. begin
  5340. include(init_settings.moduleswitches,cs_fp_emulation);
  5341. init_settings.fputype:=fpu_soft;
  5342. end;
  5343. end;
  5344. else
  5345. ;
  5346. end;
  5347. {$endif mipsel}
  5348. {$ifdef m68k}
  5349. if init_settings.cputype in cpu_coldfire then
  5350. def_system_macro('CPUCOLDFIRE');
  5351. case target_info.system of
  5352. system_m68k_linux,
  5353. system_m68k_netbsd:
  5354. begin
  5355. if not (option.FPUSetExplicitly) and
  5356. not (init_settings.cputype in cpu_coldfire) then
  5357. begin
  5358. { enable HW FPU for UNIX by default, but only for
  5359. original 68k, not Coldfire }
  5360. exclude(init_settings.moduleswitches,cs_fp_emulation);
  5361. init_settings.fputype:=fpu_68881;
  5362. end;
  5363. end;
  5364. system_m68k_atari,
  5365. system_m68k_sinclairql,
  5366. system_m68k_human68k:
  5367. begin
  5368. if not option.CPUSetExplicitly then
  5369. init_settings.cputype:=cpu_mc68000;
  5370. end;
  5371. system_m68k_palmos:
  5372. begin
  5373. if not option.CPUSetExplicitly then
  5374. init_settings.cputype:=cpu_mc68000;
  5375. if not (option.FPUSetExplicitly) then
  5376. begin
  5377. { No FPU for PalmOS by default }
  5378. exclude(init_settings.moduleswitches,cs_fp_emulation);
  5379. init_settings.fputype:=fpu_none;
  5380. end;
  5381. end;
  5382. else
  5383. ;
  5384. end;
  5385. {$endif m68k}
  5386. {$ifdef wasm}
  5387. { if no explicit exception handling mode is set for WebAssembly, select branchful exceptions }
  5388. if init_settings.targetswitches*[ts_wasm_no_exceptions,ts_wasm_native_exnref_exceptions,ts_wasm_native_legacy_exceptions,ts_wasm_bf_exceptions]=[] then
  5389. begin
  5390. def_system_macro(TargetSwitchStr[ts_wasm_bf_exceptions].define);
  5391. include(init_settings.targetswitches,ts_wasm_bf_exceptions);
  5392. end;
  5393. {$endif wasm}
  5394. {$if defined(loongarch64)}
  5395. { LoongArch defaults }
  5396. if (target_info.abi = abi_loongarch_lp64d) then
  5397. begin
  5398. init_settings.cputype:=cpu_3a;
  5399. init_settings.fputype:=fpu_fd;
  5400. end;
  5401. {$endif defined(loongarch64)}
  5402. { now we can define cpu and fpu type }
  5403. def_cpu_macros;
  5404. set_endianess_macros;
  5405. { Use init_settings cpu type for asm cpu type,
  5406. if asmcputype is cpu_none,
  5407. at least as long as there is no explicit
  5408. option to set it on command line PM }
  5409. if init_settings.asmcputype = cpu_none then
  5410. init_settings.asmcputype:=init_settings.cputype;
  5411. {$if defined(cpucapabilities)}
  5412. for cpuflag:=low(cpuflag) to high(cpuflag) do
  5413. begin
  5414. str(cpuflag,hs);
  5415. if cpuflag in cpu_capabilities[init_settings.cputype] then
  5416. def_system_macro(hs)
  5417. else
  5418. undef_system_macro(hs);
  5419. end;
  5420. {$endif defined(cpucapabilities)}
  5421. {$if defined(fpucapabilities)}
  5422. for fpuflag:=low(fpuflag) to high(fpuflag) do
  5423. begin
  5424. str(fpuflag,hs);
  5425. if fpuflag in fpu_capabilities[init_settings.fputype] then
  5426. def_system_macro(hs)
  5427. else
  5428. undef_system_macro(hs);
  5429. end;
  5430. {$endif defined(fpucapabilities)}
  5431. if init_settings.fputype<>fpu_none then
  5432. begin
  5433. {$if defined(i386) or defined(i8086)}
  5434. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  5435. {$endif}
  5436. def_system_macro('FPC_HAS_TYPE_SINGLE');
  5437. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  5438. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  5439. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  5440. {$endif}
  5441. {$if defined(m68k)}
  5442. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  5443. {$endif}
  5444. {$ifdef x86_64}
  5445. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  5446. { normally, win64 doesn't support the legacy fpu }
  5447. if target_info.system=system_x86_64_win64 then
  5448. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  5449. else
  5450. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  5451. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  5452. {$endif}
  5453. end;
  5454. { Enable now for testing }
  5455. {$ifndef DISABLE_TLS_DIRECTORY}
  5456. if target_info.system in systems_windows then
  5457. def_system_macro('FPC_USE_TLS_DIRECTORY');
  5458. {$endif not DISABLE_TLS_DIRECTORY}
  5459. {$ifndef DISABLE_WIN64_SEH}
  5460. if target_info.system=system_x86_64_win64 then
  5461. def_system_macro('FPC_USE_WIN64_SEH');
  5462. {$endif DISABLE_WIN64_SEH}
  5463. {$ifndef DISABLE_WIN32_SEH}
  5464. if target_info.system=system_i386_win32 then
  5465. def_system_macro('FPC_USE_WIN32_SEH');
  5466. {$endif not DISABLE_WIN32_SEH}
  5467. {$ifdef ARM}
  5468. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  5469. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  5470. not(cs_fp_emulation in init_settings.moduleswitches) then
  5471. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  5472. {$endif ARM}
  5473. { inline bsf/bsr implementation }
  5474. {$if defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64)}
  5475. def_system_macro('FPC_HAS_INTERNAL_BSF');
  5476. def_system_macro('FPC_HAS_INTERNAL_BSR');
  5477. {$endif}
  5478. { hardware FMA support }
  5479. {$if defined(i386) or defined(x86_64)}
  5480. if (fpu_capabilities[current_settings.fputype]*[FPUX86_HAS_FMA,FPUX86_HAS_FMA4])<>[] then
  5481. begin
  5482. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  5483. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  5484. end;
  5485. {$endif defined(i386) or defined(x86_64)}
  5486. {$if defined(arm)}
  5487. { it is determined during system unit compilation if clz is used for bsf or not,
  5488. this is not perfect but the current implementation bsf/bsr does not allow another
  5489. solution }
  5490. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  5491. ((init_settings.instructionset=is_arm) or
  5492. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  5493. begin
  5494. def_system_macro('FPC_HAS_INTERNAL_BSR');
  5495. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  5496. def_system_macro('FPC_HAS_INTERNAL_BSF');
  5497. end;
  5498. {$endif}
  5499. {$if defined(xtensa)}
  5500. { it is determined during system unit compilation if nsau is used for bsr or not,
  5501. this is not perfect but the current implementation bsf/bsr does not allow another
  5502. solution }
  5503. if CPUXTENSA_HAS_NSAx in cpu_capabilities[init_settings.cputype] then
  5504. begin
  5505. def_system_macro('FPC_HAS_INTERNAL_BSR');
  5506. end;
  5507. {$endif}
  5508. {$if defined(powerpc64)}
  5509. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  5510. big endian (unless specified otherwise). As the gcc man page says:
  5511. "Overriding the default ABI requires special system support and is
  5512. likely to fail in spectacular ways" }
  5513. if not option.ABISetExplicitly then
  5514. begin
  5515. if (target_info.abi=abi_powerpc_sysv) and
  5516. (target_info.endian=endian_little) then
  5517. target_info.abi:=abi_powerpc_elfv2
  5518. else
  5519. if (target_info.abi=abi_powerpc_elfv2) and
  5520. (target_info.endian=endian_big) then
  5521. target_info.abi:=abi_powerpc_sysv
  5522. end;
  5523. {$endif}
  5524. {$if defined(powerpc) or defined(powerpc64)}
  5525. { define _CALL_ELF symbol like gcc }
  5526. case target_info.abi of
  5527. abi_powerpc_sysv:
  5528. set_system_compvar('_CALL_ELF','1');
  5529. abi_powerpc_elfv2:
  5530. set_system_compvar('_CALL_ELF','2');
  5531. else
  5532. ;
  5533. end;
  5534. {$endif}
  5535. { Section smartlinking conflicts with import sections on Windows }
  5536. if GenerateImportSection and
  5537. (target_info.system in [system_i386_win32,system_x86_64_win64,system_aarch64_win64]) then
  5538. exclude(target_info.flags,tf_smartlink_sections);
  5539. if not option.LinkTypeSetExplicitly then
  5540. set_default_link_type;
  5541. if source_info.endian<>target_info.endian then
  5542. begin
  5543. if option.LinkInternSetExplicitly then
  5544. Message(link_w_unsupported_cross_endian_internal_linker)
  5545. else
  5546. include(init_settings.globalswitches,cs_link_extern);
  5547. end;
  5548. { Default alignment settings,
  5549. 1. load the defaults for the target
  5550. 2. adapt defaults specifically for the target
  5551. 3. override with generic optimizer setting (little size)
  5552. 4. override with the user specified -Oa }
  5553. UpdateAlignment(init_settings.alignment,target_info.alignment);
  5554. {$ifdef arm}
  5555. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  5556. begin
  5557. init_settings.alignment.procalign:=2;
  5558. init_settings.alignment.jumpalign:=2;
  5559. init_settings.alignment.coalescealign:=2;
  5560. init_settings.alignment.loopalign:=2;
  5561. end;
  5562. {$endif arm}
  5563. if (cs_opt_size in init_settings.optimizerswitches) then
  5564. begin
  5565. init_settings.alignment.procalign:=1;
  5566. init_settings.alignment.jumpalign:=1;
  5567. init_settings.alignment.coalescealign:=1;
  5568. init_settings.alignment.loopalign:=1;
  5569. {$ifdef x86}
  5570. { constalignmax=1 keeps the executable and thus the memory foot print small but
  5571. all processors except x86 are really hurt by this or might even crash }
  5572. init_settings.alignment.constalignmax:=1;
  5573. {$endif x86}
  5574. end;
  5575. UpdateAlignment(init_settings.alignment,option.paraalignment);
  5576. set_system_macro('FPC_VERSION',version_nr);
  5577. set_system_macro('FPC_RELEASE',release_nr);
  5578. set_system_macro('FPC_PATCH',patch_nr);
  5579. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  5580. if target_info.system in systems_indirect_entry_information then
  5581. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  5582. if not (tf_winlikewidestring in target_info.flags) then
  5583. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  5584. if tf_supports_packages in target_info.flags then
  5585. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  5586. if target_info.system in systems_indirect_var_imports then
  5587. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  5588. if cs_compilesystem in init_settings.moduleswitches then
  5589. for i:=low(tfeature) to high(tfeature) do
  5590. if i in features then
  5591. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  5592. {$push}
  5593. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  5594. if ControllerSupport and (target_info.system in (systems_embedded+systems_freertos)) and
  5595. (init_settings.controllertype<>ct_none) then
  5596. begin
  5597. with embedded_controllers[init_settings.controllertype] do
  5598. begin
  5599. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  5600. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  5601. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  5602. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  5603. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  5604. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  5605. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  5606. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  5607. end;
  5608. end;
  5609. {$pop}
  5610. { as stackalign is not part of the alignment record, we do not need to define the others alignments for symmetry yet }
  5611. set_system_macro('FPC_STACKALIGNMENT',tostr(target_info.stackalign));
  5612. option.free;
  5613. Option:=nil;
  5614. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl{$ifdef z80},pocall_stdcall{$endif}];
  5615. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  5616. if (tf_safecall_clearstack in target_info.flags) then
  5617. begin
  5618. include (cdecl_pocalls, pocall_safecall);
  5619. include (clearstack_pocalls, pocall_safecall)
  5620. end;
  5621. end;
  5622. initialization
  5623. coption:=toption;
  5624. finalization
  5625. if assigned(option) then
  5626. option.free;
  5627. end.