Makefile 2.96 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 29
ifeq "$(ghc_ge_504)" "NO"
SRC_HC_OPTS +=  -package util
endif

30 31 32
# 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...
33
SRC_HC_OPTS      += -Wall
sof's avatar
sof committed
34 35

ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
36
INSTALLED_SCRIPT_PROG  = hsc2hs-ghc
rrt's avatar
rrt committed
37
endif
38 39 40 41 42 43 44 45 46 47 48 49
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"
50
HSC2HS_BINDIR=$$\"\"libexecdir
51 52 53
HSC2HS_DIR=$$\"\"libdir
HSC2HS_EXTRA=
else
54
HSC2HS_BINDIR=$(libexecdir)
55
HSC2HS_DIR=$(libdir)
56
HSC2HS_EXTRA=--cc=$(bindir)/ghc-$(ProjectVersion)
57 58
endif # BIN_DIST
else
59 60
HSC2HS_BINDIR=$(FPTOOLS_TOP_ABS)/$(GHC_HSC2HS_DIR_REL)
HSC2HS_DIR=$(FPTOOLS_TOP_ABS_PLATFORM)/$(GHC_HSC2HS_DIR_REL)
sof's avatar
sof committed
61 62

ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
sof's avatar
sof committed
63
extra_flags=$(addprefix --cflag=,$(filter-out -O,$(SRC_CC_OPTS)))
rrt's avatar
rrt committed
64
endif
sof's avatar
sof committed
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 68 69
endif

$(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 75 76

SCRIPT_OBJS=hsc2hs.sh
INTERP=$(SHELL)

rrt's avatar
rrt committed
77
ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
78 79
INSTALL_SCRIPTS  += $(SCRIPT_PROG)
INSTALL_LIBEXECS += $(HS_PROG)
rrt's avatar
rrt committed
80 81 82
else
INSTALL_PROGS    += $(HS_PROG)
endif
83 84 85 86

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

87
# -----------------------------------------------------------------------------
88 89 90
# don't recurse on 'make install'
#
ifeq "$(INSTALLING)" "1"
91
all :: $(HS_PROG)
92 93
	$(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@

94 95 96
clean distclean maintainer-clean :: 
	$(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
endif
sof's avatar
sof committed
97

98 99 100 101 102 103 104 105 106
ifeq "$(INSTALLING)$(HOSTPLATFORM)" "0i386-unknown-mingw32"
all :: $(INPLACE_SCRIPT_PROG).bat

FULL_INPLACE_PATH=$(subst /,\\,$(FPTOOLS_TOP_ABS)/utils/hsc2hs/)
$(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
107
include $(TOP)/mk/target.mk