options.pas 134 KB

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