Merge branch 'master' of git://git.exim.org/exim
[users/heiko/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 input=lookups/Makefile.predynamic
6 target=lookups/Makefile
7 defs_source=Makefile
8 tag_marker='MAGIC-TAG-MODS-OBJ-RULES-GO-HERE'
9
10 tab='   '
11
12 # We always do something now, since there should always be a lookup,
13 # and now we need to run in order to put the OBJ+= rules in.
14
15 if grep -q "^CFLAGS_DYNAMIC[ $tab]*=" "$defs_source"
16 then
17   # we have a definition, we're good to go
18   : # noop (true) statement for bash compatibility
19 else
20   echo >&2 "Missing CFLAGS_DYNAMIC inhibits building dynamic module lookup"
21   exit 1
22 fi
23
24 tmp="$target.t"
25
26 want_dynamic() {
27   local dyn_name="$1"
28   grep -q "^LOOKUP_${dyn_name}[ $tab]*=[ $tab]*2" "$defs_source"
29 }
30
31 want_at_all() {
32   local want_name="$1"
33   grep -q "^LOOKUP_${want_name}[ $tab]*=[ $tab]*." "$defs_source"
34 }
35
36 emit_module_rule() {
37   local lookup_name="$1"
38   local mod_name
39   if [ "${lookup_name%:*}" = "$lookup_name" ]
40   then
41     mod_name=$(echo $lookup_name | tr A-Z a-z)
42   else
43     mod_name="${lookup_name#*:}"
44     lookup_name="${lookup_name%:*}"
45   fi
46
47   if want_dynamic "$lookup_name"
48   then
49     echo "MODS += ${mod_name}.so"
50     grep "^LOOKUP_${lookup_name}_" "$defs_source"
51     echo "LOOKUP_${mod_name}_INCLUDE = \$(LOOKUP_${lookup_name}_INCLUDE)"
52     echo "LOOKUP_${mod_name}_LIBS = \$(LOOKUP_${lookup_name}_LIBS)"
53   elif want_at_all "$lookup_name"
54   then
55     echo "OBJ += ${mod_name}.o"
56   fi
57 }
58
59 exec 5>&1
60 exec > "$tmp"
61
62 sed -n "1,/$tag_marker/p" < "$input"
63
64 for name_mod in \
65     CDB DBM:dbmdb DNSDB DSEARCH IBASE LSEARCH MYSQL NIS NISPLUS ORACLE \
66     PASSWD PGSQL SQLITE TESTDB WHOSON
67 do
68   emit_module_rule $name_mod
69 done
70
71 if want_at_all LDAP
72 then
73   echo "OBJ += ldap.o"
74 fi
75
76 sed -n "/$tag_marker/,\$p" < "$input"
77
78 exec >&5
79 mv "$tmp" "$target"
80
81
82 # vim: set ft=sh sw=2 :