Index: src/ironruby/Ruby.csproj
===================================================================
--- src/ironruby/Ruby.csproj	(revision 101)
+++ src/ironruby/Ruby.csproj	(working copy)
@@ -10,10 +10,14 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Ruby</RootNamespace>
     <AssemblyName>IronRuby</AssemblyName>
-    <SccProjectName></SccProjectName>
-    <SccLocalPath></SccLocalPath>
-    <SccAuxPath></SccAuxPath>
-    <SccProvider></SccProvider>
+    <SccProjectName>
+    </SccProjectName>
+    <SccLocalPath>
+    </SccLocalPath>
+    <SccAuxPath>
+    </SccAuxPath>
+    <SccProvider>
+    </SccProvider>
     <OldToolsVersion>2.0</OldToolsVersion>
     <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
   </PropertyGroup>
@@ -25,9 +29,11 @@
     <DefineConstants>TRACE;DEBUG</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
-    <DelaySign></DelaySign>
+    <DelaySign>
+    </DelaySign>
     <AssemblyOriginatorKeyFile>..\..\..\MSSharedLibKey.snk</AssemblyOriginatorKeyFile>
-    <SignAssembly></SignAssembly>
+    <SignAssembly>
+    </SignAssembly>
     <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@@ -37,9 +43,11 @@
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
-    <DelaySign></DelaySign>
+    <DelaySign>
+    </DelaySign>
     <AssemblyOriginatorKeyFile>..\..\..\MSSharedLibKey.snk</AssemblyOriginatorKeyFile>
-    <SignAssembly></SignAssembly>
+    <SignAssembly>
+    </SignAssembly>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Silverlight Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -49,9 +57,11 @@
     <PlatformTarget>AnyCPU</PlatformTarget>
     <ErrorReport>prompt</ErrorReport>
     <NoStdLib>true</NoStdLib>
-    <SignAssembly></SignAssembly>
+    <SignAssembly>
+    </SignAssembly>
     <AssemblyOriginatorKeyFile>..\..\..\SilverlightKey.snk</AssemblyOriginatorKeyFile>
-    <DelaySign></DelaySign>
+    <DelaySign>
+    </DelaySign>
     <SilverlightBuild>true</SilverlightBuild>
     <SilverlightSdkPath>..\..\..\Utilities\Silverlight\x86ret\</SilverlightSdkPath>
   </PropertyGroup>
@@ -62,9 +72,11 @@
     <DebugType>pdbonly</DebugType>
     <PlatformTarget>AnyCPU</PlatformTarget>
     <ErrorReport>prompt</ErrorReport>
-    <SignAssembly></SignAssembly>
+    <SignAssembly>
+    </SignAssembly>
     <AssemblyOriginatorKeyFile>..\..\..\SilverlightKey.snk</AssemblyOriginatorKeyFile>
-    <DelaySign></DelaySign>
+    <DelaySign>
+    </DelaySign>
     <SilverlightBuild>true</SilverlightBuild>
     <SilverlightSdkPath>..\..\..\Utilities\Silverlight\x86ret\</SilverlightSdkPath>
   </PropertyGroup>
@@ -119,6 +131,7 @@
     <Compile Include="Runtime\EqualityComparer.cs" />
     <Compile Include="Builtins\Hash.cs" />
     <Compile Include="Runtime\Globals\GlobalVariables.cs" />
+    <Compile Include="Runtime\Globals\KCodeGlobalVariableInfo.cs" />
     <Compile Include="Runtime\Globals\ReadOnlyGlobalVariableInfo.cs" />
     <Compile Include="Runtime\Globals\GlobalVariableInfo.cs" />
     <Compile Include="Runtime\Globals\GlobalVariable.cs" />
@@ -258,12 +271,12 @@
     </None>
   </ItemGroup>
   <ItemGroup>
-    <ProjectReference Include="..\..\..\..\..\ndp\fx\src\Core\Microsoft\Scripting\Microsoft.Scripting.Core.csproj">
+    <ProjectReference Include="..\Microsoft.Scripting.Core\Microsoft.Scripting.Core.csproj">
       <Project>{2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}</Project>
       <Name>Microsoft.Scripting.Core</Name>
       <Private>False</Private>
     </ProjectReference>
-    <ProjectReference Include="..\..\..\Runtime\Microsoft.Scripting\Microsoft.Scripting.csproj">
+    <ProjectReference Include="..\Microsoft.Scripting\Microsoft.Scripting.csproj">
       <Project>{EB66B766-6354-4208-A3D4-AACBDCB5C3B3}</Project>
       <Name>Microsoft.Scripting</Name>
     </ProjectReference>
