options.pas 154 KB

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