Rob Landley | e0e2fa4 | 2013-03-27 10:24:11 +1100 | [diff] [blame] | 1 | #!/bin/sh |
Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0 |
Rob Landley | e0e2fa4 | 2013-03-27 10:24:11 +1100 | [diff] [blame] | 3 | |
Masahiro Yamada | 555187a | 2019-06-04 19:14:05 +0900 | [diff] [blame] | 4 | if [ $# -ne 2 ] |
Rob Landley | e0e2fa4 | 2013-03-27 10:24:11 +1100 | [diff] [blame] | 5 | then |
Masahiro Yamada | 555187a | 2019-06-04 19:14:05 +0900 | [diff] [blame] | 6 | echo "Usage: headers_install.sh INFILE OUTFILE" |
Rob Landley | e0e2fa4 | 2013-03-27 10:24:11 +1100 | [diff] [blame] | 7 | echo |
| 8 | echo "Prepares kernel header files for use by user space, by removing" |
| 9 | echo "all compiler.h definitions and #includes, removing any" |
| 10 | echo "#ifdef __KERNEL__ sections, and putting __underscores__ around" |
| 11 | echo "asm/inline/volatile keywords." |
| 12 | echo |
Masahiro Yamada | 555187a | 2019-06-04 19:14:05 +0900 | [diff] [blame] | 13 | echo "INFILE: header file to operate on" |
| 14 | echo "OUTFILE: output file which the processed header is writen to" |
Rob Landley | e0e2fa4 | 2013-03-27 10:24:11 +1100 | [diff] [blame] | 15 | |
| 16 | exit 1 |
| 17 | fi |
| 18 | |
| 19 | # Grab arguments |
Masahiro Yamada | 555187a | 2019-06-04 19:14:05 +0900 | [diff] [blame] | 20 | INFILE=$1 |
| 21 | OUTFILE=$2 |
| 22 | TMPFILE=$OUTFILE.tmp |
Rob Landley | e0e2fa4 | 2013-03-27 10:24:11 +1100 | [diff] [blame] | 23 | |
Masahiro Yamada | 555187a | 2019-06-04 19:14:05 +0900 | [diff] [blame] | 24 | trap 'rm -f $OUTFILE $TMPFILE' EXIT |
Rob Landley | e0e2fa4 | 2013-03-27 10:24:11 +1100 | [diff] [blame] | 25 | |
Masahiro Yamada | 555187a | 2019-06-04 19:14:05 +0900 | [diff] [blame] | 26 | sed -E -e ' |
| 27 | s/([[:space:](])(__user|__force|__iomem)[[:space:]]/\1/g |
| 28 | s/__attribute_const__([[:space:]]|$)/\1/g |
| 29 | s@^#include <linux/compiler(|_types).h>@@ |
| 30 | s/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g |
| 31 | s/(^|[[:space:](])(inline|asm|volatile)([[:space:](]|$)/\1__\2__\3/g |
| 32 | s@#(ifndef|define|endif[[:space:]]*/[*])[[:space:]]*_UAPI@#\1 @ |
| 33 | ' $INFILE > $TMPFILE || exit 1 |
Rob Landley | e0e2fa4 | 2013-03-27 10:24:11 +1100 | [diff] [blame] | 34 | |
Masahiro Yamada | 555187a | 2019-06-04 19:14:05 +0900 | [diff] [blame] | 35 | scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__ $TMPFILE > $OUTFILE |
| 36 | [ $? -gt 1 ] && exit 1 |
| 37 | |
| 38 | rm -f $TMPFILE |
Rob Landley | e0e2fa4 | 2013-03-27 10:24:11 +1100 | [diff] [blame] | 39 | trap - EXIT |