Index: src/ironruby/Runtime/Globals/KCodeGlobalVariableInfo.cs
===================================================================
--- src/ironruby/Runtime/Globals/KCodeGlobalVariableInfo.cs	(revision 0)
+++ src/ironruby/Runtime/Globals/KCodeGlobalVariableInfo.cs	(revision 0)
@@ -0,0 +1,64 @@
+﻿/* ****************************************************************************
+ *
+ * Copyright (c) Microsoft Corporation. 
+ *
+ * This source code is subject to terms and conditions of the Microsoft Public License. A 
+ * copy of the license can be found in the License.html file at the root of this distribution. If 
+ * you cannot locate the  Microsoft Public License, please send an email to 
+ * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
+ * by the terms of the Microsoft Public License.
+ *
+ * You must not remove this notice, or any other, from this software.
+ *
+ *
+ * ***************************************************************************/
+
+using Microsoft.Scripting;
+
+using Ruby.Builtins;
+
+namespace Ruby.Runtime {
+    internal sealed class KCodeGlobalVariableInfo : GlobalVariable {
+        public readonly MutableString NONE = new MutableString("NONE");
+        public readonly MutableString UTF8 = new MutableString("UTF8");
+        public readonly MutableString SJIS = new MutableString("SJIS");
+        public readonly MutableString EUC = new MutableString("EUC");
+
+        private MutableString _value;
+
+        public KCodeGlobalVariableInfo() {
+            _value = NONE;
+        }
+
+        public override object GetValue(RubyExecutionContext /*!*/ context, RubyScope scope) {
+            return _value;
+        }
+
+        public override void SetValue(RubyExecutionContext /*!*/ context, RubyScope scope, SymbolId name, object value) {
+            string lang = value as MutableString;
+
+            if ((lang != null) && (lang.Length > 0)) {
+                switch (lang[0]) {
+                    case 'E':
+                    case 'e':
+                        _value = EUC;
+                        break;
+                    case 'S':
+                    case 's':
+                        _value = SJIS;
+                        break;
+                    case 'U':
+                    case 'u':
+                        _value = UTF8;
+                        break;
+                    case 'N':
+                    case 'n':
+                    case 'A':
+                    case 'a':
+                        _value = NONE;
+                        break;
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
Index: src/ironruby/Runtime/RubyExecutionContext.cs
===================================================================
--- src/ironruby/Runtime/RubyExecutionContext.cs	(revision 101)
+++ src/ironruby/Runtime/RubyExecutionContext.cs	(working copy)
@@ -269,7 +269,6 @@
 
             // $0
             // $?
-            // $-K
 
             DefineGlobalVariableNoLock(SymbolTable.StringToId("stdin"), new GlobalVariableInfo(StandardInput));
             DefineGlobalVariableNoLock(SymbolTable.StringToId("stdout"), Runtime.GlobalVariables.OutputStream);
@@ -290,6 +289,11 @@
             DefineGlobalVariableNoLock(SymbolTable.StringToId("DEBUG"), debug);
             DefineGlobalVariableNoLock(SymbolTable.StringToId("-d"), debug);
 
+            KCodeGlobalVariableInfo kcode = new KCodeGlobalVariableInfo();
+            
+            DefineGlobalVariableNoLock(SymbolTable.StringToId("KCODE"), kcode);
+            DefineGlobalVariableNoLock(SymbolTable.StringToId("-K"), kcode);
+
 #if !SILVERLIGHT
             DefineGlobalVariableNoLock(Symbols.CurrentProcessId, new ReadOnlyGlobalVariableInfo(Process.GetCurrentProcess().Id));
 #endif
Index: tests/ironruby/Runtime/Global/test_kcode.rb
===================================================================
--- tests/ironruby/Runtime/Global/test_kcode.rb	(revision 0)
+++ tests/ironruby/Runtime/Global/test_kcode.rb	(revision 0)
@@ -0,0 +1,19 @@
+require '../../util/assert.rb'
+
+assert_equal($KCODE, 'NONE')
+assert_equal($-K, 'NONE')
+
+$KCODE = 'SJIS'
+
+assert_equal($KCODE, 'SJIS')
+assert_equal($-K, 'SJIS')
+
+$KCODE = 'NONE'
+
+assert_equal($KCODE, 'NONE')
+assert_equal($-K, 'NONE')
+
+$KCODE = 'BAD'
+
+assert_equal($KCODE, 'NONE')
+assert_equal($-K, 'NONE')
Index: tests/ironruby/Runtime/Global/test_kcode.rb
===================================================================
--- tests/ironruby/Runtime/Global/test_kcode.rb	(revision 0)
+++ tests/ironruby/Runtime/Global/test_kcode.rb	(revision 0)
@@ -0,0 +1,19 @@
+require '../../util/assert.rb'
+
+assert_equal($KCODE, 'NONE')
+assert_equal($-K, 'NONE')
+
+$KCODE = 'SJIS'
+
+assert_equal($KCODE, 'SJIS')
+assert_equal($-K, 'SJIS')
+
+$KCODE = 'NONE'
+
+assert_equal($KCODE, 'NONE')
+assert_equal($-K, 'NONE')
+
+$KCODE = 'BAD'
+
+assert_equal($KCODE, 'NONE')
+assert_equal($-K, 'NONE')
