options.pas 178 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263
  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. if (pos('+',s)<>0) or (pos('-',s)<>0) then
  1620. begin
  1621. deletepos:=min(pos('+',s),pos('-',s));
  1622. extrasettings:=Copy(s,Pos('+',s),Length(s));
  1623. Delete(s,Pos('+',s),Length(s));
  1624. end
  1625. else
  1626. extrasettings:='';
  1627. {$endif cpucapabilities}
  1628. if not(Setcputype(s,init_settings)) then
  1629. IllegalPara(opt);
  1630. {$ifdef cpucapabilities}
  1631. while extrasettings<>'' do
  1632. begin
  1633. Delete(extrasettings,1,1);
  1634. includecapability:=true;
  1635. if Pos('+',extrasettings)<>0 then
  1636. begin
  1637. s:=Copy(extrasettings,1,Pos('+',extrasettings)-1);
  1638. Delete(extrasettings,1,Pos('+',extrasettings)-1);
  1639. end
  1640. else if Pos('-',extrasettings)<>0 then
  1641. begin
  1642. s:=Copy(extrasettings,1,Pos('+',extrasettings)-1);
  1643. Delete(extrasettings,1,Pos('+',extrasettings)-1);
  1644. includecapability:=false;
  1645. end
  1646. else
  1647. begin
  1648. s:=extrasettings;
  1649. extrasettings:='';
  1650. end;
  1651. for cf in tcpuflags do
  1652. begin
  1653. Str(cf,cpuflagsstr);
  1654. { expect that the cpuflagsstr i.e. the enum as well contains _HAS_ }
  1655. if Pos('_HAS_',cpuflagsstr)<>0 then
  1656. { get rid of prefix including _HAS_ }
  1657. Delete(cpuflagsstr,1,Pos('_HAS_',cpuflagsstr)+4)
  1658. else
  1659. Internalerror(2021110601);
  1660. if s=cpuflagsstr then
  1661. begin
  1662. if includecapability then
  1663. Include(cpu_capabilities[init_settings.cputype],cf)
  1664. else
  1665. Exclude(cpu_capabilities[init_settings.cputype],cf);
  1666. s:='';
  1667. break;
  1668. end;
  1669. end;
  1670. if s<>'' then
  1671. IllegalPara(opt);
  1672. end;
  1673. {$endif cpucapabilities}
  1674. CPUSetExplicitly:=true;
  1675. break;
  1676. end;
  1677. 'P':
  1678. begin
  1679. delete(more,1,1);
  1680. case upper(copy(more,1,pos('=',more)-1)) of
  1681. 'PACKSET':
  1682. begin
  1683. delete(more,1,pos('=',more));
  1684. case more of
  1685. '0','DEFAULT','NORMAL':
  1686. init_settings.setalloc:=0;
  1687. '1','2','4','8':
  1688. init_settings.setalloc:=StrToInt(more);
  1689. else
  1690. IllegalPara(opt);
  1691. end
  1692. end;
  1693. 'PACKENUM':
  1694. begin
  1695. delete(more,1,pos('=',more));
  1696. case more of
  1697. '0','DEFAULT','NORMAL':
  1698. init_settings.packenum:=4;
  1699. '1','2','4':
  1700. init_settings.packenum:=StrToInt(more);
  1701. else
  1702. IllegalPara(opt);
  1703. end;
  1704. end;
  1705. 'PACKRECORD':
  1706. begin
  1707. delete(more,1,pos('=',more));
  1708. case more of
  1709. '0','DEFAULT','NORMAL':
  1710. init_settings.packrecords:=default_settings.packrecords;
  1711. '1','2','4','8','16','32':
  1712. init_settings.packrecords:=StrToInt(more);
  1713. else
  1714. IllegalPara(opt);
  1715. end;
  1716. end
  1717. else
  1718. IllegalPara(opt);
  1719. end;
  1720. end;
  1721. 'r' :
  1722. If UnsetBool(More, j, opt, false) then
  1723. exclude(init_settings.localswitches,cs_check_range)
  1724. Else
  1725. include(init_settings.localswitches,cs_check_range);
  1726. 'R' :
  1727. If UnsetBool(More, j, opt, false) then
  1728. begin
  1729. exclude(init_settings.localswitches,cs_check_range);
  1730. exclude(init_settings.localswitches,cs_check_object);
  1731. end
  1732. Else
  1733. begin
  1734. include(init_settings.localswitches,cs_check_range);
  1735. include(init_settings.localswitches,cs_check_object);
  1736. end;
  1737. 's' :
  1738. begin
  1739. val(copy(more,j+1,length(more)-j),stacksize,code);
  1740. if (code<>0)
  1741. {$ifdef cpu16bitaddr}
  1742. or (stacksize>=65521)
  1743. {$else cpu16bitaddr}
  1744. or (stacksize>=67107840)
  1745. {$endif cpu16bitaddr}
  1746. or (stacksize<1024) then
  1747. IllegalPara(opt);
  1748. break;
  1749. end;
  1750. 't' :
  1751. If UnsetBool(More, j, opt, false) then
  1752. exclude(init_settings.localswitches,cs_check_stack)
  1753. Else
  1754. include(init_settings.localswitches,cs_check_stack);
  1755. 'D' :
  1756. If UnsetBool(More, j, opt, false) then
  1757. exclude(init_settings.moduleswitches,cs_create_dynamic)
  1758. Else
  1759. include(init_settings.moduleswitches,cs_create_dynamic);
  1760. 'X' :
  1761. If UnsetBool(More, j, opt, false) then
  1762. exclude(init_settings.moduleswitches,cs_create_smart)
  1763. Else
  1764. include(init_settings.moduleswitches,cs_create_smart);
  1765. 'T' :
  1766. begin
  1767. if not UpdateTargetSwitchStr(copy(more,j+1,length(more)),init_settings.targetswitches,true) then
  1768. IllegalPara(opt);
  1769. break;
  1770. end;
  1771. 'v' :
  1772. If target_info.system in systems_jvm then
  1773. If UnsetBool(More, j, opt, false) then
  1774. exclude(init_settings.localswitches,cs_check_var_copyout)
  1775. Else
  1776. include(init_settings.localswitches,cs_check_var_copyout)
  1777. else
  1778. IllegalPara(opt);
  1779. 'V':
  1780. begin
  1781. s:=upper(copy(more,j+1,length(more)-j));
  1782. if s='GLOBAL-DYNAMIC' then
  1783. init_settings.tlsmodel:=tlsm_global_dynamic
  1784. else if s='LOCAL-EXEC' then
  1785. init_settings.tlsmodel:=tlsm_local_exec
  1786. else
  1787. IllegalPara(opt);
  1788. break;
  1789. end;
  1790. else
  1791. IllegalPara(opt);
  1792. end;
  1793. inc(j);
  1794. end;
  1795. end;
  1796. 'd' :
  1797. begin
  1798. l:=Pos(':=',more);
  1799. if l>0 then
  1800. hs:=copy(more,1,l-1)
  1801. else
  1802. hs:=more;
  1803. if (not is_identifier(hs)) then
  1804. begin
  1805. if hs='' then
  1806. Message1(option_missing_arg,'-d')
  1807. else
  1808. Message1(option_malformed_para,opt);
  1809. StopOptions(1);
  1810. end;
  1811. if l>0 then
  1812. begin
  1813. if cs_support_macro in init_settings.moduleswitches then
  1814. set_system_macro(hs,Copy(more,l+2,255))
  1815. else
  1816. set_system_compvar(hs,Copy(more,l+2,255));
  1817. end
  1818. else
  1819. def_system_macro(hs);
  1820. end;
  1821. 'D' :
  1822. begin
  1823. j:=1;
  1824. while j<=length(more) do
  1825. begin
  1826. case more[j] of
  1827. 'd' :
  1828. begin
  1829. include(init_settings.globalswitches,cs_link_deffile);
  1830. description:=Copy(more,j+1,255);
  1831. break;
  1832. end;
  1833. 'D' :
  1834. begin
  1835. datestr:=Copy(more,j+1,255);
  1836. break;
  1837. end;
  1838. 'T' :
  1839. begin
  1840. timestr:=Copy(more,j+1,255);
  1841. break;
  1842. end;
  1843. 'v' :
  1844. begin
  1845. include(init_settings.globalswitches,cs_link_deffile);
  1846. dllversion:=Copy(more,j+1,255);
  1847. l:=pos('.',dllversion);
  1848. dllminor:=0;
  1849. error:=0;
  1850. if l>0 then
  1851. begin
  1852. val(copy(dllversion,l+1,255),minor,error);
  1853. if (error=0) and
  1854. (minor>=0) and (minor<=$ffff) then
  1855. dllminor:=minor
  1856. else
  1857. if error=0 then
  1858. error:=1;
  1859. end;
  1860. if l=0 then
  1861. l:=256;
  1862. dllmajor:=1;
  1863. major:=0;
  1864. if error=0 then
  1865. val(copy(dllversion,1,l-1),major,error);
  1866. if (error=0) and (major>=0) and (major<=$ffff) then
  1867. dllmajor:=major
  1868. else
  1869. if error=0 then
  1870. error:=1;
  1871. if error<>0 then
  1872. Message1(scan_w_wrong_version_ignored,dllversion);
  1873. break;
  1874. end;
  1875. 'w' :
  1876. begin
  1877. include(init_settings.globalswitches,cs_link_deffile);
  1878. usewindowapi:=true;
  1879. end;
  1880. '-' :
  1881. begin
  1882. exclude(init_settings.globalswitches,cs_link_deffile);
  1883. usewindowapi:=false;
  1884. end;
  1885. else
  1886. IllegalPara(opt);
  1887. end;
  1888. inc(j);
  1889. end;
  1890. end;
  1891. 'e' :
  1892. exepath:=FixPath(More,true);
  1893. 'E' :
  1894. begin
  1895. if UnsetBool(More, 0, opt, true) then
  1896. exclude(init_settings.globalswitches,cs_link_nolink)
  1897. else
  1898. include(init_settings.globalswitches,cs_link_nolink);
  1899. end;
  1900. 'f' :
  1901. begin
  1902. if more='PIC' then
  1903. begin
  1904. if tf_no_pic_supported in target_info.flags then
  1905. message(scan_w_pic_ignored)
  1906. else
  1907. include(init_settings.moduleswitches,cs_create_pic)
  1908. end
  1909. else
  1910. IllegalPara(opt);
  1911. end;
  1912. 'F' :
  1913. begin
  1914. if more='' then
  1915. IllegalPara(opt);
  1916. c:=more[1];
  1917. Delete(more,1,1);
  1918. DefaultReplacements(More);
  1919. case c of
  1920. 'a' :
  1921. autoloadunits:=more;
  1922. 'c' :
  1923. begin
  1924. { if we first specify that the system code page should be
  1925. used and then explicitly specify a code page, unset the
  1926. flag that we're using the system code page again }
  1927. SetCompileModeSwitch('SYSTEMCODEPAGE-',true);
  1928. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  1929. init_settings.sourcecodepage:=CP_UTF8
  1930. else if not(cpavailable(more)) then
  1931. Message1(option_code_page_not_available,more)
  1932. else
  1933. init_settings.sourcecodepage:=codepagebyname(more);
  1934. include(init_settings.moduleswitches,cs_explicit_codepage);
  1935. end;
  1936. 'C' :
  1937. RCCompiler:=More;
  1938. 'd' :
  1939. if UnsetBool(more, 0, opt, true) then
  1940. init_settings.disabledircache:=false
  1941. else
  1942. init_settings.disabledircache:=true;
  1943. 'D' :
  1944. utilsdirectory:=FixPath(More,true);
  1945. 'e' :
  1946. SetRedirectFile(More);
  1947. 'E' :
  1948. OutputExeDir:=FixPath(More,true);
  1949. 'f' :
  1950. if (target_info.system in systems_darwin) then
  1951. if ispara then
  1952. ParaFrameworkPath.AddPath(More,false)
  1953. else
  1954. frameworksearchpath.AddPath(More,true)
  1955. {$ifdef XTENSA}
  1956. else if (target_info.system=system_xtensa_freertos) then
  1957. idfpath:=FixPath(More,true)
  1958. {$endif XTENSA}
  1959. else
  1960. IllegalPara(opt);
  1961. 'F' :
  1962. RCForceFPCRes:=true;
  1963. 'i' :
  1964. begin
  1965. if ispara then
  1966. ParaIncludePath.AddPath(More,false)
  1967. else
  1968. includesearchpath.AddPath(More,true);
  1969. end;
  1970. 'm' :
  1971. begin
  1972. s:=ExtractFileDir(more);
  1973. if TryStrToInt(ExtractFileName(more),j) then
  1974. begin
  1975. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  1976. if assigned(unicodemapping) then
  1977. registermapping(unicodemapping)
  1978. else
  1979. IllegalPara(opt);
  1980. end
  1981. else
  1982. IllegalPara(opt);
  1983. end;
  1984. 'M' :
  1985. unicodepath:=FixPath(More,true);
  1986. 'g' :
  1987. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  1988. 'l' :
  1989. begin
  1990. if ispara then
  1991. ParaLibraryPath.AddLibraryPath(sysrootpath,More,false)
  1992. else
  1993. LibrarySearchPath.AddLibraryPath(sysrootpath,More,true)
  1994. end;
  1995. 'L' :
  1996. begin
  1997. if More<>'' then
  1998. ParaDynamicLinker:=More
  1999. else
  2000. IllegalPara(opt);
  2001. end;
  2002. 'N' :
  2003. begin
  2004. if more<>'' then
  2005. paranamespaces.insert(more)
  2006. else
  2007. illegalpara(opt);
  2008. end;
  2009. 'o' :
  2010. begin
  2011. if ispara then
  2012. ParaObjectPath.AddPath(More,false)
  2013. else
  2014. ObjectSearchPath.AddPath(More,true);
  2015. end;
  2016. 'P' :
  2017. begin
  2018. if ispara then
  2019. parapackages.add(more,nil)
  2020. else
  2021. add_package(more,true,true);
  2022. end;
  2023. 'p' :
  2024. begin
  2025. if ispara then
  2026. parapackagepath.AddPath(More,false)
  2027. else
  2028. packagesearchpath.AddPath(More,true);
  2029. end;
  2030. 'r' :
  2031. Msgfilename:=More;
  2032. 'R' :
  2033. ResCompiler:=More;
  2034. 'u' :
  2035. begin
  2036. if ispara then
  2037. ParaUnitPath.AddPath(More,false)
  2038. else
  2039. unitsearchpath.AddPath(More,true);
  2040. end;
  2041. 'U' :
  2042. OutputUnitDir:=FixPath(More,true);
  2043. 'W',
  2044. 'w':
  2045. begin
  2046. if More<>'' then
  2047. begin
  2048. DefaultReplacements(More);
  2049. D:=ExtractFilePath(More);
  2050. if (D<>'') then
  2051. D:=FixPath(D,True);
  2052. D:=D+ExtractFileName(More);
  2053. if (c='W') then
  2054. WpoFeedbackOutput:=D
  2055. else
  2056. WpoFeedbackInput:=D;
  2057. end
  2058. else
  2059. IllegalPara(opt);
  2060. end;
  2061. else
  2062. IllegalPara(opt);
  2063. end;
  2064. end;
  2065. 'g' :
  2066. begin
  2067. if UnsetBool(More, 0, opt, false) then
  2068. begin
  2069. exclude(init_settings.moduleswitches,cs_debuginfo);
  2070. exclude(init_settings.globalswitches,cs_use_heaptrc);
  2071. exclude(init_settings.globalswitches,cs_use_lineinfo);
  2072. exclude(init_settings.localswitches,cs_checkpointer);
  2073. paratargetdbg:=dbg_none;
  2074. localvartrashing := -1;
  2075. end
  2076. else
  2077. begin
  2078. include(init_settings.moduleswitches,cs_debuginfo);
  2079. if paratargetdbg=dbg_none then
  2080. paratargetdbg:=target_info.dbg;
  2081. end;
  2082. if not RelocSectionSetExplicitly then
  2083. RelocSection:=false;
  2084. j:=1;
  2085. while j<=length(more) do
  2086. begin
  2087. case more[j] of
  2088. 'c' :
  2089. begin
  2090. if UnsetBool(More, j, opt, false) then
  2091. exclude(init_settings.localswitches,cs_checkpointer)
  2092. else if (target_info.system in systems_support_checkpointer) then
  2093. begin
  2094. if do_release then
  2095. Message(option_gc_incompatible_with_release_flag)
  2096. else
  2097. include(init_settings.localswitches,cs_checkpointer);
  2098. end
  2099. else
  2100. UnsupportedPara('-gc');
  2101. end;
  2102. 'h' :
  2103. begin
  2104. if UnsetBool(More, j, opt, false) then
  2105. exclude(init_settings.globalswitches,cs_use_heaptrc)
  2106. else
  2107. begin
  2108. if cs_gdb_valgrind in init_settings.globalswitches then
  2109. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  2110. include(init_settings.globalswitches,cs_use_heaptrc);
  2111. end;
  2112. end;
  2113. 'l' :
  2114. begin
  2115. if UnsetBool(More, j, opt, false) then
  2116. exclude(init_settings.globalswitches,cs_use_lineinfo)
  2117. else
  2118. include(init_settings.globalswitches,cs_use_lineinfo);
  2119. end;
  2120. 'm' :
  2121. begin
  2122. paratargetdbg:=dbg_codeview;
  2123. end;
  2124. 'o' :
  2125. begin
  2126. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  2127. IllegalPara(opt);
  2128. break;
  2129. end;
  2130. 'p' :
  2131. begin
  2132. if UnsetBool(More, j, opt, false) then
  2133. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  2134. else
  2135. include(init_settings.globalswitches,cs_stabs_preservecase);
  2136. end;
  2137. 's' :
  2138. begin
  2139. paratargetdbg:=dbg_stabs;
  2140. end;
  2141. 't' :
  2142. begin
  2143. if UnsetBool(More, j, opt, false) then
  2144. localvartrashing := -1
  2145. else
  2146. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  2147. end;
  2148. 'v' :
  2149. begin
  2150. if UnsetBool(More, j, opt, false) then
  2151. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  2152. else
  2153. begin
  2154. if cs_use_heaptrc in init_settings.globalswitches then
  2155. Message2(option_valgrind_heaptrc_mismatch,'-gh', '-gv');
  2156. include(init_settings.globalswitches,cs_gdb_valgrind);
  2157. end;
  2158. end;
  2159. 'w' :
  2160. begin
  2161. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  2162. begin
  2163. case more[j+1] of
  2164. '2': paratargetdbg:=dbg_dwarf2;
  2165. '3': paratargetdbg:=dbg_dwarf3;
  2166. '4': paratargetdbg:=dbg_dwarf4;
  2167. end;
  2168. inc(j);
  2169. end
  2170. else
  2171. paratargetdbg:=dbg_dwarf2;
  2172. end;
  2173. else
  2174. IllegalPara(opt);
  2175. end;
  2176. inc(j);
  2177. end;
  2178. end;
  2179. 'h' :
  2180. begin
  2181. NoPressEnter:=true;
  2182. if (More <> '') and (More [1] = 'F') then
  2183. begin
  2184. FPCHelpLines := true;
  2185. Delete (More, 1, 1);
  2186. FPCBinaryPath := More;
  2187. end;
  2188. WriteHelpPages;
  2189. end;
  2190. 'i' :
  2191. begin
  2192. if (More='') or
  2193. (More [1] in ['a', 'b', 'c', 'f', 'i', 'm', 'o', 'r', 't', 'u', 'w', 'x']) then
  2194. WriteInfo (More)
  2195. else
  2196. QuickInfo:=QuickInfo+More;
  2197. end;
  2198. 'I' :
  2199. begin
  2200. if ispara then
  2201. ParaIncludePath.AddPath(More,false)
  2202. else
  2203. includesearchpath.AddPath(More,false);
  2204. end;
  2205. 'k' :
  2206. begin
  2207. if more<>'' then
  2208. ParaLinkOptions:=ParaLinkOptions+' '+More
  2209. else
  2210. IllegalPara(opt);
  2211. end;
  2212. 'l' :
  2213. ParaLogo:=not UnSetBool(more,0,opt,true);
  2214. {$ifdef PREPROCWRITE}
  2215. 'm' :
  2216. parapreprocess:=not UnSetBool(more,0,opt,true);
  2217. {$endif PREPROCWRITE}
  2218. 'M' :
  2219. begin
  2220. more:=Upper(more);
  2221. if not SetCompileMode(more, true) then
  2222. if not SetCompileModeSwitch(more, true) then
  2223. IllegalPara(opt);
  2224. end;
  2225. 'n' :
  2226. begin
  2227. if More='' then
  2228. disable_configfile:=true
  2229. else
  2230. IllegalPara(opt);
  2231. end;
  2232. 'o' :
  2233. begin
  2234. if More<>'' then
  2235. begin
  2236. DefaultReplacements(More);
  2237. D:=ExtractFilePath(More);
  2238. if (D<>'') then
  2239. OutputExeDir:=FixPath(D,True);
  2240. OutputFileName:=ExtractFileName(More);
  2241. end
  2242. else
  2243. IllegalPara(opt);
  2244. end;
  2245. 'O' :
  2246. begin
  2247. j:=1;
  2248. while j<=length(more) do
  2249. begin
  2250. case more[j] of
  2251. '1' :
  2252. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  2253. '2' :
  2254. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  2255. '3' :
  2256. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  2257. '4' :
  2258. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  2259. 'a' :
  2260. begin
  2261. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  2262. IllegalPara(opt);
  2263. break;
  2264. end;
  2265. 's' :
  2266. include(init_settings.optimizerswitches,cs_opt_size);
  2267. 'p' :
  2268. begin
  2269. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  2270. begin
  2271. OptCPUSetExplicitly:=true;
  2272. { Give warning for old i386 switches }
  2273. if (Length(More)-j=1) and
  2274. (More[j+1]>='1') and (More[j+1]<='5')then
  2275. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  2276. else
  2277. IllegalPara(opt);
  2278. end;
  2279. break;
  2280. end;
  2281. 'o' :
  2282. begin
  2283. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  2284. IllegalPara(opt);
  2285. break;
  2286. end;
  2287. '-' :
  2288. begin
  2289. init_settings.optimizerswitches:=[];
  2290. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2291. end;
  2292. { Obsolete switches }
  2293. 'g' :
  2294. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  2295. 'G' :
  2296. Message1(option_obsolete_switch,'-OG');
  2297. 'r' :
  2298. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  2299. 'u' :
  2300. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  2301. 'w' :
  2302. begin
  2303. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  2304. IllegalPara(opt);
  2305. break;
  2306. end;
  2307. 'W' :
  2308. begin
  2309. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  2310. IllegalPara(opt);
  2311. break;
  2312. end;
  2313. else
  2314. IllegalPara(opt);
  2315. end;
  2316. inc(j);
  2317. end;
  2318. end;
  2319. 'p' :
  2320. begin
  2321. if UnsetBool(More, 0, opt, false) then
  2322. begin
  2323. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  2324. undef_system_macro('FPC_PROFILE');
  2325. end
  2326. else
  2327. if Length(More)=0 then
  2328. IllegalPara(opt)
  2329. else
  2330. case more[1] of
  2331. 'g' : if UnsetBool(more, 1, opt, false) then
  2332. begin
  2333. exclude(init_settings.moduleswitches,cs_profile);
  2334. undef_system_macro('FPC_PROFILE');
  2335. end
  2336. else if (target_info.system in supported_targets_pg) then
  2337. begin
  2338. include(init_settings.moduleswitches,cs_profile);
  2339. def_system_macro('FPC_PROFILE');
  2340. end
  2341. else
  2342. UnsupportedPara('-pg');
  2343. else
  2344. IllegalPara(opt);
  2345. end;
  2346. end;
  2347. 'P' :
  2348. begin
  2349. { used to select the target processor with the "fpc" binary;
  2350. give an error if it's not the target architecture supported by
  2351. this compiler binary (will be verified after the target_info
  2352. is set) }
  2353. processorstr:=More;
  2354. end;
  2355. 'R' :
  2356. begin
  2357. if not SetAsmReadMode(More,init_settings.asmmode) then
  2358. IllegalPara(opt);
  2359. end;
  2360. 's' :
  2361. begin
  2362. if UnsetBool(More, 0, opt, false) then
  2363. begin
  2364. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  2365. if more<>'' then
  2366. IllegalPara(opt);
  2367. end
  2368. else
  2369. begin
  2370. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  2371. if more='h' then
  2372. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target,cs_assemble_on_target]
  2373. else if more='t' then
  2374. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target,cs_assemble_on_target]
  2375. else if more='T' then
  2376. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]-[cs_asm_extern]
  2377. else if more='r' then
  2378. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  2379. else if more<>'' then
  2380. IllegalPara(opt);
  2381. end;
  2382. end;
  2383. 'S' :
  2384. begin
  2385. if more='' then
  2386. IllegalPara(opt);
  2387. if more[1]='I' then
  2388. begin
  2389. {$ifdef jvm}
  2390. UnsupportedPara('-SI');
  2391. {$endif}
  2392. if upper(more)='ICOM' then
  2393. init_settings.interfacetype:=it_interfacecom
  2394. else if upper(more)='ICORBA' then
  2395. init_settings.interfacetype:=it_interfacecorba
  2396. else
  2397. IllegalPara(opt);
  2398. end
  2399. else
  2400. begin
  2401. j:=1;
  2402. while j<=length(more) do
  2403. begin
  2404. case more[j] of
  2405. '2' : //an alternative to -Mobjfpc
  2406. SetCompileMode('OBJFPC',true);
  2407. 'a' :
  2408. If UnsetBool(More, j, opt, false) then
  2409. exclude(init_settings.localswitches,cs_do_assertion)
  2410. else
  2411. include(init_settings.localswitches,cs_do_assertion);
  2412. 'c' :
  2413. If UnsetBool(More, j, opt, false) then
  2414. exclude(init_settings.moduleswitches,cs_support_c_operators)
  2415. else
  2416. include(init_settings.moduleswitches,cs_support_c_operators);
  2417. 'C':
  2418. If UnsetBool(More, j, opt, false) then
  2419. exclude(init_settings.localswitches,cs_check_all_case_coverage)
  2420. else
  2421. include(init_settings.localswitches,cs_check_all_case_coverage);
  2422. 'd' : //an alternative to -Mdelphi
  2423. SetCompileMode('DELPHI',true);
  2424. 'e' :
  2425. begin
  2426. SetErrorFlags(copy(more,j+1,length(more)));
  2427. break;
  2428. end;
  2429. 'f' :
  2430. begin
  2431. if not(cs_compilesystem in init_settings.moduleswitches) then
  2432. Message(option_features_only_for_system_unit);
  2433. inc(j);
  2434. if more[j]='-' then
  2435. begin
  2436. if length(more)>j then
  2437. IllegalPara(opt)
  2438. else
  2439. features:=[];
  2440. end
  2441. else
  2442. begin
  2443. if (HandleFeature(upper(copy(more,j,length(more)-j+1)))) then
  2444. j:=length(more)
  2445. else
  2446. IllegalPara(opt);
  2447. end;
  2448. end;
  2449. 'g' :
  2450. If UnsetBool(More, j, opt, false) then
  2451. exclude(init_settings.moduleswitches,cs_support_goto)
  2452. else
  2453. include(init_settings.moduleswitches,cs_support_goto);
  2454. 'h' :
  2455. If UnsetBool(More, j, opt, false) then
  2456. exclude(init_settings.localswitches,cs_refcountedstrings)
  2457. else
  2458. include(init_settings.localswitches,cs_refcountedstrings);
  2459. 'i' :
  2460. If UnsetBool(More, j, opt, false) then
  2461. exclude(init_settings.localswitches,cs_do_inline)
  2462. else
  2463. include(init_settings.localswitches,cs_do_inline);
  2464. 'j' :
  2465. If UnsetBool(More, j, opt, false) then
  2466. exclude(init_settings.localswitches,cs_typed_const_writable)
  2467. else
  2468. include(init_settings.localswitches,cs_typed_const_writable);
  2469. 'k' :
  2470. If UnsetBool(More, j, opt, false) then
  2471. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  2472. else
  2473. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  2474. 'm' :
  2475. If UnsetBool(More, j, opt, false) then
  2476. exclude(init_settings.moduleswitches,cs_support_macro)
  2477. else
  2478. include(init_settings.moduleswitches,cs_support_macro);
  2479. 'o' : //an alternative to -Mtp
  2480. SetCompileMode('TP',true);
  2481. 'r' :
  2482. If UnsetBool(More, j, opt, false) then
  2483. exclude(init_settings.globalswitches,cs_transparent_file_names)
  2484. else
  2485. include(init_settings.globalswitches,cs_transparent_file_names);
  2486. {$ifdef gpc_mode}
  2487. 'p' : //an alternative to -Mgpc
  2488. SetCompileMode('GPC',true);
  2489. {$endif}
  2490. 's' :
  2491. If UnsetBool(More, j, opt, false) then
  2492. exclude(init_settings.globalswitches,cs_constructor_name)
  2493. else
  2494. include(init_settings.globalswitches,cs_constructor_name);
  2495. 't' :
  2496. Message1(option_obsolete_switch,'-St');
  2497. 'v' :
  2498. If UnsetBool(More, j, opt, false) then
  2499. exclude(init_settings.globalswitches,cs_support_vectors)
  2500. else
  2501. include(init_settings.globalswitches,cs_support_vectors);
  2502. 'x' :
  2503. If UnsetBool(More, j, opt, false) then
  2504. SetCompileModeSwitch('EXCEPTIONS-',true)
  2505. else
  2506. SetCompileModeSwitch('EXCEPTIONS',true);
  2507. 'y' :
  2508. If UnsetBool(More, j, opt, false) then
  2509. exclude(init_settings.localswitches,cs_typed_addresses)
  2510. else
  2511. include(init_settings.localswitches,cs_typed_addresses);
  2512. '-' :
  2513. begin
  2514. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  2515. cs_support_vectors,cs_load_fpcylix_unit];
  2516. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  2517. cs_typed_addresses];
  2518. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  2519. cs_support_macro];
  2520. end;
  2521. else
  2522. IllegalPara(opt);
  2523. end;
  2524. inc(j);
  2525. end;
  2526. end;
  2527. end;
  2528. 'T' :
  2529. begin
  2530. more:=Upper(More);
  2531. if paratarget=system_none then
  2532. begin
  2533. { remove old target define }
  2534. TargetOptions(false);
  2535. { load new target }
  2536. paratarget:=find_system_by_string(More);
  2537. if paratarget<>system_none then
  2538. set_target(paratarget)
  2539. else
  2540. IllegalPara(opt);
  2541. { set new define }
  2542. TargetOptions(true);
  2543. end
  2544. else
  2545. if More<>upper(target_info.shortname) then
  2546. Message1(option_target_is_already_set,target_info.shortname);
  2547. end;
  2548. 'u' :
  2549. if is_identifier(more) then
  2550. undef_system_macro(more)
  2551. else
  2552. begin
  2553. if (more='') then
  2554. Message1(option_missing_arg,'-u')
  2555. else
  2556. Message1(option_malformed_para,opt);
  2557. StopOptions(1);
  2558. end;
  2559. 'U' :
  2560. begin
  2561. j:=1;
  2562. while j<=length(more) do
  2563. begin
  2564. case more[j] of
  2565. {$ifdef UNITALIASES}
  2566. 'a' :
  2567. begin
  2568. AddUnitAlias(Copy(More,j+1,255));
  2569. break;
  2570. end;
  2571. {$endif UNITALIASES}
  2572. 'n' :
  2573. exclude(init_settings.globalswitches,cs_check_unit_name);
  2574. 'p' :
  2575. begin
  2576. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  2577. break;
  2578. end;
  2579. 'r' :
  2580. begin
  2581. do_release:=true;
  2582. if (cs_checkpointer in init_settings.localswitches) then
  2583. begin
  2584. Message(option_gc_incompatible_with_release_flag);
  2585. exclude(init_settings.localswitches,cs_checkpointer);
  2586. end;
  2587. end;
  2588. 's' :
  2589. include(init_settings.moduleswitches,cs_compilesystem);
  2590. '-' :
  2591. begin
  2592. exclude(init_settings.moduleswitches,cs_compilesystem);
  2593. exclude(init_settings.globalswitches,cs_check_unit_name);
  2594. end;
  2595. else
  2596. IllegalPara(opt);
  2597. end;
  2598. inc(j);
  2599. end;
  2600. end;
  2601. 'v' :
  2602. begin
  2603. if not setverbosity(More) then
  2604. IllegalPara(opt);
  2605. end;
  2606. 'V' : ; { Ignore used by fpc }
  2607. 'W' :
  2608. begin
  2609. j:=1;
  2610. while j<=length(More) do
  2611. begin
  2612. case More[j] of
  2613. 'A':
  2614. begin
  2615. if target_info.system in systems_all_windows then
  2616. begin
  2617. if UnsetBool(More, j, opt, false) then
  2618. SetApptype(app_cui)
  2619. else
  2620. SetApptype(app_native);
  2621. end
  2622. else
  2623. IllegalPara(opt);
  2624. end;
  2625. 'b':
  2626. begin
  2627. if target_info.system in systems_darwin then
  2628. begin
  2629. if UnsetBool(More, j, opt, false) then
  2630. SetApptype(app_cui)
  2631. else
  2632. SetApptype(app_bundle)
  2633. end
  2634. else
  2635. IllegalPara(opt);
  2636. end;
  2637. 'B':
  2638. begin
  2639. if target_info.system in systems_all_windows+systems_symbian+[system_z80_zxspectrum] then
  2640. begin
  2641. { -WB200000 means set trefered base address
  2642. to $200000, but does not change relocsection boolean
  2643. this way we can create both relocatble and
  2644. non relocatable DLL at a specific base address PM }
  2645. if (length(More)>j) then
  2646. begin
  2647. val('$'+Copy(More,j+1,255),imagebase,code);
  2648. if code<>0 then
  2649. IllegalPara(opt);
  2650. ImageBaseSetExplicity:=true;
  2651. end
  2652. else
  2653. begin
  2654. RelocSection:=true;
  2655. RelocSectionSetExplicitly:=true;
  2656. end;
  2657. break;
  2658. end
  2659. else
  2660. IllegalPara(opt);
  2661. end;
  2662. 'C':
  2663. begin
  2664. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2665. begin
  2666. if UnsetBool(More, j, opt, false) then
  2667. SetApptype(app_gui)
  2668. else
  2669. SetApptype(app_cui);
  2670. end
  2671. else
  2672. IllegalPara(opt);
  2673. end;
  2674. 'D':
  2675. begin
  2676. if target_info.system in systems_all_windows then
  2677. begin
  2678. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2679. UseDeffileForExportsSetExplicitly:=true;
  2680. end
  2681. else
  2682. IllegalPara(opt);
  2683. end;
  2684. 'e':
  2685. begin
  2686. if (target_info.system in systems_darwin) then
  2687. begin
  2688. set_target_res(res_ext);
  2689. target_info.resobjext:='.fpcres';
  2690. end
  2691. else
  2692. IllegalPara(opt);
  2693. end;
  2694. 'F':
  2695. begin
  2696. if target_info.system in systems_os2 then
  2697. begin
  2698. if UnsetBool(More, j, opt, false) then
  2699. SetApptype(app_cui)
  2700. else
  2701. SetApptype(app_fs);
  2702. end
  2703. else
  2704. IllegalPara(opt);
  2705. end;
  2706. 'G':
  2707. begin
  2708. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2709. begin
  2710. if UnsetBool(More, j, opt, false) then
  2711. SetApptype(app_cui)
  2712. else
  2713. SetApptype(app_gui);
  2714. end
  2715. else
  2716. IllegalPara(opt);
  2717. end;
  2718. {$if defined(i8086)}
  2719. 'h':
  2720. begin
  2721. if UnsetBool(More, j, opt, false) then
  2722. exclude(init_settings.moduleswitches,cs_huge_code)
  2723. else
  2724. include(init_settings.moduleswitches,cs_huge_code);
  2725. end;
  2726. {$endif defined(i8086)}
  2727. 'I':
  2728. begin
  2729. if target_info.system in systems_all_windows then
  2730. begin
  2731. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2732. GenerateImportSectionSetExplicitly:=true;
  2733. end
  2734. else
  2735. IllegalPara(opt);
  2736. end;
  2737. 'i':
  2738. begin
  2739. if (target_info.system in systems_darwin) then
  2740. begin
  2741. set_target_res(res_macho);
  2742. target_info.resobjext:=
  2743. targetinfos[target_info.system]^.resobjext;
  2744. end
  2745. else
  2746. IllegalPara(opt);
  2747. end;
  2748. 'm':
  2749. begin
  2750. {$if defined(i8086)}
  2751. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  2752. begin
  2753. case Upper(Copy(More,j+1,255)) of
  2754. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2755. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2756. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2757. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2758. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2759. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2760. else
  2761. IllegalPara(opt);
  2762. end;
  2763. break;
  2764. end
  2765. else
  2766. {$endif defined(i8086)}
  2767. IllegalPara(opt);
  2768. end;
  2769. 'M':
  2770. begin
  2771. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim])) and
  2772. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2773. begin
  2774. break;
  2775. end
  2776. else
  2777. IllegalPara(opt);
  2778. end;
  2779. 'N':
  2780. begin
  2781. if target_info.system in systems_all_windows then
  2782. begin
  2783. RelocSection:=UnsetBool(More,j,opt,false);
  2784. RelocSectionSetExplicitly:=true;
  2785. end
  2786. else
  2787. IllegalPara(opt);
  2788. end;
  2789. 'p':
  2790. begin
  2791. {$push}
  2792. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  2793. if ((target_info.system in systems_embedded) or (target_info.system in systems_freertos)) and
  2794. ControllerSupport then
  2795. begin
  2796. s:=upper(copy(more,j+1,length(more)-j));
  2797. if not(SetControllerType(s,init_settings.controllertype)) then
  2798. IllegalPara(opt)
  2799. else
  2800. begin
  2801. if init_settings.cputype<>embedded_controllers[init_settings.controllertype].cputype then
  2802. begin
  2803. Message(scan_n_changecputype);
  2804. init_settings.cputype:=embedded_controllers[init_settings.controllertype].cputype;
  2805. end;
  2806. end;
  2807. break;
  2808. end
  2809. else
  2810. IllegalPara(opt);
  2811. {$pop}
  2812. end;
  2813. 'P':
  2814. begin
  2815. if (target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim]) and
  2816. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2817. begin
  2818. break;
  2819. end
  2820. {$ifdef XTENSA}
  2821. else if (target_info.system in [system_xtensa_freertos]) and
  2822. ParseVersionStr(idf_version,'IDF_VERSION',copy(More,2,255)) then
  2823. begin
  2824. break;
  2825. end
  2826. {$endif XTENSA}
  2827. else
  2828. IllegalPara(opt);
  2829. end;
  2830. {$if defined(m68k)}
  2831. 'L':
  2832. begin
  2833. if (target_info.system in [system_m68k_sinclairql]) then
  2834. sinclairql_vlink_experimental:=false
  2835. else
  2836. IllegalPara(opt);
  2837. end;
  2838. 'Q':
  2839. begin
  2840. if (target_info.system in [system_m68k_sinclairql]) then
  2841. begin
  2842. sinclairql_metadata_format:=Upper(Copy(More,j+1,255));
  2843. case sinclairql_metadata_format of
  2844. 'QHDR', 'XTCC': ; { allowed formats }
  2845. else
  2846. IllegalPara(opt);
  2847. end;
  2848. break;
  2849. end
  2850. else
  2851. IllegalPara(opt);
  2852. end;
  2853. {$endif defined(m68k)}
  2854. 'R':
  2855. begin
  2856. if target_info.system in systems_all_windows then
  2857. begin
  2858. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2859. RelocSection:=not UnsetBool(More,j,opt,false);
  2860. RelocSectionSetExplicitly:=true;
  2861. end
  2862. else
  2863. IllegalPara(opt);
  2864. end;
  2865. 't':
  2866. begin
  2867. {$if defined(i8086)}
  2868. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  2869. begin
  2870. case Upper(Copy(More,j+1,255)) of
  2871. 'EXE': SetAppType(app_cui);
  2872. 'COM': SetAppType(app_com);
  2873. else
  2874. IllegalPara(opt);
  2875. end;
  2876. break;
  2877. end
  2878. else
  2879. {$endif defined(i8086)}
  2880. IllegalPara(opt);
  2881. end;
  2882. 'T':
  2883. begin
  2884. if target_info.system in systems_macos then
  2885. begin
  2886. if UnsetBool(More, j, opt, false) then
  2887. SetApptype(app_cui)
  2888. else
  2889. SetApptype(app_tool);
  2890. end
  2891. else
  2892. IllegalPara(opt);
  2893. end;
  2894. 'X':
  2895. begin
  2896. if (target_info.system in systems_linux) then
  2897. begin
  2898. if UnsetBool(More, j, opt, false) then
  2899. exclude(init_settings.moduleswitches,cs_executable_stack)
  2900. else
  2901. include(init_settings.moduleswitches,cs_executable_stack)
  2902. end
  2903. else
  2904. IllegalPara(opt);
  2905. end;
  2906. else
  2907. IllegalPara(opt);
  2908. end;
  2909. inc(j);
  2910. end;
  2911. end;
  2912. 'X' :
  2913. begin
  2914. j:=1;
  2915. while j<=length(more) do
  2916. begin
  2917. case More[j] of
  2918. '9' :
  2919. begin
  2920. if target_info.system in systems_linux then
  2921. begin
  2922. if UnsetBool(More, j, opt, false) then
  2923. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2924. else
  2925. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2926. end
  2927. else
  2928. IllegalPara(opt);
  2929. end;
  2930. 'a' :
  2931. begin
  2932. If UnsetBool(More, j, opt, false) then
  2933. exclude(init_settings.globalswitches,cs_large)
  2934. else
  2935. include(init_settings.globalswitches,cs_large);
  2936. end;
  2937. 'c' : Cshared:=TRUE;
  2938. 'd' : Dontlinkstdlibpath:=TRUE;
  2939. 'e' :
  2940. begin
  2941. If UnsetBool(More, j, opt, false) then
  2942. exclude(init_settings.globalswitches,cs_link_extern)
  2943. else
  2944. include(init_settings.globalswitches,cs_link_extern);
  2945. end;
  2946. 'f' :
  2947. include(init_settings.globalswitches,cs_link_pthread);
  2948. 'g' :
  2949. begin
  2950. If UnsetBool(More, j, opt, false) then
  2951. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2952. else
  2953. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2954. end;
  2955. 'i' :
  2956. begin
  2957. If UnsetBool(More, j, opt, false) then
  2958. include(init_settings.globalswitches,cs_link_extern)
  2959. else
  2960. exclude(init_settings.globalswitches,cs_link_extern);
  2961. end;
  2962. 'n' :
  2963. begin
  2964. If UnsetBool(More, j, opt, false) then
  2965. exclude(init_settings.globalswitches,cs_link_native)
  2966. else
  2967. include(init_settings.globalswitches,cs_link_native);
  2968. end;
  2969. {$ifdef llvm}
  2970. 'l' :
  2971. begin
  2972. if j=length(more) then
  2973. IllegalPara(opt)
  2974. else
  2975. begin
  2976. case more[j+1] of
  2977. 'S':
  2978. begin
  2979. llvmutilssuffix:=copy(more,j+2,length(more));
  2980. j:=length(more);
  2981. end
  2982. else
  2983. IllegalPara(opt);
  2984. end;
  2985. end;
  2986. end;
  2987. {$endif}
  2988. 'm' :
  2989. begin
  2990. If UnsetBool(More, j, opt, false) then
  2991. exclude(init_settings.globalswitches,cs_link_map)
  2992. else
  2993. include(init_settings.globalswitches,cs_link_map);
  2994. end;
  2995. 'p' : ; { Ignore used by fpc.pp }
  2996. 'r' :
  2997. begin
  2998. if (target_info.system in suppported_targets_x_smallr) then
  2999. begin
  3000. rlinkpath:=Copy(more,2,length(More)-1);
  3001. DefaultReplacements(rlinkpath);
  3002. end
  3003. else
  3004. IgnoredPara('-Xr');
  3005. more:='';
  3006. end;
  3007. 'R' :
  3008. begin
  3009. sysrootpath:=copy(more,2,length(more)-1);
  3010. defaultreplacements(sysrootpath);
  3011. more:='';
  3012. end;
  3013. 's' :
  3014. begin
  3015. If UnsetBool(More, j, opt, false) then
  3016. exclude(init_settings.globalswitches,cs_link_strip)
  3017. else
  3018. include(init_settings.globalswitches,cs_link_strip);
  3019. end;
  3020. 't' :
  3021. include(init_settings.globalswitches,cs_link_staticflag);
  3022. 'u' :
  3023. begin
  3024. if target_info.system in systems_support_uf2 then
  3025. begin
  3026. if UnsetBool(More, j, opt, false) then
  3027. exclude(init_settings.globalswitches,cs_generate_uf2)
  3028. else
  3029. include(init_settings.globalswitches,cs_generate_uf2);
  3030. end
  3031. else
  3032. IgnoredPara('-Xu');
  3033. end;
  3034. 'v' :
  3035. begin
  3036. If UnsetBool(More, j, opt, false) then
  3037. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  3038. else
  3039. include(init_settings.globalswitches,cs_link_opt_vtable);
  3040. end;
  3041. 'D' :
  3042. begin
  3043. def_system_macro('FPC_LINK_DYNAMIC');
  3044. undef_system_macro('FPC_LINK_SMART');
  3045. undef_system_macro('FPC_LINK_STATIC');
  3046. exclude(init_settings.globalswitches,cs_link_static);
  3047. exclude(init_settings.globalswitches,cs_link_smart);
  3048. include(init_settings.globalswitches,cs_link_shared);
  3049. LinkTypeSetExplicitly:=true;
  3050. end;
  3051. 'M' :
  3052. begin
  3053. mainaliasname:=Copy(more,2,length(More)-1);
  3054. More:='';
  3055. end;
  3056. 'P' :
  3057. begin
  3058. utilsprefix:=Copy(more,2,length(More)-1);
  3059. DefaultReplacements(utilsprefix);
  3060. More:='';
  3061. end;
  3062. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  3063. // these are not aggregable.
  3064. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  3065. IllegalPara(opt)
  3066. else
  3067. begin
  3068. case more[j+1] of
  3069. 'A' : begin
  3070. s:=Copy(more,3,length(More)-2);
  3071. if not LinkLibraryAliases.AddDep(s) Then
  3072. IllegalPara(opt);
  3073. end;
  3074. 'O' : begin
  3075. s:=Copy(more,3,length(More)-2);
  3076. if not LinkLibraryOrder.AddWeight(s) Then
  3077. IllegalPara(opt);
  3078. end;
  3079. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  3080. else
  3081. IllegalPara(opt);
  3082. end; {case}
  3083. j:=length(more);
  3084. end; {else begin}
  3085. end;
  3086. 'S' :
  3087. begin
  3088. ForceStaticLinking;
  3089. end;
  3090. 'V' :
  3091. begin
  3092. if UnsetBool(More, j, opt, false) then
  3093. exclude(init_settings.globalswitches,cs_link_vlink)
  3094. else
  3095. begin
  3096. include(init_settings.globalswitches,cs_link_vlink);
  3097. include(init_settings.globalswitches,cs_link_extern);
  3098. end;
  3099. LinkerSetExplicitly:=true;
  3100. end;
  3101. 'X' :
  3102. begin
  3103. def_system_macro('FPC_LINK_SMART');
  3104. undef_system_macro('FPC_LINK_STATIC');
  3105. undef_system_macro('FPC_LINK_DYNAMIC');
  3106. exclude(init_settings.globalswitches,cs_link_static);
  3107. include(init_settings.globalswitches,cs_link_smart);
  3108. exclude(init_settings.globalswitches,cs_link_shared);
  3109. LinkTypeSetExplicitly:=true;
  3110. end;
  3111. '-' :
  3112. begin
  3113. exclude(init_settings.globalswitches,cs_link_staticflag);
  3114. exclude(init_settings.globalswitches,cs_link_strip);
  3115. exclude(init_settings.globalswitches,cs_link_map);
  3116. set_default_link_type;
  3117. end;
  3118. else
  3119. IllegalPara(opt);
  3120. end;
  3121. inc(j);
  3122. end;
  3123. end;
  3124. else
  3125. IllegalPara(opt);
  3126. end;
  3127. end;
  3128. '@' :
  3129. begin
  3130. Message(option_no_nested_response_file);
  3131. StopOptions(1);
  3132. end;
  3133. else
  3134. begin
  3135. if (length(param_file)<>0) then
  3136. Message2(option_only_one_source_support,param_file,opt);
  3137. param_file:=opt;
  3138. Message1(option_found_file,opt);
  3139. end;
  3140. end;
  3141. end;
  3142. procedure Toption.Interpret_file(const filename : TPathStr);
  3143. procedure RemoveSep(var fn:TPathStr);
  3144. var
  3145. i : longint;
  3146. begin
  3147. i:=0;
  3148. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  3149. inc(i);
  3150. Delete(fn,1,i);
  3151. i:=length(fn);
  3152. while (i>0) and (fn[i] in [',',' ',#9]) do
  3153. dec(i);
  3154. fn:=copy(fn,1,i);
  3155. end;
  3156. function GetName(var fn:TPathStr):TPathStr;
  3157. var
  3158. i : longint;
  3159. begin
  3160. i:=0;
  3161. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  3162. inc(i);
  3163. GetName:=Copy(fn,1,i);
  3164. Delete(fn,1,i);
  3165. end;
  3166. const
  3167. maxlevel = 15;
  3168. var
  3169. f : text;
  3170. s, tmp,
  3171. opts : TCmdStr;
  3172. skip : array[0..maxlevel] of boolean;
  3173. line,
  3174. level : longint;
  3175. option_read : boolean;
  3176. oldfilemode : byte;
  3177. ConfigFile: TPathStr;
  3178. begin
  3179. { avoid infinite loop }
  3180. Inc(FileLevel);
  3181. Option_read:=false;
  3182. If FileLevel>MaxLevel then
  3183. Message(option_too_many_cfg_files);
  3184. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  3185. ConfigFile := ExpandFileName(filename);
  3186. { Maybe It's Directory ?} //Jaro Change:
  3187. if PathExists(ConfigFile,false) then
  3188. begin
  3189. Message1(option_config_is_dir,filename);
  3190. exit;
  3191. end;
  3192. { open file }
  3193. Message1(option_using_file,filename);
  3194. oldfilemode:=filemode;
  3195. filemode:=0;
  3196. assign(f,ConfigFile);
  3197. {$push}{$I-}
  3198. reset(f);
  3199. {$pop}
  3200. filemode:=oldfilemode;
  3201. if ioresult<>0 then
  3202. begin
  3203. Message1(option_unable_open_file,filename);
  3204. exit;
  3205. end;
  3206. Message1(option_start_reading_configfile,filename);
  3207. fillchar(skip,sizeof(skip),0);
  3208. level:=0;
  3209. line:=0;
  3210. while not eof(f) do
  3211. begin
  3212. readln(f,opts);
  3213. inc(line);
  3214. RemoveSep(opts);
  3215. if (opts<>'') and (opts[1]<>';') then
  3216. begin
  3217. if opts[1]='#' then
  3218. begin
  3219. Message1(option_interpreting_file_option,opts);
  3220. Delete(opts,1,1);
  3221. s:=upper(GetName(opts));
  3222. if (s='SECTION') then
  3223. begin
  3224. RemoveSep(opts);
  3225. s:=upper(GetName(opts));
  3226. if level=0 then
  3227. skip[level]:=not defined_macro(s) or (s='COMMON');
  3228. end
  3229. else
  3230. if (s='IFDEF') then
  3231. begin
  3232. RemoveSep(opts);
  3233. if Level>=maxlevel then
  3234. begin
  3235. Message2(option_too_many_ifdef,filename,tostr(line));
  3236. stopOptions(1);
  3237. end;
  3238. inc(Level);
  3239. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  3240. end
  3241. else
  3242. if (s='IFNDEF') then
  3243. begin
  3244. RemoveSep(opts);
  3245. if Level>=maxlevel then
  3246. begin
  3247. Message2(option_too_many_ifdef,filename,tostr(line));
  3248. stopOptions(1);
  3249. end;
  3250. inc(Level);
  3251. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  3252. end
  3253. else
  3254. if (s='ELSE') then
  3255. begin
  3256. if Level=0 then
  3257. begin
  3258. Message2(option_else_without_if,filename,tostr(line));
  3259. stopOptions(1);
  3260. end
  3261. else
  3262. skip[level]:=skip[level-1] or (not skip[level])
  3263. end
  3264. else
  3265. if (s='ENDIF') then
  3266. begin
  3267. skip[level]:=false;
  3268. if Level=0 then
  3269. begin
  3270. Message2(option_too_many_endif,filename,tostr(line));
  3271. stopOptions(1);
  3272. end;
  3273. dec(level);
  3274. end
  3275. else
  3276. if (not skip[level]) then
  3277. begin
  3278. if (s='DEFINE') then
  3279. begin
  3280. RemoveSep(opts);
  3281. tmp:= GetName(opts);
  3282. if tmp <> '' then
  3283. def_system_macro(tmp);
  3284. Option_read:=true;
  3285. end
  3286. else
  3287. if (s='UNDEF') then
  3288. begin
  3289. RemoveSep(opts);
  3290. tmp:= GetName(opts);
  3291. if tmp <> '' then
  3292. undef_system_macro(tmp);
  3293. Option_read:=true;
  3294. end
  3295. else
  3296. if (s='WRITE') then
  3297. begin
  3298. Delete(opts,1,1);
  3299. DefaultReplacements(opts);
  3300. WriteLn(opts);
  3301. Option_read:=true;
  3302. end
  3303. else
  3304. if (s='INCLUDE') then
  3305. begin
  3306. Delete(opts,1,1);
  3307. DefaultReplacements(opts);
  3308. Interpret_file(opts);
  3309. Option_read:=true;
  3310. end
  3311. else
  3312. if (s='CFGDIR') then
  3313. begin
  3314. Delete(opts,1,1);
  3315. DefaultReplacements(opts);
  3316. ParaIncludeCfgPath.AddPath(opts,false);
  3317. Option_read:=true;
  3318. end;
  3319. end;
  3320. end
  3321. else
  3322. begin
  3323. if (opts[1]='-') or (opts[1]='@') then
  3324. begin
  3325. if (not skip[level]) then
  3326. interpret_option(opts,false);
  3327. Option_read:=true;
  3328. end
  3329. else
  3330. Message1(option_illegal_para,opts);
  3331. end;
  3332. end;
  3333. end;
  3334. if Level>0 then
  3335. Message(option_too_less_endif);
  3336. if Not Option_read then
  3337. Message1(option_no_option_found,filename)
  3338. else
  3339. Message1(option_end_reading_configfile,filename);
  3340. Close(f);
  3341. Dec(FileLevel);
  3342. end;
  3343. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  3344. var
  3345. argstart,
  3346. env,
  3347. pc : pchar;
  3348. arglen : longint;
  3349. quote : set of char;
  3350. hs : TCmdStr;
  3351. begin
  3352. Message1(option_using_env,envname);
  3353. env:=GetEnvPChar(envname);
  3354. pc:=env;
  3355. hs:='';
  3356. if assigned(pc) then
  3357. begin
  3358. repeat
  3359. { skip leading spaces }
  3360. while pc^ in [' ',#9,#13] do
  3361. inc(pc);
  3362. case pc^ of
  3363. #0 :
  3364. break;
  3365. '"' :
  3366. begin
  3367. quote:=['"'];
  3368. inc(pc);
  3369. end;
  3370. '''' :
  3371. begin
  3372. quote:=[''''];
  3373. inc(pc);
  3374. end;
  3375. else
  3376. quote:=[' ',#9,#13];
  3377. end;
  3378. { scan until the end of the argument }
  3379. argstart:=pc;
  3380. while (pc^<>#0) and not(pc^ in quote) do
  3381. inc(pc);
  3382. { create argument }
  3383. arglen:=pc-argstart;
  3384. { TODO: FIXME: silent truncation of environment parameters }
  3385. if (arglen > 255) then
  3386. arglen := 255;
  3387. setlength(hs,arglen);
  3388. move(argstart^,hs[1],arglen);
  3389. interpret_option(hs,true);
  3390. { skip quote }
  3391. if pc^ in quote then
  3392. inc(pc);
  3393. until false;
  3394. end
  3395. else
  3396. Message1(option_no_option_found,'(env) '+envname);
  3397. FreeEnvPChar(env);
  3398. end;
  3399. procedure toption.read_parameters;
  3400. var
  3401. opts : TCmdStr;
  3402. paramindex : longint;
  3403. begin
  3404. paramindex:=0;
  3405. while paramindex<paramcount do
  3406. begin
  3407. inc(paramindex);
  3408. opts:=objpas.paramstr(paramindex);
  3409. if length(opts)>0 then
  3410. case opts[1] of
  3411. '@' :
  3412. if not firstpass then
  3413. begin
  3414. Delete(opts,1,1);
  3415. Message1(option_reading_further_from,opts);
  3416. interpret_file(opts);
  3417. end;
  3418. '!' :
  3419. if not firstpass then
  3420. begin
  3421. Delete(opts,1,1);
  3422. Message1(option_reading_further_from,'(env) '+opts);
  3423. interpret_envvar(opts);
  3424. end;
  3425. else
  3426. interpret_option(opts,true);
  3427. end;
  3428. end;
  3429. end;
  3430. procedure toption.parsecmd(cmd:TCmdStr);
  3431. var
  3432. i,ps : longint;
  3433. opts : TCmdStr;
  3434. begin
  3435. while (cmd<>'') do
  3436. begin
  3437. while cmd[1]=' ' do
  3438. delete(cmd,1,1);
  3439. i:=pos(' ',cmd);
  3440. if i=0 then
  3441. i:=2147483647;
  3442. opts:=Copy(cmd,1,i-1);
  3443. Delete(cmd,1,i);
  3444. case opts[1] of
  3445. '@' :
  3446. if not firstpass then
  3447. begin
  3448. Delete(opts,1,1);
  3449. Message1(option_reading_further_from,opts);
  3450. interpret_file(opts);
  3451. end;
  3452. '!' :
  3453. if not firstpass then
  3454. begin
  3455. Delete(opts,1,1);
  3456. Message1(option_reading_further_from,'(env) '+opts);
  3457. interpret_envvar(opts);
  3458. end;
  3459. '"' :
  3460. begin
  3461. Delete(opts,1,1);
  3462. ps:=pos('"',cmd);
  3463. if (i<>256) and (ps>0) then
  3464. begin
  3465. opts:=opts + ' '+ copy(cmd,1,ps-1);
  3466. cmd:=copy(cmd,ps+1,255);
  3467. end;
  3468. interpret_option(opts,true);
  3469. end;
  3470. else
  3471. interpret_option(opts,true);
  3472. end;
  3473. end;
  3474. end;
  3475. procedure toption.writequickinfo;
  3476. var
  3477. s : string;
  3478. i : longint;
  3479. procedure addinfo(const hs:string);
  3480. begin
  3481. if s<>'' then
  3482. s:=s+' '+hs
  3483. else
  3484. s:=hs;
  3485. end;
  3486. begin
  3487. s:='';
  3488. i:=0;
  3489. while (i<length(quickinfo)) do
  3490. begin
  3491. inc(i);
  3492. case quickinfo[i] of
  3493. 'S' :
  3494. begin
  3495. inc(i);
  3496. case quickinfo[i] of
  3497. 'O' :
  3498. addinfo(lower(source_info.shortname));
  3499. 'P' :
  3500. addinfo(source_cpu_string);
  3501. else
  3502. IllegalPara('-i'+QuickInfo);
  3503. end;
  3504. end;
  3505. 'T' :
  3506. begin
  3507. inc(i);
  3508. case quickinfo[i] of
  3509. 'O' :
  3510. addinfo(lower(target_info.shortname));
  3511. 'P' :
  3512. AddInfo(target_cpu_string);
  3513. else
  3514. IllegalPara('-i'+QuickInfo);
  3515. end;
  3516. end;
  3517. 'V' :
  3518. AddInfo(version_string);
  3519. 'W' :
  3520. AddInfo(full_version_string);
  3521. 'D' :
  3522. AddInfo(date_string);
  3523. '_' :
  3524. ;
  3525. else
  3526. IllegalPara('-i'+QuickInfo);
  3527. end;
  3528. end;
  3529. if s<>'' then
  3530. begin
  3531. writeln(s);
  3532. stopoptions(0);
  3533. end;
  3534. end;
  3535. procedure TOption.TargetOptions(def:boolean);
  3536. var
  3537. s : string;
  3538. i : integer;
  3539. target_unsup_features : tfeatures;
  3540. begin
  3541. if def then
  3542. def_system_macro(target_info.shortname)
  3543. else
  3544. undef_system_macro(target_info.shortname);
  3545. s:=target_info.extradefines;
  3546. while (s<>'') do
  3547. begin
  3548. i:=pos(';',s);
  3549. if i=0 then
  3550. i:=length(s)+1;
  3551. if def then
  3552. def_system_macro(Copy(s,1,i-1))
  3553. else
  3554. undef_system_macro(Copy(s,1,i-1));
  3555. delete(s,1,i);
  3556. end;
  3557. if (tf_winlikewidestring in target_info.flags) then
  3558. if def then
  3559. def_system_macro('FPC_WINLIKEWIDESTRING')
  3560. else
  3561. undef_system_macro('FPC_WINLIKEWIDESTRING');
  3562. if (tf_requires_proper_alignment in target_info.flags) then
  3563. if def then
  3564. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  3565. else
  3566. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3567. if (tf_init_final_units_by_calls in target_info.flags) then
  3568. if def then
  3569. def_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS')
  3570. else
  3571. undef_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS');
  3572. if source_info.system<>target_info.system then
  3573. if def then
  3574. def_system_macro('FPC_CROSSCOMPILING')
  3575. else
  3576. undef_system_macro('FPC_CROSSCOMPILING');
  3577. if source_info.cpu<>target_info.cpu then
  3578. if def then
  3579. def_system_macro('FPC_CPUCROSSCOMPILING')
  3580. else
  3581. def_system_macro('FPC_CPUCROSSCOMPILING');
  3582. if (tf_no_generic_stackcheck in target_info.flags) then
  3583. if def then
  3584. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  3585. else
  3586. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  3587. if (tf_section_threadvars in target_info.flags) then
  3588. if def then
  3589. def_system_macro('FPC_SECTION_THREADVARS')
  3590. else
  3591. undef_system_macro('FPC_SECTION_THREADVARS');
  3592. if (tf_use_psabieh in target_info.flags) then
  3593. if def then
  3594. def_system_macro('FPC_USE_PSABIEH')
  3595. else
  3596. undef_system_macro('FPC_USE_PSABIEH');
  3597. { Code generation flags }
  3598. if (tf_pic_default in target_info.flags) then
  3599. if def then
  3600. include(init_settings.moduleswitches,cs_create_pic)
  3601. else
  3602. exclude(init_settings.moduleswitches,cs_create_pic);
  3603. { Resources support }
  3604. if (tf_has_winlike_resources in target_info.flags) then
  3605. if def then
  3606. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  3607. else
  3608. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  3609. { Features }
  3610. case target_info.system of
  3611. system_arm_gba:
  3612. target_unsup_features:=[f_dynlibs];
  3613. system_arm_nds:
  3614. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  3615. system_i386_nativent:
  3616. // until these features are implemented, they are disabled in the compiler
  3617. target_unsup_features:=[f_stackcheck];
  3618. system_i8086_msdos:
  3619. target_unsup_features:=[f_threading,f_dynlibs];
  3620. system_i8086_win16:
  3621. target_unsup_features:=[f_threading];
  3622. system_jvm_java32,
  3623. system_jvm_android32:
  3624. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  3625. f_variants,f_objects,f_commandargs,
  3626. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  3627. system_arm_palmos,
  3628. system_m68k_palmos:
  3629. target_unsup_features:=[f_threading];
  3630. system_m68k_atari:
  3631. target_unsup_features:=[f_threading];
  3632. { classic amiga has dynamic libraries, but they cannot be integrated in the
  3633. normal dynlibs infrastructure due to architectural differences, so therefore
  3634. lets disable the feature. }
  3635. system_m68k_amiga:
  3636. target_unsup_features:=[f_dynlibs];
  3637. system_m68k_sinclairql:
  3638. target_unsup_features:=[f_threading,f_dynlibs];
  3639. system_z80_zxspectrum:
  3640. target_unsup_features:=[f_threading,f_dynlibs{,f_fileio,f_textio},f_commandargs,f_exitcode];
  3641. system_z80_msxdos:
  3642. target_unsup_features:=[f_threading,f_dynlibs];
  3643. else
  3644. target_unsup_features:=[];
  3645. end;
  3646. if def then
  3647. features:=features-target_unsup_features
  3648. else
  3649. features:=features+target_unsup_features;
  3650. {$if defined(atari) or defined(hasamiga)}
  3651. { enable vlink as default linker on Atari and Amiga but not for cross compilers (for now) }
  3652. if (target_info.system in [system_m68k_amiga,system_m68k_atari,system_powerpc_amiga]) and
  3653. not LinkerSetExplicitly then
  3654. include(init_settings.globalswitches,cs_link_vlink);
  3655. {$endif}
  3656. {$ifdef m68k}
  3657. if (target_info.system in [system_m68k_sinclairql]) and
  3658. not LinkerSetExplicitly then
  3659. include(init_settings.globalswitches,cs_link_vlink);
  3660. {$endif m68k}
  3661. end;
  3662. procedure TOption.checkoptionscompatibility;
  3663. begin
  3664. {$ifdef wasm}
  3665. if (Ord(ts_wasm_no_exceptions in init_settings.targetswitches)+
  3666. Ord(ts_wasm_js_exceptions in init_settings.targetswitches)+
  3667. Ord(ts_wasm_native_exceptions in init_settings.targetswitches)+
  3668. Ord(ts_wasm_bf_exceptions in init_settings.targetswitches))>1 then
  3669. begin
  3670. Message(option_too_many_exception_modes);
  3671. StopOptions(1);
  3672. end;
  3673. {$endif}
  3674. {$ifdef i8086}
  3675. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  3676. begin
  3677. Message(option_com_files_require_tiny_model);
  3678. StopOptions(1);
  3679. end;
  3680. {$endif i8086}
  3681. {$ifndef i8086_link_intern_debuginfo}
  3682. if (cs_debuginfo in init_settings.moduleswitches) and
  3683. (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) and
  3684. not (cs_link_extern in init_settings.globalswitches) then
  3685. begin
  3686. Message(option_debug_info_requires_external_linker);
  3687. include(init_settings.globalswitches,cs_link_extern);
  3688. end;
  3689. {$endif i8086_link_intern_debuginfo}
  3690. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  3691. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  3692. begin
  3693. { smartlink creation does not yet work with DWARF
  3694. debug info on most targets, but it works in internal assembler }
  3695. if (cs_create_smart in init_settings.moduleswitches) and
  3696. not (af_outputbinary in target_asm.flags) then
  3697. begin
  3698. Message(option_dwarf_smartlink_creation);
  3699. exclude(init_settings.moduleswitches,cs_create_smart);
  3700. end;
  3701. { smart linking does not yet work with DWARF debug info on most targets }
  3702. if (cs_link_smart in init_settings.globalswitches) then
  3703. begin
  3704. Message(option_dwarf_smart_linking);
  3705. ForceStaticLinking;
  3706. end;
  3707. end;
  3708. { external debug info is only supported for DWARF on darwin }
  3709. if (target_info.system in systems_darwin) and
  3710. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  3711. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  3712. begin
  3713. Message(option_debug_external_unsupported);
  3714. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  3715. end;
  3716. { Also create a smartlinked version, on an assembler that
  3717. does not support smartlink sections like nasm?
  3718. This is not compatible with using internal linker. }
  3719. if ((cs_link_smart in init_settings.globalswitches) or
  3720. (cs_create_smart in init_settings.moduleswitches)) and
  3721. (af_needar in target_asm.flags) and
  3722. not (af_smartlink_sections in target_asm.flags) and
  3723. not (cs_link_extern in init_settings.globalswitches) and
  3724. (target_info.link<>ld_none) and
  3725. not (cs_link_nolink in init_settings.globalswitches) then
  3726. begin
  3727. Message(option_smart_link_requires_external_linker);
  3728. include(init_settings.globalswitches,cs_link_extern);
  3729. end;
  3730. end;
  3731. constructor TOption.create;
  3732. begin
  3733. LogoWritten:=false;
  3734. NoPressEnter:=false;
  3735. FirstPass:=false;
  3736. ABISetExplicitly:=false;
  3737. FPUSetExplicitly:=false;
  3738. CPUSetExplicitly:=false;
  3739. OptCPUSetExplicitly:=false;
  3740. FileLevel:=0;
  3741. Quickinfo:='';
  3742. ParaIncludeCfgPath:=TSearchPathList.Create;
  3743. ParaIncludePath:=TSearchPathList.Create;
  3744. ParaObjectPath:=TSearchPathList.Create;
  3745. ParaUnitPath:=TSearchPathList.Create;
  3746. ParaLibraryPath:=TSearchPathList.Create;
  3747. ParaFrameworkPath:=TSearchPathList.Create;
  3748. parapackagepath:=TSearchPathList.Create;
  3749. parapackages:=TFPHashObjectList.Create;
  3750. paranamespaces:=TCmdStrList.Create;
  3751. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3752. MacVersionSet:=false;
  3753. paratarget:=system_none;
  3754. paratargetasm:=as_none;
  3755. paratargetdbg:=dbg_none;
  3756. LinkTypeSetExplicitly:=false;
  3757. LinkerSetExplicitly:=false;
  3758. end;
  3759. destructor TOption.destroy;
  3760. begin
  3761. ParaIncludeCfgPath.Free;
  3762. ParaIncludePath.Free;
  3763. ParaObjectPath.Free;
  3764. ParaUnitPath.Free;
  3765. ParaLibraryPath.Free;
  3766. ParaFrameworkPath.Free;
  3767. parapackagepath.Free;
  3768. ParaPackages.Free;
  3769. paranamespaces.free;
  3770. end;
  3771. {****************************************************************************
  3772. Callable Routines
  3773. ****************************************************************************}
  3774. function check_configfile(fn:string; var foundfn:string):boolean;
  3775. function CfgFileExists(const fn:string):boolean;
  3776. begin
  3777. Comment(V_Tried,'Configfile search: '+fn);
  3778. CfgFileExists:=FileExists(fn);
  3779. end;
  3780. var
  3781. {$ifdef Unix}
  3782. hs,
  3783. {$endif Unix}
  3784. configpath : string;
  3785. begin
  3786. foundfn:=fn;
  3787. check_configfile:=true;
  3788. { retrieve configpath }
  3789. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3790. {$ifdef Unix}
  3791. if configpath='' then
  3792. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3793. {$endif}
  3794. {
  3795. Order to read configuration file :
  3796. try reading fpc.cfg in :
  3797. 1 - current dir
  3798. 2 - configpath
  3799. 3 - compiler path
  3800. }
  3801. if not FileExists(fn) then
  3802. begin
  3803. {$ifdef Unix}
  3804. hs:=GetEnvironmentVariable('HOME');
  3805. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3806. foundfn:=FixPath(hs,false)+'.'+fn
  3807. else
  3808. {$endif}
  3809. if CfgFileExists(configpath+fn) then
  3810. foundfn:=configpath+fn
  3811. else
  3812. {$ifdef WINDOWS}
  3813. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3814. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3815. else
  3816. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3817. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3818. else
  3819. {$endif WINDOWS}
  3820. {$ifndef Unix}
  3821. if CfgFileExists(exepath+fn) then
  3822. foundfn:=exepath+fn
  3823. else
  3824. {$else}
  3825. if CfgFileExists('/etc/'+fn) then
  3826. foundfn:='/etc/'+fn
  3827. else
  3828. {$endif}
  3829. check_configfile:=false;
  3830. end;
  3831. end;
  3832. procedure read_arguments(cmd:TCmdStr);
  3833. procedure def_cpu_macros;
  3834. var
  3835. abi : tabi;
  3836. fputype : tfputype;
  3837. cputype : tcputype;
  3838. controller: tcontrollertype;
  3839. s: string;
  3840. begin
  3841. {$ifdef llvm}
  3842. def_system_macro('CPULLVM');
  3843. {$endif}
  3844. for cputype:=low(tcputype) to high(tcputype) do
  3845. undef_system_macro('CPU'+Cputypestr[cputype]);
  3846. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3847. for fputype:=low(tfputype) to high(tfputype) do
  3848. undef_system_macro('FPU'+fputypestr[fputype]);
  3849. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3850. {$PUSH}
  3851. {$WARN 6018 OFF} { Unreachable code due to compile time evaluation }
  3852. if ControllerSupport then
  3853. begin
  3854. for controller:=low(tcontrollertype) to high(tcontrollertype) do
  3855. begin
  3856. s:=embedded_controllers[controller].controllertypestr;
  3857. if s<>'' then
  3858. undef_system_macro('FPC_MCU_'+s);
  3859. end;
  3860. s:=embedded_controllers[init_settings.controllertype].controllertypestr;
  3861. if s<>'' then
  3862. def_system_macro('FPC_MCU_'+s);
  3863. end;
  3864. {$POP}
  3865. { define abi }
  3866. for abi:=low(tabi) to high(tabi) do
  3867. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3868. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3869. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3870. systems since most code needs to behave the same on both}
  3871. if target_info.abi = abi_eabihf then
  3872. def_system_macro('FPC_ABI_EABI');
  3873. { using a case is pretty useless here (FK) }
  3874. { some stuff for TP compatibility }
  3875. {$ifdef i386}
  3876. def_system_macro('CPU86');
  3877. def_system_macro('CPU87');
  3878. def_system_macro('CPU386');
  3879. {$endif}
  3880. { new processor stuff }
  3881. {$ifdef i386}
  3882. def_system_macro('CPUI386');
  3883. def_system_macro('CPU32');
  3884. def_system_macro('CPUX86');
  3885. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3886. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3887. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3888. {$endif}
  3889. {$ifdef m68k}
  3890. def_system_macro('CPU68');
  3891. def_system_macro('CPU68K');
  3892. def_system_macro('CPUM68K');
  3893. def_system_macro('CPU32');
  3894. def_system_macro('FPC_CURRENCY_IS_INT64');
  3895. def_system_macro('FPC_COMP_IS_INT64');
  3896. {$endif}
  3897. {$ifdef powerpc}
  3898. def_system_macro('CPUPOWERPC');
  3899. def_system_macro('CPUPOWERPC32');
  3900. def_system_macro('CPU32');
  3901. def_system_macro('FPC_CURRENCY_IS_INT64');
  3902. def_system_macro('FPC_COMP_IS_INT64');
  3903. {$endif}
  3904. {$ifdef POWERPC64}
  3905. def_system_macro('CPUPOWERPC');
  3906. def_system_macro('CPUPOWERPC64');
  3907. def_system_macro('CPU64');
  3908. def_system_macro('FPC_CURRENCY_IS_INT64');
  3909. def_system_macro('FPC_COMP_IS_INT64');
  3910. {$endif}
  3911. {$ifdef x86_64}
  3912. def_system_macro('CPUX86_64');
  3913. def_system_macro('CPUAMD64');
  3914. def_system_macro('CPU64');
  3915. def_system_macro('CPUX64');
  3916. { not supported for now, afaik (FK)
  3917. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3918. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3919. { normally, win64 doesn't support the legacy fpu }
  3920. if target_info.system=system_x86_64_win64 then
  3921. begin
  3922. def_system_macro('FPC_CURRENCY_IS_INT64');
  3923. def_system_macro('FPC_COMP_IS_INT64');
  3924. end;
  3925. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3926. {$endif}
  3927. {$ifdef sparc}
  3928. def_system_macro('CPUSPARCGEN');
  3929. def_system_macro('CPUSPARC');
  3930. def_system_macro('CPUSPARC32');
  3931. def_system_macro('CPU32');
  3932. def_system_macro('FPC_CURRENCY_IS_INT64');
  3933. def_system_macro('FPC_COMP_IS_INT64');
  3934. {$endif}
  3935. {$ifdef sparc64}
  3936. def_system_macro('CPUSPARCGEN');
  3937. def_system_macro('CPUSPARC64');
  3938. def_system_macro('CPU64');
  3939. def_system_macro('FPC_CURRENCY_IS_INT64');
  3940. def_system_macro('FPC_COMP_IS_INT64');
  3941. {$endif}
  3942. {$ifdef arm}
  3943. def_system_macro('CPUARM');
  3944. def_system_macro('CPU32');
  3945. def_system_macro('FPC_CURRENCY_IS_INT64');
  3946. def_system_macro('FPC_COMP_IS_INT64');
  3947. {$endif arm}
  3948. {$ifdef avr}
  3949. def_system_macro('CPUAVR');
  3950. def_system_macro('CPU16');
  3951. def_system_macro('FPC_CURRENCY_IS_INT64');
  3952. def_system_macro('FPC_COMP_IS_INT64');
  3953. {$endif avr}
  3954. {$ifdef jvm}
  3955. def_system_macro('CPUJVM');
  3956. def_system_macro('CPU32');
  3957. def_system_macro('FPC_CURRENCY_IS_INT64');
  3958. def_system_macro('FPC_COMP_IS_INT64');
  3959. {$endif jvm}
  3960. {$ifdef mipsel}
  3961. def_system_macro('CPUMIPS');
  3962. def_system_macro('CPUMIPS32');
  3963. def_system_macro('CPUMIPSEL');
  3964. def_system_macro('CPUMIPSEL32');
  3965. def_system_macro('CPU32');
  3966. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3967. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3968. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3969. def_system_macro('FPC_CURRENCY_IS_INT64');
  3970. def_system_macro('FPC_COMP_IS_INT64');
  3971. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3972. { On most systems, locals are accessed relative to base pointer,
  3973. but for MIPS cpu, they are accessed relative to stack pointer.
  3974. This needs adaptation for so low level routines,
  3975. like MethodPointerLocal and related objects unit functions. }
  3976. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3977. {$endif mipsel}
  3978. {$ifdef mipseb}
  3979. def_system_macro('CPUMIPS');
  3980. def_system_macro('CPUMIPS32');
  3981. def_system_macro('CPUMIPSEB');
  3982. def_system_macro('CPUMIPSEB32');
  3983. def_system_macro('CPU32');
  3984. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3985. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3986. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3987. def_system_macro('FPC_CURRENCY_IS_INT64');
  3988. def_system_macro('FPC_COMP_IS_INT64');
  3989. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3990. { See comment above for mipsel }
  3991. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3992. {$endif}
  3993. {$ifdef i8086}
  3994. def_system_macro('CPU86'); { Borland compatibility }
  3995. def_system_macro('CPU87'); { Borland compatibility }
  3996. def_system_macro('CPUI8086');
  3997. def_system_macro('CPU16');
  3998. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3999. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4000. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4001. case init_settings.x86memorymodel of
  4002. mm_tiny: def_system_macro('FPC_MM_TINY');
  4003. mm_small: def_system_macro('FPC_MM_SMALL');
  4004. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  4005. mm_compact: def_system_macro('FPC_MM_COMPACT');
  4006. mm_large: def_system_macro('FPC_MM_LARGE');
  4007. mm_huge: def_system_macro('FPC_MM_HUGE');
  4008. end;
  4009. {$endif i8086}
  4010. {$ifdef aarch64}
  4011. def_system_macro('CPUAARCH64');
  4012. def_system_macro('CPU64');
  4013. def_system_macro('FPC_CURRENCY_IS_INT64');
  4014. def_system_macro('FPC_COMP_IS_INT64');
  4015. {$endif aarch64}
  4016. {$ifdef riscv32}
  4017. def_system_macro('CPURISCV');
  4018. def_system_macro('CPURISCV32');
  4019. def_system_macro('CPU32');
  4020. def_system_macro('FPC_CURRENCY_IS_INT64');
  4021. def_system_macro('FPC_COMP_IS_INT64');
  4022. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4023. {$endif riscv32}
  4024. {$ifdef riscv64}
  4025. def_system_macro('CPURISCV');
  4026. def_system_macro('CPURISCV64');
  4027. def_system_macro('CPU64');
  4028. def_system_macro('FPC_CURRENCY_IS_INT64');
  4029. def_system_macro('FPC_COMP_IS_INT64');
  4030. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4031. {$endif riscv64}
  4032. {$ifdef xtensa}
  4033. def_system_macro('CPUXTENSA');
  4034. def_system_macro('CPU32');
  4035. def_system_macro('FPC_CURRENCY_IS_INT64');
  4036. def_system_macro('FPC_COMP_IS_INT64');
  4037. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  4038. {$endif xtensa}
  4039. {$ifdef z80}
  4040. def_system_macro('CPUZ80');
  4041. def_system_macro('CPU16');
  4042. def_system_macro('FPC_CURRENCY_IS_INT64');
  4043. def_system_macro('FPC_COMP_IS_INT64');
  4044. {$endif z80}
  4045. {$ifdef wasm32}
  4046. def_system_macro('CPUWASM');
  4047. def_system_macro('CPUWASM32');
  4048. def_system_macro('CPU32');
  4049. def_system_macro('FPC_CURRENCY_IS_INT64');
  4050. def_system_macro('FPC_COMP_IS_INT64');
  4051. {$endif wasm32}
  4052. {$if defined(cpu8bitalu)}
  4053. def_system_macro('CPUINT8');
  4054. {$elseif defined(cpu16bitalu)}
  4055. def_system_macro('CPUINT16');
  4056. {$elseif defined(cpu32bitalu)}
  4057. def_system_macro('CPUINT32');
  4058. {$elseif defined(cpu64bitalu)}
  4059. def_system_macro('CPUINT64');
  4060. {$endif defined(cpu64bitalu)}
  4061. {$if defined(avr)}
  4062. def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
  4063. {$endif}
  4064. {$if defined(i8086) or defined(avr)}
  4065. def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
  4066. {$endif i8086 or avr}
  4067. { abs(long) is handled internally on all CPUs }
  4068. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  4069. {$if defined(i8086) or defined(i386) or defined(x86_64) or defined(powerpc64) or defined(aarch64)}
  4070. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  4071. {$endif i8086 or i386 or x86_64 or powerpc64 or aarch64}
  4072. def_system_macro('FPC_HAS_UNICODESTRING');
  4073. def_system_macro('FPC_RTTI_PACKSET1');
  4074. def_system_macro('FPC_HAS_CPSTRING');
  4075. {$ifdef x86_64}
  4076. def_system_macro('FPC_HAS_RIP_RELATIVE');
  4077. {$endif x86_64}
  4078. def_system_macro('FPC_HAS_CEXTENDED');
  4079. def_system_macro('FPC_HAS_RESSTRINITS');
  4080. { these cpus have an inline rol/ror implementaion }
  4081. {$ifdef cpurox}
  4082. {$ifdef m68k}
  4083. if CPUM68K_HAS_ROLROR in cpu_capabilities[init_settings.cputype] then
  4084. def_system_macro('FPC_HAS_INTERNAL_ROX');
  4085. {$else}
  4086. def_system_macro('FPC_HAS_INTERNAL_ROX');
  4087. {$endif}
  4088. {$endif}
  4089. {$ifdef powerpc64}
  4090. def_system_macro('FPC_HAS_LWSYNC');
  4091. {$endif}
  4092. { currently, all supported CPUs have an internal sar implementation }
  4093. def_system_macro('FPC_HAS_INTERNAL_SAR');
  4094. {$ifdef SUPPORT_GET_FRAME}
  4095. def_system_macro('INTERNAL_BACKTRACE');
  4096. {$endif SUPPORT_GET_FRAME}
  4097. def_system_macro('STR_CONCAT_PROCS');
  4098. {$warnings off}
  4099. if pocall_default = pocall_register then
  4100. def_system_macro('REGCALL');
  4101. {$warnings on}
  4102. end;
  4103. var
  4104. env: ansistring;
  4105. i : tfeature;
  4106. j : longint;
  4107. tmplist : TCmdStrList;
  4108. cmditem,
  4109. tmpcmditem : TCmdStrListItem;
  4110. cmdstr : TCmdStr;
  4111. {$if defined(cpucapabilities)}
  4112. cpuflag : tcpuflags;
  4113. {$endif defined(cpucapabilities)}
  4114. {$if defined(fpucapabilities)}
  4115. fpuflag : tfpuflags;
  4116. {$endif defined(fpucapabilities)}
  4117. {$if defined(cpucapabilities) or defined(fpucapabilities)}
  4118. hs : string;
  4119. {$endif defined(cpucapabilities) or defined(fpucapabilities)}
  4120. begin
  4121. option:=coption.create;
  4122. disable_configfile:=false;
  4123. { Non-core target defines }
  4124. Option.TargetOptions(true);
  4125. { get default messagefile }
  4126. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  4127. { default configfile can be specified on the commandline,
  4128. remove it first }
  4129. if (cmd<>'') and (cmd[1]='[') then
  4130. begin
  4131. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  4132. Delete(cmd,1,pos(']',cmd));
  4133. end
  4134. else
  4135. ppccfg:='fpc.cfg';
  4136. { first pass reading of parameters, only -i -v -T etc.}
  4137. option.firstpass:=true;
  4138. if cmd<>'' then
  4139. option.parsecmd(cmd)
  4140. else
  4141. begin
  4142. option.read_parameters;
  4143. { Write only quickinfo }
  4144. if option.quickinfo<>'' then
  4145. option.writequickinfo;
  4146. end;
  4147. option.firstpass:=false;
  4148. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  4149. Option.TargetOptions(true);
  4150. { target is set here, for wince the default app type is gui }
  4151. if target_info.system in systems_wince then
  4152. SetApptype(app_gui)
  4153. else
  4154. SetApptype(apptype);
  4155. { default defines }
  4156. def_system_macro(target_info.shortname);
  4157. def_system_macro('FPC');
  4158. def_system_macro('VER'+version_nr);
  4159. def_system_macro('VER'+version_nr+'_'+release_nr);
  4160. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  4161. { Temporary defines, until things settle down }
  4162. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  4163. def_system_macro('FPC_HAS_CONSTREF');
  4164. def_system_macro('FPC_STATICRIPFIXED');
  4165. def_system_macro('FPC_VARIANTCOPY_FIXED');
  4166. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  4167. def_system_macro('FPC_HAS_MEMBAR');
  4168. def_system_macro('FPC_SETBASE_USED');
  4169. def_system_macro('FPC_ALIGNED_THREADVARTABLES');
  4170. { don't remove this, it's also for fpdoc necessary (FK) }
  4171. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  4172. { make cpu makros available when reading the config files the second time }
  4173. def_cpu_macros;
  4174. if tf_cld in target_info.flags then
  4175. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  4176. InternalError(2013092801);
  4177. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  4178. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  4179. InternalError(2013092802);
  4180. { Use standard Android NDK prefixes when cross-compiling }
  4181. if (source_info.system<>target_info.system) and (target_info.system in systems_android) then
  4182. case target_info.system of
  4183. system_arm_android:
  4184. utilsprefix:='arm-linux-androideabi-';
  4185. system_i386_android:
  4186. utilsprefix:='i686-linux-android-';
  4187. else
  4188. utilsprefix:=target_cpu_string + '-linux-android-';
  4189. end;
  4190. { Set up default value for the heap }
  4191. if target_info.system in (systems_embedded+systems_freertos+[system_z80_zxspectrum,system_z80_msxdos]) then
  4192. begin
  4193. case target_info.system of
  4194. {$ifdef AVR}
  4195. system_avr_embedded:
  4196. if init_settings.controllertype=ct_avrsim then
  4197. heapsize:=8192
  4198. else
  4199. heapsize:=128;
  4200. {$endif AVR}
  4201. system_arm_freertos:
  4202. heapsize:=8192;
  4203. system_xtensa_freertos:
  4204. { keep default value }
  4205. ;
  4206. system_arm_embedded:
  4207. heapsize:=256;
  4208. system_mipsel_embedded:
  4209. heapsize:=256;
  4210. else
  4211. heapsize:=256;
  4212. end;
  4213. end;
  4214. { read configuration file }
  4215. if (not disable_configfile) and
  4216. (ppccfg<>'') then
  4217. read_configfile:=check_configfile(ppccfg,ppccfg)
  4218. else
  4219. read_configfile := false;
  4220. { Read commandline and configfile }
  4221. param_file:='';
  4222. { read configfile }
  4223. if read_configfile then
  4224. option.interpret_file(ppccfg);
  4225. { read parameters again to override config file }
  4226. if cmd<>'' then
  4227. option.parsecmd(cmd)
  4228. else
  4229. begin
  4230. { Write help pages if no parameters are passed }
  4231. if (paramcount=0) then
  4232. Option.WriteHelpPages;
  4233. option.read_parameters;
  4234. { Write only quickinfo }
  4235. if option.quickinfo<>'' then
  4236. option.writequickinfo;
  4237. end;
  4238. { check the compatibility of different options and adjust them if necessary
  4239. (and print possible errors)
  4240. }
  4241. option.checkoptionscompatibility;
  4242. { uses the CPUXXX-defines and target_info to determine whether the selected
  4243. target processor, if any, is supported }
  4244. Option.VerifyTargetProcessor;
  4245. { Stop if errors in options }
  4246. if ErrorCount>0 then
  4247. StopOptions(1);
  4248. { endian define }
  4249. case target_info.endian of
  4250. endian_little :
  4251. begin
  4252. def_system_macro('ENDIAN_LITTLE');
  4253. def_system_macro('FPC_LITTLE_ENDIAN');
  4254. end;
  4255. endian_big :
  4256. begin
  4257. def_system_macro('ENDIAN_BIG');
  4258. def_system_macro('FPC_BIG_ENDIAN');
  4259. end;
  4260. end;
  4261. { Write logo }
  4262. if option.ParaLogo then
  4263. option.writelogo;
  4264. { Check file to compile }
  4265. if param_file='' then
  4266. begin
  4267. Message(option_no_source_found);
  4268. StopOptions(1);
  4269. end;
  4270. {$ifndef Unix}
  4271. param_file:=FixFileName(param_file);
  4272. {$endif not unix}
  4273. inputfilepath:=ExtractFilePath(param_file);
  4274. inputfilename:=ExtractFileName(param_file);
  4275. if ExtractFileExt(inputfilename)='' then
  4276. begin
  4277. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  4278. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  4279. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  4280. inputfilename:=ChangeFileExt(inputfilename,pasext)
  4281. else if ((m_mac in current_settings.modeswitches) or
  4282. (tf_p_ext_support in target_info.flags))
  4283. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  4284. inputfilename:=ChangeFileExt(inputfilename,pext);
  4285. end;
  4286. { Check output dir }
  4287. if (OutputExeDir<>'') and
  4288. not PathExists(OutputExeDir,false) then
  4289. begin
  4290. Message1(general_e_path_does_not_exist,OutputExeDir);
  4291. StopOptions(1);
  4292. end;
  4293. { Add paths specified with parameters to the searchpaths }
  4294. UnitSearchPath.AddList(option.ParaUnitPath,true);
  4295. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  4296. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  4297. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  4298. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  4299. packagesearchpath.addlist(option.parapackagepath,true);
  4300. for j:=0 to option.parapackages.count-1 do
  4301. add_package(option.parapackages.NameOfIndex(j),true,true);
  4302. { add default namespaces }
  4303. tmplist:=TCmdStrList.Create;
  4304. cmditem:=TCmdStrListItem(option.paranamespaces.First);
  4305. while assigned(cmditem) do
  4306. begin
  4307. { use a temporary list cause if ";" are involved we need to reverse the
  4308. order due to how TCmdStrList behaves }
  4309. cmdstr:=cmditem.str;
  4310. repeat
  4311. j:=Pos(';',cmdstr);
  4312. if j>0 then
  4313. begin
  4314. tmplist.insert(copy(cmdstr,1,j-1));
  4315. delete(cmdstr,1,j);
  4316. end
  4317. else
  4318. tmplist.insert(cmdstr);
  4319. until j=0;
  4320. tmpcmditem:=TCmdStrListItem(tmplist.First);
  4321. while assigned(tmpcmditem) do
  4322. begin
  4323. namespacelist.insert(tmpcmditem.Str);
  4324. tmpcmditem:=TCmdStrListItem(tmpcmditem.Next);
  4325. end;
  4326. tmplist.clear;
  4327. cmditem:=TCmdStrListItem(cmditem.Next);
  4328. end;
  4329. tmplist.Free;
  4330. { add unit environment and exepath to the unit search path }
  4331. if inputfilepath<>'' then
  4332. Unitsearchpath.AddPath(inputfilepath,true);
  4333. if not disable_configfile then
  4334. begin
  4335. env:=GetEnvironmentVariable(target_info.unit_env);
  4336. if env<>'' then
  4337. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  4338. end;
  4339. {$ifdef Unix}
  4340. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  4341. if fpcdir='' then
  4342. begin
  4343. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  4344. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  4345. else
  4346. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  4347. end;
  4348. {$else unix}
  4349. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  4350. if fpcdir='' then
  4351. begin
  4352. fpcdir:=ExePath+'../';
  4353. if not(PathExists(fpcdir+'units',true)) and
  4354. not(PathExists(fpcdir+'rtl',true)) then
  4355. fpcdir:=fpcdir+'../';
  4356. end;
  4357. {$endif unix}
  4358. { first try development RTL, else use the default installation path }
  4359. if not disable_configfile then
  4360. begin
  4361. if PathExists(FpcDir+'rtl',true) then
  4362. if (tf_use_8_3 in Source_Info.Flags) or
  4363. (tf_use_8_3 in Target_Info.Flags) then
  4364. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  4365. else
  4366. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  4367. else
  4368. if (tf_use_8_3 in Source_Info.Flags) or
  4369. (tf_use_8_3 in Target_Info.Flags) then
  4370. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  4371. else
  4372. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  4373. end;
  4374. { Add exepath if the exe is not in the current dir, because that is always searched already.
  4375. Do not add it when linking on the target because then we can maybe already find
  4376. .o files that are not for the target }
  4377. if (ExePath<>cfileutl.GetCurrentDir) and
  4378. not(cs_link_on_target in init_settings.globalswitches) then
  4379. UnitSearchPath.AddPath(ExePath,false);
  4380. { Add unit dir to the object and library path }
  4381. objectsearchpath.AddList(unitsearchpath,false);
  4382. librarysearchpath.AddList(unitsearchpath,false);
  4383. {$ifdef llvm}
  4384. { default to clang }
  4385. if (option.paratargetasm=as_none) then
  4386. begin
  4387. option.paratargetasm:=as_clang_llvm;
  4388. end;
  4389. {$endif llvm}
  4390. { maybe override assembler }
  4391. if (option.paratargetasm<>as_none) then
  4392. begin
  4393. if (option.paratargetasm=as_default) then
  4394. begin
  4395. option.paratargetasm:=target_info.assem;
  4396. end;
  4397. if not set_target_asm(option.paratargetasm) then
  4398. begin
  4399. if assigned(asminfos[option.paratargetasm]) then
  4400. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name)
  4401. else
  4402. Message2(option_incompatible_asm,'<invalid assembler>',target_info.name);
  4403. set_target_asm(target_info.assemextern);
  4404. Message1(option_asm_forced,target_asm.idtxt);
  4405. end;
  4406. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  4407. (option.paratargetdbg<>dbg_none) then
  4408. begin
  4409. Message1(option_confict_asm_debug,
  4410. asminfos[option.paratargetasm]^.idtxt);
  4411. option.paratargetdbg:=dbg_none;
  4412. exclude(init_settings.moduleswitches,cs_debuginfo);
  4413. end;
  4414. { Some assemblers, like clang, do not support
  4415. stabs debugging format, switch to dwardé in that case }
  4416. if (af_no_stabs in asminfos[option.paratargetasm]^.flags) and
  4417. (option.paratargetdbg=dbg_stabs) then
  4418. begin
  4419. option.paratargetdbg:=dbg_dwarf2;
  4420. end;
  4421. end;
  4422. {TOptionheck a second time as we might have changed assembler just above }
  4423. option.checkoptionscompatibility;
  4424. { maybe override debug info format }
  4425. if (option.paratargetdbg<>dbg_none) then
  4426. if not set_target_dbg(option.paratargetdbg) then
  4427. Message(option_w_unsupported_debug_format);
  4428. { switch assembler if it's binary and we got -a on the cmdline }
  4429. if (af_outputbinary in target_asm.flags) and
  4430. ((cs_asm_leave in init_settings.globalswitches) or
  4431. { if -s is passed, we shouldn't call the internal assembler }
  4432. (cs_asm_extern in init_settings.globalswitches)) then
  4433. begin
  4434. Message(option_switch_bin_to_src_assembler);
  4435. {$ifdef llvm}
  4436. set_target_asm(as_clang_llvm);
  4437. {$else}
  4438. set_target_asm(target_info.assemextern);
  4439. {$endif}
  4440. { At least i8086 needs that for nasm and -CX
  4441. which is incompatible with internal linker }
  4442. option.checkoptionscompatibility;
  4443. end;
  4444. { Force use of external linker if there is no
  4445. internal linker or the linking is skipped }
  4446. if not(cs_link_extern in init_settings.globalswitches) and
  4447. ((target_info.link=ld_none) or
  4448. (cs_link_nolink in init_settings.globalswitches)) then
  4449. begin
  4450. include(init_settings.globalswitches,cs_link_extern);
  4451. end;
  4452. { turn off stripping if compiling with debuginfo or profile }
  4453. if (
  4454. (cs_debuginfo in init_settings.moduleswitches) or
  4455. (cs_profile in init_settings.moduleswitches)
  4456. ) and
  4457. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  4458. exclude(init_settings.globalswitches,cs_link_strip);
  4459. { choose a reasonable tls model }
  4460. if (tf_section_threadvars in target_info.flags) and (init_settings.tlsmodel=tlsm_none) then
  4461. begin
  4462. if cs_create_pic in init_settings.moduleswitches then
  4463. init_settings.tlsmodel:=tlsm_global_dynamic
  4464. else
  4465. init_settings.tlsmodel:=tlsm_local_exec;
  4466. end;
  4467. { set Mac OS X version default macros if not specified explicitly }
  4468. option.MaybeSetDefaultMacVersionMacro;
  4469. {$ifdef XTENSA}
  4470. { set ESP32 or ESP8266 default SDK versions }
  4471. option.MaybeSetIdfVersionMacro;
  4472. {$endif XTENSA}
  4473. {$ifdef cpufpemu}
  4474. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  4475. if fpu type not explicitly set }
  4476. if not(option.FPUSetExplicitly) and
  4477. ((target_info.system in [system_arm_wince,system_arm_gba,
  4478. system_m68k_amiga,system_m68k_atari,
  4479. system_arm_nds,system_arm_embedded,system_arm_freertos,
  4480. system_riscv32_embedded,system_riscv64_embedded,system_xtensa_linux,
  4481. system_z80_embedded,system_z80_zxspectrum])
  4482. {$ifdef arm}
  4483. or (target_info.abi=abi_eabi)
  4484. {$endif arm}
  4485. )
  4486. or (init_settings.fputype=fpu_soft)
  4487. then
  4488. begin
  4489. include(init_settings.moduleswitches,cs_fp_emulation);
  4490. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  4491. init_settings.fputype:=fpu_soft;
  4492. end;
  4493. {$endif cpufpemu}
  4494. {$ifdef i386}
  4495. if target_info.system in systems_i386_default_486 then
  4496. begin
  4497. { Avoid use of MMX/CMOVcc instructions on older systems.
  4498. Some systems might not handle these instructions correctly,
  4499. Used emulators might also be problematic. PM }
  4500. if not option.CPUSetExplicitly then
  4501. init_settings.cputype:=cpu_486;
  4502. end;
  4503. case target_info.system of
  4504. system_i386_android:
  4505. begin
  4506. { set default cpu type to PentiumM for Android unless specified otherwise }
  4507. if not option.CPUSetExplicitly then
  4508. init_settings.cputype:=cpu_PentiumM;
  4509. if not option.OptCPUSetExplicitly then
  4510. init_settings.optimizecputype:=cpu_PentiumM;
  4511. { set default fpu type to SSSE3 for Android unless specified otherwise }
  4512. if not option.FPUSetExplicitly then
  4513. init_settings.fputype:=fpu_ssse3;
  4514. end;
  4515. else
  4516. ;
  4517. end;
  4518. {$endif i386}
  4519. {$ifdef xtensa}
  4520. { xtensa-linux target does not support controller setting option -Wp }
  4521. if not(option.FPUSetExplicitly) and not(target_info.system = system_xtensa_linux) then
  4522. begin
  4523. init_settings.fputype:=embedded_controllers[init_settings.controllertype].fputype;
  4524. if (init_settings.fputype=fpu_soft) then
  4525. include(init_settings.moduleswitches,cs_fp_emulation);
  4526. end;
  4527. if not(option.CPUSetExplicitly) and (target_info.system=system_xtensa_linux) then
  4528. init_settings.cputype:=cpu_lx6;
  4529. if (target_info.system in [system_xtensa_embedded,system_xtensa_freertos]) and not(option.ABISetExplicitly) then
  4530. begin
  4531. if CPUXTENSA_REGWINDOW in cpu_capabilities[init_settings.cputype] then
  4532. target_info.abi:=abi_xtensa_windowed
  4533. else
  4534. target_info.abi:=abi_xtensa_call0;
  4535. end;
  4536. {$endif xtensa}
  4537. {$ifdef arm}
  4538. case target_info.system of
  4539. system_arm_ios:
  4540. begin
  4541. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  4542. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  4543. }
  4544. if not option.CPUSetExplicitly then
  4545. init_settings.cputype:=cpu_armv7;
  4546. if not option.OptCPUSetExplicitly then
  4547. init_settings.optimizecputype:=cpu_armv7;
  4548. if not option.FPUSetExplicitly then
  4549. init_settings.fputype:=fpu_vfpv3;
  4550. end;
  4551. system_arm_android:
  4552. begin
  4553. { set default cpu type to ARMv5T for Android unless specified otherwise }
  4554. if not option.CPUSetExplicitly then
  4555. init_settings.cputype:=cpu_armv5t;
  4556. if not option.OptCPUSetExplicitly then
  4557. init_settings.optimizecputype:=cpu_armv5t;
  4558. end;
  4559. else
  4560. ;
  4561. end;
  4562. { set ABI defaults }
  4563. case target_info.abi of
  4564. abi_eabihf:
  4565. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  4566. begin
  4567. {$ifdef CPUARMV6}
  4568. { if the compiler is built for armv6, then
  4569. inherit this setting, e.g. Raspian is armhf but
  4570. only armv6, this makes rebuilds of the compiler
  4571. easier }
  4572. if not option.CPUSetExplicitly then
  4573. init_settings.cputype:=cpu_armv6;
  4574. if not option.OptCPUSetExplicitly then
  4575. init_settings.optimizecputype:=cpu_armv6;
  4576. {$else CPUARMV6}
  4577. if not option.CPUSetExplicitly then
  4578. init_settings.cputype:=cpu_armv7a;
  4579. if not option.OptCPUSetExplicitly then
  4580. init_settings.optimizecputype:=cpu_armv7a;
  4581. {$endif CPUARMV6}
  4582. { Set FPU type }
  4583. if not(option.FPUSetExplicitly) then
  4584. begin
  4585. if init_settings.cputype < cpu_armv7 then
  4586. init_settings.fputype:=fpu_vfpv2
  4587. else
  4588. init_settings.fputype:=fpu_vfpv3_d16;
  4589. end
  4590. else
  4591. begin
  4592. if (not(FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[init_settings.fputype]))
  4593. or (target_info.system = system_arm_ios) then
  4594. begin
  4595. Message(option_illegal_fpu_eabihf);
  4596. StopOptions(1);
  4597. end;
  4598. end;
  4599. end;
  4600. abi_eabi:
  4601. begin
  4602. if target_info.system=system_arm_linux then
  4603. begin
  4604. { this is what Debian uses }
  4605. if not option.CPUSetExplicitly then
  4606. init_settings.cputype:=cpu_armv4t;
  4607. if not option.OptCPUSetExplicitly then
  4608. init_settings.optimizecputype:=cpu_armv4t;
  4609. if not(option.FPUSetExplicitly) then
  4610. init_settings.fputype:=fpu_soft;
  4611. end;
  4612. end;
  4613. else
  4614. ;
  4615. end;
  4616. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4617. begin
  4618. def_system_macro('CPUTHUMB');
  4619. if not option.FPUSetExplicitly then
  4620. init_settings.fputype:=fpu_soft;
  4621. if not(init_settings.fputype in [fpu_none,fpu_soft,fpu_libgcc]) then
  4622. Message2(option_unsupported_fpu,fputypestr[init_settings.fputype],'Thumb');
  4623. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  4624. 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';
  4625. {$else FPC_ARMAL or FPC_ARMHF}
  4626. if target_info.endian=endian_little then
  4627. 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';
  4628. {$endif FPC_ARMAL or FPC_ARMHF}
  4629. end;
  4630. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4631. def_system_macro('CPUTHUMB2');
  4632. {$endif arm}
  4633. {$ifdef aarch64}
  4634. case target_info.system of
  4635. system_aarch64_darwin:
  4636. begin
  4637. if not option.CPUSetExplicitly then
  4638. init_settings.cputype:=cpu_armv84a;
  4639. if not option.OptCPUSetExplicitly then
  4640. init_settings.optimizecputype:=cpu_armv84a;
  4641. end;
  4642. else
  4643. ;
  4644. end;
  4645. {$endif aarch64}
  4646. {$if defined(riscv32) or defined(riscv64)}
  4647. { RISC-V defaults }
  4648. if (target_info.abi = abi_riscv_hf) then
  4649. begin
  4650. {$ifdef riscv32}
  4651. if not option.CPUSetExplicitly then
  4652. init_settings.cputype:=cpu_rv32ima;
  4653. if not option.OptCPUSetExplicitly then
  4654. init_settings.optimizecputype:=cpu_rv32ima;
  4655. {$else}
  4656. if not option.CPUSetExplicitly then
  4657. init_settings.cputype:=cpu_rv64imac;
  4658. if not option.OptCPUSetExplicitly then
  4659. init_settings.optimizecputype:=cpu_rv64imac;
  4660. {$endif}
  4661. { Set FPU type }
  4662. if not(option.FPUSetExplicitly) then
  4663. init_settings.fputype:=fpu_fd
  4664. else
  4665. begin
  4666. if not (init_settings.fputype in [fpu_fd]) then
  4667. begin
  4668. Message(option_illegal_fpu_eabihf);
  4669. StopOptions(1);
  4670. end;
  4671. end;
  4672. end;
  4673. {$endif defined(riscv32) or defined(riscv64)}
  4674. {$ifdef jvm}
  4675. { set default CPU type to Dalvik when targeting Android }
  4676. if target_info.system=system_jvm_android32 then
  4677. begin
  4678. if not option.CPUSetExplicitly then
  4679. init_settings.cputype:=cpu_dalvik;
  4680. end;
  4681. {$endif jvm}
  4682. {$ifdef llvm}
  4683. { standard extension for llvm bitcode files }
  4684. target_info.asmext:='.ll';
  4685. { don't generate dwarf cfi, llvm will do that }
  4686. exclude(target_info.flags,tf_needs_dwarf_cfi);
  4687. {$endif llvm}
  4688. {$ifdef mipsel}
  4689. case target_info.system of
  4690. system_mipsel_android:
  4691. begin
  4692. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  4693. if not option.CPUSetExplicitly then
  4694. init_settings.cputype:=cpu_mips32;
  4695. if not option.OptCPUSetExplicitly then
  4696. init_settings.optimizecputype:=cpu_mips32;
  4697. if not option.FPUSetExplicitly then
  4698. init_settings.fputype:=fpu_mips2;
  4699. end;
  4700. system_mipsel_embedded:
  4701. begin
  4702. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  4703. if not option.CPUSetExplicitly then
  4704. init_settings.cputype:=cpu_pic32mx;
  4705. if not option.OptCPUSetExplicitly then
  4706. init_settings.optimizecputype:=cpu_pic32mx;
  4707. if not option.FPUSetExplicitly then
  4708. init_settings.fputype:=fpu_soft;
  4709. end;
  4710. else
  4711. ;
  4712. end;
  4713. {$endif mipsel}
  4714. {$ifdef m68k}
  4715. if init_settings.cputype in cpu_coldfire then
  4716. def_system_macro('CPUCOLDFIRE');
  4717. case target_info.system of
  4718. system_m68k_linux,
  4719. system_m68k_netbsd:
  4720. begin
  4721. if not (option.FPUSetExplicitly) and
  4722. not (init_settings.cputype in cpu_coldfire) then
  4723. begin
  4724. { enable HW FPU for UNIX by default, but only for
  4725. original 68k, not Coldfire }
  4726. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4727. init_settings.fputype:=fpu_68881;
  4728. end;
  4729. end;
  4730. system_m68k_sinclairql:
  4731. begin
  4732. if not option.CPUSetExplicitly then
  4733. init_settings.cputype:=cpu_mc68000;
  4734. end;
  4735. system_m68k_palmos:
  4736. begin
  4737. if not option.CPUSetExplicitly then
  4738. init_settings.cputype:=cpu_mc68000;
  4739. if not (option.FPUSetExplicitly) then
  4740. begin
  4741. { No FPU for PalmOS by default }
  4742. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4743. init_settings.fputype:=fpu_none;
  4744. end;
  4745. end;
  4746. else
  4747. ;
  4748. end;
  4749. {$endif m68k}
  4750. {$ifdef wasm}
  4751. { if no explicit exception handling mode is set for WebAssembly, assume no exceptions }
  4752. if init_settings.targetswitches*[ts_wasm_no_exceptions,ts_wasm_js_exceptions,ts_wasm_native_exceptions,ts_wasm_bf_exceptions]=[] then
  4753. begin
  4754. def_system_macro(TargetSwitchStr[ts_wasm_no_exceptions].define);
  4755. include(init_settings.targetswitches,ts_wasm_no_exceptions);
  4756. end;
  4757. {$endif wasm}
  4758. { now we can define cpu and fpu type }
  4759. def_cpu_macros;
  4760. { Use init_settings cpu type for asm cpu type,
  4761. if asmcputype is cpu_none,
  4762. at least as long as there is no explicit
  4763. option to set it on command line PM }
  4764. if init_settings.asmcputype = cpu_none then
  4765. init_settings.asmcputype:=init_settings.cputype;
  4766. {$ifdef llvm}
  4767. def_system_macro('CPULLVM');
  4768. {$endif llvm}
  4769. {$if defined(cpucapabilities)}
  4770. for cpuflag:=low(cpuflag) to high(cpuflag) do
  4771. begin
  4772. str(cpuflag,hs);
  4773. if cpuflag in cpu_capabilities[init_settings.cputype] then
  4774. def_system_macro(hs)
  4775. else
  4776. undef_system_macro(hs);
  4777. end;
  4778. {$endif defined(cpucapabilities)}
  4779. {$if defined(fpucapabilities)}
  4780. for fpuflag:=low(fpuflag) to high(fpuflag) do
  4781. begin
  4782. str(fpuflag,hs);
  4783. if fpuflag in fpu_capabilities[init_settings.fputype] then
  4784. def_system_macro(hs)
  4785. else
  4786. undef_system_macro(hs);
  4787. end;
  4788. {$endif defined(fpucapabilities)}
  4789. if init_settings.fputype<>fpu_none then
  4790. begin
  4791. {$if defined(i386) or defined(i8086)}
  4792. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4793. {$endif}
  4794. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4795. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4796. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  4797. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4798. {$endif}
  4799. {$if defined(m68k)}
  4800. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  4801. {$endif}
  4802. {$ifdef x86_64}
  4803. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4804. { normally, win64 doesn't support the legacy fpu }
  4805. if target_info.system=system_x86_64_win64 then
  4806. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  4807. else
  4808. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4809. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4810. {$endif}
  4811. end;
  4812. { Enable now for testing }
  4813. {$ifndef DISABLE_TLS_DIRECTORY}
  4814. if target_info.system in systems_windows then
  4815. def_system_macro('FPC_USE_TLS_DIRECTORY');
  4816. {$endif not DISABLE_TLS_DIRECTORY}
  4817. {$ifndef DISABLE_WIN64_SEH}
  4818. if target_info.system=system_x86_64_win64 then
  4819. def_system_macro('FPC_USE_WIN64_SEH');
  4820. {$endif DISABLE_WIN64_SEH}
  4821. {$ifndef DISABLE_WIN32_SEH}
  4822. if target_info.system=system_i386_win32 then
  4823. def_system_macro('FPC_USE_WIN32_SEH');
  4824. {$endif not DISABLE_WIN32_SEH}
  4825. {$ifdef ARM}
  4826. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  4827. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  4828. not(cs_fp_emulation in init_settings.moduleswitches) then
  4829. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  4830. {$endif ARM}
  4831. { inline bsf/bsr implementation }
  4832. {$if defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64)}
  4833. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4834. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4835. {$endif}
  4836. { hardware FMA support }
  4837. {$if defined(i386) or defined(x86_64)}
  4838. if (fpu_capabilities[current_settings.fputype]*[FPUX86_HAS_FMA,FPUX86_HAS_FMA4])<>[] then
  4839. begin
  4840. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  4841. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  4842. end;
  4843. {$endif defined(i386) or defined(x86_64)}
  4844. {$if defined(arm)}
  4845. { it is determined during system unit compilation if clz is used for bsf or not,
  4846. this is not perfect but the current implementation bsf/bsr does not allow another
  4847. solution }
  4848. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  4849. ((init_settings.instructionset=is_arm) or
  4850. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  4851. begin
  4852. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4853. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  4854. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4855. end;
  4856. {$endif}
  4857. {$if defined(xtensa)}
  4858. { it is determined during system unit compilation if nsau is used for bsr or not,
  4859. this is not perfect but the current implementation bsf/bsr does not allow another
  4860. solution }
  4861. if CPUXTENSA_HAS_NSAx in cpu_capabilities[init_settings.cputype] then
  4862. begin
  4863. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4864. end;
  4865. {$endif}
  4866. {$if defined(powerpc64)}
  4867. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  4868. big endian (unless specified otherwise). As the gcc man page says:
  4869. "Overriding the default ABI requires special system support and is
  4870. likely to fail in spectacular ways" }
  4871. if not option.ABISetExplicitly then
  4872. begin
  4873. if (target_info.abi=abi_powerpc_sysv) and
  4874. (target_info.endian=endian_little) then
  4875. target_info.abi:=abi_powerpc_elfv2
  4876. else
  4877. if (target_info.abi=abi_powerpc_elfv2) and
  4878. (target_info.endian=endian_big) then
  4879. target_info.abi:=abi_powerpc_sysv
  4880. end;
  4881. {$endif}
  4882. {$if defined(powerpc) or defined(powerpc64)}
  4883. { define _CALL_ELF symbol like gcc }
  4884. case target_info.abi of
  4885. abi_powerpc_sysv:
  4886. set_system_compvar('_CALL_ELF','1');
  4887. abi_powerpc_elfv2:
  4888. set_system_compvar('_CALL_ELF','2');
  4889. else
  4890. ;
  4891. end;
  4892. {$endif}
  4893. { Section smartlinking conflicts with import sections on Windows }
  4894. if GenerateImportSection and
  4895. (target_info.system in [system_i386_win32,system_x86_64_win64,system_aarch64_win64]) then
  4896. exclude(target_info.flags,tf_smartlink_sections);
  4897. if not option.LinkTypeSetExplicitly then
  4898. set_default_link_type;
  4899. { Default alignment settings,
  4900. 1. load the defaults for the target
  4901. 2. adapt defaults specifically for the target
  4902. 3. override with generic optimizer setting (little size)
  4903. 4. override with the user specified -Oa }
  4904. UpdateAlignment(init_settings.alignment,target_info.alignment);
  4905. {$ifdef arm}
  4906. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4907. begin
  4908. init_settings.alignment.procalign:=2;
  4909. init_settings.alignment.jumpalign:=2;
  4910. init_settings.alignment.coalescealign:=2;
  4911. init_settings.alignment.loopalign:=2;
  4912. end;
  4913. {$endif arm}
  4914. if (cs_opt_size in init_settings.optimizerswitches) then
  4915. begin
  4916. init_settings.alignment.procalign:=1;
  4917. init_settings.alignment.jumpalign:=1;
  4918. init_settings.alignment.coalescealign:=1;
  4919. init_settings.alignment.loopalign:=1;
  4920. {$ifdef x86}
  4921. { constalignmax=1 keeps the executable and thus the memory foot print small but
  4922. all processors except x86 are really hurt by this or might even crash }
  4923. init_settings.alignment.constalignmax:=1;
  4924. {$endif x86}
  4925. end;
  4926. UpdateAlignment(init_settings.alignment,option.paraalignment);
  4927. set_system_macro('FPC_VERSION',version_nr);
  4928. set_system_macro('FPC_RELEASE',release_nr);
  4929. set_system_macro('FPC_PATCH',patch_nr);
  4930. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  4931. if target_info.system in systems_indirect_entry_information then
  4932. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  4933. if not (tf_winlikewidestring in target_info.flags) then
  4934. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  4935. if tf_supports_packages in target_info.flags then
  4936. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  4937. if target_info.system in systems_indirect_var_imports then
  4938. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  4939. if cs_compilesystem in init_settings.moduleswitches then
  4940. for i:=low(tfeature) to high(tfeature) do
  4941. if i in features then
  4942. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  4943. {$push}
  4944. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  4945. if ControllerSupport and (target_info.system in (systems_embedded+systems_freertos)) and
  4946. (init_settings.controllertype<>ct_none) then
  4947. begin
  4948. with embedded_controllers[init_settings.controllertype] do
  4949. begin
  4950. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  4951. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  4952. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  4953. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  4954. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  4955. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  4956. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  4957. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  4958. end;
  4959. end;
  4960. {$pop}
  4961. { as stackalign is not part of the alignment record, we do not need to define the others alignments for symmetry yet }
  4962. set_system_macro('FPC_STACKALIGNMENT',tostr(target_info.stackalign));
  4963. option.free;
  4964. Option:=nil;
  4965. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl{$ifdef z80},pocall_stdcall{$endif}];
  4966. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  4967. if (tf_safecall_clearstack in target_info.flags) then
  4968. begin
  4969. include (cdecl_pocalls, pocall_safecall);
  4970. include (clearstack_pocalls, pocall_safecall)
  4971. end;
  4972. end;
  4973. initialization
  4974. coption:=toption;
  4975. finalization
  4976. if assigned(option) then
  4977. option.free;
  4978. end.