Fixes for building the libraries with cabal on Windows
[ghc.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 INSTALLING=1
9
10 # This causes libghccompat.a to be used:
11 include $(GHC_COMPAT_DIR)/compat.mk
12
13 # This is required because libghccompat.a must be built with
14 # $(GhcHcOpts) because it is linked to the compiler, and hence
15 # we must also build with $(GhcHcOpts) here:
16 SRC_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
17
18 HS_PROG = hsc2hs-bin
19 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
20 HS_PROG = hsc2hs$(exeext)
21 endif
22 ifeq "$(HOSTPLATFORM)" "i386-unknown-cygwinw32"
23 HS_PROG = hsc2hs$(exeext)
24 endif
25
26 ifeq "$(ghc_ge_504)" "NO"
27 SRC_HC_OPTS += -package util
28 endif
29
30 # Note: Somehow we should pass $(exeext) here, but the history of changes used
31 # for calling the C preprocessor via GHC has changed a few times, making a
32 # clean solution impossible. So we revert to a hack in Main.hs...
33 SRC_HC_OPTS += -Wall
34
35 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
36 INSTALLED_SCRIPT_PROG = hsc2hs-ghc
37 endif
38 INPLACE_SCRIPT_PROG = hsc2hs-inplace
39
40 ifeq "$(INSTALLING)" "1"
41 TOP_PWD := $(prefix)
42 SCRIPT_PROG = $(INSTALLED_SCRIPT_PROG)
43 else
44 TOP_PWD := $(FPTOOLS_TOP_ABS)
45 SCRIPT_PROG = $(INPLACE_SCRIPT_PROG)
46 endif
47
48 ifeq "$(INSTALLING)" "1"
49 ifeq "$(BIN_DIST)" "1"
50 HSC2HS_BINDIR=$$\"\"libexecdir
51 HSC2HS_DIR=$$\"\"libdir
52 HSC2HS_EXTRA=
53 else
54 HSC2HS_BINDIR=$(libexecdir)
55 HSC2HS_DIR=$(libdir)
56 HSC2HS_EXTRA=--cc=$(bindir)/ghc-$(ProjectVersion)
57 endif # BIN_DIST
58 else
59 HSC2HS_BINDIR=$(FPTOOLS_TOP_ABS)/$(GHC_HSC2HS_DIR_REL)
60 HSC2HS_DIR=$(FPTOOLS_TOP_ABS_PLATFORM)/$(GHC_HSC2HS_DIR_REL)
61
62 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
63 extra_flags=$(addprefix --cflag=,$(filter-out -O,$(SRC_CC_OPTS)))
64 endif
65
66 HSC2HS_EXTRA=--cc=$(CC) --ld=$(CC) $(extra_flags) --cflag=-D__GLASGOW_HASKELL__=$(ProjectVersionInt) -I$(FPTOOLS_TOP_ABS_PLATFORM)/$(GHC_INCLUDE_DIR_REL)
67 endif
68
69 $(SCRIPT_PROG) : Makefile
70 $(INSTALLED_SCRIPT_PROG) : $(TOP)/mk/config.mk
71
72 SCRIPT_SUBST_VARS = HSC2HS_BINDIR HSC2HS_DIR HS_PROG HSC2HS_EXTRA
73
74 SCRIPT_OBJS=hsc2hs.sh
75 INTERP=$(SHELL)
76
77 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
78 INSTALL_SCRIPTS += $(SCRIPT_PROG)
79 INSTALL_LIBEXECS += $(HS_PROG)
80 else
81 INSTALL_PROGS += $(HS_PROG)
82 endif
83
84 override datadir=$(libdir)
85 INSTALL_DATAS += template-hsc.h
86
87 # -----------------------------------------------------------------------------
88 # don't recurse on 'make install'
89 #
90 ifeq "$(INSTALLING)" "1"
91 all :: $(HS_PROG)
92 $(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
93
94 clean distclean maintainer-clean ::
95 $(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
96 endif
97
98 ifeq "$(INSTALLING)$(HOSTPLATFORM)" "0i386-unknown-mingw32"
99 all :: $(INPLACE_SCRIPT_PROG).bat
100
101 FULL_INPLACE_PATH=$(subst /,\\,$(FPTOOLS_TOP_ABS)/utils/hsc2hs/)
102 $(INPLACE_SCRIPT_PROG).bat :
103 echo '@call $(FULL_INPLACE_PATH)$(HS_PROG) --template=$(FULL_INPLACE_PATH)template-hsc.h $(HSC2HS_EXTRA) %*' >> $@
104 chmod 755 $@
105 endif
106
107 include $(TOP)/mk/target.mk