Commit | Line | Data |
---|---|---|
0a349494 PP |
1 | #! /bin/sh |
2 | ||
3 | # We turn the configure-built build-$foo/lookups/Makefile.predynamic into Makefile | |
4 | ||
88d5edb0 | 5 | if [ -x /usr/xpg4/bin/sh ] && [ -z "$EXIM_BLOCK_XPG4_LOOP" ] |
4050a044 PP |
6 | then |
7 | EXIM_BLOCK_XPG4_LOOP=yes | |
8 | export EXIM_BLOCK_XPG4_LOOP | |
9 | PATH="/usr/xpg4/bin:$PATH" | |
10 | export PATH | |
88d5edb0 | 11 | exec /usr/xpg4/bin/sh "$0" "$@" |
4050a044 PP |
12 | fi |
13 | ||
0a349494 PP |
14 | input=lookups/Makefile.predynamic |
15 | target=lookups/Makefile | |
16 | defs_source=Makefile | |
17 | tag_marker='MAGIC-TAG-MODS-OBJ-RULES-GO-HERE' | |
18 | ||
19 | tab=' ' | |
eec525c4 | 20 | |
7b797365 PP |
21 | # We rely on tr(1) for translating case below. Some people export |
22 | # values of LC_CTYPE and LC_COLLATE which apparently break our assumptions. | |
23 | # We're a script expecting certain output based on known inputs and not dealing | |
24 | # with UTF8, so we should be safe doingthis: | |
25 | LC_ALL=C | |
26 | export LC_ALL | |
0a349494 | 27 | |
0cc9542a PP |
28 | # nb: do not permit leading whitespace for this, as CFLAGS_DYNAMIC is exported |
29 | # to the lookups subdir via a line with leading whitespace which otherwise | |
30 | # matches | |
0a349494 PP |
31 | if grep -q "^CFLAGS_DYNAMIC[ $tab]*=" "$defs_source" |
32 | then | |
33 | # we have a definition, we're good to go | |
4050a044 | 34 | enable_dynamic=yes |
0a349494 PP |
35 | else |
36 | echo >&2 "Missing CFLAGS_DYNAMIC inhibits building dynamic module lookup" | |
4050a044 | 37 | enable_dynamic='' |
7b797365 PP |
38 | # We always do something now, since there should always be a lookup, |
39 | # and now we need to run in order to put the OBJ=$(OBJ)+ rules in. So we | |
40 | # continue on. | |
0a349494 PP |
41 | fi |
42 | ||
43 | tmp="$target.t" | |
44 | ||
0cc9542a PP |
45 | # For the want_ checks, we need to let the user override values from the make |
46 | # command-line, not just check the Makefile. | |
47 | ||
0a349494 PP |
48 | want_dynamic() { |
49 | local dyn_name="$1" | |
0cc9542a PP |
50 | local re="LOOKUP_${dyn_name}[ $tab]*=[ $tab]*2" |
51 | env | grep -q "^$re" | |
52 | if [ $? -eq 0 ]; then return 0; fi | |
53 | grep -q "^[ $tab]*$re" "$defs_source" | |
0a349494 PP |
54 | } |
55 | ||
56 | want_at_all() { | |
57 | local want_name="$1" | |
0cc9542a PP |
58 | local re="LOOKUP_${want_name}[ $tab]*=[ $tab]*." |
59 | env | grep -q "^$re" | |
60 | if [ $? -eq 0 ]; then return 0; fi | |
61 | grep -q "^[ $tab]*$re" "$defs_source" | |
0a349494 PP |
62 | } |
63 | ||
159f52d2 TF |
64 | # The values of these variables will be emitted into the Makefile. |
65 | ||
66 | MODS="" | |
67 | OBJ="" | |
68 | ||
0a349494 PP |
69 | emit_module_rule() { |
70 | local lookup_name="$1" | |
71 | local mod_name | |
72 | if [ "${lookup_name%:*}" = "$lookup_name" ] | |
73 | then | |
74 | mod_name=$(echo $lookup_name | tr A-Z a-z) | |
75 | else | |
76 | mod_name="${lookup_name#*:}" | |
77 | lookup_name="${lookup_name%:*}" | |
78 | fi | |
79 | ||
80 | if want_dynamic "$lookup_name" | |
81 | then | |
4050a044 PP |
82 | if [ -z "$enable_dynamic" ]; then |
83 | echo >&2 "Inhibited dynamic modules prevents building dynamic $lookup_name" | |
84 | exit 1 | |
85 | fi | |
159f52d2 | 86 | MODS="${MODS} ${mod_name}.so" |
56e0c4ce | 87 | grep "^LOOKUP_${lookup_name}_" "$defs_source" |
0a349494 PP |
88 | echo "LOOKUP_${mod_name}_INCLUDE = \$(LOOKUP_${lookup_name}_INCLUDE)" |
89 | echo "LOOKUP_${mod_name}_LIBS = \$(LOOKUP_${lookup_name}_LIBS)" | |
90 | elif want_at_all "$lookup_name" | |
91 | then | |
159f52d2 | 92 | OBJ="${OBJ} ${mod_name}.o" |
0a349494 PP |
93 | fi |
94 | } | |
95 | ||
96 | exec 5>&1 | |
97 | exec > "$tmp" | |
98 | ||
99 | sed -n "1,/$tag_marker/p" < "$input" | |
100 | ||
101 | for name_mod in \ | |
102 | CDB DBM:dbmdb DNSDB DSEARCH IBASE LSEARCH MYSQL NIS NISPLUS ORACLE \ | |
103 | PASSWD PGSQL SQLITE TESTDB WHOSON | |
104 | do | |
105 | emit_module_rule $name_mod | |
106 | done | |
107 | ||
108 | if want_at_all LDAP | |
109 | then | |
159f52d2 | 110 | OBJ="${OBJ} ldap.o" |
0a349494 PP |
111 | fi |
112 | ||
159f52d2 TF |
113 | # Because the variable is EXPERIMENTAL_SPF and not LOOKUP_SPF we |
114 | # always include spf.o and compile a dummy if EXPERIMENTAL_SPF is not | |
115 | # defined. | |
116 | ||
117 | OBJ="${OBJ} spf.o" | |
118 | ||
119 | echo "MODS = $MODS" | |
120 | echo "OBJ = $OBJ" | |
121 | ||
0a349494 PP |
122 | sed -n "/$tag_marker/,\$p" < "$input" |
123 | ||
124 | exec >&5 | |
125 | mv "$tmp" "$target" | |
126 | ||
127 | ||
128 | # vim: set ft=sh sw=2 : |