options.pas 186 KB

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