Skip to content
Browse files

Using cabal to build the RTS too

darcs-hash:20090426163329-6ac22-9d423edf98d8d41be557867d95aa28c814d0460f.gz
  • Loading branch information...
1 parent 5fe6bd7 commit 2546ded163a4189582b7e826af2d159b1e9419ea eb committed Apr 26, 2009
Showing with 58 additions and 24 deletions.
  1. +18 −7 Epic/Compiler.lhs
  2. +11 −11 Makefile
  3. +26 −0 Setup.hs
  4. +0 −4 Setup.lhs
  5. +3 −2 epic.cabal
View
25 Epic/Compiler.lhs
@@ -12,8 +12,7 @@
> module Epic.Compiler(CompileOptions(..),
> compile,
> compileOpts,
-> link,
-> libdir) where
+> link) where
Brings everything together; parsing, checking, code generation
@@ -26,7 +25,8 @@ Brings everything together; parsing, checking, code generation
> import Epic.Parser
> import Epic.Scopecheck
> import Epic.CodegenC
-> import Epic.Prefix
+
+> import Paths_epic
> -- | (Debugging) options to give to compiler
> data CompileOptions = KeepC -- ^ Keep intermediate C file
@@ -52,6 +52,11 @@ Brings everything together; parsing, checking, code generation
> compile fn outf iface
> = compileOpts fn outf iface []
+Chop off everything after the last / - get the directory a file is in
+
+> trimLast f = case span (\x -> x /= '/') (reverse f) of
+> (eman, htap) -> reverse htap
+
> compileOpts :: FilePath -- ^ Input file name
> -> FilePath -- ^ Output file name
> -> Maybe FilePath -- ^ Interface (.ei) file name, if desired
@@ -66,8 +71,11 @@ Brings everything together; parsing, checking, code generation
> Success ds -> do
> (tmpn,tmph) <- tempfile
> checked <- compileDecls (checkAll ds) tmph
+> fp <- getDataFileName "evm/closure.h"
+> let libdir = trimLast fp
> let cmd = "gcc -c -O2 -foptimize-sibling-calls -x c " ++ tmpn ++ " -I" ++ libdir ++ " -o " ++ outf ++ " " ++ addGCC opts ++ doTrace opts
> -- putStrLn $ cmd
+> -- putStrLn $ fp
> exit <- system cmd
> if (elem KeepC opts)
> then do system $ "cp " ++ tmpn ++ " " ++
@@ -100,6 +108,8 @@ Brings everything together; parsing, checking, code generation
> -> IO ()
> link infs extraIncs outf = do
> mainprog <- mkMain extraIncs
+> fp <- getDataFileName "evm/closure.h"
+> let libdir = trimLast fp
> let cmd = "gcc -x c -O2 -foptimize-sibling-calls " ++ mainprog ++ " -x none -L" ++
> libdir++" -I"++libdir ++ " " ++
> (concat (map (++" ") infs)) ++
@@ -116,16 +126,17 @@ Grr.)
> mkMain :: [FilePath] -> IO FilePath
> mkMain extra =
-> do mp <- readFile (libdir ++ "/mainprog.c")
+> do mppath <- getDataFileName "evm/mainprog.c"
+> mp <- readFile mppath
> (tmp, tmpH) <- tempfile
> hPutStr tmpH (concat (map (\x -> "#include <" ++ x ++ ">\n") extra))
> hPutStr tmpH mp
> hClose tmpH
> return tmp
-> -- |Get the path where the required C libraries and include files are stored
-> libdir :: FilePath
-> libdir = libprefix ++ "/lib/evm"
+ -- |Get the path where the required C libraries and include files are stored
+ libdir :: FilePath
+ libdir = libprefix ++ "/lib/evm"
> tempfile :: IO (FilePath, Handle)
> tempfile = do env <- environment "TMPDIR"
View
22 Makefile
@@ -2,32 +2,32 @@ DB = --user
PREFIX = $(HOME)
GHCOPTS =
-package: rts
- runhaskell Setup.lhs build
+package:
+ runhaskell Setup.hs build
cabal-package:
- runhaskell Setup.lhs sdist
+ runhaskell Setup.hs sdist
configure:
- runhaskell Setup.lhs configure --user --ghc --prefix=$(PREFIX)
- cd Epic; echo "module Epic.Prefix where libprefix=\"$(PREFIX)\"" > Prefix.hs
+ runhaskell Setup.hs configure --user --ghc --prefix=$(PREFIX)
+# cd Epic; echo "module Epic.Prefix where libprefix=\"$(PREFIX)\"" > Prefix.hs
rts:
$(MAKE) -C evm
-install: .PHONY rts
- $(MAKE) -C evm install PREFIX=$(PREFIX)
+install: .PHONY
+ #$(MAKE) -C evm install PREFIX=$(PREFIX)
#$(MAKE) -C lib install PREFIX=$(PREFIX)
- runhaskell Setup.lhs install $(DB)
+ runhaskell Setup.hs install $(DB)
unregister:
- runhaskell Setup.lhs unregister $(DB)
+ runhaskell Setup.hs unregister $(DB)
doc:
- runhaskell Setup.lhs haddock
+ runhaskell Setup.hs haddock
clean:
- runhaskell Setup.lhs clean
+ runhaskell Setup.hs clean
$(MAKE) -C evm clean
cd compiler; rm -f *.o *.hi epic
View
26 Setup.hs
@@ -0,0 +1,26 @@
+import Distribution.Simple
+import Distribution.PackageDescription
+
+import System
+
+-- After Epic is built, we need a run time system.
+
+-- FIXME: This is probably all done the wrong way, I don't really understand
+-- Cabal properly...
+
+buildLib args flags desc local
+ = do exit <- system "make -C evm"
+ return ()
+
+-- This is a hack. I don't know how to tell cabal that a data file needs
+-- installing but shouldn't be in the distribution. And it won't make the
+-- distribution if it's not there, so instead I just delete
+-- the file after configure.
+
+postConfLib args flags desc local
+ = do exit <- system "make -C evm clean"
+ return ()
+
+main = defaultMainWithHooks (simpleUserHooks { postBuild = buildLib,
+ postConf = postConfLib})
+
View
4 Setup.lhs
@@ -1,4 +0,0 @@
-> import Distribution.Simple
-
-> main = defaultMain
-
View
5 epic.cabal
@@ -1,5 +1,5 @@
Name: epic
-Version: 0.1.1
+Version: 0.1.2
Author: Edwin Brady
License: BSD3
License-file: LICENSE
@@ -21,5 +21,6 @@ Extensions: MultiParamTypeClasses, FunctionalDependencies,
Exposed-modules: Epic.Compiler
Other-modules: Epic.Bytecode Epic.Parser Epic.Scopecheck
Epic.Language Epic.Lexer Epic.CodegenC
- Epic.Prefix Epic.OTTLang
+ Epic.OTTLang Paths_epic
+Data-files: evm/libevm.a evm/closure.h evm/stdfuns.h evm/mainprog.c
Extra-source-files: evm/*.c evm/*.h evm/Makefile

0 comments on commit 2546ded

Please sign in to comment.
Something went wrong with that request. Please try again.