options.pas 156 KB

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