summaryrefslogtreecommitdiff
path: root/rules/shell-wrapper.mk
blob: 503a8d26e8c74e1575e6dcb223c960822c265d63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -----------------------------------------------------------------------------
#
# (c) 2009 The University of Glasgow
#
# This file is part of the GHC build system.
#
# To understand how the build system works and how to modify it, see
#      http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
#      http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
#
# -----------------------------------------------------------------------------

define shell-wrapper
# $1 = dir
# $2 = distdir

ifeq "$$($1_$2_SHELL_WRAPPER)" "YES"

ifeq "$$(Windows)" "YES"

ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER)" "YES"
# Just install the binary on Windows
$1_$2_INSTALL = YES
endif

else

ifeq "$$($1_$2_SHELL_WRAPPER_NAME)" ""
$1_$2_SHELL_WRAPPER_NAME = $1/$$($1_$2_PROG).wrapper
endif

ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
all_$1_$2 : $$(INPLACE_BIN)/$$($1_$2_PROG)

$$(INPLACE_BIN)/$$($1_$2_PROG): $$($1_$2_INPLACE)
	"$$(RM)" $$(RM_OPTS)                              $$@
	echo '#!$$(SHELL)'                             >> $$@
	echo 'executablename="$$(TOP)/$$<"'            >> $$@
	echo 'datadir="$$(TOP)/$$(INPLACE_LIB)"'       >> $$@
	echo 'bindir="$$(TOP)/$$(INPLACE_BIN)"'        >> $$@
	echo 'topdir="$$(TOP)/$$(INPLACE_TOPDIR)"'     >> $$@
	$($1_$2_SHELL_WRAPPER_EXTRA)
	$($1_$2_INPLACE_SHELL_WRAPPER_EXTRA)
	cat $$($1_$2_SHELL_WRAPPER_NAME)               >> $$@
	$$(EXECUTABLE_FILE)                               $$@
endif

ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER)" "YES"

ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)" ""
$1_$2_INSTALL_SHELL_WRAPPER_NAME = $$($1_$2_PROG)
endif

# Install the binary in $(libexecdir), and install a shell wrapper in $(bindir)
INSTALL_LIBEXECS += $1/$2/build/tmp/$$($1_$2_PROG)
BINDIST_WRAPPERS += $$($1_$2_SHELL_WRAPPER_NAME)

install: install_$1_$2_wrapper

.PHONY: install_$1_$2_wrapper
install_$1_$2_wrapper: WRAPPER=$$(DESTDIR)$$(bindir)/$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)
install_$1_$2_wrapper:
	$$(INSTALL_DIR) "$$(DESTDIR)$$(bindir)"
	"$$(RM)" $$(RM_OPTS)                                        "$$(WRAPPER)"
	$$(CREATE_SCRIPT)                                           "$$(WRAPPER)"
	echo '#!$$(SHELL)'                                       >> "$$(WRAPPER)"
	echo 'exedir="$$(ghclibexecdir)"'                        >> "$$(WRAPPER)"
	echo 'exeprog="$$($1_$2_PROG)"'                          >> "$$(WRAPPER)"
	echo 'executablename="$$$$exedir/$$$$exeprog"'           >> "$$(WRAPPER)"
	echo 'datadir="$$(datadir)"'                             >> "$$(WRAPPER)"
	echo 'bindir="$$(bindir)"'                               >> "$$(WRAPPER)"
	echo 'topdir="$$(topdir)"'                               >> "$$(WRAPPER)"
	$($1_$2_SHELL_WRAPPER_EXTRA)
	$($1_$2_INSTALL_SHELL_WRAPPER_EXTRA)
	cat $$($1_$2_SHELL_WRAPPER_NAME)                         >> "$$(WRAPPER)"
	$$(EXECUTABLE_FILE)                                         "$$(WRAPPER)"

endif # $1_$2_INSTALL_SHELL_WRAPPER

endif

endif # $1_$2_SHELL_WRAPPER

endef