options.pas 161 KB

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