generate argz.c and argz.in.h from glibc sources
[gnulib.git] / config / argz.mk
1 # Generate argz.c and argz.in.h from glibc sources.
2
3 glibc_dir = ../glibc
4 glibc_dir = /mirror/d/glibc
5
6 argz_names = \
7   append addsep ctsep insert next stringify count \
8   extract create delete replace
9 argz_files = $(patsubst %, $(glibc_dir)/string/argz-%.c, $(argz_names))
10
11 define print-header
12   printf '%s\n'                                                         \
13 "/* Functions for dealing with '\0' separated arg vectors."             \
14 "   Copyright (C) 1995-1998, 2000-2002, 2006 Free Software Foundation, Inc."\
15 "   This file is part of the GNU C Library."                            \
16 ""                                                                      \
17 "   This program is free software; you can redistribute it and/or modify"\
18 "   it under the terms of the GNU General Public License as published by"\
19 "   the Free Software Foundation; either version 2, or (at your option)"\
20 "   any later version."                                                 \
21 ""                                                                      \
22 "   This program is distributed in the hope that it will be useful,"    \
23 "   but WITHOUT ANY WARRANTY; without even the implied warranty of"     \
24 "   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the"      \
25 "   GNU General Public License for more details."                       \
26 ""                                                                      \
27 "   You should have received a copy of the GNU General Public License along"\
28 "   with this program; if not, write to the Free Software Foundation,"  \
29 "   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */"\
30 ""                                                                      \
31 "#include <config.h>"                                                   \
32 ""                                                                      \
33 "#include <argz.h>"                                                     \
34 "#include <errno.h>"                                                    \
35 "#include <stdlib.h>"                                                   \
36 "#include <string.h>"
37 endef
38
39 targets = argz.c argz.in.h
40
41 all: $(targets)
42
43 argz.c: $(argz_files)
44         ($(print-header);                                               \
45          for i in $^; do                                                \
46            perl -pe 's/__(argz_|st|mem)/$$1/g' $$i                      \
47              | perl -0x0 -pe 's,/\*(.|\n)+?\*/\n,,'                     \
48              | grep -vE '^(#include|INTDEF|weak_alias|libc_hidden_def)'; \
49          done) > $@-t && mv $@-t $@
50
51 argz.in.h: $(glibc_dir)/string/argz.h
52         perl -pe 's/__(restrict|const|st|mem)/$$1/g;'                   \
53             -e 's/\s*__THROW//;'                                        \
54             -e 's/\s*__attribute_pure__//;'                             \
55           $<                                                            \
56           | perl -ne                                                    \
57             '/^(#include <features\.h>|__(?:BEGIN|END)_DECLS)/ or print' \
58           | perl -0x3b -pe 's/extern \S+ \*?__argz_(.|\n)*?\)\n*;//'    \
59           | perl -pe 's/__(argz_next)/$$1/g;'                           \
60           > $@-t && mv $@-t $@
61
62 clean:
63         rm -f $(targets)