Skip to content

Commit 2f6eb53

Browse files
committed
More install stuff
1 parent 5a5a9ac commit 2f6eb53

2 files changed

Lines changed: 56 additions & 6 deletions

File tree

Tools/Install.hs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ import Foreign.Storable
66
import Foreign.Marshal.Utils
77
import Foreign.Ptr
88
import System.Directory
9+
import System.Envirinment
910
import System.FilePath
1011
import System.Process
1112
import MicroHs.Config
1213

1314
type CConf = [(Key, Value)]
1415

15-
confFile :: FilePath
16-
confFile = "mhs.conf"
17-
1816
theConfig :: String
1917
theConfig | _isWindows = "windows"
2018
| otherwise = "unix"
@@ -27,8 +25,10 @@ doIt = False
2725

2826
main :: IO ()
2927
main = 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
{-
5354
MCABALMHS=$(MCABAL)/mhs-$(VERSION)
5455
MDATA=$(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 = "\ninstall [--help] [-v] [--dryrun] [-tTARGET] [NAME=MACRO] [GOAL]\n"

lib/System/Directory.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,13 @@ createDirectoryIfMissing False d = do
120120
createDirectoryIfMissing True d = do
121121
let ds = scanl1 (\ x y -> x ++ "/" ++ y) . split [] $ d
122122
split r [] = [r]
123-
split r ('/':cs) = r : split [] cs
124-
split r (c:cs) = split (r ++ [c]) cs
123+
split r (c:cs) | isPathSeparator c = r : split [] cs
124+
| otherwise = split (r ++ [c]) cs
125125
mapM_ (createDirectoryIfMissing False) ds
126126

127+
isPathSeparator :: Char -> Bool
128+
isPathSeparator c = c == '/' || _isWindows && c == '\\'
129+
127130
-- XXX does not copy flags
128131
copyFile :: FilePath -> FilePath -> IO ()
129132
copyFile src dst = do

0 commit comments

Comments
 (0)