source: ProjectBuilder/devel/pb/lib/ProjectBuilder/Base.pm@ 314

Last change on this file since 314 was 314, checked in by Bruno Cornec, 16 years ago
  • Big rewrite still WIP
  • lot of interface changes, pbconf relocated and split from project dir.
  • URL usage
File size: 36.0 KB
Line 
1#!/usr/bin/perl -w
2#
3# Base subroutines for the Project-Builder project
4#
5# $Id$
6#
7
8use strict;
9use lib qw (lib);
10use File::Basename;
11use File::Path;
12use File::Temp qw /tempdir/;
13use Data::Dumper;
14
15use ProjectBuilder::Changelog qw (pb_changelog);
16
17$ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
18
19sub pb_env_init {
20
21my $proj=shift || undef;
22my $pbinit=shift || undef;
23my $ver;
24my $tag;
25
26# For the moment not dynamic
27my $debug = 0; # Debug level
28my $LOG = *STDOUT; # Where to log
29
30#
31# Check project name
32# Could be with env var PBPROJ
33# or option -p
34# if not define take the first in conf file
35#
36if ((defined $ENV{'PBPROJ'}) &&
37 (not (defined $proj))) {
38 $proj = $ENV{'PBPROJ'};
39}
40
41#
42# We get the pbconf file for that project
43# and use its content
44#
45my ($pbconf) = pb_conf_read("$ENV{'PBETC'}","pbconf");
46print "DEBUG pbconf: ".Dumper($pbconf)."\n" if ($debug >= 1);
47
48my %pbconf = %$pbconf;
49if (not defined $proj) {
50 # Take the first as the default project
51 $proj = (keys %pbconf)[0];
52 if (($debug >= 0) and (defined $proj)) {
53 print $LOG "WARNING: using $proj as default project as none has been specified\n"
54 print $LOG "Please create a pbconf reference for project $proj in $ENV{'PBETC'}\nif you want to use another project\n";
55 }
56}
57die "No project defined - use env var PBPROJ or -p proj or a pbconf entry in $ENV{'PBETC'}" if (not (defined $proj));
58
59# That's always the environment variable that will be used
60$ENV{'PBPROJ'} = $proj;
61
62if (not defined ($pbconf{$ENV{'PBPROJ'}})) {
63 die "Please create a pbconf reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n";
64}
65
66#
67# Detect the root dir for hosting all the content generated with pb
68#
69# Tree will look like this:
70#
71# maint pbdir dev dir (optional)
72# | |
73# ------------------------ --------------------
74# | | | |
75# pbproj1 pbproj2 pbproj1 pbproj2
76# | |
77# --------------------------------------------- ----------
78# * * | | | | * *
79# 1.0 dev pbconf ... build delivery 1.0 dev
80# | | |
81# ------ pbrc
82# | |
83# 1.0 dev
84# |
85# ----------------------------------
86# | | | |
87# pkg1 pbproj1.pb pbfilter pbcl
88# |
89# -----------------
90# | | |
91# rpm deb pbfilter
92#
93#
94# (*) By default, if no relocation in .pbrc, dev dir is taken in the maint pbdir (when appropriate)
95# Names under a pbproj and the corresponding pbconf should be similar
96#
97
98my ($pbdir) = pb_conf_get_if("pbdir");
99my %pbdir = %$pbdir;
100
101if (not defined $ENV{'PBDIR'}) {
102 if (not defined ($pbdir{$ENV{'PBPROJ'}})) {
103 print $LOG "WARNING: no pbdir defined, using /var/cache\n";
104 print $LOG "Please create a pbdir reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\nif you want to use another directory\n";
105 }
106 # That's always the environment variable that will be used
107 $ENV{'PBDIR'} = $pbdir{$ENV{'PBPROJ'}};
108}
109# Expand potential env variable in it
110eval { $ENV{'PBDIR'} =~ s/(\$ENV.+\})/$1/eeg };
111
112#
113# Set delivery directory
114#
115$ENV{'PBDESTDIR'}="$ENV{'PBDIR'}/$ENV{'PBPROJ'}/delivery";
116
117#
118# Removes all directory existing below the delivery dir
119# as they are temp dir only
120# Files stay and have to be cleaned up manually if needed
121# those files serves as communication channels between pb phases
122# Removing them prevents a following phase to detect what has been done before
123#
124if (-d $ENV{'PBDESTDIR'}) {
125 opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
126 foreach my $d (readdir(DIR)) {
127 next if ($d =~ /^\./);
128 next if (-f "$ENV{'PBDESTDIR'}/$d");
129 pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
130 }
131 closedir(DIR);
132}
133if (! -d "$ENV{'PBDESTDIR'}") {
134 pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
135}
136
137#
138# Set build directory
139#
140$ENV{'PBBUILDDIR'}="$ENV{'PBDIR'}/$ENV{'PBPROJ'}/build";
141if (! -d "$ENV{'PBBUILDDIR'}") {
142 pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
143}
144
145#
146# Set temp directory
147#
148if (not defined $ENV{'TMPDIR'}) {
149 $ENV{'TMPDIR'}="/tmp";
150}
151$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
152
153#
154# Check pbconf compliance
155#
156$ENV{'PBCONF'} = "$ENV{'PBDIR'}/$ENV{'PBPROJ'}/pbconf";
157
158my ($scheme, $account, $host, $port, $path) = pb_get_uri($pbconf{$ENV{'PBPROJ'}});
159my $cms = { $ENV{'PBPROJ'} => $scheme };
160
161if ((not -d "$ENV{'PBCONF'}") || (defined $pbinit)) {
162 pb_cms_checkout($cms,$pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONF'});
163} else {
164 my $cmsurl = pb_cms_getinfo($cms,$ENV{'PBCONF'});
165 if ($cmsurl !~ /^$scheme/) {
166 pb_rm_rf("$ENV{'PBCONF'}");
167 pb_cms_checkout($cms,$pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONF'});
168 } elsif ($cmsurl ne $pbconf{$ENV{'PBPROJ'}}) {
169 # The local content doesn't correpond to the repository
170 print $LOG "ERROR: Inconsistency detected:\n";
171 print $LOG "* $ENV{'PBCONF'} refers to $cmsurl but\n";
172 print $LOG "* $ENV{'PBETC'} refers to $pbconf{$ENV{'PBPROJ'}}\n";
173 die "Project $ENV{'PBPROJ'} is not Project-Builder compliant.";
174 } else {
175 # they match - do nothing - there may be local changes
176 }
177}
178
179# Check where is our PBROOT (release tag name can't be guessed the first time)
180if (not defined $ENV{'PBROOT'}) {
181 if (! -f ("$ENV{'PBDESTDIR'}/pbrc")) {
182 opendir(DIR,$ENV{'PBCONF'}) || die "Unable to open directory $ENV{'PBCONF'}: $!";
183 my maxmtime = 0;
184 foreach my $d (readdir(DIR)) {
185 next if ($d =~ /^\./);
186 next if (! -d $d);
187 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)
188 = stat($d);
189 # Keep the most recent
190 if ($mtime > $maxmtime) {
191 $ENV{'PBROOT'} = "$ENV{'PBCONF'}/$d";
192 $maxmtime = $mtime;
193 }
194 }
195 closedir(DIR);
196 print $LOG "WARNING: no pbroot defined, using $ENV{'PBROOT'}\n";
197 print $LOG "Please -r release if you want to use another release\n";
198 } else {
199 my ($pbroot) = pb_conf_read_if("$ENV{'PBDESTDIR'}/pbrc","pbroot");
200 # That's always the environment variable that will be used
201 $ENV{'PBROOT'} = $pbroot{$ENV{'PBPROJ'}};
202 }
203} else {
204 # transform in full path if relative
205 $ENV{'PBROOT'} = "$ENV{'PBCONF'}/$ENV{'PBROOT'}" if ($ENV{'PBROOT'} !~ |/|);
206}
207
208my %version = ();
209my %defpkgdir = ();
210my %extpkgdir = ();
211my %filteredfiles = ();
212my %supfiles = ();
213
214if ((-f "$ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb") and (not defined $pbinit)) {
215 # List of pkg to build by default (mandatory)
216 my ($defpkgdir) = pb_conf_get("defpkgdir");
217 # List of additional pkg to build when all is called (optional)
218 # Valid version names (optional)
219 # List of files to filter (optional)
220 # Project version and tag (optional)
221 my ($extpkgdir, $version, $filteredfiles, $supfiles, $pkgv, $pkgt) = pb_conf_get_if("extpkgdir","version","filteredfiles","supfiles","projver","projtag");
222 print "DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n" if ($debug >= 1);
223 print "DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n" if ($debug >= 1);
224 print "DEBUG: version: ".Dumper($version)."\n" if ($debug >= 1);
225 print "DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n" if ($debug >= 1);
226 print "DEBUG: supfiles: ".Dumper($supfiles)."\n" if ($debug >= 1);
227 # Global
228 %defpkgdir = %$defpkgdir;
229 %extpkgdir = %$extpkgdir if (defined $extpkgdir);
230 %version = %$version if (defined $version);
231 %filteredfiles = %$filteredfiles if (defined $filteredfiles);
232 %supfiles = %$supfiles if (defined $supfiles);
233 #
234 # Get global Version/Tag
235 #
236 if (not defined $ENV{'PBVER'}) {
237 if ((defined $pkgv) && (defined $pkgv->{$ENV{'PBPROJ'}})) {
238 $ENV{'PBVER'}=$pkgv->{$ENV{'PBPROJ'}};
239 } else {
240 die "No projver found in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
241 }
242 }
243 die "Invalid version name $ENV{'PBVER'} in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb" if (($ENV{'PBVER'} !~ /[0-9.]+/) && (not defined $version) && ($ENV{'PBVER'} =~ /$version{$ENV{'PBPROJ'}}/));
244
245 if (not defined $ENV{'PBTAG'}) {
246 if ((defined $pkgt) && (defined $pkgt->{$ENV{'PBPROJ'}})) {
247 $ENV{'PBTAG'}=$pkgt->{$ENV{'PBPROJ'}};
248 } else {
249 die "No projtag found in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
250 }
251 }
252 die "Invalid tag name $ENV{'PBTAG'} in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb" if ($ENV{'PBTAG'} !~ /[0-9.]+/);
253} else {
254 if (defined $pbinit) {
255 open(CONF,"> $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb") || die "Unable to create $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
256 print CONF << "EOF";
257#
258# Project Builder configuration file
259# For project $ENV{'PBPROJ'}
260#
261# \$Id\$
262#
263
264#
265# Which CMS system is used (Subversion, CVS or tar file content extracted)
266#
267#cms $ENV{'PBPROJ'} = svn
268#cms $ENV{'PBPROJ'} = cvs
269#cms $ENV{'PBPROJ'} = flat
270
271#
272# Packager label
273#
274#packager $ENV{'PBPROJ'} = "William Porte <bill\@$ENV{'PBPROJ'}.org>"
275#
276
277# For delivery to a machine by SSH (potentially the FTP server)
278# Needs hostname, account and directory
279#
280#sshhost $ENV{'PBPROJ'} = www.$ENV{'PBPROJ'}.org
281#sshlogin $ENV{'PBPROJ'} = bill
282#sshdir $ENV{'PBPROJ'} = /$ENV{'PBPROJ'}/ftp
283#sshport $ENV{'PBPROJ'} = 22
284
285#
286# For Virtual machines management
287# Naming convention to follow: distribution name (as per ProjectBuilder::Distribution)
288# followed by '_' and by release number
289# a .vmtype extension will be added to the resulting string
290# a QEMU rhel_3 here means that the VM will be named rhel_3.qemu
291#
292#vmlist $ENV{'PBPROJ'} = mandrake_10.1,mandrake_10.2,mandriva_2006.0,mandriva_2007.0,mandriva_2007.1,mandriva_2008.0,redhat_7.3,redhat_9,fedora_4,fedora_5,fedora_6,fedora_7,rhel_3,rhel_4,rhel_5,suse_10.0,suse_10.1,suse_10.2,suse_10.3,sles_9,sles_10,gentoo_nover,debian_3.1,debian_4.0,ubuntu_6.06,ubuntu_7.04,ubuntu_7.10
293
294#
295# Valid values for vmtype are
296# qemu, (vmware, xen, ... TBD)
297#vmtype $ENV{'PBPROJ'} = qemu
298
299# Hash for VM stuff on vmtype
300#vmntp default = pool.ntp.org
301
302# We suppose we can commmunicate with the VM through SSH
303#vmhost $ENV{'PBPROJ'} = localhost
304#vmlogin $ENV{'PBPROJ'} = pb
305#vmport $ENV{'PBPROJ'} = 2222
306
307# Timeout to wait when VM is launched/stopped
308#vmtmout default = 120
309
310# per VMs needed paramaters
311#vmopt $ENV{'PBPROJ'} = -m 384 -daemonize
312#vmpath $ENV{'PBPROJ'} = /home/qemu
313#vmsize $ENV{'PBPROJ'} = 5G
314
315#
316# Global version/tag for the project
317#
318#projver $ENV{'PBPROJ'} = devel
319#projtag $ENV{'PBPROJ'} = 1
320
321# Adapt to your needs:
322# Optional if you need to overwrite the global values above
323#
324#pkgver pkg1 = stable
325#pkgtag pkg1 = 3
326#pkgver nil
327#pkgtag nil
328
329# Hash of default package/package directory
330#defpkgdir pkg1 = pkg1dir
331
332# Hash of additional package/package directory
333#extpkgdir pkg1-doc = pkg1-docdir
334
335# Hash of valid version names
336#version devel
337#version stable
338
339# List of files per pkg on which to apply filters
340# Files are mentioned relatively to pbroot/defpkgdir
341#filteredfiles pkg1 = Makefile.PL
342#filteredfiles pkg1-doc = configure.in
343#supfiles pkg1 = pkg1.init
344EOF
345 close(CONF);
346 pb_mkdir_p("$ENV{'PBROOT'}/pbfilter") || die "Unable to create $ENV{'PBROOT'}/pbfilter";
347 open(CONF,"> $ENV{'PBROOT'}/pbfilter/all.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/all.pbf";
348 print CONF << "EOF";
349#
350# \$Id\$
351#
352# Filter for all files
353#
354# PBSRC is replaced by the source package format
355#filter PBSRC = ftp://ftp.$ENV{'PBPROJ'}.org/src/%{name}-%{version}.tar.gz
356
357# PBVER is replaced by the version (\$pbver in code)
358#filter PBVER = \$pbver
359
360# PBDATE is replaced by the date (\$pbdate in code)
361#filter PBDATE = \$pbdate
362
363# PBLOG is replaced by the changelog if value is yes
364#filter PBLOG = yes
365
366# PBTAG is replaced by the tag (\$pbtag in code)
367#filter PBTAG = \$pbtag
368
369# PBREV is replaced by the revision (\$pbrev in code)
370#filter PBREV = \$pbrev
371
372# PBPKG is replaced by the package name (\$pbpkg in code)
373#filter PBPKG = \$pbpkg
374
375# PBPACKAGER is replaced by the packager name (\$pbpackager in code)
376#filter PBPACKAGER = \$pbpackager
377
378# PBDESC contains the description of the package
379#filter PBDESC = "Bla-Bla"
380
381# PBURL contains the URL of the Web site of the project
382#filter PBURL = http://www.$ENV{'PBPROJ'}.org
383EOF
384 close(CONF);
385 open(CONF,"> $ENV{'PBROOT'}/pbfilter/rpm.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/rpm.pbf";
386 print CONF << "EOF";
387#
388# \$Id\$
389#
390# Filter for rpm build
391#
392
393# PBGRP is replaced by the RPM group of apps
394# Cf: http://fedoraproject.org/wiki/RPMGroups
395#filter PBGRP = Applications/Archiving
396
397# PBDEP is replaced by the list of dependencies
398#filter PBDEP =
399
400# PBSUF is replaced by the package name (\$pbpkg in code)
401#filter PBSUF = \$pbsuf
402
403# PBOBS is replaced by the Obsolete line
404#filter PBOBS =
405
406EOF
407 close(CONF);
408 open(CONF,"> $ENV{'PBROOT'}/pbfilter/deb.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/deb.pbf";
409 print CONF << "EOF";
410#
411# \$Id\$
412#
413# Filter for debian build
414#
415# PBGRP is replaced by the group of apps
416#filter PBGRP = utils
417
418# PBVER is replaced by the version (\$pbver in code)
419#filter PBVER = \$pbver
420
421# PBDEP is replaced by the list of dependencies
422#filter PBDEP =
423
424# PBSUG is replaced by the list of suggestions
425#filter PBSUG =
426
427# PBREC is replaced by the list of recommandations
428#filter PBREC =
429
430# PBLOG is replaced by the changelog if value is yes
431#filter PBLOG = yes
432
433# PBPKG is replaced by the package name (\$pbpkg in code)
434#filter PBPKG = \$pbpkg
435
436# PBPACKAGER is replaced by the packager name (\$pbpackager in code)
437#filter PBPACKAGER = \$pbpackager
438
439EOF
440 close(CONF);
441 open(CONF,"> $ENV{'PBROOT'}/pbfilter/md.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/md.pbf";
442 print CONF << "EOF";
443# Specific group for Mandriva for $ENV{'PBPROJ'}
444filter PBGRP = Archiving/Backup
445EOF
446 close(CONF);
447 open(CONF,"> $ENV{'PBROOT'}/pbfilter/novell.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/novell.pbf";
448 print CONF << "EOF";
449# Specific group for SuSE for $ENV{'PBPROJ'}
450filter PBGRP = Productivity/Archiving/Backup
451EOF
452 close(CONF);
453 pb_mkdir_p("$ENV{'PBROOT'}/pkg1/deb") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb";
454 open(CONF,"> $ENV{'PBROOT'}/pkg1/deb/control") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb/control";
455 print CONF << "EOF";
456Source: PBPKG
457Section: PBGRP
458Priority: optional
459Maintainer: PBPACKAGER
460Build-Depends: debhelper (>= 4.2.20), PBDEP
461Standards-Version: 3.6.1
462
463Package: PBPKG
464Architecture: amd64 i386 ia64
465Section: PBGRP
466Priority: optional
467Depends: \${shlibs:Depends}, \${misc:Depends}, PBDEP
468Recommends: PBREC
469Suggests: PBSUG
470Description:
471 PBDESC
472 .
473 Homepage: PBURL
474
475EOF
476 close(CONF);
477 open(CONF,"> $ENV{'PBROOT'}/pkg1/deb/copyright") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb/copyright";
478 print CONF << "EOF";
479This package is debianized by PBPACKAGER
480`date`
481
482The current upstream source was downloaded from
483ftp://ftp.$ENV{'PBPROJ'}.org/src/.
484
485Upstream Authors: Put their name here
486
487Copyright:
488
489 This package is free software; you can redistribute it and/or modify
490 it under the terms of the GNU General Public License as published by
491 the Free Software Foundation; version 2 dated June, 1991.
492
493 This package is distributed in the hope that it will be useful,
494 but WITHOUT ANY WARRANTY; without even the implied warranty of
495 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
496 GNU General Public License for more details.
497
498 You should have received a copy of the GNU General Public License
499 along with this package; if not, write to the Free Software
500 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
501 MA 02110-1301, USA.
502
503On Debian systems, the complete text of the GNU General
504Public License can be found in /usr/share/common-licenses/GPL.
505
506EOF
507 close(CONF);
508 open(CONF,"> $ENV{'PBROOT'}/pkg1/deb/changelog") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb/changelog";
509 print CONF << "EOF";
510PBLOG
511EOF
512 close(CONF);
513 open(CONF,"> $ENV{'PBROOT'}/pkg1/deb/compat") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb/compat";
514 print CONF << "EOF";
5154
516EOF
517 close(CONF);
518 open(CONF,"> $ENV{'PBROOT'}/pkg1/deb/pkg1.dirs") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb/pkg1.dirs";
519 print CONF << "EOF";
520EOF
521 close(CONF);
522 open(CONF,"> $ENV{'PBROOT'}/pkg1/deb/pkg1.docs") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb/pkg1.docs";
523 print CONF << "EOF";
524INSTALL
525COPYING
526AUTHORS
527NEWS
528README
529EOF
530 close(CONF);
531 open(CONF,"> $ENV{'PBROOT'}/pkg1/deb/rules") || die "Unable to create $ENV{'PBROOT'}/pkg1/deb/rules";
532 print CONF << 'EOF';
533#!/usr/bin/make -f
534# -*- makefile -*-
535# Sample debian/rules that uses debhelper.
536# GNU copyright 1997 to 1999 by Joey Hess.
537#
538# $Id$
539#
540
541# Uncomment this to turn on verbose mode.
542#export DH_VERBOSE=1
543
544# Define package name variable for a one-stop change.
545PACKAGE_NAME = PBPKG
546
547# These are used for cross-compiling and for saving the configure script
548# from having to guess our platform (since we know it already)
549DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
550DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
551
552CFLAGS = -Wall -g
553
554ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
555 CFLAGS += -O0
556else
557 CFLAGS += -O2
558endif
559ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
560 INSTALL_PROGRAM += -s
561endif
562config.status: configure
563 dh_testdir
564
565 # Configure the package.
566 CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr
567 --mandir=\$${prefix}/share/man
568
569# Build both architecture dependent and independent
570build: build-arch build-indep
571
572# Build architecture dependent
573build-arch: build-arch-stamp
574
575build-arch-stamp: config.status
576 dh_testdir
577
578 # Compile the package.
579 $(MAKE)
580
581 touch build-stamp
582
583# Build architecture independent
584build-indep: build-indep-stamp
585
586build-indep-stamp: config.status
587 # Nothing to do, the only indep item is the manual which is available as html in original source
588 touch build-indep-stamp
589
590# Clean up
591clean:
592 dh_testdir
593 dh_testroot
594 rm -f build-arch-stamp build-indep-stamp #CONFIGURE-STAMP#
595 # Clean temporary document directory
596 rm -rf debian/doc-temp
597 # Clean up.
598 -$(MAKE) distclean
599 rm -f config.log
600ifneq "$(wildcard /usr/share/misc/config.sub)" ""
601 cp -f /usr/share/misc/config.sub config.sub
602endif
603ifneq "$(wildcard /usr/share/misc/config.guess)" ""
604 cp -f /usr/share/misc/config.guess config.guess
605endif
606
607 dh_clean
608
609# Install architecture dependent and independent
610install: install-arch install-indep
611
612# Install architecture dependent
613install-arch: build-arch
614 dh_testdir
615 dh_testroot
616 dh_clean -k -s
617 dh_installdirs -s
618
619 # Install the package files into build directory:
620 # - start with upstream make install
621 $(MAKE) install prefix=$(CURDIR)/debian/$(PACKAGE_NAME)/usr mandir=$(CURDIR)/debian/$(PACKAGE_NAME)/us
622r/share/man
623 # - copy html manual to temporary location for renaming
624 mkdir -p debian/doc-temp
625 dh_install -s
626
627# Install architecture independent
628install-indep: build-indep
629 dh_testdir
630 dh_testroot
631 dh_clean -k -i
632 dh_installdirs -i
633 dh_install -i
634
635# Must not depend on anything. This is to be called by
636# binary-arch/binary-indep
637# in another 'make' thread.
638binary-common:
639 dh_testdir
640 dh_testroot
641 dh_installchangelogs ChangeLog
642 dh_installdocs
643 dh_installman
644 dh_link
645 dh_strip
646 dh_compress
647 dh_fixperms
648 dh_installdeb
649 dh_shlibdeps
650 dh_gencontrol
651 dh_md5sums
652 dh_builddeb
653
654# Build architecture independant packages using the common target.
655binary-indep: build-indep install-indep
656 $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
657
658# Build architecture dependant packages using the common target.
659binary-arch: build-arch install-arch
660 $(MAKE) -f debian/rules DH_OPTIONS=-a binary-common
661
662# Build architecture depdendent and independent packages
663binary: binary-arch binary-indep
664.PHONY: clean binary
665
666EOF
667 close(CONF);
668 pb_mkdir_p("$ENV{'PBROOT'}/pkg1/rpm") || die "Unable to create $ENV{'PBROOT'}/pkg1/rpm";
669 open(CONF,"> $ENV{'PBROOT'}/pkg1/rpm/pkg1.spec") || die "Unable to create $ENV{'PBROOT'}/pkg1/rpm/pkg1.spec";
670 print CONF << 'EOF';
671#
672# $Id$
673#
674
675Summary: bla-bla
676Summary(fr): french bla-bla
677
678Name: PBPKG
679Version: PBVER
680Release: PBTAGPBSUF
681License: GPL
682Group: PBGRP
683Url: PBURL
684Source: PBSRC
685BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(id -u -n)
686Requires: PBDEP
687
688%description
689PBDESC
690
691%description -l fr
692french desc
693
694%prep
695%setup -q
696
697%build
698%configure
699make %{?_smp_mflags}
700
701%install
702%{__rm} -rf $RPM_BUILD_ROOT
703make DESTDIR=$RPM_BUILD_ROOT install
704
705%clean
706%{__rm} -rf $RPM_BUILD_ROOT
707
708%files
709%defattr(-,root,root)
710%doc ChangeLog
711%doc INSTALL COPYING README AUTHORS NEWS
712
713%changelog
714PBLOG
715
716EOF
717 close(CONF);
718 pb_mkdir_p("$ENV{'PBROOT'}/pkg1/pbfilter") || die "Unable to create $ENV{'PBROOT'}/pkg1/pbfilter";
719
720 print "\nDo not to forget to commit the pbconf directory in your CMS if needed\n";
721 print "After having renamed the pkg1 directory to your package's name \n\n";
722 } else {
723 die "Unable to open $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
724 }
725}
726umask 0022;
727return($debug,$LOG, \%filteredfiles, \%supfiles, \%defpkgdir, \%extpkgdir);
728}
729
730# Internal mkdir -p function
731sub pb_mkdir_p {
732my @dir = @_;
733my $ret = mkpath(@dir, 0, 0755);
734return($ret);
735}
736
737# Internal rm -rf function
738sub pb_rm_rf {
739my @dir = @_;
740my $ret = rmtree(@dir, 0, 0);
741return($ret);
742}
743
744# Internal system function
745sub pb_system {
746
747my $cmd=shift;
748my $cmt=shift || $cmd;
749
750print "$cmt... ";
751#system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log");
752system($cmd);
753if ($? == -1) {
754 print "failed to execute ($cmd) : $!\n";
755 pb_display_file("$ENV{'PBTMP'}/system.log");
756} elsif ($? & 127) {
757 printf "child ($cmd) died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
758 pb_display_file("$ENV{'PBTMP'}/system.log");
759} elsif ($? == 0) {
760 print "OK\n";
761} else {
762 printf "child ($cmd) exited with value %d\n", $? >> 8;
763 pb_display_file("$ENV{'PBTMP'}/system.log");
764}
765}
766
767sub pb_display_file {
768
769my $file=shift;
770
771return if (not -f $file);
772open(FILE,"$file");
773while (<FILE>) {
774 print $_;
775}
776close(FILE);
777}
778
779# Function which returns a pointer on a table
780# corresponding to a set of values queried in the conf file
781# and test the returned vaue as they need to exist in that case
782sub pb_conf_get {
783
784my @param = @_;
785my @return = pb_conf_get_if(@param);
786
787die "No params found for $ENV{'PBPROJ'}" if (not defined @return);
788
789foreach my $i (0..$#param) {
790 die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $return[$i]);
791}
792return(@return);
793}
794
795# Function which returns a pointer on a table
796# corresponding to a set of values queried in the conf file
797# Those value may be undef if they do not exist
798sub pb_conf_get_if {
799
800my @param = @_;
801
802# Everything is returned via ptr1
803my @ptr1 = pb_conf_read_if("$ENV{'PBETC'}", @param);
804my @ptr2 = pb_conf_read_if("$ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb", @param);
805
806my $p1;
807my $p2;
808
809#print "DEBUG: param1: ".Dumper(@ptr1)."\n"; # if ($debug >= 1);
810#print "DEBUG: param2: ".Dumper(@ptr2)."\n"; # if ($debug >= 1);
811
812foreach my $i (0..$#param) {
813 $p1 = $ptr1[$i];
814 $p2 = $ptr2[$i];
815 # Always try to take the param from the home dir conf file in priority
816 # in order to mask what could be defined under the CMS to allow for overloading
817 if (not defined $p2) {
818 # No ref in CMS project conf file so use the home dir one.
819 $p1->{$ENV{'PBPROJ'}} = $p1->{'default'} if (not defined $p1->{$ENV{'PBPROJ'}});
820 } else {
821 # Ref found in CMS project conf file
822 if (not defined $p1) {
823 # No ref in home dir project conf file so use the CMS one.
824 $p2->{$ENV{'PBPROJ'}} = $p2->{'default'} if (not defined $p2->{$ENV{'PBPROJ'}});
825 $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}};
826 } else {
827 # Both are defined - handling the overloading
828 if (not defined $p1->{'default'}) {
829 if (defined $p2->{'default'}) {
830 $p1->{'default'} = $p2->{'default'};
831 }
832 }
833
834 if (not defined $p1->{$ENV{'PBPROJ'}}) {
835 if (defined $p2->{$ENV{'PBPROJ'}}) {
836 $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}};
837 } else {
838 $p1->{$ENV{'PBPROJ'}} = $p1->{'default'};
839 }
840 }
841 }
842 }
843 $ptr1[$i] = $p1;
844 #print "DEBUG: param ptr1: ".Dumper(@ptr1)."\n"; # if ($debug >= 1);
845}
846return(@ptr1);
847}
848
849# Function which returns a pointer on a hash
850# corresponding to a declaration (arg2) in a conf file (arg1)
851# if that conf file doesn't exist returns undef
852sub pb_conf_read_if {
853
854my $conffile = shift;
855my @param = @_;
856
857open(CONF,$conffile) || return((undef));
858close(CONF);
859return(pb_conf_read($conffile,@param));
860}
861
862# Function which returns a pointer on a hash
863# corresponding to a declaration (arg2) in a conf file (arg1)
864sub pb_conf_read {
865
866my $conffile = shift;
867my @param = @_;
868my $trace;
869my @ptr;
870my %h;
871
872my $debug = 0;
873
874open(CONF,$conffile) || die "Unable to open $conffile";
875while(<CONF>) {
876 if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {
877 print "DEBUG: 1:$1 2:$2 3:$3\n" if ($debug >= 1);
878 $h{$1}{$2}=$3;
879 }
880}
881close(CONF);
882
883for my $param (@param) {
884 push @ptr,$h{$param};
885}
886print "DEBUG: h:".Dumper(%h)." param:".Dumper(@param)." ptr:".Dumper(@ptr)."\n" if ($debug >= 1);
887return(@ptr);
888}
889
890# Analyze a url passed and return protocol, account, password, server, port, path
891sub pb_get_uri {
892
893my $uri = shift || undef;
894
895# A URL has the format protocol://[ac@]host[:port][path[?query][#fragment]].
896# Cf man URI
897my ($scheme, $authority, $path, $query, $fragment) =
898 $uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;
899my ($account,$host,$port) = $authority =~ m|(?:([^\@]+)\@)?([^:]+)(:(?:[0-9]+))?|;
900print "DEBUG: scheme:$scheme ac:$account host:$host port:$port path:$path\n" if ($debug >= 1);
901return($scheme, $account, $host, $port, $path);
902}
903
904
905# Setup environment for CMS system for URL passed
906sub pb_cms_init {
907
908my $proj = shift || undef;
909my $ret;
910
911my ($cms) = pb_conf_get("cms");
912
913if ($cms->{$proj} eq "svn") {
914 $ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; svnversion .)`;
915 chomp($ENV{'PBREVISION'});
916 $ENV{'PBCMSLOGFILE'}="svn.log";
917} elsif ($cms->{$proj} eq "flat") {
918 $ENV{'PBREVISION'}="flat";
919 $ENV{'PBCMSLOGFILE'}="flat.log";
920} elsif ($cms->{$proj} eq "cvs") {
921 # Way too slow
922 #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
923 #chomp($ENV{'PBREVISION'});
924 $ENV{'PBREVISION'}="CVS";
925 $ENV{'PBCMSLOGFILE'}="cvs.log";
926 #
927 # Export content if needed
928 #
929 my ($cvsrsh) = pb_conf_get_if("cvsrsh");
930 $ENV{'CVS_RSH'} = $cvsrsh->{$proj} if (defined $cvsrsh->{$proj});
931} else {
932 die "cms $cms->{$proj} unknown";
933}
934return($cms);
935}
936
937sub pb_cms_export {
938my $cms = shift;
939my $pbdate = shift || undef;
940my $source = shift;
941my $destdir = shift;
942my $tmp;
943my $tmp1;
944
945if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
946 if (-d $source) {
947 $tmp = $destdir;
948 } else {
949 $tmp = $destdir."/".basename($source);
950 }
951 pb_system("svn export $source $tmp","Exporting $source from SVN to $tmp");
952} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
953 if (-d $source) {
954 $tmp = $destdir;
955 } else {
956 $tmp = $destdir."/".basename($source);
957 }
958 pb_system("cp -a $source $tmp","Exporting $source from DIR to $tmp");
959} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
960 my $dir=dirname($destdir);
961 my $base=basename($destdir);
962 if (-d $source) {
963 $tmp1 = $source;
964 $tmp1 =~ s|$ENV{'PBROOT'}/||;
965 } else {
966 $tmp1 = dirname($source);
967 $tmp1 =~ s|$ENV{'PBROOT'}/||;
968 $tmp1 = $tmp1."/".basename($source);
969 }
970 # CVS needs a relative path !
971 my ($cvsroot) = pb_conf_get("cvsroot");
972 pb_system("cd $dir ; cvs -d $cvsroot->{$ENV{'PBPROJ'}} export -D \"$pbdate\" -d $base $tmp1","Exporting $source from CVS to $destdir");
973} else {
974 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
975}
976}
977
978
979sub pb_create_authors {
980
981my $authors=shift;
982my $dest=shift;
983my $cms=shift;
984
985return if ($authors eq "/dev/null");
986open(SAUTH,$authors) || die "Unable to open $authors";
987open(DAUTH,"> $dest/AUTHORS") || die "Unable to create $dest/AUTHORS";
988print DAUTH "Authors of the project are:\n";
989print DAUTH "===========================\n";
990while (<SAUTH>) {
991 my ($nick,$gcos) = split(/:/);
992 chomp($gcos);
993 print DAUTH "$gcos";
994 if (defined $cms) {
995 print DAUTH " ($nick under $cms)\n";
996 } else {
997 print DAUTH "\n";
998 }
999}
1000close(DAUTH);
1001close(SAUTH);
1002}
1003
1004sub pb_cms_log {
1005my $cms = shift;
1006my $pkgdir = shift;
1007my $dest = shift;
1008my $chglog = shift;
1009my $authors = shift;
1010
1011pb_create_authors($authors,$dest,$cms->{$ENV{'PBPROJ'}});
1012
1013if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
1014 if (! -f "$dest/ChangeLog") {
1015 if (-x "/usr/bin/svn2cl") {
1016 pb_system("/usr/bin/svn2cl --group-by-day --authors=$authors -i -o $dest/ChangeLog $pkgdir","Generating ChangeLog from SVN");
1017 } else {
1018 # To be written from pbcl
1019 pb_system("svn log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
1020 }
1021 }
1022} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
1023 if (! -f "$dest/ChangeLog") {
1024 pb_system("echo ChangeLog for $pkgdir > $dest/ChangeLog","Empty ChangeLog file created");
1025 }
1026} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
1027 my $tmp=basename($pkgdir);
1028 # CVS needs a relative path !
1029 if (! -f "$dest/ChangeLog") {
1030 if (-x "/usr/bin/cvs2cl") {
1031 pb_system("/usr/bin/cvs2cl --group-by-day -U $authors -f $dest/ChangeLog $pkgdir","Generating ChangeLog from CVS");
1032 } else {
1033 # To be written from pbcl
1034 pb_system("cvs log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
1035 }
1036 }
1037} else {
1038 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
1039}
1040}
1041
1042sub pb_cms_getinfo {
1043my $cms = shift;
1044my $dir = shift;
1045my $url = "";
1046my $void = "";
1047
1048if ($cms->{$ENV{'PBPROJ'}} =~ /^svn/) {
1049 open(PIPE,"LANGUAGE=C svn info $dir |") || return("");
1050 while (<PIPE>) {
1051 ($void,$url) = split(/^URL:/) if (/^URL:/);
1052 }
1053 close(PIPE);
1054 chomp($url);
1055} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
1056} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
1057} else {
1058 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
1059}
1060return($url);
1061}
1062
1063sub pb_cms_copy {
1064my $cms = shift;
1065my $oldurl = shift;
1066my $newurl = shift;
1067
1068if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
1069 pb_system("svn copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
1070} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
1071} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
1072} else {
1073 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
1074}
1075}
1076
1077sub pb_cms_checkout {
1078my $cms = shift;
1079my $url = shift;
1080my $destination = shift;
1081
1082if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
1083 pb_system("svn co $url $destination","Checking $url to $destination ");
1084} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
1085} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
1086} else {
1087 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
1088}
1089}
1090
1091sub pb_cms_checkin {
1092my $cms = shift;
1093my $dir = shift;
1094
1095my $ver = basename($dir);
1096if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
1097 pb_system("svn ci -m \"Updated to $ver\" $dir","Checking in $dir");
1098 pb_system("svn up $dir","Updating $dir");
1099} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
1100} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
1101} else {
1102 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
1103}
1104}
1105
1106sub pb_cms_isdiff {
1107my $cms = shift;
1108
1109if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
1110 open(PIPE,"svn diff $ENV{'PBROOT'} |") || die "Unable to get svn diff from $ENV{'PBROOT'}";
1111 my $l = 0;
1112 while (<PIPE>) {
1113 $l++;
1114 }
1115 return($l);
1116} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
1117} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
1118} else {
1119 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
1120}
1121}
1122
1123# Get all filters to apply
1124# They're cumulative from less specific to most specific
1125# suffix is .pbf
1126
1127sub pb_get_filters {
1128
1129# For the moment not dynamic
1130my $debug = 0; # Debug level
1131my $LOG = *STDOUT; # Where to log
1132
1133my @ffiles;
1134my ($ffile00, $ffile0, $ffile1, $ffile2, $ffile3);
1135my ($mfile00, $mfile0, $mfile1, $mfile2, $mfile3);
1136my $pbpkg = shift || die "No package specified";
1137my $dtype = shift || "";
1138my $dfam = shift || "";
1139my $ddir = shift || "";
1140my $dver = shift || "";
1141my $ptr; # returned value pointer on the hash of filters
1142my %ptr;
1143my %h;
1144
1145# Global filter files first, then package specificities
1146if (-d "$ENV{'PBROOT'}/pbfilter") {
1147 $mfile00 = "$ENV{'PBROOT'}/pbfilter/all.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/all.pbf");
1148 $mfile0 = "$ENV{'PBROOT'}/pbfilter/$dtype.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$dtype.pbf");
1149 $mfile1 = "$ENV{'PBROOT'}/pbfilter/$dfam.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$dfam.pbf");
1150 $mfile2 = "$ENV{'PBROOT'}/pbfilter/$ddir.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$ddir.pbf");
1151 $mfile3 = "$ENV{'PBROOT'}/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$ddir-$dver.pbf");
1152
1153 push @ffiles,$mfile00 if (defined $mfile00);
1154 push @ffiles,$mfile0 if (defined $mfile0);
1155 push @ffiles,$mfile1 if (defined $mfile1);
1156 push @ffiles,$mfile2 if (defined $mfile2);
1157 push @ffiles,$mfile3 if (defined $mfile3);
1158}
1159
1160if (-d "$ENV{'PBROOT'}/$pbpkg/pbfilter") {
1161 $ffile00 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/all.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/all.pbf");
1162 $ffile0 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dtype.pbf");
1163 $ffile1 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dfam.pbf");
1164 $ffile2 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir.pbf");
1165 $ffile3 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
1166
1167 push @ffiles,$ffile00 if (defined $ffile00);
1168 push @ffiles,$ffile0 if (defined $ffile0);
1169 push @ffiles,$ffile1 if (defined $ffile1);
1170 push @ffiles,$ffile2 if (defined $ffile2);
1171 push @ffiles,$ffile3 if (defined $ffile3);
1172}
1173if (@ffiles) {
1174 print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
1175
1176 foreach my $f (@ffiles) {
1177 open(CONF,$f) || next;
1178 while(<CONF>) {
1179 if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {
1180 $h{$1}{$2}=$3;
1181 }
1182 }
1183 close(CONF);
1184
1185 $ptr = $h{"filter"};
1186 print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
1187 }
1188} else {
1189 $ptr = { };
1190}
1191%ptr = %$ptr;
1192return(\%ptr);
1193}
1194
1195# Function which applies filter on pb build files
1196sub pb_filter_file_pb {
1197
1198my $f=shift;
1199my $ptr=shift;
1200my %filter=%$ptr;
1201my $destfile=shift;
1202my $dtype=shift;
1203my $pbsuf=shift;
1204my $pbproj=shift;
1205my $pbpkg=shift;
1206my $pbver=shift;
1207my $pbtag=shift;
1208my $pbrev=shift;
1209my $pbdate=shift;
1210my $defpkgdir = shift;
1211my $extpkgdir = shift;
1212my $pbpackager = shift;
1213my $chglog = shift || undef;
1214
1215# For the moment not dynamic
1216my $debug = 0; # Debug level
1217my $LOG = *STDOUT; # Where to log
1218
1219print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
1220pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
1221open(DEST,"> $destfile") || die "Unable to create $destfile";
1222open(FILE,"$f") || die "Unable to open $f: $!";
1223while (<FILE>) {
1224 my $line = $_;
1225 foreach my $s (keys %filter) {
1226 # Process single variables
1227 print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug >= 1);
1228 my $tmp = $filter{$s};
1229 next if (not defined $tmp);
1230 # Expand variables if any single one found
1231 print $LOG "DEBUG tmp: $tmp\n" if ($debug >= 1);
1232 if ($tmp =~ /\$/) {
1233 eval { $tmp =~ s/(\$\w+)/$1/eeg };
1234 # special case for ChangeLog only for pb
1235 } elsif (($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
1236 my $p = $defpkgdir->{$pbpkg};
1237 $p = $extpkgdir->{$pbpkg} if (not defined $p);
1238 pb_changelog($dtype, $pbpkg, $pbver, $pbtag, $pbsuf, $p, \*DEST, $tmp, $chglog);
1239 $tmp = "";
1240 }
1241 $line =~ s|$s|$tmp|;
1242 }
1243 print DEST $line;
1244}
1245close(FILE);
1246close(DEST);
1247}
1248
1249# Function which applies filter on files (external call)
1250sub pb_filter_file {
1251
1252my $f=shift;
1253my $ptr=shift;
1254my %filter=%$ptr;
1255my $destfile=shift;
1256my $pbproj=shift;
1257my $pbpkg=shift;
1258my $pbver=shift;
1259my $pbtag=shift;
1260my $pbrev=shift;
1261my $pbdate=shift;
1262my $pbpackager=shift;
1263
1264# For the moment not dynamic
1265my $debug = 0; # Debug level
1266my $LOG = *STDOUT; # Where to log
1267
1268print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
1269pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
1270open(DEST,"> $destfile") || die "Unable to create $destfile";
1271open(FILE,"$f") || die "Unable to open $f: $!";
1272while (<FILE>) {
1273 my $line = $_;
1274 foreach my $s (keys %filter) {
1275 # Process single variables
1276 print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
1277 my $tmp = $filter{$s};
1278 next if (not defined $tmp);
1279 # Expand variables if any single one found
1280 if ($tmp =~ /\$/) {
1281 eval { $tmp =~ s/(\$\w+)/$1/eeg };
1282 }
1283 $line =~ s|$s|$tmp|;
1284 }
1285 print DEST $line;
1286}
1287close(FILE);
1288close(DEST);
1289}
1290
1291
12921;
Note: See TracBrowser for help on using the repository browser.