diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,2 +1,18 @@
+2022-05-30 v0.0.4
+	* Injecting cabal flags via environment variable. [#13](https://github.com/kazu-yamamoto/hhp/pull/13)
+	* Update to handle sub-libraries in .cabal file. [#14](https://github.com/kazu-yamamoto/hhp/pull/14)
+
+2022-07-21 v0.0.3
+	* fixing test due to hlint change.
+	* supporting GHC 8.10
+
+2019-10-03 v0.0.2
+	* supporting Cabal 3.0 and GHC 8.8.
+
+2019-06-21 v0.0.1
+	* setting PartialTypeSignatures and NamedWildCards for check
+	* Remap save-buffer to hhp-save-buffer [#6](https://github.com/kazu-yamamoto/hhp/pull/6)
+	* using "-fdefer-typed-holes" for check.
+
 2018-12-18 v0.0.0
 	* First release
diff --git a/hhp.cabal b/hhp.cabal
--- a/hhp.cabal
+++ b/hhp.cabal
@@ -1,5 +1,5 @@
 Name:                   hhp
-Version:                0.0.3
+Version:                0.0.4
 Author:                 Kazu Yamamoto <kazu@iij.ad.jp>
 Maintainer:             Kazu Yamamoto <kazu@iij.ad.jp>
 License:                BSD3
@@ -90,7 +90,6 @@
   Build-Depends:        base >= 4.9 && < 5
                       , directory
                       , filepath
-                      , ghc
                       , hhp
 
 Executable hhpi
@@ -103,7 +102,6 @@
                       , containers
                       , directory
                       , filepath
-                      , ghc
                       , hhp
 
 Test-Suite doctest
@@ -161,6 +159,7 @@
                       , containers
                       , deepseq
                       , directory
+                      , extra
                       , filepath
                       , ghc
                       , hspec >= 1.7.1
@@ -168,6 +167,7 @@
                       , syb
                       , hlint >= 1.7.1
                       , ghc-boot
+  build-tool-depends: hspec-discover:hspec-discover
 
 Source-Repository head
   Type:                 git
diff --git a/lib/Hhp.hs b/lib/Hhp.hs
--- a/lib/Hhp.hs
+++ b/lib/Hhp.hs
@@ -28,6 +28,8 @@
   , rootInfo
   , packageDoc
   , findSymbol
+  -- * Misc
+  , cProjectVersion
   ) where
 
 import Hhp.Boot
@@ -43,3 +45,5 @@
 import Hhp.List
 import Hhp.PkgDoc
 import Hhp.Types
+
+import Config (cProjectVersion)
diff --git a/lib/Hhp/CabalApi.hs b/lib/Hhp/CabalApi.hs
--- a/lib/Hhp/CabalApi.hs
+++ b/lib/Hhp/CabalApi.hs
@@ -27,21 +27,23 @@
 import Distribution.PackageDescription.Configuration (finalizePD)
 import Distribution.PackageDescription.Parsec (readGenericPackageDescription)
 import Distribution.Types.ComponentRequestedSpec (defaultComponentRequestedSpec)
-import Distribution.Types.Flag (mkFlagAssignment)
+import Distribution.Types.Flag (mkFlagAssignment, mkFlagName)
 import Distribution.Types.PackageName (unPackageName)
 #elif MIN_VERSION_Cabal(2,2,0)
 import Distribution.PackageDescription.Configuration (finalizePD)
 import Distribution.PackageDescription.Parsec (readGenericPackageDescription)
 import Distribution.Types.ComponentRequestedSpec (defaultComponentRequestedSpec)
-import Distribution.Types.GenericPackageDescription (mkFlagAssignment)
+import Distribution.Types.GenericPackageDescription (mkFlagAssignment, mkFlagName)
 import Distribution.Types.PackageName (unPackageName)
 #elif MIN_VERSION_Cabal(2,0,0)
 import Distribution.PackageDescription.Configuration (finalizePD)
 import Distribution.PackageDescription.Parse (readPackageDescription)
 import Distribution.Types.ComponentRequestedSpec (defaultComponentRequestedSpec)
+import Distribution.Types.GenericPackageDescription (mkFlagName)
 import Distribution.Types.PackageName (unPackageName)
 #else
 import Distribution.Package (PackageName(PackageName))
+import Distribution.PackageDescription (FlagName (FlagName))
 import Distribution.PackageDescription.Configuration (finalizePackageDescription)
 import Distribution.PackageDescription.Parse (readPackageDescription)
 #endif
@@ -52,6 +54,7 @@
 import Data.Maybe (maybeToList, mapMaybe)
 import Data.Set (fromList, toList)
 import System.Directory (doesFileExist)
+import System.Environment (lookupEnv)
 import System.FilePath (dropExtension, takeFileName, (</>))
 
 import Hhp.Types
@@ -125,25 +128,33 @@
 #else
     epgd <- readPackageDescription silent file
 #endif
-    case toPkgDesc cid' epgd of
+    flags <- getFlags
+    case toPkgDesc cid' flags epgd of
         Left deps    -> throwIO $ userError $ show deps ++ " are not installed"
         Right (pd,_) -> if nullPkg pd
                         then throwIO $ userError $ file ++ " is broken"
                         else return pd
   where
+    envFlags = do
+      let parseF []      = []
+          parseF ccs@(c:cs)
+            | c == '-'   = [(mkFlagName cs, False)]
+            | otherwise  = [(mkFlagName ccs, True)]
+      maybe [] (concatMap parseF . words) `fmap` lookupEnv "HHP_CABAL_FLAGS"
 #if MIN_VERSION_Cabal(2,2,0)
-    none = mkFlagAssignment []
+    getFlags = mkFlagAssignment `fmap` envFlags
 #else
-    none = []
+    getFlags = envFlags
 #endif
 #if MIN_VERSION_Cabal(2,0,0)
     nullPkg pd = unPackageName (C.pkgName (P.package pd)) == ""
-    toPkgDesc cid = finalizePD none defaultComponentRequestedSpec (const True) buildPlatform cid []
+    toPkgDesc cid flags = finalizePD flags defaultComponentRequestedSpec (const True) buildPlatform cid []
 #else
+    mkFlagName = FlagName
     nullPkg pd = name == ""
       where
         PackageName name = C.pkgName (P.package pd)
-    toPkgDesc cid = finalizePackageDescription none (const True) buildPlatform cid []
+    toPkgDesc cid flags = finalizePackageDescription flags (const True) buildPlatform cid []
 #endif
 
 ----------------------------------------------------------------
@@ -174,9 +185,14 @@
 
 -- | Extracting all 'BuildInfo' for libraries, executables, and tests.
 cabalAllBuildInfo :: PackageDescription -> [BuildInfo]
-cabalAllBuildInfo pd = libBI ++ execBI ++ testBI ++ benchBI
+cabalAllBuildInfo pd = libBI ++ subBI ++ execBI ++ testBI ++ benchBI
   where
     libBI   = map P.libBuildInfo       $ maybeToList $ P.library pd
+#if MIN_VERSION_Cabal(2,0,0)
+    subBI   = map P.libBuildInfo       $ P.subLibraries pd
+#else
+    subBI   = []
+#endif
     execBI  = map P.buildInfo          $ P.executables pd
     testBI  = map P.testBuildInfo      $ P.testSuites pd
 #if __GLASGOW_HASKELL__ >= 704
diff --git a/lib/Hhp/Gap.hs b/lib/Hhp/Gap.hs
--- a/lib/Hhp/Gap.hs
+++ b/lib/Hhp/Gap.hs
@@ -17,9 +17,14 @@
   , languagesAndExtensions
   , mkFunTy
   , mkFunTys
+  , getModSummaryForMain
   ) where
 
+import Data.List (find)
+
 import DynFlags (DynFlags, supportedLanguagesAndExtensions)
+import GHC(Ghc,getModuleGraph,moduleNameString,moduleName,ms_mod)
+
 import GHC (LHsBind, LHsExpr, Type)
 #if __GLASGOW_HASKELL__ >= 808
 import GHC (Located, Pat)
@@ -47,6 +52,7 @@
 import GHC (mgModSummaries, ModSummary, ModuleGraph)
 #else
 import qualified Data.IntSet as I (IntSet, empty)
+import GHC (ModSummary)
 #endif
 
 #if __GLASGOW_HASKELL__ >= 810
@@ -179,3 +185,14 @@
 mkFunTys :: [Type] -> Type -> Type
 mkFunTys = mkVisFunTys
 #endif
+
+----------------------------------------------------------------
+
+getModSummaryForMain :: Ghc (Maybe ModSummary)
+#if __GLASGOW_HASKELL__ >= 804
+getModSummaryForMain = find isMain . mgModSummaries <$> getModuleGraph
+#else
+getModSummaryForMain = find isMain <$> getModuleGraph
+#endif
+  where
+    isMain m = moduleNameString (moduleName (ms_mod m)) == "Main"
diff --git a/lib/Hhp/Ghc.hs b/lib/Hhp/Ghc.hs
--- a/lib/Hhp/Ghc.hs
+++ b/lib/Hhp/Ghc.hs
@@ -21,6 +21,10 @@
   , lookupSym
   -- * Misc
   , getSystemLibDir
+  , liftIO
+  , runGhc
+  , getMainFileToBeDeleted
+  , Ghc
   ) where
 
 import Hhp.Boot
