1 # -----------------------------------------------------------------------------
2 # To compile with nhc98 on unix:
3 # nhc98 -cpp -package base -o hsc2hs-bin Main.hs
6 include $(TOP)/mk/boilerplate.mk
8 # This causes libghccompat.a to be used:
9 include $(GHC_COMPAT_DIR)/compat.mk
11 # This is required because libghccompat.a must be built with
12 # $(GhcHcOpts) because it is linked to the compiler, and hence
13 # we must also build with $(GhcHcOpts) here:
14 SRC_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
17 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
18 HS_PROG = hsc2hs$(exeext)
20 ifeq "$(HOSTPLATFORM)" "i386-unknown-cygwinw32"
21 HS_PROG = hsc2hs$(exeext)
24 # Note: Somehow we should pass $(exeext) here, but the history of changes used
25 # for calling the C preprocessor via GHC has changed a few times, making a
26 # clean solution impossible. So we revert to a hack in Main.hs...
29 # -----------------------------------------------------------------------------
32 INPLACE_HS=hsc2hs-inplace.hs
33 INPLACE_PROG=hsc2hs-inplace
34 EXCLUDED_SRCS+=$(INPLACE_HS)
36 # FPTOOLS_TOP_ABS platform uses backslashes, at least on Cygwin, but that
37 # will go wrong when we use it in a Haskell string below.
38 TOP_ABS=$(subst \\,/,$(FPTOOLS_TOP_ABS_PLATFORM))
40 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
41 extra_flags=$(addprefix --cflag=,$(filter-out -O,$(SRC_CC_OPTS)))
46 $(INPLACE_HS): Makefile $(FPTOOLS_TOP)/mk/config.mk
47 echo "import System.Cmd; import System.Environment; import System.Exit" > $@
48 echo "main = do args <- getArgs; rawSystem \"$(TOP_ABS)/$(GHC_HSC2HS_DIR_REL)/$(HS_PROG)\" (\"--template=$(TOP_ABS)/$(GHC_HSC2HS_DIR_REL)/template-hsc.h\":\"--cc=$(CC)\":\"--ld=$(CC)\"$(patsubst %,:\"%\",$(extra_flags)):\"--cflag=-D__GLASGOW_HASKELL__=$(ProjectVersionInt)\":\"-I$(TOP_ABS)/$(GHC_INCLUDE_DIR_REL)\":\"-I$(TOP_ABS)/gmp/gmpbuild\":args) >>= exitWith" >> $@
50 $(INPLACE_PROG): $(INPLACE_HS)
51 $(GHC) --make $< -o $@
53 all :: $(INPLACE_PROG)
55 CLEAN_FILES += $(INPLACE_HS) $(INPLACE_PROG)
57 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
58 INSTALL_PROGS += $(HS_PROG)
60 INSTALL_LIBEXECS += $(HS_PROG)
62 LINK_TARGET = $(LINK)-$(ProjectVersion)
63 INSTALLED_SCRIPT=$(bindir)/$(LINK_TARGET)
65 $(RM) -f $(INSTALLED_SCRIPT)
66 echo "#!$(SHELL)" >> $(INSTALLED_SCRIPT)
67 echo "HSC2HS_BINDIR=$(libexecdir)" >> $(INSTALLED_SCRIPT)
68 echo "HSC2HS_DIR=$(libdir)" >> $(INSTALLED_SCRIPT)
69 echo "HS_PROG=$(HS_PROG)" >> $(INSTALLED_SCRIPT)
70 echo "HSC2HS_EXTRA=" >> $(INSTALLED_SCRIPT)
71 cat hsc2hs.sh >> $(INSTALLED_SCRIPT)
72 $(EXECUTABLE_FILE) $(INSTALLED_SCRIPT)
75 # -----------------------------------------------------------------------------
77 override datadir=$(libdir)
78 INSTALL_DATAS += template-hsc.h
81 $(INSTALL_DIR) $(BIN_DIST_DIR)/utils/hsc2hs
82 $(INSTALL_DATA) Makefile $(BIN_DIST_DIR)/utils/hsc2hs/
83 $(INSTALL_DATA) hsc2hs.sh $(BIN_DIST_DIR)/utils/hsc2hs/
84 $(INSTALL_DATA) $(INSTALL_DATAS) $(BIN_DIST_DIR)/utils/hsc2hs/
85 $(INSTALL_PROGRAM) $(HS_PROG) $(BIN_DIST_DIR)/utils/hsc2hs/
87 include $(TOP)/mk/target.mk