Bug 139: portability fixes and documentation.
[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 if grep -q "^LOOKUP.*=[ $tab]*2" "$defs_source"
12 then
13   # we have work to do
14 else
15   echo "No dynamic module loading support"
16   cp "$input" "$target"
17   exit 0
18 fi
19
20 if grep -q "^CFLAGS_DYNAMIC[ $tab]*=" "$defs_source"
21 then
22   # we have a definition, we're good to go
23 else
24   echo >&2 "Missing CFLAGS_DYNAMIC inhibits building dynamic module lookup"
25   exit 1
26 fi
27
28 tmp="$target.t"
29
30 want_dynamic() {
31   local dyn_name="$1"
32   grep -q "^LOOKUP_${dyn_name}[ $tab]*=[ $tab]*2" "$defs_source"
33 }
34
35 want_at_all() {
36   local want_name="$1"
37   grep -q "^LOOKUP_${want_name}[ $tab]*=[ $tab]*." "$defs_source"
38 }
39
40 emit_module_rule() {
41   local lookup_name="$1"
42   local mod_name
43   if [ "${lookup_name%:*}" = "$lookup_name" ]
44   then
45     mod_name=$(echo $lookup_name | tr A-Z a-z)
46   else
47     mod_name="${lookup_name#*:}"
48     lookup_name="${lookup_name%:*}"
49   fi
50
51   if want_dynamic "$lookup_name"
52   then
53     echo "MODS += ${mod_name}.so"
54     echo "LOOKUP_${mod_name}_INCLUDE = \$(LOOKUP_${lookup_name}_INCLUDE)"
55     echo "LOOKUP_${mod_name}_LIBS = \$(LOOKUP_${lookup_name}_LIBS)"
56   elif want_at_all "$lookup_name"
57   then
58     echo "OBJ += ${mod_name}.o"
59   fi
60 }
61
62 exec 5>&1
63 exec > "$tmp"
64
65 sed -n "1,/$tag_marker/p" < "$input"
66
67 for name_mod in \
68     CDB DBM:dbmdb DNSDB DSEARCH IBASE LSEARCH MYSQL NIS NISPLUS ORACLE \
69     PASSWD PGSQL SQLITE TESTDB WHOSON
70 do
71   emit_module_rule $name_mod
72 done
73
74 if want_at_all LDAP
75 then
76   echo "OBJ += ldap.o"
77 fi
78
79 sed -n "/$tag_marker/,\$p" < "$input"
80
81 exec >&5
82 mv "$tmp" "$target"
83
84
85 # vim: set ft=sh sw=2 :