2
0

options.pas 133 KB

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