options.pas 173 KB

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