3 # Copyright (c) The Exim Maintainers 1995 - 2021
5 # We turn the configure-built build-$foo/lookups/Makefile.predynamic into Makefile
7 # We always re-exec ourselves at least once, because it's the cleanest and
8 # most portable way to turn on various features we expect of POSIX sh.
9 if [ -z "$EXIM_LOOKUP_MAKEFILE_ADJUSTED" ]
12 EXIM_LOOKUP_MAKEFILE_ADJUSTED=yes
13 export EXIM_LOOKUP_MAKEFILE_ADJUSTED
15 # Solaris sh and tr are problematic until we get xpg4 variants
16 if [ -x /usr/xpg4/bin/sh ]
18 PATH="/usr/xpg4/bin:$PATH"
20 SHELL=/usr/xpg4/bin/sh
24 # IRIX uses /bin/ksh for sh but in a compatibility mode unless $_XPG == 1,
25 # where said compatibility mode disables $(...)
29 # We need the _right_ tr, so must do that first; but if a shell which
30 # we're more confident is sane is available, let's try that. Mostly,
31 # the problem is that "local" is not actually in "the" standard, it's
32 # just in every not-insane shell. Though arguably, there are no shells
33 # with POSIX-ish syntax which qualify as "not insane".
34 for b in /bin/dash /bin/bash /usr/local/bin/bash
42 # if we get a report of a system with zsh but not bash, we can add that
43 # to the list, but be sure to enable sh_word_split in that case.
45 exec "$SHELL" "$0" "$@"
48 input=lookups/Makefile.predynamic
49 target=lookups/Makefile.postdynamic
50 defs_source=Makefile-t
51 tag_marker='MAGIC-TAG-MODS-OBJ-RULES-GO-HERE'
55 # We rely on tr(1) for translating case below. Some people export
56 # values of LC_CTYPE and LC_COLLATE which apparently break our assumptions.
57 # We're a script expecting certain output based on known inputs and not dealing
58 # with UTF8, so we should be safe doingthis:
62 if [ -f "$defs_source" ]
67 echo >&2 "$0: ERROR: MISSING FILE '${defs_source}'"
68 echo >&2 "$0: SHOULD HAVE BEEN CALLED FROM scripts/Configure-Makefile"
72 # nb: do not permit leading whitespace for this, as CFLAGS_DYNAMIC is exported
73 # to the lookups subdir via a line with leading whitespace which otherwise
75 if grep -q "^CFLAGS_DYNAMIC[ $tab?:]*=" "$defs_source"
77 # we have a definition, we're good to go
78 echo >&2 ">>> Creating lookups/Makefile for building dynamic modules"
81 echo >&2 ">>> Creating lookups/Makefile without dynamic module support"
83 # We always do something now, since there should always be a lookup,
84 # and now we need to run in order to put the OBJ=$(OBJ)+ rules in. So we
88 # For the want_ checks, we need to let the user override values from the make
89 # command-line, not just check the Makefile.
93 local re="LOOKUP_${dyn_name}[ $tab]*=[ $tab]*2"
95 if [ $? -eq 0 ]; then return 0; fi
96 grep -q "^[ $tab]*$re" "$defs_source"
101 local re="LOOKUP_${want_name}[ $tab]*=[ $tab]*."
103 if [ $? -eq 0 ]; then return 0; fi
104 grep -q "^[ $tab]*$re" "$defs_source"
107 # Adapted want_at_all above to work for EXPERIMENTAL features
108 want_experimental() {
110 local re="EXPERIMENTAL_${want_name}[ $tab]*=[ $tab]*."
112 if [ $? -eq 0 ]; then return 0; fi
113 grep -q "^[ $tab]*$re" "$defs_source"
116 # The values of these variables will be emitted into the Makefile.
122 local lookup_name="$1"
123 local mod_name pkgconf
124 if [ "${lookup_name%:*}" = "$lookup_name" ]
126 # Square brackets are redundant but benign for POSIX compliant tr,
127 # however Solaris /usr/bin/tr requires them. Sometimes Solaris
128 # gets installed without a complete set of xpg4 tools, sigh.
129 mod_name=$(echo $lookup_name | tr [A-Z] [a-z])
131 mod_name="${lookup_name#*:}"
132 lookup_name="${lookup_name%:*}"
135 if want_dynamic "$lookup_name"
137 if [ -z "$enable_dynamic" ]; then
138 echo >&2 "Missing CFLAGS_DYNAMIC prevents building dynamic $lookup_name"
141 MODS="${MODS} ${mod_name}.so"
142 pkgconf=$(grep "^LOOKUP_${lookup_name}_PC" "$defs_source")
143 if [ $? -eq 0 ]; then
144 pkgconf=$(echo $pkgconf | sed 's/^.*= *//')
145 echo "LOOKUP_${mod_name}_INCLUDE = $(pkg-config --cflags $pkgconf)"
146 echo "LOOKUP_${mod_name}_LIBS = $(pkg-config --libs $pkgconf)"
148 grep "^LOOKUP_${lookup_name}_" "$defs_source"
149 echo "LOOKUP_${mod_name}_INCLUDE = \$(LOOKUP_${lookup_name}_INCLUDE)"
150 echo "LOOKUP_${mod_name}_LIBS = \$(LOOKUP_${lookup_name}_LIBS)"
152 elif want_at_all "$lookup_name"
154 OBJ="${OBJ} ${mod_name}.o"
162 sed -n "1,/$tag_marker/p" < "$input"
165 CDB DBM:dbmdb DNSDB DSEARCH IBASE JSON LMDB LSEARCH MYSQL NIS NISPLUS ORACLE \
166 PASSWD PGSQL REDIS SQLITE TESTDB WHOSON
168 emit_module_rule $name_mod
176 # Because the variable is EXPERIMENTAL_SPF and not LOOKUP_SPF we
177 # always include spf.o and compile a dummy if EXPERIMENTAL_SPF is not
182 # readsock is always wanted as it implements the ${readsock } expansion
183 OBJ="${OBJ} readsock.o"
188 sed -n "/$tag_marker/,\$p" < "$input"
192 # Configure-Makefile will move $target into place
194 # vim: set ft=sh sw=2 :