options.pas 128 KB

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