micro-opt: replace stmGetEnclosingTRec() with a field access
[ghc-hetmet.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         echo 'topdir=$$(TOP)/$$(INPLACE_TOPDIR)'       >> $$@
42         cat $$($1_$2_SHELL_WRAPPER_NAME)               >> $$@
43         $$(EXECUTABLE_FILE)                               $$@
44 endif
45
46 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER)" "YES"
47
48 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)" ""
49 $1_$2_INSTALL_SHELL_WRAPPER_NAME = $$($1_$2_PROG)
50 endif
51
52 # Install the binary in $(libexecdir), and install a shell wrapper in $(bindir)
53 INSTALL_LIBEXECS += $1/$2/build/tmp/$$($1_$2_PROG)
54 BINDIST_WRAPPERS += $$($1_$2_SHELL_WRAPPER_NAME)
55
56 install: install_$1_$2_wrapper
57
58 .PHONY: install_$1_$2_wrapper
59 install_$1_$2_wrapper: WRAPPER=$$(DESTDIR)$$(bindir)/$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)
60 install_$1_$2_wrapper:
61         $$(INSTALL_DIR) $$(DESTDIR)$$(bindir)
62         "$$(RM)" $$(RM_OPTS)                                      $$(WRAPPER)
63         $$(CREATE_SCRIPT)                                         $$(WRAPPER)
64         echo '#!$$(SHELL)'                                     >> $$(WRAPPER)
65         echo 'executablename=$$(ghclibexecdir)/$$($1_$2_PROG)' >> $$(WRAPPER)
66         echo 'datadir=$$(datadir)'                             >> $$(WRAPPER)
67         echo 'bindir=$$(bindir)'                               >> $$(WRAPPER)
68         echo 'topdir=$$(topdir)'                               >> $$(WRAPPER)
69         cat $$($1_$2_SHELL_WRAPPER_NAME)                       >> $$(WRAPPER)
70         $$(EXECUTABLE_FILE)                                       $$(WRAPPER)
71
72 endif # $1_$2_INSTALL_SHELL_WRAPPER
73
74 endif
75
76 endif # $1_$2_SHELL_WRAPPER
77
78 endef