@@ -6,15 +6,13 @@ import Foreign.Storable
66import Foreign.Marshal.Utils
77import Foreign.Ptr
88import System.Directory
9+ import System.Envirinment
910import System.FilePath
1011import System.Process
1112import MicroHs.Config
1213
1314type CConf = [(Key , Value )]
1415
15- confFile :: FilePath
16- confFile = " mhs.conf"
17-
1816theConfig :: String
1917theConfig | _isWindows = " windows"
2018 | otherwise = " unix"
@@ -27,8 +25,10 @@ doIt = False
2725
2826main :: IO ()
2927main = do
28+ args <- getArgs
29+ let flags = decodeArgs defaultFlags args
3030 home <- getHomeDirectory
31- confText <- readFile confFile
31+ confText <- readFile ( confFile flags)
3232 let conf = either (\ s -> error $ " cannot parse config " ++ s) id $
3333 parseConfig confFile confText
3434 cconf = fromMaybe (error $ " Cannot locate section " ++ theConfig) $
@@ -48,10 +48,12 @@ main = do
4848 mData = mCabalMhs </> " packages" </> (" mhs-" ++ version) </> " data"
4949 mkdir mData
5050 copy " mhs.conf" (mData </> " mhs.conf" )
51+ copyDir rts (mData </> rts)
5152
5253{-
5354MCABALMHS=$(MCABAL)/mhs-$(VERSION)
5455MDATA=$(MCABALMHS)/packages/mhs-$(VERSION)/data
56+ MRUNTIME=$(MDATA)/$(RTS)
5557 cp -r $(RTS)/* $(MRUNTIME)
5658 @mkdir -p $(MCABALMHS)
5759 bin/mhs -Q generated/base.pkg $(MCABALMHS)
@@ -126,3 +128,48 @@ copy src dst = do
126128 when doIt $ do
127129 copyFile src dst
128130 copyPermissions src dst
131+
132+ copyDir :: FilePath -> FilePath -> IO ()
133+ copyDir src dst = do
134+ mkdir dst
135+ let one file = do
136+ d <- doesDirectoryExist file
137+ (if d then copyDir else copy) (src </> d) (dst </> d)
138+ mapM_ one =<< listDirectory src
139+
140+ -----
141+
142+ data Flags = Flags
143+ { target :: String
144+ , dryRun :: Bool
145+ , verbose :: Bool
146+ , macros :: [String ]
147+ , goals :: [String ]
148+ , confFile :: FilePath
149+ }
150+ deriving (Show )
151+
152+ defaultFlags :: Flags
153+ defaultFlags = Flags
154+ { target = if _isWindows then " windows" else " unix"
155+ , dryRun = False
156+ , verbose = False
157+ , macros = []
158+ , goals = []
159+ , confFile = " mhs.conf"
160+ }
161+
162+ decodeArgs :: Flags -> [String ] -> Flags
163+ decodeArgs f [] = f
164+ decodeArgs f (arg: args) =
165+ case arg of
166+ " --help" -> error usage
167+ " -v" -> decodeArgs f{verbose = True } args
168+ " --dryrun" -> decodeArgs f{dryRun = True } args
169+ ' -' : ' t' : s -> decodeArgs f{target = s} mdls args
170+ ' -' : _ -> error $ " Unknown flag: " ++ arg ++ " \n " ++ usage
171+ _ | ' =' `elem` arg -> decodeArgs f{macros = macros f ++ [arg]} args
172+ | otherwise -> decodeArgs f{goals = goals f ++ [arg]} args
173+
174+ usage :: String
175+ usage = " \n install [--help] [-v] [--dryrun] [-tTARGET] [NAME=MACRO] [GOAL]\n "
0 commit comments