# -----------------------------------------------------------------------------
-# $Id: Makefile,v 1.25 2001/10/23 16:31:05 rrt Exp $
+# To compile with nhc98 on unix:
+# nhc98 -cpp -package base -o hsc2hs-bin Main.hs
TOP=../..
include $(TOP)/mk/boilerplate.mk
INSTALLING=1
-ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
+SRC_HC_OPTS += -i$(GHC_LIB_COMPAT_DIR)
+SRC_LD_OPTS += -L$(GHC_LIB_COMPAT_DIR) -lghccompat
+
+# This is required because libghccompat.a must be built with
+# $(GhcHcOpts) because it is linked to the compiler, and hence
+# we must also build with $(GhcHcOpts) here:
+SRC_HC_OPTS += $(GhcHcOpts)
+
HS_PROG = hsc2hs-bin
-else
-HS_PROG = hsc2hs
+ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
+HS_PROG = hsc2hs$(exeext)
+endif
+ifeq "$(HOSTPLATFORM)" "i386-unknown-cygwinw32"
+HS_PROG = hsc2hs$(exeext)
endif
-SRC_HC_OPTS += -package util -cpp
-ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-SRC_HC_OPTS += -package win32
-endif
-ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
+ifeq "$(ghc_ge_504)" "NO"
+SRC_HC_OPTS += -package util
+endif
+
+# Note: Somehow we should pass $(exeext) here, but the history of changes used
+# for calling the C preprocessor via GHC has changed a few times, making a
+# clean solution impossible. So we revert to a hack in Main.hs...
+SRC_HC_OPTS += -Wall
+
+ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
INSTALLED_SCRIPT_PROG = hsc2hs
endif
INPLACE_SCRIPT_PROG = hsc2hs-inplace
endif # BIN_DIST
else
HSC2HS_BINDIR=$(FPTOOLS_TOP_ABS)/$(CURRENT_DIR)
-HSC2HS_DIR=$(FPTOOLS_TOP_ABS)/$(CURRENT_DIR)
-ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
-HSC2HS_EXTRA="--cc=$(CC) --cflag=-D__GLASGOW_HASKELL__=$(ProjectVersionInt) -I$(FPTOOLS_TOP_ABS)/$(INCLUDE_DIR)"
-else
+HSC2HS_DIR=$(FPTOOLS_TOP_ABS_PLATFORM)/$(CURRENT_DIR)
+
+ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
extra_flags=$(addprefix --cflag=,$(filter-out -O,$(SRC_CC_OPTS)))
-HSC2HS_EXTRA="--cc=$(CC) $(extra_flags) --cflag=-D__GLASGOW_HASKELL__=$(ProjectVersionInt) -I$(FPTOOLS_TOP_ABS)/$(INCLUDE_DIR)"
endif
+
+HSC2HS_EXTRA="--cc=$(CC) --ld=$(CC) $(extra_flags) --cflag=-D__GLASGOW_HASKELL__=$(ProjectVersionInt) -I$(FPTOOLS_TOP_ABS_PLATFORM)/$(INCLUDE_DIR)"
endif
$(SCRIPT_PROG) : Makefile
override datadir=$(libdir)
INSTALL_DATAS += template-hsc.h
-# -----------------------------------------------------------------------------
-# Create driver configuration
-
-CONFIG_HS = Config.hs
-
-boot :: $(CONFIG_HS)
-
-all :: $(CONFIG_HS)
-
-$(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk Makefile
- @$(RM) -f $(CONFIG_HS)
- @echo -n "Creating $(CONFIG_HS) ... "
- @echo "module Config where" >>$(CONFIG_HS)
- @echo "cDEFAULT_TMPDIR = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
- @echo "cGCC = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
- @echo done.
-
-CLEAN_FILES += $(CONFIG_HS)
+# This is horrible. We ought to be able to omit the entire directory
+# from mkDependHS.
+SRC_MKDEPENDHS_OPTS += \
+ -optdep--exclude-module=Compat.RawSystem \
+ -optdep--exclude-module=Compat.Directory \
+ -optdep--exclude-module=Distribution.Compat.ReadP \
+ -optdep--exclude-module=Distribution.Extension \
+ -optdep--exclude-module=Distribution.GetOpt \
+ -optdep--exclude-module=Distribution.InstalledPackageInfo \
+ -optdep--exclude-module=Distribution.License \
+ -optdep--exclude-module=Distribution.Package \
+ -optdep--exclude-module=Distribution.ParseUtils \
+ -optdep--exclude-module=Distribution.Setup \
+ -optdep--exclude-module=Distribution.Version \
+ -optdep--exclude-module=System.Directory.Internals
+# -----------------------------------------------------------------------------
# don't recurse on 'make install'
#
ifeq "$(INSTALLING)" "1"
-all clean distclean maintainer-clean ::
+all :: $(HS_PROG)
$(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
-endif
-MKDEPENDHS_SRCS += $(CONFIG_HS)
+clean distclean maintainer-clean ::
+ $(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
+endif
include $(TOP)/mk/target.mk
-
-# hsc2hs-inplace is needed to boot in ghc/lib/std...
-ifneq "$(BootingFromHc)" "YES"
-boot :: all
-endif