diff --git a/Depend.hs b/Depend.hs
new file mode 100644
--- /dev/null
+++ b/Depend.hs
@@ -0,0 +1,88 @@
+module Depend (
+
+  ebDepends
+
+) where
+
+import Distribution.Package
+import Distribution.PackageDescription
+import Distribution.Version
+import Data.Version
+import Data.Maybe
+
+pkgCabEbList :: [ ( String, Maybe String ) ]
+pkgCabEbList = [
+
+  ( "ghc"       , Just "dev-lang/ghc"        ) ,
+  ( "Cabal"     , Just "dev-haskell/cabal"   ) ,
+  ( "X11"       , Just "dev-haskell/x11"     ) ,
+  ( "directory" , Nothing                    ) ,
+  ( "base"      , Nothing                    ) ,
+  ( "bytestring", Nothing                    ) ,
+  ( "containers", Nothing                    ) ,
+  ( "array"     , Nothing                    ) ,
+  ( "unix"      , Nothing                    ) ,
+  ( "ghc-prim"  , Nothing                    ) ,
+  ( "filepath"  , Nothing                    ) ,
+  ( "old-locale", Nothing                    ) ,
+  ( "random"    , Nothing                    ) ,
+  ( "X11-xft"   , Just "dev-haskell/x11-xft" ) ,
+  ( "process"   , Nothing                    ) ,
+  ( "HUnit"     , Just "dev-haskell/hunit"   ) ,
+  ( "old-time"  , Nothing                    ) ,
+  ( "HaXml"	, Just "dev-haskell/haxml"   ) ,
+  ( "Imlib"	, Just "dev-haskell/imlib"   ) ,
+  ( "ListLike"	, Just "dev-haskell/listlike") ,
+  ( "pretty"	, Nothing                    ) ,
+  ( "template-haskell"	, Nothing            ) ,
+  ( "GLUT"      , Just "dev-haskell/glut"    ) ,
+  ( "HsSyck"	, Just "dev-haskell/hssyck"  ) ,
+  ( "HTTP"      , Just "dev-haskell/http"    )
+ ]
+
+ebDepend :: Dependency -> Maybe String
+ebDepend dp
+  = let ( b, a ) = ebPkgVersion dp
+     in fmap ( \n -> b ++ n ++ a ) $ ebPkgName dp
+             
+
+ebPkgName :: Dependency -> Maybe String
+ebPkgName = getPkgName . getDepPkgName
+
+getPkgName :: String -> Maybe String
+getPkgName cbpkg = case lookup cbpkg pkgCabEbList of
+                        Just ebpkg -> ebpkg
+                        Nothing    -> Just $ "dev-haskell/" ++ cbpkg
+
+getDepPkgName :: Dependency -> String
+getDepPkgName ( Dependency ( PackageName nam ) _ ) = nam
+
+ebPkgVersion :: Dependency -> ( String, String )
+ebPkgVersion = getPkgVersion . getDepPkgVersion
+
+getPkgVersion :: VersionRange -> ( String, String )
+getPkgVersion AnyVersion = ( "", "" )
+getPkgVersion ( UnionVersionRanges vr1 vr2 )
+  = let ( b1, a1 ) = getPkgVersion vr1
+        ( b2, a2 ) = getPkgVersion vr2
+     in ( b2 ++ b1, "-" ++ a1 )
+getPkgVersion ( ThisVersion v ) = ( "=", showVersion v )
+getPkgVersion ( LaterVersion v ) = ( ">", showVersion v )
+getPkgVersion ( EarlierVersion v ) = ( "<", showVersion v )
+getPkgVersion ( IntersectVersionRanges v1 v2 ) = getPkgVersion v1
+getPkgVersion ( WildcardVersion v@Version{versionBranch = vb} ) =
+	( "<", "-" ++ showVersion v{versionBranch = init vb ++ [last vb + 1]} )
+
+getDepPkgVersion :: Dependency -> VersionRange
+getDepPkgVersion ( Dependency _ vr ) = vr
+
+
+--  print $ catMaybes $ map ebDepend $ concatMap condTreeConstraints $ map snd $ condExecutables gpd
+ebDepends :: GenericPackageDescription -> [ String ]
+ebDepends gpd =
+  let exdep = catMaybes $ map ebDepend $ concatMap condTreeConstraints $ map snd $ condExecutables gpd
+      libdep = concat $ maybeToList $
+	fmap ( catMaybes . map ebDepend . condTreeConstraints ) $ condLibrary gpd
+--  print $ map snd $ condExecutables gpd
+--  print $ fmap ( map ebDepend . condTreeConstraints ) $ condLibrary gpd
+   in exdep ++ libdep
diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2010, Yoshikuni Jujo
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+  * Redistributions of source code must retain the above copyright notice,
+    this list of conditions and the following disclaimer.
+
+  * Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+
+  * Neither the name of the Yoshikuni Jujo nor the names of its
+    contributors may be used to endorse or promote products derived from
+    this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVEN SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/cabal2ebuild.cabal b/cabal2ebuild.cabal
new file mode 100644
--- /dev/null
+++ b/cabal2ebuild.cabal
@@ -0,0 +1,35 @@
+Name:                cabal2ebuild
+Version:             0.0.15.3
+Stability:           Experimental
+Synopsis:            make gentoo's .ebuild file from .cabal file
+Description:
+	> % ls
+	> hoge.cabal ...
+	> % cabal2ebuild
+	> % ls
+	> % hoge.cabal hoge-0.1.2.3.ebuild ...
+Homepage:            yet
+License:             BSD3
+License-file:        LICENSE
+Author:              Yoshikuni Jujo <PAF01143@nifty.ne.jp>
+Maintainer:          Yoshikuni Jujo <PAF01143@nifty.ne.jp>
+-- Copyright:           
+Category:            Distribution
+Build-type:          Simple
+-- Extra-source-files:  
+Cabal-version:       >=1.6
+
+source-repository head
+  type:		git
+  location:	git://github.com/YoshikuniJujo/cabal2ebuild.git
+
+source-repository this
+  type:		git
+  location:	git://github.com/YoshikuniJujo/cabal2ebuild.git
+  tag:		0.0.15.3
+
+executable cabal2ebuild
+  main-is:       cabal2ebuild.hs
+  other-modules: Depend
+  build-depends: base > 3 && < 5, directory, Cabal, filepath
+  Ghc-options:		-Wall
diff --git a/cabal2ebuild.hs b/cabal2ebuild.hs
new file mode 100644
--- /dev/null
+++ b/cabal2ebuild.hs
@@ -0,0 +1,157 @@
+import Distribution.Package
+import Distribution.Version
+import Distribution.PackageDescription
+import Distribution.PackageDescription.Parse
+import Distribution.Verbosity
+import Data.Maybe
+import Data.Version
+import Distribution.License
+import System.Directory
+import Data.List
+import Depend
+
+import System.IO.Unsafe
+import System.Directory
+import System.FilePath
+import Control.Applicative
+
+test :: IO ()
+test = do
+  gpd <- readPackageDescription normal "cabal2ebuild.cabal"
+  print $ getName gpd ++ ".ebuild"
+  print $ getName gpd ++ ".tar.gz"
+  print $ getLicense gpd
+  print $ hasLib gpd
+  print $ hasEx gpd
+  putStrLn $ makeCabalFeatures ( hasLib gpd ) ( hasEx gpd )
+  putStrLn $ makeSrcURI $ getName gpd
+  putStrLn ""
+--  putStrLn $ makeEbuild gpd
+  print $ condTreeData $ snd $ head $ condExecutables gpd
+  mapM_ print $ condTreeConstraints $ snd $ head $ condExecutables gpd
+  print $ synopsis $ packageDescription gpd
+  putStrLn ""
+  putStr $ ebuildToFile $ gpdToEbuild gpd
+  print $ condLibrary gpd
+  print $ ebDepends gpd
+  
+
+-- main :: IO ()
+main = do
+  cabal <- fmap ( head . filter ( isSuffixOf ".cabal" ) ) $ getDirectoryContents "."
+  gpd <- readPackageDescription normal cabal
+  writeFile ( makeFileName gpd ) -- $ makeEbuild gpd
+                                 $ ebuildToFile $ gpdToEbuild gpd
+
+makeFileName :: GenericPackageDescription -> String
+makeFileName gpd = getName gpd ++ ".ebuild"
+
+-- data EbLicense = BSD3 | GPL | LGPL deriving Show
+
+data EbKWords = X86 | BX86 deriving Show
+
+showEKW :: EbKWords -> String
+showEKW X86  = "x86"
+showEKW BX86 = "~x86"
+
+data Ebuild = Ebuild {
+ 
+  ebCabalFt :: [ String ] ,
+  ebInherit :: String ,
+  ebAPI     :: Int ,
+  ebDsc     :: String ,
+  ebHmpg    :: String ,
+  srcURI    :: String ,
+  ebLicense :: License ,
+  ebSlot    :: Int ,
+  ebKWords  :: [ EbKWords ] ,
+  ebDepend  :: [ String ]
+
+ } deriving Show
+
+gpdToEbuild :: GenericPackageDescription -> Ebuild
+gpdToEbuild gpd = Ebuild {
+
+  ebCabalFt = ft ,
+  ebInherit = "haskell-cabal",
+  ebAPI     = 3 ,
+  ebDsc     = synopsis $ packageDescription gpd ,
+  ebHmpg    = homepage $ packageDescription gpd ,
+  srcURI    = makeSrcURI ( getName gpd ) ,
+  ebLicense = getLicense gpd ,
+  ebSlot    = 0 ,
+  ebKWords  = [ X86 ] ,
+  ebDepend  = ">=dev-lang/ghc-6.10" : "dev-haskell/cabal" : ebDepends gpd
+
+ }
+  where
+  ft :: [ String ]
+  ft = concatMap snd $ filter fst
+    [ ( hasLib gpd , [ "lib", "haddock", "profile", "hscolour" ] ),
+      ( hasEx gpd  , [ "bin" ] ) ] 
+  
+ebuildToFile :: Ebuild -> String
+ebuildToFile eb =
+  "EAPI=" ++ show ( ebAPI eb ) ++ "\n\n" ++
+  "CABAL_FEATURES=\"" ++ unwords ( ebCabalFt eb ) ++ "\"\n" ++
+  "inherit " ++ ebInherit eb ++ "\n\n" ++
+  "DESCRIPTION=" ++ show ( ebDsc eb ) ++ "\n" ++
+  "HOMEPAGE=" ++ show ( ebHmpg eb ) ++ "\n" ++
+  "SRC_URI=" ++ srcURI eb ++ "\n\n" ++
+  "LICENSE=\"" ++ show ( ebLicense eb ) ++ "\"\n" ++
+  "SLOT=\"" ++ show ( ebSlot eb ) ++ "\"\n" ++
+  "KEYWORDS=\"" ++ unwords ( map showEKW $ ebKWords eb ) ++ "\"\n\n" ++
+  "DEPEND=\"" ++ unlines ( ebDepend eb ) ++ "\"\n"
+
+makeEbuild :: GenericPackageDescription -> String
+makeEbuild gpd =
+  makeCabalFeatures ( hasLib gpd ) ( hasEx gpd ) ++ "\n" ++
+  "inherit haskell-cabal\n\n" ++
+  "EAPI=3\n\n" ++
+  "SRC_URI=" ++ makeSrcURI ( getName gpd ) ++ "\n\n" ++
+  makeLicense ( getLicense gpd ) ++ "\n" ++
+  "SLOT=\"0\"\n" ++ "KEYWORDS=\"x86\"\n"
+
+makeCabalFeatures :: Bool -> Bool -> String
+makeCabalFeatures lb ex
+  = let ls = if lb then "lib " else ""
+        xs = if ex then "bin " else ""
+     in "CABAL_FEATURES=" ++ show ( xs ++ ls ++ "haddock profile hscolour" )
+
+myGentooRepo :: Maybe String
+myGentooRepo = unsafePerformIO $ do
+	hd <- getHomeDirectory
+	let confFile = hd </> ".cabal2ebuild" </> "gentoo_repo.txt"
+	fe <- doesFileExist confFile
+	if not fe then return Nothing else
+		fromConfigFile <$> readFile confFile
+
+fromConfigFile :: String -> Maybe String
+fromConfigFile cnt = case lines cnt of
+	["local", repo] -> Just repo
+	_ -> Nothing
+
+makeSrcURI :: String -> String
+-- makeSrcURI nam = show ( "http://homepage3.nifty.com/salamander/second/portage/distfiles/" ++ nam ++ ".tar.gz" )
+makeSrcURI nam = case myGentooRepo of
+	Just r -> show $ r ++ nam ++ ".tar.gz"
+	_ -> show $ "http://hackage.haskell.org/package/" ++ nam ++ "/" ++
+		nam ++ ".tar.gz"
+
+makeLicense :: License -> String
+makeLicense l = "LICENSE=" ++ show ( show l )
+
+getName :: GenericPackageDescription -> String
+getName gpd = let pd = packageDescription gpd
+                  PackageName pn = pkgName $ package pd
+                  vn = showVersion $ pkgVersion $ package pd
+               in pn ++ "-" ++ vn
+
+getLicense :: GenericPackageDescription -> License
+getLicense = license . packageDescription
+
+hasLib :: GenericPackageDescription -> Bool
+hasLib = isJust . condLibrary
+
+hasEx :: GenericPackageDescription -> Bool
+hasEx = not . null . condExecutables
