Blame view

scripts/headers_install.pl 1.79 KB
15a2ee74d   Jeremy Huntwork   Fix incompatibili...
1
  #!/usr/bin/perl -w
7712401ae   Sam Ravnborg   kbuild: optimize ...
2
3
4
5
  #
  # headers_install prepare the listed header files for use in
  # user space and copy the files to their destination.
  #
db1bec4f5   Sam Ravnborg   kbuild: install a...
6
7
8
9
10
11
12
  # Usage: headers_install.pl readdir installdir arch [files...]
  # readdir:    dir to open files
  # installdir: dir to install the files
  # 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
7712401ae   Sam Ravnborg   kbuild: optimize ...
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;
7712401ae   Sam Ravnborg   kbuild: optimize ...
20

db1bec4f5   Sam Ravnborg   kbuild: install a...
21
  my ($readdir, $installdir, $arch, @files) = @ARGV;
7712401ae   Sam Ravnborg   kbuild: optimize ...
22

c01226c31   Arnd Bergmann   warn about use of...
23
  my $unifdef = "scripts/unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__";
7712401ae   Sam Ravnborg   kbuild: optimize ...
24
25
26
  
  foreach my $file (@files) {
  	my $tmpfile = "$installdir/$file.tmp";
bae4cecc0   Stephen Hemminger   headers_install: ...
27
28
29
30
31
32
33
34
  
  	open(my $in, '<', "$readdir/$file")
  	    or die "$readdir/$file: $!
  ";
  	open(my $out, '>', $tmpfile)
  	    or die "$tmpfile: $!
  ";
  	while (my $line = <$in>) {
7712401ae   Sam Ravnborg   kbuild: optimize ...
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;
f210735fe   Markus Trippelsdorf   headers_install: ...
40
  		$line =~ s/\b__packed\b/__attribute__((packed))/g;
7712401ae   Sam Ravnborg   kbuild: optimize ...
41
  		$line =~ s/^#include <linux\/compiler.h>//;
4307184f2   Mike Frysinger   kbuild: in header...
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;
bae4cecc0   Stephen Hemminger   headers_install: ...
45
  		printf {$out} "%s", $line;
7712401ae   Sam Ravnborg   kbuild: optimize ...
46
  	}
bae4cecc0   Stephen Hemminger   headers_install: ...
47
48
  	close $out;
  	close $in;
7712401ae   Sam Ravnborg   kbuild: optimize ...
49
  	system $unifdef . " $tmpfile > $installdir/$file";
2979076fb   Mike Frysinger   headers_install: ...
50
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: $!
  ";
  	}
7712401ae   Sam Ravnborg   kbuild: optimize ...
58
59
60
  	unlink $tmpfile;
  }
  exit 0;