options.pas 138 KB

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