options.pas 156 KB

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