options.pas 155 KB

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