]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libsysdecode/mklinuxtables
kdump: Decode Linux sigprocmask how argument
[FreeBSD/FreeBSD.git] / lib / libsysdecode / mklinuxtables
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 "David Kirchner" <dpk@dpk.net>. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 # 1. Redistributions of source code must retain the above copyright
9 #    notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 #    notice, this list of conditions and the following disclaimer in the
12 #    documentation and/or other materials provided with the distribution.
13 #
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 # SUCH DAMAGE.
25 #
26 # $FreeBSD$
27 #
28 # Generates tables_linux.h
29 #
30
31 set -e
32
33 LC_ALL=C; export LC_ALL
34
35 if [ -z "$1" ]
36 then
37         echo "usage: sh $0 include-dir [output-file]"
38         exit 1
39 fi
40 include_dir=$1
41 if [ -n "$2" ]; then
42         output_file="$2"
43         output_tmp=$(mktemp -u)
44         exec > "$output_tmp"
45 fi
46
47 all_headers=
48 #
49 # Generate a table C #definitions.  The including file can define the
50 # TABLE_NAME(n), TABLE_ENTRY(x), and TABLE_END macros to define what
51 # the tables map to.
52 #
53 gen_table()
54 {
55         local name grep file excl filter
56         name=$1
57         grep=$2
58         file=$3
59         excl=$4
60
61         if [ -z "$excl" ]; then
62                 filter="cat"
63         else
64                 filter="egrep -v"
65         fi
66         cat <<_EOF_
67 TABLE_START(${name})
68 _EOF_
69         if [ -e "${include_dir}/${file}" ]; then
70                 all_headers="${all_headers:+${all_headers} }${file}"
71                 egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
72                         $include_dir/$file | ${filter} ${excl} | \
73                 awk '{ for (i = 1; i <= NF; i++) \
74                         if ($i ~ /define/) \
75                                 break; \
76                         ++i; \
77                         sub(/LINUX_/, "", $i); \
78                         printf "TABLE_ENTRY(LINUX_%s, %s)\n", $i, $i }'
79         fi
80 cat <<_EOF_
81 TABLE_END
82
83 _EOF_
84 }
85
86 cat <<_EOF_
87 /* This file is auto-generated. */
88
89 _EOF_
90
91 gen_table "clockids"    "LINUX_CLOCK_[A-Z_]+[[:space:]]+[0-9]+"          "compat/linux/linux_timer.h"
92 gen_table "clockcpuids" "LINUX_CPUCLOCK_[A-Z_]+[[:space:]]+[0-9]+"       "compat/linux/linux_timer.h"   "_MASK|_MAX"
93 gen_table "sigprocmaskhow" "LINUX_SIG_[A-Z]+[[:space:]]+[0-9]+"          "compat/linux/linux.h"
94
95 # Generate a .depend file for our output file
96 if [ -n "$output_file" ]; then
97         depend_tmp=$(mktemp -u)
98         {
99                 echo "$output_file: \\"
100                 echo "$all_headers" | tr ' ' '\n' | sort -u |
101                     sed -e "s,^,        $include_dir/," -e 's,$, \\,'
102                 echo
103         } > "$depend_tmp"
104         if cmp -s "$output_tmp" "$output_file"; then
105                 rm -f "$output_tmp" "$depend_tmp"
106         else
107                 mv -f "$depend_tmp" ".depend.${output_file}"
108                 mv -f "$output_tmp" "$output_file"
109         fi
110 fi