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