xref: /linux/scripts/headers_install.sh (revision 4ba24fef3eb3b142197135223b90ced2f319cd53)
1e0e2fa4bSRob Landley#!/bin/sh
2e0e2fa4bSRob Landley
3*f9a4d110SJavier Barrioif [ $# -lt 2 ]
4e0e2fa4bSRob Landleythen
5*f9a4d110SJavier Barrio	echo "Usage: headers_install.sh OUTDIR SRCDIR [FILES...]"
6e0e2fa4bSRob Landley	echo
7e0e2fa4bSRob Landley	echo "Prepares kernel header files for use by user space, by removing"
8e0e2fa4bSRob Landley	echo "all compiler.h definitions and #includes, removing any"
9e0e2fa4bSRob Landley	echo "#ifdef __KERNEL__ sections, and putting __underscores__ around"
10e0e2fa4bSRob Landley	echo "asm/inline/volatile keywords."
11e0e2fa4bSRob Landley	echo
12e0e2fa4bSRob Landley	echo "OUTDIR: directory to write each userspace header FILE to."
13c0ff68f1SNicolas Dichtel	echo "SRCDIR: source directory where files are picked."
14e0e2fa4bSRob Landley	echo "FILES:  list of header files to operate on."
15e0e2fa4bSRob Landley
16e0e2fa4bSRob Landley	exit 1
17e0e2fa4bSRob Landleyfi
18e0e2fa4bSRob Landley
19e0e2fa4bSRob Landley# Grab arguments
20e0e2fa4bSRob Landley
21e0e2fa4bSRob LandleyOUTDIR="$1"
22e0e2fa4bSRob Landleyshift
23c0ff68f1SNicolas DichtelSRCDIR="$1"
24c0ff68f1SNicolas Dichtelshift
25e0e2fa4bSRob Landley
26e0e2fa4bSRob Landley# Iterate through files listed on command line
27e0e2fa4bSRob Landley
28e0e2fa4bSRob LandleyFILE=
29e0e2fa4bSRob Landleytrap 'rm -f "$OUTDIR/$FILE" "$OUTDIR/$FILE.sed"' EXIT
30e0e2fa4bSRob Landleyfor i in "$@"
31e0e2fa4bSRob Landleydo
32e0e2fa4bSRob Landley	FILE="$(basename "$i")"
33e0e2fa4bSRob Landley	sed -r \
34e0e2fa4bSRob Landley		-e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
35e0e2fa4bSRob Landley		-e 's/__attribute_const__([ \t]|$)/\1/g' \
36e0e2fa4bSRob Landley		-e 's@^#include <linux/compiler.h>@@' \
37e0e2fa4bSRob Landley		-e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
38e0e2fa4bSRob Landley		-e 's/(^|[ \t(])(inline|asm|volatile)([ \t(]|$)/\1__\2__\3/g' \
39e0e2fa4bSRob Landley		-e 's@#(ifndef|define|endif[ \t]*/[*])[ \t]*_UAPI@#\1 @' \
40c0ff68f1SNicolas Dichtel		"$SRCDIR/$i" > "$OUTDIR/$FILE.sed" || exit 1
41e0e2fa4bSRob Landley	scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__ "$OUTDIR/$FILE.sed" \
42e0e2fa4bSRob Landley		> "$OUTDIR/$FILE"
43e0e2fa4bSRob Landley	[ $? -gt 1 ] && exit 1
44e0e2fa4bSRob Landley	rm -f "$OUTDIR/$FILE.sed"
45e0e2fa4bSRob Landleydone
46e0e2fa4bSRob Landleytrap - EXIT
47