Build system: check $CLEANING instead of $MAKECMDGOALS
[ghc.git] / rules / shell-wrapper.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009-2012 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://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://ghc.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_NAME)" ""
20 $1_$2_SHELL_WRAPPER_NAME = $1/$$($1_$2_PROGNAME).wrapper
21 endif
22
23 ifeq "$$($1_$2_WANT_INPLACE_WRAPPER)" "YES"
24
25 $1_$2_INPLACE_SHELL_WRAPPER_NAME = $$($1_$2_PROG)
26
27 ifeq "$$($1_$2_TOPDIR)" "YES"
28 INPLACE_WRAPPER = $$(INPLACE_LIB)/$$($1_$2_INPLACE_SHELL_WRAPPER_NAME)
29 else
30 INPLACE_WRAPPER = $$(INPLACE_BIN)/$$($1_$2_INPLACE_SHELL_WRAPPER_NAME)
31 endif
32
33 all_$1_$2 : $$(INPLACE_WRAPPER)
34
35 $$(INPLACE_WRAPPER): WRAPPER=$$@
36 ifeq "$$($1_$2_SHELL_WRAPPER)" "YES"
37 $$(INPLACE_WRAPPER): $$($1_$2_SHELL_WRAPPER_NAME)
38 endif
39 $$(INPLACE_WRAPPER): $$($1_$2_INPLACE)
40 $$(call removeFiles, $$@)
41 echo '#!$$(SHELL)' >> $$@
42 echo 'executablename="$$(TOP)/$$<"' >> $$@
43 echo 'datadir="$$(TOP)/$$(INPLACE_LIB)"' >> $$@
44 echo 'bindir="$$(TOP)/$$(INPLACE_BIN)"' >> $$@
45 echo 'topdir="$$(TOP)/$$(INPLACE_TOPDIR)"' >> $$@
46 echo 'pgmgcc="$$(WhatGccIsCalled)"' >> $$@
47 $$($1_$2_SHELL_WRAPPER_EXTRA)
48 $$($1_$2_INPLACE_SHELL_WRAPPER_EXTRA)
49 ifeq "$$(DYNAMIC_GHC_PROGRAMS)" "YES"
50 echo '$$(call prependLibraryPath,$$($1_$2_DEP_LIB_DIRS_SEARCHPATH))' >> $$@
51 endif
52 ifeq "$$($1_$2_SHELL_WRAPPER)" "YES"
53 cat $$($1_$2_SHELL_WRAPPER_NAME) >> $$@
54 else
55 echo 'exec "$$$$executablename" $$$${1+"$$$$@"}' >> $$@
56 endif
57 $$(EXECUTABLE_FILE) $$@
58
59 endif
60
61 ifeq "$$($1_$2_WANT_INSTALLED_WRAPPER)" "YES"
62
63 ifeq "$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)" ""
64 $1_$2_INSTALL_SHELL_WRAPPER_NAME = $$($1_$2_PROG)
65 endif
66
67 # Install the binary in $(ghclibexecdir), and install a shell wrapper in $(bindir)
68 INSTALL_LIBEXECS += $1/$2/build/tmp/$$($1_$2_PROG)
69 BINDIST_WRAPPERS += $$($1_$2_SHELL_WRAPPER_NAME)
70
71 install: install_$1_$2_wrapper
72
73 .PHONY: install_$1_$2_wrapper
74 install_$1_$2_wrapper: WRAPPER=$$(DESTDIR)$$(bindir)/$(CrossCompilePrefix)$$($1_$2_INSTALL_SHELL_WRAPPER_NAME)
75 install_$1_$2_wrapper:
76 $$(call INSTALL_DIR,"$$(DESTDIR)$$(bindir)")
77 $$(call removeFiles, "$$(WRAPPER)")
78 $$(CREATE_SCRIPT) "$$(WRAPPER)"
79 echo '#!$$(SHELL)' >> "$$(WRAPPER)"
80 echo 'exedir="$$(ghclibexecdir)/bin"' >> "$$(WRAPPER)"
81 echo 'exeprog="$$($1_$2_PROG)"' >> "$$(WRAPPER)"
82 echo 'executablename="$$$$exedir/$$$$exeprog"' >> "$$(WRAPPER)"
83 echo 'datadir="$$(datadir)"' >> "$$(WRAPPER)"
84 echo 'bindir="$$(bindir)"' >> "$$(WRAPPER)"
85 echo 'topdir="$$(topdir)"' >> "$$(WRAPPER)"
86 $$($1_$2_SHELL_WRAPPER_EXTRA)
87 $$($1_$2_INSTALL_SHELL_WRAPPER_EXTRA)
88 cat $$($1_$2_SHELL_WRAPPER_NAME) >> "$$(WRAPPER)"
89 $$(EXECUTABLE_FILE) "$$(WRAPPER)"
90
91 endif
92
93 ifeq "$$($1_$2_WANT_BINDIST_WRAPPER)" "YES"
94 ifneq "$$(TargetOS_CPP)" "mingw32"
95
96 $1_$2_BINDIST_WRAPPER = $1/$2/build/tmp/$$($1_$2_PROGNAME)-bindist
97
98 all_$1_$2 : $$($1_$2_BINDIST_WRAPPER)
99
100 BINDIST_EXTRAS += $$($1_$2_BINDIST_WRAPPER)
101
102 $$($1_$2_BINDIST_WRAPPER): $1/$2/build/tmp/$$($1_$2_PROG)
103 $$(call removeFiles, $$@)
104 echo '#!$$(SHELL)' >> $$@
105 ifeq "$$(DYNAMIC_GHC_PROGRAMS)" "YES"
106 echo '$$(call prependLibraryPath,$$($1_$2_DEP_LIB_REL_DIRS_SEARCHPATH))' >> $$@
107 endif
108 echo 'exec "$$<" $$$${1+"$$$$@"}' >> $$@
109 $$(EXECUTABLE_FILE) $$@
110
111 endif
112 endif
113
114 $(call profEnd, shell-wrapper($1,$2))
115 endef