2008-10-29 21:20:13 +00:00
|
|
|
#!/usr/bin/perl -w
|
2008-06-15 19:41:09 +00:00
|
|
|
#
|
|
|
|
# headers_install prepare the listed header files for use in
|
|
|
|
# user space and copy the files to their destination.
|
|
|
|
#
|
2008-06-16 19:29:38 +00:00
|
|
|
# Usage: headers_install.pl readdir installdir arch [files...]
|
2012-10-02 17:01:57 +00:00
|
|
|
# installdir: dir to install the files to
|
2008-06-16 19:29:38 +00:00
|
|
|
# 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
|
2008-06-15 19:41:09 +00:00
|
|
|
#
|
|
|
|
# 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;
|
|
|
|
|
2012-10-02 17:01:57 +00:00
|
|
|
my ($installdir, $arch, @files) = @ARGV;
|
2008-06-15 19:41:09 +00:00
|
|
|
|
2009-09-21 14:37:12 +00:00
|
|
|
my $unifdef = "scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__";
|
2008-06-15 19:41:09 +00:00
|
|
|
|
2012-10-02 17:01:57 +00:00
|
|
|
foreach my $filename (@files) {
|
|
|
|
my $file = $filename;
|
|
|
|
$file =~ s!^.*/!!;
|
|
|
|
|
2008-06-15 19:41:09 +00:00
|
|
|
my $tmpfile = "$installdir/$file.tmp";
|
2010-02-22 23:17:26 +00:00
|
|
|
|
2012-10-02 17:01:57 +00:00
|
|
|
open(my $in, '<', $filename)
|
|
|
|
or die "$filename: $!\n";
|
2010-02-22 23:17:26 +00:00
|
|
|
open(my $out, '>', $tmpfile)
|
|
|
|
or die "$tmpfile: $!\n";
|
|
|
|
while (my $line = <$in>) {
|
2008-06-15 19:41:09 +00:00
|
|
|
$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;
|
2011-06-24 13:51:00 +00:00
|
|
|
$line =~ s/\b__packed\b/__attribute__((packed))/g;
|
2008-06-15 19:41:09 +00:00
|
|
|
$line =~ s/^#include <linux\/compiler.h>//;
|
2008-12-27 08:23:15 +00:00
|
|
|
$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;
|
2010-02-22 23:17:26 +00:00
|
|
|
printf {$out} "%s", $line;
|
2008-06-15 19:41:09 +00:00
|
|
|
}
|
2010-02-22 23:17:26 +00:00
|
|
|
close $out;
|
|
|
|
close $in;
|
|
|
|
|
2008-06-15 19:41:09 +00:00
|
|
|
system $unifdef . " $tmpfile > $installdir/$file";
|
2010-11-24 00:54:02 +00:00
|
|
|
# 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";
|
|
|
|
}
|
2008-06-15 19:41:09 +00:00
|
|
|
unlink $tmpfile;
|
|
|
|
}
|
|
|
|
exit 0;
|