diff --git a/src/server/Setup.hs b/src/server/Setup.hs index c46cb0330..290fa3b8b 100644 --- a/src/server/Setup.hs +++ b/src/server/Setup.hs @@ -1,6 +1,89 @@ -module Main where +{-# OPTIONS_GHC -fwarn-unused-imports #-} + +import Control.Monad(when) +import System.Directory(createDirectoryIfMissing,doesFileExist, + getDirectoryContents,copyFile,removeFile) +import System.FilePath((>)) +import System.Cmd(system) +import System.Exit(ExitCode(..)) import Distribution.Simple +import Distribution.Simple.Setup +import Distribution.Simple.LocalBuildInfo(datadir,buildDir,absoluteInstallDirs) main :: IO () -main = defaultMainWithHooks simpleUserHooks +main = defaultMainWithHooks simpleUserHooks{ postInst = instWWW + , postCopy = copyWWW + } +-------------------------------------------------------------------------------- +-- To test the GF web service and minibar, use "cabal install" (or +-- "runhaskell Setup.hs install") to install the program pgf-http, the +-- example grammars listed below, and the minibar. Then start the server with +-- the command "pgf-http" and open http://localhost:41296/minibar/minibar.html +-- in your web browser (Firefox, Safari, Opera or Chrome). + +example_grammars = + -- (pgf, tmp, src) + [("Foods.pgf","foods", + "..">"..">"contrib">"summerschool">"foods">"Foods???.gf"), + ("Letter.pgf","letter", + "..">"..">"examples">"letter">"Letter???.gf")] + +minibar_src = "..">"runtime">"javascript">"minibar" + +-------------------------------------------------------------------------------- +instWWW args flags pki lbi = setupWWW args dest pki lbi + where + dest = NoCopyDest + +copyWWW args flags pki lbi = setupWWW args dest pki lbi + where + dest = case copyDest flags of + NoFlag -> NoCopyDest + Flag d -> d + +setupWWW args dest pkg lbi = + do mapM_ (createDirectoryIfMissing True) [grammars_dir,minibar_dir] + mapM_ build_pgf example_grammars + copy_minibar + create_root_index + where + grammars_dir = www_dir > "grammars" + minibar_dir = www_dir > "minibar" + www_dir = datadir (absoluteInstallDirs pkg lbi dest) > "www" + gfo_dir = buildDir lbi > "gfo" + + build_pgf (pgf,tmp,src) = + do createDirectoryIfMissing True tmp_dir + execute cmd + copyFile pgf (grammars_dir>pgf) + removeFile pgf + where + tmp_dir = gfo_dir>tmp + cmd = "gf -make -s -optimize-pgf --gfo-dir="++tmp_dir++ + -- " --output-dir="++grammars_dir++ -- has no effect?! + " "++src + + copy_minibar = + do files <- getDirectoryContents minibar_src + mapM_ copy files + where + copy file = + do isFile <- doesFileExist src + when isFile $ copyFile src (minibar_dir>file) + where + src = minibar_src>file + + create_root_index = writeFile (www_dir>"index.html") index_html + + index_html = "
"++grammars_dir++""
+execute command =
+ do putStrLn command
+ e <- system command
+ case e of
+ ExitSuccess -> return ()
+ _ -> fail "Command failed"
+ return ()
diff --git a/src/server/gf-server.cabal b/src/server/gf-server.cabal
index 8551f0e51..fe7ad17c8 100644
--- a/src/server/gf-server.cabal
+++ b/src/server/gf-server.cabal
@@ -1,7 +1,7 @@
name: gf-server
version: 1.0
cabal-version: >= 1.2
-build-type: Simple
+build-type: Custom
license: GPL
license-file: LICENSE
synopsis: FastCGI Server for Grammatical Framework