-rwxr-xr-x | scripts/makecfg.pl | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/scripts/makecfg.pl b/scripts/makecfg.pl index d7dc41e..de9d71a 100755 --- a/scripts/makecfg.pl +++ b/scripts/makecfg.pl | |||
@@ -2,78 +2,83 @@ | |||
2 | eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' | 2 | eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' |
3 | if 0; #$running_under_some_shell | 3 | if 0; #$running_under_some_shell |
4 | 4 | ||
5 | use strict; | 5 | use strict; |
6 | use File::Find; | 6 | use File::Find; |
7 | 7 | ||
8 | my $packages=""; | 8 | my $packages=""; |
9 | open(FILE, "<./packages"); | 9 | open(FILE, "<./packages"); |
10 | while(<FILE>){$packages.=$_;} | 10 | while(<FILE>){$packages.=$_;} |
11 | close(FILE); | 11 | close(FILE); |
12 | 12 | ||
13 | my ($dirname,$dir,$file,@files,$filename,$tagname,$name,$caps,$pre,$post,$sources,@dupecheck,$basedir); | 13 | my ($dirname,$dir,$file,@files,$filename,$tagname,$name,$caps,$pre,$post,$sources,@dupecheck,$basedir); |
14 | my @founddirs; | ||
14 | $file = shift || die; | 15 | $file = shift || die; |
15 | $basedir = shift; | 16 | $basedir = shift; |
16 | push(@files, $file); | ||
17 | 17 | ||
18 | foreach(@files){ | 18 | my $cfg=$file; |
19 | my $cfg=$_; | ||
20 | ($dirname=$cfg)=~s,(.*)/(.*),$1,; | 19 | ($dirname=$cfg)=~s,(.*)/(.*),$1,; |
21 | ($filename=$cfg)=~s,(.*/)(.*),$2,; | 20 | ($filename=$cfg)=~s,(.*/)(.*),$2,; |
22 | ($tagname=$dirname)=~s,.*/,,; | 21 | ($tagname=$dirname)=~s,.*/,,; |
23 | ($caps=$tagname)=~tr/[a-z]/[A-Z]/; | 22 | ($caps=$tagname)=~tr/[a-z]/[A-Z]/; |
24 | #print "cfg is $cfg\n"; | 23 | #print "cfg is $cfg\n"; |
25 | #print "dir is $dirname\n"; | 24 | #print "dir is $dirname\n"; |
26 | #print "filename is $filename\n"; | 25 | #print "filename is $filename\n"; |
27 | sub wanted; | 26 | sub wanted; |
28 | 27 | ||
29 | if(-e "$dirname/config.in.in"){ | 28 | if(-e "$dirname/config.in.in"){ |
30 | my $contents; | 29 | my $contents; |
31 | open(FILE, "<$dirname/config.in.in"); | 30 | open(FILE, "<$dirname/config.in.in"); |
32 | while(<FILE>){ $contents.=$_; } | 31 | while(<FILE>){ $contents.=$_; } |
33 | close(FILE); | 32 | close(FILE); |
34 | if($contents=~/\@sources\@/){ | 33 | if($contents=~/\@sources\@/){ |
35 | ($post = $contents) =~ s/^.*\@sources\@//s; | 34 | ($post = $contents) =~ s/^.*\@sources\@//s; |
36 | ($pre = $contents) =~ s/\@sources\@.*$//s; | 35 | ($pre = $contents) =~ s/\@sources\@.*$//s; |
37 | } else { | 36 | } else { |
38 | $pre = $contents; | 37 | $pre = $contents; |
39 | } | 38 | } |
40 | } else { | 39 | } else { |
40 | my ($firstletter, $rest); | ||
41 | $firstletter = substr($tagname, 0, 1); | ||
42 | $rest = substr($tagname, 1); | ||
43 | $firstletter =~ tr/a-z/A-Z/; | ||
44 | $tagname = $firstletter . $rest; | ||
41 | $pre = "menu \"$tagname\"\n"; | 45 | $pre = "menu \"$tagname\"\n"; |
42 | $post = "endmenu\n"; | 46 | $post = "endmenu\n"; |
43 | } | 47 | } |
44 | 48 | ||
45 | open(CFG, ">$cfg") || die "Unable to open $cfg for writing\n"; | 49 | open(CFG, ">$cfg") || die "Unable to open $cfg for writing\n"; |
46 | select(CFG); | 50 | select(CFG); |
47 | print $pre; | 51 | print $pre; |
48 | @dupecheck=(); | 52 | @dupecheck=(); |
49 | File::Find::find({wanted => \&wanted}, $dirname); | 53 | File::Find::find({wanted => \&wanted}, $dirname); |
54 | @::founddirs=sort(@::founddirs); | ||
55 | foreach (@::founddirs) { | ||
56 | if(grep(/^$_\/config.in$/, @dupecheck)){ | ||
57 | next; | ||
58 | } | ||
59 | my $nslashes = $_ =~ tr!/!!; | ||
60 | my $dirnslashes = $dirname =~ tr!/!!; | ||
61 | $dirnslashes++; | ||
62 | if($dirnslashes != $nslashes){next;} | ||
63 | my $reldir; | ||
64 | if (defined($basedir)) { | ||
65 | ($reldir=$_)=~s,^$basedir/,,; | ||
66 | } | ||
67 | print " source " . $reldir . "/config.in\n"; | ||
68 | push(@dupecheck, $_ . "/config.in"); | ||
69 | } | ||
50 | print $post; | 70 | print $post; |
51 | select(STDOUT); | 71 | select(STDOUT); |
52 | close(CFG); | 72 | close(CFG); |
53 | } | ||
54 | exit; | 73 | exit; |
55 | 74 | ||
56 | use vars qw/*name *dir *prune/; | 75 | use vars qw/*name *dir *prune/; |
57 | *name = *File::Find::name; | 76 | *name = *File::Find::name; |
58 | *dir = *File::Find::dir; | 77 | *dir = *File::Find::dir; |
59 | *prune = *File::Find::prune; | 78 | *prune = *File::Find::prune; |
60 | 79 | ||
61 | sub wanted { | 80 | sub wanted { |
62 | if( /config.in$/s ) { | 81 | if( /config.in$/s ) { |
63 | if(grep(/^$File::Find::dir\/config.in$/, @dupecheck)){ | 82 | push(@::founddirs,$File::Find::dir); |
64 | return; | ||
65 | } | ||
66 | my $nslashes = $File::Find::dir =~ tr!/!!; | ||
67 | my $dirnslashes = $dirname =~ tr!/!!; | ||
68 | $dirnslashes++; | ||
69 | # print STDERR "dirnslashes is $dirnslashes\n"; | ||
70 | # print STDERR "nslashes is $nslashes\n"; | ||
71 | if($dirnslashes != $nslashes){return;} | ||
72 | my $reldir; | ||
73 | if (defined($basedir)) { | ||
74 | ($reldir=$File::Find::dir)=~s,^$basedir/,,; | ||
75 | } | ||
76 | print " source " . $reldir . "/config.in\n"; | ||
77 | push(@dupecheck, $File::Find::dir . "/config.in"); | ||
78 | } | 83 | } |
79 | } | 84 | } |