2
0

options.pas 159 KB

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