ifBuildable.hs 1.09 KB
Newer Older
Ian Lynagh's avatar
Ian Lynagh committed
1
2
3
4
5

module Main (main) where

import Control.Monad
import System.Cmd
6
import System.Directory
Ian Lynagh's avatar
Ian Lynagh committed
7
8
import System.Environment
import System.Exit
9
import System.IO
Ian Lynagh's avatar
Ian Lynagh committed
10
11

main :: IO ()
12
13
14
15
16
17
18
main = do args <- getArgs
          case args of
              [] ->
                  error "No package or command given"
              [_] ->
                  error "No command given"
              package : prog : progArgs ->
19
20
21
22
23
24
25
26
27
28
29
30
31
                  doit package prog progArgs

doit :: String -> String -> [String] -> IO ()
doit package prog progArgs
 = do setCurrentDirectory package
      unbuildable <- doesFileExist "unbuildable"
      if unbuildable
         then do mustBeBuildables <- getMustBeBuildablePackages
                 if package `elem` mustBeBuildables
                     then error (package ++ " is unbuildable")
                     else hPutStrLn stderr "Warning: Package is unbuildable"
         else do ec <- rawSystem prog progArgs
                 exitWith ec
Ian Lynagh's avatar
Ian Lynagh committed
32
33
34
35
36
37

getMustBeBuildablePackages :: IO [String]
getMustBeBuildablePackages
 = do xs <- readFile "../core-packages"
      return $ filter ("readline" /=) $ lines xs