3 # DSF-Helper, a Debhelper-inspired helper for Debian Sourceforge
5 # Roland Mas <lolando@debian.org>
6 # This code is copyright Roland Mas 2002
7 # You are welcome to use, modify and redistribute this file under the terms of
8 # the GNU General Public License version 2.
11 use vars qw! @known_files @file_list @package_list %chunks ! ;
12 use subs qw! &pkgfile &get_chunk ! ;
18 @known_files = qw/ config templates preinst postinst prerm postrm links init.d / ;
26 $package =~ s/^.[^-]*-// ;
28 if (-f "debian/dsf-in/$package.$filename.dsfh-in") {
29 return "debian/dsf-in/$package.$filename.dsfh-in";
32 if (-f "debian/dsf-in/$package.$filename") {
33 return "debian/dsf-in/$package.$filename";
43 my $function = shift ;
45 unless (defined $chunks{$varname}) {
46 # First time this variable is encountered, creating slot
47 # print "Creating data structure for var $varname.\n" ;
48 $chunks{$varname} = {} ;
51 unless (defined $chunks{$varname}{$function}) {
52 # First time this instance is accessed, loading data
53 # print "Loading data for var $varname and function $function.\n" ;
54 $chunks{$varname}{$function} = '' ;
55 my $fname = "debian/dsf-helper/$varname.$function" ;
57 print "File $fname file not found, aborting.\n" ;
63 $chunks{$varname}{$function} .= $_ ;
68 return $chunks{$varname}{$function} ;
73 @package_list = split /\n/, qx! dh_listpackages ! ;
74 my $package_name = qx! grep ^PACKAGE= debian/rules | cut -d= -f2 ! ;
75 $package_name =~ s/\n//;
76 my $old_package_name = qx! grep ^OLDPACKAGE= debian/rules | cut -d= -f2 ! ;
77 $old_package_name =~ s/\n//;
78 my $forge_name = qx! grep ^FORGENAME= debian/rules | cut -d= -f2 ! ;
79 $forge_name =~ s/\n//;
81 if ($ARGV[0] && $ARGV[0] eq "--clean") {
82 EXTLOOP: for my $ext (@known_files) {
83 PKGLOOP: for my $pkg (@package_list) {
84 my $srcfile = &pkgfile ($pkg, $ext) ;
85 next PKGLOOP unless $srcfile ;
86 #my $destfile = $srcfile ;
87 my $destfile = "debian/$pkg.$ext" ;
88 #$destfile =~ s/\.dsfh-in$// ;
90 print "Removing $destfile\n" ;
98 EXTLOOP: for my $ext (@known_files) {
99 #print "Extension: $ext\n" ;
100 PKGLOOP: for my $pkg (@package_list) {
101 #print " Package: $pkg\n" ;
102 my $srcfile = &pkgfile ($pkg, $ext) ;
103 #print " SrcPackage: $srcfile\n" ;
104 next PKGLOOP unless $srcfile ;
105 # my $destfile = $srcfile ;
106 # $destfile =~ s/\.dsfh-in$// ;
107 my $destfile = "debian/$pkg.$ext" ;
108 print "$srcfile -> $destfile\n" ;
110 open S, "< $srcfile" ;
113 while (my $l = <S>) {
115 while ($l =~ m!\#DSFHELPER:([-_a-zA-Z0-9/]+)\#!) {
117 my $chunk = get_chunk ($chunkname, $ext) ;
118 $l =~ s!\#DSFHELPER:$chunkname\#!$chunk! ;
123 if ($ext eq "templates") {
124 # Need to remove a few extra blank lines
125 $dest =~ s/^#.*\n//gm ;
127 $dest =~ s/\n\n+/\n\n/g ;
129 $dest =~ s/\@PACKAGE\@/$package_name/g ;
130 $dest =~ s/\@OLDPACKAGE\@/$old_package_name/g ;
131 $dest =~ s/\@FORGENAME\@/$forge_name/g ;
133 open D, "> $destfile" ;
139 print "package_name: $package_name\n" ;
140 print "forge_name: $forge_name\n" ;