Make test-suite client cmd -t<timeout> actually work
[exim.git] / src / scripts / lookups-Makefile
1 #! /bin/sh
2
3 # We turn the configure-built build-$foo/lookups/Makefile.predynamic into Makefile
4
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.
7 if [ -z "$EXIM_LOOKUP_MAKEFILE_ADJUSTED" ]
8 then
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
27 exec "$SHELL" "$0" "$@"
28 fi
29
30 input=lookups/Makefile.predynamic
31 target=lookups/Makefile
32 defs_source=Makefile
33 tag_marker='MAGIC-TAG-MODS-OBJ-RULES-GO-HERE'
34
35 tab=' '
36
37 # We rely on tr(1) for translating case below. Some people export
38 # values of LC_CTYPE and LC_COLLATE which apparently break our assumptions.
39 # We're a script expecting certain output based on known inputs and not dealing
40 # with UTF8, so we should be safe doingthis:
41 LC_ALL=C
42 export LC_ALL
43
44 # nb: do not permit leading whitespace for this, as CFLAGS_DYNAMIC is exported
45 # to the lookups subdir via a line with leading whitespace which otherwise
46 # matches
47 if grep -q "^CFLAGS_DYNAMIC[ $tab]*=" "$defs_source"
48 then
49 # we have a definition, we're good to go
50 enable_dynamic=yes
51 else
52 echo >&2 "Missing CFLAGS_DYNAMIC inhibits building dynamic module lookup"
53 enable_dynamic=''
54 # We always do something now, since there should always be a lookup,
55 # and now we need to run in order to put the OBJ=$(OBJ)+ rules in. So we
56 # continue on.
57 fi
58
59 tmp="$target.t"
60
61 # For the want_ checks, we need to let the user override values from the make
62 # command-line, not just check the Makefile.
63
64 want_dynamic() {
65 local dyn_name="$1"
66 local re="LOOKUP_${dyn_name}[ $tab]*=[ $tab]*2"
67 env | grep -q "^$re"
68 if [ $? -eq 0 ]; then return 0; fi
69 grep -q "^[ $tab]*$re" "$defs_source"
70 }
71
72 want_at_all() {
73 local want_name="$1"
74 local re="LOOKUP_${want_name}[ $tab]*=[ $tab]*."
75 env | grep -q "^$re"
76 if [ $? -eq 0 ]; then return 0; fi
77 grep -q "^[ $tab]*$re" "$defs_source"
78 }
79
80 # The values of these variables will be emitted into the Makefile.
81
82 MODS=""
83 OBJ=""
84
85 emit_module_rule() {
86 local lookup_name="$1"
87 local mod_name pkgconf
88 if [ "${lookup_name%:*}" = "$lookup_name" ]
89 then
90 mod_name=$(echo $lookup_name | tr A-Z a-z)
91 else
92 mod_name="${lookup_name#*:}"
93 lookup_name="${lookup_name%:*}"
94 fi
95
96 if want_dynamic "$lookup_name"
97 then
98 if [ -z "$enable_dynamic" ]; then
99 echo >&2 "Inhibited dynamic modules prevents building dynamic $lookup_name"
100 exit 1
101 fi
102 MODS="${MODS} ${mod_name}.so"
103 pkgconf=$(grep "^LOOKUP_${lookup_name}_PC" "$defs_source")
104 if [ $? -eq 0 ]; then
105 pkgconf=$(echo $pkgconf | sed 's/^.*= *//')
106 echo "LOOKUP_${mod_name}_INCLUDE = $(pkg-config --cflags $pkgconf)"
107 echo "LOOKUP_${mod_name}_LIBS = $(pkg-config --libs $pkgconf)"
108 else
109 grep "^LOOKUP_${lookup_name}_" "$defs_source"
110 echo "LOOKUP_${mod_name}_INCLUDE = \$(LOOKUP_${lookup_name}_INCLUDE)"
111 echo "LOOKUP_${mod_name}_LIBS = \$(LOOKUP_${lookup_name}_LIBS)"
112 fi
113 elif want_at_all "$lookup_name"
114 then
115 OBJ="${OBJ} ${mod_name}.o"
116 fi
117 }
118
119 exec 5>&1
120 exec > "$tmp"
121
122 sed -n "1,/$tag_marker/p" < "$input"
123
124 for name_mod in \
125 CDB DBM:dbmdb DNSDB DSEARCH IBASE LSEARCH MYSQL NIS NISPLUS ORACLE \
126 PASSWD PGSQL SQLITE TESTDB WHOSON
127 do
128 emit_module_rule $name_mod
129 done
130
131 if want_at_all LDAP
132 then
133 OBJ="${OBJ} ldap.o"
134 fi
135
136 # Because the variable is EXPERIMENTAL_SPF and not LOOKUP_SPF we
137 # always include spf.o and compile a dummy if EXPERIMENTAL_SPF is not
138 # defined.
139
140 OBJ="${OBJ} spf.o"
141
142 echo "MODS = $MODS"
143 echo "OBJ = $OBJ"
144
145 sed -n "/$tag_marker/,\$p" < "$input"
146
147 exec >&5
148 mv "$tmp" "$target"
149
150
151 # vim: set ft=sh sw=2 :