options.pas 172 KB

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