options.pas 172 KB

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