options.pas 178 KB

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