options.pas 181 KB

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