options.pas 183 KB

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