options.pas 164 KB

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