#!/usr/bin/perl -w1#2# headers_install prepare the listed header files for use in3# user space and copy the files to their destination.4#5# Usage: headers_install.pl readdir installdir arch [files...]6# readdir: dir to open files7# installdir: dir to install the files8# arch: current architecture9# arch is used to force a reinstallation when the arch10# changes because kbuild then detect a command line change.11# files: list of files to check12#13# Step in preparation for users space:14# 1) Drop all use of compiler.h definitions15# 2) Drop include of compiler.h16# 3) Drop all sections defined out by __KERNEL__ (using unifdef)1718use strict;1920my ($readdir, $installdir, $arch, @files) = @ARGV;2122my $unifdef = "scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__";2324foreach my $file (@files) {25my $tmpfile = "$installdir/$file.tmp";2627open(my $in, '<', "$readdir/$file")28or die "$readdir/$file: $!\n";29open(my $out, '>', $tmpfile)30or die "$tmpfile: $!\n";31while (my $line = <$in>) {32$line =~ s/([\s(])__user\s/$1/g;33$line =~ s/([\s(])__force\s/$1/g;34$line =~ s/([\s(])__iomem\s/$1/g;35$line =~ s/\s__attribute_const__\s/ /g;36$line =~ s/\s__attribute_const__$//g;37$line =~ s/^#include <linux\/compiler.h>//;38$line =~ s/(^|\s)(inline)\b/$1__$2__/g;39$line =~ s/(^|\s)(asm)\b(\s|[(]|$)/$1__$2__$3/g;40$line =~ s/(^|\s|[(])(volatile)\b(\s|[(]|$)/$1__$2__$3/g;41printf {$out} "%s", $line;42}43close $out;44close $in;4546system $unifdef . " $tmpfile > $installdir/$file";47# unifdef will exit 0 on success, and will exit 1 when the48# file was processed successfully but no changes were made,49# so abort only when it's higher than that.50my $e = $? >> 8;51if ($e > 1) {52die "$tmpfile: $!\n";53}54unlink $tmpfile;55}56exit 0;575859