Fw: Haskell + automake?

Andre Pang andrep@cse.unsw.EDU.AU
Mon, 5 Aug 2002 22:35:35 +0800


--0F1p//8PRICkK4MW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

> Has anyone come up with some magic to let automake play nice with
> Haskell compilers (ghc 5 or nhc 98 preferred)?

I'll attach a Makefile.am.ghc file which I'm using for a current
project, along with an example Makefile.am, and another file
(Makefile.am.global) which you might want to use to set some
options like GHCFLAGS.

Hopefully the attachments won't get stripped/mangled -- drop me
a note if they do ...


-- 
#ozone/algorithm <andrep@cse.unsw.EDU.AU>          - b.sc (comp. sci+psych)

--0F1p//8PRICkK4MW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="Makefile.am"

include $(top_srcdir)/Makefile.am.global

SUBDIRS = \
	  core \
	  doc \
	  dynamic_test \
	  functions \
	  output_drivers \
	  parsec \
	  renderers \
	  runtime_loader \
	  tests

EXTRA_DIST = License.Clarified_Artistic \
	     License.GPL-2 \
	     BUGS \
	     TODO \
	     Makefile.am.ghc \
	     Makefile.am.global \
	     autoreconf

CLEANFILES += confdefs.h

##hdoc:
##	hdoc -d doc $(srcdir)/$(chiba_test_1_SOURCES)



--0F1p//8PRICkK4MW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="Makefile.am.ghc"

# Ultra-hack (or how to get GHC to play nicely^W with automake!)
#
# We use "ghc --make" to do the dependency tracking instead of automake having
# to realise what the dependencies are.  This is good, because "ghc --make"
# will undoubtedly be a lot more reliable than any ultra-boogie scripts that we
# could ever whip up.
#
# However, since "ghc --make" always wants to see the 'main' function in
# whatever .hs file you give it, we need to pass it the "-no-hs-main" option to
# stop it from trying to find 'main'.  This prevents GHC from spitting out an
# error and stopping the whole make process.
#
# Of course, in the event that GHC does actually find a 'main' function, it
# then decides to merrily link all the imported modules together to produce an
# executable, which is not what we want at all.  (Especially since the '-o'
# option tells GHC that we want an executable called "Foo.o", and it then tries
# to write over the existing Foo.o object file which it just compiled.  Arrgh.)
# So, to stop that, we, uhm, tell GHC to use the 'true' command for the linker,
# which doesn't do anything at all, besides return 0.
#
# I'm very proud of this hack :).

AM_GHC_DEPEND_FLAGS = -no-hs-main --make -pgmltrue -odir . -hidir .

DEFAULT_INCLUDES = -i$(srcdir)

#HMAKE_INCLUDES = $(DEFAULT_INCLUDES) -P$(srcdir)

AM_GHC_COMPILE_FLAGS = $(DEFS) $(GHC_PACKAGES) \
	  	  $(DEFAULT_INCLUDES) $(INCLUDES) \
	  	  $(AM_GHCFLAGS) $(GHCFLAGS)

# If the user has hmake, use that instead of ghc to compile stuff.  It's far
# less hacky than the evil --make -pgmltrue options above, and hmake is also
# a bit smarter in compiling stuff.  In particular, if you are importing an
# already-compiled module which resides in a different directory, GHC will go
# recompile the module again and put the compiled object in the current
# directory.  hmake will check the other directory and see that you've already
# compiled that module.

#if HMAKE
#COMPILE = $(HMAKE) -ghc $(AM_GHC_COMPILE_FLAGS)
#else
COMPILE = $(GHC) $(AM_GHC_DEPEND_FLAGS) $(AM_GHC_COMPILE_FLAGS)
#endif

## It seems that automake requires that you use "Suffix Rules", which are now
## deprecated by GNU make's Pattern Rules.  See the make info manual for more
## details.  (I suppose automake is also meant to work on systems without GNU
## make, though ...)

hs.o:
	$(COMPILE) -o $@ $<


# Use ghc as the linker

LINK = $(GHC) $(GHC_PACKAGES) $(AM_LDFLAGS) $(GHCFLAGS) -o $@


# Clean out .hi files too

CLEANFILES = *.hi


# Tell automake that .hs files compile to .o files

SUFFIXES = .hs



--0F1p//8PRICkK4MW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="Makefile.am.global"

