options.pas 170 KB

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