options.pas 174 KB

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