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 ifeq "$(ghc_ge_605)" "NO"
21 # This causes libghccompat.a to be used:
22 include $(GHC_COMPAT_DIR)/compat.mk
24 # This is required because libghccompat.a must be built with
25 # $(GhcHcOpts) because it is linked to the compiler, and hence
26 # we must also build with $(GhcHcOpts) here:
27 SRC_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
29 # We have two version: the inplace version compiled by the bootstrap compiler
30 # and the install version compiled by the stage 1 compiler
34 HS_PROG = hsc2hs-inplace.bin
37 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
38 HS_PROG = hsc2hs$(exeext)
40 ifeq "$(HOSTPLATFORM)" "i386-unknown-cygwinw32"
41 HS_PROG = hsc2hs$(exeext)
44 # Note: Somehow we should pass $(exeext) here, but the history of changes used
45 # for calling the C preprocessor via GHC has changed a few times, making a
46 # clean solution impossible. So we revert to a hack in Main.hs...
49 # -----------------------------------------------------------------------------
52 INPLACE_HS=hsc2hs-inplace.hs
53 INPLACE_PROG=hsc2hs-inplace
54 EXCLUDED_SRCS+=$(INPLACE_HS)
56 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
57 extra_flags=$(addprefix --cflag=,$(filter-out -O,$(SRC_CC_OPTS)))
63 space=$(nothing) $(nothing)
67 # :\"-Ifoo\":\"-Ibar\"
68 GMP_INCLUDE_DIRS_STRINGS = $(subst $(space),,$(foreach d,$(GMP_INCLUDE_DIRS),:\"-I$(d)\"))
70 $(INPLACE_HS): Makefile $(FPTOOLS_TOP)/mk/config.mk
71 echo "import System.Cmd; import System.Environment; import System.Exit" > $@
72 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" >> $@
74 $(INPLACE_PROG): $(INPLACE_HS)
77 all :: $(INPLACE_PROG)
79 CLEAN_FILES += $(INPLACE_HS) $(INPLACE_PROG)
81 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
82 INSTALL_PROGS += $(HS_PROG)
84 INSTALL_LIBEXECS += $(HS_PROG)
86 LINK_TARGET = $(LINK)-$(ProjectVersion)
87 INSTALLED_SCRIPT=$(DESTDIR)$(bindir)/$(LINK_TARGET)
89 $(RM) -f $(INSTALLED_SCRIPT)
90 echo "#!$(SHELL)" >> $(INSTALLED_SCRIPT)
91 echo "HSC2HS_BINDIR=$(libexecdir)" >> $(INSTALLED_SCRIPT)
92 echo "HSC2HS_DIR=$(libdir)" >> $(INSTALLED_SCRIPT)
93 echo "HS_PROG=$(HS_PROG)" >> $(INSTALLED_SCRIPT)
94 echo "HSC2HS_EXTRA=" >> $(INSTALLED_SCRIPT)
95 cat hsc2hs.sh >> $(INSTALLED_SCRIPT)
96 $(EXECUTABLE_FILE) $(INSTALLED_SCRIPT)
98 ifneq "$(NO_INSTALL_HSC2HS)" "YES"
100 $(CP) $(INSTALLED_SCRIPT) $(DESTDIR)/$(bindir)/hsc2hs
104 # hsc2hs-inplace is needed to 'make boot' in compiler.
105 # Do a recursive 'make all' after generating dependencies, because this
106 # will work with 'make -j'.
107 ifneq "$(BootingFromHc)" "YES"
112 # -----------------------------------------------------------------------------
114 override datadir=$(libdir)
115 INSTALL_DATAS += template-hsc.h
118 $(INSTALL_DIR) $(BIN_DIST_DIR)/utils/hsc2hs
119 $(INSTALL_DATA) Makefile $(BIN_DIST_DIR)/utils/hsc2hs/
120 $(INSTALL_DATA) hsc2hs.sh $(BIN_DIST_DIR)/utils/hsc2hs/
121 $(INSTALL_DATA) $(INSTALL_DATAS) $(BIN_DIST_DIR)/utils/hsc2hs/
122 $(INSTALL_PROGRAM) $(HS_PROG) $(BIN_DIST_DIR)/utils/hsc2hs/
124 include $(TOP)/mk/target.mk