options.pas 141 KB

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