Tweak how shell wrappers are built
[ghc.git] / rules / shell-wrapper.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009 The University of Glasgow
4 #
5 # This file is part of the GHC build system.
6 #
7 # To understand how the build system works and how to modify it, see
8 # http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
10 #
11 # -----------------------------------------------------------------------------
12
13 define shell-wrapper
14 # $1 = dir
15 # $2 = distdir
16
17 ifeq "$$($1_$2_SHELL_WRAPPER)" "YES"
18
19 ifeq "$$(Windows)" "YES"
20
21 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER)" "YES"
22 # Just install the binary on Windows
23 $1_$2_INSTALL = YES
24 endif
25
26 else
27
28 ifeq "$$($1_$2_SHELL_WRAPPER_NAME)" ""
29 $1_$2_SHELL_WRAPPER_NAME = $1/$$($1_$2_PROG).wrapper
30 endif
31
32 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
33 all_$1_$2 : $$(INPLACE_BIN)/$$($1_$2_PROG)
34
35 $$(INPLACE_BIN)/$$($1_$2_PROG): WRAPPER=$$@
36 $$(INPLACE_BIN)/$$($1_$2_PROG): $$($1_$2_INPLACE)
37 "$$(RM)" $$(RM_OPTS) $$@
38 echo '#!$$(SHELL)' >> $$@
39 echo 'executablename="$$(TOP)/$$<"' >> $$@
40 echo 'datadir="$$(TOP)/$$(INPLACE_LIB)"' >> $$@
41 echo 'bindir="$$(TOP)/$$(INPLACE_BIN)"' >> $$@
42 echo 'topdir="$$(TOP)/$$(INPLACE_TOPDIR)"' >> $$@
43 $$($1_$2_SHELL_WRAPPER_EXTRA)
44 $$($1_$2_INPLACE_SHELL_WRAPPER_EXTRA)
45 cat $$($1_$2_SHELL_WRAPPER_NAME) >> $$@
46 $$(EXECUTABLE_FILE) $$@
47 endif
48
49 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER)" "YES"
50
51 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)" ""
52 $1_$2_INSTALL_SHELL_WRAPPER_NAME = $$($1_$2_PROG)
53 endif
54
55 # Install the binary in $(libexecdir), and install a shell wrapper in $(bindir)
56 INSTALL_LIBEXECS += $1/$2/build/tmp/$$($1_$2_PROG)
57 BINDIST_WRAPPERS += $$($1_$2_SHELL_WRAPPER_NAME)
58
59 install: install_$1_$2_wrapper
60
61 .PHONY: install_$1_$2_wrapper
62 install_$1_$2_wrapper: WRAPPER=$$(DESTDIR)$$(bindir)/$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)
63 install_$1_$2_wrapper:
64 $$(INSTALL_DIR) "$$(DESTDIR)$$(bindir)"
65 "$$(RM)" $$(RM_OPTS) "$$(WRAPPER)"
66 $$(CREATE_SCRIPT) "$$(WRAPPER)"
67 echo '#!$$(SHELL)' >> "$$(WRAPPER)"
68 echo 'exedir="$$(ghclibexecdir)"' >> "$$(WRAPPER)"
69 echo 'exeprog="$$($1_$2_PROG)"' >> "$$(WRAPPER)"
70 echo 'executablename="$$$$exedir/$$$$exeprog"' >> "$$(WRAPPER)"
71 echo 'datadir="$$(datadir)"' >> "$$(WRAPPER)"
72 echo 'bindir="$$(bindir)"' >> "$$(WRAPPER)"
73 echo 'topdir="$$(topdir)"' >> "$$(WRAPPER)"
74 $$($1_$2_SHELL_WRAPPER_EXTRA)
75 $$($1_$2_INSTALL_SHELL_WRAPPER_EXTRA)
76 cat $$($1_$2_SHELL_WRAPPER_NAME) >> "$$(WRAPPER)"
77 $$(EXECUTABLE_FILE) "$$(WRAPPER)"
78
79 endif # $1_$2_INSTALL_SHELL_WRAPPER
80
81 endif
82
83 endif # $1_$2_SHELL_WRAPPER
84
85 endef