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 # Beyond stage 1, honour any Mac OS X depolyment target options. If we use
9 # these options in stage 1 we get a linker error if the bootstrap compiler is
10 # for a more recent OS version
12 SRC_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
13 SRC_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
14 SRC_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
17 # This causes libghccompat.a to be used:
18 include $(GHC_COMPAT_DIR)/compat.mk
20 # This is required because libghccompat.a must be built with
21 # $(GhcHcOpts) because it is linked to the compiler, and hence
22 # we must also build with $(GhcHcOpts) here:
23 SRC_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
25 # We have two version: the inplace version compiled by the bootstrap compiler
26 # and the install version compiled by the stage 1 compiler
30 HS_PROG = hsc2hs-inplace.bin
33 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
34 HS_PROG = hsc2hs$(exeext)
36 ifeq "$(HOSTPLATFORM)" "i386-unknown-cygwinw32"
37 HS_PROG = hsc2hs$(exeext)
40 # Note: Somehow we should pass $(exeext) here, but the history of changes used
41 # for calling the C preprocessor via GHC has changed a few times, making a
42 # clean solution impossible. So we revert to a hack in Main.hs...
45 # -----------------------------------------------------------------------------
48 INPLACE_HS=hsc2hs-inplace.hs
49 INPLACE_PROG=hsc2hs-inplace
50 EXCLUDED_SRCS+=$(INPLACE_HS)
52 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
53 extra_flags=$(addprefix --cflag=,$(filter-out -O,$(SRC_CC_OPTS)))
59 space=$(nothing) $(nothing)
63 # :\"-Ifoo\":\"-Ibar\"
64 GMP_INCLUDE_DIRS_STRINGS = $(subst $(space),,$(foreach d,$(GMP_INCLUDE_DIRS),:\"-I$(d)\"))
66 $(INPLACE_HS): Makefile $(FPTOOLS_TOP)/mk/config.mk
67 echo "import System.Cmd; import System.Environment; import System.Exit" > $@
68 echo "main = do args <- getArgs; rawSystem \"$(FPTOOLS_TOP_ABS)/$(GHC_HSC2HS_DIR_REL)/$(HS_PROG)\" (\"--template=$(FPTOOLS_TOP_ABS)/$(GHC_HSC2HS_DIR_REL)/template-hsc.h\":\"--cc=$(CC)\":\"--ld=$(CC)\"$(patsubst %,:\"%\",$(extra_flags)):\"--cflag=-D__GLASGOW_HASKELL__=$(ProjectVersionInt)\":\"-I$(FPTOOLS_TOP_ABS)/$(GHC_INCLUDE_DIR_REL)\":\"-I$(FPTOOLS_TOP_ABS)/gmp/gmpbuild\"$(GMP_INCLUDE_DIRS_STRINGS):args) >>= exitWith" >> $@
70 $(INPLACE_PROG): $(INPLACE_HS)
73 all :: $(INPLACE_PROG)
75 CLEAN_FILES += $(INPLACE_HS) $(INPLACE_PROG)
77 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
78 INSTALL_PROGS += $(HS_PROG)
80 INSTALL_LIBEXECS += $(HS_PROG)
82 LINK_TARGET = $(LINK)-$(ProjectVersion)
83 INSTALLED_SCRIPT=$(DESTDIR)$(bindir)/$(LINK_TARGET)
85 $(RM) -f $(INSTALLED_SCRIPT)
86 echo "#!$(SHELL)" >> $(INSTALLED_SCRIPT)
87 echo "HSC2HS_BINDIR=$(libexecdir)" >> $(INSTALLED_SCRIPT)
88 echo "HSC2HS_DIR=$(libdir)" >> $(INSTALLED_SCRIPT)
89 echo "HS_PROG=$(HS_PROG)" >> $(INSTALLED_SCRIPT)
90 echo "HSC2HS_EXTRA=" >> $(INSTALLED_SCRIPT)
91 cat hsc2hs.sh >> $(INSTALLED_SCRIPT)
92 $(EXECUTABLE_FILE) $(INSTALLED_SCRIPT)
94 ifneq "$(NO_INSTALL_HSC2HS)" "YES"
96 $(CP) $(INSTALLED_SCRIPT) $(DESTDIR)/$(bindir)/hsc2hs
100 # -----------------------------------------------------------------------------
102 override datadir=$(libdir)
103 INSTALL_DATAS += template-hsc.h
106 $(INSTALL_DIR) $(BIN_DIST_DIR)/utils/hsc2hs
107 $(INSTALL_DATA) Makefile $(BIN_DIST_DIR)/utils/hsc2hs/
108 $(INSTALL_DATA) hsc2hs.sh $(BIN_DIST_DIR)/utils/hsc2hs/
109 $(INSTALL_DATA) $(INSTALL_DATAS) $(BIN_DIST_DIR)/utils/hsc2hs/
110 $(INSTALL_PROGRAM) $(HS_PROG) $(BIN_DIST_DIR)/utils/hsc2hs/
112 include $(TOP)/mk/target.mk