headers_install.pl 1.8 KB
Newer Older
1
#!/usr/bin/perl -w
2 3 4 5
#
# headers_install prepare the listed header files for use in
# user space and copy the files to their destination.
#
6
# Usage: headers_install.pl readdir installdir arch [files...]
7
# installdir: dir to install the files to
8 9 10 11
# arch:       current architecture
#             arch is used to force a reinstallation when the arch
#             changes because kbuild then detect a command line change.
# files:      list of files to check
12 13 14 15 16 17 18 19
#
# Step in preparation for users space:
# 1) Drop all use of compiler.h definitions
# 2) Drop include of compiler.h
# 3) Drop all sections defined out by __KERNEL__ (using unifdef)

use strict;

20
my ($installdir, $arch, @files) = @ARGV;
21

22
my $unifdef = "scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__";
23

24 25 26 27
foreach my $filename (@files) {
	my $file = $filename;
	$file =~ s!^.*/!!;

28
	my $tmpfile = "$installdir/$file.tmp";
29

30 31
	open(my $in, '<', $filename)
	    or die "$filename: $!\n";
32 33 34
	open(my $out, '>', $tmpfile)
	    or die "$tmpfile: $!\n";
	while (my $line = <$in>) {
35 36 37 38 39
		$line =~ s/([\s(])__user\s/$1/g;
		$line =~ s/([\s(])__force\s/$1/g;
		$line =~ s/([\s(])__iomem\s/$1/g;
		$line =~ s/\s__attribute_const__\s/ /g;
		$line =~ s/\s__attribute_const__$//g;
40
		$line =~ s/\b__packed\b/__attribute__((packed))/g;
41
		$line =~ s/^#include <linux\/compiler.h>//;
42 43 44
		$line =~ s/(^|\s)(inline)\b/$1__$2__/g;
		$line =~ s/(^|\s)(asm)\b(\s|[(]|$)/$1__$2__$3/g;
		$line =~ s/(^|\s|[(])(volatile)\b(\s|[(]|$)/$1__$2__$3/g;
45
		printf {$out} "%s", $line;
46
	}
47 48 49
	close $out;
	close $in;

50
	system $unifdef . " $tmpfile > $installdir/$file";
51 52 53 54 55 56 57
	# unifdef will exit 0 on success, and will exit 1 when the
	# file was processed successfully but no changes were made,
	# so abort only when it's higher than that.
	my $e = $? >> 8;
	if ($e > 1) {
		die "$tmpfile: $!\n";
	}
58 59 60
	unlink $tmpfile;
}
exit 0;