options.pas 178 KB

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