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