options.pas 134 KB

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