3 # Copyright (c) The Exim Maintainers 1995 - 2024
4 # SPDX-License-Identifier: GPL-2.0-or-later
10 # We turn the configure-built build-$foo/$class/Makefile.predynamic into Makefile.
11 # This is used for router and transport drivers, called from scripts/Configure-Makefile.
13 # We always re-exec ourselves at least once, because it's the cleanest and
14 # most portable way to turn on various features we expect of POSIX sh.
15 if [ -z "$EXIM_DRIVER_MAKEFILE_ADJUSTED" ]
18 EXIM_DRIVER_MAKEFILE_ADJUSTED=yes
19 export EXIM_DRIVER_MAKEFILE_ADJUSTED
21 # Solaris sh and tr are problematic until we get xpg4 variants
22 if [ -x /usr/xpg4/bin/sh ]
24 PATH="/usr/xpg4/bin:$PATH"
26 SHELL=/usr/xpg4/bin/sh
30 # IRIX uses /bin/ksh for sh but in a compatibility mode unless $_XPG == 1,
31 # where said compatibility mode disables $(...)
35 # We need the _right_ tr, so must do that first; but if a shell which
36 # we're more confident is sane is available, let's try that. Mostly,
37 # the problem is that "local" is not actually in "the" standard, it's
38 # just in every not-insane shell. Though arguably, there are no shells
39 # with POSIX-ish syntax which qualify as "not insane".
40 for b in /bin/dash /bin/bash /usr/local/bin/bash
48 # if we get a report of a system with zsh but not bash, we can add that
49 # to the list, but be sure to enable sh_word_split in that case.
51 exec "$SHELL" "$0" "$@"
54 input=$class/Makefile.predynamic
55 target=$class/Makefile.postdynamic
56 defs_source=Makefile-t
57 tag_marker='MAGIC-TAG-MODS-OBJ-RULES-GO-HERE'
61 # We rely on tr(1) for translating case below. Some people export
62 # values of LC_CTYPE and LC_COLLATE which apparently break our assumptions.
63 # We're a script expecting certain output based on known inputs and not dealing
64 # with UTF8, so we should be safe doing this:
68 if [ -f "$defs_source" ]
73 echo >&2 "$0: ERROR: MISSING FILE '${defs_source}'"
74 echo >&2 "$0: SHOULD HAVE BEEN CALLED FROM scripts/Configure-Makefile"
78 # nb: do not permit leading whitespace for this, as CFLAGS_DYNAMIC is exported
79 # to the lookups subdir via a line with leading whitespace which otherwise
81 if grep -q "^CFLAGS_DYNAMIC[ $tab?:]*=" "$defs_source"
83 # we have a definition, we're good to go
84 echo >&2 ">>> Creating $class/Makefile for building dynamic modules"
87 echo >&2 ">>> Creating $class/Makefile without dynamic module support"
89 # We always do something now, since there should always be a lookup,
90 # and now we need to run in order to put the OBJ=$(OBJ)+ rules in. So we
94 # For the want_ checks, we need to let the user override values from the make
95 # command-line, not just check the Makefile.
98 local dyn_name="${1#_}"
99 local re="(${classdef}|EXPERIMENTAL)_${dyn_name}[ $tab]*=[ $tab]*2"
100 #XXX Solaris does not support -E on grep. Must use egrep.
101 env | grep -E -q "^$re"
102 if [ $? -eq 0 ]; then return 0; fi
103 grep -E -q "^[ $tab]*$re" "$defs_source"
106 want_not_disabled() {
107 local want_name="${1#_}"
108 [ "$local_want_name" = "$1" ] && return 0;
109 local re="DISABLED_${want_name}[ $tab]*=[ $tab]*."
110 env | grep -E -q "^$re"
111 [ $? -ne 0 ] && return 0
112 grep -E -q "^[ $tab]*$re" "$defs_source"
113 [ $? -ne 0 ] && return 0
119 local re="(${classdef}|EXPERIMENTAL)_${want_name}[ $tab]*=[ $tab]*."
120 env | grep -E -q "^$re"
121 if [ $? -eq 0 ]; then return 0; fi
122 grep -E -q "^[ $tab]*$re" "$defs_source"
125 # The values of these variables will be emitted into the Makefile.
132 local mod_name pkgconf
133 if [ "${name%:*}" = "$name" ]
135 # Square brackets are redundant but benign for POSIX compliant tr,
136 # however Solaris /usr/bin/tr requires them. Sometimes Solaris
137 # gets installed without a complete set of xpg4 tools, sigh.
138 mod_name=$(echo $name | tr [A-Z] [a-z])
140 mod_name="${name#*:}"
144 if want_dynamic "$name"
146 if [ -z "$enable_dynamic" ]; then
147 echo >&2 "Missing CFLAGS_DYNAMIC prevents building dynamic $name"
150 MODS="${MODS} ${mod_name#_}.so"
151 grep "^${classdef}_${name}_PC" "$defs_source" 1>&2
152 pkgconf=$(grep "^${classdef}_${name}_PC" "$defs_source")
153 if [ $? -eq 0 ]; then
154 pkgconf=$(echo $pkgconf | sed 's/^.*= *//')
155 echo "${classdef}_${mod_name#_}_INCLUDE = $(pkg-config --cflags $pkgconf)"
156 echo "${classdef}_${mod_name#_}_LIBS = $(pkg-config --libs $pkgconf)"
158 grep "^${classdef}_${name}_" "$defs_source"
159 echo "${classdef}_${mod_name#_}_INCLUDE = \$(${classdef}_${name}_INCLUDE)"
160 echo "${classdef}_${mod_name#_}_LIBS = \$(${classdef}_${name}_LIBS)"
162 elif want_not_disabled "$name"; then
163 OBJ="${OBJ} ${mod_name#_}.o"
164 elif want_at_all "$name"; then
165 OBJ="${OBJ} ${mod_name}.o"
173 sed -n "1,/$tag_marker/p" < "$input"
175 for name_mod in $drnames
177 emit_module_rule $name_mod
183 sed -n "/$tag_marker/,\$p" < "$input"
187 # Configure-Makefile will move $target into place
189 # vim: set ft=sh sw=2 :