Permalink
Browse files

More cabalization

Generate the templates and wrappers via Cabal and use autoconf/make only for
the generation of the documentation. Some code from Happy has been re-used
through highly advanced cut-n-paste technology.

TODO: Nuke the shell wrapper + proprietary Haskell code and use Cabal facilities
for accessing the templates and wrappers.
  • Loading branch information...
1 parent 07b6eb6 commit 00e0242cf1cc6e09561571fd196d2ef397ef0866 sven.panne@aedion.de committed Apr 21, 2006
Showing with 104 additions and 165 deletions.
  1. +0 −6 Makefile
  2. +97 −2 Setup.lhs
  3. +5 −3 alex.spec
  4. +2 −3 doc/Makefile
  5. +0 −27 mk/boilerplate.mk
  6. +0 −12 mk/config.mk
  7. +0 −10 mk/target.mk
  8. +0 −18 mk/version.mk
  9. +0 −84 src/Makefile
View
@@ -1,6 +0,0 @@
-TOP = .
-include $(TOP)/mk/boilerplate.mk
-
-SUBDIRS = src templates doc
-
-include $(TOP)/mk/target.mk
View
@@ -1,6 +1,101 @@
#!/usr/bin/runhaskell
\begin{code}
-import Distribution.Simple
-main = defaultMain
+module Main where
+
+import Control.Exception ( finally )
+import Distribution.PackageDescription ( PackageDescription )
+import Distribution.Setup ( BuildFlags, CleanFlags, CopyDest(..), CopyFlags(..), InstallFlags )
+import Distribution.Simple ( defaultMainWithHooks, defaultUserHooks, UserHooks(..), Args, compilerPath )
+import Distribution.Simple.LocalBuildInfo ( LocalBuildInfo(..), mkDataDir )
+import System.Directory ( removeFile, copyFile, getCurrentDirectory, setCurrentDirectory, createDirectoryIfMissing )
+import System.Exit ( ExitCode(..) )
+import System.IO ( FilePath )
+import System.Process ( runCommand, waitForProcess )
+import Text.Printf ( printf )
+
+main :: IO ()
+main = defaultMainWithHooks defaultUserHooks{ postBuild = myPostBuild,
+ postClean = myPostClean,
+ postCopy = myPostCopy,
+ postInst = myPostInstall }
+
+myPostBuild :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ExitCode
+myPostBuild _ _ _ lbi =
+ excursion "templates" $ do
+ let cpp_template src dst opts = do
+ let dst_pp = dst ++ ".hspp"
+ cmd = printf "%s -E -cpp -o %s %s %s"
+ (compilerPath (compiler lbi)) dst_pp src (unwords opts)
+ -- hack to turn cpp-style '# 27 "GenericTemplate.hs"' into
+ -- '{-# LINE 27 "GenericTemplate.hs" #-}'.
+ perl = printf "perl -pe \'s/^#\\s+(\\d+)\\s+(\"[^\"]*\")/{-# LINE \\1 \\2 #-}/g;s/\\$(Id:.*)\\$/\\1/g' < %s > %s" dst_pp dst
+ do_cmd cmd `cmd_seq` do_cmd perl
+ cmd_seqs ([ cpp_template "GenericTemplate.hs" dst opts | (dst,opts) <- templates ] ++
+ [ cpp_template "wrappers.hs" dst opts | (dst,opts) <- wrappers ])
+
+myPostClean :: Args -> CleanFlags -> PackageDescription -> Maybe LocalBuildInfo -> IO ExitCode
+myPostClean _ _ _ _ =
+ excursion "templates" $ do
+ sequence [ removeFile f >> removeFile (f ++ ".hspp") | (f,_) <- all_templates]
+ return ExitSuccess
+
+myPostInstall :: Args -> InstallFlags -> PackageDescription -> LocalBuildInfo -> IO ExitCode
+myPostInstall _ _ pkg_descr lbi =
+ install pkg_descr lbi NoCopyDest
+
+myPostCopy :: Args -> CopyFlags -> PackageDescription -> LocalBuildInfo -> IO ExitCode
+myPostCopy _ copy_flags pkg_descr lbi =
+ install pkg_descr lbi (copyDest copy_flags)
+
+install :: PackageDescription -> LocalBuildInfo -> CopyDest -> IO ExitCode
+install pkg_descr lbi copy_dest =
+ excursion "templates" $ do
+ let dataDir = mkDataDir pkg_descr lbi copy_dest
+ createDirectoryIfMissing True dataDir
+ sequence [ copyFile f (dataDir ++ '/':f) | (f,_) <- all_templates ]
+ -- XXX: joinFileName
+ return ExitSuccess
+
+all_templates :: [(FilePath,[String])]
+all_templates = templates ++ wrappers
+
+templates :: [(FilePath,[String])]
+templates = [
+ ("AlexTemplate", []),
+ ("AlexTemplate-ghc", ["-DALEX_GHC"]),
+ ("AlexTemplate-ghc-debug", ["-DALEX_GHC","-DALEX_DEBUG"]),
+ ("AlexTemplate-debug", ["-DALEX_DEBUG"])
+ ]
+
+wrappers :: [(FilePath,[String])]
+wrappers = [
+ ("AlexWrapper-basic", ["-DALEX_BASIC"]),
+ ("AlexWrapper-posn", ["-DALEX_POSN"]),
+ ("AlexWrapper-monad", ["-DALEX_MONAD"]),
+ ("AlexWrapper-gscan", ["-DALEX_GSCAN"])
+ ]
+
+-- -----------------------------------------------------------------------------
+-- Utils
+
+do_cmd :: String -> IO ExitCode
+do_cmd c = do
+ putStrLn c
+ runCommand c >>= waitForProcess
+
+cmd_seq :: IO ExitCode -> IO ExitCode -> IO ExitCode
+cmd_seq c1 c2 = do
+ e <- c1
+ case e of
+ ExitSuccess -> c2
+ _ -> return e
+
+cmd_seqs :: [IO ExitCode] -> IO ExitCode
+cmd_seqs = foldr cmd_seq (return ExitSuccess)
+
+excursion :: FilePath -> IO a -> IO a
+excursion d io = do
+ cwd <- getCurrentDirectory
+ (do setCurrentDirectory d; io) `finally` setCurrentDirectory cwd
\end{code}
View
@@ -24,13 +24,15 @@ expressions. It is similar to the tool lex or flex for C/C++.
%setup -n alex-%{version}
%build
+runhaskell Setup.lhs configure --prefix=%{prefix}
+runhaskell Setup.lhs build
+cd doc
test -f configure || autoreconf
-./configure --prefix=%{prefix}
-make
+./configure
make html
%install
-make prefix=${RPM_BUILD_ROOT}%{prefix} install
+runhaskell Setup.lhs copy --destdir=${RPM_BUILD_ROOT}
%clean
rm -rf ${RPM_BUILD_ROOT}
View
@@ -1,7 +1,6 @@
-TOP=..
-include $(TOP)/mk/boilerplate.mk
+include config.mk
XML_DOC = alex
INSTALL_XML_DOC = alex
-include $(TOP)/mk/target.mk
+include docbook-xml.mk
View
@@ -1,27 +0,0 @@
-# Begin by slurping in the boilerplate from one level up.
-# Remember, TOP is the top level of the innermost level
-# (FPTOOLS_TOP is the fptools top)
-
--include $(TOP)/mk/version.mk
-
-# We need to set TOP to be the TOP that the next level up expects!
-# The TOP variable is reset after the inclusion of the fptools
-# boilerplate, so we stash TOP away first:
-ALEX_TOP := $(TOP)
-TOP:=$(TOP)/..
-
-ALEX_INPLACE = $(ALEX_TOP)/src/alex-inplace
-
-include $(TOP)/mk/boilerplate.mk
-
-# Reset TOP
-TOP:=$(ALEX_TOP)
-
-# -----------------------------------------------------------------
-# Everything after this point
-# augments or overrides previously set variables.
-# -----------------------------------------------------------------
-
--include $(TOP)/mk/paths.mk
--include $(TOP)/mk/opts.mk
--include $(TOP)/mk/suffix.mk
View
@@ -1,12 +0,0 @@
-#
-# Alex project information
-#
-
-# what to include in a binary distribution
-AlexMainDir = alex
-AlexBinDistDirs = alex
-AlexBinDistDocs = alex/doc
-AlexBinDistShScripts = alex-$(ProjectVersion)
-AlexBinDistLinks = alex
-
-include $(AlexMainDir)/mk/version.mk
View
@@ -1,10 +0,0 @@
-# We need to set TOP to be the TOP that the next level up expects!
-# The TOP variable is reset after the inclusion of the fptools
-# boilerplate, so we stash TOP away first:
-ALEX_TOP := $(TOP)
-TOP:=$(TOP)/..
-
-include $(TOP)/mk/target.mk
-
-# Reset TOP
-TOP:=$(ALEX_TOP)
View
@@ -1,18 +0,0 @@
-#
-# Project-specific version information.
-#
-# Note:
-# this config file is intended to centralise all
-# project version information. To bump up the version
-# info on your package, edit this file and recompile
-# all the dependents. This file lives in the source tree.
-#
-
-#
-# happy project variable settings:
-#
-ProjectName = Alex
-ProjectNameShort = alex
-ProjectVersion = 2.0.1
-ProjectVersionInt = 200
-ProjectPatchLevel = 1
View
@@ -1,84 +0,0 @@
-TOP = ..
-include $(TOP)/mk/boilerplate.mk
-
-INSTALLING=1
-
-ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-HS_PROG_EXT = .exe
-else
-HS_PROG_EXT = .bin
-endif
-
-HS_PROG = alex$(HS_PROG_EXT)
-
-ifeq "$(Windows)" "YES"
-Main_HC_OPTS += -Dmingw32_HOST_OS=1
-endif
-
-# -----------------------------------------------------------------------------
-
-ifeq "$(INSTALLING)" "1"
-ifeq "$(BIN_DIST)" "1"
-ALEXLIB=$$\"\"libdir
-ALEXBIN=$$\"\"libexecdir/$(HS_PROG)
-else
-ALEXLIB=$(libdir)
-ALEXBIN=$(libexecdir)/$(HS_PROG)
-endif # BIN_DIST
-else
-ALEXLIB=$(FPTOOLS_TOP_ABS)/alex/templates
-ALEXBIN=$(FPTOOLS_TOP_ABS)/alex/src/$(HS_PROG)
-endif
-
-INSTALLED_SCRIPT_PROG = alex-$(ProjectVersion)
-INPLACE_SCRIPT_PROG = alex-inplace
-
-ifeq "$(INSTALLING)" "1"
-TOP_PWD := $(prefix)
-SCRIPT_PROG = $(INSTALLED_SCRIPT_PROG)
-ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-LINK = alex
-endif
-else
-TOP_PWD := $(FPTOOLS_TOP_ABS)
-SCRIPT_PROG = $(INPLACE_SCRIPT_PROG)
-endif
-
-SCRIPT_OBJS=alex.sh
-
-INTERP=$(SHELL)
-
-SCRIPT_SUBST_VARS = \
- ALEXLIB \
- ALEXBIN
-
-# The script isn't installed on Windows; we run the binary directly
-ifeq "$(Windows)" "NO"
-INSTALL_SCRIPTS += $(SCRIPT_PROG)
-endif
-
-INSTALL_LIBEXECS = $(HS_PROG)
-
-# Hack to avoid automatic cleaning machinery from cleaning Scan.hs
-#
-DERIVED_ALEX_SRCS =
-
-# don't recurse on 'make install'
-#
-ifeq "$(INSTALLING)" "1"
-all clean distclean maintainer-clean ::
- $(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
-endif
-
-# -----------------------------------------------------------------------------
-# Testing
-
-cmp :: Scan.hs
- ./alex-inplace Scan.x -o Scan.hs-CMP
- cmp Scan.hs Scan.hs-CMP
-
-CLEAN_FILES += Scan.hs-CMP
-
-# -----------------------------------------------------------------------------
-
-include $(TOP)/mk/target.mk

0 comments on commit 00e0242

Please sign in to comment.