Pass the location of gcc in the ghc wrapper script; partially fixes #3863
[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): WRAPPER=$$@
36 $$(INPLACE_BIN)/$$($1_$2_PROG): $$($1_$2_INPLACE)
37         "$$(RM)" $$(RM_OPTS)                              $$@
38         echo '#!$$(SHELL)'                             >> $$@
39         echo 'executablename="$$(TOP)/$$<"'            >> $$@
40         echo 'datadir="$$(TOP)/$$(INPLACE_LIB)"'       >> $$@
41         echo 'bindir="$$(TOP)/$$(INPLACE_BIN)"'        >> $$@
42         echo 'topdir="$$(TOP)/$$(INPLACE_TOPDIR)"'     >> $$@
43         echo 'pgmgcc="$$(WhatGccIsCalled)"'            >> $$@
44         $$($1_$2_SHELL_WRAPPER_EXTRA)
45         $$($1_$2_INPLACE_SHELL_WRAPPER_EXTRA)
46         cat $$($1_$2_SHELL_WRAPPER_NAME)               >> $$@
47         $$(EXECUTABLE_FILE)                               $$@
48 endif
49
50 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER)" "YES"
51
52 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)" ""
53 $1_$2_INSTALL_SHELL_WRAPPER_NAME = $$($1_$2_PROG)
54 endif
55
56 # Install the binary in $(libexecdir), and install a shell wrapper in $(bindir)
57 INSTALL_LIBEXECS += $1/$2/build/tmp/$$($1_$2_PROG)
58 BINDIST_WRAPPERS += $$($1_$2_SHELL_WRAPPER_NAME)
59
60 install: install_$1_$2_wrapper
61
62 .PHONY: install_$1_$2_wrapper
63 install_$1_$2_wrapper: WRAPPER=$$(DESTDIR)$$(bindir)/$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)
64 install_$1_$2_wrapper:
65         $$(INSTALL_DIR) "$$(DESTDIR)$$(bindir)"
66         "$$(RM)" $$(RM_OPTS)                                        "$$(WRAPPER)"
67         $$(CREATE_SCRIPT)                                           "$$(WRAPPER)"
68         echo '#!$$(SHELL)'                                       >> "$$(WRAPPER)"
69         echo 'exedir="$$(ghclibexecdir)"'                        >> "$$(WRAPPER)"
70         echo 'exeprog="$$($1_$2_PROG)"'                          >> "$$(WRAPPER)"
71         echo 'executablename="$$$$exedir/$$$$exeprog"'           >> "$$(WRAPPER)"
72         echo 'datadir="$$(datadir)"'                             >> "$$(WRAPPER)"
73         echo 'bindir="$$(bindir)"'                               >> "$$(WRAPPER)"
74         echo 'topdir="$$(topdir)"'                               >> "$$(WRAPPER)"
75         echo 'pgmgcc="$$(WhatGccIsCalled)"'                      >> "$$(WRAPPER)"
76         $$($1_$2_SHELL_WRAPPER_EXTRA)
77         $$($1_$2_INSTALL_SHELL_WRAPPER_EXTRA)
78         cat $$($1_$2_SHELL_WRAPPER_NAME)                         >> "$$(WRAPPER)"
79         $$(EXECUTABLE_FILE)                                         "$$(WRAPPER)"
80
81 endif # $1_$2_INSTALL_SHELL_WRAPPER
82
83 endif
84
85 endif # $1_$2_SHELL_WRAPPER
86
87 endef