options.pas 153 KB

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