Update.
[glibc.git] / nss / db-Makefile
blob220419c7a96c1ae614988bdf991e8f892f7ed3d3
1 # Makefile to (re-)generate db versions of system database files.
2 # Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
4 # Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Library General Public License as
8 # published by the Free Software Foundation; either version 2 of the
9 # License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # Library General Public License for more details.
16 # You should have received a copy of the GNU Library General Public
17 # License along with the GNU C Library; see the file COPYING.LIB.  If not,
18 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, USA.  */
21 DATABASES = $(wildcard /etc/passwd /etc/group /etc/ethers /etc/protocols \
22                        /etc/rpc /etc/services /etc/shadow /etc/netgroup)
24 VAR_DB = /var/db
26 AWK = awk
27 MAKEDB = makedb --quiet
29 all: $(patsubst %,$(VAR_DB)/%.db,$(notdir $(DATABASES)))
32 $(VAR_DB)/passwd.db: /etc/passwd
33         @echo -n "$(patsubst %.db,%,$(@F))... "
34         @$(AWK) 'BEGIN { FS=":"; OFS=":"; cnt=0 } \
35                  /^[ \t]*$$/ { next } \
36                  /^[ \t]*#/ { next } \
37                  { printf "0%u ", cnt++; print } \
38                  /^[^#]/ { printf ".%s ", $$1; print; \
39                            printf "=%s ", $$3; print }' $^ | \
40         $(MAKEDB) -o $@ -
41         @echo "done."
43 $(VAR_DB)/group.db: /etc/group
44         @echo -n "$(patsubst %.db,%,$(@F))... "
45         @$(AWK) 'BEGIN { FS=":"; OFS=":"; cnt=0 } \
46                  /^[ \t]*$$/ { next } \
47                  /^[ \t]*#/ { next } \
48                  { printf "0%u ", cnt++; print } \
49                  /^[^#]/ { printf ".%s ", $$1; print; \
50                            printf "=%s ", $$3; print }' $^ | \
51         $(MAKEDB) -o $@ -
52         @echo "done."
54 $(VAR_DB)/ethers.db: /etc/ethers
55         @echo -n "$(patsubst %.db,%,$(@F))... "
56         @$(AWK) 'BEGIN { cnt=0 } \
57                  /^[ \t]*$$/ { next } \
58                  /^[ \t]*#/ { next } \
59                  { printf "0%u ", cnt++; print } \
60                  /^[^#]/ { printf ".%s ", $$1; print; \
61                            printf "=%s ", $$2; print }' $^ | \
62         $(MAKEDB) -o $@ -
63         @echo "done."
65 $(VAR_DB)/protocols.db: /etc/protocols
66         @echo -n "$(patsubst %.db,%,$(@F))... "
67         @$(AWK) 'BEGIN { cnt=0 } \
68                  /^[ \t]*$$/ { next } \
69                  /^[ \t]*#/ { next } \
70                  { printf "0%u ", cnt++; print } \
71                  /^[^#]/ { printf ".%s ", $$1; print; \
72                            printf "=%s ", $$2; print; \
73                            for (i = 3; i <= NF && !($$i ~ /^#/); ++i) \
74                              { printf ".%s ", $$i; print } }' $^ | \
75         $(MAKEDB) -o $@ -
76         @echo "done."
78 $(VAR_DB)/rpc.db: /etc/rpc
79         @echo -n "$(patsubst %.db,%,$(@F))... "
80         @$(AWK) 'BEGIN { cnt=0 } \
81                  /^[ \t]*$$/ { next } \
82                  /^[ \t]*#/ { next } \
83                  { printf "0%u ", cnt++; print } \
84                  /^[^#]/ { printf ".%s ", $$1; print; \
85                            printf "=%s ", $$2; print; \
86                            for (i = 3; i <= NF && !($$i ~ /^#/); ++i) \
87                              { printf ".%s ", $$i; print } }' $^ | \
88         $(MAKEDB) -o $@ -
89         @echo "done."
91 $(VAR_DB)/services.db: /etc/services
92         @echo -n "$(patsubst %.db,%,$(@F))... "
93         @$(AWK) 'BEGIN { FS="[ \t/]+"; cnt=0 } \
94                  /^[ \t]*$$/ { next } \
95                  /^[ \t]*#/ { next } \
96                  { printf "0%u ", cnt++; print } \
97                  /^[^#]/ { printf ".%s/%s ", $$1, $$3; print; \
98                            printf ".%s/ ", $$1; print; \
99                            printf "=%s/%s ", $$2, $$3; print; \
100                            printf "=%s/ ", $$2; print; \
101                            for (i = 4; i <= NF && !($$i ~ /^#/); ++i) \
102                              { printf ".%s/%s ", $$i, $$3; print; \
103                                printf ".%s/ ", $$i; print } }' $^ | \
104         $(MAKEDB) -o $@ -
105         @echo "done."
107 $(VAR_DB)/shadow.db: /etc/shadow
108         @echo -n "$(patsubst %.db,%,$(@F))... "
109         @$(AWK) 'BEGIN { FS=":"; OFS=":"; cnt=0 } \
110                  /^[ \t]*$$/ { next } \
111                  /^[ \t]*#/ { next } \
112                  { printf "0%u ", cnt++; print } \
113                  /^[^#]/ { printf ".%s ", $$1; print }' $^ | \
114         (umask 077 && $(MAKEDB) -o $@ -)
115         @echo "done."
116         @if chgrp shadow $@ 2>/dev/null; then \
117           chmod g+r $@; \
118         else \
119           chown 0 $@; chgrp 0 $@; chmod 600 $@; \
120           echo; \
121           echo "Warning: The shadow password database $@"; \
122           echo "has been set to be readable only by root.  You may want"; \
123           echo "to make it readable by the \`shadow' group depending"; \
124           echo "on your configuration."; \
125           echo; \
126         fi
128 $(VAR_DB)/netgroup.db: /etc/netgroup
129         @echo -n "$(patsubst %.db,%,$(@F))... "
130         @$(AWK) 'BEGIN { cnt=0 } \
131                  /^[ \t]*$$/ { next } \
132                  /^[ \t]*#/ { next } \
133                  { printf "0%u ", cnt++; print } \
134                  /^[^#]/ { end=sub(/\\/, " "); \
135                            gsub(/[ \t]+/, " "); \
136                            if(end == 1) printf "%s", $$0; else print }' $^ | \
137         $(MAKEDB) -o $@ -
138         @echo "done."