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