# It seems that compiling with -O2 fixes some bugs which would otherwise
# appear.  In particular, the Dynamic types stuff seems to break if you omit
# the -O2 ...

GHCFLAGS = -fglasgow-exts -O2

# Almost every bit of code uses the lang package

GHC_PACKAGES = -package lang


# Hrm, why doesn't automake build this for me?  A bit lame, really :)

$(top_builddir)/runtime_loader/libRuntimeLoader.a:
	cd $(top_builddir) && make -C runtime_loader libRuntimeLoader.a

$(top_builddir)/core/libChiba.a:
	cd $(top_builddir) && make -C core libChiba.a

$(top_builddir)/core/libChibaRender.a:
	cd $(top_builddir) && make -C core libChibaRender.a

$(top_builddir)/core/libChibaHS.a:
	cd $(top_builddir) && make -C core libChibaHS.a

$(top_builddir)/parsec/libParsec.a:
	cd $(top_builddir) && make -C parsec libParsec.a


include $(top_srcdir)/Makefile.am.ghc


--0F1p//8PRICkK4MW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="configure.in"

AC_INIT(runtime_loader/RuntimeLoader.hs)

AM_INIT_AUTOMAKE(chiba, 0.2)

AC_PROG_MAKE_SET

# We need AC_PROG_CC to enable a whole host of auto{conf,make} stuff related to
# building programs (such as enabling the EXEEXT and OBJEXT variables, etc.)
# I guess one day we should have a AC_PROG_GHC m4 macro to do it, but this
# works for now.

AC_PROG_CC
#AC_PROG_CXX

# Needed to build a library out of the runtime loader
AC_PROG_RANLIB

AC_PROG_INSTALL
AC_PATH_PROG(TEST, test)


#
# Test for GHC: this handy autoconf macro blatantly stolen from HDoc
# http://www.fmi.uni-passau.de/~groessli/hdoc/
#

AC_ARG_WITH(ghc,
	    [  --with-ghc=GHC          where to find ghc],
	    [GHC=$withval])

if $TEST -z "$GHC"; then
  AC_CHECK_TOOL(GHC, ghc, ghc)
fi

GHC_FLAGS=""

if $TEST "$GHC"; then
	AC_MSG_CHECKING([for ghc version])
	changequote(<<, >>)
	ghc_version=`$GHC --version 2>&1 | sed -n -e 's/.* version \([0-9.][0-9.]*\).*/\1/p'`
	ghc_major=`echo "$ghc_version" | sed -n -e 's/\([0-9][0-9]*\).*/\1/p'`
	ghc_minor=`echo "$ghc_version" | sed -n -e 's/[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/p'`
	changequote([, ])
	AC_MSG_RESULT([$ghc_version])
	if $TEST "$ghc_major" -ge 5 -a "$ghc_minor" -ge 02; then
		GHCTYPE=ghc5
		AC_MSG_CHECKING([for ghc library directory])
		GHC_LIB_PATH=`$GHC --print-libdir`
		AC_MSG_RESULT([$GHC_LIB_PATH])
	else
		AC_MSG_ERROR([
			      ** Sorry, your GHC is too old. GHC >= 5.02 required.
			      ])
		GHC=""
		GHCTYPE=""
	fi
else
	AC_MSG_ERROR([
		      ** Could not find GHC.
		      ])
fi

AC_SUBST(GHC)
AC_SUBST(GHC_LIB_PATH)

#
# Test for hmake (broken right now -- it fails make distcheck ...)
#

#AC_ARG_WITH(hmake,
#        [  --with-hmake=HMAKE      where to find hmake (optional)],
#	[HMAKE=$withval])
#
#if $TEST -z "$HMAKE"; then
#  AC_CHECK_TOOL(HMAKE, hmake, hmake)
#fi
#
#AC_SUBST(HMAKE)
#AM_CONDITIONAL(HMAKE, test -n "$HMAKE")


#
# Thunderbirds are go!
#

AC_OUTPUT(
	  runtime_loader/GHCLibraryPath.hs

	  Makefile
	  core/Makefile
	  doc/Makefile
	  dynamic_test/Makefile
	  functions/Makefile
	  output_drivers/Makefile
	  parsec/Makefile
	  renderers/Makefile
	  runtime_loader/Makefile
	  tests/Makefile
	 )


--0F1p//8PRICkK4MW--