@@ -28,5 +32,27 @@
 import Hhp.Check
 import Hhp.Find
 import Hhp.GHCApi
+import Hhp.Gap
 import Hhp.Info
 import Hhp.List
+
+import GHC (runGhc)
+import CoreMonad (liftIO)
+import GHC (Ghc)
+import qualified GHC as G
+
+import Data.Maybe (fromMaybe)
+
+getMainFileToBeDeleted :: FilePath -> Ghc (Maybe FilePath)
+getMainFileToBeDeleted file = isSameMainFile file <$> getModSummaryForMain
+
+isSameMainFile :: FilePath -> Maybe G.ModSummary -> Maybe FilePath
+isSameMainFile _    Nothing  = Nothing
+isSameMainFile file (Just x)
+    | mainfile == file = Nothing
+    | otherwise        = Just mainfile
+  where
+    mmainfile = G.ml_hs_file (G.ms_location x)
+    -- G.ms_hspp_file x is a temporary file with CPP.
+    -- this is a just fake.
+    mainfile = fromMaybe (G.ms_hspp_file x) mmainfile
diff --git a/src/hhpc.hs b/src/hhpc.hs
--- a/src/hhpc.hs
+++ b/src/hhpc.hs
@@ -2,8 +2,6 @@
 
 module Main where
 
