options.pas 152 KB

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