options.pas 130 KB

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