quickrelease: A dumb script for making source-only tarballs
[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
27 exec "$SHELL" "$0" "$@"
4050a044
PP
28fi
29
0a349494 30input=lookups/Makefile.predynamic
58ee1eb6
TF
31target=lookups/Makefile.postdynamic
32defs_source=Makefile-t
0a349494
PP
33tag_marker='MAGIC-TAG-MODS-OBJ-RULES-GO-HERE'
34
35tab=' '
eec525c4 36
7b797365
PP
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:
41LC_ALL=C
42export LC_ALL
0a349494 43
0cc9542a
PP
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
58ee1eb6 47if grep -q "^CFLAGS_DYNAMIC[ $tab?:]*=" "$defs_source"
0a349494
PP
48then
49 # we have a definition, we're good to go
58ee1eb6 50 echo >&2 ">>> Creating lookups/Makefile for building dynamic modules"
4050a044 51 enable_dynamic=yes
0a349494 52else
58ee1eb6 53 echo >&2 ">>> Creating lookups/Makefile without dynamic module support"
4050a044 54 enable_dynamic=''
7b797365
PP
55 # We always do something now, since there should always be a lookup,
56 # and now we need to run in order to put the OBJ=$(OBJ)+ rules in. So we
57 # continue on.
0a349494
PP
58fi
59
0cc9542a
PP
60# For the want_ checks, we need to let the user override values from the make
61# command-line, not just check the Makefile.
62
0a349494
PP
63want_dynamic() {
64 local dyn_name="$1"
0cc9542a
PP
65 local re="LOOKUP_${dyn_name}[ $tab]*=[ $tab]*2"
66 env | grep -q "^$re"
67 if [ $? -eq 0 ]; then return 0; fi
68 grep -q "^[ $tab]*$re" "$defs_source"
0a349494
PP
69}
70
71want_at_all() {
72 local want_name="$1"
0cc9542a
PP
73 local re="LOOKUP_${want_name}[ $tab]*=[ $tab]*."
74 env | grep -q "^$re"
75 if [ $? -eq 0 ]; then return 0; fi
76 grep -q "^[ $tab]*$re" "$defs_source"
0a349494
PP
77}
78
9bdd29ad
TL
79# Adapted want_at_all above to work for EXPERIMENTAL features
80want_experimental() {
81 local want_name="$1"
82 local re="EXPERIMENTAL_${want_name}[ $tab]*=[ $tab]*."
83 env | grep -q "^$re"
84 if [ $? -eq 0 ]; then return 0; fi
85 grep -q "^[ $tab]*$re" "$defs_source"
86}
87
159f52d2
TF
88# The values of these variables will be emitted into the Makefile.
89
90MODS=""
91OBJ=""
92
0a349494
PP
93emit_module_rule() {
94 local lookup_name="$1"
dde3daac 95 local mod_name pkgconf
0a349494
PP
96 if [ "${lookup_name%:*}" = "$lookup_name" ]
97 then
98 mod_name=$(echo $lookup_name | tr A-Z a-z)
99 else
100 mod_name="${lookup_name#*:}"
101 lookup_name="${lookup_name%:*}"
102 fi
103
104 if want_dynamic "$lookup_name"
105 then
4050a044 106 if [ -z "$enable_dynamic" ]; then
58ee1eb6 107 echo >&2 "Missing CFLAGS_DYNAMIC prevents building dynamic $lookup_name"
4050a044
PP
108 exit 1
109 fi
159f52d2 110 MODS="${MODS} ${mod_name}.so"
dde3daac
PP
111 pkgconf=$(grep "^LOOKUP_${lookup_name}_PC" "$defs_source")
112 if [ $? -eq 0 ]; then
113 pkgconf=$(echo $pkgconf | sed 's/^.*= *//')
114 echo "LOOKUP_${mod_name}_INCLUDE = $(pkg-config --cflags $pkgconf)"
115 echo "LOOKUP_${mod_name}_LIBS = $(pkg-config --libs $pkgconf)"
116 else
117 grep "^LOOKUP_${lookup_name}_" "$defs_source"
118 echo "LOOKUP_${mod_name}_INCLUDE = \$(LOOKUP_${lookup_name}_INCLUDE)"
119 echo "LOOKUP_${mod_name}_LIBS = \$(LOOKUP_${lookup_name}_LIBS)"
120 fi
0a349494
PP
121 elif want_at_all "$lookup_name"
122 then
159f52d2 123 OBJ="${OBJ} ${mod_name}.o"
0a349494
PP
124 fi
125}
126
58ee1eb6 127rm -f "$target"
0a349494 128exec 5>&1
58ee1eb6 129exec > "$target"
0a349494
PP
130
131sed -n "1,/$tag_marker/p" < "$input"
132
133for name_mod in \
134 CDB DBM:dbmdb DNSDB DSEARCH IBASE LSEARCH MYSQL NIS NISPLUS ORACLE \
135 PASSWD PGSQL SQLITE TESTDB WHOSON
136do
137 emit_module_rule $name_mod
138done
139
140if want_at_all LDAP
141then
159f52d2 142 OBJ="${OBJ} ldap.o"
0a349494
PP
143fi
144
159f52d2
TF
145# Because the variable is EXPERIMENTAL_SPF and not LOOKUP_SPF we
146# always include spf.o and compile a dummy if EXPERIMENTAL_SPF is not
147# defined.
148
149OBJ="${OBJ} spf.o"
150
9bdd29ad
TL
151# Because the variable is EXPERIMENTAL_REDIS and not LOOKUP_REDIS we
152# use a different function to check for EXPERIMENTAL_* features
153# requested. Don't use the SPF method with dummy functions above.
154if want_experimental REDIS
155then
156 OBJ="${OBJ} redis.o"
157fi
158
159f52d2
TF
159echo "MODS = $MODS"
160echo "OBJ = $OBJ"
161
0a349494
PP
162sed -n "/$tag_marker/,\$p" < "$input"
163
164exec >&5
0a349494 165
58ee1eb6 166# Configure-Makefile will move $target into place
0a349494
PP
167
168# vim: set ft=sh sw=2 :