summaryrefslogtreecommitdiff
path: root/scripts/makecfg.pl
Unidiff
Diffstat (limited to 'scripts/makecfg.pl') (more/less context) (ignore whitespace changes)
-rwxr-xr-xscripts/makecfg.pl43
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
@@ -1,79 +1,84 @@
1#!/usr/bin/perl -w 1#!/usr/bin/perl -w
2eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' 2eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3if 0; #$running_under_some_shell 3if 0; #$running_under_some_shell
4 4
5use strict; 5use strict;
6use File::Find; 6use File::Find;
7 7
8my $packages=""; 8my $packages="";
9open(FILE, "<./packages"); 9open(FILE, "<./packages");
10while(<FILE>){$packages.=$_;} 10while(<FILE>){$packages.=$_;}
11close(FILE); 11close(FILE);
12 12
13my ($dirname,$dir,$file,@files,$filename,$tagname,$name,$caps,$pre,$post,$sources,@dupecheck,$basedir); 13my ($dirname,$dir,$file,@files,$filename,$tagname,$name,$caps,$pre,$post,$sources,@dupecheck,$basedir);
14my @founddirs;
14$file = shift || die; 15$file = shift || die;
15$basedir = shift; 16$basedir = shift;
16push(@files, $file);
17 17
18foreach(@files){ 18my $cfg=$file;
19my $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";
27sub wanted; 26sub wanted;
28 27
29if(-e "$dirname/config.in.in"){ 28if(-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
45open(CFG, ">$cfg") || die "Unable to open $cfg for writing\n"; 49open(CFG, ">$cfg") || die "Unable to open $cfg for writing\n";
46select(CFG); 50select(CFG);
47print $pre; 51print $pre;
48@dupecheck=(); 52@dupecheck=();
49File::Find::find({wanted => \&wanted}, $dirname); 53File::Find::find({wanted => \&wanted}, $dirname);
54@::founddirs=sort(@::founddirs);
55foreach (@::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}
50print $post; 70print $post;
51select(STDOUT); 71select(STDOUT);
52close(CFG); 72close(CFG);
53}
54exit; 73exit;
55 74
56use vars qw/*name *dir *prune/; 75use 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
61sub wanted { 80sub 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}