Remove hardtop_plat/FPTOOLS_TOP_ABS_PLATFORM
[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 # This causes libghccompat.a to be used:
9 include $(GHC_COMPAT_DIR)/compat.mk
10
11 # This is required because libghccompat.a must be built with
12 # $(GhcHcOpts) because it is linked to the compiler, and hence
13 # we must also build with $(GhcHcOpts) here:
14 SRC_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
15
16 HS_PROG = hsc2hs-bin
17 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
18 HS_PROG = hsc2hs$(exeext)
19 endif
20 ifeq "$(HOSTPLATFORM)" "i386-unknown-cygwinw32"
21 HS_PROG = hsc2hs$(exeext)
22 endif
23
24 # Note: Somehow we should pass $(exeext) here, but the history of changes used
25 # for calling the C preprocessor via GHC has changed a few times, making a
26 # clean solution impossible. So we revert to a hack in Main.hs...
27 SRC_HC_OPTS += -Wall
28
29 # -----------------------------------------------------------------------------
30 # hsc2hs script
31
32 INPLACE_HS=hsc2hs-inplace.hs
33 INPLACE_PROG=hsc2hs-inplace
34 EXCLUDED_SRCS+=$(INPLACE_HS)
35
36 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
37 extra_flags=$(addprefix --cflag=,$(filter-out -O,$(SRC_CC_OPTS)))
38 else
39 extra_flags=
40 endif
41
42 $(INPLACE_HS): Makefile $(FPTOOLS_TOP)/mk/config.mk
43 echo "import System.Cmd; import System.Environment; import System.Exit" > $@
44 echo "main = do args <- getArgs; rawSystem \"$(FPTOOLS_TOP_ABS)/$(GHC_HSC2HS_DIR_REL)/$(HS_PROG)\" (\"--template=$(FPTOOLS_TOP_ABS)/$(GHC_HSC2HS_DIR_REL)/template-hsc.h\":\"--cc=$(CC)\":\"--ld=$(CC)\"$(patsubst %,:\"%\",$(extra_flags)):\"--cflag=-D__GLASGOW_HASKELL__=$(ProjectVersionInt)\":\"-I$(FPTOOLS_TOP_ABS)/$(GHC_INCLUDE_DIR_REL)\":\"-I$(FPTOOLS_TOP_ABS)/gmp/gmpbuild\":args) >>= exitWith" >> $@
45
46 $(INPLACE_PROG): $(INPLACE_HS)
47 $(HC) --make $< -o $@
48
49 all :: $(INPLACE_PROG)
50
51 CLEAN_FILES += $(INPLACE_HS) $(INPLACE_PROG)
52
53 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
54 INSTALL_PROGS += $(HS_PROG)
55 else
56 INSTALL_LIBEXECS += $(HS_PROG)
57 LINK = hsc2hs
58 LINK_TARGET = $(LINK)-$(ProjectVersion)
59 INSTALLED_SCRIPT=$(DESTDIR)$(bindir)/$(LINK_TARGET)
60 install::
61 $(RM) -f $(INSTALLED_SCRIPT)
62 echo "#!$(SHELL)" >> $(INSTALLED_SCRIPT)
63 echo "HSC2HS_BINDIR=$(libexecdir)" >> $(INSTALLED_SCRIPT)
64 echo "HSC2HS_DIR=$(libdir)" >> $(INSTALLED_SCRIPT)
65 echo "HS_PROG=$(HS_PROG)" >> $(INSTALLED_SCRIPT)
66 echo "HSC2HS_EXTRA=" >> $(INSTALLED_SCRIPT)
67 cat hsc2hs.sh >> $(INSTALLED_SCRIPT)
68 $(EXECUTABLE_FILE) $(INSTALLED_SCRIPT)
69 endif
70
71 # -----------------------------------------------------------------------------
72
73 override datadir=$(libdir)
74 INSTALL_DATAS += template-hsc.h
75
76 binary-dist:
77 $(INSTALL_DIR) $(BIN_DIST_DIR)/utils/hsc2hs
78 $(INSTALL_DATA) Makefile $(BIN_DIST_DIR)/utils/hsc2hs/
79 $(INSTALL_DATA) hsc2hs.sh $(BIN_DIST_DIR)/utils/hsc2hs/
80 $(INSTALL_DATA) $(INSTALL_DATAS) $(BIN_DIST_DIR)/utils/hsc2hs/
81 $(INSTALL_PROGRAM) $(HS_PROG) $(BIN_DIST_DIR)/utils/hsc2hs/
82
83 include $(TOP)/mk/target.mk