options.pas 129 KB

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