Fix the build with GHC 6.4
[ghc-hetmet.git] / utils / hsc2hs / Makefile
1 # -----------------------------------------------------------------------------
2 # To compile with nhc98 on unix:
3 #     nhc98 -cpp -package base -o hsc2hs-bin Main.hs
4
5 TOP=../..
6 include $(TOP)/mk/boilerplate.mk
7
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
11 ifeq "$(stage)" "2"
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))
15 endif
16
17 ifeq "$(ghc_ge_605)" "NO"
18 SRC_HC_OPTS += -cpp
19 endif
20
21 # This causes libghccompat.a to be used:
22 include $(GHC_COMPAT_DIR)/compat.mk
23
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)
28
29 # We have two version: the inplace version compiled by the bootstrap compiler
30 #   and the install version compiled by the stage 1 compiler
31 ifeq "$(stage)" "2"
32 HS_PROG           = hsc2hs.bin
33 else
34 HS_PROG           = hsc2hs-inplace.bin
35 endif
36
37 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
38 HS_PROG           = hsc2hs$(exeext)
39 endif
40 ifeq "$(HOSTPLATFORM)" "i386-unknown-cygwinw32"
41 HS_PROG           = hsc2hs$(exeext)
42 endif
43
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...
47 SRC_HC_OPTS      += -Wall
48
49 # -----------------------------------------------------------------------------
50 # hsc2hs script
51
52 INPLACE_HS=hsc2hs-inplace.hs
53 INPLACE_PROG=hsc2hs-inplace
54 EXCLUDED_SRCS+=$(INPLACE_HS)
55
56 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
57 extra_flags=$(addprefix --cflag=,$(filter-out -O,$(SRC_CC_OPTS)))
58 else
59 extra_flags=
60 endif
61
62 nothing=
63 space=$(nothing) $(nothing)
64 # Given
65 #   foo bar
66 # make
67 #   :\"-Ifoo\":\"-Ibar\"
68 GMP_INCLUDE_DIRS_STRINGS = $(subst $(space),,$(foreach d,$(GMP_INCLUDE_DIRS),:\"-I$(d)\"))
69
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" >> $@
73
74 $(INPLACE_PROG): $(INPLACE_HS)
75         $(HC) --make $< -o $@
76
77 all :: $(INPLACE_PROG)
78
79 CLEAN_FILES += $(INPLACE_HS) $(INPLACE_PROG)
80
81 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
82 INSTALL_PROGS    += $(HS_PROG)
83 else
84 INSTALL_LIBEXECS += $(HS_PROG)
85 LINK = hsc2hs-ghc
86 LINK_TARGET = $(LINK)-$(ProjectVersion)
87 INSTALLED_SCRIPT=$(DESTDIR)$(bindir)/$(LINK_TARGET)
88 install::
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)
97
98 ifneq "$(NO_INSTALL_HSC2HS)" "YES"
99 install::
100         $(CP) $(INSTALLED_SCRIPT) $(DESTDIR)/$(bindir)/hsc2hs
101 endif
102 endif
103
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"
108 boot :: depend
109         $(MAKE) all
110 endif
111
112 # -----------------------------------------------------------------------------
113
114 override datadir=$(libdir)
115 INSTALL_DATAS += template-hsc.h
116
117 binary-dist:
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/
123
124 include $(TOP)/mk/target.mk