options.pas 131 KB

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