options.pas 131 KB

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