Merge branch 'master' of darcs.haskell.org:/srv/darcs//ghc
[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 $(call trace, shell-wrapper($1,$2))
15 $(call profStart, shell-wrapper($1,$2))
16 # $1 = dir
17 # $2 = distdir
18
19 ifeq "$$($1_$2_SHELL_WRAPPER) $$(Windows)" "YES NO"
20
21 ifeq "$$($1_$2_SHELL_WRAPPER_NAME)" ""
22 $1_$2_SHELL_WRAPPER_NAME = $1/$$($1_$2_PROG).wrapper
23 endif
24
25 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
26 all_$1_$2 : $$(INPLACE_BIN)/$$($1_$2_PROG)
27
28 $$(INPLACE_BIN)/$$($1_$2_PROG): WRAPPER=$$@
29 $$(INPLACE_BIN)/$$($1_$2_PROG): $$($1_$2_INPLACE) $$($1_$2_SHELL_WRAPPER_NAME)
30 $$(call removeFiles, $$@)
31 echo '#!$$(SHELL)' >> $$@
32 echo 'executablename="$$(TOP)/$$<"' >> $$@
33 echo 'datadir="$$(TOP)/$$(INPLACE_LIB)"' >> $$@
34 echo 'bindir="$$(TOP)/$$(INPLACE_BIN)"' >> $$@
35 echo 'topdir="$$(TOP)/$$(INPLACE_TOPDIR)"' >> $$@
36 echo 'pgmgcc="$$(WhatGccIsCalled)"' >> $$@
37 $$($1_$2_SHELL_WRAPPER_EXTRA)
38 $$($1_$2_INPLACE_SHELL_WRAPPER_EXTRA)
39 cat $$($1_$2_SHELL_WRAPPER_NAME) >> $$@
40 $$(EXECUTABLE_FILE) $$@
41 endif
42
43 ifeq "$$($1_$2_INSTALL)" "YES"
44
45 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)" ""
46 $1_$2_INSTALL_SHELL_WRAPPER_NAME = $$($1_$2_PROG)
47 endif
48
49 # Install the binary in $(libexecdir), and install a shell wrapper in $(bindir)
50 INSTALL_LIBEXECS += $1/$2/build/tmp/$$($1_$2_PROG)
51 BINDIST_WRAPPERS += $$($1_$2_SHELL_WRAPPER_NAME)
52
53 install: install_$1_$2_wrapper
54
55 .PHONY: install_$1_$2_wrapper
56 install_$1_$2_wrapper: WRAPPER=$$(DESTDIR)$$(bindir)/$(CrossCompilePrefix)$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)
57 install_$1_$2_wrapper:
58 $$(call INSTALL_DIR,"$$(DESTDIR)$$(bindir)")
59 $$(call removeFiles, "$$(WRAPPER)")
60 $$(CREATE_SCRIPT) "$$(WRAPPER)"
61 echo '#!$$(SHELL)' >> "$$(WRAPPER)"
62 echo 'exedir="$$(ghclibexecdir)"' >> "$$(WRAPPER)"
63 echo 'exeprog="$$($1_$2_PROG)"' >> "$$(WRAPPER)"
64 echo 'executablename="$$$$exedir/$$$$exeprog"' >> "$$(WRAPPER)"
65 echo 'datadir="$$(datadir)"' >> "$$(WRAPPER)"
66 echo 'bindir="$$(bindir)"' >> "$$(WRAPPER)"
67 echo 'topdir="$$(topdir)"' >> "$$(WRAPPER)"
68 $$($1_$2_SHELL_WRAPPER_EXTRA)
69 $$($1_$2_INSTALL_SHELL_WRAPPER_EXTRA)
70 cat $$($1_$2_SHELL_WRAPPER_NAME) >> "$$(WRAPPER)"
71 $$(EXECUTABLE_FILE) "$$(WRAPPER)"
72
73 endif # $1_$2_INSTALL
74
75 endif # $1_$2_SHELL_WRAPPER && !Windows
76
77 $(call profEnd, shell-wrapper($1,$2))
78 endef