GHC new build system megapatch
[ghc.git] / rules / shell-wrapper.mk
1 define shell-wrapper
2 # $1 = dir
3 # $2 = distdir
4
5 ifeq "$$($1_$2_SHELL_WRAPPER)" "YES"
6
7 ifeq "$(Windows)" "YES"
8
9 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER)" "YES"
10 # Just install the binary on Windows
11 $1_$2_INSTALL = YES
12 endif
13
14 else
15
16 ifeq "$$($1_$2_SHELL_WRAPPER_NAME)" ""
17 $1_$2_SHELL_WRAPPER_NAME = $1/$$($1_$2_PROG).wrapper
18 endif
19
20 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
21 all_$1_$2 : $$(INPLACE_BIN)/$$($1_$2_PROG)
22
23 $$(INPLACE_BIN)/$$($1_$2_PROG): $$($1_$2_INPLACE)
24 $$(RM) -f $$@
25 echo '#!$$(SHELL)' >> $$@
26 echo 'executablename=$$(TOP)/$$<' >> $$@
27 echo 'datadir=$$(TOP)/$$(INPLACE_LIB)' >> $$@
28 echo 'bindir=$$(TOP)/$$(INPLACE_BIN)' >> $$@
29 cat $$($1_$2_SHELL_WRAPPER_NAME) >> $$@
30 $$(EXECUTABLE_FILE) $$@
31 endif
32
33 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER)" "YES"
34
35 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)" ""
36 $1_$2_INSTALL_SHELL_WRAPPER_NAME = $$($1_$2_PROG)
37 endif
38
39 # Install the binary in $(libexecdir), and install a shell wrapper in $(bindir)
40 INSTALL_LIBEXECS += $1/$2/build/tmp/$$($1_$2_PROG)
41 BINDIST_WRAPPERS += $$($1_$2_SHELL_WRAPPER_NAME)
42
43 install: install_$1_$2_wrapper
44
45 .PHONY: install_$1_$2_wrapper
46 install_$1_$2_wrapper: WRAPPER=$$(DESTDIR)$$(bindir)/$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)
47 install_$1_$2_wrapper:
48 $$(MKDIRHIER) $$(DESTDIR)$$(bindir)
49 $$(RM) -f $$(WRAPPER)
50 echo '#!$$(SHELL)' >> $$(WRAPPER)
51 echo 'executablename=$$(libexecdir)/$$($1_$2_PROG)' >> $$(WRAPPER)
52 echo 'datadir=$$(datadir)' >> $$(WRAPPER)
53 echo 'bindir=$$(bindir)' >> $$(WRAPPER)
54 cat $$($1_$2_SHELL_WRAPPER_NAME) >> $$(WRAPPER)
55 $$(EXECUTABLE_FILE) $$(WRAPPER)
56
57 endif # $1_$2_INSTALL_SHELL_WRAPPER
58
59 endif
60
61 endif # $1_$2_SHELL_WRAPPER
62
63 endef