-import Config (cProjectVersion)
-
 import Control.Exception (Exception, Handler(..), ErrorCall(..))
 import qualified Control.Exception as E
 import Data.Typeable (Typeable)
diff --git a/src/hhpi.hs b/src/hhpi.hs
--- a/src/hhpi.hs
+++ b/src/hhpi.hs
@@ -18,20 +18,10 @@
 
 module Main where
 
-import Config (cProjectVersion)
-import CoreMonad (liftIO)
-import GHC (Ghc)
-#if __GLASGOW_HASKELL__ >= 804
-import GHC (mgModSummaries)
-#endif
-import qualified GHC as G
-
 import Control.Concurrent (forkIO, MVar, newEmptyMVar, putMVar, readMVar)
 import Control.Exception (SomeException(..), Exception)
 import qualified Control.Exception as E
 import Control.Monad (when, void)
-import Data.List (find)
-import Data.Maybe (fromMaybe)
 import Data.Set (Set)
 import qualified Data.Set as S
 import Data.Typeable (Typeable)
@@ -120,7 +110,7 @@
 ----------------------------------------------------------------
 
 run :: Cradle -> Maybe FilePath -> Options -> Ghc a -> IO a
-run cradle mlibdir opt body = G.runGhc mlibdir $ do
+run cradle mlibdir opt body = runGhc mlibdir $ do
     initializeFlagsWithCradle opt cradle
     body
 
@@ -178,30 +168,10 @@
     let set1
          | S.member file set = set
          | otherwise         = S.insert file set
-    mx <- isSameMainFile file <$> getModSummaryForMain
-    return $ case mx of
+    mf <- getMainFileToBeDeleted file
+    return $ case mf of
         Nothing       -> set1
         Just mainfile -> S.delete mainfile set1
-
-getModSummaryForMain :: Ghc (Maybe G.ModSummary)
-#if __GLASGOW_HASKELL__ >= 804
-getModSummaryForMain = find isMain . mgModSummaries <$> G.getModuleGraph
-#else
-getModSummaryForMain = find isMain <$> G.getModuleGraph
-#endif
-  where
-    isMain m = G.moduleNameString (G.moduleName (G.ms_mod m)) == "Main"
-
-isSameMainFile :: FilePath -> Maybe G.ModSummary -> Maybe FilePath
-isSameMainFile _    Nothing  = Nothing
-isSameMainFile file (Just x)
-    | mainfile == file = Nothing
-    | otherwise        = Just mainfile
-  where
-    mmainfile = G.ml_hs_file (G.ms_location x)
-    -- G.ms_hspp_file x is a temporary file with CPP.
-    -- this is a just fake.
-    mainfile = fromMaybe (G.ms_hspp_file x) mmainfile
 
 ----------------------------------------------------------------
 
