options.pas 175 KB

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