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