2
0

options.pas 150 KB

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