options.pas 151 KB

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