]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | # | |
3 | use strict; | |
4 | use warnings; | |
5 | use File::Find qw(find); | |
6 | ||
7 | my $rpmdir = shift @ARGV or die; | |
8 | my $fileoutdir = shift @ARGV or die; | |
9 | ||
10 | # files which match: */include/*/Kbuild | |
11 | my @modulebuild_in_include; | |
12 | # files which match: */Kbuild */Kconfig except include | |
13 | my @modulebuild; | |
14 | # parent dirs of Kconfig files which match */include* | |
15 | my @dirs_in_include; | |
16 | # parent dirs of Kconfig files except include | |
17 | my @dirs; | |
18 | ||
19 | sub push_dirs | |
20 | { | |
21 | my $list = shift; | |
22 | my $dir = shift; | |
23 | my $subdir = ""; | |
24 | foreach my $sub ( split( '/', $dir )) { | |
25 | $subdir .= "/" . $sub; | |
26 | push @$list, "\%dir $rpmdir$subdir\n"; | |
27 | } | |
28 | } | |
29 | ||
30 | sub wanted | |
31 | { | |
32 | return unless -f; | |
33 | return unless /^Kconfig/ or /^Makefile/ or /^Kbuild/; | |
34 | #return if /\.orig$/; | |
35 | return if $File::Find::name =~ /Documentation/; | |
36 | (my $file = $File::Find::name) =~ s#^\./##; | |
37 | $file =~ m#^(.*)/#; | |
38 | my $dir = $1 || ""; | |
39 | if ( $dir =~ m{^(.*/)?include(/.*?)?$} ) { | |
40 | push @modulebuild_in_include, "$rpmdir/$file\n"; | |
41 | push_dirs( \@dirs_in_include, $dir ); | |
42 | } else { | |
43 | push @modulebuild, "$rpmdir/$file\n"; | |
44 | push_dirs( \@dirs, $dir ); | |
45 | } | |
46 | } | |
47 | ||
48 | find(\&wanted, "."); | |
49 | ||
50 | sub uniq | |
51 | { | |
52 | my %hash = map { $_, 1 } @_; | |
53 | return sort keys %hash; | |
54 | } | |
55 | ||
56 | sub remove | |
57 | { | |
58 | my $from = shift; | |
59 | my $what = shift; | |
60 | my %hash = map { $_, 1 } @$from; | |
61 | foreach ( @$what ) { | |
62 | delete $hash{ $_ }; | |
63 | } | |
64 | return sort keys %hash; | |
65 | } | |
66 | ||
67 | # to module-build add all Kconfig, Makefile and Kbuild files | |
68 | # also add all their parent dirs if they aren't parents of some include directory | |
69 | open F_OUT, "> $fileoutdir/files.mb_include_modulebuild_and_dirs" | |
70 | or die "Can't create files.mb_include_modulebuild_and_dirs: $!\n"; | |
71 | print F_OUT remove( \@dirs, \@dirs_in_include ); | |
72 | print F_OUT uniq( @modulebuild_in_include, @modulebuild ); | |
73 | close F_OUT and print "files.mb_include_modulebuild_and_dirs created\n"; | |
74 | ||
75 | # from source remove all files Kconfig, Makefile and Kbuild files | |
76 | # also remove all their parent dirs | |
77 | open F_OUT, "> $fileoutdir/files.source_exclude_modulebuild_and_dirs" | |
78 | or die "Can't create files.source_exclude_modulebuild_and_dirs: $!\n"; | |
79 | print F_OUT map {"\%exclude $_"} uniq( @modulebuild_in_include, @modulebuild, | |
80 | @dirs_in_include, @dirs ); | |
81 | close F_OUT and print "files.source_exclude_modulebuild_and_dirs created\n"; | |
82 | ||
83 | # from headers remove all Kconfig, Makefile and Kbuild files that are | |
84 | # part of include directory | |
85 | open F_OUT, "> $fileoutdir/files.headers_exclude_kbuild" | |
86 | or die "Can't create files.headers_exclude_kbuild: $!\n"; | |
87 | print F_OUT map {"\%exclude $_"} uniq( @modulebuild_in_include ); | |
88 | close F_OUT and print "files.headers_exclude_kbuild created\n"; |