build: try to get dash/bash for sanity
[exim.git] / src / scripts / lookups-Makefile
CommitLineData
0a349494
PP
1#! /bin/sh
2
3# We turn the configure-built build-$foo/lookups/Makefile.predynamic into Makefile
4
bddd7526
PP
5# We always re-exec ourselves at least once, because it's the cleanest and
6# most portable way to turn on various features we expect of POSIX sh.
7if [ -z "$EXIM_LOOKUP_MAKEFILE_ADJUSTED" ]
4050a044 8then
bddd7526
PP
9 SHELL=/bin/sh
10 EXIM_LOOKUP_MAKEFILE_ADJUSTED=yes
11 export EXIM_LOOKUP_MAKEFILE_ADJUSTED
12
13 # Solaris sh and tr are problematic until we get xpg4 variants
14 if [ -x /usr/xpg4/bin/sh ]
15 then
16 PATH="/usr/xpg4/bin:$PATH"
17 export PATH
18 SHELL=/usr/xpg4/bin/sh
19 export SHELL
20 fi
21
22 # IRIX uses /bin/ksh for sh but in a compatibility mode unless $_XPG == 1,
23 # where said compatibility mode disables $(...)
24 _XPG=1
25 export _XPG
26
5c7706b0
PP
27 # We need the _right_ tr, so must do that first; but if a shell which
28 # we're more confident is sane is available, let's try that. Mostly,
29 # the problem is that "local" is not actually in "the" standard, it's
30 # just in every not-insane shell. Though arguably, there are no shells
31 # with POSIX-ish syntax which qualify as "not insane".
32 for b in /bin/dash /bin/bash /usr/local/bin/bash
33 do
34 if [ -x "$b" ]
35 then
36 SHELL="$b"
37 break
38 fi
39 done
40 # if we get a report of a system with zsh but not bash, we can add that
41 # to the list, but be sure to enable sh_word_split in that case.
42
bddd7526 43 exec "$SHELL" "$0" "$@"
4050a044
PP
44fi
45
0a349494 46input=lookups/Makefile.predynamic
58ee1eb6
TF
47target=lookups/Makefile.postdynamic
48defs_source=Makefile-t
0a349494
PP
49tag_marker='MAGIC-TAG-MODS-OBJ-RULES-GO-HERE'
50
51tab=' '
eec525c4 52
7b797365
PP
53# We rely on tr(1) for translating case below. Some people export
54# values of LC_CTYPE and LC_COLLATE which apparently break our assumptions.
55# We're a script expecting certain output based on known inputs and not dealing
56# with UTF8, so we should be safe doingthis:
57LC_ALL=C
58export LC_ALL
0a349494 59
5c7706b0
PP
60if [ -f "$defs_source" ]
61then
62 :
63 # we are happy
64else
65 echo >&2 "$0: ERROR: MISSING FILE '${defs_source}'"
66 echo >&2 "$0: SHOULD HAVE BEEN CALLED FROM scripts/Configure-Makefile"
67 exit 1
68fi
69
0cc9542a
PP
70# nb: do not permit leading whitespace for this, as CFLAGS_DYNAMIC is exported
71# to the lookups subdir via a line with leading whitespace which otherwise
72# matches
58ee1eb6 73if grep -q "^CFLAGS_DYNAMIC[ $tab?:]*=" "$defs_source"
0a349494
PP
74then
75 # we have a definition, we're good to go
58ee1eb6 76 echo >&2 ">>> Creating lookups/Makefile for building dynamic modules"
4050a044 77 enable_dynamic=yes
0a349494 78else
58ee1eb6 79 echo >&2 ">>> Creating lookups/Makefile without dynamic module support"
4050a044 80 enable_dynamic=''
7b797365
PP
81 # We always do something now, since there should always be a lookup,
82 # and now we need to run in order to put the OBJ=$(OBJ)+ rules in. So we
83 # continue on.
0a349494
PP
84fi
85
0cc9542a
PP
86# For the want_ checks, we need to let the user override values from the make
87# command-line, not just check the Makefile.
88
0a349494
PP
89want_dynamic() {
90 local dyn_name="$1"
0cc9542a
PP
91 local re="LOOKUP_${dyn_name}[ $tab]*=[ $tab]*2"
92 env | grep -q "^$re"
93 if [ $? -eq 0 ]; then return 0; fi
94 grep -q "^[ $tab]*$re" "$defs_source"
0a349494
PP
95}
96
97want_at_all() {
98 local want_name="$1"
0cc9542a
PP
99 local re="LOOKUP_${want_name}[ $tab]*=[ $tab]*."
100 env | grep -q "^$re"
101 if [ $? -eq 0 ]; then return 0; fi
102 grep -q "^[ $tab]*$re" "$defs_source"
0a349494
PP
103}
104
9bdd29ad
TL
105# Adapted want_at_all above to work for EXPERIMENTAL features
106want_experimental() {
107 local want_name="$1"
108 local re="EXPERIMENTAL_${want_name}[ $tab]*=[ $tab]*."
109 env | grep -q "^$re"
110 if [ $? -eq 0 ]; then return 0; fi
111 grep -q "^[ $tab]*$re" "$defs_source"
112}
113
159f52d2
TF
114# The values of these variables will be emitted into the Makefile.
115
116MODS=""
117OBJ=""
118
0a349494
PP
119emit_module_rule() {
120 local lookup_name="$1"
dde3daac 121 local mod_name pkgconf
0a349494
PP
122 if [ "${lookup_name%:*}" = "$lookup_name" ]
123 then
7245734e
TF
124 # Square brackets are redundant but benign for POSIX compliant tr,
125 # however Solaris /usr/bin/tr requires them. Sometimes Solaris
126 # gets installed without a complete set of xpg4 tools, sigh.
127 mod_name=$(echo $lookup_name | tr [A-Z] [a-z])
0a349494
PP
128 else
129 mod_name="${lookup_name#*:}"
130 lookup_name="${lookup_name%:*}"
131 fi
132
133 if want_dynamic "$lookup_name"
134 then
4050a044 135 if [ -z "$enable_dynamic" ]; then
58ee1eb6 136 echo >&2 "Missing CFLAGS_DYNAMIC prevents building dynamic $lookup_name"
4050a044
PP
137 exit 1
138 fi
159f52d2 139 MODS="${MODS} ${mod_name}.so"
dde3daac
PP
140 pkgconf=$(grep "^LOOKUP_${lookup_name}_PC" "$defs_source")
141 if [ $? -eq 0 ]; then
142 pkgconf=$(echo $pkgconf | sed 's/^.*= *//')
143 echo "LOOKUP_${mod_name}_INCLUDE = $(pkg-config --cflags $pkgconf)"
144 echo "LOOKUP_${mod_name}_LIBS = $(pkg-config --libs $pkgconf)"
145 else
146 grep "^LOOKUP_${lookup_name}_" "$defs_source"
147 echo "LOOKUP_${mod_name}_INCLUDE = \$(LOOKUP_${lookup_name}_INCLUDE)"
148 echo "LOOKUP_${mod_name}_LIBS = \$(LOOKUP_${lookup_name}_LIBS)"
149 fi
0a349494
PP
150 elif want_at_all "$lookup_name"
151 then
159f52d2 152 OBJ="${OBJ} ${mod_name}.o"
0a349494
PP
153 fi
154}
155
58ee1eb6 156rm -f "$target"
0a349494 157exec 5>&1
58ee1eb6 158exec > "$target"
0a349494
PP
159
160sed -n "1,/$tag_marker/p" < "$input"
161
162for name_mod in \
163 CDB DBM:dbmdb DNSDB DSEARCH IBASE LSEARCH MYSQL NIS NISPLUS ORACLE \
164 PASSWD PGSQL SQLITE TESTDB WHOSON
165do
166 emit_module_rule $name_mod
167done
168
169if want_at_all LDAP
170then
159f52d2 171 OBJ="${OBJ} ldap.o"
0a349494
PP
172fi
173
159f52d2
TF
174# Because the variable is EXPERIMENTAL_SPF and not LOOKUP_SPF we
175# always include spf.o and compile a dummy if EXPERIMENTAL_SPF is not
176# defined.
177
178OBJ="${OBJ} spf.o"
179
9bdd29ad
TL
180# Because the variable is EXPERIMENTAL_REDIS and not LOOKUP_REDIS we
181# use a different function to check for EXPERIMENTAL_* features
182# requested. Don't use the SPF method with dummy functions above.
183if want_experimental REDIS
184then
185 OBJ="${OBJ} redis.o"
186fi
187
159f52d2
TF
188echo "MODS = $MODS"
189echo "OBJ = $OBJ"
190
0a349494
PP
191sed -n "/$tag_marker/,\$p" < "$input"
192
193exec >&5
0a349494 194
58ee1eb6 195# Configure-Makefile will move $target into place
0a349494
PP
196
197# vim: set ft=sh sw=2 :