merge GHC HEAD
[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 $(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)" "YES"
20
21 ifeq "$$(Windows)" "YES"
22
23 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER)" "YES"
24 # Just install the binary on Windows
25 $1_$2_INSTALL = YES
26 endif
27
28 else
29
30 ifeq "$$($1_$2_SHELL_WRAPPER_NAME)" ""
31 $1_$2_SHELL_WRAPPER_NAME = $1/$$($1_$2_PROG).wrapper
32 endif
33
34 ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
35 all_$1_$2 : $$(INPLACE_BIN)/$$($1_$2_PROG)
36
37 $$(INPLACE_BIN)/$$($1_$2_PROG): WRAPPER=$$@
38 $$(INPLACE_BIN)/$$($1_$2_PROG): $$($1_$2_INPLACE) $$($1_$2_SHELL_WRAPPER_NAME)
39         "$$(RM)" $$(RM_OPTS)                              $$@
40         echo '#!$$(SHELL)'                             >> $$@
41         echo 'executablename="$$(TOP)/$$<"'            >> $$@
42         echo 'datadir="$$(TOP)/$$(INPLACE_LIB)"'       >> $$@
43         echo 'bindir="$$(TOP)/$$(INPLACE_BIN)"'        >> $$@
44         echo 'topdir="$$(TOP)/$$(INPLACE_TOPDIR)"'     >> $$@
45         echo 'pgmgcc="$$(WhatGccIsCalled)"'            >> $$@
46         $$($1_$2_SHELL_WRAPPER_EXTRA)
47         $$($1_$2_INPLACE_SHELL_WRAPPER_EXTRA)
48         cat $$($1_$2_SHELL_WRAPPER_NAME)               >> $$@
49         $$(EXECUTABLE_FILE)                               $$@
50 endif
51
52 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER)" "YES"
53
54 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)" ""
55 $1_$2_INSTALL_SHELL_WRAPPER_NAME = $$($1_$2_PROG)
56 endif
57
58 # Install the binary in $(libexecdir), and install a shell wrapper in $(bindir)
59 INSTALL_LIBEXECS += $1/$2/build/tmp/$$($1_$2_PROG)
60 BINDIST_WRAPPERS += $$($1_$2_SHELL_WRAPPER_NAME)
61
62 install: install_$1_$2_wrapper
63
64 .PHONY: install_$1_$2_wrapper
65 install_$1_$2_wrapper: WRAPPER=$$(DESTDIR)$$(bindir)/$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)
66 install_$1_$2_wrapper:
67         $$(call INSTALL_DIR,"$$(DESTDIR)$$(bindir)")
68         "$$(RM)" $$(RM_OPTS)                                        "$$(WRAPPER)"
69         $$(CREATE_SCRIPT)                                           "$$(WRAPPER)"
70         echo '#!$$(SHELL)'                                       >> "$$(WRAPPER)"
71         echo 'exedir="$$(ghclibexecdir)"'                        >> "$$(WRAPPER)"
72         echo 'exeprog="$$($1_$2_PROG)"'                          >> "$$(WRAPPER)"
73         echo 'executablename="$$$$exedir/$$$$exeprog"'           >> "$$(WRAPPER)"
74         echo 'datadir="$$(datadir)"'                             >> "$$(WRAPPER)"
75         echo 'bindir="$$(bindir)"'                               >> "$$(WRAPPER)"
76         echo 'topdir="$$(topdir)"'                               >> "$$(WRAPPER)"
77         $$($1_$2_SHELL_WRAPPER_EXTRA)
78         $$($1_$2_INSTALL_SHELL_WRAPPER_EXTRA)
79         cat $$($1_$2_SHELL_WRAPPER_NAME)                         >> "$$(WRAPPER)"
80         $$(EXECUTABLE_FILE)                                         "$$(WRAPPER)"
81
82 endif # $1_$2_INSTALL_SHELL_WRAPPER
83
84 endif
85
86 endif # $1_$2_SHELL_WRAPPER
87
88 $(call profEnd, shell-wrapper($1,$2))
89 endef