Let /dev/null have normal permissions.
[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     echo "LOOKUP_${mod_name}_INCLUDE = \$(LOOKUP_${lookup_name}_INCLUDE)"
51     echo "LOOKUP_${mod_name}_LIBS = \$(LOOKUP_${lookup_name}_LIBS)"
52   elif want_at_all "$lookup_name"
53   then
54     echo "OBJ += ${mod_name}.o"
55   fi
56 }
57
58 exec 5>&1
59 exec > "$tmp"
60
61 sed -n "1,/$tag_marker/p" < "$input"
62
63 for name_mod in \
64     CDB DBM:dbmdb DNSDB DSEARCH IBASE LSEARCH MYSQL NIS NISPLUS ORACLE \
65     PASSWD PGSQL SQLITE TESTDB WHOSON
66 do
67   emit_module_rule $name_mod
68 done
69
70 if want_at_all LDAP
71 then
72   echo "OBJ += ldap.o"
73 fi
74
75 sed -n "/$tag_marker/,\$p" < "$input"
76
77 exec >&5
78 mv "$tmp" "$target"
79
80
81 # vim: set ft=sh sw=2 :