summaryrefslogtreecommitdiff
path: root/scripts/makecfg.pl
authorkergoth <kergoth>2002-11-05 02:33:22 (UTC)
committer kergoth <kergoth>2002-11-05 02:33:22 (UTC)
commited163d67a674b1c4ac6b7e917a509029da446dfb (patch) (unidiff)
treed444f6395e82b1dd66f0ce8a413348a6f183bad3 /scripts/makecfg.pl
parent9ac6d0a443c417158e3f2acf2de0629c51b6511c (diff)
downloadopie-ed163d67a674b1c4ac6b7e917a509029da446dfb.zip
opie-ed163d67a674b1c4ac6b7e917a509029da446dfb.tar.gz
opie-ed163d67a674b1c4ac6b7e917a509029da446dfb.tar.bz2
config.in generation to reduce maintainance headaches
Diffstat (limited to 'scripts/makecfg.pl') (more/less context) (ignore whitespace changes)
-rwxr-xr-xscripts/makecfg.pl98
1 files changed, 98 insertions, 0 deletions
diff --git a/scripts/makecfg.pl b/scripts/makecfg.pl
new file mode 100755
index 0000000..20c23f5
--- a/dev/null
+++ b/scripts/makecfg.pl
@@ -0,0 +1,98 @@
1#!/usr/bin/perl -w
2eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3if 0; #$running_under_some_shell
4
5use strict;
6use File::Find;
7
8my $packages="";
9open(FILE, "<./packages");
10while(<FILE>){$packages.=$_;}
11close(FILE);
12
13my ($dirname,$dir,$cfg,$filename,$tagname,$name,$caps,$pre,$post,$sources,@dupecheck);
14$cfg = shift || die;
15($dirname=$cfg)=~s,(.*)/(.*),$1,;
16($filename=$cfg)=~s,(.*/)(.*),$2,;
17($tagname=$dirname)=~s,.*/,,;
18($caps=$tagname)=~tr/[a-z]/[A-Z]/;
19#print "cfg is $cfg\n";
20#print "dir is $dirname\n";
21#print "filename is $filename\n";
22sub wanted;
23
24if(-e "$dirname/config.in.in"){
25 my $contents;
26 open(FILE, "<$dirname/config.in.in");
27 while(<FILE>){ $contents.=$_; }
28 close(FILE);
29 if($contents=~/\@sources\@/){
30 ($post = $contents) =~ s/^.*\@sources\@//s;
31 ($pre = $contents) =~ s/\@sources\@.*$//s;
32 } else {
33 $pre = $contents;
34 }
35} else {
36 $pre = "menu \"$tagname\"\n";
37 $post = "endmenu\n";
38}
39
40open(CFG, ">$cfg") || die "Unable to open $cfg for writing\n";
41select(CFG);
42print $pre;
43@dupecheck=();
44File::Find::find({wanted => \&wanted}, $dirname);
45print $post;
46select(STDOUT);
47close(CFG);
48
49exit;
50
51open(FILE,">$dir/config.in");
52select(FILE);
53print "menu \"$name\"\n";
54print "\n";
55my @subdirs=();
56my @dirs;
57foreach(grep(/^$dir/, @dirs)){
58 chomp;
59 /^$dir\/$name.pro$/ && next;
60 my $localdir=$_;
61 if($dir=~m,^$localdir$,){
62 next;
63 }
64#($locadir=$_)~s,/[^/]+$,,g;
65 if($localdir=~/^\.$/){next;}
66 if(grep(/^$localdir$/, @subdirs)){next;}
67 my $nslashes = $localdir =~ tr!/!!;
68 my $dirnslashes = $dir =~ tr!/!!;
69 $dirnslashes++;
70 if($dirnslashes != $nslashes ){next;}
71 print STDERR "$localdir/config.in\n";
72 print " source $localdir/config.in\n";
73 push(@subdirs, $localdir);
74 print "endmenu\n";
75 select(STDOUT);
76 close(FILE);
77}
78
79use vars qw/*name *dir *prune/;
80*name = *File::Find::name;
81*dir = *File::Find::dir;
82*prune = *File::Find::prune;
83
84sub wanted {
85 if( /config.in/s ) {
86 if(grep(/^$File::Find::dir\/config.in$/, @dupecheck)){
87 return;
88 }
89 my $nslashes = $File::Find::dir =~ tr!/!!;
90 my $dirnslashes = $dirname =~ tr!/!!;
91 $dirnslashes++;
92 # print STDERR "dirnslashes is $dirnslashes\n";
93 # print STDERR "nslashes is $nslashes\n";
94 if($dirnslashes != $nslashes){return;}
95 print " source " . $File::Find::dir . "/config.in\n";
96 push(@dupecheck, $File::Find::dir . "/config.in");
97 }
98}