Get dynamic-by-default mostly working on OS X
[ghc.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 $(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_PROG).wrapper
21 endif
22
23 ifeq "$$($1_$2_WANT_INPLACE_WRAPPER)" "YES"
24
25 ifeq "$$($1_$2_TOPDIR)" "YES"
26 INPLACE_WRAPPER = $$(INPLACE_LIB)/$$($1_$2_PROG)
27 else
28 INPLACE_WRAPPER = $$(INPLACE_BIN)/$$($1_$2_PROG)
29 endif
30
31 all_$1_$2 : $$(INPLACE_WRAPPER)
32
33 $$(INPLACE_BIN)/$$($1_$2_PROG): WRAPPER=$$@
34 ifeq "$$($1_$2_SHELL_WRAPPER)" "YES"
35 $$(INPLACE_WRAPPER): $$($1_$2_SHELL_WRAPPER_NAME)
36 endif
37 $$(INPLACE_WRAPPER): $$($1_$2_INPLACE)
38 $$(call removeFiles, $$@)
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 ifeq "$$(DYNAMIC_BY_DEFAULT)" "YES"
48 ifeq "$$(TargetOS_CPP)" "linux"
49 echo 'export LD_LIBRARY_PATH="$$($1_$2_DEP_LIB_DIRS_SEARCHPATH)"' >> $$@
50 else ifeq "$$(TargetOS_CPP)" "darwin"
51 echo 'export DYLD_LIBRARY_PATH="$$($1_$2_DEP_LIB_DIRS_SEARCHPATH)"' >> $$@
52 endif
53 endif
54 ifeq "$$($1_$2_SHELL_WRAPPER)" "YES"
55 cat $$($1_$2_SHELL_WRAPPER_NAME) >> $$@
56 else
57 echo 'exec "$$$$executablename" $$$${1+"$$$$@"}' >> $$@
58 endif
59 $$(EXECUTABLE_FILE) $$@
60
61 endif
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 $(libexecdir), 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
94
95 $(call profEnd, shell-wrapper($1,$2))
96 endef