options.pas 151 KB

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