options.pas 140 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186
  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
  2076. IllegalPara(opt);
  2077. end;
  2078. 'b':
  2079. begin
  2080. if target_info.system in systems_darwin then
  2081. begin
  2082. if UnsetBool(More, j, opt, false) then
  2083. SetApptype(app_cui)
  2084. else
  2085. SetApptype(app_bundle)
  2086. end
  2087. else
  2088. IllegalPara(opt);
  2089. end;
  2090. 'B':
  2091. begin
  2092. if target_info.system in systems_all_windows+systems_symbian then
  2093. begin
  2094. { -WB200000 means set trefered base address
  2095. to $200000, but does not change relocsection boolean
  2096. this way we can create both relocatble and
  2097. non relocatable DLL at a specific base address PM }
  2098. if (length(More)>j) then
  2099. begin
  2100. val('$'+Copy(More,j+1,255),imagebase,code);
  2101. if code<>0 then
  2102. IllegalPara(opt);
  2103. ImageBaseSetExplicity:=true;
  2104. end
  2105. else
  2106. begin
  2107. RelocSection:=true;
  2108. RelocSectionSetExplicitly:=true;
  2109. end;
  2110. break;
  2111. end
  2112. else
  2113. IllegalPara(opt);
  2114. end;
  2115. 'C':
  2116. begin
  2117. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2118. begin
  2119. if UnsetBool(More, j, opt, false) then
  2120. SetApptype(app_gui)
  2121. else
  2122. SetApptype(app_cui);
  2123. end
  2124. else
  2125. IllegalPara(opt);
  2126. end;
  2127. 'D':
  2128. begin
  2129. if target_info.system in systems_all_windows then
  2130. begin
  2131. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2132. UseDeffileForExportsSetExplicitly:=true;
  2133. end
  2134. else
  2135. IllegalPara(opt);
  2136. end;
  2137. 'e':
  2138. begin
  2139. if (target_info.system in systems_darwin) then
  2140. begin
  2141. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  2142. set_target_res(res_ext);
  2143. target_info.resobjext:='.fpcres';
  2144. end
  2145. else
  2146. IllegalPara(opt);
  2147. end;
  2148. 'F':
  2149. begin
  2150. if target_info.system in systems_os2 then
  2151. begin
  2152. if UnsetBool(More, j, opt, false) then
  2153. SetApptype(app_cui)
  2154. else
  2155. SetApptype(app_fs);
  2156. end
  2157. else
  2158. IllegalPara(opt);
  2159. end;
  2160. 'G':
  2161. begin
  2162. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2163. begin
  2164. if UnsetBool(More, j, opt, false) then
  2165. SetApptype(app_cui)
  2166. else
  2167. SetApptype(app_gui);
  2168. end
  2169. else
  2170. IllegalPara(opt);
  2171. end;
  2172. 'I':
  2173. begin
  2174. if target_info.system in systems_all_windows then
  2175. begin
  2176. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2177. GenerateImportSectionSetExplicitly:=true;
  2178. end
  2179. else
  2180. IllegalPara(opt);
  2181. end;
  2182. 'i':
  2183. begin
  2184. if (target_info.system in systems_darwin) then
  2185. begin
  2186. set_target_res(res_macho);
  2187. target_info.resobjext:=
  2188. targetinfos[target_info.system]^.resobjext;
  2189. end
  2190. else
  2191. IllegalPara(opt);
  2192. end;
  2193. 'm':
  2194. begin
  2195. {$if defined(i8086)}
  2196. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  2197. begin
  2198. case Upper(Copy(More,j+1,255)) of
  2199. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2200. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2201. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2202. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2203. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2204. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2205. else
  2206. IllegalPara(opt);
  2207. end;
  2208. break;
  2209. end
  2210. else
  2211. {$endif defined(i8086)}
  2212. IllegalPara(opt);
  2213. end;
  2214. 'M':
  2215. begin
  2216. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim])) and
  2217. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2218. begin
  2219. break;
  2220. end
  2221. else
  2222. IllegalPara(opt);
  2223. end;
  2224. 'N':
  2225. begin
  2226. if target_info.system in systems_all_windows then
  2227. begin
  2228. RelocSection:=UnsetBool(More,j,opt,false);
  2229. RelocSectionSetExplicitly:=true;
  2230. end
  2231. else
  2232. IllegalPara(opt);
  2233. end;
  2234. 'p':
  2235. begin
  2236. {$push}
  2237. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  2238. if (target_info.system in systems_embedded) and
  2239. ControllerSupport then
  2240. begin
  2241. s:=upper(copy(more,j+1,length(more)-j));
  2242. if not(SetControllerType(s,init_settings.controllertype)) then
  2243. IllegalPara(opt);
  2244. break;
  2245. end
  2246. else
  2247. IllegalPara(opt);
  2248. {$pop}
  2249. end;
  2250. 'P':
  2251. begin
  2252. if (target_info.system in [system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim]) and
  2253. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2254. begin
  2255. break;
  2256. end
  2257. else
  2258. IllegalPara(opt);
  2259. end;
  2260. 'R':
  2261. begin
  2262. if target_info.system in systems_all_windows then
  2263. begin
  2264. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2265. RelocSection:=not UnsetBool(More,j,opt,false);
  2266. RelocSectionSetExplicitly:=true;
  2267. end
  2268. else
  2269. IllegalPara(opt);
  2270. end;
  2271. 't':
  2272. begin
  2273. {$if defined(i8086)}
  2274. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  2275. begin
  2276. case Upper(Copy(More,j+1,255)) of
  2277. 'EXE': SetAppType(app_cui);
  2278. 'COM': SetAppType(app_com);
  2279. else
  2280. IllegalPara(opt);
  2281. end;
  2282. break;
  2283. end
  2284. else
  2285. {$endif defined(i8086)}
  2286. IllegalPara(opt);
  2287. end;
  2288. 'T':
  2289. begin
  2290. if target_info.system in systems_macos then
  2291. begin
  2292. if UnsetBool(More, j, opt, false) then
  2293. SetApptype(app_cui)
  2294. else
  2295. SetApptype(app_tool);
  2296. end
  2297. else
  2298. IllegalPara(opt);
  2299. end;
  2300. 'X':
  2301. begin
  2302. if (target_info.system in systems_linux) then
  2303. begin
  2304. if UnsetBool(More, j, opt, false) then
  2305. exclude(init_settings.moduleswitches,cs_executable_stack)
  2306. else
  2307. include(init_settings.moduleswitches,cs_executable_stack)
  2308. end
  2309. else
  2310. IllegalPara(opt);
  2311. end;
  2312. else
  2313. IllegalPara(opt);
  2314. end;
  2315. inc(j);
  2316. end;
  2317. end;
  2318. 'X' :
  2319. begin
  2320. j:=1;
  2321. while j<=length(more) do
  2322. begin
  2323. case More[j] of
  2324. '9' :
  2325. begin
  2326. if target_info.system in systems_linux then
  2327. begin
  2328. if UnsetBool(More, j, opt, false) then
  2329. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2330. else
  2331. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2332. end
  2333. else
  2334. IllegalPara(opt);
  2335. end;
  2336. 'c' : Cshared:=TRUE;
  2337. 'd' : Dontlinkstdlibpath:=TRUE;
  2338. 'e' :
  2339. begin
  2340. If UnsetBool(More, j, opt, false) then
  2341. exclude(init_settings.globalswitches,cs_link_extern)
  2342. else
  2343. include(init_settings.globalswitches,cs_link_extern);
  2344. end;
  2345. 'f' :
  2346. include(init_settings.globalswitches,cs_link_pthread);
  2347. 'g' :
  2348. begin
  2349. If UnsetBool(More, j, opt, false) then
  2350. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2351. else
  2352. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2353. end;
  2354. 'i' :
  2355. begin
  2356. If UnsetBool(More, j, opt, false) then
  2357. include(init_settings.globalswitches,cs_link_extern)
  2358. else
  2359. exclude(init_settings.globalswitches,cs_link_extern);
  2360. end;
  2361. 'n' :
  2362. begin
  2363. If UnsetBool(More, j, opt, false) then
  2364. exclude(init_settings.globalswitches,cs_link_native)
  2365. else
  2366. include(init_settings.globalswitches,cs_link_native);
  2367. end;
  2368. 'm' :
  2369. begin
  2370. If UnsetBool(More, j, opt, false) then
  2371. exclude(init_settings.globalswitches,cs_link_map)
  2372. else
  2373. include(init_settings.globalswitches,cs_link_map);
  2374. end;
  2375. 'p' : ; { Ignore used by fpc.pp }
  2376. 'r' :
  2377. begin
  2378. if (target_info.system in suppported_targets_x_smallr) then
  2379. begin
  2380. rlinkpath:=Copy(more,2,length(More)-1);
  2381. DefaultReplacements(rlinkpath);
  2382. end
  2383. else
  2384. IgnoredPara('-Xr');
  2385. more:='';
  2386. end;
  2387. 'R' :
  2388. begin
  2389. sysrootpath:=copy(more,2,length(more)-1);
  2390. defaultreplacements(sysrootpath);
  2391. more:='';
  2392. end;
  2393. 's' :
  2394. begin
  2395. If UnsetBool(More, j, opt, false) then
  2396. exclude(init_settings.globalswitches,cs_link_strip)
  2397. else
  2398. include(init_settings.globalswitches,cs_link_strip);
  2399. end;
  2400. 't' :
  2401. include(init_settings.globalswitches,cs_link_staticflag);
  2402. 'v' :
  2403. begin
  2404. If UnsetBool(More, j, opt, false) then
  2405. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2406. else
  2407. include(init_settings.globalswitches,cs_link_opt_vtable);
  2408. end;
  2409. 'D' :
  2410. begin
  2411. def_system_macro('FPC_LINK_DYNAMIC');
  2412. undef_system_macro('FPC_LINK_SMART');
  2413. undef_system_macro('FPC_LINK_STATIC');
  2414. exclude(init_settings.globalswitches,cs_link_static);
  2415. exclude(init_settings.globalswitches,cs_link_smart);
  2416. include(init_settings.globalswitches,cs_link_shared);
  2417. LinkTypeSetExplicitly:=true;
  2418. end;
  2419. 'M' :
  2420. begin
  2421. mainaliasname:=Copy(more,2,length(More)-1);
  2422. More:='';
  2423. end;
  2424. 'P' :
  2425. begin
  2426. utilsprefix:=Copy(more,2,length(More)-1);
  2427. DefaultReplacements(utilsprefix);
  2428. More:='';
  2429. end;
  2430. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2431. // these are not aggregable.
  2432. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2433. IllegalPara(opt)
  2434. else
  2435. begin
  2436. case more[j+1] of
  2437. 'A' : begin
  2438. s:=Copy(more,3,length(More)-2);
  2439. if not LinkLibraryAliases.AddDep(s) Then
  2440. IllegalPara(opt);
  2441. end;
  2442. 'O' : begin
  2443. s:=Copy(more,3,length(More)-2);
  2444. if not LinkLibraryOrder.AddWeight(s) Then
  2445. IllegalPara(opt);
  2446. end;
  2447. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2448. else
  2449. IllegalPara(opt);
  2450. end; {case}
  2451. j:=length(more);
  2452. end; {else begin}
  2453. end;
  2454. 'S' :
  2455. begin
  2456. ForceStaticLinking;
  2457. end;
  2458. 'V' :
  2459. begin
  2460. if UnsetBool(More, j, opt, false) then
  2461. exclude(init_settings.globalswitches,cs_link_vlink)
  2462. else
  2463. begin
  2464. include(init_settings.globalswitches,cs_link_vlink);
  2465. include(init_settings.globalswitches,cs_link_extern);
  2466. end;
  2467. end;
  2468. 'X' :
  2469. begin
  2470. def_system_macro('FPC_LINK_SMART');
  2471. undef_system_macro('FPC_LINK_STATIC');
  2472. undef_system_macro('FPC_LINK_DYNAMIC');
  2473. exclude(init_settings.globalswitches,cs_link_static);
  2474. include(init_settings.globalswitches,cs_link_smart);
  2475. exclude(init_settings.globalswitches,cs_link_shared);
  2476. LinkTypeSetExplicitly:=true;
  2477. end;
  2478. '-' :
  2479. begin
  2480. exclude(init_settings.globalswitches,cs_link_staticflag);
  2481. exclude(init_settings.globalswitches,cs_link_strip);
  2482. exclude(init_settings.globalswitches,cs_link_map);
  2483. set_default_link_type;
  2484. end;
  2485. else
  2486. IllegalPara(opt);
  2487. end;
  2488. inc(j);
  2489. end;
  2490. end;
  2491. else
  2492. IllegalPara(opt);
  2493. end;
  2494. end;
  2495. '@' :
  2496. begin
  2497. Message(option_no_nested_response_file);
  2498. StopOptions(1);
  2499. end;
  2500. else
  2501. begin
  2502. if (length(param_file)<>0) then
  2503. Message2(option_only_one_source_support,param_file,opt);
  2504. param_file:=opt;
  2505. Message1(option_found_file,opt);
  2506. end;
  2507. end;
  2508. end;
  2509. procedure Toption.Interpret_file(const filename : TPathStr);
  2510. procedure RemoveSep(var fn:TPathStr);
  2511. var
  2512. i : longint;
  2513. begin
  2514. i:=0;
  2515. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2516. inc(i);
  2517. Delete(fn,1,i);
  2518. i:=length(fn);
  2519. while (i>0) and (fn[i] in [',',' ',#9]) do
  2520. dec(i);
  2521. fn:=copy(fn,1,i);
  2522. end;
  2523. function GetName(var fn:TPathStr):TPathStr;
  2524. var
  2525. i : longint;
  2526. begin
  2527. i:=0;
  2528. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2529. inc(i);
  2530. GetName:=Copy(fn,1,i);
  2531. Delete(fn,1,i);
  2532. end;
  2533. const
  2534. maxlevel = 15;
  2535. var
  2536. f : text;
  2537. s, tmp,
  2538. opts : TCmdStr;
  2539. skip : array[0..maxlevel] of boolean;
  2540. line,
  2541. level : longint;
  2542. option_read : boolean;
  2543. oldfilemode : byte;
  2544. ConfigFile: TPathStr;
  2545. begin
  2546. { avoid infinite loop }
  2547. Inc(FileLevel);
  2548. Option_read:=false;
  2549. If FileLevel>MaxLevel then
  2550. Message(option_too_many_cfg_files);
  2551. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2552. ConfigFile := ExpandFileName(filename);
  2553. { Maybe It's Directory ?} //Jaro Change:
  2554. if PathExists(ConfigFile,false) then
  2555. begin
  2556. Message1(option_config_is_dir,filename);
  2557. exit;
  2558. end;
  2559. { open file }
  2560. Message1(option_using_file,filename);
  2561. oldfilemode:=filemode;
  2562. filemode:=0;
  2563. assign(f,ConfigFile);
  2564. {$push}{$I-}
  2565. reset(f);
  2566. {$pop}
  2567. filemode:=oldfilemode;
  2568. if ioresult<>0 then
  2569. begin
  2570. Message1(option_unable_open_file,filename);
  2571. exit;
  2572. end;
  2573. Message1(option_start_reading_configfile,filename);
  2574. fillchar(skip,sizeof(skip),0);
  2575. level:=0;
  2576. line:=0;
  2577. while not eof(f) do
  2578. begin
  2579. readln(f,opts);
  2580. inc(line);
  2581. RemoveSep(opts);
  2582. if (opts<>'') and (opts[1]<>';') then
  2583. begin
  2584. if opts[1]='#' then
  2585. begin
  2586. Message1(option_interpreting_file_option,opts);
  2587. Delete(opts,1,1);
  2588. s:=upper(GetName(opts));
  2589. if (s='SECTION') then
  2590. begin
  2591. RemoveSep(opts);
  2592. s:=upper(GetName(opts));
  2593. if level=0 then
  2594. skip[level]:=not defined_macro(s) or (s='COMMON');
  2595. end
  2596. else
  2597. if (s='IFDEF') then
  2598. begin
  2599. RemoveSep(opts);
  2600. if Level>=maxlevel then
  2601. begin
  2602. Message2(option_too_many_ifdef,filename,tostr(line));
  2603. stopOptions(1);
  2604. end;
  2605. inc(Level);
  2606. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2607. end
  2608. else
  2609. if (s='IFNDEF') then
  2610. begin
  2611. RemoveSep(opts);
  2612. if Level>=maxlevel then
  2613. begin
  2614. Message2(option_too_many_ifdef,filename,tostr(line));
  2615. stopOptions(1);
  2616. end;
  2617. inc(Level);
  2618. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2619. end
  2620. else
  2621. if (s='ELSE') then
  2622. begin
  2623. if Level=0 then
  2624. begin
  2625. Message2(option_else_without_if,filename,tostr(line));
  2626. stopOptions(1);
  2627. end
  2628. else
  2629. skip[level]:=skip[level-1] or (not skip[level])
  2630. end
  2631. else
  2632. if (s='ENDIF') then
  2633. begin
  2634. skip[level]:=false;
  2635. if Level=0 then
  2636. begin
  2637. Message2(option_too_many_endif,filename,tostr(line));
  2638. stopOptions(1);
  2639. end;
  2640. dec(level);
  2641. end
  2642. else
  2643. if (not skip[level]) then
  2644. begin
  2645. if (s='DEFINE') then
  2646. begin
  2647. RemoveSep(opts);
  2648. tmp:= GetName(opts);
  2649. if tmp <> '' then
  2650. def_system_macro(tmp);
  2651. Option_read:=true;
  2652. end
  2653. else
  2654. if (s='UNDEF') then
  2655. begin
  2656. RemoveSep(opts);
  2657. tmp:= GetName(opts);
  2658. if tmp <> '' then
  2659. undef_system_macro(tmp);
  2660. Option_read:=true;
  2661. end
  2662. else
  2663. if (s='WRITE') then
  2664. begin
  2665. Delete(opts,1,1);
  2666. DefaultReplacements(opts);
  2667. WriteLn(opts);
  2668. Option_read:=true;
  2669. end
  2670. else
  2671. if (s='INCLUDE') then
  2672. begin
  2673. Delete(opts,1,1);
  2674. DefaultReplacements(opts);
  2675. Interpret_file(opts);
  2676. Option_read:=true;
  2677. end
  2678. else
  2679. if (s='CFGDIR') then
  2680. begin
  2681. Delete(opts,1,1);
  2682. DefaultReplacements(opts);
  2683. ParaIncludeCfgPath.AddPath(opts,false);
  2684. Option_read:=true;
  2685. end;
  2686. end;
  2687. end
  2688. else
  2689. begin
  2690. if (opts[1]='-') or (opts[1]='@') then
  2691. begin
  2692. if (not skip[level]) then
  2693. interpret_option(opts,false);
  2694. Option_read:=true;
  2695. end
  2696. else
  2697. Message1(option_illegal_para,opts);
  2698. end;
  2699. end;
  2700. end;
  2701. if Level>0 then
  2702. Message(option_too_less_endif);
  2703. if Not Option_read then
  2704. Message1(option_no_option_found,filename)
  2705. else
  2706. Message1(option_end_reading_configfile,filename);
  2707. Close(f);
  2708. Dec(FileLevel);
  2709. end;
  2710. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  2711. var
  2712. argstart,
  2713. env,
  2714. pc : pchar;
  2715. arglen : longint;
  2716. quote : set of char;
  2717. hs : TCmdStr;
  2718. begin
  2719. Message1(option_using_env,envname);
  2720. env:=GetEnvPChar(envname);
  2721. pc:=env;
  2722. if assigned(pc) then
  2723. begin
  2724. repeat
  2725. { skip leading spaces }
  2726. while pc^ in [' ',#9,#13] do
  2727. inc(pc);
  2728. case pc^ of
  2729. #0 :
  2730. break;
  2731. '"' :
  2732. begin
  2733. quote:=['"'];
  2734. inc(pc);
  2735. end;
  2736. '''' :
  2737. begin
  2738. quote:=[''''];
  2739. inc(pc);
  2740. end;
  2741. else
  2742. quote:=[' ',#9,#13];
  2743. end;
  2744. { scan until the end of the argument }
  2745. argstart:=pc;
  2746. while (pc^<>#0) and not(pc^ in quote) do
  2747. inc(pc);
  2748. { create argument }
  2749. arglen:=pc-argstart;
  2750. { TODO: FIXME: silent truncation of environment parameters }
  2751. if (arglen > 255) then
  2752. arglen := 255;
  2753. setlength(hs,arglen);
  2754. move(argstart^,hs[1],arglen);
  2755. interpret_option(hs,true);
  2756. { skip quote }
  2757. if pc^ in quote then
  2758. inc(pc);
  2759. until false;
  2760. end
  2761. else
  2762. Message1(option_no_option_found,'(env) '+envname);
  2763. FreeEnvPChar(env);
  2764. end;
  2765. procedure toption.read_parameters;
  2766. var
  2767. opts : TCmdStr;
  2768. paramindex : longint;
  2769. begin
  2770. paramindex:=0;
  2771. while paramindex<paramcount do
  2772. begin
  2773. inc(paramindex);
  2774. opts:=objpas.paramstr(paramindex);
  2775. if length(opts)>0 then
  2776. case opts[1] of
  2777. '@' :
  2778. if not firstpass then
  2779. begin
  2780. Delete(opts,1,1);
  2781. Message1(option_reading_further_from,opts);
  2782. interpret_file(opts);
  2783. end;
  2784. '!' :
  2785. if not firstpass then
  2786. begin
  2787. Delete(opts,1,1);
  2788. Message1(option_reading_further_from,'(env) '+opts);
  2789. interpret_envvar(opts);
  2790. end;
  2791. else
  2792. interpret_option(opts,true);
  2793. end;
  2794. end;
  2795. end;
  2796. procedure toption.parsecmd(cmd:TCmdStr);
  2797. var
  2798. i,ps : longint;
  2799. opts : TCmdStr;
  2800. begin
  2801. while (cmd<>'') do
  2802. begin
  2803. while cmd[1]=' ' do
  2804. delete(cmd,1,1);
  2805. i:=pos(' ',cmd);
  2806. if i=0 then
  2807. i:=2147483647;
  2808. opts:=Copy(cmd,1,i-1);
  2809. Delete(cmd,1,i);
  2810. case opts[1] of
  2811. '@' :
  2812. if not firstpass then
  2813. begin
  2814. Delete(opts,1,1);
  2815. Message1(option_reading_further_from,opts);
  2816. interpret_file(opts);
  2817. end;
  2818. '!' :
  2819. if not firstpass then
  2820. begin
  2821. Delete(opts,1,1);
  2822. Message1(option_reading_further_from,'(env) '+opts);
  2823. interpret_envvar(opts);
  2824. end;
  2825. '"' :
  2826. begin
  2827. Delete(opts,1,1);
  2828. ps:=pos('"',cmd);
  2829. if (i<>256) and (ps>0) then
  2830. begin
  2831. opts:=opts + ' '+ copy(cmd,1,ps-1);
  2832. cmd:=copy(cmd,ps+1,255);
  2833. end;
  2834. interpret_option(opts,true);
  2835. end;
  2836. else
  2837. interpret_option(opts,true);
  2838. end;
  2839. end;
  2840. end;
  2841. procedure toption.writequickinfo;
  2842. var
  2843. s : string;
  2844. i : longint;
  2845. procedure addinfo(const hs:string);
  2846. begin
  2847. if s<>'' then
  2848. s:=s+' '+hs
  2849. else
  2850. s:=hs;
  2851. end;
  2852. begin
  2853. s:='';
  2854. i:=0;
  2855. while (i<length(quickinfo)) do
  2856. begin
  2857. inc(i);
  2858. case quickinfo[i] of
  2859. 'S' :
  2860. begin
  2861. inc(i);
  2862. case quickinfo[i] of
  2863. 'O' :
  2864. addinfo(lower(source_info.shortname));
  2865. 'P' :
  2866. addinfo(source_cpu_string);
  2867. else
  2868. IllegalPara('-i'+QuickInfo);
  2869. end;
  2870. end;
  2871. 'T' :
  2872. begin
  2873. inc(i);
  2874. case quickinfo[i] of
  2875. 'O' :
  2876. addinfo(lower(target_info.shortname));
  2877. 'P' :
  2878. AddInfo(target_cpu_string);
  2879. else
  2880. IllegalPara('-i'+QuickInfo);
  2881. end;
  2882. end;
  2883. 'V' :
  2884. AddInfo(version_string);
  2885. 'W' :
  2886. AddInfo(full_version_string);
  2887. 'D' :
  2888. AddInfo(date_string);
  2889. '_' :
  2890. ;
  2891. else
  2892. IllegalPara('-i'+QuickInfo);
  2893. end;
  2894. end;
  2895. if s<>'' then
  2896. begin
  2897. writeln(s);
  2898. stopoptions(0);
  2899. end;
  2900. end;
  2901. procedure TOption.TargetOptions(def:boolean);
  2902. var
  2903. s : string;
  2904. i : integer;
  2905. target_unsup_features : tfeatures;
  2906. begin
  2907. if def then
  2908. def_system_macro(target_info.shortname)
  2909. else
  2910. undef_system_macro(target_info.shortname);
  2911. s:=target_info.extradefines;
  2912. while (s<>'') do
  2913. begin
  2914. i:=pos(';',s);
  2915. if i=0 then
  2916. i:=length(s)+1;
  2917. if def then
  2918. def_system_macro(Copy(s,1,i-1))
  2919. else
  2920. undef_system_macro(Copy(s,1,i-1));
  2921. delete(s,1,i);
  2922. end;
  2923. if (tf_winlikewidestring in target_info.flags) then
  2924. if def then
  2925. def_system_macro('FPC_WINLIKEWIDESTRING')
  2926. else
  2927. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2928. if (tf_requires_proper_alignment in target_info.flags) then
  2929. if def then
  2930. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2931. else
  2932. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2933. if source_info.system<>target_info.system then
  2934. if def then
  2935. def_system_macro('FPC_CROSSCOMPILING')
  2936. else
  2937. undef_system_macro('FPC_CROSSCOMPILING');
  2938. if source_info.cpu<>target_info.cpu then
  2939. if def then
  2940. def_system_macro('FPC_CPUCROSSCOMPILING')
  2941. else
  2942. def_system_macro('FPC_CPUCROSSCOMPILING');
  2943. if (tf_no_generic_stackcheck in target_info.flags) then
  2944. if def then
  2945. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2946. else
  2947. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2948. if (tf_section_threadvars in target_info.flags) then
  2949. if def then
  2950. def_system_macro('FPC_SECTION_THREADVARS')
  2951. else
  2952. undef_system_macro('FPC_SECTION_THREADVARS');
  2953. { Code generation flags }
  2954. if (tf_pic_default in target_info.flags) then
  2955. if def then
  2956. include(init_settings.moduleswitches,cs_create_pic)
  2957. else
  2958. exclude(init_settings.moduleswitches,cs_create_pic);
  2959. { Resources support }
  2960. if (tf_has_winlike_resources in target_info.flags) then
  2961. if def then
  2962. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2963. else
  2964. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2965. { Features }
  2966. case target_info.system of
  2967. system_arm_gba:
  2968. target_unsup_features:=[f_dynlibs];
  2969. system_arm_nds:
  2970. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2971. system_i386_nativent:
  2972. // until these features are implemented, they are disabled in the compiler
  2973. target_unsup_features:=[f_stackcheck];
  2974. system_jvm_java32,
  2975. system_jvm_android32:
  2976. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  2977. f_variants,f_objects,f_commandargs,
  2978. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  2979. else
  2980. target_unsup_features:=[];
  2981. end;
  2982. if def then
  2983. features:=features-target_unsup_features
  2984. else
  2985. features:=features+target_unsup_features;
  2986. {$if defined(atari) or defined(hasamiga)}
  2987. { enable vlink as default linker on Atari, Amiga, and MorphOS, but not for cross compilers (for now) }
  2988. if target_info.system in [system_m68k_amiga,system_m68k_atari,
  2989. system_powerpc_amiga,system_powerpc_morphos] then
  2990. include(init_settings.globalswitches,cs_link_vlink);
  2991. {$endif}
  2992. end;
  2993. procedure TOption.checkoptionscompatibility;
  2994. begin
  2995. {$ifdef i8086}
  2996. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  2997. begin
  2998. Message(option_com_files_require_tiny_model);
  2999. StopOptions(1);
  3000. end;
  3001. {$endif i8086}
  3002. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  3003. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  3004. begin
  3005. { smartlink creation does not yet work with DWARF
  3006. debug info on most targets, but it works in internal assembler }
  3007. if (cs_create_smart in init_settings.moduleswitches) and
  3008. not (af_outputbinary in target_asm.flags) then
  3009. begin
  3010. Message(option_dwarf_smartlink_creation);
  3011. exclude(init_settings.moduleswitches,cs_create_smart);
  3012. end;
  3013. { smart linking does not yet work with DWARF debug info on most targets }
  3014. if (cs_link_smart in init_settings.globalswitches) then
  3015. begin
  3016. Message(option_dwarf_smart_linking);
  3017. ForceStaticLinking;
  3018. end;
  3019. end;
  3020. { external debug info is only supported for DWARF on darwin }
  3021. if (target_info.system in systems_darwin) and
  3022. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  3023. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  3024. begin
  3025. Message(option_debug_external_unsupported);
  3026. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  3027. end;
  3028. { Also create a smartlinked version, on an assembler that
  3029. does not support smartlink sections like nasm?
  3030. This is not compatible with using internal linker. }
  3031. if ((cs_link_smart in init_settings.globalswitches) or
  3032. (cs_create_smart in init_settings.moduleswitches)) and
  3033. (af_needar in target_asm.flags) and
  3034. not (af_smartlink_sections in target_asm.flags) and
  3035. not (cs_link_extern in init_settings.globalswitches) and
  3036. (target_info.link<>ld_none) and
  3037. not (cs_link_nolink in init_settings.globalswitches) then
  3038. begin
  3039. Message(option_smart_link_requires_external_linker);
  3040. include(init_settings.globalswitches,cs_link_extern);
  3041. end;
  3042. end;
  3043. constructor TOption.create;
  3044. begin
  3045. LogoWritten:=false;
  3046. NoPressEnter:=false;
  3047. FirstPass:=false;
  3048. ABISetExplicitly:=false;
  3049. FPUSetExplicitly:=false;
  3050. CPUSetExplicitly:=false;
  3051. OptCPUSetExplicitly:=false;
  3052. FileLevel:=0;
  3053. Quickinfo:='';
  3054. ParaIncludeCfgPath:=TSearchPathList.Create;
  3055. ParaIncludePath:=TSearchPathList.Create;
  3056. ParaObjectPath:=TSearchPathList.Create;
  3057. ParaUnitPath:=TSearchPathList.Create;
  3058. ParaLibraryPath:=TSearchPathList.Create;
  3059. ParaFrameworkPath:=TSearchPathList.Create;
  3060. parapackagepath:=TSearchPathList.Create;
  3061. parapackages:=TFPHashObjectList.Create;
  3062. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3063. MacVersionSet:=false;
  3064. paratarget:=system_none;
  3065. paratargetasm:=as_none;
  3066. paratargetdbg:=dbg_none;
  3067. LinkTypeSetExplicitly:=false;
  3068. end;
  3069. destructor TOption.destroy;
  3070. begin
  3071. ParaIncludeCfgPath.Free;
  3072. ParaIncludePath.Free;
  3073. ParaObjectPath.Free;
  3074. ParaUnitPath.Free;
  3075. ParaLibraryPath.Free;
  3076. ParaFrameworkPath.Free;
  3077. parapackagepath.Free;
  3078. ParaPackages.Free;
  3079. end;
  3080. {****************************************************************************
  3081. Callable Routines
  3082. ****************************************************************************}
  3083. function check_configfile(fn:string; var foundfn:string):boolean;
  3084. function CfgFileExists(const fn:string):boolean;
  3085. begin
  3086. Comment(V_Tried,'Configfile search: '+fn);
  3087. CfgFileExists:=FileExists(fn);
  3088. end;
  3089. var
  3090. {$ifdef Unix}
  3091. hs,
  3092. {$endif Unix}
  3093. configpath : string;
  3094. begin
  3095. foundfn:=fn;
  3096. check_configfile:=true;
  3097. { retrieve configpath }
  3098. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3099. {$ifdef Unix}
  3100. if configpath='' then
  3101. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3102. {$endif}
  3103. {
  3104. Order to read configuration file :
  3105. try reading fpc.cfg in :
  3106. 1 - current dir
  3107. 2 - configpath
  3108. 3 - compiler path
  3109. }
  3110. if not FileExists(fn) then
  3111. begin
  3112. {$ifdef Unix}
  3113. hs:=GetEnvironmentVariable('HOME');
  3114. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3115. foundfn:=FixPath(hs,false)+'.'+fn
  3116. else
  3117. {$endif}
  3118. if CfgFileExists(configpath+fn) then
  3119. foundfn:=configpath+fn
  3120. else
  3121. {$ifdef WINDOWS}
  3122. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3123. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3124. else
  3125. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3126. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3127. else
  3128. {$endif WINDOWS}
  3129. {$ifndef Unix}
  3130. if CfgFileExists(exepath+fn) then
  3131. foundfn:=exepath+fn
  3132. else
  3133. {$else}
  3134. if CfgFileExists('/etc/'+fn) then
  3135. foundfn:='/etc/'+fn
  3136. else
  3137. {$endif}
  3138. check_configfile:=false;
  3139. end;
  3140. end;
  3141. procedure read_arguments(cmd:TCmdStr);
  3142. var
  3143. env: ansistring;
  3144. i : tfeature;
  3145. j : longint;
  3146. abi : tabi;
  3147. {$if defined(cpucapabilities)}
  3148. cpuflag : tcpuflags;
  3149. hs : string;
  3150. {$endif defined(cpucapabilities)}
  3151. begin
  3152. option:=coption.create;
  3153. disable_configfile:=false;
  3154. { Non-core target defines }
  3155. Option.TargetOptions(true);
  3156. { get default messagefile }
  3157. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  3158. { default configfile can be specified on the commandline,
  3159. remove it first }
  3160. if (cmd<>'') and (cmd[1]='[') then
  3161. begin
  3162. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  3163. Delete(cmd,1,pos(']',cmd));
  3164. end
  3165. else
  3166. ppccfg:='fpc.cfg';
  3167. { first pass reading of parameters, only -i -v -T etc.}
  3168. option.firstpass:=true;
  3169. if cmd<>'' then
  3170. option.parsecmd(cmd)
  3171. else
  3172. begin
  3173. option.read_parameters;
  3174. { Write only quickinfo }
  3175. if option.quickinfo<>'' then
  3176. option.writequickinfo;
  3177. end;
  3178. option.firstpass:=false;
  3179. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  3180. Option.TargetOptions(true);
  3181. { target is set here, for wince the default app type is gui }
  3182. if target_info.system in systems_wince then
  3183. SetApptype(app_gui)
  3184. else
  3185. SetApptype(apptype);
  3186. { default defines }
  3187. def_system_macro(target_info.shortname);
  3188. def_system_macro('FPC');
  3189. def_system_macro('VER'+version_nr);
  3190. def_system_macro('VER'+version_nr+'_'+release_nr);
  3191. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  3192. { Temporary defines, until things settle down }
  3193. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  3194. def_system_macro('FPC_HAS_CONSTREF');
  3195. def_system_macro('FPC_STATICRIPFIXED');
  3196. def_system_macro('FPC_VARIANTCOPY_FIXED');
  3197. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  3198. { abs(long) is handled internally on all CPUs }
  3199. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  3200. {$if defined(x86_64) or defined(powerpc64) or defined(cpuaarch64)}
  3201. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  3202. {$endif x86_64 or powerpc64 or aarch64}
  3203. def_system_macro('FPC_HAS_MANAGEMENT_OPERATORS');
  3204. def_system_macro('FPC_HAS_UNICODESTRING');
  3205. def_system_macro('FPC_RTTI_PACKSET1');
  3206. def_system_macro('FPC_HAS_CPSTRING');
  3207. {$ifdef x86_64}
  3208. def_system_macro('FPC_HAS_RIP_RELATIVE');
  3209. {$endif x86_64}
  3210. def_system_macro('FPC_HAS_CEXTENDED');
  3211. def_system_macro('FPC_HAS_RESSTRINITS');
  3212. { these cpus have an inline rol/ror implementaion }
  3213. {$ifdef cpurox}
  3214. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3215. {$endif}
  3216. { these cpus have an inline sar implementaion }
  3217. { currently, all supported CPUs have an internal sar implementation }
  3218. { $if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64) or defined(sparc) or defined(mips)}
  3219. def_system_macro('FPC_HAS_INTERNAL_SAR');
  3220. { $endif}
  3221. {$ifdef powerpc64}
  3222. def_system_macro('FPC_HAS_LWSYNC');
  3223. {$endif}
  3224. def_system_macro('FPC_HAS_MEMBAR');
  3225. def_system_macro('FPC_SETBASE_USED');
  3226. {$ifdef SUPPORT_GET_FRAME}
  3227. def_system_macro('INTERNAL_BACKTRACE');
  3228. {$endif SUPPORT_GET_FRAME}
  3229. def_system_macro('STR_CONCAT_PROCS');
  3230. {$warnings off}
  3231. if pocall_default = pocall_register then
  3232. def_system_macro('REGCALL');
  3233. {$warnings on}
  3234. { don't remove this, it's also for fpdoc necessary (FK) }
  3235. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  3236. { using a case is pretty useless here (FK) }
  3237. { some stuff for TP compatibility }
  3238. {$ifdef i386}
  3239. def_system_macro('CPU86');
  3240. def_system_macro('CPU87');
  3241. def_system_macro('CPU386');
  3242. {$endif}
  3243. { new processor stuff }
  3244. {$ifdef i386}
  3245. def_system_macro('CPUI386');
  3246. def_system_macro('CPU32');
  3247. def_system_macro('CPUX86');
  3248. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3249. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3250. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3251. {$endif}
  3252. {$ifdef m68k}
  3253. def_system_macro('CPU68');
  3254. def_system_macro('CPU68K');
  3255. def_system_macro('CPUM68K');
  3256. def_system_macro('CPU32');
  3257. def_system_macro('FPC_CURRENCY_IS_INT64');
  3258. def_system_macro('FPC_COMP_IS_INT64');
  3259. {$endif}
  3260. {$ifdef powerpc}
  3261. def_system_macro('CPUPOWERPC');
  3262. def_system_macro('CPUPOWERPC32');
  3263. def_system_macro('CPU32');
  3264. def_system_macro('FPC_CURRENCY_IS_INT64');
  3265. def_system_macro('FPC_COMP_IS_INT64');
  3266. {$endif}
  3267. {$ifdef POWERPC64}
  3268. def_system_macro('CPUPOWERPC');
  3269. def_system_macro('CPUPOWERPC64');
  3270. def_system_macro('CPU64');
  3271. def_system_macro('FPC_CURRENCY_IS_INT64');
  3272. def_system_macro('FPC_COMP_IS_INT64');
  3273. {$endif}
  3274. {$ifdef x86_64}
  3275. def_system_macro('CPUX86_64');
  3276. def_system_macro('CPUAMD64');
  3277. def_system_macro('CPU64');
  3278. def_system_macro('CPUX64');
  3279. { not supported for now, afaik (FK)
  3280. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3281. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3282. { normally, win64 doesn't support the legacy fpu }
  3283. if target_info.system=system_x86_64_win64 then
  3284. begin
  3285. def_system_macro('FPC_CURRENCY_IS_INT64');
  3286. def_system_macro('FPC_COMP_IS_INT64');
  3287. end;
  3288. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3289. {$endif}
  3290. {$ifdef sparc}
  3291. def_system_macro('CPUSPARC');
  3292. def_system_macro('CPUSPARC32');
  3293. def_system_macro('CPU32');
  3294. def_system_macro('FPC_CURRENCY_IS_INT64');
  3295. def_system_macro('FPC_COMP_IS_INT64');
  3296. {$endif}
  3297. {$ifdef arm}
  3298. def_system_macro('CPUARM');
  3299. def_system_macro('CPU32');
  3300. def_system_macro('FPC_CURRENCY_IS_INT64');
  3301. def_system_macro('FPC_COMP_IS_INT64');
  3302. {$endif arm}
  3303. {$ifdef avr}
  3304. def_system_macro('CPUAVR');
  3305. def_system_macro('CPU16');
  3306. def_system_macro('FPC_CURRENCY_IS_INT64');
  3307. def_system_macro('FPC_COMP_IS_INT64');
  3308. {$endif avr}
  3309. {$ifdef jvm}
  3310. def_system_macro('CPUJVM');
  3311. def_system_macro('CPU32');
  3312. def_system_macro('FPC_CURRENCY_IS_INT64');
  3313. def_system_macro('FPC_COMP_IS_INT64');
  3314. {$endif jvm}
  3315. {$ifdef mipsel}
  3316. def_system_macro('CPUMIPS');
  3317. def_system_macro('CPUMIPS32');
  3318. def_system_macro('CPUMIPSEL');
  3319. def_system_macro('CPUMIPSEL32');
  3320. def_system_macro('CPU32');
  3321. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3322. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3323. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3324. def_system_macro('FPC_CURRENCY_IS_INT64');
  3325. def_system_macro('FPC_COMP_IS_INT64');
  3326. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3327. { On most systems, locals are accessed relative to base pointer,
  3328. but for MIPS cpu, they are accessed relative to stack pointer.
  3329. This needs adaptation for so low level routines,
  3330. like MethodPointerLocal and related objects unit functions. }
  3331. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3332. {$endif mipsel}
  3333. {$ifdef mipseb}
  3334. def_system_macro('CPUMIPS');
  3335. def_system_macro('CPUMIPS32');
  3336. def_system_macro('CPUMIPSEB');
  3337. def_system_macro('CPUMIPSEB32');
  3338. def_system_macro('CPU32');
  3339. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3340. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3341. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3342. def_system_macro('FPC_CURRENCY_IS_INT64');
  3343. def_system_macro('FPC_COMP_IS_INT64');
  3344. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3345. { See comment above for mipsel }
  3346. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3347. {$endif}
  3348. {$ifdef i8086}
  3349. def_system_macro('CPU86'); { Borland compatibility }
  3350. def_system_macro('CPU87'); { Borland compatibility }
  3351. def_system_macro('CPUI8086');
  3352. def_system_macro('CPU16');
  3353. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3354. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3355. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3356. case init_settings.x86memorymodel of
  3357. mm_tiny: def_system_macro('FPC_MM_TINY');
  3358. mm_small: def_system_macro('FPC_MM_SMALL');
  3359. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3360. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3361. mm_large: def_system_macro('FPC_MM_LARGE');
  3362. mm_huge: def_system_macro('FPC_MM_HUGE');
  3363. end;
  3364. {$endif i8086}
  3365. {$ifdef aarch64}
  3366. def_system_macro('CPUAARCH64');
  3367. def_system_macro('CPU64');
  3368. def_system_macro('FPC_CURRENCY_IS_INT64');
  3369. def_system_macro('FPC_COMP_IS_INT64');
  3370. {$endif aarch64}
  3371. {$if defined(cpu8bitalu)}
  3372. def_system_macro('CPUINT8');
  3373. {$elseif defined(cpu16bitalu)}
  3374. def_system_macro('CPUINT16');
  3375. {$elseif defined(cpu32bitalu)}
  3376. def_system_macro('CPUINT32');
  3377. {$elseif defined(cpu64bitalu)}
  3378. def_system_macro('CPUINT64');
  3379. {$endif defined(cpu64bitalu)}
  3380. if tf_cld in target_info.flags then
  3381. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  3382. InternalError(2013092801);
  3383. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  3384. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  3385. InternalError(2013092801);
  3386. { Set up a default prefix for binutils when cross-compiling }
  3387. if source_info.system<>target_info.system then
  3388. case target_info.system of
  3389. { Use standard Android NDK prefixes }
  3390. system_arm_android:
  3391. utilsprefix:='arm-linux-androideabi-';
  3392. system_i386_android:
  3393. utilsprefix:='i686-linux-android-';
  3394. system_mipsel_android:
  3395. utilsprefix:='mipsel-linux-android-';
  3396. end;
  3397. { Set up default value for the heap }
  3398. if target_info.system in systems_embedded then
  3399. begin
  3400. case target_info.system of
  3401. {$ifdef AVR}
  3402. system_avr_embedded:
  3403. if init_settings.controllertype=ct_avrsim then
  3404. heapsize:=8192
  3405. else
  3406. heapsize:=128;
  3407. {$endif AVR}
  3408. system_arm_embedded:
  3409. heapsize:=256;
  3410. system_mipsel_embedded:
  3411. heapsize:=256;
  3412. else
  3413. heapsize:=256;
  3414. end;
  3415. end;
  3416. { read configuration file }
  3417. if (not disable_configfile) and
  3418. (ppccfg<>'') then
  3419. read_configfile:=check_configfile(ppccfg,ppccfg)
  3420. else
  3421. read_configfile := false;
  3422. { Read commandline and configfile }
  3423. param_file:='';
  3424. { read configfile }
  3425. if read_configfile then
  3426. option.interpret_file(ppccfg);
  3427. { read parameters again to override config file }
  3428. if cmd<>'' then
  3429. option.parsecmd(cmd)
  3430. else
  3431. begin
  3432. { Write help pages if no parameters are passed }
  3433. if (paramcount=0) then
  3434. Option.WriteHelpPages;
  3435. option.read_parameters;
  3436. { Write only quickinfo }
  3437. if option.quickinfo<>'' then
  3438. option.writequickinfo;
  3439. end;
  3440. { check the compatibility of different options and adjust them if necessary
  3441. (and print possible errors)
  3442. }
  3443. option.checkoptionscompatibility;
  3444. { uses the CPUXXX-defines and target_info to determine whether the selected
  3445. target processor, if any, is supported }
  3446. Option.VerifyTargetProcessor;
  3447. { Stop if errors in options }
  3448. if ErrorCount>0 then
  3449. StopOptions(1);
  3450. { endian define }
  3451. case target_info.endian of
  3452. endian_little :
  3453. begin
  3454. def_system_macro('ENDIAN_LITTLE');
  3455. def_system_macro('FPC_LITTLE_ENDIAN');
  3456. end;
  3457. endian_big :
  3458. begin
  3459. def_system_macro('ENDIAN_BIG');
  3460. def_system_macro('FPC_BIG_ENDIAN');
  3461. end;
  3462. end;
  3463. { define abi }
  3464. for abi:=low(tabi) to high(tabi) do
  3465. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3466. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3467. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3468. systems since most code needs to behave the same on both}
  3469. if target_info.abi = abi_eabihf then
  3470. def_system_macro('FPC_ABI_EABI');
  3471. { Write logo }
  3472. if option.ParaLogo then
  3473. option.writelogo;
  3474. { Check file to compile }
  3475. if param_file='' then
  3476. begin
  3477. Message(option_no_source_found);
  3478. StopOptions(1);
  3479. end;
  3480. {$ifndef Unix}
  3481. param_file:=FixFileName(param_file);
  3482. {$endif not unix}
  3483. inputfilepath:=ExtractFilePath(param_file);
  3484. inputfilename:=ExtractFileName(param_file);
  3485. if ExtractFileExt(inputfilename)='' then
  3486. begin
  3487. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  3488. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  3489. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  3490. inputfilename:=ChangeFileExt(inputfilename,pasext)
  3491. else if ((m_mac in current_settings.modeswitches) or
  3492. (tf_p_ext_support in target_info.flags))
  3493. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  3494. inputfilename:=ChangeFileExt(inputfilename,pext);
  3495. end;
  3496. { Check output dir }
  3497. if (OutputExeDir<>'') and
  3498. not PathExists(OutputExeDir,false) then
  3499. begin
  3500. Message1(general_e_path_does_not_exist,OutputExeDir);
  3501. StopOptions(1);
  3502. end;
  3503. { Add paths specified with parameters to the searchpaths }
  3504. UnitSearchPath.AddList(option.ParaUnitPath,true);
  3505. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  3506. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  3507. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  3508. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  3509. packagesearchpath.addlist(option.parapackagepath,true);
  3510. for j:=0 to option.parapackages.count-1 do
  3511. add_package(option.parapackages.NameOfIndex(j),true,true);
  3512. { add unit environment and exepath to the unit search path }
  3513. if inputfilepath<>'' then
  3514. Unitsearchpath.AddPath(inputfilepath,true);
  3515. if not disable_configfile then
  3516. begin
  3517. env:=GetEnvironmentVariable(target_info.unit_env);
  3518. if env<>'' then
  3519. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  3520. end;
  3521. {$ifdef Unix}
  3522. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3523. if fpcdir='' then
  3524. begin
  3525. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  3526. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  3527. else
  3528. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  3529. end;
  3530. {$else unix}
  3531. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3532. if fpcdir='' then
  3533. begin
  3534. fpcdir:=ExePath+'../';
  3535. if not(PathExists(fpcdir+'units',true)) and
  3536. not(PathExists(fpcdir+'rtl',true)) then
  3537. fpcdir:=fpcdir+'../';
  3538. end;
  3539. {$endif unix}
  3540. { first try development RTL, else use the default installation path }
  3541. if not disable_configfile then
  3542. begin
  3543. if PathExists(FpcDir+'rtl',true) then
  3544. if (tf_use_8_3 in Source_Info.Flags) or
  3545. (tf_use_8_3 in Target_Info.Flags) then
  3546. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  3547. else
  3548. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  3549. else
  3550. if (tf_use_8_3 in Source_Info.Flags) or
  3551. (tf_use_8_3 in Target_Info.Flags) then
  3552. UnitSearchPath.AddPath(FpcDir+'units/'+target_os_string+'/rtl',false)
  3553. else
  3554. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  3555. end;
  3556. { Add exepath if the exe is not in the current dir, because that is always searched already.
  3557. Do not add it when linking on the target because then we can maybe already find
  3558. .o files that are not for the target }
  3559. if (ExePath<>cfileutl.GetCurrentDir) and
  3560. not(cs_link_on_target in init_settings.globalswitches) then
  3561. UnitSearchPath.AddPath(ExePath,false);
  3562. { Add unit dir to the object and library path }
  3563. objectsearchpath.AddList(unitsearchpath,false);
  3564. librarysearchpath.AddList(unitsearchpath,false);
  3565. {$ifdef llvm}
  3566. { force llvm assembler writer }
  3567. option.paratargetasm:=as_llvm;
  3568. {$endif llvm}
  3569. { maybe override assembler }
  3570. if (option.paratargetasm<>as_none) then
  3571. begin
  3572. if not set_target_asm(option.paratargetasm) then
  3573. begin
  3574. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name);
  3575. set_target_asm(target_info.assemextern);
  3576. Message1(option_asm_forced,target_asm.idtxt);
  3577. end;
  3578. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  3579. (option.paratargetdbg<>dbg_none) then
  3580. begin
  3581. Message1(option_confict_asm_debug,
  3582. asminfos[option.paratargetasm]^.idtxt);
  3583. option.paratargetdbg:=dbg_none;
  3584. exclude(init_settings.moduleswitches,cs_debuginfo);
  3585. end;
  3586. end;
  3587. {TOptionheck a second time as we might have changed assembler just above }
  3588. option.checkoptionscompatibility;
  3589. { maybe override debug info format }
  3590. if (option.paratargetdbg<>dbg_none) then
  3591. if not set_target_dbg(option.paratargetdbg) then
  3592. Message(option_w_unsupported_debug_format);
  3593. { switch assembler if it's binary and we got -a on the cmdline }
  3594. if (cs_asm_leave in init_settings.globalswitches) and
  3595. (af_outputbinary in target_asm.flags) then
  3596. begin
  3597. Message(option_switch_bin_to_src_assembler);
  3598. set_target_asm(target_info.assemextern);
  3599. { At least i8086 needs that for nasm and -CX
  3600. which is incompatible with internal linker }
  3601. option.checkoptionscompatibility;
  3602. end;
  3603. { Force use of external linker if there is no
  3604. internal linker or the linking is skipped }
  3605. if not(cs_link_extern in init_settings.globalswitches) and
  3606. ((target_info.link=ld_none) or
  3607. (cs_link_nolink in init_settings.globalswitches)) then
  3608. begin
  3609. include(init_settings.globalswitches,cs_link_extern);
  3610. end;
  3611. { turn off stripping if compiling with debuginfo or profile }
  3612. if (
  3613. (cs_debuginfo in init_settings.moduleswitches) or
  3614. (cs_profile in init_settings.moduleswitches)
  3615. ) and
  3616. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  3617. exclude(init_settings.globalswitches,cs_link_strip);
  3618. { set Mac OS X version default macros if not specified explicitly }
  3619. option.MaybeSetDefaultMacVersionMacro;
  3620. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  3621. if fpu type not explicitly set }
  3622. if not(option.FPUSetExplicitly) and
  3623. ((target_info.system in [system_arm_wince,system_arm_gba,
  3624. system_m68k_amiga,system_m68k_atari,system_m68k_linux,
  3625. system_arm_nds,system_arm_embedded])
  3626. {$ifdef arm}
  3627. or (target_info.abi=abi_eabi)
  3628. {$endif arm}
  3629. )
  3630. {$if defined(arm) or defined (m68k)}
  3631. or (init_settings.fputype=fpu_soft)
  3632. {$endif arm or m68k}
  3633. then
  3634. begin
  3635. {$ifdef cpufpemu}
  3636. include(init_settings.moduleswitches,cs_fp_emulation);
  3637. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  3638. init_settings.fputype:=fpu_soft;
  3639. {$endif cpufpemu}
  3640. end;
  3641. {$ifdef i386}
  3642. case target_info.system of
  3643. system_i386_android:
  3644. begin
  3645. { set default cpu type to PentiumM for Android unless specified otherwise }
  3646. if not option.CPUSetExplicitly then
  3647. init_settings.cputype:=cpu_PentiumM;
  3648. if not option.OptCPUSetExplicitly then
  3649. init_settings.optimizecputype:=cpu_PentiumM;
  3650. { set default fpu type to SSSE3 for Android unless specified otherwise }
  3651. if not option.FPUSetExplicitly then
  3652. init_settings.fputype:=fpu_ssse3;
  3653. end;
  3654. end;
  3655. {$endif i386}
  3656. {$ifdef arm}
  3657. case target_info.system of
  3658. system_arm_darwin:
  3659. begin
  3660. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  3661. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  3662. }
  3663. if not option.CPUSetExplicitly then
  3664. init_settings.cputype:=cpu_armv7;
  3665. if not option.OptCPUSetExplicitly then
  3666. init_settings.optimizecputype:=cpu_armv7;
  3667. if not option.FPUSetExplicitly then
  3668. init_settings.fputype:=fpu_vfpv3;
  3669. end;
  3670. system_arm_android:
  3671. begin
  3672. { set default cpu type to ARMv5T for Android unless specified otherwise }
  3673. if not option.CPUSetExplicitly then
  3674. init_settings.cputype:=cpu_armv5t;
  3675. if not option.OptCPUSetExplicitly then
  3676. init_settings.optimizecputype:=cpu_armv5t;
  3677. end;
  3678. end;
  3679. { ARMHF defaults }
  3680. if (target_info.abi = abi_eabihf) then
  3681. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  3682. begin
  3683. {$ifdef CPUARMV6}
  3684. { if the compiler is built for armv6, then
  3685. inherit this setting, e.g. Raspian is armhf but
  3686. only armv6, this makes rebuilds of the compiler
  3687. easier }
  3688. if not option.CPUSetExplicitly then
  3689. init_settings.cputype:=cpu_armv6;
  3690. if not option.OptCPUSetExplicitly then
  3691. init_settings.optimizecputype:=cpu_armv6;
  3692. {$else CPUARMV6}
  3693. if not option.CPUSetExplicitly then
  3694. init_settings.cputype:=cpu_armv7a;
  3695. if not option.OptCPUSetExplicitly then
  3696. init_settings.optimizecputype:=cpu_armv7a;
  3697. {$endif CPUARMV6}
  3698. { Set FPU type }
  3699. if not(option.FPUSetExplicitly) then
  3700. begin
  3701. init_settings.fputype:=fpu_vfpv3_d16
  3702. end
  3703. else
  3704. begin
  3705. if not (init_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv3_d16,fpu_vfpv4]) then
  3706. begin
  3707. Message(option_illegal_fpu_eabihf);
  3708. StopOptions(1);
  3709. end;
  3710. end;
  3711. end;
  3712. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3713. begin
  3714. def_system_macro('CPUTHUMB');
  3715. if not option.FPUSetExplicitly then
  3716. init_settings.fputype:=fpu_soft;
  3717. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  3718. 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';
  3719. {$else FPC_ARMAL or FPC_ARMHF}
  3720. if target_info.endian=endian_little then
  3721. 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';
  3722. {$endif FPC_ARMAL or FPC_ARMHF}
  3723. end;
  3724. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3725. def_system_macro('CPUTHUMB2');
  3726. {$endif arm}
  3727. {$ifdef jvm}
  3728. { set default CPU type to Dalvik when targeting Android }
  3729. if target_info.system=system_jvm_android32 then
  3730. begin
  3731. if not option.CPUSetExplicitly then
  3732. init_settings.cputype:=cpu_dalvik;
  3733. end;
  3734. {$endif jvm}
  3735. {$ifdef llvm}
  3736. { standard extension for llvm bitcode files }
  3737. target_info.asmext:='.ll';
  3738. { don't generate dwarf cfi, llvm will do that }
  3739. exclude(target_info.flags,tf_needs_dwarf_cfi);
  3740. {$endif llvm}
  3741. {$ifdef mipsel}
  3742. case target_info.system of
  3743. system_mipsel_android:
  3744. begin
  3745. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  3746. if not option.CPUSetExplicitly then
  3747. init_settings.cputype:=cpu_mips32;
  3748. if not option.OptCPUSetExplicitly then
  3749. init_settings.optimizecputype:=cpu_mips32;
  3750. if not option.FPUSetExplicitly then
  3751. init_settings.fputype:=fpu_mips2;
  3752. end;
  3753. system_mipsel_embedded:
  3754. begin
  3755. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  3756. if not option.CPUSetExplicitly then
  3757. init_settings.cputype:=cpu_pic32mx;
  3758. if not option.OptCPUSetExplicitly then
  3759. init_settings.optimizecputype:=cpu_pic32mx;
  3760. if not option.FPUSetExplicitly then
  3761. init_settings.fputype:=fpu_soft;
  3762. end;
  3763. end;
  3764. {$endif mipsel}
  3765. {$ifdef m68k}
  3766. if init_settings.cputype in cpu_coldfire then
  3767. def_system_macro('CPUCOLDFIRE');
  3768. {$endif m68k}
  3769. { now we can define cpu and fpu type }
  3770. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3771. { Use init_settings cpu type for asm cpu type,
  3772. if asmcputype is cpu_none,
  3773. at least as long as there is no explicit
  3774. option to set it on command line PM }
  3775. if init_settings.asmcputype = cpu_none then
  3776. init_settings.asmcputype:=init_settings.cputype;
  3777. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3778. {$ifdef llvm}
  3779. def_system_macro('CPULLVM');
  3780. {$endif llvm}
  3781. {$if defined(cpucapabilities)}
  3782. for cpuflag:=low(cpuflag) to high(cpuflag) do
  3783. begin
  3784. str(cpuflag,hs);
  3785. if cpuflag in cpu_capabilities[init_settings.cputype] then
  3786. def_system_macro(hs)
  3787. else
  3788. undef_system_macro(hs);
  3789. end;
  3790. {$endif defined(cpucapabilities)}
  3791. if init_settings.fputype<>fpu_none then
  3792. begin
  3793. {$if defined(i386) or defined(i8086)}
  3794. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3795. {$endif}
  3796. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3797. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3798. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  3799. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3800. {$endif}
  3801. {$if defined(m68k)}
  3802. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  3803. {$endif}
  3804. {$ifdef x86_64}
  3805. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3806. { normally, win64 doesn't support the legacy fpu }
  3807. if target_info.system=system_x86_64_win64 then
  3808. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  3809. else
  3810. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3811. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3812. {$endif}
  3813. end;
  3814. { Enable now for testing }
  3815. {$ifndef DISABLE_TLS_DIRECTORY}
  3816. if target_info.system in systems_windows then
  3817. def_system_macro('FPC_USE_TLS_DIRECTORY');
  3818. {$endif not DISABLE_TLS_DIRECTORY}
  3819. {$ifndef DISABLE_WIN64_SEH}
  3820. if target_info.system=system_x86_64_win64 then
  3821. def_system_macro('FPC_USE_WIN64_SEH');
  3822. {$endif DISABLE_WIN64_SEH}
  3823. {$ifdef TEST_WIN32_SEH}
  3824. if target_info.system=system_i386_win32 then
  3825. def_system_macro('FPC_USE_WIN32_SEH');
  3826. {$endif TEST_WIN32_SEH}
  3827. {$ifdef ARM}
  3828. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  3829. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  3830. not(cs_fp_emulation in init_settings.moduleswitches) then
  3831. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  3832. {$endif ARM}
  3833. { inline bsf/bsr implementation }
  3834. {$if not defined(llvm) and (defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64))}
  3835. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3836. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3837. {$endif}
  3838. { hardware FMA support }
  3839. {$if defined(i386) or defined(x86_64)}
  3840. if (cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[] then
  3841. begin
  3842. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  3843. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  3844. end;
  3845. {$endif defined(i386) or defined(x86_64)}
  3846. {$if defined(arm)}
  3847. { it is determined during system unit compilation if clz is used for bsf or not,
  3848. this is not perfect but the current implementation bsf/bsr does not allow another
  3849. solution }
  3850. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  3851. ((init_settings.instructionset=is_arm) or
  3852. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  3853. begin
  3854. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3855. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  3856. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3857. end;
  3858. {$endif}
  3859. {$if defined(powerpc64)}
  3860. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  3861. big endian (unless specified otherwise). As the gcc man page says:
  3862. "Overriding the default ABI requires special system support and is
  3863. likely to fail in spectacular ways" }
  3864. if not option.ABISetExplicitly then
  3865. begin
  3866. if (target_info.abi=abi_powerpc_sysv) and
  3867. (target_info.endian=endian_little) then
  3868. target_info.abi:=abi_powerpc_elfv2
  3869. else
  3870. if (target_info.abi=abi_powerpc_elfv2) and
  3871. (target_info.endian=endian_big) then
  3872. target_info.abi:=abi_powerpc_sysv
  3873. end;
  3874. {$endif}
  3875. {$if defined(powerpc) or defined(powerpc64)}
  3876. { define _CALL_ELF symbol like gcc }
  3877. case target_info.abi of
  3878. abi_powerpc_sysv:
  3879. set_system_compvar('_CALL_ELF','1');
  3880. abi_powerpc_elfv2:
  3881. set_system_compvar('_CALL_ELF','2');
  3882. end;
  3883. {$endif}
  3884. { Section smartlinking conflicts with import sections on Windows }
  3885. if GenerateImportSection and
  3886. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  3887. exclude(target_info.flags,tf_smartlink_sections);
  3888. if not option.LinkTypeSetExplicitly then
  3889. set_default_link_type;
  3890. { Default alignment settings,
  3891. 1. load the defaults for the target
  3892. 2. override with generic optimizer setting (little size)
  3893. 3. override with the user specified -Oa }
  3894. UpdateAlignment(init_settings.alignment,target_info.alignment);
  3895. if (cs_opt_size in init_settings.optimizerswitches) then
  3896. begin
  3897. init_settings.alignment.procalign:=1;
  3898. init_settings.alignment.jumpalign:=1;
  3899. init_settings.alignment.loopalign:=1;
  3900. {$ifdef x86}
  3901. { constalignmax=1 keeps the executable and thus the memory foot print small but
  3902. all processors except x86 are really hurt by this or might even crash }
  3903. init_settings.alignment.constalignmax:=1;
  3904. {$endif x86}
  3905. end;
  3906. UpdateAlignment(init_settings.alignment,option.paraalignment);
  3907. set_system_macro('FPC_VERSION',version_nr);
  3908. set_system_macro('FPC_RELEASE',release_nr);
  3909. set_system_macro('FPC_PATCH',patch_nr);
  3910. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  3911. if target_info.system in systems_indirect_entry_information then
  3912. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  3913. if not (tf_winlikewidestring in target_info.flags) then
  3914. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  3915. if tf_supports_packages in target_info.flags then
  3916. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  3917. if target_info.system in systems_indirect_var_imports then
  3918. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  3919. for i:=low(tfeature) to high(tfeature) do
  3920. if i in features then
  3921. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  3922. {$push}
  3923. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  3924. if ControllerSupport and (target_info.system in systems_embedded) and
  3925. (init_settings.controllertype<>ct_none) then
  3926. begin
  3927. with embedded_controllers[init_settings.controllertype] do
  3928. begin
  3929. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  3930. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  3931. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  3932. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  3933. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  3934. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  3935. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  3936. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  3937. end;
  3938. end;
  3939. {$pop}
  3940. option.free;
  3941. Option:=nil;
  3942. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl];
  3943. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  3944. if (tf_safecall_clearstack in target_info.flags) then
  3945. begin
  3946. include (cdecl_pocalls, pocall_safecall);
  3947. include (clearstack_pocalls, pocall_safecall)
  3948. end;
  3949. end;
  3950. initialization
  3951. coption:=toption;
  3952. finalization
  3953. if assigned(option) then
  3954. option.free;
  3955. end.