options.pas 170 KB

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