options.pas 158 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663
  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. i_bsd;
  98. const
  99. page_size = 24;
  100. page_width = 80;
  101. var
  102. option : toption;
  103. read_configfile, { read config file, set when a cfgfile is found }
  104. disable_configfile : boolean;
  105. fpcdir,
  106. ppccfg,
  107. param_file : string; { file to compile specified on the commandline }
  108. {****************************************************************************
  109. Options not supported on all platforms
  110. ****************************************************************************}
  111. const
  112. { gprof (requires implementation of g_profilecode in the code generator) }
  113. supported_targets_pg = [system_i386_linux,system_x86_64_linux,system_mipseb_linux,system_mipsel_linux,system_arm_linux]
  114. + [system_i386_win32]
  115. + [system_powerpc_darwin,system_x86_64_darwin]
  116. + [system_i386_GO32V2]
  117. + [system_i386_freebsd]
  118. + [system_i386_netbsd]
  119. + [system_i386_wdosx]
  120. + [system_riscv32_linux,system_riscv64_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. procedure SplitLine (var OrigString: TCmdStr; const Placeholder: TCmdStr;
  196. var RemainderString: TCmdStr);
  197. var
  198. I: longint;
  199. HS2: TCmdStr;
  200. begin
  201. RemainderString := '';
  202. if OrigString = '' then
  203. Exit;
  204. repeat
  205. I := Pos (NewLineStr, OrigString);
  206. if I > 0 then
  207. begin
  208. HS2 := Copy (OrigString, 1, Pred (I));
  209. { Stop if this line contains the placeholder for list replacement }
  210. if Pos (Placeholder, HS2) > 0 then
  211. begin
  212. RemainderString := Copy (OrigString, I + Length (NewLineStr),
  213. Length (OrigString) - I - Length (NewLineStr));
  214. { Special case - NewLineStr at the end of the line }
  215. if RemainderString = '' then
  216. RemainderString := NewLineStr;
  217. OrigString := HS2;
  218. Exit;
  219. end;
  220. Comment (V_Normal, HS2);
  221. Delete (OrigString, 1, Pred (I) + Length (NewLineStr));
  222. end;
  223. until I = 0;
  224. if (OrigString <> '') and (Pos (Placeholder, OrigString) = 0) then
  225. Comment (V_Normal, OrigString);
  226. end;
  227. procedure ListOSTargets (OrigString: TCmdStr);
  228. var
  229. target : tsystem;
  230. begin
  231. SplitLine (OrigString, OSTargetsPlaceholder, HS3);
  232. for target:=low(tsystem) to high(tsystem) do
  233. if assigned(targetinfos[target]) then
  234. begin
  235. hs1:=targetinfos[target]^.shortname;
  236. if OrigString = '' then
  237. Comment (V_Normal, hs1)
  238. else
  239. begin
  240. hs := OrigString;
  241. hs1:=hs1 + ': ' + targetinfos[target]^.name;
  242. if tf_under_development in targetinfos[target]^.flags then
  243. hs1:=hs1+' {*}';
  244. Replace(hs,OSTargetsPlaceholder,hs1);
  245. Comment(V_Normal,hs);
  246. end;
  247. end;
  248. OrigString := HS3;
  249. SplitLine (OrigString, OSTargetsPlaceholder, HS3);
  250. end;
  251. procedure ListCPUInstructionSets (OrigString: TCmdStr);
  252. var
  253. cpu : tcputype;
  254. begin
  255. SplitLine (OrigString, CPUListPlaceholder, HS3);
  256. hs1:='';
  257. for cpu:=low(tcputype) to high(tcputype) do
  258. begin
  259. if (OrigString = '') then
  260. begin
  261. if CPUTypeStr [CPU] <> '' then
  262. Comment (V_Normal, CPUTypeStr [CPU]);
  263. end
  264. else
  265. begin
  266. if length(hs1+cputypestr[cpu])>70 then
  267. begin
  268. hs:=OrigString;
  269. HS1 := HS1 + ',';
  270. Replace(hs,CPUListPlaceholder,hs1);
  271. Comment(V_Normal,hs);
  272. hs1:=''
  273. end
  274. else if hs1<>'' then
  275. hs1:=hs1+',';
  276. if cputypestr[cpu]<>'' then
  277. hs1:=hs1+cputypestr[cpu];
  278. end;
  279. end;
  280. if (OrigString <> '') and (hs1 <> '') then
  281. begin
  282. hs:=OrigString;
  283. Replace(hs,CPUListPlaceholder,hs1);
  284. Comment(V_Normal,hs);
  285. hs1:=''
  286. end;
  287. OrigString := HS3;
  288. SplitLine (OrigString, CPUListPlaceholder, HS3);
  289. end;
  290. procedure ListFPUInstructionSets (OrigString: TCmdStr);
  291. var
  292. fpu : tfputype;
  293. begin
  294. SplitLine (OrigString, FPUListPlaceholder, HS3);
  295. hs1:='';
  296. for fpu:=low(tfputype) to high(tfputype) do
  297. begin
  298. if (OrigString = '') then
  299. begin
  300. if FPUTypeStr [FPU] <> '' then
  301. Comment (V_Normal, FPUTypeStr [FPU]);
  302. end
  303. else
  304. begin
  305. if length(hs1+fputypestr[fpu])>70 then
  306. begin
  307. hs:=OrigString;
  308. HS1 := HS1 + ',';
  309. Replace(hs,FPUListPlaceholder,hs1);
  310. Comment(V_Normal,hs);
  311. hs1:=''
  312. end
  313. else if hs1<>'' then
  314. hs1:=hs1+',';
  315. if fputypestr[fpu]<>'' then
  316. hs1:=hs1+fputypestr[fpu];
  317. end;
  318. end;
  319. if (OrigString <> '') and (hs1 <> '') then
  320. begin
  321. hs:=OrigString;
  322. Replace(hs,FPUListPlaceholder,hs1);
  323. Comment(V_Normal,hs);
  324. hs1:=''
  325. end;
  326. OrigString := HS3;
  327. SplitLine (OrigString, FPUListPlaceholder, HS3);
  328. end;
  329. procedure ListABITargets (OrigString: TCmdStr);
  330. var
  331. abi : tabi;
  332. begin
  333. SplitLine (OrigString, ABIListPlaceholder, HS3);
  334. for abi:=low(abi) to high(abi) do
  335. begin
  336. if not abiinfo[abi].supported then
  337. continue;
  338. hs1:=abiinfo[abi].name;
  339. if hs1<>'' then
  340. begin
  341. if OrigString = '' then
  342. Comment (V_Normal, HS1)
  343. else
  344. begin
  345. hs:=OrigString;
  346. Replace(hs,ABIListPlaceholder,hs1);
  347. Comment(V_Normal,hs);
  348. end;
  349. end;
  350. end;
  351. OrigString := HS3;
  352. SplitLine (OrigString, ABIListPlaceholder, HS3);
  353. end;
  354. procedure ListOptimizations (OrigString: TCmdStr);
  355. var
  356. opt : toptimizerswitch;
  357. begin
  358. SplitLine (OrigString, OptListPlaceholder, HS3);
  359. for opt:=low(toptimizerswitch) to high(toptimizerswitch) do
  360. begin
  361. if opt in supported_optimizerswitches then
  362. begin
  363. hs1:=OptimizerSwitchStr[opt];
  364. if hs1<>'' then
  365. begin
  366. if OrigString = '' then
  367. Comment (V_Normal, hs1)
  368. else
  369. begin
  370. hs:=OrigString;
  371. Replace(hs,OptListPlaceholder,hs1);
  372. Comment(V_Normal,hs);
  373. end;
  374. end;
  375. end;
  376. end;
  377. OrigString := HS3;
  378. SplitLine (OrigString, OptListPlaceholder, HS3);
  379. end;
  380. procedure ListWPOptimizations (OrigString: TCmdStr);
  381. var
  382. wpopt: twpoptimizerswitch;
  383. begin
  384. SplitLine (OrigString, WPOListPlaceholder, HS3);
  385. for wpopt:=low(twpoptimizerswitch) to high(twpoptimizerswitch) do
  386. begin
  387. { currently all whole program optimizations are platform-independent
  388. if opt in supported_wpoptimizerswitches then
  389. }
  390. begin
  391. hs1:=WPOptimizerSwitchStr[wpopt];
  392. if hs1<>'' then
  393. begin
  394. if OrigString = '' then
  395. Comment (V_Normal, hs1)
  396. else
  397. begin
  398. hs:=OrigString;
  399. Replace(hs,WPOListPlaceholder,hs1);
  400. Comment(V_Normal,hs);
  401. end;
  402. end;
  403. end;
  404. end;
  405. OrigString := HS3;
  406. SplitLine (OrigString, WPOListPlaceholder, HS3);
  407. end;
  408. procedure ListAsmModes (OrigString: TCmdStr);
  409. var
  410. asmmode : tasmmode;
  411. begin
  412. SplitLine (OrigString, AsmModeListPlaceholder, HS3);
  413. for asmmode:=low(tasmmode) to high(tasmmode) do
  414. if assigned(asmmodeinfos[asmmode]) then
  415. begin
  416. hs1:=asmmodeinfos[asmmode]^.idtxt;
  417. if hs1<>'' then
  418. begin
  419. if OrigString = '' then
  420. Comment (V_Normal, hs1)
  421. else
  422. begin
  423. hs:=OrigString;
  424. Replace(hs,AsmModeListPlaceholder,hs1);
  425. Comment(V_Normal,hs);
  426. end;
  427. end;
  428. end;
  429. OrigString := HS3;
  430. SplitLine (OrigString, AsmModeListPlaceholder, HS3);
  431. end;
  432. procedure ListControllerTypes (OrigString: TCmdStr);
  433. var
  434. controllertype : tcontrollertype;
  435. begin
  436. {$PUSH}
  437. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  438. if (ControllerSupport) then
  439. begin
  440. SplitLine (OrigString, ControllerListPlaceholder, HS3);
  441. hs1:='';
  442. for controllertype:=low(tcontrollertype) to high(tcontrollertype) do
  443. begin
  444. if (OrigString = '') then
  445. begin
  446. if Embedded_Controllers [ControllerType].ControllerTypeStr <> '' then
  447. Comment (V_Normal, Embedded_Controllers [ControllerType].ControllerTypeStr);
  448. end
  449. else
  450. begin
  451. if length(hs1+embedded_controllers[controllertype].ControllerTypeStr)
  452. >70 then
  453. begin
  454. hs:=OrigString;
  455. HS1 := HS1 + ',';
  456. Replace(hs,ControllerListPlaceholder,hs1);
  457. Comment(V_Normal,hs);
  458. hs1:=''
  459. end
  460. else if hs1<>'' then
  461. hs1:=hs1+',';
  462. if embedded_controllers[controllertype].ControllerTypeStr<>'' then
  463. hs1:=hs1+embedded_controllers[controllertype].ControllerTypeStr;
  464. end;
  465. end;
  466. if (OrigString <> '') and (hs1<>'') then
  467. begin
  468. hs:=OrigString;
  469. Replace(hs,ControllerListPlaceholder,hs1);
  470. Comment(V_Normal,hs);
  471. hs1:=''
  472. end;
  473. OrigString := HS3;
  474. SplitLine (OrigString, ControllerListPlaceholder, HS3);
  475. end;
  476. {$POP}
  477. end;
  478. procedure ListFeatures (OrigString: TCmdStr);
  479. var
  480. Feature: TFeature;
  481. begin
  482. SplitLine (OrigString, FeatureListPlaceholder, HS3);
  483. HS1 := '';
  484. for Feature := Low (TFeature) to High (TFeature) do
  485. begin
  486. if (OrigString = '') then
  487. begin
  488. if FeatureStr [Feature] <> '' then
  489. Comment (V_Normal, FeatureStr [Feature]);
  490. end
  491. else
  492. begin
  493. if Length (HS1 + FeatureStr [Feature]) > 70 then
  494. begin
  495. HS := OrigString;
  496. HS1 := HS1 + ',';
  497. Replace (HS, FeatureListPlaceholder, HS1);
  498. Comment (V_Normal, HS);
  499. HS1 := ''
  500. end
  501. else if HS1 <> '' then
  502. HS1 := HS1 + ',';
  503. if FeatureStr [Feature] <> '' then
  504. HS1 := HS1 + FeatureStr [Feature];
  505. end;
  506. end;
  507. if (OrigString <> '') and (HS1 <> '') then
  508. begin
  509. HS := OrigString;
  510. Replace (HS, FeatureListPlaceholder, HS1);
  511. Comment (V_Normal, HS);
  512. HS1 := ''
  513. end;
  514. OrigString := HS3;
  515. SplitLine (OrigString, FeatureListPlaceholder, HS3);
  516. end;
  517. procedure ListModeswitches (OrigString: TCmdStr);
  518. var
  519. Modeswitch: TModeswitch;
  520. begin
  521. SplitLine (OrigString, ModeswitchListPlaceholder, HS3);
  522. HS1 := '';
  523. for Modeswitch := Low (TModeswitch) to High (TModeswitch) do
  524. begin
  525. if (OrigString = '') then
  526. begin
  527. if ModeswitchStr [Modeswitch] <> '' then
  528. Comment (V_Normal, ModeswitchStr [Modeswitch]);
  529. end
  530. else
  531. begin
  532. if Length (HS1 + ModeswitchStr [Modeswitch]) > 60 then
  533. begin
  534. HS := OrigString;
  535. HS1 := HS1 + ',';
  536. Replace (HS, ModeswitchListPlaceholder, HS1);
  537. Comment (V_Normal, HS);
  538. HS1 := ''
  539. end
  540. else if HS1 <> '' then
  541. HS1 := HS1 + ',';
  542. if ModeswitchStr [Modeswitch] <> '' then
  543. HS1 := HS1 + ModeswitchStr [Modeswitch];
  544. end;
  545. end;
  546. if (OrigString <> '') and (HS1 <> '') then
  547. begin
  548. HS := OrigString;
  549. Replace (HS, ModeswitchListPlaceholder, HS1);
  550. Comment (V_Normal, HS);
  551. HS1 := ''
  552. end;
  553. OrigString := HS3;
  554. SplitLine (OrigString, ModeswitchListPlaceholder, HS3);
  555. end;
  556. begin
  557. if More = '' then
  558. begin
  559. msg_str:=MessageStr(option_info);
  560. p:=pchar(msg_str);
  561. while assigned(p) do
  562. begin
  563. s:=GetMsgLine(p);
  564. { list permitted values for certain options }
  565. if pos(OSTargetsPlaceholder,s)>0 then
  566. ListOSTargets (S)
  567. else if pos(CPUListPlaceholder,s)>0 then
  568. ListCPUInstructionSets (S)
  569. else if pos(FPUListPlaceholder,s)>0 then
  570. ListFPUInstructionSets (S)
  571. else if pos(ABIListPlaceholder,s)>0 then
  572. ListABITargets (S)
  573. else if pos(OptListPlaceholder,s)>0 then
  574. ListOptimizations (S)
  575. else if pos(WPOListPlaceholder,s)>0 then
  576. ListWPOptimizations (S)
  577. else if Pos (ModeswitchListPlaceholder, S) > 0 then
  578. ListModeswitches (S)
  579. else if pos(AsmModeListPlaceholder,s)>0 then
  580. ListAsmModes (S)
  581. else if pos(ControllerListPlaceholder,s)>0 then
  582. ListControllerTypes (S)
  583. else if pos(FeatureListPlaceholder,s)>0 then
  584. ListFeatures (S)
  585. else
  586. Comment(V_Normal,s);
  587. end;
  588. end
  589. else
  590. begin
  591. J := 1;
  592. while J <= Length (More) do
  593. begin
  594. if J > 1 then
  595. Comment(V_Normal,''); (* Put empty line between multiple sections *)
  596. case More [J] of
  597. 'a': ListABITargets ('');
  598. 'c': ListCPUInstructionSets ('');
  599. 'f': ListFPUInstructionSets ('');
  600. 'i': ListAsmModes ('');
  601. 'm': ListModeswitches ('');
  602. 'o': ListOptimizations ('');
  603. 'r': ListFeatures ('');
  604. 't': ListOSTargets ('');
  605. 'u': ListControllerTypes ('');
  606. 'w': ListWPOptimizations ('');
  607. else
  608. IllegalPara ('-i' + More);
  609. end;
  610. Inc (J);
  611. end;
  612. end;
  613. StopOptions(0);
  614. end;
  615. procedure Toption.WriteHelpPages;
  616. function PadEnd(s:string;i:longint):string;
  617. begin
  618. if length(s) >= i then
  619. S := S + ' '
  620. else
  621. while (length(s)<i) do
  622. s:=s+' ';
  623. PadEnd:=s;
  624. end;
  625. var
  626. lastident,
  627. j,outline,
  628. ident,
  629. HelpLineHeight,
  630. lines : longint;
  631. show : boolean;
  632. opt : string[32];
  633. input,
  634. HelpLine,
  635. s : string;
  636. p : pchar;
  637. msg_str: TMsgStr;
  638. begin
  639. WriteLogo;
  640. Lines:=4;
  641. if FPCHelpLines then
  642. Message1(option_usage,FixFileName(FPCBinaryPath))
  643. else
  644. Message1(option_usage,FixFileName(system.paramstr(0)));
  645. lastident:=0;
  646. msg_str:=MessageStr(option_help_pages);
  647. p:=pchar(msg_str);
  648. while assigned(p) do
  649. begin
  650. { get a line and reset }
  651. s:=GetMsgLine(p);
  652. ident:=0;
  653. show:=false;
  654. { parse options }
  655. case s[1] of
  656. 'F': if FPCHelpLines then
  657. Show := true;
  658. {$ifdef UNITALIASES}
  659. 'a',
  660. {$endif}
  661. {$ifdef EXTDEBUG}
  662. 'e',
  663. {$endif EXTDEBUG}
  664. {$ifdef i386}
  665. '3',
  666. {$endif}
  667. {$ifdef x86_64}
  668. '4',
  669. {$endif}
  670. {$ifdef m68k}
  671. '6',
  672. {$endif}
  673. {$ifdef i8086}
  674. '8',
  675. {$endif}
  676. {$ifdef aarch64}
  677. 'a',
  678. {$endif}
  679. {$ifdef arm}
  680. 'A',
  681. {$endif}
  682. {$ifdef mipsel}
  683. 'm',
  684. {$endif}
  685. {$ifdef mipseb}
  686. 'M',
  687. {$endif}
  688. {$ifdef powerpc}
  689. 'P',
  690. {$endif}
  691. {$ifdef powerpc64}
  692. 'p',
  693. {$endif}
  694. {$ifdef sparc}
  695. 'S',
  696. {$endif}
  697. {$ifdef sparc64}
  698. 's',
  699. {$endif}
  700. {$ifdef riscv32}
  701. 'R',
  702. {$endif}
  703. {$ifdef riscv64}
  704. 'r',
  705. {$endif}
  706. {$ifdef avr}
  707. 'V',
  708. {$endif}
  709. {$ifdef jvm}
  710. 'J',
  711. {$endif}
  712. {$ifdef llvm}
  713. 'L',
  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', '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. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  2331. set_target_res(res_ext);
  2332. target_info.resobjext:='.fpcres';
  2333. end
  2334. else
  2335. IllegalPara(opt);
  2336. end;
  2337. 'F':
  2338. begin
  2339. if target_info.system in systems_os2 then
  2340. begin
  2341. if UnsetBool(More, j, opt, false) then
  2342. SetApptype(app_cui)
  2343. else
  2344. SetApptype(app_fs);
  2345. end
  2346. else
  2347. IllegalPara(opt);
  2348. end;
  2349. 'G':
  2350. begin
  2351. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2352. begin
  2353. if UnsetBool(More, j, opt, false) then
  2354. SetApptype(app_cui)
  2355. else
  2356. SetApptype(app_gui);
  2357. end
  2358. else
  2359. IllegalPara(opt);
  2360. end;
  2361. {$if defined(i8086)}
  2362. 'h':
  2363. begin
  2364. if UnsetBool(More, j, opt, false) then
  2365. exclude(init_settings.moduleswitches,cs_huge_code)
  2366. else
  2367. include(init_settings.moduleswitches,cs_huge_code);
  2368. end;
  2369. {$endif defined(i8086)}
  2370. 'I':
  2371. begin
  2372. if target_info.system in systems_all_windows then
  2373. begin
  2374. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2375. GenerateImportSectionSetExplicitly:=true;
  2376. end
  2377. else
  2378. IllegalPara(opt);
  2379. end;
  2380. 'i':
  2381. begin
  2382. if (target_info.system in systems_darwin) then
  2383. begin
  2384. set_target_res(res_macho);
  2385. target_info.resobjext:=
  2386. targetinfos[target_info.system]^.resobjext;
  2387. end
  2388. else
  2389. IllegalPara(opt);
  2390. end;
  2391. 'm':
  2392. begin
  2393. {$if defined(i8086)}
  2394. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  2395. begin
  2396. case Upper(Copy(More,j+1,255)) of
  2397. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2398. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2399. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2400. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2401. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2402. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2403. else
  2404. IllegalPara(opt);
  2405. end;
  2406. break;
  2407. end
  2408. else
  2409. {$endif defined(i8086)}
  2410. IllegalPara(opt);
  2411. end;
  2412. 'M':
  2413. begin
  2414. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim])) and
  2415. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2416. begin
  2417. break;
  2418. end
  2419. else
  2420. IllegalPara(opt);
  2421. end;
  2422. 'N':
  2423. begin
  2424. if target_info.system in systems_all_windows then
  2425. begin
  2426. RelocSection:=UnsetBool(More,j,opt,false);
  2427. RelocSectionSetExplicitly:=true;
  2428. end
  2429. else
  2430. IllegalPara(opt);
  2431. end;
  2432. 'p':
  2433. begin
  2434. {$push}
  2435. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  2436. if (target_info.system in systems_embedded) and
  2437. ControllerSupport then
  2438. begin
  2439. s:=upper(copy(more,j+1,length(more)-j));
  2440. if not(SetControllerType(s,init_settings.controllertype)) then
  2441. IllegalPara(opt)
  2442. else
  2443. begin
  2444. if init_settings.cputype<>embedded_controllers[init_settings.controllertype].cputype then
  2445. begin
  2446. Message(scan_n_changecputype);
  2447. init_settings.cputype:=embedded_controllers[init_settings.controllertype].cputype;
  2448. end;
  2449. end;
  2450. break;
  2451. end
  2452. else
  2453. IllegalPara(opt);
  2454. {$pop}
  2455. end;
  2456. 'P':
  2457. begin
  2458. if (target_info.system in [system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim]) and
  2459. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2460. begin
  2461. break;
  2462. end
  2463. else
  2464. IllegalPara(opt);
  2465. end;
  2466. 'R':
  2467. begin
  2468. if target_info.system in systems_all_windows then
  2469. begin
  2470. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2471. RelocSection:=not UnsetBool(More,j,opt,false);
  2472. RelocSectionSetExplicitly:=true;
  2473. end
  2474. else
  2475. IllegalPara(opt);
  2476. end;
  2477. 't':
  2478. begin
  2479. {$if defined(i8086)}
  2480. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  2481. begin
  2482. case Upper(Copy(More,j+1,255)) of
  2483. 'EXE': SetAppType(app_cui);
  2484. 'COM': SetAppType(app_com);
  2485. else
  2486. IllegalPara(opt);
  2487. end;
  2488. break;
  2489. end
  2490. else
  2491. {$endif defined(i8086)}
  2492. IllegalPara(opt);
  2493. end;
  2494. 'T':
  2495. begin
  2496. if target_info.system in systems_macos then
  2497. begin
  2498. if UnsetBool(More, j, opt, false) then
  2499. SetApptype(app_cui)
  2500. else
  2501. SetApptype(app_tool);
  2502. end
  2503. else
  2504. IllegalPara(opt);
  2505. end;
  2506. 'X':
  2507. begin
  2508. if (target_info.system in systems_linux) then
  2509. begin
  2510. if UnsetBool(More, j, opt, false) then
  2511. exclude(init_settings.moduleswitches,cs_executable_stack)
  2512. else
  2513. include(init_settings.moduleswitches,cs_executable_stack)
  2514. end
  2515. else
  2516. IllegalPara(opt);
  2517. end;
  2518. else
  2519. IllegalPara(opt);
  2520. end;
  2521. inc(j);
  2522. end;
  2523. end;
  2524. 'X' :
  2525. begin
  2526. j:=1;
  2527. while j<=length(more) do
  2528. begin
  2529. case More[j] of
  2530. '9' :
  2531. begin
  2532. if target_info.system in systems_linux then
  2533. begin
  2534. if UnsetBool(More, j, opt, false) then
  2535. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2536. else
  2537. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2538. end
  2539. else
  2540. IllegalPara(opt);
  2541. end;
  2542. 'c' : Cshared:=TRUE;
  2543. 'd' : Dontlinkstdlibpath:=TRUE;
  2544. 'e' :
  2545. begin
  2546. If UnsetBool(More, j, opt, false) then
  2547. exclude(init_settings.globalswitches,cs_link_extern)
  2548. else
  2549. include(init_settings.globalswitches,cs_link_extern);
  2550. end;
  2551. 'f' :
  2552. include(init_settings.globalswitches,cs_link_pthread);
  2553. 'g' :
  2554. begin
  2555. If UnsetBool(More, j, opt, false) then
  2556. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2557. else
  2558. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2559. end;
  2560. 'i' :
  2561. begin
  2562. If UnsetBool(More, j, opt, false) then
  2563. include(init_settings.globalswitches,cs_link_extern)
  2564. else
  2565. exclude(init_settings.globalswitches,cs_link_extern);
  2566. end;
  2567. 'n' :
  2568. begin
  2569. If UnsetBool(More, j, opt, false) then
  2570. exclude(init_settings.globalswitches,cs_link_native)
  2571. else
  2572. include(init_settings.globalswitches,cs_link_native);
  2573. end;
  2574. 'm' :
  2575. begin
  2576. If UnsetBool(More, j, opt, false) then
  2577. exclude(init_settings.globalswitches,cs_link_map)
  2578. else
  2579. include(init_settings.globalswitches,cs_link_map);
  2580. end;
  2581. 'p' : ; { Ignore used by fpc.pp }
  2582. 'r' :
  2583. begin
  2584. if (target_info.system in suppported_targets_x_smallr) then
  2585. begin
  2586. rlinkpath:=Copy(more,2,length(More)-1);
  2587. DefaultReplacements(rlinkpath);
  2588. end
  2589. else
  2590. IgnoredPara('-Xr');
  2591. more:='';
  2592. end;
  2593. 'R' :
  2594. begin
  2595. sysrootpath:=copy(more,2,length(more)-1);
  2596. defaultreplacements(sysrootpath);
  2597. more:='';
  2598. end;
  2599. 's' :
  2600. begin
  2601. If UnsetBool(More, j, opt, false) then
  2602. exclude(init_settings.globalswitches,cs_link_strip)
  2603. else
  2604. include(init_settings.globalswitches,cs_link_strip);
  2605. end;
  2606. 't' :
  2607. include(init_settings.globalswitches,cs_link_staticflag);
  2608. 'v' :
  2609. begin
  2610. If UnsetBool(More, j, opt, false) then
  2611. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2612. else
  2613. include(init_settings.globalswitches,cs_link_opt_vtable);
  2614. end;
  2615. 'D' :
  2616. begin
  2617. def_system_macro('FPC_LINK_DYNAMIC');
  2618. undef_system_macro('FPC_LINK_SMART');
  2619. undef_system_macro('FPC_LINK_STATIC');
  2620. exclude(init_settings.globalswitches,cs_link_static);
  2621. exclude(init_settings.globalswitches,cs_link_smart);
  2622. include(init_settings.globalswitches,cs_link_shared);
  2623. LinkTypeSetExplicitly:=true;
  2624. end;
  2625. 'M' :
  2626. begin
  2627. mainaliasname:=Copy(more,2,length(More)-1);
  2628. More:='';
  2629. end;
  2630. 'P' :
  2631. begin
  2632. utilsprefix:=Copy(more,2,length(More)-1);
  2633. DefaultReplacements(utilsprefix);
  2634. More:='';
  2635. end;
  2636. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2637. // these are not aggregable.
  2638. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2639. IllegalPara(opt)
  2640. else
  2641. begin
  2642. case more[j+1] of
  2643. 'A' : begin
  2644. s:=Copy(more,3,length(More)-2);
  2645. if not LinkLibraryAliases.AddDep(s) Then
  2646. IllegalPara(opt);
  2647. end;
  2648. 'O' : begin
  2649. s:=Copy(more,3,length(More)-2);
  2650. if not LinkLibraryOrder.AddWeight(s) Then
  2651. IllegalPara(opt);
  2652. end;
  2653. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2654. else
  2655. IllegalPara(opt);
  2656. end; {case}
  2657. j:=length(more);
  2658. end; {else begin}
  2659. end;
  2660. 'S' :
  2661. begin
  2662. ForceStaticLinking;
  2663. end;
  2664. 'V' :
  2665. begin
  2666. if UnsetBool(More, j, opt, false) then
  2667. exclude(init_settings.globalswitches,cs_link_vlink)
  2668. else
  2669. begin
  2670. include(init_settings.globalswitches,cs_link_vlink);
  2671. include(init_settings.globalswitches,cs_link_extern);
  2672. end;
  2673. LinkerSetExplicitly:=true;
  2674. end;
  2675. 'X' :
  2676. begin
  2677. def_system_macro('FPC_LINK_SMART');
  2678. undef_system_macro('FPC_LINK_STATIC');
  2679. undef_system_macro('FPC_LINK_DYNAMIC');
  2680. exclude(init_settings.globalswitches,cs_link_static);
  2681. include(init_settings.globalswitches,cs_link_smart);
  2682. exclude(init_settings.globalswitches,cs_link_shared);
  2683. LinkTypeSetExplicitly:=true;
  2684. end;
  2685. '-' :
  2686. begin
  2687. exclude(init_settings.globalswitches,cs_link_staticflag);
  2688. exclude(init_settings.globalswitches,cs_link_strip);
  2689. exclude(init_settings.globalswitches,cs_link_map);
  2690. set_default_link_type;
  2691. end;
  2692. else
  2693. IllegalPara(opt);
  2694. end;
  2695. inc(j);
  2696. end;
  2697. end;
  2698. else
  2699. IllegalPara(opt);
  2700. end;
  2701. end;
  2702. '@' :
  2703. begin
  2704. Message(option_no_nested_response_file);
  2705. StopOptions(1);
  2706. end;
  2707. else
  2708. begin
  2709. if (length(param_file)<>0) then
  2710. Message2(option_only_one_source_support,param_file,opt);
  2711. param_file:=opt;
  2712. Message1(option_found_file,opt);
  2713. end;
  2714. end;
  2715. end;
  2716. procedure Toption.Interpret_file(const filename : TPathStr);
  2717. procedure RemoveSep(var fn:TPathStr);
  2718. var
  2719. i : longint;
  2720. begin
  2721. i:=0;
  2722. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2723. inc(i);
  2724. Delete(fn,1,i);
  2725. i:=length(fn);
  2726. while (i>0) and (fn[i] in [',',' ',#9]) do
  2727. dec(i);
  2728. fn:=copy(fn,1,i);
  2729. end;
  2730. function GetName(var fn:TPathStr):TPathStr;
  2731. var
  2732. i : longint;
  2733. begin
  2734. i:=0;
  2735. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2736. inc(i);
  2737. GetName:=Copy(fn,1,i);
  2738. Delete(fn,1,i);
  2739. end;
  2740. const
  2741. maxlevel = 15;
  2742. var
  2743. f : text;
  2744. s, tmp,
  2745. opts : TCmdStr;
  2746. skip : array[0..maxlevel] of boolean;
  2747. line,
  2748. level : longint;
  2749. option_read : boolean;
  2750. oldfilemode : byte;
  2751. ConfigFile: TPathStr;
  2752. begin
  2753. { avoid infinite loop }
  2754. Inc(FileLevel);
  2755. Option_read:=false;
  2756. If FileLevel>MaxLevel then
  2757. Message(option_too_many_cfg_files);
  2758. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2759. ConfigFile := ExpandFileName(filename);
  2760. { Maybe It's Directory ?} //Jaro Change:
  2761. if PathExists(ConfigFile,false) then
  2762. begin
  2763. Message1(option_config_is_dir,filename);
  2764. exit;
  2765. end;
  2766. { open file }
  2767. Message1(option_using_file,filename);
  2768. oldfilemode:=filemode;
  2769. filemode:=0;
  2770. assign(f,ConfigFile);
  2771. {$push}{$I-}
  2772. reset(f);
  2773. {$pop}
  2774. filemode:=oldfilemode;
  2775. if ioresult<>0 then
  2776. begin
  2777. Message1(option_unable_open_file,filename);
  2778. exit;
  2779. end;
  2780. Message1(option_start_reading_configfile,filename);
  2781. fillchar(skip,sizeof(skip),0);
  2782. level:=0;
  2783. line:=0;
  2784. while not eof(f) do
  2785. begin
  2786. readln(f,opts);
  2787. inc(line);
  2788. RemoveSep(opts);
  2789. if (opts<>'') and (opts[1]<>';') then
  2790. begin
  2791. if opts[1]='#' then
  2792. begin
  2793. Message1(option_interpreting_file_option,opts);
  2794. Delete(opts,1,1);
  2795. s:=upper(GetName(opts));
  2796. if (s='SECTION') then
  2797. begin
  2798. RemoveSep(opts);
  2799. s:=upper(GetName(opts));
  2800. if level=0 then
  2801. skip[level]:=not defined_macro(s) or (s='COMMON');
  2802. end
  2803. else
  2804. if (s='IFDEF') then
  2805. begin
  2806. RemoveSep(opts);
  2807. if Level>=maxlevel then
  2808. begin
  2809. Message2(option_too_many_ifdef,filename,tostr(line));
  2810. stopOptions(1);
  2811. end;
  2812. inc(Level);
  2813. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2814. end
  2815. else
  2816. if (s='IFNDEF') then
  2817. begin
  2818. RemoveSep(opts);
  2819. if Level>=maxlevel then
  2820. begin
  2821. Message2(option_too_many_ifdef,filename,tostr(line));
  2822. stopOptions(1);
  2823. end;
  2824. inc(Level);
  2825. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2826. end
  2827. else
  2828. if (s='ELSE') then
  2829. begin
  2830. if Level=0 then
  2831. begin
  2832. Message2(option_else_without_if,filename,tostr(line));
  2833. stopOptions(1);
  2834. end
  2835. else
  2836. skip[level]:=skip[level-1] or (not skip[level])
  2837. end
  2838. else
  2839. if (s='ENDIF') then
  2840. begin
  2841. skip[level]:=false;
  2842. if Level=0 then
  2843. begin
  2844. Message2(option_too_many_endif,filename,tostr(line));
  2845. stopOptions(1);
  2846. end;
  2847. dec(level);
  2848. end
  2849. else
  2850. if (not skip[level]) then
  2851. begin
  2852. if (s='DEFINE') then
  2853. begin
  2854. RemoveSep(opts);
  2855. tmp:= GetName(opts);
  2856. if tmp <> '' then
  2857. def_system_macro(tmp);
  2858. Option_read:=true;
  2859. end
  2860. else
  2861. if (s='UNDEF') then
  2862. begin
  2863. RemoveSep(opts);
  2864. tmp:= GetName(opts);
  2865. if tmp <> '' then
  2866. undef_system_macro(tmp);
  2867. Option_read:=true;
  2868. end
  2869. else
  2870. if (s='WRITE') then
  2871. begin
  2872. Delete(opts,1,1);
  2873. DefaultReplacements(opts);
  2874. WriteLn(opts);
  2875. Option_read:=true;
  2876. end
  2877. else
  2878. if (s='INCLUDE') then
  2879. begin
  2880. Delete(opts,1,1);
  2881. DefaultReplacements(opts);
  2882. Interpret_file(opts);
  2883. Option_read:=true;
  2884. end
  2885. else
  2886. if (s='CFGDIR') then
  2887. begin
  2888. Delete(opts,1,1);
  2889. DefaultReplacements(opts);
  2890. ParaIncludeCfgPath.AddPath(opts,false);
  2891. Option_read:=true;
  2892. end;
  2893. end;
  2894. end
  2895. else
  2896. begin
  2897. if (opts[1]='-') or (opts[1]='@') then
  2898. begin
  2899. if (not skip[level]) then
  2900. interpret_option(opts,false);
  2901. Option_read:=true;
  2902. end
  2903. else
  2904. Message1(option_illegal_para,opts);
  2905. end;
  2906. end;
  2907. end;
  2908. if Level>0 then
  2909. Message(option_too_less_endif);
  2910. if Not Option_read then
  2911. Message1(option_no_option_found,filename)
  2912. else
  2913. Message1(option_end_reading_configfile,filename);
  2914. Close(f);
  2915. Dec(FileLevel);
  2916. end;
  2917. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  2918. var
  2919. argstart,
  2920. env,
  2921. pc : pchar;
  2922. arglen : longint;
  2923. quote : set of char;
  2924. hs : TCmdStr;
  2925. begin
  2926. Message1(option_using_env,envname);
  2927. env:=GetEnvPChar(envname);
  2928. pc:=env;
  2929. hs:='';
  2930. if assigned(pc) then
  2931. begin
  2932. repeat
  2933. { skip leading spaces }
  2934. while pc^ in [' ',#9,#13] do
  2935. inc(pc);
  2936. case pc^ of
  2937. #0 :
  2938. break;
  2939. '"' :
  2940. begin
  2941. quote:=['"'];
  2942. inc(pc);
  2943. end;
  2944. '''' :
  2945. begin
  2946. quote:=[''''];
  2947. inc(pc);
  2948. end;
  2949. else
  2950. quote:=[' ',#9,#13];
  2951. end;
  2952. { scan until the end of the argument }
  2953. argstart:=pc;
  2954. while (pc^<>#0) and not(pc^ in quote) do
  2955. inc(pc);
  2956. { create argument }
  2957. arglen:=pc-argstart;
  2958. { TODO: FIXME: silent truncation of environment parameters }
  2959. if (arglen > 255) then
  2960. arglen := 255;
  2961. setlength(hs,arglen);
  2962. move(argstart^,hs[1],arglen);
  2963. interpret_option(hs,true);
  2964. { skip quote }
  2965. if pc^ in quote then
  2966. inc(pc);
  2967. until false;
  2968. end
  2969. else
  2970. Message1(option_no_option_found,'(env) '+envname);
  2971. FreeEnvPChar(env);
  2972. end;
  2973. procedure toption.read_parameters;
  2974. var
  2975. opts : TCmdStr;
  2976. paramindex : longint;
  2977. begin
  2978. paramindex:=0;
  2979. while paramindex<paramcount do
  2980. begin
  2981. inc(paramindex);
  2982. opts:=objpas.paramstr(paramindex);
  2983. if length(opts)>0 then
  2984. case opts[1] of
  2985. '@' :
  2986. if not firstpass then
  2987. begin
  2988. Delete(opts,1,1);
  2989. Message1(option_reading_further_from,opts);
  2990. interpret_file(opts);
  2991. end;
  2992. '!' :
  2993. if not firstpass then
  2994. begin
  2995. Delete(opts,1,1);
  2996. Message1(option_reading_further_from,'(env) '+opts);
  2997. interpret_envvar(opts);
  2998. end;
  2999. else
  3000. interpret_option(opts,true);
  3001. end;
  3002. end;
  3003. end;
  3004. procedure toption.parsecmd(cmd:TCmdStr);
  3005. var
  3006. i,ps : longint;
  3007. opts : TCmdStr;
  3008. begin
  3009. while (cmd<>'') do
  3010. begin
  3011. while cmd[1]=' ' do
  3012. delete(cmd,1,1);
  3013. i:=pos(' ',cmd);
  3014. if i=0 then
  3015. i:=2147483647;
  3016. opts:=Copy(cmd,1,i-1);
  3017. Delete(cmd,1,i);
  3018. case opts[1] of
  3019. '@' :
  3020. if not firstpass then
  3021. begin
  3022. Delete(opts,1,1);
  3023. Message1(option_reading_further_from,opts);
  3024. interpret_file(opts);
  3025. end;
  3026. '!' :
  3027. if not firstpass then
  3028. begin
  3029. Delete(opts,1,1);
  3030. Message1(option_reading_further_from,'(env) '+opts);
  3031. interpret_envvar(opts);
  3032. end;
  3033. '"' :
  3034. begin
  3035. Delete(opts,1,1);
  3036. ps:=pos('"',cmd);
  3037. if (i<>256) and (ps>0) then
  3038. begin
  3039. opts:=opts + ' '+ copy(cmd,1,ps-1);
  3040. cmd:=copy(cmd,ps+1,255);
  3041. end;
  3042. interpret_option(opts,true);
  3043. end;
  3044. else
  3045. interpret_option(opts,true);
  3046. end;
  3047. end;
  3048. end;
  3049. procedure toption.writequickinfo;
  3050. var
  3051. s : string;
  3052. i : longint;
  3053. procedure addinfo(const hs:string);
  3054. begin
  3055. if s<>'' then
  3056. s:=s+' '+hs
  3057. else
  3058. s:=hs;
  3059. end;
  3060. begin
  3061. s:='';
  3062. i:=0;
  3063. while (i<length(quickinfo)) do
  3064. begin
  3065. inc(i);
  3066. case quickinfo[i] of
  3067. 'S' :
  3068. begin
  3069. inc(i);
  3070. case quickinfo[i] of
  3071. 'O' :
  3072. addinfo(lower(source_info.shortname));
  3073. 'P' :
  3074. addinfo(source_cpu_string);
  3075. else
  3076. IllegalPara('-i'+QuickInfo);
  3077. end;
  3078. end;
  3079. 'T' :
  3080. begin
  3081. inc(i);
  3082. case quickinfo[i] of
  3083. 'O' :
  3084. addinfo(lower(target_info.shortname));
  3085. 'P' :
  3086. AddInfo(target_cpu_string);
  3087. else
  3088. IllegalPara('-i'+QuickInfo);
  3089. end;
  3090. end;
  3091. 'V' :
  3092. AddInfo(version_string);
  3093. 'W' :
  3094. AddInfo(full_version_string);
  3095. 'D' :
  3096. AddInfo(date_string);
  3097. '_' :
  3098. ;
  3099. else
  3100. IllegalPara('-i'+QuickInfo);
  3101. end;
  3102. end;
  3103. if s<>'' then
  3104. begin
  3105. writeln(s);
  3106. stopoptions(0);
  3107. end;
  3108. end;
  3109. procedure TOption.TargetOptions(def:boolean);
  3110. var
  3111. s : string;
  3112. i : integer;
  3113. target_unsup_features : tfeatures;
  3114. begin
  3115. if def then
  3116. def_system_macro(target_info.shortname)
  3117. else
  3118. undef_system_macro(target_info.shortname);
  3119. s:=target_info.extradefines;
  3120. while (s<>'') do
  3121. begin
  3122. i:=pos(';',s);
  3123. if i=0 then
  3124. i:=length(s)+1;
  3125. if def then
  3126. def_system_macro(Copy(s,1,i-1))
  3127. else
  3128. undef_system_macro(Copy(s,1,i-1));
  3129. delete(s,1,i);
  3130. end;
  3131. if (tf_winlikewidestring in target_info.flags) then
  3132. if def then
  3133. def_system_macro('FPC_WINLIKEWIDESTRING')
  3134. else
  3135. undef_system_macro('FPC_WINLIKEWIDESTRING');
  3136. if (tf_requires_proper_alignment in target_info.flags) then
  3137. if def then
  3138. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  3139. else
  3140. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3141. if (tf_init_final_units_by_calls in target_info.flags) then
  3142. if def then
  3143. def_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS')
  3144. else
  3145. undef_system_macro('FPC_INIT_FINAL_UNITS_BY_CALLS');
  3146. if source_info.system<>target_info.system then
  3147. if def then
  3148. def_system_macro('FPC_CROSSCOMPILING')
  3149. else
  3150. undef_system_macro('FPC_CROSSCOMPILING');
  3151. if source_info.cpu<>target_info.cpu then
  3152. if def then
  3153. def_system_macro('FPC_CPUCROSSCOMPILING')
  3154. else
  3155. def_system_macro('FPC_CPUCROSSCOMPILING');
  3156. if (tf_no_generic_stackcheck in target_info.flags) then
  3157. if def then
  3158. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  3159. else
  3160. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  3161. if (tf_section_threadvars in target_info.flags) then
  3162. if def then
  3163. def_system_macro('FPC_SECTION_THREADVARS')
  3164. else
  3165. undef_system_macro('FPC_SECTION_THREADVARS');
  3166. if (tf_use_psabieh in target_info.flags) then
  3167. if def then
  3168. def_system_macro('FPC_USE_PSABIEH')
  3169. else
  3170. undef_system_macro('FPC_USE_PSABIEH');
  3171. { Code generation flags }
  3172. if (tf_pic_default in target_info.flags) then
  3173. if def then
  3174. include(init_settings.moduleswitches,cs_create_pic)
  3175. else
  3176. exclude(init_settings.moduleswitches,cs_create_pic);
  3177. { Resources support }
  3178. if (tf_has_winlike_resources in target_info.flags) then
  3179. if def then
  3180. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  3181. else
  3182. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  3183. { Features }
  3184. case target_info.system of
  3185. system_arm_gba:
  3186. target_unsup_features:=[f_dynlibs];
  3187. system_arm_nds:
  3188. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  3189. system_i386_nativent:
  3190. // until these features are implemented, they are disabled in the compiler
  3191. target_unsup_features:=[f_stackcheck];
  3192. system_i8086_msdos:
  3193. target_unsup_features:=[f_threading,f_dynlibs];
  3194. system_i8086_win16:
  3195. target_unsup_features:=[f_threading];
  3196. system_jvm_java32,
  3197. system_jvm_android32:
  3198. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  3199. f_variants,f_objects,f_commandargs,
  3200. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  3201. system_arm_palmos,
  3202. system_m68k_palmos:
  3203. target_unsup_features:=[f_threading];
  3204. system_m68k_atari:
  3205. target_unsup_features:=[f_threading];
  3206. { classic amiga has dynamic libraries, but they cannot be integrated in the
  3207. normal dynlibs infrastructure due to architectural differences, so therefore
  3208. lets disable the feature. }
  3209. system_m68k_amiga:
  3210. target_unsup_features:=[f_dynlibs];
  3211. else
  3212. target_unsup_features:=[];
  3213. end;
  3214. if def then
  3215. features:=features-target_unsup_features
  3216. else
  3217. features:=features+target_unsup_features;
  3218. {$if defined(atari) or defined(hasamiga)}
  3219. { enable vlink as default linker on Atari, Amiga, and MorphOS, but not for cross compilers (for now) }
  3220. if (target_info.system in [system_m68k_amiga,system_m68k_atari,
  3221. system_powerpc_amiga]) and
  3222. not LinkerSetExplicitly then
  3223. include(init_settings.globalswitches,cs_link_vlink);
  3224. {$endif}
  3225. end;
  3226. procedure TOption.checkoptionscompatibility;
  3227. begin
  3228. {$ifdef i8086}
  3229. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  3230. begin
  3231. Message(option_com_files_require_tiny_model);
  3232. StopOptions(1);
  3233. end;
  3234. {$endif i8086}
  3235. {$ifndef i8086_link_intern_debuginfo}
  3236. if (cs_debuginfo in init_settings.moduleswitches) and
  3237. (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) and
  3238. not (cs_link_extern in init_settings.globalswitches) then
  3239. begin
  3240. Message(option_debug_info_requires_external_linker);
  3241. include(init_settings.globalswitches,cs_link_extern);
  3242. end;
  3243. {$endif i8086_link_intern_debuginfo}
  3244. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  3245. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  3246. begin
  3247. { smartlink creation does not yet work with DWARF
  3248. debug info on most targets, but it works in internal assembler }
  3249. if (cs_create_smart in init_settings.moduleswitches) and
  3250. not (af_outputbinary in target_asm.flags) then
  3251. begin
  3252. Message(option_dwarf_smartlink_creation);
  3253. exclude(init_settings.moduleswitches,cs_create_smart);
  3254. end;
  3255. { smart linking does not yet work with DWARF debug info on most targets }
  3256. if (cs_link_smart in init_settings.globalswitches) then
  3257. begin
  3258. Message(option_dwarf_smart_linking);
  3259. ForceStaticLinking;
  3260. end;
  3261. end;
  3262. { external debug info is only supported for DWARF on darwin }
  3263. if (target_info.system in systems_darwin) and
  3264. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  3265. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  3266. begin
  3267. Message(option_debug_external_unsupported);
  3268. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  3269. end;
  3270. { Also create a smartlinked version, on an assembler that
  3271. does not support smartlink sections like nasm?
  3272. This is not compatible with using internal linker. }
  3273. if ((cs_link_smart in init_settings.globalswitches) or
  3274. (cs_create_smart in init_settings.moduleswitches)) and
  3275. (af_needar in target_asm.flags) and
  3276. not (af_smartlink_sections in target_asm.flags) and
  3277. not (cs_link_extern in init_settings.globalswitches) and
  3278. (target_info.link<>ld_none) and
  3279. not (cs_link_nolink in init_settings.globalswitches) then
  3280. begin
  3281. Message(option_smart_link_requires_external_linker);
  3282. include(init_settings.globalswitches,cs_link_extern);
  3283. end;
  3284. end;
  3285. constructor TOption.create;
  3286. begin
  3287. LogoWritten:=false;
  3288. NoPressEnter:=false;
  3289. FirstPass:=false;
  3290. ABISetExplicitly:=false;
  3291. FPUSetExplicitly:=false;
  3292. CPUSetExplicitly:=false;
  3293. OptCPUSetExplicitly:=false;
  3294. FileLevel:=0;
  3295. Quickinfo:='';
  3296. ParaIncludeCfgPath:=TSearchPathList.Create;
  3297. ParaIncludePath:=TSearchPathList.Create;
  3298. ParaObjectPath:=TSearchPathList.Create;
  3299. ParaUnitPath:=TSearchPathList.Create;
  3300. ParaLibraryPath:=TSearchPathList.Create;
  3301. ParaFrameworkPath:=TSearchPathList.Create;
  3302. parapackagepath:=TSearchPathList.Create;
  3303. parapackages:=TFPHashObjectList.Create;
  3304. paranamespaces:=TCmdStrList.Create;
  3305. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3306. MacVersionSet:=false;
  3307. paratarget:=system_none;
  3308. paratargetasm:=as_none;
  3309. paratargetdbg:=dbg_none;
  3310. LinkTypeSetExplicitly:=false;
  3311. LinkerSetExplicitly:=false;
  3312. end;
  3313. destructor TOption.destroy;
  3314. begin
  3315. ParaIncludeCfgPath.Free;
  3316. ParaIncludePath.Free;
  3317. ParaObjectPath.Free;
  3318. ParaUnitPath.Free;
  3319. ParaLibraryPath.Free;
  3320. ParaFrameworkPath.Free;
  3321. parapackagepath.Free;
  3322. ParaPackages.Free;
  3323. paranamespaces.free;
  3324. end;
  3325. {****************************************************************************
  3326. Callable Routines
  3327. ****************************************************************************}
  3328. function check_configfile(fn:string; var foundfn:string):boolean;
  3329. function CfgFileExists(const fn:string):boolean;
  3330. begin
  3331. Comment(V_Tried,'Configfile search: '+fn);
  3332. CfgFileExists:=FileExists(fn);
  3333. end;
  3334. var
  3335. {$ifdef Unix}
  3336. hs,
  3337. {$endif Unix}
  3338. configpath : string;
  3339. begin
  3340. foundfn:=fn;
  3341. check_configfile:=true;
  3342. { retrieve configpath }
  3343. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3344. {$ifdef Unix}
  3345. if configpath='' then
  3346. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3347. {$endif}
  3348. {
  3349. Order to read configuration file :
  3350. try reading fpc.cfg in :
  3351. 1 - current dir
  3352. 2 - configpath
  3353. 3 - compiler path
  3354. }
  3355. if not FileExists(fn) then
  3356. begin
  3357. {$ifdef Unix}
  3358. hs:=GetEnvironmentVariable('HOME');
  3359. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3360. foundfn:=FixPath(hs,false)+'.'+fn
  3361. else
  3362. {$endif}
  3363. if CfgFileExists(configpath+fn) then
  3364. foundfn:=configpath+fn
  3365. else
  3366. {$ifdef WINDOWS}
  3367. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3368. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3369. else
  3370. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3371. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3372. else
  3373. {$endif WINDOWS}
  3374. {$ifndef Unix}
  3375. if CfgFileExists(exepath+fn) then
  3376. foundfn:=exepath+fn
  3377. else
  3378. {$else}
  3379. if CfgFileExists('/etc/'+fn) then
  3380. foundfn:='/etc/'+fn
  3381. else
  3382. {$endif}
  3383. check_configfile:=false;
  3384. end;
  3385. end;
  3386. procedure read_arguments(cmd:TCmdStr);
  3387. procedure def_cpu_macros;
  3388. var
  3389. abi : tabi;
  3390. fputype : tfputype;
  3391. cputype : tcputype;
  3392. controller: tcontrollertype;
  3393. s: string;
  3394. begin
  3395. {$ifdef llvm}
  3396. def_system_macro('CPULLVM');
  3397. {$endif}
  3398. for cputype:=low(tcputype) to high(tcputype) do
  3399. undef_system_macro('CPU'+Cputypestr[cputype]);
  3400. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3401. for fputype:=low(tfputype) to high(tfputype) do
  3402. undef_system_macro('FPU'+fputypestr[fputype]);
  3403. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3404. {$PUSH}
  3405. {$WARN 6018 OFF} { Unreachable code due to compile time evaluation }
  3406. if ControllerSupport then
  3407. begin
  3408. for controller:=low(tcontrollertype) to high(tcontrollertype) do
  3409. begin
  3410. s:=embedded_controllers[controller].controllertypestr;
  3411. if s<>'' then
  3412. undef_system_macro('FPC_MCU_'+s);
  3413. end;
  3414. s:=embedded_controllers[init_settings.controllertype].controllertypestr;
  3415. if s<>'' then
  3416. def_system_macro('FPC_MCU_'+s);
  3417. end;
  3418. {$POP}
  3419. { define abi }
  3420. for abi:=low(tabi) to high(tabi) do
  3421. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3422. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3423. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3424. systems since most code needs to behave the same on both}
  3425. if target_info.abi = abi_eabihf then
  3426. def_system_macro('FPC_ABI_EABI');
  3427. { using a case is pretty useless here (FK) }
  3428. { some stuff for TP compatibility }
  3429. {$ifdef i386}
  3430. def_system_macro('CPU86');
  3431. def_system_macro('CPU87');
  3432. def_system_macro('CPU386');
  3433. {$endif}
  3434. { new processor stuff }
  3435. {$ifdef i386}
  3436. def_system_macro('CPUI386');
  3437. def_system_macro('CPU32');
  3438. def_system_macro('CPUX86');
  3439. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3440. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3441. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3442. {$endif}
  3443. {$ifdef m68k}
  3444. def_system_macro('CPU68');
  3445. def_system_macro('CPU68K');
  3446. def_system_macro('CPUM68K');
  3447. def_system_macro('CPU32');
  3448. def_system_macro('FPC_CURRENCY_IS_INT64');
  3449. def_system_macro('FPC_COMP_IS_INT64');
  3450. {$endif}
  3451. {$ifdef powerpc}
  3452. def_system_macro('CPUPOWERPC');
  3453. def_system_macro('CPUPOWERPC32');
  3454. def_system_macro('CPU32');
  3455. def_system_macro('FPC_CURRENCY_IS_INT64');
  3456. def_system_macro('FPC_COMP_IS_INT64');
  3457. {$endif}
  3458. {$ifdef POWERPC64}
  3459. def_system_macro('CPUPOWERPC');
  3460. def_system_macro('CPUPOWERPC64');
  3461. def_system_macro('CPU64');
  3462. def_system_macro('FPC_CURRENCY_IS_INT64');
  3463. def_system_macro('FPC_COMP_IS_INT64');
  3464. {$endif}
  3465. {$ifdef x86_64}
  3466. def_system_macro('CPUX86_64');
  3467. def_system_macro('CPUAMD64');
  3468. def_system_macro('CPU64');
  3469. def_system_macro('CPUX64');
  3470. { not supported for now, afaik (FK)
  3471. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3472. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3473. { normally, win64 doesn't support the legacy fpu }
  3474. if target_info.system=system_x86_64_win64 then
  3475. begin
  3476. def_system_macro('FPC_CURRENCY_IS_INT64');
  3477. def_system_macro('FPC_COMP_IS_INT64');
  3478. end;
  3479. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3480. {$endif}
  3481. {$ifdef sparc}
  3482. def_system_macro('CPUSPARCGEN');
  3483. def_system_macro('CPUSPARC');
  3484. def_system_macro('CPUSPARC32');
  3485. def_system_macro('CPU32');
  3486. def_system_macro('FPC_CURRENCY_IS_INT64');
  3487. def_system_macro('FPC_COMP_IS_INT64');
  3488. {$endif}
  3489. {$ifdef sparc64}
  3490. def_system_macro('CPUSPARCGEN');
  3491. def_system_macro('CPUSPARC64');
  3492. def_system_macro('CPU64');
  3493. def_system_macro('FPC_CURRENCY_IS_INT64');
  3494. def_system_macro('FPC_COMP_IS_INT64');
  3495. {$endif}
  3496. {$ifdef arm}
  3497. def_system_macro('CPUARM');
  3498. def_system_macro('CPU32');
  3499. def_system_macro('FPC_CURRENCY_IS_INT64');
  3500. def_system_macro('FPC_COMP_IS_INT64');
  3501. {$endif arm}
  3502. {$ifdef avr}
  3503. def_system_macro('CPUAVR');
  3504. def_system_macro('CPU16');
  3505. def_system_macro('FPC_CURRENCY_IS_INT64');
  3506. def_system_macro('FPC_COMP_IS_INT64');
  3507. {$endif avr}
  3508. {$ifdef jvm}
  3509. def_system_macro('CPUJVM');
  3510. def_system_macro('CPU32');
  3511. def_system_macro('FPC_CURRENCY_IS_INT64');
  3512. def_system_macro('FPC_COMP_IS_INT64');
  3513. {$endif jvm}
  3514. {$ifdef mipsel}
  3515. def_system_macro('CPUMIPS');
  3516. def_system_macro('CPUMIPS32');
  3517. def_system_macro('CPUMIPSEL');
  3518. def_system_macro('CPUMIPSEL32');
  3519. def_system_macro('CPU32');
  3520. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3521. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3522. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3523. def_system_macro('FPC_CURRENCY_IS_INT64');
  3524. def_system_macro('FPC_COMP_IS_INT64');
  3525. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3526. { On most systems, locals are accessed relative to base pointer,
  3527. but for MIPS cpu, they are accessed relative to stack pointer.
  3528. This needs adaptation for so low level routines,
  3529. like MethodPointerLocal and related objects unit functions. }
  3530. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3531. {$endif mipsel}
  3532. {$ifdef mipseb}
  3533. def_system_macro('CPUMIPS');
  3534. def_system_macro('CPUMIPS32');
  3535. def_system_macro('CPUMIPSEB');
  3536. def_system_macro('CPUMIPSEB32');
  3537. def_system_macro('CPU32');
  3538. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3539. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3540. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3541. def_system_macro('FPC_CURRENCY_IS_INT64');
  3542. def_system_macro('FPC_COMP_IS_INT64');
  3543. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3544. { See comment above for mipsel }
  3545. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3546. {$endif}
  3547. {$ifdef i8086}
  3548. def_system_macro('CPU86'); { Borland compatibility }
  3549. def_system_macro('CPU87'); { Borland compatibility }
  3550. def_system_macro('CPUI8086');
  3551. def_system_macro('CPU16');
  3552. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3553. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3554. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3555. case init_settings.x86memorymodel of
  3556. mm_tiny: def_system_macro('FPC_MM_TINY');
  3557. mm_small: def_system_macro('FPC_MM_SMALL');
  3558. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3559. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3560. mm_large: def_system_macro('FPC_MM_LARGE');
  3561. mm_huge: def_system_macro('FPC_MM_HUGE');
  3562. end;
  3563. {$endif i8086}
  3564. {$ifdef aarch64}
  3565. def_system_macro('CPUAARCH64');
  3566. def_system_macro('CPU64');
  3567. def_system_macro('FPC_CURRENCY_IS_INT64');
  3568. def_system_macro('FPC_COMP_IS_INT64');
  3569. {$endif aarch64}
  3570. {$ifdef riscv32}
  3571. def_system_macro('CPURISCV');
  3572. def_system_macro('CPURISCV32');
  3573. def_system_macro('CPU32');
  3574. def_system_macro('FPC_CURRENCY_IS_INT64');
  3575. def_system_macro('FPC_COMP_IS_INT64');
  3576. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3577. {$endif riscv32}
  3578. {$ifdef riscv64}
  3579. def_system_macro('CPURISCV');
  3580. def_system_macro('CPURISCV64');
  3581. def_system_macro('CPU64');
  3582. def_system_macro('FPC_CURRENCY_IS_INT64');
  3583. def_system_macro('FPC_COMP_IS_INT64');
  3584. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3585. {$endif riscv64}
  3586. {$if defined(cpu8bitalu)}
  3587. def_system_macro('CPUINT8');
  3588. {$elseif defined(cpu16bitalu)}
  3589. def_system_macro('CPUINT16');
  3590. {$elseif defined(cpu32bitalu)}
  3591. def_system_macro('CPUINT32');
  3592. {$elseif defined(cpu64bitalu)}
  3593. def_system_macro('CPUINT64');
  3594. {$endif defined(cpu64bitalu)}
  3595. {$if defined(avr)}
  3596. def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
  3597. {$endif}
  3598. {$if defined(i8086) or defined(avr)}
  3599. def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
  3600. {$endif i8086 or avr}
  3601. { abs(long) is handled internally on all CPUs }
  3602. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  3603. {$if defined(i8086) or defined(i386) or defined(x86_64) or defined(powerpc64) or defined(aarch64)}
  3604. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  3605. {$endif i8086 or i386 or x86_64 or powerpc64 or aarch64}
  3606. def_system_macro('FPC_HAS_UNICODESTRING');
  3607. def_system_macro('FPC_RTTI_PACKSET1');
  3608. def_system_macro('FPC_HAS_CPSTRING');
  3609. {$ifdef x86_64}
  3610. def_system_macro('FPC_HAS_RIP_RELATIVE');
  3611. {$endif x86_64}
  3612. def_system_macro('FPC_HAS_CEXTENDED');
  3613. def_system_macro('FPC_HAS_RESSTRINITS');
  3614. { these cpus have an inline rol/ror implementaion }
  3615. {$ifdef cpurox}
  3616. {$ifdef m68k}
  3617. if CPUM68K_HAS_ROLROR in cpu_capabilities[init_settings.cputype] then
  3618. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3619. {$else}
  3620. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3621. {$endif}
  3622. {$endif}
  3623. {$ifdef powerpc64}
  3624. def_system_macro('FPC_HAS_LWSYNC');
  3625. {$endif}
  3626. { currently, all supported CPUs have an internal sar implementation }
  3627. def_system_macro('FPC_HAS_INTERNAL_SAR');
  3628. {$ifdef SUPPORT_GET_FRAME}
  3629. def_system_macro('INTERNAL_BACKTRACE');
  3630. {$endif SUPPORT_GET_FRAME}
  3631. def_system_macro('STR_CONCAT_PROCS');
  3632. {$warnings off}
  3633. if pocall_default = pocall_register then
  3634. def_system_macro('REGCALL');
  3635. {$warnings on}
  3636. end;
  3637. var
  3638. env: ansistring;
  3639. i : tfeature;
  3640. j : longint;
  3641. tmplist : TCmdStrList;
  3642. cmditem,
  3643. tmpcmditem : TCmdStrListItem;
  3644. cmdstr : TCmdStr;
  3645. {$if defined(cpucapabilities)}
  3646. cpuflag : tcpuflags;
  3647. {$endif defined(cpucapabilities)}
  3648. {$if defined(fpucapabilities)}
  3649. fpuflag : tfpuflags;
  3650. {$endif defined(fpucapabilities)}
  3651. {$if defined(cpucapabilities) or defined(fpucapabilities)}
  3652. hs : string;
  3653. {$endif defined(cpucapabilities) or defined(fpucapabilities)}
  3654. begin
  3655. option:=coption.create;
  3656. disable_configfile:=false;
  3657. { Non-core target defines }
  3658. Option.TargetOptions(true);
  3659. { get default messagefile }
  3660. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  3661. { default configfile can be specified on the commandline,
  3662. remove it first }
  3663. if (cmd<>'') and (cmd[1]='[') then
  3664. begin
  3665. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  3666. Delete(cmd,1,pos(']',cmd));
  3667. end
  3668. else
  3669. ppccfg:='fpc.cfg';
  3670. { first pass reading of parameters, only -i -v -T etc.}
  3671. option.firstpass:=true;
  3672. if cmd<>'' then
  3673. option.parsecmd(cmd)
  3674. else
  3675. begin
  3676. option.read_parameters;
  3677. { Write only quickinfo }
  3678. if option.quickinfo<>'' then
  3679. option.writequickinfo;
  3680. end;
  3681. option.firstpass:=false;
  3682. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  3683. Option.TargetOptions(true);
  3684. { target is set here, for wince the default app type is gui }
  3685. if target_info.system in systems_wince then
  3686. SetApptype(app_gui)
  3687. else
  3688. SetApptype(apptype);
  3689. { default defines }
  3690. def_system_macro(target_info.shortname);
  3691. def_system_macro('FPC');
  3692. def_system_macro('VER'+version_nr);
  3693. def_system_macro('VER'+version_nr+'_'+release_nr);
  3694. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  3695. { Temporary defines, until things settle down }
  3696. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  3697. def_system_macro('FPC_HAS_CONSTREF');
  3698. def_system_macro('FPC_STATICRIPFIXED');
  3699. def_system_macro('FPC_VARIANTCOPY_FIXED');
  3700. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  3701. def_system_macro('FPC_HAS_MEMBAR');
  3702. def_system_macro('FPC_SETBASE_USED');
  3703. { don't remove this, it's also for fpdoc necessary (FK) }
  3704. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  3705. { make cpu makros available when reading the config files the second time }
  3706. def_cpu_macros;
  3707. if tf_cld in target_info.flags then
  3708. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  3709. InternalError(2013092801);
  3710. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  3711. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  3712. InternalError(2013092801);
  3713. { Use standard Android NDK prefixes when cross-compiling }
  3714. if (source_info.system<>target_info.system) and (target_info.system in systems_android) then
  3715. case target_info.system of
  3716. system_arm_android:
  3717. utilsprefix:='arm-linux-androideabi-';
  3718. system_i386_android:
  3719. utilsprefix:='i686-linux-android-';
  3720. else
  3721. utilsprefix:=target_cpu_string + '-linux-android-';
  3722. end;
  3723. { Set up default value for the heap }
  3724. if target_info.system in systems_embedded then
  3725. begin
  3726. case target_info.system of
  3727. {$ifdef AVR}
  3728. system_avr_embedded:
  3729. if init_settings.controllertype=ct_avrsim then
  3730. heapsize:=8192
  3731. else
  3732. heapsize:=128;
  3733. {$endif AVR}
  3734. system_arm_embedded:
  3735. heapsize:=256;
  3736. system_mipsel_embedded:
  3737. heapsize:=256;
  3738. else
  3739. heapsize:=256;
  3740. end;
  3741. end;
  3742. { read configuration file }
  3743. if (not disable_configfile) and
  3744. (ppccfg<>'') then
  3745. read_configfile:=check_configfile(ppccfg,ppccfg)
  3746. else
  3747. read_configfile := false;
  3748. { Read commandline and configfile }
  3749. param_file:='';
  3750. { read configfile }
  3751. if read_configfile then
  3752. option.interpret_file(ppccfg);
  3753. { read parameters again to override config file }
  3754. if cmd<>'' then
  3755. option.parsecmd(cmd)
  3756. else
  3757. begin
  3758. { Write help pages if no parameters are passed }
  3759. if (paramcount=0) then
  3760. Option.WriteHelpPages;
  3761. option.read_parameters;
  3762. { Write only quickinfo }
  3763. if option.quickinfo<>'' then
  3764. option.writequickinfo;
  3765. end;
  3766. { check the compatibility of different options and adjust them if necessary
  3767. (and print possible errors)
  3768. }
  3769. option.checkoptionscompatibility;
  3770. { uses the CPUXXX-defines and target_info to determine whether the selected
  3771. target processor, if any, is supported }
  3772. Option.VerifyTargetProcessor;
  3773. { Stop if errors in options }
  3774. if ErrorCount>0 then
  3775. StopOptions(1);
  3776. { endian define }
  3777. case target_info.endian of
  3778. endian_little :
  3779. begin
  3780. def_system_macro('ENDIAN_LITTLE');
  3781. def_system_macro('FPC_LITTLE_ENDIAN');
  3782. end;
  3783. endian_big :
  3784. begin
  3785. def_system_macro('ENDIAN_BIG');
  3786. def_system_macro('FPC_BIG_ENDIAN');
  3787. end;
  3788. end;
  3789. { Write logo }
  3790. if option.ParaLogo then
  3791. option.writelogo;
  3792. { Check file to compile }
  3793. if param_file='' then
  3794. begin
  3795. Message(option_no_source_found);
  3796. StopOptions(1);
  3797. end;
  3798. {$ifndef Unix}
  3799. param_file:=FixFileName(param_file);
  3800. {$endif not unix}
  3801. inputfilepath:=ExtractFilePath(param_file);
  3802. inputfilename:=ExtractFileName(param_file);
  3803. if ExtractFileExt(inputfilename)='' then
  3804. begin
  3805. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  3806. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  3807. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  3808. inputfilename:=ChangeFileExt(inputfilename,pasext)
  3809. else if ((m_mac in current_settings.modeswitches) or
  3810. (tf_p_ext_support in target_info.flags))
  3811. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  3812. inputfilename:=ChangeFileExt(inputfilename,pext);
  3813. end;
  3814. { Check output dir }
  3815. if (OutputExeDir<>'') and
  3816. not PathExists(OutputExeDir,false) then
  3817. begin
  3818. Message1(general_e_path_does_not_exist,OutputExeDir);
  3819. StopOptions(1);
  3820. end;
  3821. { Add paths specified with parameters to the searchpaths }
  3822. UnitSearchPath.AddList(option.ParaUnitPath,true);
  3823. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  3824. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  3825. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  3826. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  3827. packagesearchpath.addlist(option.parapackagepath,true);
  3828. for j:=0 to option.parapackages.count-1 do
  3829. add_package(option.parapackages.NameOfIndex(j),true,true);
  3830. { add default namespaces }
  3831. tmplist:=TCmdStrList.Create;
  3832. cmditem:=TCmdStrListItem(option.paranamespaces.First);
  3833. while assigned(cmditem) do
  3834. begin
  3835. { use a temporary list cause if ";" are involved we need to reverse the
  3836. order due to how TCmdStrList behaves }
  3837. cmdstr:=cmditem.str;
  3838. repeat
  3839. j:=Pos(';',cmdstr);
  3840. if j>0 then
  3841. begin
  3842. tmplist.insert(copy(cmdstr,1,j-1));
  3843. delete(cmdstr,1,j);
  3844. end
  3845. else
  3846. tmplist.insert(cmdstr);
  3847. until j=0;
  3848. tmpcmditem:=TCmdStrListItem(tmplist.First);
  3849. while assigned(tmpcmditem) do
  3850. begin
  3851. namespacelist.insert(tmpcmditem.Str);
  3852. tmpcmditem:=TCmdStrListItem(tmpcmditem.Next);
  3853. end;
  3854. tmplist.clear;
  3855. cmditem:=TCmdStrListItem(cmditem.Next);
  3856. end;
  3857. tmplist.Free;
  3858. { add unit environment and exepath to the unit search path }
  3859. if inputfilepath<>'' then
  3860. Unitsearchpath.AddPath(inputfilepath,true);
  3861. if not disable_configfile then
  3862. begin
  3863. env:=GetEnvironmentVariable(target_info.unit_env);
  3864. if env<>'' then
  3865. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  3866. end;
  3867. {$ifdef Unix}
  3868. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3869. if fpcdir='' then
  3870. begin
  3871. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  3872. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  3873. else
  3874. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  3875. end;
  3876. {$else unix}
  3877. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3878. if fpcdir='' then
  3879. begin
  3880. fpcdir:=ExePath+'../';
  3881. if not(PathExists(fpcdir+'units',true)) and
  3882. not(PathExists(fpcdir+'rtl',true)) then
  3883. fpcdir:=fpcdir+'../';
  3884. end;
  3885. {$endif unix}
  3886. { first try development RTL, else use the default installation path }
  3887. if not disable_configfile then
  3888. begin
  3889. if PathExists(FpcDir+'rtl',true) then
  3890. if (tf_use_8_3 in Source_Info.Flags) or
  3891. (tf_use_8_3 in Target_Info.Flags) then
  3892. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  3893. else
  3894. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  3895. else
  3896. if (tf_use_8_3 in Source_Info.Flags) or
  3897. (tf_use_8_3 in Target_Info.Flags) then
  3898. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  3899. else
  3900. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  3901. end;
  3902. { Add exepath if the exe is not in the current dir, because that is always searched already.
  3903. Do not add it when linking on the target because then we can maybe already find
  3904. .o files that are not for the target }
  3905. if (ExePath<>cfileutl.GetCurrentDir) and
  3906. not(cs_link_on_target in init_settings.globalswitches) then
  3907. UnitSearchPath.AddPath(ExePath,false);
  3908. { Add unit dir to the object and library path }
  3909. objectsearchpath.AddList(unitsearchpath,false);
  3910. librarysearchpath.AddList(unitsearchpath,false);
  3911. {$ifdef llvm}
  3912. { default to clang }
  3913. if (option.paratargetasm=as_none) then
  3914. begin
  3915. option.paratargetasm:=as_llvm_clang;
  3916. end;
  3917. {$endif llvm}
  3918. { maybe override assembler }
  3919. if (option.paratargetasm<>as_none) then
  3920. begin
  3921. if not set_target_asm(option.paratargetasm) then
  3922. begin
  3923. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name);
  3924. set_target_asm(target_info.assemextern);
  3925. Message1(option_asm_forced,target_asm.idtxt);
  3926. end;
  3927. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  3928. (option.paratargetdbg<>dbg_none) then
  3929. begin
  3930. Message1(option_confict_asm_debug,
  3931. asminfos[option.paratargetasm]^.idtxt);
  3932. option.paratargetdbg:=dbg_none;
  3933. exclude(init_settings.moduleswitches,cs_debuginfo);
  3934. end;
  3935. { Some assemblers, like clang, do not support
  3936. stabs debugging format, switch to dwardé in that case }
  3937. if (af_no_stabs in asminfos[option.paratargetasm]^.flags) and
  3938. (option.paratargetdbg=dbg_stabs) then
  3939. begin
  3940. option.paratargetdbg:=dbg_dwarf2;
  3941. end;
  3942. end;
  3943. {TOptionheck a second time as we might have changed assembler just above }
  3944. option.checkoptionscompatibility;
  3945. { maybe override debug info format }
  3946. if (option.paratargetdbg<>dbg_none) then
  3947. if not set_target_dbg(option.paratargetdbg) then
  3948. Message(option_w_unsupported_debug_format);
  3949. { switch assembler if it's binary and we got -a on the cmdline }
  3950. if ((cs_asm_leave in init_settings.globalswitches) and
  3951. (af_outputbinary in target_asm.flags)) or
  3952. { if -s is passed, we shouldn't call the internal assembler }
  3953. (cs_asm_extern in init_settings.globalswitches) then
  3954. begin
  3955. Message(option_switch_bin_to_src_assembler);
  3956. {$ifdef llvm}
  3957. set_target_asm(as_llvm_clang);
  3958. {$else}
  3959. set_target_asm(target_info.assemextern);
  3960. {$endif}
  3961. { At least i8086 needs that for nasm and -CX
  3962. which is incompatible with internal linker }
  3963. option.checkoptionscompatibility;
  3964. end;
  3965. { Force use of external linker if there is no
  3966. internal linker or the linking is skipped }
  3967. if not(cs_link_extern in init_settings.globalswitches) and
  3968. ((target_info.link=ld_none) or
  3969. (cs_link_nolink in init_settings.globalswitches)) then
  3970. begin
  3971. include(init_settings.globalswitches,cs_link_extern);
  3972. end;
  3973. { turn off stripping if compiling with debuginfo or profile }
  3974. if (
  3975. (cs_debuginfo in init_settings.moduleswitches) or
  3976. (cs_profile in init_settings.moduleswitches)
  3977. ) and
  3978. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  3979. exclude(init_settings.globalswitches,cs_link_strip);
  3980. { choose a reasonable tls model }
  3981. if (tf_section_threadvars in target_info.flags) and (init_settings.tlsmodel=tlsm_none) then
  3982. begin
  3983. if cs_create_pic in init_settings.moduleswitches then
  3984. init_settings.tlsmodel:=tlsm_global_dynamic
  3985. else
  3986. init_settings.tlsmodel:=tlsm_local_exec;
  3987. end;
  3988. { set Mac OS X version default macros if not specified explicitly }
  3989. option.MaybeSetDefaultMacVersionMacro;
  3990. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  3991. if fpu type not explicitly set }
  3992. if not(option.FPUSetExplicitly) and
  3993. ((target_info.system in [system_arm_wince,system_arm_gba,
  3994. system_m68k_amiga,system_m68k_atari,
  3995. system_arm_nds,system_arm_embedded,
  3996. system_riscv32_embedded,system_riscv64_embedded])
  3997. {$ifdef arm}
  3998. or (target_info.abi=abi_eabi)
  3999. {$endif arm}
  4000. )
  4001. {$if defined(arm) or defined(riscv32) or defined(riscv64) or defined (m68k)}
  4002. or (init_settings.fputype=fpu_soft)
  4003. {$endif arm or m68k}
  4004. then
  4005. begin
  4006. {$ifdef cpufpemu}
  4007. include(init_settings.moduleswitches,cs_fp_emulation);
  4008. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  4009. init_settings.fputype:=fpu_soft;
  4010. {$endif cpufpemu}
  4011. end;
  4012. {$ifdef i386}
  4013. case target_info.system of
  4014. system_i386_android:
  4015. begin
  4016. { set default cpu type to PentiumM for Android unless specified otherwise }
  4017. if not option.CPUSetExplicitly then
  4018. init_settings.cputype:=cpu_PentiumM;
  4019. if not option.OptCPUSetExplicitly then
  4020. init_settings.optimizecputype:=cpu_PentiumM;
  4021. { set default fpu type to SSSE3 for Android unless specified otherwise }
  4022. if not option.FPUSetExplicitly then
  4023. init_settings.fputype:=fpu_ssse3;
  4024. end;
  4025. else
  4026. ;
  4027. end;
  4028. {$endif i386}
  4029. {$ifdef arm}
  4030. case target_info.system of
  4031. system_arm_darwin:
  4032. begin
  4033. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  4034. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  4035. }
  4036. if not option.CPUSetExplicitly then
  4037. init_settings.cputype:=cpu_armv7;
  4038. if not option.OptCPUSetExplicitly then
  4039. init_settings.optimizecputype:=cpu_armv7;
  4040. if not option.FPUSetExplicitly then
  4041. init_settings.fputype:=fpu_vfpv3;
  4042. end;
  4043. system_arm_android:
  4044. begin
  4045. { set default cpu type to ARMv5T for Android unless specified otherwise }
  4046. if not option.CPUSetExplicitly then
  4047. init_settings.cputype:=cpu_armv5t;
  4048. if not option.OptCPUSetExplicitly then
  4049. init_settings.optimizecputype:=cpu_armv5t;
  4050. end;
  4051. else
  4052. ;
  4053. end;
  4054. { ARMHF defaults }
  4055. if (target_info.abi = abi_eabihf) then
  4056. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  4057. begin
  4058. {$ifdef CPUARMV6}
  4059. { if the compiler is built for armv6, then
  4060. inherit this setting, e.g. Raspian is armhf but
  4061. only armv6, this makes rebuilds of the compiler
  4062. easier }
  4063. if not option.CPUSetExplicitly then
  4064. init_settings.cputype:=cpu_armv6;
  4065. if not option.OptCPUSetExplicitly then
  4066. init_settings.optimizecputype:=cpu_armv6;
  4067. {$else CPUARMV6}
  4068. if not option.CPUSetExplicitly then
  4069. init_settings.cputype:=cpu_armv7a;
  4070. if not option.OptCPUSetExplicitly then
  4071. init_settings.optimizecputype:=cpu_armv7a;
  4072. {$endif CPUARMV6}
  4073. { Set FPU type }
  4074. if not(option.FPUSetExplicitly) then
  4075. begin
  4076. if init_settings.cputype < cpu_armv7 then
  4077. init_settings.fputype:=fpu_vfpv2
  4078. else
  4079. init_settings.fputype:=fpu_vfpv3_d16;
  4080. end
  4081. else
  4082. begin
  4083. if (not(FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[init_settings.fputype]))
  4084. or (target_info.system = system_arm_darwin) then
  4085. begin
  4086. Message(option_illegal_fpu_eabihf);
  4087. StopOptions(1);
  4088. end;
  4089. end;
  4090. end;
  4091. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4092. begin
  4093. def_system_macro('CPUTHUMB');
  4094. if not option.FPUSetExplicitly then
  4095. init_settings.fputype:=fpu_soft;
  4096. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  4097. 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';
  4098. {$else FPC_ARMAL or FPC_ARMHF}
  4099. if target_info.endian=endian_little then
  4100. 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';
  4101. {$endif FPC_ARMAL or FPC_ARMHF}
  4102. end;
  4103. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  4104. def_system_macro('CPUTHUMB2');
  4105. {$endif arm}
  4106. {$if defined(riscv32) or defined(riscv64)}
  4107. { RISC-V defaults }
  4108. if (target_info.abi = abi_riscv_hf) then
  4109. begin
  4110. {$ifdef riscv32}
  4111. if not option.CPUSetExplicitly then
  4112. init_settings.cputype:=cpu_rv32ima;
  4113. if not option.OptCPUSetExplicitly then
  4114. init_settings.optimizecputype:=cpu_rv32ima;
  4115. {$else}
  4116. if not option.CPUSetExplicitly then
  4117. init_settings.cputype:=cpu_rv64imac;
  4118. if not option.OptCPUSetExplicitly then
  4119. init_settings.optimizecputype:=cpu_rv64imac;
  4120. {$endif}
  4121. { Set FPU type }
  4122. if not(option.FPUSetExplicitly) then
  4123. init_settings.fputype:=fpu_fd
  4124. else
  4125. begin
  4126. if not (init_settings.fputype in [fpu_fd]) then
  4127. begin
  4128. Message(option_illegal_fpu_eabihf);
  4129. StopOptions(1);
  4130. end;
  4131. end;
  4132. end;
  4133. {$endif defined(riscv32) or defined(riscv64)}
  4134. {$ifdef jvm}
  4135. { set default CPU type to Dalvik when targeting Android }
  4136. if target_info.system=system_jvm_android32 then
  4137. begin
  4138. if not option.CPUSetExplicitly then
  4139. init_settings.cputype:=cpu_dalvik;
  4140. end;
  4141. {$endif jvm}
  4142. {$ifdef llvm}
  4143. { standard extension for llvm bitcode files }
  4144. target_info.asmext:='.ll';
  4145. { don't generate dwarf cfi, llvm will do that }
  4146. exclude(target_info.flags,tf_needs_dwarf_cfi);
  4147. {$endif llvm}
  4148. {$ifdef mipsel}
  4149. case target_info.system of
  4150. system_mipsel_android:
  4151. begin
  4152. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  4153. if not option.CPUSetExplicitly then
  4154. init_settings.cputype:=cpu_mips32;
  4155. if not option.OptCPUSetExplicitly then
  4156. init_settings.optimizecputype:=cpu_mips32;
  4157. if not option.FPUSetExplicitly then
  4158. init_settings.fputype:=fpu_mips2;
  4159. end;
  4160. system_mipsel_embedded:
  4161. begin
  4162. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  4163. if not option.CPUSetExplicitly then
  4164. init_settings.cputype:=cpu_pic32mx;
  4165. if not option.OptCPUSetExplicitly then
  4166. init_settings.optimizecputype:=cpu_pic32mx;
  4167. if not option.FPUSetExplicitly then
  4168. init_settings.fputype:=fpu_soft;
  4169. end;
  4170. else
  4171. ;
  4172. end;
  4173. {$endif mipsel}
  4174. {$ifdef m68k}
  4175. if init_settings.cputype in cpu_coldfire then
  4176. def_system_macro('CPUCOLDFIRE');
  4177. case target_info.system of
  4178. system_m68k_linux,
  4179. system_m68k_netbsd:
  4180. begin
  4181. if not (option.FPUSetExplicitly) and
  4182. not (init_settings.cputype in cpu_coldfire) then
  4183. begin
  4184. { enable HW FPU for UNIX by default, but only for
  4185. original 68k, not Coldfire }
  4186. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4187. init_settings.fputype:=fpu_68881;
  4188. end;
  4189. end;
  4190. system_m68k_palmos:
  4191. begin
  4192. if not option.CPUSetExplicitly then
  4193. init_settings.cputype:=cpu_mc68000;
  4194. if not (option.FPUSetExplicitly) then
  4195. begin
  4196. { No FPU for PalmOS by default }
  4197. exclude(init_settings.moduleswitches,cs_fp_emulation);
  4198. init_settings.fputype:=fpu_none;
  4199. end;
  4200. end;
  4201. else
  4202. ;
  4203. end;
  4204. {$endif m68k}
  4205. { now we can define cpu and fpu type }
  4206. def_cpu_macros;
  4207. { Use init_settings cpu type for asm cpu type,
  4208. if asmcputype is cpu_none,
  4209. at least as long as there is no explicit
  4210. option to set it on command line PM }
  4211. if init_settings.asmcputype = cpu_none then
  4212. init_settings.asmcputype:=init_settings.cputype;
  4213. {$ifdef llvm}
  4214. def_system_macro('CPULLVM');
  4215. {$endif llvm}
  4216. {$if defined(cpucapabilities)}
  4217. for cpuflag:=low(cpuflag) to high(cpuflag) do
  4218. begin
  4219. str(cpuflag,hs);
  4220. if cpuflag in cpu_capabilities[init_settings.cputype] then
  4221. def_system_macro(hs)
  4222. else
  4223. undef_system_macro(hs);
  4224. end;
  4225. {$endif defined(cpucapabilities)}
  4226. {$if defined(fpucapabilities)}
  4227. for fpuflag:=low(fpuflag) to high(fpuflag) do
  4228. begin
  4229. str(fpuflag,hs);
  4230. if fpuflag in fpu_capabilities[init_settings.fputype] then
  4231. def_system_macro(hs)
  4232. else
  4233. undef_system_macro(hs);
  4234. end;
  4235. {$endif defined(fpucapabilities)}
  4236. if init_settings.fputype<>fpu_none then
  4237. begin
  4238. {$if defined(i386) or defined(i8086)}
  4239. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4240. {$endif}
  4241. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4242. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4243. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  4244. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4245. {$endif}
  4246. {$if defined(m68k)}
  4247. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  4248. {$endif}
  4249. {$ifdef x86_64}
  4250. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4251. { normally, win64 doesn't support the legacy fpu }
  4252. if target_info.system=system_x86_64_win64 then
  4253. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  4254. else
  4255. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4256. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4257. {$endif}
  4258. end;
  4259. { Enable now for testing }
  4260. {$ifndef DISABLE_TLS_DIRECTORY}
  4261. if target_info.system in systems_windows then
  4262. def_system_macro('FPC_USE_TLS_DIRECTORY');
  4263. {$endif not DISABLE_TLS_DIRECTORY}
  4264. {$ifndef DISABLE_WIN64_SEH}
  4265. if target_info.system=system_x86_64_win64 then
  4266. def_system_macro('FPC_USE_WIN64_SEH');
  4267. {$endif DISABLE_WIN64_SEH}
  4268. {$ifndef DISABLE_WIN32_SEH}
  4269. if target_info.system=system_i386_win32 then
  4270. def_system_macro('FPC_USE_WIN32_SEH');
  4271. {$endif not DISABLE_WIN32_SEH}
  4272. {$ifdef ARM}
  4273. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  4274. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  4275. not(cs_fp_emulation in init_settings.moduleswitches) then
  4276. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  4277. {$endif ARM}
  4278. { inline bsf/bsr implementation }
  4279. {$if defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64)}
  4280. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4281. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4282. {$endif}
  4283. { hardware FMA support }
  4284. {$if defined(i386) or defined(x86_64)}
  4285. if (cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[] then
  4286. begin
  4287. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  4288. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  4289. end;
  4290. {$endif defined(i386) or defined(x86_64)}
  4291. {$if defined(arm)}
  4292. { it is determined during system unit compilation if clz is used for bsf or not,
  4293. this is not perfect but the current implementation bsf/bsr does not allow another
  4294. solution }
  4295. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  4296. ((init_settings.instructionset=is_arm) or
  4297. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  4298. begin
  4299. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4300. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  4301. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4302. end;
  4303. {$endif}
  4304. {$if defined(powerpc64)}
  4305. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  4306. big endian (unless specified otherwise). As the gcc man page says:
  4307. "Overriding the default ABI requires special system support and is
  4308. likely to fail in spectacular ways" }
  4309. if not option.ABISetExplicitly then
  4310. begin
  4311. if (target_info.abi=abi_powerpc_sysv) and
  4312. (target_info.endian=endian_little) then
  4313. target_info.abi:=abi_powerpc_elfv2
  4314. else
  4315. if (target_info.abi=abi_powerpc_elfv2) and
  4316. (target_info.endian=endian_big) then
  4317. target_info.abi:=abi_powerpc_sysv
  4318. end;
  4319. {$endif}
  4320. {$if defined(powerpc) or defined(powerpc64)}
  4321. { define _CALL_ELF symbol like gcc }
  4322. case target_info.abi of
  4323. abi_powerpc_sysv:
  4324. set_system_compvar('_CALL_ELF','1');
  4325. abi_powerpc_elfv2:
  4326. set_system_compvar('_CALL_ELF','2');
  4327. else
  4328. ;
  4329. end;
  4330. {$endif}
  4331. { Section smartlinking conflicts with import sections on Windows }
  4332. if GenerateImportSection and
  4333. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  4334. exclude(target_info.flags,tf_smartlink_sections);
  4335. if not option.LinkTypeSetExplicitly then
  4336. set_default_link_type;
  4337. { Default alignment settings,
  4338. 1. load the defaults for the target
  4339. 2. override with generic optimizer setting (little size)
  4340. 3. override with the user specified -Oa }
  4341. UpdateAlignment(init_settings.alignment,target_info.alignment);
  4342. if (cs_opt_size in init_settings.optimizerswitches) then
  4343. begin
  4344. init_settings.alignment.procalign:=1;
  4345. init_settings.alignment.jumpalign:=1;
  4346. init_settings.alignment.coalescealign:=1;
  4347. init_settings.alignment.loopalign:=1;
  4348. {$ifdef x86}
  4349. { constalignmax=1 keeps the executable and thus the memory foot print small but
  4350. all processors except x86 are really hurt by this or might even crash }
  4351. init_settings.alignment.constalignmax:=1;
  4352. {$endif x86}
  4353. end;
  4354. UpdateAlignment(init_settings.alignment,option.paraalignment);
  4355. set_system_macro('FPC_VERSION',version_nr);
  4356. set_system_macro('FPC_RELEASE',release_nr);
  4357. set_system_macro('FPC_PATCH',patch_nr);
  4358. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  4359. if target_info.system in systems_indirect_entry_information then
  4360. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  4361. if not (tf_winlikewidestring in target_info.flags) then
  4362. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  4363. if tf_supports_packages in target_info.flags then
  4364. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  4365. if target_info.system in systems_indirect_var_imports then
  4366. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  4367. if cs_compilesystem in init_settings.moduleswitches then
  4368. for i:=low(tfeature) to high(tfeature) do
  4369. if i in features then
  4370. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  4371. {$push}
  4372. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  4373. if ControllerSupport and (target_info.system in systems_embedded) and
  4374. (init_settings.controllertype<>ct_none) then
  4375. begin
  4376. with embedded_controllers[init_settings.controllertype] do
  4377. begin
  4378. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  4379. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  4380. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  4381. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  4382. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  4383. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  4384. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  4385. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  4386. end;
  4387. end;
  4388. {$pop}
  4389. { as stackalign is not part of the alignment record, we do not need to define the others alignments for symmetry yet }
  4390. set_system_macro('FPC_STACKALIGNMENT',tostr(target_info.stackalign));
  4391. option.free;
  4392. Option:=nil;
  4393. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl];
  4394. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  4395. if (tf_safecall_clearstack in target_info.flags) then
  4396. begin
  4397. include (cdecl_pocalls, pocall_safecall);
  4398. include (clearstack_pocalls, pocall_safecall)
  4399. end;
  4400. end;
  4401. initialization
  4402. coption:=toption;
  4403. finalization
  4404. if assigned(option) then
  4405. option.free;
  4406. end.