cymake.hs 1.66 KB
Newer Older
Björn Peemöller 's avatar
Björn Peemöller committed
1 2 3
{- |
    Module      :  $Header$
    Description :  Main module
4
    Copyright   :  (c) 2005, Martin Engelke  (men@informatik.uni-kiel.de)
Björn Peemöller 's avatar
Björn Peemöller committed
5 6 7 8 9 10
                       2011, Björn Peemöller (bjp@informatik.uni-kiel.de)
    License     :  OtherLicense

    Maintainer  :  bjp@informatik.uni-kiel.de
    Stability   :  experimental
    Portability :  portable
Bjoern Peemoeller's avatar
Bjoern Peemoeller committed
11 12 13 14 15 16

    Command line tool for generating Curry representations (e.g. FlatCurry,
    AbstractCurry) for a Curry source file including all imported modules.
-}
module Main (main) where

Björn Peemöller 's avatar
Björn Peemöller committed
17
import Base.Messages (putErrsLn, abortWith)
Bjoern Peemoeller's avatar
Bjoern Peemoeller committed
18 19
import Files.CymakePath (cymakeGreeting)
import Html.CurryHtml (source2html)
Björn Peemöller 's avatar
Björn Peemöller committed
20 21 22

import CurryBuilder (buildCurry)
import CompilerOpts (Options (..), compilerOpts, usage)
Bjoern Peemoeller's avatar
Bjoern Peemoeller committed
23 24 25

-- |The command line tool cymake
main :: IO ()
26
main = compilerOpts >>= cymake
Bjoern Peemoeller's avatar
Bjoern Peemoeller committed
27

Björn Peemöller 's avatar
Björn Peemöller committed
28
-- |Invoke the curry builder w.r.t the command line arguments
29 30
cymake :: (String, Options, [String], [String]) -> IO ()
cymake (prog, opts, files, errs)
31 32
  | optHelp opts    = printUsage prog
  | optVersion opts = printVersion
33
  | null files      = printUsage prog
Björn Peemöller 's avatar
Björn Peemöller committed
34
  | not $ null errs = badUsage prog errs
35 36
  | optHtml opts    = mapM_ (source2html opts) files
  | otherwise       = mapM_ (buildCurry  opts) files
37 38 39 40

-- |Print the program greeting
printVersion :: IO ()
printVersion = putStrLn cymakeGreeting
Bjoern Peemoeller's avatar
Bjoern Peemoeller committed
41

Björn Peemöller 's avatar
Björn Peemöller committed
42
-- |Print the usage information of the command line tool
43 44 45
printUsage :: String -> IO ()
printUsage prog = putStrLn $ usage prog

Björn Peemöller 's avatar
Björn Peemöller committed
46
-- |Print errors and abort execution on bad parameters
Bjoern Peemoeller's avatar
Bjoern Peemoeller committed
47 48 49 50
badUsage :: String -> [String] -> IO ()
badUsage prog errs = do
  putErrsLn $ map (\ err -> prog ++ ": " ++ err) errs
  abortWith ["Try '" ++ prog ++ " --help' for more information"]