options.pas 149 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429
  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
  1628. include(init_settings.globalswitches,cs_use_heaptrc);
  1629. end;
  1630. 'l' :
  1631. begin
  1632. if UnsetBool(More, j, opt, false) then
  1633. exclude(init_settings.globalswitches,cs_use_lineinfo)
  1634. else
  1635. include(init_settings.globalswitches,cs_use_lineinfo);
  1636. end;
  1637. 'm' :
  1638. begin
  1639. paratargetdbg:=dbg_codeview;
  1640. end;
  1641. 'o' :
  1642. begin
  1643. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  1644. IllegalPara(opt);
  1645. break;
  1646. end;
  1647. 'p' :
  1648. begin
  1649. if UnsetBool(More, j, opt, false) then
  1650. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  1651. else
  1652. include(init_settings.globalswitches,cs_stabs_preservecase);
  1653. end;
  1654. 's' :
  1655. begin
  1656. paratargetdbg:=dbg_stabs;
  1657. end;
  1658. 't' :
  1659. begin
  1660. if UnsetBool(More, j, opt, false) then
  1661. localvartrashing := -1
  1662. else
  1663. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  1664. end;
  1665. 'v' :
  1666. begin
  1667. if UnsetBool(More, j, opt, false) then
  1668. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  1669. else
  1670. include(init_settings.globalswitches,cs_gdb_valgrind);
  1671. end;
  1672. 'w' :
  1673. begin
  1674. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  1675. begin
  1676. case more[j+1] of
  1677. '2': paratargetdbg:=dbg_dwarf2;
  1678. '3': paratargetdbg:=dbg_dwarf3;
  1679. '4': paratargetdbg:=dbg_dwarf4;
  1680. end;
  1681. inc(j);
  1682. end
  1683. else
  1684. paratargetdbg:=dbg_dwarf2;
  1685. end;
  1686. else
  1687. IllegalPara(opt);
  1688. end;
  1689. inc(j);
  1690. end;
  1691. end;
  1692. 'h' :
  1693. begin
  1694. NoPressEnter:=true;
  1695. if (More <> '') and (More [1] = 'F') then
  1696. begin
  1697. FPCHelpLines := true;
  1698. Delete (More, 1, 1);
  1699. FPCBinaryPath := More;
  1700. end;
  1701. WriteHelpPages;
  1702. end;
  1703. 'i' :
  1704. begin
  1705. if (More='') or
  1706. (More [1] in ['a', 'c', 'f', 'i', 'o', 'r', 't', 'u', 'w']) then
  1707. WriteInfo (More)
  1708. else
  1709. QuickInfo:=QuickInfo+More;
  1710. end;
  1711. 'I' :
  1712. begin
  1713. if ispara then
  1714. ParaIncludePath.AddPath(More,false)
  1715. else
  1716. includesearchpath.AddPath(More,false);
  1717. end;
  1718. 'k' :
  1719. begin
  1720. if more<>'' then
  1721. ParaLinkOptions:=ParaLinkOptions+' '+More
  1722. else
  1723. IllegalPara(opt);
  1724. end;
  1725. 'l' :
  1726. ParaLogo:=not UnSetBool(more,0,opt,true);
  1727. {$ifdef PREPROCWRITE}
  1728. 'm' :
  1729. parapreprocess:=not UnSetBool(more,0,opt,true);
  1730. {$endif PREPROCWRITE}
  1731. 'M' :
  1732. begin
  1733. more:=Upper(more);
  1734. if not SetCompileMode(more, true) then
  1735. if not SetCompileModeSwitch(more, true) then
  1736. IllegalPara(opt);
  1737. end;
  1738. 'n' :
  1739. begin
  1740. if More='' then
  1741. disable_configfile:=true
  1742. else
  1743. IllegalPara(opt);
  1744. end;
  1745. 'o' :
  1746. begin
  1747. if More<>'' then
  1748. begin
  1749. DefaultReplacements(More);
  1750. D:=ExtractFilePath(More);
  1751. if (D<>'') then
  1752. OutputExeDir:=FixPath(D,True);
  1753. OutputFileName:=ExtractFileName(More);
  1754. end
  1755. else
  1756. IllegalPara(opt);
  1757. end;
  1758. 'O' :
  1759. begin
  1760. j:=1;
  1761. while j<=length(more) do
  1762. begin
  1763. case more[j] of
  1764. '1' :
  1765. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1766. '2' :
  1767. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1768. '3' :
  1769. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1770. '4' :
  1771. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  1772. 'a' :
  1773. begin
  1774. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1775. IllegalPara(opt);
  1776. break;
  1777. end;
  1778. 's' :
  1779. include(init_settings.optimizerswitches,cs_opt_size);
  1780. 'p' :
  1781. begin
  1782. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1783. begin
  1784. OptCPUSetExplicitly:=true;
  1785. { Give warning for old i386 switches }
  1786. if (Length(More)-j=1) and
  1787. (More[j+1]>='1') and (More[j+1]<='5')then
  1788. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1789. else
  1790. IllegalPara(opt);
  1791. end;
  1792. break;
  1793. end;
  1794. 'o' :
  1795. begin
  1796. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  1797. IllegalPara(opt);
  1798. break;
  1799. end;
  1800. '-' :
  1801. begin
  1802. init_settings.optimizerswitches:=[];
  1803. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1804. end;
  1805. { Obsolete switches }
  1806. 'g' :
  1807. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  1808. 'G' :
  1809. Message1(option_obsolete_switch,'-OG');
  1810. 'r' :
  1811. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  1812. 'u' :
  1813. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  1814. 'w' :
  1815. begin
  1816. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  1817. IllegalPara(opt);
  1818. break;
  1819. end;
  1820. 'W' :
  1821. begin
  1822. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  1823. IllegalPara(opt);
  1824. break;
  1825. end;
  1826. else
  1827. IllegalPara(opt);
  1828. end;
  1829. inc(j);
  1830. end;
  1831. end;
  1832. 'p' :
  1833. begin
  1834. if UnsetBool(More, 0, opt, false) then
  1835. begin
  1836. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  1837. undef_system_macro('FPC_PROFILE');
  1838. end
  1839. else
  1840. if Length(More)=0 then
  1841. IllegalPara(opt)
  1842. else
  1843. case more[1] of
  1844. 'g' : if UnsetBool(more, 1, opt, false) then
  1845. begin
  1846. exclude(init_settings.moduleswitches,cs_profile);
  1847. undef_system_macro('FPC_PROFILE');
  1848. end
  1849. else if (target_info.system in supported_targets_pg) then
  1850. begin
  1851. include(init_settings.moduleswitches,cs_profile);
  1852. def_system_macro('FPC_PROFILE');
  1853. end
  1854. else
  1855. UnsupportedPara('-pg');
  1856. else
  1857. IllegalPara(opt);
  1858. end;
  1859. end;
  1860. 'P' :
  1861. begin
  1862. { used to select the target processor with the "fpc" binary;
  1863. give an error if it's not the target architecture supported by
  1864. this compiler binary (will be verified after the target_info
  1865. is set) }
  1866. processorstr:=More;
  1867. end;
  1868. 'R' :
  1869. begin
  1870. if not SetAsmReadMode(More,init_settings.asmmode) then
  1871. IllegalPara(opt);
  1872. end;
  1873. 's' :
  1874. begin
  1875. if UnsetBool(More, 0, opt, false) then
  1876. begin
  1877. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1878. if more<>'' then
  1879. IllegalPara(opt);
  1880. end
  1881. else
  1882. begin
  1883. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1884. if more='h' then
  1885. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target]
  1886. else if more='t' then
  1887. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]
  1888. else if more='r' then
  1889. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  1890. else if more<>'' then
  1891. IllegalPara(opt);
  1892. end;
  1893. end;
  1894. 'S' :
  1895. begin
  1896. if more='' then
  1897. IllegalPara(opt);
  1898. if more[1]='I' then
  1899. begin
  1900. {$ifdef jvm}
  1901. UnsupportedPara('-SI');
  1902. {$endif}
  1903. if upper(more)='ICOM' then
  1904. init_settings.interfacetype:=it_interfacecom
  1905. else if upper(more)='ICORBA' then
  1906. init_settings.interfacetype:=it_interfacecorba
  1907. else
  1908. IllegalPara(opt);
  1909. end
  1910. else
  1911. begin
  1912. j:=1;
  1913. while j<=length(more) do
  1914. begin
  1915. case more[j] of
  1916. '2' : //an alternative to -Mobjfpc
  1917. SetCompileMode('OBJFPC',true);
  1918. 'a' :
  1919. If UnsetBool(More, j, opt, false) then
  1920. exclude(init_settings.localswitches,cs_do_assertion)
  1921. else
  1922. include(init_settings.localswitches,cs_do_assertion);
  1923. 'c' :
  1924. If UnsetBool(More, j, opt, false) then
  1925. exclude(init_settings.moduleswitches,cs_support_c_operators)
  1926. else
  1927. include(init_settings.moduleswitches,cs_support_c_operators);
  1928. 'd' : //an alternative to -Mdelphi
  1929. SetCompileMode('DELPHI',true);
  1930. 'e' :
  1931. begin
  1932. SetErrorFlags(copy(more,j+1,length(more)));
  1933. break;
  1934. end;
  1935. 'f' :
  1936. begin
  1937. if not(cs_compilesystem in init_settings.moduleswitches) then
  1938. Message(option_features_only_for_system_unit);
  1939. inc(j);
  1940. if more[j]='-' then
  1941. begin
  1942. if length(more)>j then
  1943. IllegalPara(opt)
  1944. else
  1945. features:=[];
  1946. end
  1947. else
  1948. begin
  1949. if (HandleFeature(upper(copy(more,j,length(more)-j+1)))) then
  1950. j:=length(more)
  1951. else
  1952. IllegalPara(opt);
  1953. end;
  1954. end;
  1955. 'g' :
  1956. If UnsetBool(More, j, opt, false) then
  1957. exclude(init_settings.moduleswitches,cs_support_goto)
  1958. else
  1959. include(init_settings.moduleswitches,cs_support_goto);
  1960. 'h' :
  1961. If UnsetBool(More, j, opt, false) then
  1962. exclude(init_settings.localswitches,cs_refcountedstrings)
  1963. else
  1964. include(init_settings.localswitches,cs_refcountedstrings);
  1965. 'i' :
  1966. If UnsetBool(More, j, opt, false) then
  1967. exclude(init_settings.localswitches,cs_do_inline)
  1968. else
  1969. include(init_settings.localswitches,cs_do_inline);
  1970. 'j' :
  1971. If UnsetBool(More, j, opt, false) then
  1972. exclude(init_settings.localswitches,cs_typed_const_writable)
  1973. else
  1974. include(init_settings.localswitches,cs_typed_const_writable);
  1975. 'k' :
  1976. If UnsetBool(More, j, opt, false) then
  1977. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1978. else
  1979. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1980. 'm' :
  1981. If UnsetBool(More, j, opt, false) then
  1982. exclude(init_settings.moduleswitches,cs_support_macro)
  1983. else
  1984. include(init_settings.moduleswitches,cs_support_macro);
  1985. 'o' : //an alternative to -Mtp
  1986. SetCompileMode('TP',true);
  1987. 'r' :
  1988. If UnsetBool(More, j, opt, false) then
  1989. exclude(init_settings.globalswitches,cs_transparent_file_names)
  1990. else
  1991. include(init_settings.globalswitches,cs_transparent_file_names);
  1992. {$ifdef gpc_mode}
  1993. 'p' : //an alternative to -Mgpc
  1994. SetCompileMode('GPC',true);
  1995. {$endif}
  1996. 's' :
  1997. If UnsetBool(More, j, opt, false) then
  1998. exclude(init_settings.globalswitches,cs_constructor_name)
  1999. else
  2000. include(init_settings.globalswitches,cs_constructor_name);
  2001. 't' :
  2002. Message1(option_obsolete_switch,'-St');
  2003. 'v' :
  2004. If UnsetBool(More, j, opt, false) then
  2005. exclude(init_settings.globalswitches,cs_support_vectors)
  2006. else
  2007. include(init_settings.globalswitches,cs_support_vectors);
  2008. 'x' :
  2009. If UnsetBool(More, j, opt, false) then
  2010. SetCompileModeSwitch('EXCEPTIONS-',true)
  2011. else
  2012. SetCompileModeSwitch('EXCEPTIONS',true);
  2013. 'y' :
  2014. If UnsetBool(More, j, opt, false) then
  2015. exclude(init_settings.localswitches,cs_typed_addresses)
  2016. else
  2017. include(init_settings.localswitches,cs_typed_addresses);
  2018. '-' :
  2019. begin
  2020. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  2021. cs_support_vectors,cs_load_fpcylix_unit];
  2022. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  2023. cs_typed_addresses];
  2024. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  2025. cs_support_macro];
  2026. end;
  2027. else
  2028. IllegalPara(opt);
  2029. end;
  2030. inc(j);
  2031. end;
  2032. end;
  2033. end;
  2034. 'T' :
  2035. begin
  2036. more:=Upper(More);
  2037. if paratarget=system_none then
  2038. begin
  2039. { remove old target define }
  2040. TargetOptions(false);
  2041. { load new target }
  2042. paratarget:=find_system_by_string(More);
  2043. if paratarget<>system_none then
  2044. set_target(paratarget)
  2045. else
  2046. IllegalPara(opt);
  2047. { set new define }
  2048. TargetOptions(true);
  2049. end
  2050. else
  2051. if More<>upper(target_info.shortname) then
  2052. Message1(option_target_is_already_set,target_info.shortname);
  2053. end;
  2054. 'u' :
  2055. if is_identifier(more) then
  2056. undef_system_macro(more)
  2057. else
  2058. begin
  2059. if (more='') then
  2060. Message1(option_missing_arg,'-u')
  2061. else
  2062. Message1(option_malformed_para,opt);
  2063. StopOptions(1);
  2064. end;
  2065. 'U' :
  2066. begin
  2067. j:=1;
  2068. while j<=length(more) do
  2069. begin
  2070. case more[j] of
  2071. {$ifdef UNITALIASES}
  2072. 'a' :
  2073. begin
  2074. AddUnitAlias(Copy(More,j+1,255));
  2075. break;
  2076. end;
  2077. {$endif UNITALIASES}
  2078. 'n' :
  2079. exclude(init_settings.globalswitches,cs_check_unit_name);
  2080. 'p' :
  2081. begin
  2082. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  2083. break;
  2084. end;
  2085. 'r' :
  2086. begin
  2087. do_release:=true;
  2088. if (cs_checkpointer in init_settings.localswitches) then
  2089. begin
  2090. Message(option_gc_incompatible_with_release_flag);
  2091. exclude(init_settings.localswitches,cs_checkpointer);
  2092. end;
  2093. end;
  2094. 's' :
  2095. include(init_settings.moduleswitches,cs_compilesystem);
  2096. '-' :
  2097. begin
  2098. exclude(init_settings.moduleswitches,cs_compilesystem);
  2099. exclude(init_settings.globalswitches,cs_check_unit_name);
  2100. end;
  2101. else
  2102. IllegalPara(opt);
  2103. end;
  2104. inc(j);
  2105. end;
  2106. end;
  2107. 'v' :
  2108. begin
  2109. if not setverbosity(More) then
  2110. IllegalPara(opt);
  2111. end;
  2112. 'V' : ; { Ignore used by fpc }
  2113. 'W' :
  2114. begin
  2115. j:=1;
  2116. while j<=length(More) do
  2117. begin
  2118. case More[j] of
  2119. 'A':
  2120. begin
  2121. if target_info.system in systems_all_windows then
  2122. begin
  2123. if UnsetBool(More, j, opt, false) then
  2124. SetApptype(app_cui)
  2125. else
  2126. SetApptype(app_native);
  2127. end
  2128. else
  2129. IllegalPara(opt);
  2130. end;
  2131. 'b':
  2132. begin
  2133. if target_info.system in systems_darwin then
  2134. begin
  2135. if UnsetBool(More, j, opt, false) then
  2136. SetApptype(app_cui)
  2137. else
  2138. SetApptype(app_bundle)
  2139. end
  2140. else
  2141. IllegalPara(opt);
  2142. end;
  2143. 'B':
  2144. begin
  2145. if target_info.system in systems_all_windows+systems_symbian then
  2146. begin
  2147. { -WB200000 means set trefered base address
  2148. to $200000, but does not change relocsection boolean
  2149. this way we can create both relocatble and
  2150. non relocatable DLL at a specific base address PM }
  2151. if (length(More)>j) then
  2152. begin
  2153. val('$'+Copy(More,j+1,255),imagebase,code);
  2154. if code<>0 then
  2155. IllegalPara(opt);
  2156. ImageBaseSetExplicity:=true;
  2157. end
  2158. else
  2159. begin
  2160. RelocSection:=true;
  2161. RelocSectionSetExplicitly:=true;
  2162. end;
  2163. break;
  2164. end
  2165. else
  2166. IllegalPara(opt);
  2167. end;
  2168. 'C':
  2169. begin
  2170. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2171. begin
  2172. if UnsetBool(More, j, opt, false) then
  2173. SetApptype(app_gui)
  2174. else
  2175. SetApptype(app_cui);
  2176. end
  2177. else
  2178. IllegalPara(opt);
  2179. end;
  2180. 'D':
  2181. begin
  2182. if target_info.system in systems_all_windows then
  2183. begin
  2184. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2185. UseDeffileForExportsSetExplicitly:=true;
  2186. end
  2187. else
  2188. IllegalPara(opt);
  2189. end;
  2190. 'e':
  2191. begin
  2192. if (target_info.system in systems_darwin) then
  2193. begin
  2194. set_target_res(res_ext);
  2195. target_info.resobjext:='.fpcres';
  2196. end
  2197. else
  2198. IllegalPara(opt);
  2199. end;
  2200. 'F':
  2201. begin
  2202. if target_info.system in systems_os2 then
  2203. begin
  2204. if UnsetBool(More, j, opt, false) then
  2205. SetApptype(app_cui)
  2206. else
  2207. SetApptype(app_fs);
  2208. end
  2209. else
  2210. IllegalPara(opt);
  2211. end;
  2212. 'G':
  2213. begin
  2214. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2215. begin
  2216. if UnsetBool(More, j, opt, false) then
  2217. SetApptype(app_cui)
  2218. else
  2219. SetApptype(app_gui);
  2220. end
  2221. else
  2222. IllegalPara(opt);
  2223. end;
  2224. {$if defined(i8086)}
  2225. 'h':
  2226. begin
  2227. if UnsetBool(More, j, opt, false) then
  2228. exclude(init_settings.moduleswitches,cs_huge_code)
  2229. else
  2230. include(init_settings.moduleswitches,cs_huge_code);
  2231. end;
  2232. {$endif defined(i8086)}
  2233. 'I':
  2234. begin
  2235. if target_info.system in systems_all_windows then
  2236. begin
  2237. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2238. GenerateImportSectionSetExplicitly:=true;
  2239. end
  2240. else
  2241. IllegalPara(opt);
  2242. end;
  2243. 'i':
  2244. begin
  2245. if (target_info.system in systems_darwin) then
  2246. begin
  2247. set_target_res(res_macho);
  2248. target_info.resobjext:=
  2249. targetinfos[target_info.system]^.resobjext;
  2250. end
  2251. else
  2252. IllegalPara(opt);
  2253. end;
  2254. 'm':
  2255. begin
  2256. {$if defined(i8086)}
  2257. if (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) then
  2258. begin
  2259. case Upper(Copy(More,j+1,255)) of
  2260. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2261. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2262. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2263. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2264. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2265. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2266. else
  2267. IllegalPara(opt);
  2268. end;
  2269. break;
  2270. end
  2271. else
  2272. {$endif defined(i8086)}
  2273. IllegalPara(opt);
  2274. end;
  2275. 'M':
  2276. begin
  2277. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim])) and
  2278. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2279. begin
  2280. break;
  2281. end
  2282. else
  2283. IllegalPara(opt);
  2284. end;
  2285. 'N':
  2286. begin
  2287. if target_info.system in systems_all_windows then
  2288. begin
  2289. RelocSection:=UnsetBool(More,j,opt,false);
  2290. RelocSectionSetExplicitly:=true;
  2291. end
  2292. else
  2293. IllegalPara(opt);
  2294. end;
  2295. 'p':
  2296. begin
  2297. {$push}
  2298. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  2299. if (target_info.system in systems_embedded) and
  2300. ControllerSupport then
  2301. begin
  2302. s:=upper(copy(more,j+1,length(more)-j));
  2303. if not(SetControllerType(s,init_settings.controllertype)) then
  2304. IllegalPara(opt)
  2305. else
  2306. begin
  2307. if init_settings.cputype<>embedded_controllers[init_settings.controllertype].cputype then
  2308. begin
  2309. Message(scan_n_changecputype);
  2310. init_settings.cputype:=embedded_controllers[init_settings.controllertype].cputype;
  2311. end;
  2312. end;
  2313. break;
  2314. end
  2315. else
  2316. IllegalPara(opt);
  2317. {$pop}
  2318. end;
  2319. 'P':
  2320. begin
  2321. if (target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim]) and
  2322. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2323. begin
  2324. break;
  2325. end
  2326. else
  2327. IllegalPara(opt);
  2328. end;
  2329. 'R':
  2330. begin
  2331. if target_info.system in systems_all_windows then
  2332. begin
  2333. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2334. RelocSection:=not UnsetBool(More,j,opt,false);
  2335. RelocSectionSetExplicitly:=true;
  2336. end
  2337. else
  2338. IllegalPara(opt);
  2339. end;
  2340. 't':
  2341. begin
  2342. {$if defined(i8086)}
  2343. if (target_info.system in [system_i8086_msdos,system_i8086_embedded]) then
  2344. begin
  2345. case Upper(Copy(More,j+1,255)) of
  2346. 'EXE': SetAppType(app_cui);
  2347. 'COM': SetAppType(app_com);
  2348. else
  2349. IllegalPara(opt);
  2350. end;
  2351. break;
  2352. end
  2353. else
  2354. {$endif defined(i8086)}
  2355. IllegalPara(opt);
  2356. end;
  2357. 'T':
  2358. begin
  2359. if target_info.system in systems_macos then
  2360. begin
  2361. if UnsetBool(More, j, opt, false) then
  2362. SetApptype(app_cui)
  2363. else
  2364. SetApptype(app_tool);
  2365. end
  2366. else
  2367. IllegalPara(opt);
  2368. end;
  2369. 'X':
  2370. begin
  2371. if (target_info.system in systems_linux) then
  2372. begin
  2373. if UnsetBool(More, j, opt, false) then
  2374. exclude(init_settings.moduleswitches,cs_executable_stack)
  2375. else
  2376. include(init_settings.moduleswitches,cs_executable_stack)
  2377. end
  2378. else
  2379. IllegalPara(opt);
  2380. end;
  2381. else
  2382. IllegalPara(opt);
  2383. end;
  2384. inc(j);
  2385. end;
  2386. end;
  2387. 'X' :
  2388. begin
  2389. j:=1;
  2390. while j<=length(more) do
  2391. begin
  2392. case More[j] of
  2393. '9' :
  2394. begin
  2395. if target_info.system in systems_linux then
  2396. begin
  2397. if UnsetBool(More, j, opt, false) then
  2398. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2399. else
  2400. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2401. end
  2402. else
  2403. IllegalPara(opt);
  2404. end;
  2405. 'c' : Cshared:=TRUE;
  2406. 'd' : Dontlinkstdlibpath:=TRUE;
  2407. 'e' :
  2408. begin
  2409. If UnsetBool(More, j, opt, false) then
  2410. exclude(init_settings.globalswitches,cs_link_extern)
  2411. else
  2412. include(init_settings.globalswitches,cs_link_extern);
  2413. end;
  2414. 'f' :
  2415. include(init_settings.globalswitches,cs_link_pthread);
  2416. 'g' :
  2417. begin
  2418. If UnsetBool(More, j, opt, false) then
  2419. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2420. else
  2421. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2422. end;
  2423. 'i' :
  2424. begin
  2425. If UnsetBool(More, j, opt, false) then
  2426. include(init_settings.globalswitches,cs_link_extern)
  2427. else
  2428. exclude(init_settings.globalswitches,cs_link_extern);
  2429. end;
  2430. 'n' :
  2431. begin
  2432. If UnsetBool(More, j, opt, false) then
  2433. exclude(init_settings.globalswitches,cs_link_native)
  2434. else
  2435. include(init_settings.globalswitches,cs_link_native);
  2436. end;
  2437. 'm' :
  2438. begin
  2439. If UnsetBool(More, j, opt, false) then
  2440. exclude(init_settings.globalswitches,cs_link_map)
  2441. else
  2442. include(init_settings.globalswitches,cs_link_map);
  2443. end;
  2444. 'p' : ; { Ignore used by fpc.pp }
  2445. 'r' :
  2446. begin
  2447. if (target_info.system in suppported_targets_x_smallr) then
  2448. begin
  2449. rlinkpath:=Copy(more,2,length(More)-1);
  2450. DefaultReplacements(rlinkpath);
  2451. end
  2452. else
  2453. IgnoredPara('-Xr');
  2454. more:='';
  2455. end;
  2456. 'R' :
  2457. begin
  2458. sysrootpath:=copy(more,2,length(more)-1);
  2459. defaultreplacements(sysrootpath);
  2460. more:='';
  2461. end;
  2462. 's' :
  2463. begin
  2464. If UnsetBool(More, j, opt, false) then
  2465. exclude(init_settings.globalswitches,cs_link_strip)
  2466. else
  2467. include(init_settings.globalswitches,cs_link_strip);
  2468. end;
  2469. 't' :
  2470. include(init_settings.globalswitches,cs_link_staticflag);
  2471. 'v' :
  2472. begin
  2473. If UnsetBool(More, j, opt, false) then
  2474. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2475. else
  2476. include(init_settings.globalswitches,cs_link_opt_vtable);
  2477. end;
  2478. 'D' :
  2479. begin
  2480. def_system_macro('FPC_LINK_DYNAMIC');
  2481. undef_system_macro('FPC_LINK_SMART');
  2482. undef_system_macro('FPC_LINK_STATIC');
  2483. exclude(init_settings.globalswitches,cs_link_static);
  2484. exclude(init_settings.globalswitches,cs_link_smart);
  2485. include(init_settings.globalswitches,cs_link_shared);
  2486. LinkTypeSetExplicitly:=true;
  2487. end;
  2488. 'M' :
  2489. begin
  2490. mainaliasname:=Copy(more,2,length(More)-1);
  2491. More:='';
  2492. end;
  2493. 'P' :
  2494. begin
  2495. utilsprefix:=Copy(more,2,length(More)-1);
  2496. DefaultReplacements(utilsprefix);
  2497. More:='';
  2498. end;
  2499. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2500. // these are not aggregable.
  2501. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2502. IllegalPara(opt)
  2503. else
  2504. begin
  2505. case more[j+1] of
  2506. 'A' : begin
  2507. s:=Copy(more,3,length(More)-2);
  2508. if not LinkLibraryAliases.AddDep(s) Then
  2509. IllegalPara(opt);
  2510. end;
  2511. 'O' : begin
  2512. s:=Copy(more,3,length(More)-2);
  2513. if not LinkLibraryOrder.AddWeight(s) Then
  2514. IllegalPara(opt);
  2515. end;
  2516. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2517. else
  2518. IllegalPara(opt);
  2519. end; {case}
  2520. j:=length(more);
  2521. end; {else begin}
  2522. end;
  2523. 'S' :
  2524. begin
  2525. ForceStaticLinking;
  2526. end;
  2527. 'V' :
  2528. begin
  2529. if UnsetBool(More, j, opt, false) then
  2530. exclude(init_settings.globalswitches,cs_link_vlink)
  2531. else
  2532. begin
  2533. include(init_settings.globalswitches,cs_link_vlink);
  2534. include(init_settings.globalswitches,cs_link_extern);
  2535. end;
  2536. LinkerSetExplicitly:=true;
  2537. end;
  2538. 'X' :
  2539. begin
  2540. def_system_macro('FPC_LINK_SMART');
  2541. undef_system_macro('FPC_LINK_STATIC');
  2542. undef_system_macro('FPC_LINK_DYNAMIC');
  2543. exclude(init_settings.globalswitches,cs_link_static);
  2544. include(init_settings.globalswitches,cs_link_smart);
  2545. exclude(init_settings.globalswitches,cs_link_shared);
  2546. LinkTypeSetExplicitly:=true;
  2547. end;
  2548. '-' :
  2549. begin
  2550. exclude(init_settings.globalswitches,cs_link_staticflag);
  2551. exclude(init_settings.globalswitches,cs_link_strip);
  2552. exclude(init_settings.globalswitches,cs_link_map);
  2553. set_default_link_type;
  2554. end;
  2555. else
  2556. IllegalPara(opt);
  2557. end;
  2558. inc(j);
  2559. end;
  2560. end;
  2561. else
  2562. IllegalPara(opt);
  2563. end;
  2564. end;
  2565. '@' :
  2566. begin
  2567. Message(option_no_nested_response_file);
  2568. StopOptions(1);
  2569. end;
  2570. else
  2571. begin
  2572. if (length(param_file)<>0) then
  2573. Message2(option_only_one_source_support,param_file,opt);
  2574. param_file:=opt;
  2575. Message1(option_found_file,opt);
  2576. end;
  2577. end;
  2578. end;
  2579. procedure Toption.Interpret_file(const filename : TPathStr);
  2580. procedure RemoveSep(var fn:TPathStr);
  2581. var
  2582. i : longint;
  2583. begin
  2584. i:=0;
  2585. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2586. inc(i);
  2587. Delete(fn,1,i);
  2588. i:=length(fn);
  2589. while (i>0) and (fn[i] in [',',' ',#9]) do
  2590. dec(i);
  2591. fn:=copy(fn,1,i);
  2592. end;
  2593. function GetName(var fn:TPathStr):TPathStr;
  2594. var
  2595. i : longint;
  2596. begin
  2597. i:=0;
  2598. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2599. inc(i);
  2600. GetName:=Copy(fn,1,i);
  2601. Delete(fn,1,i);
  2602. end;
  2603. const
  2604. maxlevel = 15;
  2605. var
  2606. f : text;
  2607. s, tmp,
  2608. opts : TCmdStr;
  2609. skip : array[0..maxlevel] of boolean;
  2610. line,
  2611. level : longint;
  2612. option_read : boolean;
  2613. oldfilemode : byte;
  2614. ConfigFile: TPathStr;
  2615. begin
  2616. { avoid infinite loop }
  2617. Inc(FileLevel);
  2618. Option_read:=false;
  2619. If FileLevel>MaxLevel then
  2620. Message(option_too_many_cfg_files);
  2621. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2622. ConfigFile := ExpandFileName(filename);
  2623. { Maybe It's Directory ?} //Jaro Change:
  2624. if PathExists(ConfigFile,false) then
  2625. begin
  2626. Message1(option_config_is_dir,filename);
  2627. exit;
  2628. end;
  2629. { open file }
  2630. Message1(option_using_file,filename);
  2631. oldfilemode:=filemode;
  2632. filemode:=0;
  2633. assign(f,ConfigFile);
  2634. {$push}{$I-}
  2635. reset(f);
  2636. {$pop}
  2637. filemode:=oldfilemode;
  2638. if ioresult<>0 then
  2639. begin
  2640. Message1(option_unable_open_file,filename);
  2641. exit;
  2642. end;
  2643. Message1(option_start_reading_configfile,filename);
  2644. fillchar(skip,sizeof(skip),0);
  2645. level:=0;
  2646. line:=0;
  2647. while not eof(f) do
  2648. begin
  2649. readln(f,opts);
  2650. inc(line);
  2651. RemoveSep(opts);
  2652. if (opts<>'') and (opts[1]<>';') then
  2653. begin
  2654. if opts[1]='#' then
  2655. begin
  2656. Message1(option_interpreting_file_option,opts);
  2657. Delete(opts,1,1);
  2658. s:=upper(GetName(opts));
  2659. if (s='SECTION') then
  2660. begin
  2661. RemoveSep(opts);
  2662. s:=upper(GetName(opts));
  2663. if level=0 then
  2664. skip[level]:=not defined_macro(s) or (s='COMMON');
  2665. end
  2666. else
  2667. if (s='IFDEF') then
  2668. begin
  2669. RemoveSep(opts);
  2670. if Level>=maxlevel then
  2671. begin
  2672. Message2(option_too_many_ifdef,filename,tostr(line));
  2673. stopOptions(1);
  2674. end;
  2675. inc(Level);
  2676. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2677. end
  2678. else
  2679. if (s='IFNDEF') then
  2680. begin
  2681. RemoveSep(opts);
  2682. if Level>=maxlevel then
  2683. begin
  2684. Message2(option_too_many_ifdef,filename,tostr(line));
  2685. stopOptions(1);
  2686. end;
  2687. inc(Level);
  2688. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2689. end
  2690. else
  2691. if (s='ELSE') then
  2692. begin
  2693. if Level=0 then
  2694. begin
  2695. Message2(option_else_without_if,filename,tostr(line));
  2696. stopOptions(1);
  2697. end
  2698. else
  2699. skip[level]:=skip[level-1] or (not skip[level])
  2700. end
  2701. else
  2702. if (s='ENDIF') then
  2703. begin
  2704. skip[level]:=false;
  2705. if Level=0 then
  2706. begin
  2707. Message2(option_too_many_endif,filename,tostr(line));
  2708. stopOptions(1);
  2709. end;
  2710. dec(level);
  2711. end
  2712. else
  2713. if (not skip[level]) then
  2714. begin
  2715. if (s='DEFINE') then
  2716. begin
  2717. RemoveSep(opts);
  2718. tmp:= GetName(opts);
  2719. if tmp <> '' then
  2720. def_system_macro(tmp);
  2721. Option_read:=true;
  2722. end
  2723. else
  2724. if (s='UNDEF') then
  2725. begin
  2726. RemoveSep(opts);
  2727. tmp:= GetName(opts);
  2728. if tmp <> '' then
  2729. undef_system_macro(tmp);
  2730. Option_read:=true;
  2731. end
  2732. else
  2733. if (s='WRITE') then
  2734. begin
  2735. Delete(opts,1,1);
  2736. DefaultReplacements(opts);
  2737. WriteLn(opts);
  2738. Option_read:=true;
  2739. end
  2740. else
  2741. if (s='INCLUDE') then
  2742. begin
  2743. Delete(opts,1,1);
  2744. DefaultReplacements(opts);
  2745. Interpret_file(opts);
  2746. Option_read:=true;
  2747. end
  2748. else
  2749. if (s='CFGDIR') then
  2750. begin
  2751. Delete(opts,1,1);
  2752. DefaultReplacements(opts);
  2753. ParaIncludeCfgPath.AddPath(opts,false);
  2754. Option_read:=true;
  2755. end;
  2756. end;
  2757. end
  2758. else
  2759. begin
  2760. if (opts[1]='-') or (opts[1]='@') then
  2761. begin
  2762. if (not skip[level]) then
  2763. interpret_option(opts,false);
  2764. Option_read:=true;
  2765. end
  2766. else
  2767. Message1(option_illegal_para,opts);
  2768. end;
  2769. end;
  2770. end;
  2771. if Level>0 then
  2772. Message(option_too_less_endif);
  2773. if Not Option_read then
  2774. Message1(option_no_option_found,filename)
  2775. else
  2776. Message1(option_end_reading_configfile,filename);
  2777. Close(f);
  2778. Dec(FileLevel);
  2779. end;
  2780. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  2781. var
  2782. argstart,
  2783. env,
  2784. pc : pchar;
  2785. arglen : longint;
  2786. quote : set of char;
  2787. hs : TCmdStr;
  2788. begin
  2789. Message1(option_using_env,envname);
  2790. env:=GetEnvPChar(envname);
  2791. pc:=env;
  2792. hs:='';
  2793. if assigned(pc) then
  2794. begin
  2795. repeat
  2796. { skip leading spaces }
  2797. while pc^ in [' ',#9,#13] do
  2798. inc(pc);
  2799. case pc^ of
  2800. #0 :
  2801. break;
  2802. '"' :
  2803. begin
  2804. quote:=['"'];
  2805. inc(pc);
  2806. end;
  2807. '''' :
  2808. begin
  2809. quote:=[''''];
  2810. inc(pc);
  2811. end;
  2812. else
  2813. quote:=[' ',#9,#13];
  2814. end;
  2815. { scan until the end of the argument }
  2816. argstart:=pc;
  2817. while (pc^<>#0) and not(pc^ in quote) do
  2818. inc(pc);
  2819. { create argument }
  2820. arglen:=pc-argstart;
  2821. { TODO: FIXME: silent truncation of environment parameters }
  2822. if (arglen > 255) then
  2823. arglen := 255;
  2824. setlength(hs,arglen);
  2825. move(argstart^,hs[1],arglen);
  2826. interpret_option(hs,true);
  2827. { skip quote }
  2828. if pc^ in quote then
  2829. inc(pc);
  2830. until false;
  2831. end
  2832. else
  2833. Message1(option_no_option_found,'(env) '+envname);
  2834. FreeEnvPChar(env);
  2835. end;
  2836. procedure toption.read_parameters;
  2837. var
  2838. opts : TCmdStr;
  2839. paramindex : longint;
  2840. begin
  2841. paramindex:=0;
  2842. while paramindex<paramcount do
  2843. begin
  2844. inc(paramindex);
  2845. opts:=objpas.paramstr(paramindex);
  2846. if length(opts)>0 then
  2847. case opts[1] of
  2848. '@' :
  2849. if not firstpass then
  2850. begin
  2851. Delete(opts,1,1);
  2852. Message1(option_reading_further_from,opts);
  2853. interpret_file(opts);
  2854. end;
  2855. '!' :
  2856. if not firstpass then
  2857. begin
  2858. Delete(opts,1,1);
  2859. Message1(option_reading_further_from,'(env) '+opts);
  2860. interpret_envvar(opts);
  2861. end;
  2862. else
  2863. interpret_option(opts,true);
  2864. end;
  2865. end;
  2866. end;
  2867. procedure toption.parsecmd(cmd:TCmdStr);
  2868. var
  2869. i,ps : longint;
  2870. opts : TCmdStr;
  2871. begin
  2872. while (cmd<>'') do
  2873. begin
  2874. while cmd[1]=' ' do
  2875. delete(cmd,1,1);
  2876. i:=pos(' ',cmd);
  2877. if i=0 then
  2878. i:=2147483647;
  2879. opts:=Copy(cmd,1,i-1);
  2880. Delete(cmd,1,i);
  2881. case opts[1] of
  2882. '@' :
  2883. if not firstpass then
  2884. begin
  2885. Delete(opts,1,1);
  2886. Message1(option_reading_further_from,opts);
  2887. interpret_file(opts);
  2888. end;
  2889. '!' :
  2890. if not firstpass then
  2891. begin
  2892. Delete(opts,1,1);
  2893. Message1(option_reading_further_from,'(env) '+opts);
  2894. interpret_envvar(opts);
  2895. end;
  2896. '"' :
  2897. begin
  2898. Delete(opts,1,1);
  2899. ps:=pos('"',cmd);
  2900. if (i<>256) and (ps>0) then
  2901. begin
  2902. opts:=opts + ' '+ copy(cmd,1,ps-1);
  2903. cmd:=copy(cmd,ps+1,255);
  2904. end;
  2905. interpret_option(opts,true);
  2906. end;
  2907. else
  2908. interpret_option(opts,true);
  2909. end;
  2910. end;
  2911. end;
  2912. procedure toption.writequickinfo;
  2913. var
  2914. s : string;
  2915. i : longint;
  2916. procedure addinfo(const hs:string);
  2917. begin
  2918. if s<>'' then
  2919. s:=s+' '+hs
  2920. else
  2921. s:=hs;
  2922. end;
  2923. begin
  2924. s:='';
  2925. i:=0;
  2926. while (i<length(quickinfo)) do
  2927. begin
  2928. inc(i);
  2929. case quickinfo[i] of
  2930. 'S' :
  2931. begin
  2932. inc(i);
  2933. case quickinfo[i] of
  2934. 'O' :
  2935. addinfo(lower(source_info.shortname));
  2936. 'P' :
  2937. addinfo(source_cpu_string);
  2938. else
  2939. IllegalPara('-i'+QuickInfo);
  2940. end;
  2941. end;
  2942. 'T' :
  2943. begin
  2944. inc(i);
  2945. case quickinfo[i] of
  2946. 'O' :
  2947. addinfo(lower(target_info.shortname));
  2948. 'P' :
  2949. AddInfo(target_cpu_string);
  2950. else
  2951. IllegalPara('-i'+QuickInfo);
  2952. end;
  2953. end;
  2954. 'V' :
  2955. AddInfo(version_string);
  2956. 'W' :
  2957. AddInfo(full_version_string);
  2958. 'D' :
  2959. AddInfo(date_string);
  2960. '_' :
  2961. ;
  2962. else
  2963. IllegalPara('-i'+QuickInfo);
  2964. end;
  2965. end;
  2966. if s<>'' then
  2967. begin
  2968. writeln(s);
  2969. stopoptions(0);
  2970. end;
  2971. end;
  2972. procedure TOption.TargetOptions(def:boolean);
  2973. var
  2974. s : string;
  2975. i : integer;
  2976. target_unsup_features : tfeatures;
  2977. begin
  2978. if def then
  2979. def_system_macro(target_info.shortname)
  2980. else
  2981. undef_system_macro(target_info.shortname);
  2982. s:=target_info.extradefines;
  2983. while (s<>'') do
  2984. begin
  2985. i:=pos(';',s);
  2986. if i=0 then
  2987. i:=length(s)+1;
  2988. if def then
  2989. def_system_macro(Copy(s,1,i-1))
  2990. else
  2991. undef_system_macro(Copy(s,1,i-1));
  2992. delete(s,1,i);
  2993. end;
  2994. if (tf_winlikewidestring in target_info.flags) then
  2995. if def then
  2996. def_system_macro('FPC_WINLIKEWIDESTRING')
  2997. else
  2998. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2999. if (tf_requires_proper_alignment in target_info.flags) then
  3000. if def then
  3001. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  3002. else
  3003. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3004. if source_info.system<>target_info.system then
  3005. if def then
  3006. def_system_macro('FPC_CROSSCOMPILING')
  3007. else
  3008. undef_system_macro('FPC_CROSSCOMPILING');
  3009. if source_info.cpu<>target_info.cpu then
  3010. if def then
  3011. def_system_macro('FPC_CPUCROSSCOMPILING')
  3012. else
  3013. def_system_macro('FPC_CPUCROSSCOMPILING');
  3014. if (tf_no_generic_stackcheck in target_info.flags) then
  3015. if def then
  3016. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  3017. else
  3018. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  3019. if (tf_section_threadvars in target_info.flags) then
  3020. if def then
  3021. def_system_macro('FPC_SECTION_THREADVARS')
  3022. else
  3023. undef_system_macro('FPC_SECTION_THREADVARS');
  3024. { Code generation flags }
  3025. if (tf_pic_default in target_info.flags) then
  3026. if def then
  3027. include(init_settings.moduleswitches,cs_create_pic)
  3028. else
  3029. exclude(init_settings.moduleswitches,cs_create_pic);
  3030. { Resources support }
  3031. if (tf_has_winlike_resources in target_info.flags) then
  3032. if def then
  3033. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  3034. else
  3035. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  3036. { Features }
  3037. case target_info.system of
  3038. system_arm_gba:
  3039. target_unsup_features:=[f_dynlibs];
  3040. system_arm_nds:
  3041. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  3042. system_i386_nativent:
  3043. // until these features are implemented, they are disabled in the compiler
  3044. target_unsup_features:=[f_stackcheck];
  3045. system_i8086_msdos:
  3046. target_unsup_features:=[f_threading,f_dynlibs];
  3047. system_i8086_win16:
  3048. target_unsup_features:=[f_threading];
  3049. system_jvm_java32,
  3050. system_jvm_android32:
  3051. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  3052. f_variants,f_objects,f_commandargs,
  3053. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  3054. system_arm_palmos,
  3055. system_m68k_palmos:
  3056. target_unsup_features:=[f_threading];
  3057. system_m68k_atari:
  3058. target_unsup_features:=[f_threading];
  3059. { classic amiga has dynamic libraries, but they cannot be integrated in the
  3060. normal dynlibs infrastructure due to architectural differences, so therefore
  3061. lets disable the feature. }
  3062. system_m68k_amiga:
  3063. target_unsup_features:=[f_dynlibs];
  3064. else
  3065. target_unsup_features:=[];
  3066. end;
  3067. if def then
  3068. features:=features-target_unsup_features
  3069. else
  3070. features:=features+target_unsup_features;
  3071. {$if defined(atari) or defined(hasamiga)}
  3072. { enable vlink as default linker on Atari, Amiga, and MorphOS, but not for cross compilers (for now) }
  3073. if (target_info.system in [system_m68k_amiga,system_m68k_atari,
  3074. system_powerpc_amiga,system_powerpc_morphos]) and
  3075. not LinkerSetExplicitly then
  3076. include(init_settings.globalswitches,cs_link_vlink);
  3077. {$endif}
  3078. end;
  3079. procedure TOption.checkoptionscompatibility;
  3080. begin
  3081. {$ifdef i8086}
  3082. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  3083. begin
  3084. Message(option_com_files_require_tiny_model);
  3085. StopOptions(1);
  3086. end;
  3087. {$endif i8086}
  3088. {$ifndef i8086_link_intern_debuginfo}
  3089. if (cs_debuginfo in init_settings.moduleswitches) and
  3090. (target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) and
  3091. not (cs_link_extern in init_settings.globalswitches) then
  3092. begin
  3093. Message(option_debug_info_requires_external_linker);
  3094. include(init_settings.globalswitches,cs_link_extern);
  3095. end;
  3096. {$endif i8086_link_intern_debuginfo}
  3097. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  3098. not(target_info.system in (systems_darwin+[system_i8086_msdos,system_i8086_embedded])) then
  3099. begin
  3100. { smartlink creation does not yet work with DWARF
  3101. debug info on most targets, but it works in internal assembler }
  3102. if (cs_create_smart in init_settings.moduleswitches) and
  3103. not (af_outputbinary in target_asm.flags) then
  3104. begin
  3105. Message(option_dwarf_smartlink_creation);
  3106. exclude(init_settings.moduleswitches,cs_create_smart);
  3107. end;
  3108. { smart linking does not yet work with DWARF debug info on most targets }
  3109. if (cs_link_smart in init_settings.globalswitches) then
  3110. begin
  3111. Message(option_dwarf_smart_linking);
  3112. ForceStaticLinking;
  3113. end;
  3114. end;
  3115. { external debug info is only supported for DWARF on darwin }
  3116. if (target_info.system in systems_darwin) and
  3117. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  3118. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  3119. begin
  3120. Message(option_debug_external_unsupported);
  3121. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  3122. end;
  3123. { Also create a smartlinked version, on an assembler that
  3124. does not support smartlink sections like nasm?
  3125. This is not compatible with using internal linker. }
  3126. if ((cs_link_smart in init_settings.globalswitches) or
  3127. (cs_create_smart in init_settings.moduleswitches)) and
  3128. (af_needar in target_asm.flags) and
  3129. not (af_smartlink_sections in target_asm.flags) and
  3130. not (cs_link_extern in init_settings.globalswitches) and
  3131. (target_info.link<>ld_none) and
  3132. not (cs_link_nolink in init_settings.globalswitches) then
  3133. begin
  3134. Message(option_smart_link_requires_external_linker);
  3135. include(init_settings.globalswitches,cs_link_extern);
  3136. end;
  3137. end;
  3138. constructor TOption.create;
  3139. begin
  3140. LogoWritten:=false;
  3141. NoPressEnter:=false;
  3142. FirstPass:=false;
  3143. ABISetExplicitly:=false;
  3144. FPUSetExplicitly:=false;
  3145. CPUSetExplicitly:=false;
  3146. OptCPUSetExplicitly:=false;
  3147. FileLevel:=0;
  3148. Quickinfo:='';
  3149. ParaIncludeCfgPath:=TSearchPathList.Create;
  3150. ParaIncludePath:=TSearchPathList.Create;
  3151. ParaObjectPath:=TSearchPathList.Create;
  3152. ParaUnitPath:=TSearchPathList.Create;
  3153. ParaLibraryPath:=TSearchPathList.Create;
  3154. ParaFrameworkPath:=TSearchPathList.Create;
  3155. parapackagepath:=TSearchPathList.Create;
  3156. parapackages:=TFPHashObjectList.Create;
  3157. paranamespaces:=TCmdStrList.Create;
  3158. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  3159. MacVersionSet:=false;
  3160. paratarget:=system_none;
  3161. paratargetasm:=as_none;
  3162. paratargetdbg:=dbg_none;
  3163. LinkTypeSetExplicitly:=false;
  3164. LinkerSetExplicitly:=false;
  3165. end;
  3166. destructor TOption.destroy;
  3167. begin
  3168. ParaIncludeCfgPath.Free;
  3169. ParaIncludePath.Free;
  3170. ParaObjectPath.Free;
  3171. ParaUnitPath.Free;
  3172. ParaLibraryPath.Free;
  3173. ParaFrameworkPath.Free;
  3174. parapackagepath.Free;
  3175. ParaPackages.Free;
  3176. paranamespaces.free;
  3177. end;
  3178. {****************************************************************************
  3179. Callable Routines
  3180. ****************************************************************************}
  3181. function check_configfile(fn:string; var foundfn:string):boolean;
  3182. function CfgFileExists(const fn:string):boolean;
  3183. begin
  3184. Comment(V_Tried,'Configfile search: '+fn);
  3185. CfgFileExists:=FileExists(fn);
  3186. end;
  3187. var
  3188. {$ifdef Unix}
  3189. hs,
  3190. {$endif Unix}
  3191. configpath : string;
  3192. begin
  3193. foundfn:=fn;
  3194. check_configfile:=true;
  3195. { retrieve configpath }
  3196. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3197. {$ifdef Unix}
  3198. if configpath='' then
  3199. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3200. {$endif}
  3201. {
  3202. Order to read configuration file :
  3203. try reading fpc.cfg in :
  3204. 1 - current dir
  3205. 2 - configpath
  3206. 3 - compiler path
  3207. }
  3208. if not FileExists(fn) then
  3209. begin
  3210. {$ifdef Unix}
  3211. hs:=GetEnvironmentVariable('HOME');
  3212. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3213. foundfn:=FixPath(hs,false)+'.'+fn
  3214. else
  3215. {$endif}
  3216. if CfgFileExists(configpath+fn) then
  3217. foundfn:=configpath+fn
  3218. else
  3219. {$ifdef WINDOWS}
  3220. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3221. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3222. else
  3223. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3224. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3225. else
  3226. {$endif WINDOWS}
  3227. {$ifndef Unix}
  3228. if CfgFileExists(exepath+fn) then
  3229. foundfn:=exepath+fn
  3230. else
  3231. {$else}
  3232. if CfgFileExists('/etc/'+fn) then
  3233. foundfn:='/etc/'+fn
  3234. else
  3235. {$endif}
  3236. check_configfile:=false;
  3237. end;
  3238. end;
  3239. procedure read_arguments(cmd:TCmdStr);
  3240. procedure def_cpu_macros;
  3241. var
  3242. abi : tabi;
  3243. fputype : tfputype;
  3244. cputype : tcputype;
  3245. controller: tcontrollertype;
  3246. s: string;
  3247. begin
  3248. for cputype:=low(tcputype) to high(tcputype) do
  3249. undef_system_macro('CPU'+Cputypestr[cputype]);
  3250. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3251. for fputype:=low(tfputype) to high(tfputype) do
  3252. undef_system_macro('FPU'+fputypestr[fputype]);
  3253. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3254. {$PUSH}
  3255. {$WARN 6018 OFF} { Unreachable code due to compile time evaluation }
  3256. if ControllerSupport then
  3257. begin
  3258. for controller:=low(tcontrollertype) to high(tcontrollertype) do
  3259. begin
  3260. s:=embedded_controllers[controller].controllertypestr;
  3261. if s<>'' then
  3262. undef_system_macro('FPC_MCU_'+s);
  3263. end;
  3264. s:=embedded_controllers[init_settings.controllertype].controllertypestr;
  3265. if s<>'' then
  3266. def_system_macro('FPC_MCU_'+s);
  3267. end;
  3268. {$POP}
  3269. { define abi }
  3270. for abi:=low(tabi) to high(tabi) do
  3271. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3272. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3273. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3274. systems since most code needs to behave the same on both}
  3275. if target_info.abi = abi_eabihf then
  3276. def_system_macro('FPC_ABI_EABI');
  3277. { using a case is pretty useless here (FK) }
  3278. { some stuff for TP compatibility }
  3279. {$ifdef i386}
  3280. def_system_macro('CPU86');
  3281. def_system_macro('CPU87');
  3282. def_system_macro('CPU386');
  3283. {$endif}
  3284. { new processor stuff }
  3285. {$ifdef i386}
  3286. def_system_macro('CPUI386');
  3287. def_system_macro('CPU32');
  3288. def_system_macro('CPUX86');
  3289. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3290. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3291. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3292. {$endif}
  3293. {$ifdef m68k}
  3294. def_system_macro('CPU68');
  3295. def_system_macro('CPU68K');
  3296. def_system_macro('CPUM68K');
  3297. def_system_macro('CPU32');
  3298. def_system_macro('FPC_CURRENCY_IS_INT64');
  3299. def_system_macro('FPC_COMP_IS_INT64');
  3300. {$endif}
  3301. {$ifdef powerpc}
  3302. def_system_macro('CPUPOWERPC');
  3303. def_system_macro('CPUPOWERPC32');
  3304. def_system_macro('CPU32');
  3305. def_system_macro('FPC_CURRENCY_IS_INT64');
  3306. def_system_macro('FPC_COMP_IS_INT64');
  3307. {$endif}
  3308. {$ifdef POWERPC64}
  3309. def_system_macro('CPUPOWERPC');
  3310. def_system_macro('CPUPOWERPC64');
  3311. def_system_macro('CPU64');
  3312. def_system_macro('FPC_CURRENCY_IS_INT64');
  3313. def_system_macro('FPC_COMP_IS_INT64');
  3314. {$endif}
  3315. {$ifdef x86_64}
  3316. def_system_macro('CPUX86_64');
  3317. def_system_macro('CPUAMD64');
  3318. def_system_macro('CPU64');
  3319. def_system_macro('CPUX64');
  3320. { not supported for now, afaik (FK)
  3321. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3322. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3323. { normally, win64 doesn't support the legacy fpu }
  3324. if target_info.system=system_x86_64_win64 then
  3325. begin
  3326. def_system_macro('FPC_CURRENCY_IS_INT64');
  3327. def_system_macro('FPC_COMP_IS_INT64');
  3328. end;
  3329. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3330. {$endif}
  3331. {$ifdef sparc}
  3332. def_system_macro('CPUSPARCGEN');
  3333. def_system_macro('CPUSPARC');
  3334. def_system_macro('CPUSPARC32');
  3335. def_system_macro('CPU32');
  3336. def_system_macro('FPC_CURRENCY_IS_INT64');
  3337. def_system_macro('FPC_COMP_IS_INT64');
  3338. {$endif}
  3339. {$ifdef sparc64}
  3340. def_system_macro('CPUSPARCGEN');
  3341. def_system_macro('CPUSPARC64');
  3342. def_system_macro('CPU64');
  3343. def_system_macro('FPC_CURRENCY_IS_INT64');
  3344. def_system_macro('FPC_COMP_IS_INT64');
  3345. {$endif}
  3346. {$ifdef arm}
  3347. def_system_macro('CPUARM');
  3348. def_system_macro('CPU32');
  3349. def_system_macro('FPC_CURRENCY_IS_INT64');
  3350. def_system_macro('FPC_COMP_IS_INT64');
  3351. {$endif arm}
  3352. {$ifdef avr}
  3353. def_system_macro('CPUAVR');
  3354. def_system_macro('CPU16');
  3355. def_system_macro('FPC_CURRENCY_IS_INT64');
  3356. def_system_macro('FPC_COMP_IS_INT64');
  3357. {$endif avr}
  3358. {$ifdef jvm}
  3359. def_system_macro('CPUJVM');
  3360. def_system_macro('CPU32');
  3361. def_system_macro('FPC_CURRENCY_IS_INT64');
  3362. def_system_macro('FPC_COMP_IS_INT64');
  3363. {$endif jvm}
  3364. {$ifdef mipsel}
  3365. def_system_macro('CPUMIPS');
  3366. def_system_macro('CPUMIPS32');
  3367. def_system_macro('CPUMIPSEL');
  3368. def_system_macro('CPUMIPSEL32');
  3369. def_system_macro('CPU32');
  3370. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3371. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3372. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3373. def_system_macro('FPC_CURRENCY_IS_INT64');
  3374. def_system_macro('FPC_COMP_IS_INT64');
  3375. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3376. { On most systems, locals are accessed relative to base pointer,
  3377. but for MIPS cpu, they are accessed relative to stack pointer.
  3378. This needs adaptation for so low level routines,
  3379. like MethodPointerLocal and related objects unit functions. }
  3380. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3381. {$endif mipsel}
  3382. {$ifdef mipseb}
  3383. def_system_macro('CPUMIPS');
  3384. def_system_macro('CPUMIPS32');
  3385. def_system_macro('CPUMIPSEB');
  3386. def_system_macro('CPUMIPSEB32');
  3387. def_system_macro('CPU32');
  3388. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3389. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3390. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3391. def_system_macro('FPC_CURRENCY_IS_INT64');
  3392. def_system_macro('FPC_COMP_IS_INT64');
  3393. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3394. { See comment above for mipsel }
  3395. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3396. {$endif}
  3397. {$ifdef i8086}
  3398. def_system_macro('CPU86'); { Borland compatibility }
  3399. def_system_macro('CPU87'); { Borland compatibility }
  3400. def_system_macro('CPUI8086');
  3401. def_system_macro('CPU16');
  3402. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3403. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3404. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3405. case init_settings.x86memorymodel of
  3406. mm_tiny: def_system_macro('FPC_MM_TINY');
  3407. mm_small: def_system_macro('FPC_MM_SMALL');
  3408. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3409. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3410. mm_large: def_system_macro('FPC_MM_LARGE');
  3411. mm_huge: def_system_macro('FPC_MM_HUGE');
  3412. end;
  3413. {$endif i8086}
  3414. {$ifdef aarch64}
  3415. def_system_macro('CPUAARCH64');
  3416. def_system_macro('CPU64');
  3417. def_system_macro('FPC_CURRENCY_IS_INT64');
  3418. def_system_macro('FPC_COMP_IS_INT64');
  3419. {$endif aarch64}
  3420. {$if defined(cpu8bitalu)}
  3421. def_system_macro('CPUINT8');
  3422. {$elseif defined(cpu16bitalu)}
  3423. def_system_macro('CPUINT16');
  3424. {$elseif defined(cpu32bitalu)}
  3425. def_system_macro('CPUINT32');
  3426. {$elseif defined(cpu64bitalu)}
  3427. def_system_macro('CPUINT64');
  3428. {$endif defined(cpu64bitalu)}
  3429. {$if defined(avr)}
  3430. def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
  3431. {$endif}
  3432. {$if defined(i8086) or defined(avr)}
  3433. def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
  3434. {$endif i8086 or avr}
  3435. { abs(long) is handled internally on all CPUs }
  3436. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  3437. {$if defined(i8086) or defined(i386) or defined(x86_64) or defined(powerpc64) or defined(aarch64)}
  3438. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  3439. {$endif i8086 or i386 or x86_64 or powerpc64 or aarch64}
  3440. def_system_macro('FPC_HAS_UNICODESTRING');
  3441. def_system_macro('FPC_RTTI_PACKSET1');
  3442. def_system_macro('FPC_HAS_CPSTRING');
  3443. {$ifdef x86_64}
  3444. def_system_macro('FPC_HAS_RIP_RELATIVE');
  3445. {$endif x86_64}
  3446. def_system_macro('FPC_HAS_CEXTENDED');
  3447. def_system_macro('FPC_HAS_RESSTRINITS');
  3448. { these cpus have an inline rol/ror implementaion }
  3449. {$ifdef cpurox}
  3450. {$ifdef m68k}
  3451. if CPUM68K_HAS_ROLROR in cpu_capabilities[init_settings.cputype] then
  3452. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3453. {$else}
  3454. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3455. {$endif}
  3456. {$endif}
  3457. {$ifdef powerpc64}
  3458. def_system_macro('FPC_HAS_LWSYNC');
  3459. {$endif}
  3460. { currently, all supported CPUs have an internal sar implementation }
  3461. def_system_macro('FPC_HAS_INTERNAL_SAR');
  3462. {$ifdef SUPPORT_GET_FRAME}
  3463. def_system_macro('INTERNAL_BACKTRACE');
  3464. {$endif SUPPORT_GET_FRAME}
  3465. def_system_macro('STR_CONCAT_PROCS');
  3466. {$warnings off}
  3467. if pocall_default = pocall_register then
  3468. def_system_macro('REGCALL');
  3469. {$warnings on}
  3470. end;
  3471. var
  3472. env: ansistring;
  3473. i : tfeature;
  3474. j : longint;
  3475. abi : tabi;
  3476. tmplist : TCmdStrList;
  3477. cmditem,
  3478. tmpcmditem : TCmdStrListItem;
  3479. cmdstr : TCmdStr;
  3480. {$if defined(cpucapabilities)}
  3481. cpuflag : tcpuflags;
  3482. hs : string;
  3483. {$endif defined(cpucapabilities)}
  3484. begin
  3485. option:=coption.create;
  3486. disable_configfile:=false;
  3487. { Non-core target defines }
  3488. Option.TargetOptions(true);
  3489. { get default messagefile }
  3490. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  3491. { default configfile can be specified on the commandline,
  3492. remove it first }
  3493. if (cmd<>'') and (cmd[1]='[') then
  3494. begin
  3495. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  3496. Delete(cmd,1,pos(']',cmd));
  3497. end
  3498. else
  3499. ppccfg:='fpc.cfg';
  3500. { first pass reading of parameters, only -i -v -T etc.}
  3501. option.firstpass:=true;
  3502. if cmd<>'' then
  3503. option.parsecmd(cmd)
  3504. else
  3505. begin
  3506. option.read_parameters;
  3507. { Write only quickinfo }
  3508. if option.quickinfo<>'' then
  3509. option.writequickinfo;
  3510. end;
  3511. option.firstpass:=false;
  3512. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  3513. Option.TargetOptions(true);
  3514. { target is set here, for wince the default app type is gui }
  3515. if target_info.system in systems_wince then
  3516. SetApptype(app_gui)
  3517. else
  3518. SetApptype(apptype);
  3519. { default defines }
  3520. def_system_macro(target_info.shortname);
  3521. def_system_macro('FPC');
  3522. def_system_macro('VER'+version_nr);
  3523. def_system_macro('VER'+version_nr+'_'+release_nr);
  3524. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  3525. { Temporary defines, until things settle down }
  3526. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  3527. def_system_macro('FPC_HAS_CONSTREF');
  3528. def_system_macro('FPC_STATICRIPFIXED');
  3529. def_system_macro('FPC_VARIANTCOPY_FIXED');
  3530. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  3531. def_system_macro('FPC_HAS_MEMBAR');
  3532. def_system_macro('FPC_SETBASE_USED');
  3533. { don't remove this, it's also for fpdoc necessary (FK) }
  3534. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  3535. { make cpu makros available when reading the config files the second time }
  3536. def_cpu_macros;
  3537. if tf_cld in target_info.flags then
  3538. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  3539. InternalError(2013092801);
  3540. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  3541. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  3542. InternalError(2013092801);
  3543. { Use standard Android NDK prefixes when cross-compiling }
  3544. if (source_info.system<>target_info.system) and (target_info.system in systems_android) then
  3545. case target_info.system of
  3546. system_arm_android:
  3547. utilsprefix:='arm-linux-androideabi-';
  3548. system_i386_android:
  3549. utilsprefix:='i686-linux-android-';
  3550. else
  3551. utilsprefix:=target_cpu_string + '-linux-android-';
  3552. end;
  3553. { Set up default value for the heap }
  3554. if target_info.system in systems_embedded then
  3555. begin
  3556. case target_info.system of
  3557. {$ifdef AVR}
  3558. system_avr_embedded:
  3559. if init_settings.controllertype=ct_avrsim then
  3560. heapsize:=8192
  3561. else
  3562. heapsize:=128;
  3563. {$endif AVR}
  3564. system_arm_embedded:
  3565. heapsize:=256;
  3566. system_mipsel_embedded:
  3567. heapsize:=256;
  3568. else
  3569. heapsize:=256;
  3570. end;
  3571. end;
  3572. { read configuration file }
  3573. if (not disable_configfile) and
  3574. (ppccfg<>'') then
  3575. read_configfile:=check_configfile(ppccfg,ppccfg)
  3576. else
  3577. read_configfile := false;
  3578. { Read commandline and configfile }
  3579. param_file:='';
  3580. { read configfile }
  3581. if read_configfile then
  3582. option.interpret_file(ppccfg);
  3583. { read parameters again to override config file }
  3584. if cmd<>'' then
  3585. option.parsecmd(cmd)
  3586. else
  3587. begin
  3588. { Write help pages if no parameters are passed }
  3589. if (paramcount=0) then
  3590. Option.WriteHelpPages;
  3591. option.read_parameters;
  3592. { Write only quickinfo }
  3593. if option.quickinfo<>'' then
  3594. option.writequickinfo;
  3595. end;
  3596. { check the compatibility of different options and adjust them if necessary
  3597. (and print possible errors)
  3598. }
  3599. option.checkoptionscompatibility;
  3600. { uses the CPUXXX-defines and target_info to determine whether the selected
  3601. target processor, if any, is supported }
  3602. Option.VerifyTargetProcessor;
  3603. { Stop if errors in options }
  3604. if ErrorCount>0 then
  3605. StopOptions(1);
  3606. { endian define }
  3607. case target_info.endian of
  3608. endian_little :
  3609. begin
  3610. def_system_macro('ENDIAN_LITTLE');
  3611. def_system_macro('FPC_LITTLE_ENDIAN');
  3612. end;
  3613. endian_big :
  3614. begin
  3615. def_system_macro('ENDIAN_BIG');
  3616. def_system_macro('FPC_BIG_ENDIAN');
  3617. end;
  3618. end;
  3619. { Write logo }
  3620. if option.ParaLogo then
  3621. option.writelogo;
  3622. { Check file to compile }
  3623. if param_file='' then
  3624. begin
  3625. Message(option_no_source_found);
  3626. StopOptions(1);
  3627. end;
  3628. {$ifndef Unix}
  3629. param_file:=FixFileName(param_file);
  3630. {$endif not unix}
  3631. inputfilepath:=ExtractFilePath(param_file);
  3632. inputfilename:=ExtractFileName(param_file);
  3633. if ExtractFileExt(inputfilename)='' then
  3634. begin
  3635. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  3636. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  3637. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  3638. inputfilename:=ChangeFileExt(inputfilename,pasext)
  3639. else if ((m_mac in current_settings.modeswitches) or
  3640. (tf_p_ext_support in target_info.flags))
  3641. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  3642. inputfilename:=ChangeFileExt(inputfilename,pext);
  3643. end;
  3644. { Check output dir }
  3645. if (OutputExeDir<>'') and
  3646. not PathExists(OutputExeDir,false) then
  3647. begin
  3648. Message1(general_e_path_does_not_exist,OutputExeDir);
  3649. StopOptions(1);
  3650. end;
  3651. { Add paths specified with parameters to the searchpaths }
  3652. UnitSearchPath.AddList(option.ParaUnitPath,true);
  3653. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  3654. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  3655. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  3656. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  3657. packagesearchpath.addlist(option.parapackagepath,true);
  3658. for j:=0 to option.parapackages.count-1 do
  3659. add_package(option.parapackages.NameOfIndex(j),true,true);
  3660. { add default namespaces }
  3661. tmplist:=TCmdStrList.Create;
  3662. cmditem:=TCmdStrListItem(option.paranamespaces.First);
  3663. while assigned(cmditem) do
  3664. begin
  3665. { use a temporary list cause if ";" are involved we need to reverse the
  3666. order due to how TCmdStrList behaves }
  3667. cmdstr:=cmditem.str;
  3668. repeat
  3669. j:=Pos(';',cmdstr);
  3670. if j>0 then
  3671. begin
  3672. tmplist.insert(copy(cmdstr,1,j-1));
  3673. delete(cmdstr,1,j);
  3674. end
  3675. else
  3676. tmplist.insert(cmdstr);
  3677. until j=0;
  3678. tmpcmditem:=TCmdStrListItem(tmplist.First);
  3679. while assigned(tmpcmditem) do
  3680. begin
  3681. namespacelist.insert(tmpcmditem.Str);
  3682. tmpcmditem:=TCmdStrListItem(tmpcmditem.Next);
  3683. end;
  3684. tmplist.clear;
  3685. cmditem:=TCmdStrListItem(cmditem.Next);
  3686. end;
  3687. tmplist.Free;
  3688. { add unit environment and exepath to the unit search path }
  3689. if inputfilepath<>'' then
  3690. Unitsearchpath.AddPath(inputfilepath,true);
  3691. if not disable_configfile then
  3692. begin
  3693. env:=GetEnvironmentVariable(target_info.unit_env);
  3694. if env<>'' then
  3695. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  3696. end;
  3697. {$ifdef Unix}
  3698. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3699. if fpcdir='' then
  3700. begin
  3701. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  3702. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  3703. else
  3704. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  3705. end;
  3706. {$else unix}
  3707. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3708. if fpcdir='' then
  3709. begin
  3710. fpcdir:=ExePath+'../';
  3711. if not(PathExists(fpcdir+'units',true)) and
  3712. not(PathExists(fpcdir+'rtl',true)) then
  3713. fpcdir:=fpcdir+'../';
  3714. end;
  3715. {$endif unix}
  3716. { first try development RTL, else use the default installation path }
  3717. if not disable_configfile then
  3718. begin
  3719. if PathExists(FpcDir+'rtl',true) then
  3720. if (tf_use_8_3 in Source_Info.Flags) or
  3721. (tf_use_8_3 in Target_Info.Flags) then
  3722. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  3723. else
  3724. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  3725. else
  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+'units/'+target_os_string+'/rtl',false)
  3729. else
  3730. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  3731. end;
  3732. { Add exepath if the exe is not in the current dir, because that is always searched already.
  3733. Do not add it when linking on the target because then we can maybe already find
  3734. .o files that are not for the target }
  3735. if (ExePath<>cfileutl.GetCurrentDir) and
  3736. not(cs_link_on_target in init_settings.globalswitches) then
  3737. UnitSearchPath.AddPath(ExePath,false);
  3738. { Add unit dir to the object and library path }
  3739. objectsearchpath.AddList(unitsearchpath,false);
  3740. librarysearchpath.AddList(unitsearchpath,false);
  3741. {$ifdef llvm}
  3742. { default to clang }
  3743. if (option.paratargetasm=as_none) then
  3744. begin
  3745. option.paratargetasm:=as_clang_llvm;
  3746. end;
  3747. {$endif llvm}
  3748. { maybe override assembler }
  3749. if (option.paratargetasm<>as_none) then
  3750. begin
  3751. if not set_target_asm(option.paratargetasm) then
  3752. begin
  3753. if assigned(asminfos[option.paratargetasm]) then
  3754. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name)
  3755. else
  3756. Message2(option_incompatible_asm,'<invalid assembler>',target_info.name);
  3757. set_target_asm(target_info.assemextern);
  3758. Message1(option_asm_forced,target_asm.idtxt);
  3759. end;
  3760. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  3761. (option.paratargetdbg<>dbg_none) then
  3762. begin
  3763. Message1(option_confict_asm_debug,
  3764. asminfos[option.paratargetasm]^.idtxt);
  3765. option.paratargetdbg:=dbg_none;
  3766. exclude(init_settings.moduleswitches,cs_debuginfo);
  3767. end;
  3768. { Some assemblers, like clang, do not support
  3769. stabs debugging format, switch to dwardé in that case }
  3770. if (af_no_stabs in asminfos[option.paratargetasm]^.flags) and
  3771. (option.paratargetdbg=dbg_stabs) then
  3772. begin
  3773. option.paratargetdbg:=dbg_dwarf2;
  3774. end;
  3775. end;
  3776. {TOptionheck a second time as we might have changed assembler just above }
  3777. option.checkoptionscompatibility;
  3778. { maybe override debug info format }
  3779. if (option.paratargetdbg<>dbg_none) then
  3780. if not set_target_dbg(option.paratargetdbg) then
  3781. Message(option_w_unsupported_debug_format);
  3782. { switch assembler if it's binary and we got -a on the cmdline }
  3783. if (cs_asm_leave in init_settings.globalswitches) and
  3784. (af_outputbinary in target_asm.flags) then
  3785. begin
  3786. Message(option_switch_bin_to_src_assembler);
  3787. {$ifdef llvm}
  3788. set_target_asm(as_clang_llvm);
  3789. {$else}
  3790. set_target_asm(target_info.assemextern);
  3791. {$endif}
  3792. { At least i8086 needs that for nasm and -CX
  3793. which is incompatible with internal linker }
  3794. option.checkoptionscompatibility;
  3795. end;
  3796. { Force use of external linker if there is no
  3797. internal linker or the linking is skipped }
  3798. if not(cs_link_extern in init_settings.globalswitches) and
  3799. ((target_info.link=ld_none) or
  3800. (cs_link_nolink in init_settings.globalswitches)) then
  3801. begin
  3802. include(init_settings.globalswitches,cs_link_extern);
  3803. end;
  3804. { turn off stripping if compiling with debuginfo or profile }
  3805. if (
  3806. (cs_debuginfo in init_settings.moduleswitches) or
  3807. (cs_profile in init_settings.moduleswitches)
  3808. ) and
  3809. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  3810. exclude(init_settings.globalswitches,cs_link_strip);
  3811. { set Mac OS X version default macros if not specified explicitly }
  3812. option.MaybeSetDefaultMacVersionMacro;
  3813. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  3814. if fpu type not explicitly set }
  3815. if not(option.FPUSetExplicitly) and
  3816. ((target_info.system in [system_arm_wince,system_arm_gba,
  3817. system_m68k_amiga,system_m68k_atari,
  3818. system_arm_nds,system_arm_embedded])
  3819. {$ifdef arm}
  3820. or (target_info.abi=abi_eabi)
  3821. {$endif arm}
  3822. )
  3823. {$if defined(arm) or defined (m68k)}
  3824. or (init_settings.fputype=fpu_soft)
  3825. {$endif arm or m68k}
  3826. then
  3827. begin
  3828. {$ifdef cpufpemu}
  3829. include(init_settings.moduleswitches,cs_fp_emulation);
  3830. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  3831. init_settings.fputype:=fpu_soft;
  3832. {$endif cpufpemu}
  3833. end;
  3834. {$ifdef i386}
  3835. case target_info.system of
  3836. system_i386_android:
  3837. begin
  3838. { set default cpu type to PentiumM for Android unless specified otherwise }
  3839. if not option.CPUSetExplicitly then
  3840. init_settings.cputype:=cpu_PentiumM;
  3841. if not option.OptCPUSetExplicitly then
  3842. init_settings.optimizecputype:=cpu_PentiumM;
  3843. { set default fpu type to SSSE3 for Android unless specified otherwise }
  3844. if not option.FPUSetExplicitly then
  3845. init_settings.fputype:=fpu_ssse3;
  3846. end;
  3847. end;
  3848. {$endif i386}
  3849. {$ifdef arm}
  3850. case target_info.system of
  3851. system_arm_ios:
  3852. begin
  3853. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  3854. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  3855. }
  3856. if not option.CPUSetExplicitly then
  3857. init_settings.cputype:=cpu_armv7;
  3858. if not option.OptCPUSetExplicitly then
  3859. init_settings.optimizecputype:=cpu_armv7;
  3860. if not option.FPUSetExplicitly then
  3861. init_settings.fputype:=fpu_vfpv3;
  3862. end;
  3863. system_arm_android:
  3864. begin
  3865. { set default cpu type to ARMv5T for Android unless specified otherwise }
  3866. if not option.CPUSetExplicitly then
  3867. init_settings.cputype:=cpu_armv5t;
  3868. if not option.OptCPUSetExplicitly then
  3869. init_settings.optimizecputype:=cpu_armv5t;
  3870. end;
  3871. end;
  3872. { ARMHF defaults }
  3873. if (target_info.abi = abi_eabihf) then
  3874. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  3875. begin
  3876. {$ifdef CPUARMV6}
  3877. { if the compiler is built for armv6, then
  3878. inherit this setting, e.g. Raspian is armhf but
  3879. only armv6, this makes rebuilds of the compiler
  3880. easier }
  3881. if not option.CPUSetExplicitly then
  3882. init_settings.cputype:=cpu_armv6;
  3883. if not option.OptCPUSetExplicitly then
  3884. init_settings.optimizecputype:=cpu_armv6;
  3885. {$else CPUARMV6}
  3886. if not option.CPUSetExplicitly then
  3887. init_settings.cputype:=cpu_armv7a;
  3888. if not option.OptCPUSetExplicitly then
  3889. init_settings.optimizecputype:=cpu_armv7a;
  3890. {$endif CPUARMV6}
  3891. { Set FPU type }
  3892. if not(option.FPUSetExplicitly) then
  3893. begin
  3894. if init_settings.cputype < cpu_armv7 then
  3895. init_settings.fputype:=fpu_vfpv2
  3896. else
  3897. init_settings.fputype:=fpu_vfpv3_d16;
  3898. end
  3899. else
  3900. begin
  3901. if not (init_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv3_d16,fpu_vfpv4])
  3902. or (target_info.system = system_arm_ios) then
  3903. begin
  3904. Message(option_illegal_fpu_eabihf);
  3905. StopOptions(1);
  3906. end;
  3907. end;
  3908. end;
  3909. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3910. begin
  3911. def_system_macro('CPUTHUMB');
  3912. if not option.FPUSetExplicitly then
  3913. init_settings.fputype:=fpu_soft;
  3914. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  3915. 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';
  3916. {$else FPC_ARMAL or FPC_ARMHF}
  3917. if target_info.endian=endian_little then
  3918. 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';
  3919. {$endif FPC_ARMAL or FPC_ARMHF}
  3920. end;
  3921. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3922. def_system_macro('CPUTHUMB2');
  3923. {$endif arm}
  3924. {$ifdef jvm}
  3925. { set default CPU type to Dalvik when targeting Android }
  3926. if target_info.system=system_jvm_android32 then
  3927. begin
  3928. if not option.CPUSetExplicitly then
  3929. init_settings.cputype:=cpu_dalvik;
  3930. end;
  3931. {$endif jvm}
  3932. {$ifdef llvm}
  3933. { standard extension for llvm bitcode files }
  3934. target_info.asmext:='.ll';
  3935. { don't generate dwarf cfi, llvm will do that }
  3936. exclude(target_info.flags,tf_needs_dwarf_cfi);
  3937. {$endif llvm}
  3938. {$ifdef mipsel}
  3939. case target_info.system of
  3940. system_mipsel_android:
  3941. begin
  3942. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  3943. if not option.CPUSetExplicitly then
  3944. init_settings.cputype:=cpu_mips32;
  3945. if not option.OptCPUSetExplicitly then
  3946. init_settings.optimizecputype:=cpu_mips32;
  3947. if not option.FPUSetExplicitly then
  3948. init_settings.fputype:=fpu_mips2;
  3949. end;
  3950. system_mipsel_embedded:
  3951. begin
  3952. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  3953. if not option.CPUSetExplicitly then
  3954. init_settings.cputype:=cpu_pic32mx;
  3955. if not option.OptCPUSetExplicitly then
  3956. init_settings.optimizecputype:=cpu_pic32mx;
  3957. if not option.FPUSetExplicitly then
  3958. init_settings.fputype:=fpu_soft;
  3959. end;
  3960. end;
  3961. {$endif mipsel}
  3962. {$ifdef m68k}
  3963. if init_settings.cputype in cpu_coldfire then
  3964. def_system_macro('CPUCOLDFIRE');
  3965. case target_info.system of
  3966. system_m68k_linux,
  3967. system_m68k_netbsd:
  3968. begin
  3969. if not (option.FPUSetExplicitly) and
  3970. not (init_settings.cputype in cpu_coldfire) then
  3971. begin
  3972. { enable HW FPU for UNIX by default, but only for
  3973. original 68k, not Coldfire }
  3974. exclude(init_settings.moduleswitches,cs_fp_emulation);
  3975. init_settings.fputype:=fpu_68881;
  3976. end;
  3977. end;
  3978. system_m68k_palmos:
  3979. begin
  3980. if not option.CPUSetExplicitly then
  3981. init_settings.cputype:=cpu_mc68000;
  3982. if not (option.FPUSetExplicitly) then
  3983. begin
  3984. { No FPU for PalmOS by default }
  3985. exclude(init_settings.moduleswitches,cs_fp_emulation);
  3986. init_settings.fputype:=fpu_none;
  3987. end;
  3988. end;
  3989. end;
  3990. {$endif m68k}
  3991. { now we can define cpu and fpu type }
  3992. def_cpu_macros;
  3993. { Use init_settings cpu type for asm cpu type,
  3994. if asmcputype is cpu_none,
  3995. at least as long as there is no explicit
  3996. option to set it on command line PM }
  3997. if init_settings.asmcputype = cpu_none then
  3998. init_settings.asmcputype:=init_settings.cputype;
  3999. {$ifdef llvm}
  4000. def_system_macro('CPULLVM');
  4001. {$endif llvm}
  4002. {$if defined(cpucapabilities)}
  4003. for cpuflag:=low(cpuflag) to high(cpuflag) do
  4004. begin
  4005. str(cpuflag,hs);
  4006. if cpuflag in cpu_capabilities[init_settings.cputype] then
  4007. def_system_macro(hs)
  4008. else
  4009. undef_system_macro(hs);
  4010. end;
  4011. {$endif defined(cpucapabilities)}
  4012. if init_settings.fputype<>fpu_none then
  4013. begin
  4014. {$if defined(i386) or defined(i8086)}
  4015. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4016. {$endif}
  4017. def_system_macro('FPC_HAS_TYPE_SINGLE');
  4018. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  4019. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  4020. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  4021. {$endif}
  4022. {$if defined(m68k)}
  4023. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  4024. {$endif}
  4025. {$ifdef x86_64}
  4026. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4027. { normally, win64 doesn't support the legacy fpu }
  4028. if target_info.system=system_x86_64_win64 then
  4029. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  4030. else
  4031. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  4032. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  4033. {$endif}
  4034. end;
  4035. { Enable now for testing }
  4036. {$ifndef DISABLE_TLS_DIRECTORY}
  4037. if target_info.system in systems_windows then
  4038. def_system_macro('FPC_USE_TLS_DIRECTORY');
  4039. {$endif not DISABLE_TLS_DIRECTORY}
  4040. {$ifndef DISABLE_WIN64_SEH}
  4041. if target_info.system=system_x86_64_win64 then
  4042. def_system_macro('FPC_USE_WIN64_SEH');
  4043. {$endif DISABLE_WIN64_SEH}
  4044. {$ifndef DISABLE_WIN32_SEH}
  4045. if target_info.system=system_i386_win32 then
  4046. def_system_macro('FPC_USE_WIN32_SEH');
  4047. {$endif not DISABLE_WIN32_SEH}
  4048. {$ifdef ARM}
  4049. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  4050. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  4051. not(cs_fp_emulation in init_settings.moduleswitches) then
  4052. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  4053. {$endif ARM}
  4054. { inline bsf/bsr implementation }
  4055. {$if not defined(llvm) and (defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64))}
  4056. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4057. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4058. {$endif}
  4059. { hardware FMA support }
  4060. {$if defined(i386) or defined(x86_64)}
  4061. if (cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[] then
  4062. begin
  4063. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  4064. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  4065. end;
  4066. {$endif defined(i386) or defined(x86_64)}
  4067. {$if defined(arm)}
  4068. { it is determined during system unit compilation if clz is used for bsf or not,
  4069. this is not perfect but the current implementation bsf/bsr does not allow another
  4070. solution }
  4071. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  4072. ((init_settings.instructionset=is_arm) or
  4073. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  4074. begin
  4075. def_system_macro('FPC_HAS_INTERNAL_BSR');
  4076. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  4077. def_system_macro('FPC_HAS_INTERNAL_BSF');
  4078. end;
  4079. {$endif}
  4080. {$if defined(powerpc64)}
  4081. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  4082. big endian (unless specified otherwise). As the gcc man page says:
  4083. "Overriding the default ABI requires special system support and is
  4084. likely to fail in spectacular ways" }
  4085. if not option.ABISetExplicitly then
  4086. begin
  4087. if (target_info.abi=abi_powerpc_sysv) and
  4088. (target_info.endian=endian_little) then
  4089. target_info.abi:=abi_powerpc_elfv2
  4090. else
  4091. if (target_info.abi=abi_powerpc_elfv2) and
  4092. (target_info.endian=endian_big) then
  4093. target_info.abi:=abi_powerpc_sysv
  4094. end;
  4095. {$endif}
  4096. {$if defined(powerpc) or defined(powerpc64)}
  4097. { define _CALL_ELF symbol like gcc }
  4098. case target_info.abi of
  4099. abi_powerpc_sysv:
  4100. set_system_compvar('_CALL_ELF','1');
  4101. abi_powerpc_elfv2:
  4102. set_system_compvar('_CALL_ELF','2');
  4103. end;
  4104. {$endif}
  4105. { Section smartlinking conflicts with import sections on Windows }
  4106. if GenerateImportSection and
  4107. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  4108. exclude(target_info.flags,tf_smartlink_sections);
  4109. if not option.LinkTypeSetExplicitly then
  4110. set_default_link_type;
  4111. { Default alignment settings,
  4112. 1. load the defaults for the target
  4113. 2. override with generic optimizer setting (little size)
  4114. 3. override with the user specified -Oa }
  4115. UpdateAlignment(init_settings.alignment,target_info.alignment);
  4116. if (cs_opt_size in init_settings.optimizerswitches) then
  4117. begin
  4118. init_settings.alignment.procalign:=1;
  4119. init_settings.alignment.jumpalign:=1;
  4120. init_settings.alignment.loopalign:=1;
  4121. {$ifdef x86}
  4122. { constalignmax=1 keeps the executable and thus the memory foot print small but
  4123. all processors except x86 are really hurt by this or might even crash }
  4124. init_settings.alignment.constalignmax:=1;
  4125. {$endif x86}
  4126. end;
  4127. UpdateAlignment(init_settings.alignment,option.paraalignment);
  4128. set_system_macro('FPC_VERSION',version_nr);
  4129. set_system_macro('FPC_RELEASE',release_nr);
  4130. set_system_macro('FPC_PATCH',patch_nr);
  4131. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  4132. if target_info.system in systems_indirect_entry_information then
  4133. def_system_macro('FPC_HAS_INDIRECT_ENTRY_INFORMATION');
  4134. if not (tf_winlikewidestring in target_info.flags) then
  4135. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  4136. if tf_supports_packages in target_info.flags then
  4137. def_system_macro('FPC_HAS_DYNAMIC_PACKAGES');
  4138. if target_info.system in systems_indirect_var_imports then
  4139. def_system_macro('FPC_HAS_INDIRECT_VAR_ACCESS');
  4140. if cs_compilesystem in init_settings.moduleswitches then
  4141. for i:=low(tfeature) to high(tfeature) do
  4142. if i in features then
  4143. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  4144. {$push}
  4145. {$warn 6018 off} { Unreachable code due to compile time evaluation }
  4146. if ControllerSupport and (target_info.system in systems_embedded) and
  4147. (init_settings.controllertype<>ct_none) then
  4148. begin
  4149. with embedded_controllers[init_settings.controllertype] do
  4150. begin
  4151. set_system_macro('FPC_FLASHBASE',tostr(flashbase));
  4152. set_system_macro('FPC_FLASHSIZE',tostr(flashsize));
  4153. set_system_macro('FPC_SRAMBASE',tostr(srambase));
  4154. set_system_macro('FPC_SRAMSIZE',tostr(sramsize));
  4155. set_system_macro('FPC_EEPROMBASE',tostr(eeprombase));
  4156. set_system_macro('FPC_EEPROMSIZE',tostr(eepromsize));
  4157. set_system_macro('FPC_BOOTBASE',tostr(bootbase));
  4158. set_system_macro('FPC_BOOTSIZE',tostr(bootsize));
  4159. end;
  4160. end;
  4161. {$pop}
  4162. { as stackalign is not part of the alignment record, we do not need to define the others alignments for symmetry yet }
  4163. set_system_macro('FPC_STACKALIGNMENT',tostr(target_info.stackalign));
  4164. option.free;
  4165. Option:=nil;
  4166. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl];
  4167. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal, pocall_sysv_abi_cdecl, pocall_ms_abi_cdecl];
  4168. if (tf_safecall_clearstack in target_info.flags) then
  4169. begin
  4170. include (cdecl_pocalls, pocall_safecall);
  4171. include (clearstack_pocalls, pocall_safecall)
  4172. end;
  4173. end;
  4174. initialization
  4175. coption:=toption;
  4176. finalization
  4177. if assigned(option) then
  4178. option.free;
  4179. end.