options.pas 140 KB

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