Bug-fix the xpg4 Solaris logic.
[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+= rules in.
23
24 if grep -q "^CFLAGS_DYNAMIC[ $tab]*=" "$defs_source"
25 then
26   # we have a definition, we're good to go
27   enable_dynamic=yes
28 else
29   echo >&2 "Missing CFLAGS_DYNAMIC inhibits building dynamic module lookup"
30   enable_dynamic=''
31 fi
32
33 tmp="$target.t"
34
35 want_dynamic() {
36   local dyn_name="$1"
37   grep -q "^LOOKUP_${dyn_name}[ $tab]*=[ $tab]*2" "$defs_source"
38 }
39
40 want_at_all() {
41   local want_name="$1"
42   grep -q "^LOOKUP_${want_name}[ $tab]*=[ $tab]*." "$defs_source"
43 }
44
45 emit_module_rule() {
46   local lookup_name="$1"
47   local mod_name
48   if [ "${lookup_name%:*}" = "$lookup_name" ]
49   then
50     mod_name=$(echo $lookup_name | tr A-Z a-z)
51   else
52     mod_name="${lookup_name#*:}"
53     lookup_name="${lookup_name%:*}"
54   fi
55
56   if want_dynamic "$lookup_name"
57   then
58     if [ -z "$enable_dynamic" ]; then
59       echo >&2 "Inhibited dynamic modules prevents building dynamic $lookup_name"
60       exit 1
61     fi
62     echo "MODS += ${mod_name}.so"
63     grep "^LOOKUP_${lookup_name}_" "$defs_source"
64     echo "LOOKUP_${mod_name}_INCLUDE = \$(LOOKUP_${lookup_name}_INCLUDE)"
65     echo "LOOKUP_${mod_name}_LIBS = \$(LOOKUP_${lookup_name}_LIBS)"
66   elif want_at_all "$lookup_name"
67   then
68     echo "OBJ += ${mod_name}.o"
69   fi
70 }
71
72 exec 5>&1
73 exec > "$tmp"
74
75 sed -n "1,/$tag_marker/p" < "$input"
76
77 for name_mod in \
78     CDB DBM:dbmdb DNSDB DSEARCH IBASE LSEARCH MYSQL NIS NISPLUS ORACLE \
79     PASSWD PGSQL SQLITE TESTDB WHOSON
80 do
81   emit_module_rule $name_mod
82 done
83
84 if want_at_all LDAP
85 then
86   echo "OBJ += ldap.o"
87 fi
88
89 sed -n "/$tag_marker/,\$p" < "$input"
90
91 exec >&5
92 mv "$tmp" "$target"
93
94
95 # vim: set ft=sh sw=2 :