Makefile 2.95 KB
Newer Older
1
# -----------------------------------------------------------------------------
2
# To compile with nhc98 on unix:
3
#     nhc98 -cpp -package base -o hsc2hs-bin Main.hs
4
5
6
7
8
9

TOP=../..
include $(TOP)/mk/boilerplate.mk

INSTALLING=1

10
# This causes libghccompat.a to be used:
11
include $(GHC_COMPAT_DIR)/compat.mk
12

13
14
15
# This is required because libghccompat.a must be built with
# $(GhcHcOpts) because it is linked to the compiler, and hence
# we must also build with $(GhcHcOpts) here:
16
SRC_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
17

18
HS_PROG           = hsc2hs-bin
sof's avatar
sof committed
19
20
21
22
ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
HS_PROG           = hsc2hs$(exeext)
endif
ifeq "$(HOSTPLATFORM)" "i386-unknown-cygwinw32"
sof's avatar
sof committed
23
HS_PROG           = hsc2hs$(exeext)
rrt's avatar
rrt committed
24
endif
sof's avatar
sof committed
25

26
27
28
# Note: Somehow we should pass $(exeext) here, but the history of changes used
# for calling the C preprocessor via GHC has changed a few times, making a
# clean solution impossible. So we revert to a hack in Main.hs...
29
SRC_HC_OPTS      += -Wall
sof's avatar
sof committed
30
31

ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
32
INSTALLED_SCRIPT_PROG  = hsc2hs-ghc
rrt's avatar
rrt committed
33
endif
34
35
36
37
38
39
40
41
42
43
44
45
INPLACE_SCRIPT_PROG    = hsc2hs-inplace

ifeq "$(INSTALLING)" "1"
TOP_PWD 	:= $(prefix)
SCRIPT_PROG 	=  $(INSTALLED_SCRIPT_PROG)
else
TOP_PWD 	:= $(FPTOOLS_TOP_ABS)
SCRIPT_PROG 	=  $(INPLACE_SCRIPT_PROG)
endif

ifeq "$(INSTALLING)" "1"
ifeq "$(BIN_DIST)"   "1"
46
HSC2HS_BINDIR=$$\"\"libexecdir
47
48
49
HSC2HS_DIR=$$\"\"libdir
HSC2HS_EXTRA=
else
50
HSC2HS_BINDIR=$(libexecdir)
51
HSC2HS_DIR=$(libdir)
52
HSC2HS_EXTRA=--cc=$(bindir)/ghc-$(ProjectVersion)
53
54
endif # BIN_DIST
else
55
56
HSC2HS_BINDIR=$(FPTOOLS_TOP_ABS)/$(GHC_HSC2HS_DIR_REL)
HSC2HS_DIR=$(FPTOOLS_TOP_ABS_PLATFORM)/$(GHC_HSC2HS_DIR_REL)
sof's avatar
sof committed
57
58

ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
sof's avatar
sof committed
59
extra_flags=$(addprefix --cflag=,$(filter-out -O,$(SRC_CC_OPTS)))
rrt's avatar
rrt committed
60
endif
sof's avatar
sof committed
61

62
HSC2HS_EXTRA=--cc=$(CC) --ld=$(CC) $(extra_flags) --cflag=-D__GLASGOW_HASKELL__=$(ProjectVersionInt) -I$(FPTOOLS_TOP_ABS_PLATFORM)/$(GHC_INCLUDE_DIR_REL)
63
64
65
endif

$(SCRIPT_PROG) : Makefile
66
$(INSTALLED_SCRIPT_PROG) : $(TOP)/mk/config.mk
67

68
SCRIPT_SUBST_VARS = HSC2HS_BINDIR HSC2HS_DIR HS_PROG HSC2HS_EXTRA
69
70
71
72

SCRIPT_OBJS=hsc2hs.sh
INTERP=$(SHELL)

rrt's avatar
rrt committed
73
ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
74
75
INSTALL_SCRIPTS  += $(SCRIPT_PROG)
INSTALL_LIBEXECS += $(HS_PROG)
rrt's avatar
rrt committed
76
77
78
else
INSTALL_PROGS    += $(HS_PROG)
endif
79
80
81
82

override datadir=$(libdir)
INSTALL_DATAS += template-hsc.h

83
# -----------------------------------------------------------------------------
84
85
86
# don't recurse on 'make install'
#
ifeq "$(INSTALLING)" "1"
87
all :: $(HS_PROG)
88
89
	$(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@

90
91
92
clean distclean maintainer-clean :: 
	$(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
endif
sof's avatar
sof committed
93

94
95
96
ifeq "$(INSTALLING)$(HOSTPLATFORM)" "0i386-unknown-mingw32"
all :: $(INPLACE_SCRIPT_PROG).bat

97
98
# See "MSys Note 3" in compiler/Makefile
FULL_INPLACE_PATH=$(subst /,\,$(FPTOOLS_TOP_ABS_PLATFORM)/utils/hsc2hs/)
99
100
101
102
103
$(INPLACE_SCRIPT_PROG).bat :
	echo '@call $(FULL_INPLACE_PATH)$(HS_PROG) --template=$(FULL_INPLACE_PATH)template-hsc.h $(HSC2HS_EXTRA) %*' >> $@
	chmod 755 $@
endif

sof's avatar
sof committed
104
include $(TOP)/mk/target.mk