options.pas 177 KB

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