#!/usr/bin/perl -w # # Find all the UAPI files in the nominated directory # die "Need directory argument\n" if ($#ARGV == -1); my $dir = $ARGV[0]; my $kbuild = $dir . "/Kbuild"; die "$kbuild not present" unless (-r "$dir/Kbuild"); # # We assume that only Kbuild files in include directories are pertinent to # determining which headers are UAPI headers. # my %headers = (); opendir my $dh, $dir or die; foreach $_ (readdir($dh)) { $headers{$_} = 1 if ($_ =~ /[.]h$/ || $_ =~ /[.]agh$/ || $_ =~ /[.]inc$/); } closedir($dh) or die; # Read the common arch list open FD, '; close FD or die; my %uapihdrs = (); open FD, '<', $kbuild or die "open $kbuild: $!\n"; my @lines = ; close FD or die; for (my $l = 0; $l <= $#lines; $l++) { my $line = $lines[$l]; # parse out the blocks # - this may be split over multiple lines using backslashes my $block = $line; restart: $block =~ s@#.*$@@; $block =~ s@\s+$@@g; $block =~ s@\s+@ @g; if ($block =~ /^(.*)[\\]$/) { $l++; $block = $1 . $lines[$l]; goto restart; } $block =~ s@\s+$@@g; $block =~ s@\s\s+@ @g; if ($block =~ m@^include include/asm-generic/Kbuild.asm@) { push @lines, @kbuild_asm; } if ($block =~ m@^header-y\s*[+:]?=\s*(.*)@ || $block =~ m@^opt-header\s*[+:]?=\s*(.*)@ || $block =~ m@^asm-headers\s*[+:]?=\s*(.*)@ ) { my $files = $1; next if ($block =~ m@[$][(]foreach@); foreach $h (grep m@[^/]$@, split /\s+/, $files) { if (exists $headers{"$h"}) { $uapihdrs{"$h"} = 1; } } } } print map { $_ . "\n"; } sort keys %uapihdrs;