3 # Copyright (c) The Exim Maintainers 1995 - 2021
4 # SPDX-License-Identifier: GPL-2.0-or-later
6 # We turn the configure-built build-$foo/lookups/Makefile.predynamic into Makefile
8 # We always re-exec ourselves at least once, because it's the cleanest and
9 # most portable way to turn on various features we expect of POSIX sh.
10 if [ -z "$EXIM_LOOKUP_MAKEFILE_ADJUSTED" ]
13 EXIM_LOOKUP_MAKEFILE_ADJUSTED=yes
14 export EXIM_LOOKUP_MAKEFILE_ADJUSTED
16 # Solaris sh and tr are problematic until we get xpg4 variants
17 if [ -x /usr/xpg4/bin/sh ]
19 PATH="/usr/xpg4/bin:$PATH"
21 SHELL=/usr/xpg4/bin/sh
25 # IRIX uses /bin/ksh for sh but in a compatibility mode unless $_XPG == 1,
26 # where said compatibility mode disables $(...)
30 # We need the _right_ tr, so must do that first; but if a shell which
31 # we're more confident is sane is available, let's try that. Mostly,
32 # the problem is that "local" is not actually in "the" standard, it's
33 # just in every not-insane shell. Though arguably, there are no shells
34 # with POSIX-ish syntax which qualify as "not insane".
35 for b in /bin/dash /bin/bash /usr/local/bin/bash
43 # if we get a report of a system with zsh but not bash, we can add that
44 # to the list, but be sure to enable sh_word_split in that case.
46 exec "$SHELL" "$0" "$@"
49 input=lookups/Makefile.predynamic
50 target=lookups/Makefile.postdynamic
51 defs_source=Makefile-t
52 tag_marker='MAGIC-TAG-MODS-OBJ-RULES-GO-HERE'
56 # We rely on tr(1) for translating case below. Some people export
57 # values of LC_CTYPE and LC_COLLATE which apparently break our assumptions.
58 # We're a script expecting certain output based on known inputs and not dealing
59 # with UTF8, so we should be safe doingthis:
63 if [ -f "$defs_source" ]
68 echo >&2 "$0: ERROR: MISSING FILE '${defs_source}'"
69 echo >&2 "$0: SHOULD HAVE BEEN CALLED FROM scripts/Configure-Makefile"
73 # nb: do not permit leading whitespace for this, as CFLAGS_DYNAMIC is exported
74 # to the lookups subdir via a line with leading whitespace which otherwise
76 if grep -q "^CFLAGS_DYNAMIC[ $tab?:]*=" "$defs_source"
78 # we have a definition, we're good to go
79 echo >&2 ">>> Creating lookups/Makefile for building dynamic modules"
82 echo >&2 ">>> Creating lookups/Makefile without dynamic module support"
84 # We always do something now, since there should always be a lookup,
85 # and now we need to run in order to put the OBJ=$(OBJ)+ rules in. So we
89 # For the want_ checks, we need to let the user override values from the make
90 # command-line, not just check the Makefile.
94 local re="LOOKUP_${dyn_name}[ $tab]*=[ $tab]*2"
96 if [ $? -eq 0 ]; then return 0; fi
97 grep -q "^[ $tab]*$re" "$defs_source"
102 local re="LOOKUP_${want_name}[ $tab]*=[ $tab]*."
104 if [ $? -eq 0 ]; then return 0; fi
105 grep -q "^[ $tab]*$re" "$defs_source"
108 # Adapted want_at_all above to work for EXPERIMENTAL features
109 want_experimental() {
111 local re="EXPERIMENTAL_${want_name}[ $tab]*=[ $tab]*."
113 if [ $? -eq 0 ]; then return 0; fi
114 grep -q "^[ $tab]*$re" "$defs_source"
117 # The values of these variables will be emitted into the Makefile.
123 local lookup_name="$1"
124 local mod_name pkgconf
125 if [ "${lookup_name%:*}" = "$lookup_name" ]
127 # Square brackets are redundant but benign for POSIX compliant tr,
128 # however Solaris /usr/bin/tr requires them. Sometimes Solaris
129 # gets installed without a complete set of xpg4 tools, sigh.
130 mod_name=$(echo $lookup_name | tr [A-Z] [a-z])
132 mod_name="${lookup_name#*:}"
133 lookup_name="${lookup_name%:*}"
136 if want_dynamic "$lookup_name"
138 if [ -z "$enable_dynamic" ]; then
139 echo >&2 "Missing CFLAGS_DYNAMIC prevents building dynamic $lookup_name"
142 MODS="${MODS} ${mod_name}.so"
143 pkgconf=$(grep "^LOOKUP_${lookup_name}_PC" "$defs_source")
144 if [ $? -eq 0 ]; then
145 pkgconf=$(echo $pkgconf | sed 's/^.*= *//')
146 echo "LOOKUP_${mod_name}_INCLUDE = $(pkg-config --cflags $pkgconf)"
147 echo "LOOKUP_${mod_name}_LIBS = $(pkg-config --libs $pkgconf)"
149 grep "^LOOKUP_${lookup_name}_" "$defs_source"
150 echo "LOOKUP_${mod_name}_INCLUDE = \$(LOOKUP_${lookup_name}_INCLUDE)"
151 echo "LOOKUP_${mod_name}_LIBS = \$(LOOKUP_${lookup_name}_LIBS)"
153 elif want_at_all "$lookup_name"
155 OBJ="${OBJ} ${mod_name}.o"
163 sed -n "1,/$tag_marker/p" < "$input"
166 CDB DBM:dbmdb DNSDB DSEARCH IBASE JSON LMDB LSEARCH MYSQL NIS NISPLUS ORACLE \
167 PASSWD PGSQL REDIS SQLITE TESTDB WHOSON
169 emit_module_rule $name_mod
177 # Because the variable is EXPERIMENTAL_SPF and not LOOKUP_SPF we
178 # always include spf.o and compile a dummy if EXPERIMENTAL_SPF is not
183 # readsock is always wanted as it implements the ${readsock } expansion
184 OBJ="${OBJ} readsock.o"
189 sed -n "/$tag_marker/,\$p" < "$input"
193 # Configure-Makefile will move $target into place
195 # vim: set ft=sh sw=2 :