[project @ 2003-08-01 15:10:34 by panne]
[ghc-hetmet.git] / ghc / utils / hsc2hs / Makefile
1 # -----------------------------------------------------------------------------
2 # $Id: Makefile,v 1.38 2003/06/04 15:18:30 panne Exp $
3
4 TOP=../..
5 include $(TOP)/mk/boilerplate.mk
6
7 CURRENT_DIR=ghc/utils/hsc2hs
8 INCLUDE_DIR=ghc/includes
9
10 INSTALLING=1
11
12 HS_PROG           = hsc2hs-bin
13 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
14 HS_PROG           = hsc2hs$(exeext)
15 endif
16 ifeq "$(HOSTPLATFORM)" "i386-unknown-cygwinw32"
17 HS_PROG           = hsc2hs$(exeext)
18 endif
19
20 ghc_ge_504 = $(shell if (test $(GhcCanonVersion) -ge 504); then echo YES; else echo NO; fi)
21
22 ifeq "$(ghc_ge_504)" "NO"
23 SRC_HC_OPTS +=  -package util
24 endif
25
26 SRC_HC_OPTS      += -cpp
27
28 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
29 INSTALLED_SCRIPT_PROG  = hsc2hs
30 endif
31 INPLACE_SCRIPT_PROG    = hsc2hs-inplace
32
33 ifeq "$(INSTALLING)" "1"
34 TOP_PWD         := $(prefix)
35 SCRIPT_PROG     =  $(INSTALLED_SCRIPT_PROG)
36 else
37 TOP_PWD         := $(FPTOOLS_TOP_ABS)
38 SCRIPT_PROG     =  $(INPLACE_SCRIPT_PROG)
39 endif
40
41 ifeq "$(INSTALLING)" "1"
42 ifeq "$(BIN_DIST)"   "1"
43 HSC2HS_BINDIR=$$\"\"libexecdir
44 HSC2HS_DIR=$$\"\"libdir
45 HSC2HS_EXTRA=
46 else
47 HSC2HS_BINDIR=$(libexecdir)
48 HSC2HS_DIR=$(libdir)
49 HSC2HS_EXTRA=--cc=$(bindir)/ghc-$(ProjectVersion)
50 endif # BIN_DIST
51 else
52 HSC2HS_BINDIR=$(FPTOOLS_TOP_ABS)/$(CURRENT_DIR)
53 HSC2HS_DIR=$(FPTOOLS_TOP_ABS_PLATFORM)/$(CURRENT_DIR)
54
55 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
56 extra_flags=$(addprefix --cflag=,$(filter-out -O,$(SRC_CC_OPTS)))
57 endif
58
59 HSC2HS_EXTRA="--cc=$(CC) --ld=$(CC) $(extra_flags) --cflag=-D__GLASGOW_HASKELL__=$(ProjectVersionInt) -I$(FPTOOLS_TOP_ABS_PLATFORM)/$(INCLUDE_DIR)"
60 endif
61
62 $(SCRIPT_PROG) : Makefile
63 $(INSTALLED_SCRIPT_PROG) : $(TOP)/mk/config.mk
64
65 SCRIPT_SUBST_VARS = HSC2HS_BINDIR HSC2HS_DIR HS_PROG HSC2HS_EXTRA
66
67 SCRIPT_OBJS=hsc2hs.sh
68 INTERP=$(SHELL)
69
70 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
71 INSTALL_SCRIPTS  += $(SCRIPT_PROG)
72 INSTALL_LIBEXECS += $(HS_PROG)
73 else
74 INSTALL_PROGS    += $(HS_PROG)
75 endif
76
77 override datadir=$(libdir)
78 INSTALL_DATAS += template-hsc.h
79
80 # -----------------------------------------------------------------------------
81 # Create driver configuration
82
83 CONFIG_HS   = Config.hs
84 CLEAN_FILES += $(CONFIG_HS)
85 EXTRA_SRCS  += $(CONFIG_HS)
86
87 boot :: $(CONFIG_HS)
88
89 $(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk Makefile
90         @$(RM) -f $(CONFIG_HS)
91         @echo -n "Creating $(CONFIG_HS) ... "
92         @echo "module Config where" >>$(CONFIG_HS)
93         @echo "cDEFAULT_TMPDIR       = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
94         @echo "cGCC                  = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
95         @echo "progNameSuffix        = \"$(exeext)\"" >> $(CONFIG_HS)
96 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
97         @echo "pathSep               = '/'" >> $(CONFIG_HS)
98 else
99         @echo "pathSep               = (toEnum 92 :: Char)" >> $(CONFIG_HS)
100 endif
101         @echo done.
102
103 # -----------------------------------------------------------------------------
104 # don't recurse on 'make install'
105 #
106 ifeq "$(INSTALLING)" "1"
107 all :: $(HS_PROG)
108         $(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
109
110 clean distclean maintainer-clean :: 
111         $(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
112 endif
113
114 include $(TOP)/mk/target.mk