options.pas 132 KB

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