diff --git a/test/CabalApiSpec.hs b/test/CabalApiSpec.hs
--- a/test/CabalApiSpec.hs
+++ b/test/CabalApiSpec.hs
@@ -5,6 +5,7 @@
 import Control.Exception
 import Data.Maybe
 import System.Directory
+import System.Environment (unsetEnv, setEnv)
 import System.FilePath
 import Test.Hspec
 
@@ -56,6 +57,25 @@
         it "extracts all hs-source-dirs including \".\"" $ do
             dirs <- cabalSourceDirs . cabalAllBuildInfo <$> parseCabalFile "test/data/cabalapi.cabal"
             dirs `shouldBe` [".", "test"]
+
+    describe "cabal-subLibraries" $ do
+        it "dependent packages with sublib" $ do
+            pkgs <- cabalDependPackages . cabalAllBuildInfo <$> parseCabalFile "test/data/check-sublib/check-sublib.cabal"
+            pkgs `shouldBe` ["array", "base", "bytestring"]
+
+    describe "HHP_CABAL_FLAGS" $ do
+        it "dependent packages without flags" $ do
+            unsetEnv "HHP_CABAL_FLAGS"
+            pkgs <- cabalDependPackages . cabalAllBuildInfo <$> parseCabalFile "test/data/check-flags/check-flags.cabal"
+            pkgs `shouldBe` ["base", "directory"]
+        it "dependent packages with foo flag" $ do
+            setEnv "HHP_CABAL_FLAGS" "foo"
+            pkgs <- cabalDependPackages . cabalAllBuildInfo <$> parseCabalFile "test/data/check-flags/check-flags.cabal"
+            pkgs `shouldBe` ["base", "directory", "filepath"]
+        it "dependent packages with foo and -bar flag" $ do
+            setEnv "HHP_CABAL_FLAGS" "foo -bar"
+            pkgs <- cabalDependPackages . cabalAllBuildInfo <$> parseCabalFile "test/data/check-flags/check-flags.cabal"
+            pkgs `shouldBe` ["base", "filepath"]
 
 {-
     describe "cabalAllBuildInfo" $ do
diff --git a/test/InfoSpec.hs b/test/InfoSpec.hs
--- a/test/InfoSpec.hs
+++ b/test/InfoSpec.hs
@@ -1,9 +1,9 @@
 module InfoSpec where
 
 import Data.List (isPrefixOf)
+import Data.List.Extra (replace)
 import System.Environment (getExecutablePath)
 import System.Exit
-import System.FilePath
 import System.Process
 import Test.Hspec
 
@@ -53,9 +53,6 @@
                 res `shouldSatisfy` ("bar :: [Char]" `isPrefixOf`)
 
         it "doesn't fail on unicode output" $ do
-            dir <- getDistDir
-            code <- rawSystem (dir </> "build/hhpc/hhpc") ["info", "test/data/Unicode.hs", "unicode"]
+            hhpcPath <- replace "/t/" "/x/" . replace "spec" "hhpc" <$> getExecutablePath
+            code <- rawSystem hhpcPath ["info", "test/data/Unicode.hs", "unicode"]
             code `shouldSatisfy` (== ExitSuccess)
-
-getDistDir :: IO FilePath
-getDistDir = takeDirectory . takeDirectory . takeDirectory <$> getExecutablePath
diff --git a/test/LintSpec.hs b/test/LintSpec.hs
--- a/test/LintSpec.hs
+++ b/test/LintSpec.hs
@@ -1,5 +1,6 @@
 module LintSpec where
 
+import Data.List.Extra
 import Test.Hspec
 
 import Hhp
@@ -9,7 +10,9 @@
     describe "lintSyntax" $ do
         it "check syntax with HLint" $ do
             res <- lintSyntax defaultOptions "test/data/hlint.hs"
-            res `shouldBe` "test/data/hlint.hs:5:16-26: Warning: Use sum\NULFound:\NUL  foldr (+) 0\NULPerhaps:\NUL  sum\n"
+            -- hlint displays additional line infomation
+            -- since unknown version (:5:16-26:)
+            replace "16-26" "16" res `shouldBe` "test/data/hlint.hs:5:16: Warning: Use sum\NULFound:\NUL  foldr (+) 0\NULPerhaps:\NUL  sum\n"
 
         context "without suggestions" $ do
             it "doesn't output empty line" $ do
diff --git a/test/data/hlint.hs b/test/data/hlint.hs
--- a/test/data/hlint.hs
+++ b/test/data/hlint.hs
@@ -3,3 +3,4 @@
 main :: IO ()
 main = do
     putStrLn $ foldr (+) 0 [0..10]
+    putStrLn "Hello"
