Cope with libraries in libraries/foo/bar rather than just libraries/foo
[ghc-hetmet.git] / libraries / ifBuildable.hs
1 -- Returns exitcode 0 if the given package is buildable or is a boot package,
2 -- and 1 otherwise.
3
4 module Main (main) where
5
6 import Control.Monad
7 import System.Directory
8 import System.Environment
9 import System.Exit
10 import System.IO
11
12 main :: IO ()
13 main = do args <- getArgs
14           case args of
15               [bootPackagesFile, package] ->
16                   doit bootPackagesFile package
17               _ ->
18                   error "Syntax: ifBuildable <boot-packages-file> <package>"
19
20 doit :: FilePath -> String -> IO ()
21 doit bootPackagesFile package
22  = do setCurrentDirectory package
23       unbuildable <- doesFileExist "unbuildable"
24       if not unbuildable
25          then exitWith ExitSuccess
26          else do mustBeBuildables <- getMustBeBuildables bootPackagesFile
27                  if package `elem` mustBeBuildables
28                      then exitWith ExitSuccess
29                      else do hPutStrLn stderr "Warning: Package is unbuildable"
30                              exitWith (ExitFailure 1)
31
32 getMustBeBuildables :: FilePath -> IO [String]
33 getMustBeBuildables bootPackagesFile
34  = do xs <- readFile bootPackagesFile
35       return $ filter ("editline" /=) $ lines xs
36