Debian Codegraph @

m4/header.m4

raw
1 # header.m4 -- Generate headers from kernel source
2
3 # Copyright 2002 Purdue Research Foundation, West Lafayette,
4 # Indiana 47907. All rights reserved.
5 #
6 # Written by Victor A. Abell
7 #
8 # This software is not subject to any license of the American
9 # Telephone and Telegraph Company or the Regents of the
10 # University of California.
11 #
12 # Permission is granted to anyone to use this software for
13 # any purpose on any computer system, and to alter it and
14 # redistribute it freely, subject to the following
15 # restrictions:
16 #
17 # 1. Neither the authors nor Purdue University are responsible
18 # for any consequences of the use of this software.
19 #
20 # 2. The origin of this software must not be misrepresented,
21 # either by explicit claim or by omission. Credit to the
22 # authors and Purdue University must appear in documentation
23 # and sources.
24 #
25 # 3. Altered versions must be plainly marked as such, and must
26 # not be misrepresented as being the original software.
27 #
28 # 4. This notice may not be removed or altered.
29
30 # HEADER_GENERATE([HEADER_NAME, KERNEL_SOURCE, PATTERN_BEGIN, PATTERN_END, MACRO])
31 # Create HEADER_NAME header from KERNEL_SOURCE,
32 # copying the code between lines matching PATTERN_BEGIN and PATTERN_END.
33 # The header is guarded from including twice by defining MACRO.
34 AC_DEFUN([HEADER_GENERATE], [
35 # Generate HEADER_NAME($1) from KERNEL_SOURCE($2)
36 rm -rf $1
37 AS_IF([test -r $2], [
38 # Find the line number of PATTERN_BEGIN($3)
39 # Note extra quoting [[]] for M4
40 LSOF_TMP1=$(grep -n $3 $2 | sed 's/\([[0-9]]*\):.*$/\1/')
41 AS_IF([test "X$LSOF_TMP1" != "X"], [
42 LSOF_TMP2=0
43 # Find the end of PATTERN_END($4)
44 for i in $(grep -n $4 $2 | sed 's/\([[0-9]]*\):.*/\1/') # {
45 do
46 AS_IF([test $LSOF_TMP2 -eq 0 -a $i -gt $LSOF_TMP1], [
47 LSOF_TMP2=$i
48 ])
49 done
50 AS_IF([test $LSOF_TMP2 -eq 0], [
51 LSOF_TMP1=""
52 ], [
53 cat > $1 << EOF
54 /*
55 * $1 -- created by lsof configure script on
56 EOF
57 printf " * " >> $1
58 date >> $1
59 cat >> $1 << EOF
60 */
61
62 #if !defined($5)
63 #define $5
64
65 EOF
66 ed -s $2 >> $1 << EOF
67 ${LSOF_TMP1},${LSOF_TMP2}p
68 EOF
69 AS_IF([test $? -ne 0], [
70 AC_MSG_ERROR([can't extract source from $2])
71 ], [
72 cat >> $1 << EOF
73
74 #endif /* defined($5) */
75 EOF
76 ])
77 ])
78 ])
79 ], [
80 AC_MSG_ERROR([can't read $2])
81 ])
82 ]))