ghcBinDir = /home/mechvel/ghc/6.2.2/inst/bin
#          
# EDIT these three! 
# $(s) is the Dumatel source directory,
# $(e) a directory the Dumatel library and interface to install to.
#
s = /home/mechvel/dm/1.02/dm/source
e = $(s)/export

ghc    = $(ghcBinDir)/ghc
ghcpkg = $(ghcBinDir)/ghc-pkg

# un-comment ONE of the below three lines - the one corresponding to
# `ar -s' command equivalent in your system:
#
RANLIB = ar -s
#
# RANLIB = ranlib
# RANLIB = true

language = -fglasgow-exts  -fallow-undecidable-instances       \
           -fallow-overlapping-instances                       \
           -fno-warn-overlapping-patterns  -fwarn-unused-binds \
           -fwarn-unused-matches  -fwarn-unused-imports
#
# overlaps are used slightly (Show, Cast)

idirs    =  demotest

HCFlags  =  $(language)  -i$(idirs) -odir $(e) -hidir $(e)   \
            -ddump-hi-diffs                                  \
            +RTS $(space) -RTS  $(extraHCOpts) 
 
space       = -M50m
extraHCOpts = 
#
#             -O  -fvia-C   -prof -auto-all  -hisuf p_hi -osuf p_o

pack = Package {name            = "\"dm\"",     \
                import_dirs     = ["\"$(e)\""], \
                source_dirs     = [],           \
                library_dirs    = ["\"$(e)\""], \
                hs_libraries    = ["\"HSdm\""], \
                extra_libraries = [], \
                include_dirs    = [], \
                c_includes      = [], \
                package_deps    = [\"data\"], \
                extra_ghc_opts  = [$(extraPackageOpts)], \
                extra_cc_opts   = [], \
                extra_ld_opts   = [] }

extraPackageOpts = $(planguage)
#
# `backslash' copy of $(language)
#
planguage = "\"-fglasgow-exts\"",                                  \
            "\"-fallow-undecidable-instances\"",                   \
            "\"-fallow-overlapping-instances\"",                   \
            "\"-fno-warn-overlapping-patterns\"",                  \
            "\"-fwarn-unused-binds\"","\"-fwarn-unused-matches\"", \
            "\"-fwarn-unused-imports\""

obj:
	if [ ! -d $(e) ]; then mkdir $(e); fi
	$(ghc) $(HCFlags) --make DExport  -package-name dm  

dm: obj
	rm -f  $(e)/libHSdm* $(e)/HSdm*
	ar -qc $(e)/libHSdm.a $(wildcard $(e)/*.o)
	$(RANLIB)  $(e)/libHSdm.a
	$(RANLIB)  $(e)/libHSdm.a
	echo $(pack) | $(ghcpkg) -f $(s)/dm.conf -u -g
	$(ghcpkg) -f $(s)/dm.conf -l
#
# o. files can be extracted from the library by  ar -x 
#
# for profiling:
#	ar -qc $(e)/libHSdm.a   $(wildcard $(e)/*.p_o)
#	ar -qc $(e)/libHSdm_p.a $(wildcard $(e)/*.p_o)
#	$(RANLIB)  $(e)/libHSdm_p.a
#	$(RANLIB)  $(e)/libHSdm_p.a
#
# no profilibg: 
#	ar -qc $(e)/libHSdm.a $(wildcard $(e)/*.o)
#	$(RANLIB)  $(e)/libHSdm.a
#	$(RANLIB)  $(e)/libHSdm.a


clearO:
	mv $(e)/HSdm.o   $(e)/to
	mv $(e)/HSdm_p.o $(e)/tp
	rm -f $(e)/*.o
	rm -f $(e)/*.p_o
	mv $(e)/to $(e)/HSdm.o 
	mv $(e)/tp $(e)/HSdm_p.o 

clearT:
	rm -f $(s)/demotest/*.hi $(s)/demotest/*.o $(s)/demotest/log
	rm -f $(s)/demotest/*.p_hi $(s)/demotest/*.p_o 

clearButInstall:
	rm -f  $(s)/*.hs  $(s)/log
	rm -rf $(s)/demotest

clear:
	$(ghcpkg) -f $(s)/dm.conf -r dm
	rm -rf $(e)
	rm -f $(s)/log
	rm -f $(s)/demotest/*.hi $(s)/demotest/*.o $(s)/demotest/log
	rm -f $(s)/demotest/*.p_hi $(s)/demotest/*.p_o 
