4716d9ae2a9b5ee327a994153a33bc44a4e1efbf
[ghc-hetmet.git] / ghc / 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 CURRENT_DIR=ghc/utils/hsc2hs
9 INCLUDE_DIR=ghc/includes
10
11 INSTALLING=1
12
13 SRC_HC_OPTS += -i$(GHC_LIB_COMPAT_DIR)
14 SRC_LD_OPTS += -L$(GHC_LIB_COMPAT_DIR) -lghccompat
15
16 # This is required because libghccompat.a must be built with
17 # $(GhcHcOpts) because it is linked to the compiler, and hence
18 # we must also build with $(GhcHcOpts) here:
19 SRC_HC_OPTS += $(GhcHcOpts)
20
21 HS_PROG           = hsc2hs-bin
22 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
23 HS_PROG           = hsc2hs$(exeext)
24 endif
25 ifeq "$(HOSTPLATFORM)" "i386-unknown-cygwinw32"
26 HS_PROG           = hsc2hs$(exeext)
27 endif
28
29 ifeq "$(ghc_ge_504)" "NO"
30 SRC_HC_OPTS +=  -package util
31 endif
32
33 # Note: Somehow we should pass $(exeext) here, but the history of changes used
34 # for calling the C preprocessor via GHC has changed a few times, making a
35 # clean solution impossible. So we revert to a hack in Main.hs...
36 SRC_HC_OPTS      += -Wall
37
38 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
39 INSTALLED_SCRIPT_PROG  = hsc2hs
40 endif
41 INPLACE_SCRIPT_PROG    = hsc2hs-inplace
42
43 ifeq "$(INSTALLING)" "1"
44 TOP_PWD         := $(prefix)
45 SCRIPT_PROG     =  $(INSTALLED_SCRIPT_PROG)
46 else
47 TOP_PWD         := $(FPTOOLS_TOP_ABS)
48 SCRIPT_PROG     =  $(INPLACE_SCRIPT_PROG)
49 endif
50
51 ifeq "$(INSTALLING)" "1"
52 ifeq "$(BIN_DIST)"   "1"
53 HSC2HS_BINDIR=$$\"\"libexecdir
54 HSC2HS_DIR=$$\"\"libdir
55 HSC2HS_EXTRA=
56 else
57 HSC2HS_BINDIR=$(libexecdir)
58 HSC2HS_DIR=$(libdir)
59 HSC2HS_EXTRA=--cc=$(bindir)/ghc-$(ProjectVersion)
60 endif # BIN_DIST
61 else
62 HSC2HS_BINDIR=$(FPTOOLS_TOP_ABS)/$(CURRENT_DIR)
63 HSC2HS_DIR=$(FPTOOLS_TOP_ABS_PLATFORM)/$(CURRENT_DIR)
64
65 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
66 extra_flags=$(addprefix --cflag=,$(filter-out -O,$(SRC_CC_OPTS)))
67 endif
68
69 HSC2HS_EXTRA="--cc=$(CC) --ld=$(CC) $(extra_flags) --cflag=-D__GLASGOW_HASKELL__=$(ProjectVersionInt) -I$(FPTOOLS_TOP_ABS_PLATFORM)/$(INCLUDE_DIR)"
70 endif
71
72 $(SCRIPT_PROG) : Makefile
73 $(INSTALLED_SCRIPT_PROG) : $(TOP)/mk/config.mk
74
75 SCRIPT_SUBST_VARS = HSC2HS_BINDIR HSC2HS_DIR HS_PROG HSC2HS_EXTRA
76
77 SCRIPT_OBJS=hsc2hs.sh
78 INTERP=$(SHELL)
79
80 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
81 INSTALL_SCRIPTS  += $(SCRIPT_PROG)
82 INSTALL_LIBEXECS += $(HS_PROG)
83 else
84 INSTALL_PROGS    += $(HS_PROG)
85 endif
86
87 override datadir=$(libdir)
88 INSTALL_DATAS += template-hsc.h
89
90 # This is horrible.  We ought to be able to omit the entire directory
91 # from mkDependHS.
92 SRC_MKDEPENDHS_OPTS += \
93         -optdep--exclude-module=Compat.RawSystem \
94         -optdep--exclude-module=Compat.Directory \
95         -optdep--exclude-module=Distribution.Compat.ReadP \
96         -optdep--exclude-module=Distribution.Extension \
97         -optdep--exclude-module=Distribution.GetOpt \
98         -optdep--exclude-module=Distribution.InstalledPackageInfo \
99         -optdep--exclude-module=Distribution.License \
100         -optdep--exclude-module=Distribution.Package \
101         -optdep--exclude-module=Distribution.ParseUtils \
102         -optdep--exclude-module=Distribution.Setup \
103         -optdep--exclude-module=Distribution.Version \
104         -optdep--exclude-module=System.Directory.Internals
105
106 # -----------------------------------------------------------------------------
107 # don't recurse on 'make install'
108 #
109 ifeq "$(INSTALLING)" "1"
110 all :: $(HS_PROG)
111         $(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
112
113 clean distclean maintainer-clean :: 
114         $(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
115 endif
116
117 include $(TOP)/mk/target.mk