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/routers/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_ROUTER_MAKEFILE_ADJUSTED" ]
13 EXIM_ROUTER_MAKEFILE_ADJUSTED=yes
14 export EXIM_ROUTER_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=routers/Makefile.predynamic
50 target=routers/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 doing this:
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 routers/Makefile for building dynamic modules"
82 echo >&2 ">>> Creating routers/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="ROUTER_${dyn_name}[ $tab]*=[ $tab]*2"
96 if [ $? -eq 0 ]; then return 0; fi
97 grep -q "^[ $tab]*$re" "$defs_source"
102 local re="ROUTER_${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.
124 local mod_name pkgconf
125 if [ "${name%:*}" = "$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 $name | tr [A-Z] [a-z])
132 mod_name="${name#*:}"
136 if want_dynamic "$name"
138 if [ -z "$enable_dynamic" ]; then
139 echo >&2 "Missing CFLAGS_DYNAMIC prevents building dynamic $name"
142 MODS="${MODS} ${mod_name}.so"
143 # pkgconf=$(grep "^ROUTER_${name}_PC" "$defs_source")
144 # if [ $? -eq 0 ]; then
145 # pkgconf=$(echo $pkgconf | sed 's/^.*= *//')
146 # echo "ROUTER_${mod_name}_INCLUDE = $(pkg-config --cflags $pkgconf)"
147 # echo "ROUTER_${mod_name}_LIBS = $(pkg-config --libs $pkgconf)"
149 # grep "^ROUTER_${name}_" "$defs_source"
150 # echo "ROUTER_${mod_name}_INCLUDE = \$(ROUTER_${name}_INCLUDE)"
151 # echo "ROUTER_${mod_name}_LIBS = \$(ROUTER_${name}_LIBS)"
153 elif want_at_all "$name"
155 OBJ="${OBJ} ${mod_name}.o"
163 sed -n "1,/$tag_marker/p" < "$input"
166 ACCEPT DNSLOOKUP IPLITERAL IPLOOKUP MANUALROUTE QUERYPROGRAM REDIRECT
168 emit_module_rule $name_mod
174 sed -n "/$tag_marker/,\$p" < "$input"
178 # Configure-Makefile will move $target into place
180 # vim: set ft=sh sw=2 :