Quote commands that we run, so they work if there are space in their paths
[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): $$($1_$2_INPLACE)
36 "$$(RM)" $$(RM_OPTS) $$@
37 echo '#!$$(SHELL)' >> $$@
38 echo 'executablename=$$(TOP)/$$<' >> $$@
39 echo 'datadir=$$(TOP)/$$(INPLACE_LIB)' >> $$@
40 echo 'bindir=$$(TOP)/$$(INPLACE_BIN)' >> $$@
41 cat $$($1_$2_SHELL_WRAPPER_NAME) >> $$@
42 $$(EXECUTABLE_FILE) $$@
43 endif
44
45 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER)" "YES"
46
47 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)" ""
48 $1_$2_INSTALL_SHELL_WRAPPER_NAME = $$($1_$2_PROG)
49 endif
50
51 # Install the binary in $(libexecdir), and install a shell wrapper in $(bindir)
52 INSTALL_LIBEXECS += $1/$2/build/tmp/$$($1_$2_PROG)
53 BINDIST_WRAPPERS += $$($1_$2_SHELL_WRAPPER_NAME)
54
55 install: install_$1_$2_wrapper
56
57 .PHONY: install_$1_$2_wrapper
58 install_$1_$2_wrapper: WRAPPER=$$(DESTDIR)$$(bindir)/$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)
59 install_$1_$2_wrapper:
60 "$$(MKDIRHIER)" $$(DESTDIR)$$(bindir)
61 "$$(RM)" $$(RM_OPTS) $$(WRAPPER)
62 echo '#!$$(SHELL)' >> $$(WRAPPER)
63 echo 'executablename=$$(libexecdir)/$$($1_$2_PROG)' >> $$(WRAPPER)
64 echo 'datadir=$$(datadir)' >> $$(WRAPPER)
65 echo 'bindir=$$(bindir)' >> $$(WRAPPER)
66 cat $$($1_$2_SHELL_WRAPPER_NAME) >> $$(WRAPPER)
67 $$(EXECUTABLE_FILE) $$(WRAPPER)
68
69 endif # $1_$2_INSTALL_SHELL_WRAPPER
70
71 endif
72
73 endif # $1_$2_SHELL_WRAPPER
74
75 endef