options.pas 183 KB

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