options.pas 133 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021
  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: 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 we first specify that the system code page should be
  1382. used and then explicitly specify a code page, unset the
  1383. flag that we're using the system code page again }
  1384. SetCompileModeSwitch('SYSTEMCODEPAGE-',true);
  1385. if (upper(more)='UTF8') or (upper(more)='UTF-8') then
  1386. init_settings.sourcecodepage:=CP_UTF8
  1387. else if not(cpavailable(more)) then
  1388. Message1(option_code_page_not_available,more)
  1389. else
  1390. init_settings.sourcecodepage:=codepagebyname(more);
  1391. include(init_settings.moduleswitches,cs_explicit_codepage);
  1392. end;
  1393. 'C' :
  1394. RCCompiler:=More;
  1395. 'd' :
  1396. if UnsetBool(more, 0, opt, true) then
  1397. init_settings.disabledircache:=false
  1398. else
  1399. init_settings.disabledircache:=true;
  1400. 'D' :
  1401. utilsdirectory:=FixPath(More,true);
  1402. 'e' :
  1403. SetRedirectFile(More);
  1404. 'E' :
  1405. OutputExeDir:=FixPath(More,true);
  1406. 'f' :
  1407. if (target_info.system in systems_darwin) then
  1408. if ispara then
  1409. ParaFrameworkPath.AddPath(More,false)
  1410. else
  1411. frameworksearchpath.AddPath(More,true)
  1412. else
  1413. IllegalPara(opt);
  1414. 'i' :
  1415. begin
  1416. if ispara then
  1417. ParaIncludePath.AddPath(More,false)
  1418. else
  1419. includesearchpath.AddPath(More,true);
  1420. end;
  1421. 'm' :
  1422. begin
  1423. s:=ExtractFileDir(more);
  1424. if TryStrToInt(ExtractFileName(more),j) then
  1425. begin
  1426. unicodemapping:=loadunicodemapping(More,More+'.txt',j);
  1427. if assigned(unicodemapping) then
  1428. registermapping(unicodemapping)
  1429. else
  1430. IllegalPara(opt);
  1431. end
  1432. else
  1433. IllegalPara(opt);
  1434. end;
  1435. 'M' :
  1436. unicodepath:=FixPath(More,true);
  1437. 'g' :
  1438. Message2(option_obsolete_switch_use_new,'-Fg','-Fl');
  1439. 'l' :
  1440. begin
  1441. if path_absolute(More) then
  1442. if ispara then
  1443. ParaLibraryPath.AddPath(sysrootpath,More,false)
  1444. else
  1445. LibrarySearchPath.AddPath(sysrootpath,More,true)
  1446. else
  1447. if ispara then
  1448. ParaLibraryPath.AddPath('',More,false)
  1449. else
  1450. LibrarySearchPath.AddPath('',More,true);
  1451. end;
  1452. 'L' :
  1453. begin
  1454. if More<>'' then
  1455. ParaDynamicLinker:=More
  1456. else
  1457. IllegalPara(opt);
  1458. end;
  1459. 'o' :
  1460. begin
  1461. if ispara then
  1462. ParaObjectPath.AddPath(More,false)
  1463. else
  1464. ObjectSearchPath.AddPath(More,true);
  1465. end;
  1466. 'r' :
  1467. Msgfilename:=More;
  1468. 'R' :
  1469. ResCompiler:=More;
  1470. 'u' :
  1471. begin
  1472. if ispara then
  1473. ParaUnitPath.AddPath(More,false)
  1474. else
  1475. unitsearchpath.AddPath(More,true);
  1476. end;
  1477. 'U' :
  1478. OutputUnitDir:=FixPath(More,true);
  1479. 'W',
  1480. 'w':
  1481. begin
  1482. if More<>'' then
  1483. begin
  1484. DefaultReplacements(More);
  1485. D:=ExtractFilePath(More);
  1486. if (D<>'') then
  1487. D:=FixPath(D,True);
  1488. D:=D+ExtractFileName(More);
  1489. if (c='W') then
  1490. WpoFeedbackOutput:=D
  1491. else
  1492. WpoFeedbackInput:=D;
  1493. end
  1494. else
  1495. IllegalPara(opt);
  1496. end;
  1497. else
  1498. IllegalPara(opt);
  1499. end;
  1500. end;
  1501. 'g' :
  1502. begin
  1503. if UnsetBool(More, 0, opt, false) then
  1504. begin
  1505. exclude(init_settings.moduleswitches,cs_debuginfo);
  1506. exclude(init_settings.globalswitches,cs_use_heaptrc);
  1507. exclude(init_settings.globalswitches,cs_use_lineinfo);
  1508. exclude(init_settings.localswitches,cs_checkpointer);
  1509. localvartrashing := -1;
  1510. end
  1511. else
  1512. begin
  1513. include(init_settings.moduleswitches,cs_debuginfo);
  1514. if paratargetdbg=dbg_none then
  1515. paratargetdbg:=target_info.dbg;
  1516. end;
  1517. if not RelocSectionSetExplicitly then
  1518. RelocSection:=false;
  1519. j:=1;
  1520. while j<=length(more) do
  1521. begin
  1522. case more[j] of
  1523. 'c' :
  1524. begin
  1525. if UnsetBool(More, j, opt, false) then
  1526. exclude(init_settings.localswitches,cs_checkpointer)
  1527. else if (target_info.system in systems_support_checkpointer) then
  1528. include(init_settings.localswitches,cs_checkpointer)
  1529. else
  1530. UnsupportedPara('-gc');
  1531. end;
  1532. 'h' :
  1533. begin
  1534. if UnsetBool(More, j, opt, false) then
  1535. exclude(init_settings.globalswitches,cs_use_heaptrc)
  1536. else
  1537. include(init_settings.globalswitches,cs_use_heaptrc);
  1538. end;
  1539. 'l' :
  1540. begin
  1541. if UnsetBool(More, j, opt, false) then
  1542. exclude(init_settings.globalswitches,cs_use_lineinfo)
  1543. else
  1544. include(init_settings.globalswitches,cs_use_lineinfo);
  1545. end;
  1546. 'o' :
  1547. begin
  1548. if not UpdateDebugStr(copy(more,j+1,length(more)),init_settings.debugswitches) then
  1549. IllegalPara(opt);
  1550. break;
  1551. end;
  1552. 'p' :
  1553. begin
  1554. if UnsetBool(More, j, opt, false) then
  1555. exclude(init_settings.globalswitches,cs_stabs_preservecase)
  1556. else
  1557. include(init_settings.globalswitches,cs_stabs_preservecase);
  1558. end;
  1559. 's' :
  1560. begin
  1561. paratargetdbg:=dbg_stabs;
  1562. end;
  1563. 't' :
  1564. begin
  1565. if UnsetBool(More, j, opt, false) then
  1566. localvartrashing := -1
  1567. else
  1568. localvartrashing := (localvartrashing + 1) mod nroftrashvalues;
  1569. end;
  1570. 'v' :
  1571. begin
  1572. if UnsetBool(More, j, opt, false) then
  1573. exclude(init_settings.globalswitches,cs_gdb_valgrind)
  1574. else
  1575. include(init_settings.globalswitches,cs_gdb_valgrind);
  1576. end;
  1577. 'w' :
  1578. begin
  1579. if (j<length(more)) and (more[j+1] in ['2','3','4']) then
  1580. begin
  1581. case more[j+1] of
  1582. '2': paratargetdbg:=dbg_dwarf2;
  1583. '3': paratargetdbg:=dbg_dwarf3;
  1584. '4': paratargetdbg:=dbg_dwarf4;
  1585. end;
  1586. inc(j);
  1587. end
  1588. else
  1589. paratargetdbg:=dbg_dwarf2;
  1590. end;
  1591. else
  1592. IllegalPara(opt);
  1593. end;
  1594. inc(j);
  1595. end;
  1596. end;
  1597. 'h' :
  1598. begin
  1599. NoPressEnter:=true;
  1600. if (More <> '') and (More [1] = 'F') then
  1601. begin
  1602. FPCHelpLines := true;
  1603. Delete (More, 1, 1);
  1604. FPCBinaryPath := More;
  1605. end;
  1606. WriteHelpPages;
  1607. end;
  1608. 'i' :
  1609. begin
  1610. if (More='') or
  1611. (More [1] in ['a', 'c', 'f', 'i', 'o', 'r', 't', 'u', 'w']) then
  1612. WriteInfo (More)
  1613. else
  1614. QuickInfo:=QuickInfo+More;
  1615. end;
  1616. 'I' :
  1617. begin
  1618. if ispara then
  1619. ParaIncludePath.AddPath(More,false)
  1620. else
  1621. includesearchpath.AddPath(More,false);
  1622. end;
  1623. 'k' :
  1624. begin
  1625. if more<>'' then
  1626. ParaLinkOptions:=ParaLinkOptions+' '+More
  1627. else
  1628. IllegalPara(opt);
  1629. end;
  1630. 'l' :
  1631. ParaLogo:=not UnSetBool(more,0,opt,true);
  1632. {$ifdef PREPROCWRITE}
  1633. 'm' :
  1634. parapreprocess:=not UnSetBool(more,0,opt,true);
  1635. {$endif PREPROCWRITE}
  1636. 'M' :
  1637. begin
  1638. more:=Upper(more);
  1639. if not SetCompileMode(more, true) then
  1640. if not SetCompileModeSwitch(more, true) then
  1641. IllegalPara(opt);
  1642. end;
  1643. 'n' :
  1644. begin
  1645. if More='' then
  1646. disable_configfile:=true
  1647. else
  1648. IllegalPara(opt);
  1649. end;
  1650. 'o' :
  1651. begin
  1652. if More<>'' then
  1653. begin
  1654. DefaultReplacements(More);
  1655. D:=ExtractFilePath(More);
  1656. if (D<>'') then
  1657. OutputExeDir:=FixPath(D,True);
  1658. OutputFileName:=ExtractFileName(More);
  1659. end
  1660. else
  1661. IllegalPara(opt);
  1662. end;
  1663. 'O' :
  1664. begin
  1665. j:=1;
  1666. while j<=length(more) do
  1667. begin
  1668. case more[j] of
  1669. '1' :
  1670. init_settings.optimizerswitches:=init_settings.optimizerswitches+level1optimizerswitches;
  1671. '2' :
  1672. init_settings.optimizerswitches:=init_settings.optimizerswitches+level2optimizerswitches;
  1673. '3' :
  1674. init_settings.optimizerswitches:=init_settings.optimizerswitches+level3optimizerswitches;
  1675. '4' :
  1676. init_settings.optimizerswitches:=init_settings.optimizerswitches+level4optimizerswitches;
  1677. 'a' :
  1678. begin
  1679. if not(UpdateAlignmentStr(Copy(Opt,j+3,255),ParaAlignment)) then
  1680. IllegalPara(opt);
  1681. break;
  1682. end;
  1683. 's' :
  1684. include(init_settings.optimizerswitches,cs_opt_size);
  1685. 'p' :
  1686. begin
  1687. if not Setoptimizecputype(copy(more,j+1,length(more)),init_settings.optimizecputype) then
  1688. begin
  1689. OptCPUSetExplicitly:=true;
  1690. { Give warning for old i386 switches }
  1691. if (Length(More)-j=1) and
  1692. (More[j+1]>='1') and (More[j+1]<='5')then
  1693. Message2(option_obsolete_switch_use_new,'-Op<nr>','-Op<name>')
  1694. else
  1695. IllegalPara(opt);
  1696. end;
  1697. break;
  1698. end;
  1699. 'o' :
  1700. begin
  1701. if not UpdateOptimizerStr(copy(more,j+1,length(more)),init_settings.optimizerswitches) then
  1702. IllegalPara(opt);
  1703. break;
  1704. end;
  1705. '-' :
  1706. begin
  1707. init_settings.optimizerswitches:=[];
  1708. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  1709. end;
  1710. { Obsolete switches }
  1711. 'g' :
  1712. Message2(option_obsolete_switch_use_new,'-Og','-Os');
  1713. 'G' :
  1714. Message1(option_obsolete_switch,'-OG');
  1715. 'r' :
  1716. Message2(option_obsolete_switch_use_new,'-Or','-O2 or -Ooregvar');
  1717. 'u' :
  1718. Message2(option_obsolete_switch_use_new,'-Ou','-Oouncertain');
  1719. 'w' :
  1720. begin
  1721. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.dowpoptimizerswitches) then
  1722. IllegalPara(opt);
  1723. break;
  1724. end;
  1725. 'W' :
  1726. begin
  1727. if not UpdateWpoStr(copy(more,j+1,length(more)),init_settings.genwpoptimizerswitches) then
  1728. IllegalPara(opt);
  1729. break;
  1730. end;
  1731. else
  1732. IllegalPara(opt);
  1733. end;
  1734. inc(j);
  1735. end;
  1736. end;
  1737. 'p' :
  1738. begin
  1739. if UnsetBool(More, 0, opt, false) then
  1740. begin
  1741. init_settings.moduleswitches:=init_settings.moduleswitches-[cs_profile];
  1742. undef_system_macro('FPC_PROFILE');
  1743. end
  1744. else
  1745. if Length(More)=0 then
  1746. IllegalPara(opt)
  1747. else
  1748. case more[1] of
  1749. 'g' : if UnsetBool(more, 1, opt, false) then
  1750. begin
  1751. exclude(init_settings.moduleswitches,cs_profile);
  1752. undef_system_macro('FPC_PROFILE');
  1753. end
  1754. else if (target_info.system in supported_targets_pg) then
  1755. begin
  1756. include(init_settings.moduleswitches,cs_profile);
  1757. def_system_macro('FPC_PROFILE');
  1758. end
  1759. else
  1760. UnsupportedPara('-pg');
  1761. else
  1762. IllegalPara(opt);
  1763. end;
  1764. end;
  1765. 'P' : ; { Ignore used by fpc.pp }
  1766. 'R' :
  1767. begin
  1768. if not SetAsmReadMode(More,init_settings.asmmode) then
  1769. IllegalPara(opt);
  1770. end;
  1771. 's' :
  1772. begin
  1773. if UnsetBool(More, 0, opt, false) then
  1774. begin
  1775. init_settings.globalswitches:=init_settings.globalswitches-[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1776. if more<>'' then
  1777. IllegalPara(opt);
  1778. end
  1779. else
  1780. begin
  1781. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_extern,cs_link_extern,cs_link_nolink];
  1782. if more='h' then
  1783. init_settings.globalswitches:=init_settings.globalswitches-[cs_link_on_target]
  1784. else if more='t' then
  1785. init_settings.globalswitches:=init_settings.globalswitches+[cs_link_on_target]
  1786. else if more='r' then
  1787. init_settings.globalswitches:=init_settings.globalswitches+[cs_asm_leave,cs_no_regalloc]
  1788. else if more<>'' then
  1789. IllegalPara(opt);
  1790. end;
  1791. end;
  1792. 'S' :
  1793. begin
  1794. if more='' then
  1795. IllegalPara(opt);
  1796. if more[1]='I' then
  1797. begin
  1798. {$ifdef jvm}
  1799. UnsupportedPara('-SI');
  1800. {$endif}
  1801. if upper(more)='ICOM' then
  1802. init_settings.interfacetype:=it_interfacecom
  1803. else if upper(more)='ICORBA' then
  1804. init_settings.interfacetype:=it_interfacecorba
  1805. else
  1806. IllegalPara(opt);
  1807. end
  1808. else
  1809. begin
  1810. j:=1;
  1811. while j<=length(more) do
  1812. begin
  1813. case more[j] of
  1814. '2' : //an alternative to -Mobjfpc
  1815. SetCompileMode('OBJFPC',true);
  1816. 'a' :
  1817. If UnsetBool(More, j, opt, false) then
  1818. exclude(init_settings.localswitches,cs_do_assertion)
  1819. else
  1820. include(init_settings.localswitches,cs_do_assertion);
  1821. 'c' :
  1822. If UnsetBool(More, j, opt, false) then
  1823. exclude(init_settings.moduleswitches,cs_support_c_operators)
  1824. else
  1825. include(init_settings.moduleswitches,cs_support_c_operators);
  1826. 'd' : //an alternative to -Mdelphi
  1827. SetCompileMode('DELPHI',true);
  1828. 'e' :
  1829. begin
  1830. SetErrorFlags(copy(more,j+1,length(more)));
  1831. break;
  1832. end;
  1833. 'f' :
  1834. begin
  1835. inc(j);
  1836. if more[j]='-' then
  1837. begin
  1838. features:=[];
  1839. if length(more)>j then
  1840. IllegalPara(opt);
  1841. end
  1842. else
  1843. begin
  1844. if (IncludeFeature(upper(copy(more,j,length(more)-j+1)))) then
  1845. j:=length(more)
  1846. else
  1847. IllegalPara(opt);
  1848. end;
  1849. end;
  1850. 'g' :
  1851. If UnsetBool(More, j, opt, false) then
  1852. exclude(init_settings.moduleswitches,cs_support_goto)
  1853. else
  1854. include(init_settings.moduleswitches,cs_support_goto);
  1855. 'h' :
  1856. If UnsetBool(More, j, opt, false) then
  1857. exclude(init_settings.localswitches,cs_refcountedstrings)
  1858. else
  1859. include(init_settings.localswitches,cs_refcountedstrings);
  1860. 'i' :
  1861. If UnsetBool(More, j, opt, false) then
  1862. exclude(init_settings.localswitches,cs_do_inline)
  1863. else
  1864. include(init_settings.localswitches,cs_do_inline);
  1865. 'k' :
  1866. If UnsetBool(More, j, opt, false) then
  1867. exclude(init_settings.globalswitches,cs_load_fpcylix_unit)
  1868. else
  1869. include(init_settings.globalswitches,cs_load_fpcylix_unit);
  1870. 'm' :
  1871. If UnsetBool(More, j, opt, false) then
  1872. exclude(init_settings.moduleswitches,cs_support_macro)
  1873. else
  1874. include(init_settings.moduleswitches,cs_support_macro);
  1875. 'o' : //an alternative to -Mtp
  1876. SetCompileMode('TP',true);
  1877. {$ifdef gpc_mode}
  1878. 'p' : //an alternative to -Mgpc
  1879. SetCompileMode('GPC',true);
  1880. {$endif}
  1881. 's' :
  1882. If UnsetBool(More, j, opt, false) then
  1883. exclude(init_settings.globalswitches,cs_constructor_name)
  1884. else
  1885. include(init_settings.globalswitches,cs_constructor_name);
  1886. 't' :
  1887. Message1(option_obsolete_switch,'-St');
  1888. 'v' :
  1889. If UnsetBool(More, j, opt, false) then
  1890. exclude(init_settings.globalswitches,cs_support_vectors)
  1891. else
  1892. include(init_settings.globalswitches,cs_support_vectors);
  1893. 'x' :
  1894. If UnsetBool(More, j, opt, false) then
  1895. SetCompileModeSwitch('EXCEPTIONS-',true)
  1896. else
  1897. SetCompileModeSwitch('EXCEPTIONS',true);
  1898. 'y' :
  1899. If UnsetBool(More, j, opt, false) then
  1900. exclude(init_settings.localswitches,cs_typed_addresses)
  1901. else
  1902. include(init_settings.localswitches,cs_typed_addresses);
  1903. '-' :
  1904. begin
  1905. init_settings.globalswitches:=init_settings.globalswitches - [cs_constructor_name,cs_support_exceptions,
  1906. cs_support_vectors,cs_load_fpcylix_unit];
  1907. init_settings.localswitches:=init_settings.localswitches - [cs_do_assertion,cs_do_inline, cs_refcountedstrings,
  1908. cs_typed_addresses];
  1909. init_settings.moduleswitches:=init_settings.moduleswitches - [cs_support_c_operators, cs_support_goto,
  1910. cs_support_macro];
  1911. end;
  1912. else
  1913. IllegalPara(opt);
  1914. end;
  1915. inc(j);
  1916. end;
  1917. end;
  1918. end;
  1919. 'T' :
  1920. begin
  1921. more:=Upper(More);
  1922. if paratarget=system_none then
  1923. begin
  1924. { remove old target define }
  1925. TargetOptions(false);
  1926. { load new target }
  1927. paratarget:=find_system_by_string(More);
  1928. if paratarget<>system_none then
  1929. set_target(paratarget)
  1930. else
  1931. IllegalPara(opt);
  1932. { set new define }
  1933. TargetOptions(true);
  1934. end
  1935. else
  1936. if More<>upper(target_info.shortname) then
  1937. Message1(option_target_is_already_set,target_info.shortname);
  1938. end;
  1939. 'u' :
  1940. if is_identifier(more) then
  1941. undef_system_macro(more)
  1942. else
  1943. begin
  1944. if (more='') then
  1945. Message1(option_missing_arg,'-u')
  1946. else
  1947. Message1(option_malformed_para,opt);
  1948. StopOptions(1);
  1949. end;
  1950. 'U' :
  1951. begin
  1952. j:=1;
  1953. while j<=length(more) do
  1954. begin
  1955. case more[j] of
  1956. {$ifdef UNITALIASES}
  1957. 'a' :
  1958. begin
  1959. AddUnitAlias(Copy(More,j+1,255));
  1960. break;
  1961. end;
  1962. {$endif UNITALIASES}
  1963. 'n' :
  1964. exclude(init_settings.globalswitches,cs_check_unit_name);
  1965. 'p' :
  1966. begin
  1967. Message2(option_obsolete_switch_use_new,'-Up','-Fu');
  1968. break;
  1969. end;
  1970. 'r' :
  1971. do_release:=true;
  1972. 's' :
  1973. include(init_settings.moduleswitches,cs_compilesystem);
  1974. '-' :
  1975. begin
  1976. exclude(init_settings.moduleswitches,cs_compilesystem);
  1977. exclude(init_settings.globalswitches,cs_check_unit_name);
  1978. end;
  1979. else
  1980. IllegalPara(opt);
  1981. end;
  1982. inc(j);
  1983. end;
  1984. end;
  1985. 'v' :
  1986. begin
  1987. if not setverbosity(More) then
  1988. IllegalPara(opt);
  1989. end;
  1990. 'V' : ; { Ignore used by fpc }
  1991. 'W' :
  1992. begin
  1993. j:=1;
  1994. while j<=length(More) do
  1995. begin
  1996. case More[j] of
  1997. 'A':
  1998. begin
  1999. if target_info.system in systems_all_windows then
  2000. begin
  2001. if UnsetBool(More, j, opt, false) then
  2002. SetApptype(app_cui)
  2003. else
  2004. SetApptype(app_native);
  2005. end
  2006. else
  2007. IllegalPara(opt);
  2008. end;
  2009. 'b':
  2010. begin
  2011. if target_info.system in systems_darwin then
  2012. begin
  2013. if UnsetBool(More, j, opt, false) then
  2014. SetApptype(app_cui)
  2015. else
  2016. SetApptype(app_bundle)
  2017. end
  2018. else
  2019. IllegalPara(opt);
  2020. end;
  2021. 'B':
  2022. begin
  2023. if target_info.system in systems_all_windows+systems_symbian then
  2024. begin
  2025. { -WB200000 means set trefered base address
  2026. to $200000, but does not change relocsection boolean
  2027. this way we can create both relocatble and
  2028. non relocatable DLL at a specific base address PM }
  2029. if (length(More)>j) then
  2030. begin
  2031. val('$'+Copy(More,j+1,255),imagebase,code);
  2032. if code<>0 then
  2033. IllegalPara(opt);
  2034. ImageBaseSetExplicity:=true;
  2035. end
  2036. else
  2037. begin
  2038. RelocSection:=true;
  2039. RelocSectionSetExplicitly:=true;
  2040. end;
  2041. break;
  2042. end
  2043. else
  2044. IllegalPara(opt);
  2045. end;
  2046. 'C':
  2047. begin
  2048. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2049. begin
  2050. if UnsetBool(More, j, opt, false) then
  2051. SetApptype(app_gui)
  2052. else
  2053. SetApptype(app_cui);
  2054. end
  2055. else
  2056. IllegalPara(opt);
  2057. end;
  2058. 'D':
  2059. begin
  2060. if target_info.system in systems_all_windows then
  2061. begin
  2062. UseDeffileForExports:=not UnsetBool(More, j, opt, false);
  2063. UseDeffileForExportsSetExplicitly:=true;
  2064. end
  2065. else
  2066. IllegalPara(opt);
  2067. end;
  2068. 'e':
  2069. begin
  2070. if (target_info.system in systems_darwin) then
  2071. begin
  2072. RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
  2073. set_target_res(res_ext);
  2074. target_info.resobjext:='.fpcres';
  2075. end
  2076. else
  2077. IllegalPara(opt);
  2078. end;
  2079. 'F':
  2080. begin
  2081. if target_info.system in systems_os2 then
  2082. begin
  2083. if UnsetBool(More, j, opt, false) then
  2084. SetApptype(app_cui)
  2085. else
  2086. SetApptype(app_fs);
  2087. end
  2088. else
  2089. IllegalPara(opt);
  2090. end;
  2091. 'G':
  2092. begin
  2093. if target_info.system in systems_all_windows+systems_os2+systems_macos then
  2094. begin
  2095. if UnsetBool(More, j, opt, false) then
  2096. SetApptype(app_cui)
  2097. else
  2098. SetApptype(app_gui);
  2099. end
  2100. else
  2101. IllegalPara(opt);
  2102. end;
  2103. 'I':
  2104. begin
  2105. if target_info.system in systems_all_windows then
  2106. begin
  2107. GenerateImportSection:=not UnsetBool(More,j,opt,false);
  2108. GenerateImportSectionSetExplicitly:=true;
  2109. end
  2110. else
  2111. IllegalPara(opt);
  2112. end;
  2113. 'i':
  2114. begin
  2115. if (target_info.system in systems_darwin) then
  2116. begin
  2117. set_target_res(res_macho);
  2118. target_info.resobjext:=
  2119. targetinfos[target_info.system]^.resobjext;
  2120. end
  2121. else
  2122. IllegalPara(opt);
  2123. end;
  2124. 'm':
  2125. begin
  2126. {$if defined(i8086)}
  2127. if (target_info.system in [system_i8086_msdos,system_i8086_win16]) then
  2128. begin
  2129. case Upper(Copy(More,j+1,255)) of
  2130. 'TINY': init_settings.x86memorymodel:=mm_tiny;
  2131. 'SMALL': init_settings.x86memorymodel:=mm_small;
  2132. 'MEDIUM': init_settings.x86memorymodel:=mm_medium;
  2133. 'COMPACT': init_settings.x86memorymodel:=mm_compact;
  2134. 'LARGE': init_settings.x86memorymodel:=mm_large;
  2135. 'HUGE': init_settings.x86memorymodel:=mm_huge;
  2136. else
  2137. IllegalPara(opt);
  2138. end;
  2139. break;
  2140. end
  2141. else
  2142. {$endif defined(i8086)}
  2143. IllegalPara(opt);
  2144. end;
  2145. 'M':
  2146. begin
  2147. if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim])) and
  2148. ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
  2149. begin
  2150. break;
  2151. end
  2152. else
  2153. IllegalPara(opt);
  2154. end;
  2155. 'N':
  2156. begin
  2157. if target_info.system in systems_all_windows then
  2158. begin
  2159. RelocSection:=UnsetBool(More,j,opt,false);
  2160. RelocSectionSetExplicitly:=true;
  2161. end
  2162. else
  2163. IllegalPara(opt);
  2164. end;
  2165. 'p':
  2166. begin
  2167. if (target_info.system in systems_embedded) and
  2168. ControllerSupport then
  2169. begin
  2170. s:=upper(copy(more,j+1,length(more)-j));
  2171. if not(SetControllerType(s,init_settings.controllertype)) then
  2172. IllegalPara(opt);
  2173. break;
  2174. end
  2175. else
  2176. IllegalPara(opt);
  2177. end;
  2178. 'P':
  2179. begin
  2180. if (target_info.system in [system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim]) and
  2181. ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
  2182. begin
  2183. break;
  2184. end
  2185. else
  2186. IllegalPara(opt);
  2187. end;
  2188. 'R':
  2189. begin
  2190. if target_info.system in systems_all_windows then
  2191. begin
  2192. { support -WR+ / -WR- as synonyms to -WR / -WN }
  2193. RelocSection:=not UnsetBool(More,j,opt,false);
  2194. RelocSectionSetExplicitly:=true;
  2195. end
  2196. else
  2197. IllegalPara(opt);
  2198. end;
  2199. 't':
  2200. begin
  2201. {$if defined(i8086)}
  2202. if (target_info.system in [system_i8086_msdos]) then
  2203. begin
  2204. case Upper(Copy(More,j+1,255)) of
  2205. 'EXE': SetAppType(app_cui);
  2206. 'COM': SetAppType(app_com);
  2207. else
  2208. IllegalPara(opt);
  2209. end;
  2210. break;
  2211. end
  2212. else
  2213. {$endif defined(i8086)}
  2214. IllegalPara(opt);
  2215. end;
  2216. 'T':
  2217. begin
  2218. if target_info.system in systems_macos then
  2219. begin
  2220. if UnsetBool(More, j, opt, false) then
  2221. SetApptype(app_cui)
  2222. else
  2223. SetApptype(app_tool);
  2224. end
  2225. else
  2226. IllegalPara(opt);
  2227. end;
  2228. 'X':
  2229. begin
  2230. if (target_info.system in systems_linux) then
  2231. begin
  2232. if UnsetBool(More, j, opt, false) then
  2233. exclude(init_settings.moduleswitches,cs_executable_stack)
  2234. else
  2235. include(init_settings.moduleswitches,cs_executable_stack)
  2236. end
  2237. else
  2238. IllegalPara(opt);
  2239. end;
  2240. else
  2241. IllegalPara(opt);
  2242. end;
  2243. inc(j);
  2244. end;
  2245. end;
  2246. 'X' :
  2247. begin
  2248. j:=1;
  2249. while j<=length(more) do
  2250. begin
  2251. case More[j] of
  2252. '9' :
  2253. begin
  2254. if target_info.system in systems_linux then
  2255. begin
  2256. if UnsetBool(More, j, opt, false) then
  2257. exclude(init_settings.globalswitches,cs_link_pre_binutils_2_19)
  2258. else
  2259. include(init_settings.globalswitches,cs_link_pre_binutils_2_19);
  2260. end
  2261. else
  2262. IllegalPara(opt);
  2263. end;
  2264. 'c' : Cshared:=TRUE;
  2265. 'd' : Dontlinkstdlibpath:=TRUE;
  2266. 'e' :
  2267. begin
  2268. If UnsetBool(More, j, opt, false) then
  2269. exclude(init_settings.globalswitches,cs_link_extern)
  2270. else
  2271. include(init_settings.globalswitches,cs_link_extern);
  2272. end;
  2273. 'f' :
  2274. include(init_settings.globalswitches,cs_link_pthread);
  2275. 'g' :
  2276. begin
  2277. If UnsetBool(More, j, opt, false) then
  2278. exclude(init_settings.globalswitches,cs_link_separate_dbg_file)
  2279. else
  2280. include(init_settings.globalswitches,cs_link_separate_dbg_file);
  2281. end;
  2282. 'i' :
  2283. begin
  2284. If UnsetBool(More, j, opt, false) then
  2285. include(init_settings.globalswitches,cs_link_extern)
  2286. else
  2287. exclude(init_settings.globalswitches,cs_link_extern);
  2288. end;
  2289. 'n' :
  2290. begin
  2291. If UnsetBool(More, j, opt, false) then
  2292. exclude(init_settings.globalswitches,cs_link_native)
  2293. else
  2294. include(init_settings.globalswitches,cs_link_native);
  2295. end;
  2296. 'm' :
  2297. begin
  2298. If UnsetBool(More, j, opt, false) then
  2299. exclude(init_settings.globalswitches,cs_link_map)
  2300. else
  2301. include(init_settings.globalswitches,cs_link_map);
  2302. end;
  2303. 'p' : ; { Ignore used by fpc.pp }
  2304. 'r' :
  2305. begin
  2306. if (target_info.system in suppported_targets_x_smallr) then
  2307. begin
  2308. rlinkpath:=Copy(more,2,length(More)-1);
  2309. DefaultReplacements(rlinkpath);
  2310. end
  2311. else
  2312. IgnoredPara('-Xr');
  2313. more:='';
  2314. end;
  2315. 'R' :
  2316. begin
  2317. sysrootpath:=copy(more,2,length(more)-1);
  2318. defaultreplacements(sysrootpath);
  2319. more:='';
  2320. end;
  2321. 's' :
  2322. begin
  2323. If UnsetBool(More, j, opt, false) then
  2324. exclude(init_settings.globalswitches,cs_link_strip)
  2325. else
  2326. include(init_settings.globalswitches,cs_link_strip);
  2327. end;
  2328. 't' :
  2329. include(init_settings.globalswitches,cs_link_staticflag);
  2330. 'v' :
  2331. begin
  2332. If UnsetBool(More, j, opt, false) then
  2333. exclude(init_settings.globalswitches,cs_link_opt_vtable)
  2334. else
  2335. include(init_settings.globalswitches,cs_link_opt_vtable);
  2336. end;
  2337. 'D' :
  2338. begin
  2339. def_system_macro('FPC_LINK_DYNAMIC');
  2340. undef_system_macro('FPC_LINK_SMART');
  2341. undef_system_macro('FPC_LINK_STATIC');
  2342. exclude(init_settings.globalswitches,cs_link_static);
  2343. exclude(init_settings.globalswitches,cs_link_smart);
  2344. include(init_settings.globalswitches,cs_link_shared);
  2345. LinkTypeSetExplicitly:=true;
  2346. end;
  2347. 'M' :
  2348. begin
  2349. mainaliasname:=Copy(more,2,length(More)-1);
  2350. More:='';
  2351. end;
  2352. 'P' :
  2353. begin
  2354. utilsprefix:=Copy(more,2,length(More)-1);
  2355. DefaultReplacements(utilsprefix);
  2356. More:='';
  2357. end;
  2358. 'L' : begin // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
  2359. // these are not aggregable.
  2360. if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
  2361. IllegalPara(opt)
  2362. else
  2363. begin
  2364. case more[j+1] of
  2365. 'A' : begin
  2366. s:=Copy(more,3,length(More)-2);
  2367. if not LinkLibraryAliases.AddDep(s) Then
  2368. IllegalPara(opt);
  2369. end;
  2370. 'O' : begin
  2371. s:=Copy(more,3,length(More)-2);
  2372. if not LinkLibraryOrder.AddWeight(s) Then
  2373. IllegalPara(opt);
  2374. end;
  2375. 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
  2376. else
  2377. IllegalPara(opt);
  2378. end; {case}
  2379. j:=length(more);
  2380. end; {else begin}
  2381. end;
  2382. 'S' :
  2383. begin
  2384. ForceStaticLinking;
  2385. end;
  2386. 'X' :
  2387. begin
  2388. def_system_macro('FPC_LINK_SMART');
  2389. undef_system_macro('FPC_LINK_STATIC');
  2390. undef_system_macro('FPC_LINK_DYNAMIC');
  2391. exclude(init_settings.globalswitches,cs_link_static);
  2392. include(init_settings.globalswitches,cs_link_smart);
  2393. exclude(init_settings.globalswitches,cs_link_shared);
  2394. LinkTypeSetExplicitly:=true;
  2395. end;
  2396. '-' :
  2397. begin
  2398. exclude(init_settings.globalswitches,cs_link_staticflag);
  2399. exclude(init_settings.globalswitches,cs_link_strip);
  2400. exclude(init_settings.globalswitches,cs_link_map);
  2401. set_default_link_type;
  2402. end;
  2403. else
  2404. IllegalPara(opt);
  2405. end;
  2406. inc(j);
  2407. end;
  2408. end;
  2409. else
  2410. IllegalPara(opt);
  2411. end;
  2412. end;
  2413. '@' :
  2414. begin
  2415. Message(option_no_nested_response_file);
  2416. StopOptions(1);
  2417. end;
  2418. else
  2419. begin
  2420. if (length(param_file)<>0) then
  2421. Message2(option_only_one_source_support,param_file,opt);
  2422. param_file:=opt;
  2423. Message1(option_found_file,opt);
  2424. end;
  2425. end;
  2426. end;
  2427. procedure Toption.Interpret_file(const filename : TPathStr);
  2428. procedure RemoveSep(var fn:TPathStr);
  2429. var
  2430. i : longint;
  2431. begin
  2432. i:=0;
  2433. while (i<length(fn)) and (fn[i+1] in [',',' ',#9]) do
  2434. inc(i);
  2435. Delete(fn,1,i);
  2436. i:=length(fn);
  2437. while (i>0) and (fn[i] in [',',' ',#9]) do
  2438. dec(i);
  2439. fn:=copy(fn,1,i);
  2440. end;
  2441. function GetName(var fn:TPathStr):TPathStr;
  2442. var
  2443. i : longint;
  2444. begin
  2445. i:=0;
  2446. while (i<length(fn)) and (fn[i+1] in ['a'..'z','A'..'Z','0'..'9','_','-']) do
  2447. inc(i);
  2448. GetName:=Copy(fn,1,i);
  2449. Delete(fn,1,i);
  2450. end;
  2451. const
  2452. maxlevel = 15;
  2453. var
  2454. f : text;
  2455. s, tmp,
  2456. opts : TCmdStr;
  2457. skip : array[0..maxlevel] of boolean;
  2458. line,
  2459. level : longint;
  2460. option_read : boolean;
  2461. oldfilemode : byte;
  2462. ConfigFile: TPathStr;
  2463. begin
  2464. { avoid infinite loop }
  2465. Inc(FileLevel);
  2466. Option_read:=false;
  2467. If FileLevel>MaxLevel then
  2468. Message(option_too_many_cfg_files);
  2469. if not ParaIncludeCfgPath.FindFile(fileName,true,ConfigFile) then
  2470. ConfigFile := ExpandFileName(filename);
  2471. { Maybe It's Directory ?} //Jaro Change:
  2472. if PathExists(ConfigFile,false) then
  2473. begin
  2474. Message1(option_config_is_dir,filename);
  2475. exit;
  2476. end;
  2477. { open file }
  2478. Message1(option_using_file,filename);
  2479. oldfilemode:=filemode;
  2480. filemode:=0;
  2481. assign(f,ConfigFile);
  2482. {$push}{$I-}
  2483. reset(f);
  2484. {$pop}
  2485. filemode:=oldfilemode;
  2486. if ioresult<>0 then
  2487. begin
  2488. Message1(option_unable_open_file,filename);
  2489. exit;
  2490. end;
  2491. Message1(option_start_reading_configfile,filename);
  2492. fillchar(skip,sizeof(skip),0);
  2493. level:=0;
  2494. line:=0;
  2495. while not eof(f) do
  2496. begin
  2497. readln(f,opts);
  2498. inc(line);
  2499. RemoveSep(opts);
  2500. if (opts<>'') and (opts[1]<>';') then
  2501. begin
  2502. if opts[1]='#' then
  2503. begin
  2504. Message1(option_interpreting_file_option,opts);
  2505. Delete(opts,1,1);
  2506. s:=upper(GetName(opts));
  2507. if (s='SECTION') then
  2508. begin
  2509. RemoveSep(opts);
  2510. s:=upper(GetName(opts));
  2511. if level=0 then
  2512. skip[level]:=not defined_macro(s) or (s='COMMON');
  2513. end
  2514. else
  2515. if (s='IFDEF') then
  2516. begin
  2517. RemoveSep(opts);
  2518. if Level>=maxlevel then
  2519. begin
  2520. Message2(option_too_many_ifdef,filename,tostr(line));
  2521. stopOptions(1);
  2522. end;
  2523. inc(Level);
  2524. skip[level]:=(skip[level-1] or not defined_macro(upper(GetName(opts))));
  2525. end
  2526. else
  2527. if (s='IFNDEF') then
  2528. begin
  2529. RemoveSep(opts);
  2530. if Level>=maxlevel then
  2531. begin
  2532. Message2(option_too_many_ifdef,filename,tostr(line));
  2533. stopOptions(1);
  2534. end;
  2535. inc(Level);
  2536. skip[level]:=(skip[level-1] or defined_macro(upper(GetName(opts))));
  2537. end
  2538. else
  2539. if (s='ELSE') then
  2540. begin
  2541. if Level=0 then
  2542. begin
  2543. Message2(option_else_without_if,filename,tostr(line));
  2544. stopOptions(1);
  2545. end
  2546. else
  2547. skip[level]:=skip[level-1] or (not skip[level])
  2548. end
  2549. else
  2550. if (s='ENDIF') then
  2551. begin
  2552. skip[level]:=false;
  2553. if Level=0 then
  2554. begin
  2555. Message2(option_too_many_endif,filename,tostr(line));
  2556. stopOptions(1);
  2557. end;
  2558. dec(level);
  2559. end
  2560. else
  2561. if (not skip[level]) then
  2562. begin
  2563. if (s='DEFINE') then
  2564. begin
  2565. RemoveSep(opts);
  2566. tmp:= GetName(opts);
  2567. if tmp <> '' then
  2568. def_system_macro(tmp);
  2569. Option_read:=true;
  2570. end
  2571. else
  2572. if (s='UNDEF') then
  2573. begin
  2574. RemoveSep(opts);
  2575. tmp:= GetName(opts);
  2576. if tmp <> '' then
  2577. undef_system_macro(tmp);
  2578. Option_read:=true;
  2579. end
  2580. else
  2581. if (s='WRITE') then
  2582. begin
  2583. Delete(opts,1,1);
  2584. DefaultReplacements(opts);
  2585. WriteLn(opts);
  2586. Option_read:=true;
  2587. end
  2588. else
  2589. if (s='INCLUDE') then
  2590. begin
  2591. Delete(opts,1,1);
  2592. DefaultReplacements(opts);
  2593. Interpret_file(opts);
  2594. Option_read:=true;
  2595. end
  2596. else
  2597. if (s='CFGDIR') then
  2598. begin
  2599. Delete(opts,1,1);
  2600. DefaultReplacements(opts);
  2601. ParaIncludeCfgPath.AddPath(opts,false);
  2602. Option_read:=true;
  2603. end;
  2604. end;
  2605. end
  2606. else
  2607. begin
  2608. if (opts[1]='-') or (opts[1]='@') then
  2609. begin
  2610. if (not skip[level]) then
  2611. interpret_option(opts,false);
  2612. Option_read:=true;
  2613. end
  2614. else
  2615. Message1(option_illegal_para,opts);
  2616. end;
  2617. end;
  2618. end;
  2619. if Level>0 then
  2620. Message(option_too_less_endif);
  2621. if Not Option_read then
  2622. Message1(option_no_option_found,filename)
  2623. else
  2624. Message1(option_end_reading_configfile,filename);
  2625. Close(f);
  2626. Dec(FileLevel);
  2627. end;
  2628. procedure Toption.Interpret_envvar(const envname : TCmdStr);
  2629. var
  2630. argstart,
  2631. env,
  2632. pc : pchar;
  2633. arglen : longint;
  2634. quote : set of char;
  2635. hs : TCmdStr;
  2636. begin
  2637. Message1(option_using_env,envname);
  2638. env:=GetEnvPChar(envname);
  2639. pc:=env;
  2640. if assigned(pc) then
  2641. begin
  2642. repeat
  2643. { skip leading spaces }
  2644. while pc^ in [' ',#9,#13] do
  2645. inc(pc);
  2646. case pc^ of
  2647. #0 :
  2648. break;
  2649. '"' :
  2650. begin
  2651. quote:=['"'];
  2652. inc(pc);
  2653. end;
  2654. '''' :
  2655. begin
  2656. quote:=[''''];
  2657. inc(pc);
  2658. end;
  2659. else
  2660. quote:=[' ',#9,#13];
  2661. end;
  2662. { scan until the end of the argument }
  2663. argstart:=pc;
  2664. while (pc^<>#0) and not(pc^ in quote) do
  2665. inc(pc);
  2666. { create argument }
  2667. arglen:=pc-argstart;
  2668. { TODO: FIXME: silent truncation of environment parameters }
  2669. if (arglen > 255) then
  2670. arglen := 255;
  2671. setlength(hs,arglen);
  2672. move(argstart^,hs[1],arglen);
  2673. interpret_option(hs,true);
  2674. { skip quote }
  2675. if pc^ in quote then
  2676. inc(pc);
  2677. until false;
  2678. end
  2679. else
  2680. Message1(option_no_option_found,'(env) '+envname);
  2681. FreeEnvPChar(env);
  2682. end;
  2683. procedure toption.read_parameters;
  2684. var
  2685. opts : TCmdStr;
  2686. paramindex : longint;
  2687. begin
  2688. paramindex:=0;
  2689. while paramindex<paramcount do
  2690. begin
  2691. inc(paramindex);
  2692. opts:=objpas.paramstr(paramindex);
  2693. if length(opts)>0 then
  2694. case opts[1] of
  2695. '@' :
  2696. if not firstpass then
  2697. begin
  2698. Delete(opts,1,1);
  2699. Message1(option_reading_further_from,opts);
  2700. interpret_file(opts);
  2701. end;
  2702. '!' :
  2703. if not firstpass then
  2704. begin
  2705. Delete(opts,1,1);
  2706. Message1(option_reading_further_from,'(env) '+opts);
  2707. interpret_envvar(opts);
  2708. end;
  2709. else
  2710. interpret_option(opts,true);
  2711. end;
  2712. end;
  2713. end;
  2714. procedure toption.parsecmd(cmd:TCmdStr);
  2715. var
  2716. i,ps : longint;
  2717. opts : TCmdStr;
  2718. begin
  2719. while (cmd<>'') do
  2720. begin
  2721. while cmd[1]=' ' do
  2722. delete(cmd,1,1);
  2723. i:=pos(' ',cmd);
  2724. if i=0 then
  2725. i:=2147483647;
  2726. opts:=Copy(cmd,1,i-1);
  2727. Delete(cmd,1,i);
  2728. case opts[1] of
  2729. '@' :
  2730. if not firstpass then
  2731. begin
  2732. Delete(opts,1,1);
  2733. Message1(option_reading_further_from,opts);
  2734. interpret_file(opts);
  2735. end;
  2736. '!' :
  2737. if not firstpass then
  2738. begin
  2739. Delete(opts,1,1);
  2740. Message1(option_reading_further_from,'(env) '+opts);
  2741. interpret_envvar(opts);
  2742. end;
  2743. '"' :
  2744. begin
  2745. Delete(opts,1,1);
  2746. ps:=pos('"',cmd);
  2747. if (i<>256) and (ps>0) then
  2748. begin
  2749. opts:=opts + ' '+ copy(cmd,1,ps-1);
  2750. cmd:=copy(cmd,ps+1,255);
  2751. end;
  2752. interpret_option(opts,true);
  2753. end;
  2754. else
  2755. interpret_option(opts,true);
  2756. end;
  2757. end;
  2758. end;
  2759. procedure toption.writequickinfo;
  2760. var
  2761. s : string;
  2762. i : longint;
  2763. procedure addinfo(const hs:string);
  2764. begin
  2765. if s<>'' then
  2766. s:=s+' '+hs
  2767. else
  2768. s:=hs;
  2769. end;
  2770. begin
  2771. s:='';
  2772. i:=0;
  2773. while (i<length(quickinfo)) do
  2774. begin
  2775. inc(i);
  2776. case quickinfo[i] of
  2777. 'S' :
  2778. begin
  2779. inc(i);
  2780. case quickinfo[i] of
  2781. 'O' :
  2782. addinfo(lower(source_info.shortname));
  2783. 'P' :
  2784. addinfo(source_cpu_string);
  2785. else
  2786. IllegalPara('-i'+QuickInfo);
  2787. end;
  2788. end;
  2789. 'T' :
  2790. begin
  2791. inc(i);
  2792. case quickinfo[i] of
  2793. 'O' :
  2794. addinfo(lower(target_info.shortname));
  2795. 'P' :
  2796. AddInfo(target_cpu_string);
  2797. else
  2798. IllegalPara('-i'+QuickInfo);
  2799. end;
  2800. end;
  2801. 'V' :
  2802. AddInfo(version_string);
  2803. 'W' :
  2804. AddInfo(full_version_string);
  2805. 'D' :
  2806. AddInfo(date_string);
  2807. '_' :
  2808. ;
  2809. else
  2810. IllegalPara('-i'+QuickInfo);
  2811. end;
  2812. end;
  2813. if s<>'' then
  2814. begin
  2815. writeln(s);
  2816. stopoptions(0);
  2817. end;
  2818. end;
  2819. procedure TOption.TargetOptions(def:boolean);
  2820. var
  2821. s : string;
  2822. i : integer;
  2823. target_unsup_features : tfeatures;
  2824. begin
  2825. if def then
  2826. def_system_macro(target_info.shortname)
  2827. else
  2828. undef_system_macro(target_info.shortname);
  2829. s:=target_info.extradefines;
  2830. while (s<>'') do
  2831. begin
  2832. i:=pos(';',s);
  2833. if i=0 then
  2834. i:=length(s)+1;
  2835. if def then
  2836. def_system_macro(Copy(s,1,i-1))
  2837. else
  2838. undef_system_macro(Copy(s,1,i-1));
  2839. delete(s,1,i);
  2840. end;
  2841. if (tf_winlikewidestring in target_info.flags) then
  2842. if def then
  2843. def_system_macro('FPC_WINLIKEWIDESTRING')
  2844. else
  2845. undef_system_macro('FPC_WINLIKEWIDESTRING');
  2846. if (tf_requires_proper_alignment in target_info.flags) then
  2847. if def then
  2848. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT')
  2849. else
  2850. undef_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  2851. if source_info.system<>target_info.system then
  2852. if def then
  2853. def_system_macro('FPC_CROSSCOMPILING')
  2854. else
  2855. undef_system_macro('FPC_CROSSCOMPILING');
  2856. if source_info.cpu<>target_info.cpu then
  2857. if def then
  2858. def_system_macro('FPC_CPUCROSSCOMPILING')
  2859. else
  2860. def_system_macro('FPC_CPUCROSSCOMPILING');
  2861. if (tf_no_generic_stackcheck in target_info.flags) then
  2862. if def then
  2863. def_system_macro('FPC_NO_GENERIC_STACK_CHECK')
  2864. else
  2865. undef_system_macro('FPC_NO_GENERIC_STACK_CHECK');
  2866. if (tf_section_threadvars in target_info.flags) then
  2867. if def then
  2868. def_system_macro('FPC_SECTION_THREADVARS')
  2869. else
  2870. undef_system_macro('FPC_SECTION_THREADVARS');
  2871. { Code generation flags }
  2872. if (tf_pic_default in target_info.flags) then
  2873. if def then
  2874. include(init_settings.moduleswitches,cs_create_pic)
  2875. else
  2876. exclude(init_settings.moduleswitches,cs_create_pic);
  2877. { Resources support }
  2878. if (tf_has_winlike_resources in target_info.flags) then
  2879. if def then
  2880. def_system_macro('FPC_HAS_WINLIKERESOURCES')
  2881. else
  2882. undef_system_macro('FPC_HAS_WINLIKERESOURCES');
  2883. { Features }
  2884. case target_info.system of
  2885. system_arm_gba:
  2886. target_unsup_features:=[f_dynlibs];
  2887. system_arm_nds:
  2888. target_unsup_features:=[f_threading,f_commandargs,f_fileio,f_textio,f_consoleio,f_dynlibs];
  2889. system_i386_nativent:
  2890. // until these features are implemented, they are disabled in the compiler
  2891. target_unsup_features:=[f_stackcheck];
  2892. system_jvm_java32,
  2893. system_jvm_android32:
  2894. target_unsup_features:=[f_heap,f_textio,f_consoleio,f_fileio,
  2895. f_variants,f_objects,f_commandargs,
  2896. f_processes,f_stackcheck,f_dynlibs,f_softfpu,f_objectivec1,f_resources];
  2897. else
  2898. target_unsup_features:=[];
  2899. end;
  2900. if def then
  2901. features:=features-target_unsup_features
  2902. else
  2903. features:=features+target_unsup_features;
  2904. end;
  2905. procedure TOption.checkoptionscompatibility;
  2906. begin
  2907. {$ifdef i8086}
  2908. if (apptype=app_com) and (init_settings.x86memorymodel<>mm_tiny) then
  2909. begin
  2910. Message(option_com_files_require_tiny_model);
  2911. StopOptions(1);
  2912. end;
  2913. {$endif i8086}
  2914. if (paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) and
  2915. not(target_info.system in (systems_darwin+[system_i8086_msdos])) then
  2916. begin
  2917. { smartlink creation does not yet work with DWARF
  2918. debug info on most targets, but it works in internal assembler }
  2919. if (cs_create_smart in init_settings.moduleswitches) and
  2920. not (af_outputbinary in target_asm.flags) then
  2921. begin
  2922. Message(option_dwarf_smartlink_creation);
  2923. exclude(init_settings.moduleswitches,cs_create_smart);
  2924. end;
  2925. { smart linking does not yet work with DWARF debug info on most targets }
  2926. if (cs_link_smart in init_settings.globalswitches) then
  2927. begin
  2928. Message(option_dwarf_smart_linking);
  2929. ForceStaticLinking;
  2930. end;
  2931. end;
  2932. { external debug info is only supported for DWARF on darwin }
  2933. if (target_info.system in systems_darwin) and
  2934. (cs_link_separate_dbg_file in init_settings.globalswitches) and
  2935. not(paratargetdbg in [dbg_dwarf2,dbg_dwarf3]) then
  2936. begin
  2937. Message(option_debug_external_unsupported);
  2938. exclude(init_settings.globalswitches,cs_link_separate_dbg_file);
  2939. end;
  2940. { Also create a smartlinked version, on an assembler that
  2941. does not support smartlink sections like nasm?
  2942. This is not compatible with using internal linker. }
  2943. if ((cs_link_smart in init_settings.globalswitches) or
  2944. (cs_create_smart in init_settings.moduleswitches)) and
  2945. (af_needar in target_asm.flags) and
  2946. not (af_smartlink_sections in target_asm.flags) and
  2947. not (cs_link_extern in init_settings.globalswitches) and
  2948. (target_info.link<>ld_none) and
  2949. not (cs_link_nolink in init_settings.globalswitches) then
  2950. begin
  2951. Message(option_smart_link_requires_external_linker);
  2952. include(init_settings.globalswitches,cs_link_extern);
  2953. end;
  2954. end;
  2955. constructor TOption.create;
  2956. begin
  2957. LogoWritten:=false;
  2958. NoPressEnter:=false;
  2959. FirstPass:=false;
  2960. ABISetExplicitly:=false;
  2961. FPUSetExplicitly:=false;
  2962. CPUSetExplicitly:=false;
  2963. OptCPUSetExplicitly:=false;
  2964. FileLevel:=0;
  2965. Quickinfo:='';
  2966. ParaIncludeCfgPath:=TSearchPathList.Create;
  2967. ParaIncludePath:=TSearchPathList.Create;
  2968. ParaObjectPath:=TSearchPathList.Create;
  2969. ParaUnitPath:=TSearchPathList.Create;
  2970. ParaLibraryPath:=TSearchPathList.Create;
  2971. ParaFrameworkPath:=TSearchPathList.Create;
  2972. FillChar(ParaAlignment,sizeof(ParaAlignment),0);
  2973. MacVersionSet:=false;
  2974. paratarget:=system_none;
  2975. paratargetasm:=as_none;
  2976. paratargetdbg:=dbg_none;
  2977. LinkTypeSetExplicitly:=false;
  2978. end;
  2979. destructor TOption.destroy;
  2980. begin
  2981. ParaIncludeCfgPath.Free;
  2982. ParaIncludePath.Free;
  2983. ParaObjectPath.Free;
  2984. ParaUnitPath.Free;
  2985. ParaLibraryPath.Free;
  2986. ParaFrameworkPath.Free;
  2987. end;
  2988. {****************************************************************************
  2989. Callable Routines
  2990. ****************************************************************************}
  2991. function check_configfile(const fn:string;var foundfn:string):boolean;
  2992. function CfgFileExists(const fn:string):boolean;
  2993. begin
  2994. Comment(V_Tried,'Configfile search: '+fn);
  2995. CfgFileExists:=FileExists(fn);
  2996. end;
  2997. var
  2998. {$ifdef Unix}
  2999. hs,
  3000. {$endif Unix}
  3001. configpath : string;
  3002. begin
  3003. foundfn:=fn;
  3004. check_configfile:=true;
  3005. { retrieve configpath }
  3006. configpath:=FixPath(GetEnvironmentVariable('PPC_CONFIG_PATH'),false);
  3007. {$ifdef Unix}
  3008. if configpath='' then
  3009. configpath:=ExpandFileName(FixPath(exepath+'../etc/',false));
  3010. {$endif}
  3011. {
  3012. Order to read configuration file :
  3013. try reading fpc.cfg in :
  3014. 1 - current dir
  3015. 2 - configpath
  3016. 3 - compiler path
  3017. }
  3018. if not FileExists(fn) then
  3019. begin
  3020. {$ifdef Unix}
  3021. hs:=GetEnvironmentVariable('HOME');
  3022. if (hs<>'') and CfgFileExists(FixPath(hs,false)+'.'+fn) then
  3023. foundfn:=FixPath(hs,false)+'.'+fn
  3024. else
  3025. {$endif}
  3026. if CfgFileExists(configpath+fn) then
  3027. foundfn:=configpath+fn
  3028. else
  3029. {$ifdef WINDOWS}
  3030. if (GetEnvironmentVariable('USERPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn) then
  3031. foundfn:=FixPath(GetEnvironmentVariable('USERPROFILE'),false)+fn
  3032. else
  3033. if (GetEnvironmentVariable('ALLUSERSPROFILE')<>'') and CfgFileExists(FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn) then
  3034. foundfn:=FixPath(GetEnvironmentVariable('ALLUSERSPROFILE'),false)+fn
  3035. else
  3036. {$endif WINDOWS}
  3037. {$ifndef Unix}
  3038. if CfgFileExists(exepath+fn) then
  3039. foundfn:=exepath+fn
  3040. else
  3041. {$else}
  3042. if CfgFileExists('/etc/'+fn) then
  3043. foundfn:='/etc/'+fn
  3044. else
  3045. {$endif}
  3046. check_configfile:=false;
  3047. end;
  3048. end;
  3049. procedure read_arguments(cmd:TCmdStr);
  3050. var
  3051. env: ansistring;
  3052. i : tfeature;
  3053. abi : tabi;
  3054. {$if defined(cpucapabilities)}
  3055. cpuflag : tcpuflags;
  3056. hs : string;
  3057. {$endif defined(cpucapabilities)}
  3058. begin
  3059. option:=coption.create;
  3060. disable_configfile:=false;
  3061. { Non-core target defines }
  3062. Option.TargetOptions(true);
  3063. { get default messagefile }
  3064. msgfilename:=GetEnvironmentVariable('PPC_ERROR_FILE');
  3065. { default configfile can be specified on the commandline,
  3066. remove it first }
  3067. if (cmd<>'') and (cmd[1]='[') then
  3068. begin
  3069. ppccfg:=Copy(cmd,2,pos(']',cmd)-2);
  3070. Delete(cmd,1,pos(']',cmd));
  3071. end
  3072. else
  3073. ppccfg:='fpc.cfg';
  3074. { first pass reading of parameters, only -i -v -T etc.}
  3075. option.firstpass:=true;
  3076. if cmd<>'' then
  3077. option.parsecmd(cmd)
  3078. else
  3079. begin
  3080. option.read_parameters;
  3081. { Write only quickinfo }
  3082. if option.quickinfo<>'' then
  3083. option.writequickinfo;
  3084. end;
  3085. option.firstpass:=false;
  3086. { redefine target options so all defines are written even if no -Txxx is passed on the command line }
  3087. Option.TargetOptions(true);
  3088. { target is set here, for wince the default app type is gui }
  3089. if target_info.system in systems_wince then
  3090. SetApptype(app_gui)
  3091. else
  3092. SetApptype(apptype);
  3093. { default defines }
  3094. def_system_macro(target_info.shortname);
  3095. def_system_macro('FPC');
  3096. def_system_macro('VER'+version_nr);
  3097. def_system_macro('VER'+version_nr+'_'+release_nr);
  3098. def_system_macro('VER'+version_nr+'_'+release_nr+'_'+patch_nr);
  3099. { Temporary defines, until things settle down }
  3100. def_system_macro('FPC_HAS_OPERATOR_ENUMERATOR');
  3101. def_system_macro('FPC_HAS_CONSTREF');
  3102. def_system_macro('FPC_STATICRIPFIXED');
  3103. def_system_macro('FPC_VARIANTCOPY_FIXED');
  3104. def_system_macro('FPC_DYNARRAYCOPY_FIXED');
  3105. { abs(long) is handled internally on all CPUs }
  3106. def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
  3107. {$if defined(x86_64) or defined(powerpc64) or defined(cpuaarch64)}
  3108. def_system_macro('FPC_HAS_INTERNAL_ABS_INT64');
  3109. {$endif x86_64 or powerpc64 or aarch64}
  3110. def_system_macro('FPC_HAS_UNICODESTRING');
  3111. def_system_macro('FPC_RTTI_PACKSET1');
  3112. def_system_macro('FPC_HAS_CPSTRING');
  3113. {$ifdef x86_64}
  3114. def_system_macro('FPC_HAS_RIP_RELATIVE');
  3115. {$endif x86_64}
  3116. def_system_macro('FPC_HAS_CEXTENDED');
  3117. def_system_macro('FPC_HAS_RESSTRINITS');
  3118. { these cpus have an inline rol/ror implementaion }
  3119. {$ifdef cpurox}
  3120. def_system_macro('FPC_HAS_INTERNAL_ROX');
  3121. {$endif}
  3122. { these cpus have an inline sar implementaion }
  3123. { currently, all supported CPUs have an internal sar implementation }
  3124. { $if defined(x86) or defined(arm) or defined(powerpc) or defined(powerpc64) or defined(sparc) or defined(mips)}
  3125. def_system_macro('FPC_HAS_INTERNAL_SAR');
  3126. { $endif}
  3127. {$ifdef powerpc64}
  3128. def_system_macro('FPC_HAS_LWSYNC');
  3129. {$endif}
  3130. def_system_macro('FPC_HAS_MEMBAR');
  3131. def_system_macro('FPC_SETBASE_USED');
  3132. {$ifdef SUPPORT_GET_FRAME}
  3133. def_system_macro('INTERNAL_BACKTRACE');
  3134. {$endif SUPPORT_GET_FRAME}
  3135. def_system_macro('STR_CONCAT_PROCS');
  3136. {$warnings off}
  3137. if pocall_default = pocall_register then
  3138. def_system_macro('REGCALL');
  3139. {$warnings on}
  3140. { don't remove this, it's also for fpdoc necessary (FK) }
  3141. def_system_macro('FPC_HAS_FEATURE_SUPPORT');
  3142. { using a case is pretty useless here (FK) }
  3143. { some stuff for TP compatibility }
  3144. {$ifdef i386}
  3145. def_system_macro('CPU86');
  3146. def_system_macro('CPU87');
  3147. def_system_macro('CPU386');
  3148. {$endif}
  3149. { new processor stuff }
  3150. {$ifdef i386}
  3151. def_system_macro('CPUI386');
  3152. def_system_macro('CPU32');
  3153. def_system_macro('CPUX86');
  3154. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3155. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3156. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3157. {$endif}
  3158. {$ifdef m68k}
  3159. def_system_macro('CPU68');
  3160. def_system_macro('CPU68K');
  3161. def_system_macro('CPUM68K');
  3162. def_system_macro('CPU32');
  3163. def_system_macro('FPC_CURRENCY_IS_INT64');
  3164. def_system_macro('FPC_COMP_IS_INT64');
  3165. {$endif}
  3166. {$ifdef powerpc}
  3167. def_system_macro('CPUPOWERPC');
  3168. def_system_macro('CPUPOWERPC32');
  3169. def_system_macro('CPU32');
  3170. def_system_macro('FPC_CURRENCY_IS_INT64');
  3171. def_system_macro('FPC_COMP_IS_INT64');
  3172. {$endif}
  3173. {$ifdef POWERPC64}
  3174. def_system_macro('CPUPOWERPC');
  3175. def_system_macro('CPUPOWERPC64');
  3176. def_system_macro('CPU64');
  3177. def_system_macro('FPC_CURRENCY_IS_INT64');
  3178. def_system_macro('FPC_COMP_IS_INT64');
  3179. {$endif}
  3180. {$ifdef x86_64}
  3181. def_system_macro('CPUX86_64');
  3182. def_system_macro('CPUAMD64');
  3183. def_system_macro('CPU64');
  3184. def_system_macro('CPUX64');
  3185. { not supported for now, afaik (FK)
  3186. def_system_macro('FPC_HAS_TYPE_FLOAT128'); }
  3187. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3188. { normally, win64 doesn't support the legacy fpu }
  3189. if target_info.system=system_x86_64_win64 then
  3190. begin
  3191. def_system_macro('FPC_CURRENCY_IS_INT64');
  3192. def_system_macro('FPC_COMP_IS_INT64');
  3193. end;
  3194. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3195. {$endif}
  3196. {$ifdef sparc}
  3197. def_system_macro('CPUSPARC');
  3198. def_system_macro('CPUSPARC32');
  3199. def_system_macro('CPU32');
  3200. def_system_macro('FPC_CURRENCY_IS_INT64');
  3201. def_system_macro('FPC_COMP_IS_INT64');
  3202. {$endif}
  3203. {$ifdef arm}
  3204. def_system_macro('CPUARM');
  3205. def_system_macro('CPU32');
  3206. def_system_macro('FPC_CURRENCY_IS_INT64');
  3207. def_system_macro('FPC_COMP_IS_INT64');
  3208. {$endif arm}
  3209. {$ifdef avr}
  3210. def_system_macro('CPUAVR');
  3211. def_system_macro('CPU16');
  3212. def_system_macro('FPC_CURRENCY_IS_INT64');
  3213. def_system_macro('FPC_COMP_IS_INT64');
  3214. {$endif avr}
  3215. {$ifdef jvm}
  3216. def_system_macro('CPUJVM');
  3217. def_system_macro('CPU32');
  3218. def_system_macro('FPC_CURRENCY_IS_INT64');
  3219. def_system_macro('FPC_COMP_IS_INT64');
  3220. {$endif jvm}
  3221. {$ifdef mipsel}
  3222. def_system_macro('CPUMIPS');
  3223. def_system_macro('CPUMIPS32');
  3224. def_system_macro('CPUMIPSEL');
  3225. def_system_macro('CPUMIPSEL32');
  3226. def_system_macro('CPU32');
  3227. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3228. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3229. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3230. def_system_macro('FPC_CURRENCY_IS_INT64');
  3231. def_system_macro('FPC_COMP_IS_INT64');
  3232. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3233. { On most systems, locals are accessed relative to base pointer,
  3234. but for MIPS cpu, they are accessed relative to stack pointer.
  3235. This needs adaptation for so low level routines,
  3236. like MethodPointerLocal and related objects unit functions. }
  3237. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3238. {$endif mipsel}
  3239. {$ifdef mipseb}
  3240. def_system_macro('CPUMIPS');
  3241. def_system_macro('CPUMIPS32');
  3242. def_system_macro('CPUMIPSEB');
  3243. def_system_macro('CPUMIPSEB32');
  3244. def_system_macro('CPU32');
  3245. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3246. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3247. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3248. def_system_macro('FPC_CURRENCY_IS_INT64');
  3249. def_system_macro('FPC_COMP_IS_INT64');
  3250. def_system_macro('FPC_REQUIRES_PROPER_ALIGNMENT');
  3251. { See comment above for mipsel }
  3252. def_system_macro('FPC_LOCALS_ARE_STACK_REG_RELATIVE');
  3253. {$endif}
  3254. {$ifdef i8086}
  3255. def_system_macro('CPU86'); { Borland compatibility }
  3256. def_system_macro('CPU87'); { Borland compatibility }
  3257. def_system_macro('CPU8086');
  3258. def_system_macro('CPUI8086');
  3259. def_system_macro('CPU16');
  3260. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3261. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3262. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3263. case init_settings.x86memorymodel of
  3264. mm_tiny: def_system_macro('FPC_MM_TINY');
  3265. mm_small: def_system_macro('FPC_MM_SMALL');
  3266. mm_medium: def_system_macro('FPC_MM_MEDIUM');
  3267. mm_compact: def_system_macro('FPC_MM_COMPACT');
  3268. mm_large: def_system_macro('FPC_MM_LARGE');
  3269. mm_huge: def_system_macro('FPC_MM_HUGE');
  3270. end;
  3271. {$endif i8086}
  3272. {$ifdef aarch64}
  3273. def_system_macro('CPUAARCH64');
  3274. def_system_macro('CPU64');
  3275. def_system_macro('FPC_CURRENCY_IS_INT64');
  3276. def_system_macro('FPC_COMP_IS_INT64');
  3277. {$endif aarch64}
  3278. {$if defined(cpu8bitalu)}
  3279. def_system_macro('CPUINT8');
  3280. {$elseif defined(cpu16bitalu)}
  3281. def_system_macro('CPUINT16');
  3282. {$elseif defined(cpu32bitalu)}
  3283. def_system_macro('CPUINT32');
  3284. {$elseif defined(cpu64bitalu)}
  3285. def_system_macro('CPUINT64');
  3286. {$endif defined(cpu64bitalu)}
  3287. if tf_cld in target_info.flags then
  3288. if not UpdateTargetSwitchStr('CLD', init_settings.targetswitches, true) then
  3289. InternalError(2013092801);
  3290. if tf_x86_far_procs_push_odd_bp in target_info.flags then
  3291. if not UpdateTargetSwitchStr('FARPROCSPUSHODDBP', init_settings.targetswitches, true) then
  3292. InternalError(2013092801);
  3293. { Set up a default prefix for binutils when cross-compiling }
  3294. if source_info.system<>target_info.system then
  3295. case target_info.system of
  3296. { Use standard Android NDK prefixes }
  3297. system_arm_android:
  3298. utilsprefix:='arm-linux-androideabi-';
  3299. system_i386_android:
  3300. utilsprefix:='i686-linux-android-';
  3301. system_mipsel_android:
  3302. utilsprefix:='mipsel-linux-android-';
  3303. end;
  3304. { Set up default value for the heap }
  3305. if target_info.system in systems_embedded then
  3306. begin
  3307. case target_info.system of
  3308. system_avr_embedded:
  3309. heapsize:=128;
  3310. system_arm_embedded:
  3311. heapsize:=256;
  3312. system_mipsel_embedded:
  3313. heapsize:=256;
  3314. else
  3315. heapsize:=256;
  3316. end;
  3317. end;
  3318. { read configuration file }
  3319. if (not disable_configfile) and
  3320. (ppccfg<>'') then
  3321. read_configfile:=check_configfile(ppccfg,ppccfg)
  3322. else
  3323. read_configfile := false;
  3324. { Read commandline and configfile }
  3325. param_file:='';
  3326. { read configfile }
  3327. if read_configfile then
  3328. option.interpret_file(ppccfg);
  3329. { read parameters again to override config file }
  3330. if cmd<>'' then
  3331. option.parsecmd(cmd)
  3332. else
  3333. begin
  3334. { Write help pages if no parameters are passed }
  3335. if (paramcount=0) then
  3336. Option.WriteHelpPages;
  3337. option.read_parameters;
  3338. { Write only quickinfo }
  3339. if option.quickinfo<>'' then
  3340. option.writequickinfo;
  3341. end;
  3342. { check the compatibility of different options and adjust them if necessary
  3343. (and print possible errors)
  3344. }
  3345. option.checkoptionscompatibility;
  3346. { Stop if errors in options }
  3347. if ErrorCount>0 then
  3348. StopOptions(1);
  3349. { endian define }
  3350. case target_info.endian of
  3351. endian_little :
  3352. begin
  3353. def_system_macro('ENDIAN_LITTLE');
  3354. def_system_macro('FPC_LITTLE_ENDIAN');
  3355. end;
  3356. endian_big :
  3357. begin
  3358. def_system_macro('ENDIAN_BIG');
  3359. def_system_macro('FPC_BIG_ENDIAN');
  3360. end;
  3361. end;
  3362. { define abi }
  3363. for abi:=low(tabi) to high(tabi) do
  3364. undef_system_macro('FPC_ABI_'+abiinfo[abi].name);
  3365. def_system_macro('FPC_ABI_'+abiinfo[target_info.abi].name);
  3366. { Define FPC_ABI_EABI in addition to FPC_ABI_EABIHF on EABI VFP hardfloat
  3367. systems since most code needs to behave the same on both}
  3368. if target_info.abi = abi_eabihf then
  3369. def_system_macro('FPC_ABI_EABI');
  3370. { Write logo }
  3371. if option.ParaLogo then
  3372. option.writelogo;
  3373. { Check file to compile }
  3374. if param_file='' then
  3375. begin
  3376. Message(option_no_source_found);
  3377. StopOptions(1);
  3378. end;
  3379. {$ifndef Unix}
  3380. param_file:=FixFileName(param_file);
  3381. {$endif not unix}
  3382. inputfilepath:=ExtractFilePath(param_file);
  3383. inputfilename:=ExtractFileName(param_file);
  3384. if ExtractFileExt(inputfilename)='' then
  3385. begin
  3386. if FileExists(inputfilepath+ChangeFileExt(inputfilename,sourceext)) then
  3387. inputfilename:=ChangeFileExt(inputfilename,sourceext)
  3388. else if FileExists(inputfilepath+ChangeFileExt(inputfilename,pasext)) then
  3389. inputfilename:=ChangeFileExt(inputfilename,pasext)
  3390. else if ((m_mac in current_settings.modeswitches) or
  3391. (tf_p_ext_support in target_info.flags))
  3392. and FileExists(inputfilepath+ChangeFileExt(inputfilename,pext)) then
  3393. inputfilename:=ChangeFileExt(inputfilename,pext);
  3394. end;
  3395. { Check output dir }
  3396. if (OutputExeDir<>'') and
  3397. not PathExists(OutputExeDir,false) then
  3398. begin
  3399. Message1(general_e_path_does_not_exist,OutputExeDir);
  3400. StopOptions(1);
  3401. end;
  3402. { Add paths specified with parameters to the searchpaths }
  3403. UnitSearchPath.AddList(option.ParaUnitPath,true);
  3404. ObjectSearchPath.AddList(option.ParaObjectPath,true);
  3405. IncludeSearchPath.AddList(option.ParaIncludePath,true);
  3406. LibrarySearchPath.AddList(option.ParaLibraryPath,true);
  3407. FrameworkSearchPath.AddList(option.ParaFrameworkPath,true);
  3408. { add unit environment and exepath to the unit search path }
  3409. if inputfilepath<>'' then
  3410. Unitsearchpath.AddPath(inputfilepath,true);
  3411. if not disable_configfile then
  3412. begin
  3413. env:=GetEnvironmentVariable(target_info.unit_env);
  3414. if env<>'' then
  3415. UnitSearchPath.AddPath(GetEnvironmentVariable(target_info.unit_env),false);
  3416. end;
  3417. {$ifdef Unix}
  3418. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3419. if fpcdir='' then
  3420. begin
  3421. if PathExists('/usr/local/lib/fpc/'+version_string,true) then
  3422. fpcdir:='/usr/local/lib/fpc/'+version_string+'/'
  3423. else
  3424. fpcdir:='/usr/lib/fpc/'+version_string+'/';
  3425. end;
  3426. {$else unix}
  3427. fpcdir:=FixPath(GetEnvironmentVariable('FPCDIR'),false);
  3428. if fpcdir='' then
  3429. begin
  3430. fpcdir:=ExePath+'../';
  3431. if not(PathExists(fpcdir+'units',true)) and
  3432. not(PathExists(fpcdir+'rtl',true)) then
  3433. fpcdir:=fpcdir+'../';
  3434. end;
  3435. {$endif unix}
  3436. { first try development RTL, else use the default installation path }
  3437. if not disable_configfile then
  3438. begin
  3439. if PathExists(FpcDir+'rtl',true) then
  3440. if (tf_use_8_3 in Source_Info.Flags) or
  3441. (tf_use_8_3 in Target_Info.Flags) then
  3442. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_os_string,false)
  3443. else
  3444. UnitSearchPath.AddPath(FpcDir+'rtl/'+target_full_string,false)
  3445. else
  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+'units/'+target_os_string+'/rtl',false)
  3449. else
  3450. UnitSearchPath.AddPath(FpcDir+'units/'+target_full_string+'/rtl',false);
  3451. end;
  3452. { Add exepath if the exe is not in the current dir, because that is always searched already.
  3453. Do not add it when linking on the target because then we can maybe already find
  3454. .o files that are not for the target }
  3455. if (ExePath<>cfileutl.GetCurrentDir) and
  3456. not(cs_link_on_target in init_settings.globalswitches) then
  3457. UnitSearchPath.AddPath(ExePath,false);
  3458. { Add unit dir to the object and library path }
  3459. objectsearchpath.AddList(unitsearchpath,false);
  3460. librarysearchpath.AddList(unitsearchpath,false);
  3461. {$ifdef llvm}
  3462. { force llvm assembler writer }
  3463. option.paratargetasm:=as_llvm;
  3464. {$endif llvm}
  3465. { maybe override assembler }
  3466. if (option.paratargetasm<>as_none) then
  3467. begin
  3468. if not set_target_asm(option.paratargetasm) then
  3469. begin
  3470. Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name);
  3471. set_target_asm(target_info.assemextern);
  3472. Message1(option_asm_forced,target_asm.idtxt);
  3473. end;
  3474. if (af_no_debug in asminfos[option.paratargetasm]^.flags) and
  3475. (option.paratargetdbg<>dbg_none) then
  3476. begin
  3477. Message1(option_confict_asm_debug,
  3478. asminfos[option.paratargetasm]^.idtxt);
  3479. option.paratargetdbg:=dbg_none;
  3480. exclude(init_settings.moduleswitches,cs_debuginfo);
  3481. end;
  3482. end;
  3483. {TOptionheck a second time as we might have changed assembler just above }
  3484. option.checkoptionscompatibility;
  3485. { maybe override debug info format }
  3486. if (option.paratargetdbg<>dbg_none) then
  3487. if not set_target_dbg(option.paratargetdbg) then
  3488. Message(option_w_unsupported_debug_format);
  3489. { switch assembler if it's binary and we got -a on the cmdline }
  3490. if (cs_asm_leave in init_settings.globalswitches) and
  3491. (af_outputbinary in target_asm.flags) then
  3492. begin
  3493. Message(option_switch_bin_to_src_assembler);
  3494. set_target_asm(target_info.assemextern);
  3495. end;
  3496. { Force use of external linker if there is no
  3497. internal linker or the linking is skipped }
  3498. if not(cs_link_extern in init_settings.globalswitches) and
  3499. ((target_info.link=ld_none) or
  3500. (cs_link_nolink in init_settings.globalswitches)) then
  3501. include(init_settings.globalswitches,cs_link_extern);
  3502. { turn off stripping if compiling with debuginfo or profile }
  3503. if (
  3504. (cs_debuginfo in init_settings.moduleswitches) or
  3505. (cs_profile in init_settings.moduleswitches)
  3506. ) and
  3507. not(cs_link_separate_dbg_file in init_settings.globalswitches) then
  3508. exclude(init_settings.globalswitches,cs_link_strip);
  3509. { set Mac OS X version default macros if not specified explicitly }
  3510. option.MaybeSetDefaultMacVersionMacro;
  3511. { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
  3512. if fpu type not explicitly set }
  3513. if not(option.FPUSetExplicitly) and
  3514. ((target_info.system in [system_arm_wince,system_arm_gba,
  3515. system_m68k_amiga,system_m68k_atari,system_m68k_linux,
  3516. system_arm_nds,system_arm_embedded])
  3517. {$ifdef arm}
  3518. or (target_info.abi=abi_eabi)
  3519. {$endif arm}
  3520. )
  3521. {$if defined(arm) or defined (m68k)}
  3522. or (init_settings.fputype=fpu_soft)
  3523. {$endif arm or m68k}
  3524. then
  3525. begin
  3526. {$ifdef cpufpemu}
  3527. include(init_settings.moduleswitches,cs_fp_emulation);
  3528. { cs_fp_emulation and fpu_soft are equal on arm and m68k }
  3529. init_settings.fputype:=fpu_soft;
  3530. {$endif cpufpemu}
  3531. end;
  3532. {$ifdef arm}
  3533. if target_info.abi = abi_eabihf then
  3534. begin
  3535. if not(option.FPUSetExplicitly) then
  3536. begin
  3537. init_settings.fputype:=fpu_vfpv3_d16
  3538. end
  3539. else
  3540. begin
  3541. if not (init_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv3_d16]) then
  3542. begin
  3543. Message(option_illegal_fpu_eabihf);
  3544. StopOptions(1);
  3545. end;
  3546. end;
  3547. end;
  3548. {$endif arm}
  3549. {$ifdef arm}
  3550. case target_info.system of
  3551. system_arm_darwin:
  3552. begin
  3553. { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
  3554. to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
  3555. }
  3556. if not option.CPUSetExplicitly then
  3557. init_settings.cputype:=cpu_armv7;
  3558. if not option.OptCPUSetExplicitly then
  3559. init_settings.optimizecputype:=cpu_armv7;
  3560. if not option.FPUSetExplicitly then
  3561. init_settings.fputype:=fpu_vfpv3;
  3562. end;
  3563. system_arm_android:
  3564. begin
  3565. { set default cpu type to ARMv5T for Android unless specified otherwise }
  3566. if not option.CPUSetExplicitly then
  3567. init_settings.cputype:=cpu_armv5t;
  3568. if not option.OptCPUSetExplicitly then
  3569. init_settings.optimizecputype:=cpu_armv5t;
  3570. end;
  3571. end;
  3572. { set default cpu type to ARMv7a for ARMHF unless specified otherwise }
  3573. if (target_info.abi = abi_eabihf) then
  3574. begin
  3575. {$ifdef CPUARMV6}
  3576. { if the compiler is built for armv6, then
  3577. inherit this setting, e.g. Raspian is armhf but
  3578. only armv6, this makes rebuilds of the compiler
  3579. easier }
  3580. if not option.CPUSetExplicitly then
  3581. init_settings.cputype:=cpu_armv6;
  3582. if not option.OptCPUSetExplicitly then
  3583. init_settings.optimizecputype:=cpu_armv6;
  3584. {$else CPUARMV6}
  3585. if not option.CPUSetExplicitly then
  3586. init_settings.cputype:=cpu_armv7a;
  3587. if not option.OptCPUSetExplicitly then
  3588. init_settings.optimizecputype:=cpu_armv7a;
  3589. {$endif CPUARMV6}
  3590. end;
  3591. if (init_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3592. begin
  3593. def_system_macro('CPUTHUMB');
  3594. if not option.FPUSetExplicitly then
  3595. init_settings.fputype:=fpu_soft;
  3596. {$if defined(FPC_ARMEL) or defined(FPC_ARMHF)}
  3597. 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';
  3598. {$else FPC_ARMAL or FPC_ARMHF}
  3599. if target_info.endian=endian_little then
  3600. 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';
  3601. {$endif FPC_ARMAL or FPC_ARMHF}
  3602. end;
  3603. if (init_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype]) then
  3604. def_system_macro('CPUTHUMB2');
  3605. {$endif arm}
  3606. {$ifdef jvm}
  3607. { set default CPU type to Dalvik when targeting Android }
  3608. if target_info.system=system_jvm_android32 then
  3609. begin
  3610. if not option.CPUSetExplicitly then
  3611. init_settings.cputype:=cpu_dalvik;
  3612. end;
  3613. {$endif jvm}
  3614. {$ifdef llvm}
  3615. { standard extension for llvm bitcode files }
  3616. target_info.asmext:='.ll';
  3617. { don't generate dwarf cfi, llvm will do that }
  3618. exclude(target_info.flags,tf_needs_dwarf_cfi);
  3619. {$endif llvm}
  3620. {$ifdef mipsel}
  3621. case target_info.system of
  3622. system_mipsel_android:
  3623. begin
  3624. { set default cpu type to MIPS32 rev. 1 and hard float for MIPS-Android unless specified otherwise }
  3625. if not option.CPUSetExplicitly then
  3626. init_settings.cputype:=cpu_mips32;
  3627. if not option.OptCPUSetExplicitly then
  3628. init_settings.optimizecputype:=cpu_mips32;
  3629. if not option.FPUSetExplicitly then
  3630. init_settings.fputype:=fpu_mips2;
  3631. end;
  3632. system_mipsel_embedded:
  3633. begin
  3634. { set default cpu type to PIC32MX and softfloat for MIPSEL-EMBEDDED target unless specified otherwise }
  3635. if not option.CPUSetExplicitly then
  3636. init_settings.cputype:=cpu_pic32mx;
  3637. if not option.OptCPUSetExplicitly then
  3638. init_settings.optimizecputype:=cpu_pic32mx;
  3639. if not option.FPUSetExplicitly then
  3640. init_settings.fputype:=fpu_soft;
  3641. end;
  3642. end;
  3643. {$endif mipsel}
  3644. { now we can define cpu and fpu type }
  3645. def_system_macro('CPU'+Cputypestr[init_settings.cputype]);
  3646. def_system_macro('FPU'+fputypestr[init_settings.fputype]);
  3647. {$ifdef llvm}
  3648. def_system_macro('CPULLVM');
  3649. {$endif llvm}
  3650. {$if defined(cpucapabilities)}
  3651. for cpuflag:=low(cpuflag) to high(cpuflag) do
  3652. begin
  3653. str(cpuflag,hs);
  3654. if cpuflag in cpu_capabilities[init_settings.cputype] then
  3655. def_system_macro(hs)
  3656. else
  3657. undef_system_macro(hs);
  3658. end;
  3659. {$endif defined(cpucapabilities)}
  3660. if init_settings.fputype<>fpu_none then
  3661. begin
  3662. {$if defined(i386) or defined(i8086)}
  3663. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3664. {$endif}
  3665. def_system_macro('FPC_HAS_TYPE_SINGLE');
  3666. def_system_macro('FPC_HAS_TYPE_DOUBLE');
  3667. {$if not defined(i386) and not defined(x86_64) and not defined(i8086) and not defined(aarch64)}
  3668. def_system_macro('FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE');
  3669. {$endif}
  3670. {$if defined(m68k)}
  3671. def_system_macro('FPC_INCLUDE_SOFTWARE_LONGWORD_TO_DOUBLE');
  3672. {$endif}
  3673. {$ifdef x86_64}
  3674. {$ifndef FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3675. { normally, win64 doesn't support the legacy fpu }
  3676. if target_info.system=system_x86_64_win64 then
  3677. undef_system_macro('FPC_HAS_TYPE_EXTENDED')
  3678. else
  3679. {$endif FPC_SUPPORT_X87_TYPES_ON_WIN64}
  3680. def_system_macro('FPC_HAS_TYPE_EXTENDED');
  3681. {$endif}
  3682. end;
  3683. { Enable now for testing }
  3684. {$ifndef DISABLE_TLS_DIRECTORY}
  3685. if target_info.system in systems_windows then
  3686. def_system_macro('FPC_USE_TLS_DIRECTORY');
  3687. {$endif not DISABLE_TLS_DIRECTORY}
  3688. {$ifndef DISABLE_WIN64_SEH}
  3689. if target_info.system=system_x86_64_win64 then
  3690. def_system_macro('FPC_USE_WIN64_SEH');
  3691. {$endif DISABLE_WIN64_SEH}
  3692. {$ifdef TEST_WIN32_SEH}
  3693. if target_info.system=system_i386_win32 then
  3694. def_system_macro('FPC_USE_WIN32_SEH');
  3695. {$endif TEST_WIN32_SEH}
  3696. {$ifdef ARM}
  3697. { define FPC_DOUBLE_HILO_SWAPPED if needed to properly handle doubles in RTL }
  3698. if (init_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  3699. not(cs_fp_emulation in init_settings.moduleswitches) then
  3700. def_system_macro('FPC_DOUBLE_HILO_SWAPPED');
  3701. {$endif ARM}
  3702. { inline bsf/bsr implementation }
  3703. {$if not defined(llvm) and (defined(i386) or defined(x86_64) or defined(aarch64) or defined(powerpc) or defined(powerpc64))}
  3704. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3705. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3706. {$endif}
  3707. { hardware FMA support }
  3708. {$if defined(i386) or defined(x86_64)}
  3709. if (cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[] then
  3710. begin
  3711. def_system_macro('FPC_HAS_FAST_FMA_SINGLE');
  3712. def_system_macro('FPC_HAS_FAST_FMA_DOUBLE');
  3713. end;
  3714. {$endif defined(i386) or defined(x86_64)}
  3715. {$if defined(arm)}
  3716. { it is determined during system unit compilation if clz is used for bsf or not,
  3717. this is not perfect but the current implementation bsf/bsr does not allow another
  3718. solution }
  3719. if (CPUARM_HAS_CLZ in cpu_capabilities[init_settings.cputype]) and
  3720. ((init_settings.instructionset=is_arm) or
  3721. (CPUARM_HAS_THUMB2 in cpu_capabilities[init_settings.cputype])) then
  3722. begin
  3723. def_system_macro('FPC_HAS_INTERNAL_BSR');
  3724. if CPUARM_HAS_RBIT in cpu_capabilities[init_settings.cputype] then
  3725. def_system_macro('FPC_HAS_INTERNAL_BSF');
  3726. end;
  3727. {$endif}
  3728. {$if defined(powerpc64)}
  3729. { on sysv targets, default to elfv2 for little endian and to elfv1 for
  3730. big endian (unless specified otherwise). As the gcc man page says:
  3731. "Overriding the default ABI requires special system support and is
  3732. likely to fail in spectacular ways" }
  3733. if not option.ABISetExplicitly then
  3734. begin
  3735. if (target_info.abi=abi_powerpc_sysv) and
  3736. (target_info.endian=endian_little) then
  3737. target_info.abi:=abi_powerpc_elfv2
  3738. else
  3739. if (target_info.abi=abi_powerpc_elfv2) and
  3740. (target_info.endian=endian_big) then
  3741. target_info.abi:=abi_powerpc_sysv
  3742. end;
  3743. {$endif}
  3744. {$if defined(powerpc) or defined(powerpc64)}
  3745. { define _CALL_ELF symbol like gcc }
  3746. case target_info.abi of
  3747. abi_powerpc_sysv:
  3748. set_system_compvar('_CALL_ELF','1');
  3749. abi_powerpc_elfv2:
  3750. set_system_compvar('_CALL_ELF','2');
  3751. end;
  3752. {$endif}
  3753. { Section smartlinking conflicts with import sections on Windows }
  3754. if GenerateImportSection and
  3755. (target_info.system in [system_i386_win32,system_x86_64_win64]) then
  3756. exclude(target_info.flags,tf_smartlink_sections);
  3757. if not option.LinkTypeSetExplicitly then
  3758. set_default_link_type;
  3759. { Default alignment settings,
  3760. 1. load the defaults for the target
  3761. 2. override with generic optimizer setting (little size)
  3762. 3. override with the user specified -Oa }
  3763. UpdateAlignment(init_settings.alignment,target_info.alignment);
  3764. if (cs_opt_size in init_settings.optimizerswitches) then
  3765. begin
  3766. init_settings.alignment.procalign:=1;
  3767. init_settings.alignment.jumpalign:=1;
  3768. init_settings.alignment.loopalign:=1;
  3769. {$ifdef x86}
  3770. { constalignmax=1 keeps the executable and thus the memory foot print small but
  3771. all processors except x86 are really hurt by this or might even crash }
  3772. init_settings.alignment.constalignmax:=1;
  3773. {$endif x86}
  3774. end;
  3775. UpdateAlignment(init_settings.alignment,option.paraalignment);
  3776. set_system_macro('FPC_VERSION',version_nr);
  3777. set_system_macro('FPC_RELEASE',release_nr);
  3778. set_system_macro('FPC_PATCH',patch_nr);
  3779. set_system_macro('FPC_FULLVERSION',Format('%d%.02d%.02d',[StrToInt(version_nr),StrToInt(release_nr),StrToInt(patch_nr)]));
  3780. if not(target_info.system in systems_windows) then
  3781. def_system_macro('FPC_WIDESTRING_EQUAL_UNICODESTRING');
  3782. for i:=low(tfeature) to high(tfeature) do
  3783. if i in features then
  3784. def_system_macro('FPC_HAS_FEATURE_'+featurestr[i]);
  3785. option.free;
  3786. Option:=nil;
  3787. clearstack_pocalls := [pocall_cdecl,pocall_cppdecl,pocall_syscall,pocall_mwpascal];
  3788. cdecl_pocalls := [pocall_cdecl, pocall_cppdecl, pocall_mwpascal];
  3789. if (tf_safecall_clearstack in target_info.flags) then
  3790. begin
  3791. include (cdecl_pocalls, pocall_safecall);
  3792. include (clearstack_pocalls, pocall_safecall)
  3793. end;
  3794. end;
  3795. initialization
  3796. coption:=toption;
  3797. finalization
  3798. if assigned(option) then
  3799. option.free;
  3800. end.