options.pas 148 KB

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