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

Last change on this file since 315 was 315, checked in by Bruno Cornec, 16 years ago

Backup of local dev. cms2pkg compiles but doesn't work and even remove the SVN :-(
pb_log added

File size: 36.5 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::Copy;
13use File::Temp qw /tempdir/;
14use Data::Dumper;
15use POSIX qw(strftime);
16
17use ProjectBuilder::Changelog qw (pb_changelog);
18
19$ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
20
21my $debug = 0;
22my $LOG = \*STDOUT;
23
24sub pb_env_init {
25
26my $proj=shift || undef;
27my $pbinit=shift || undef;
28my $ver;
29my $tag;
30
31#
32# Check project name
33# Could be with env var PBPROJ
34# or option -p
35# if not define take the first in conf file
36#
37if ((defined $ENV{'PBPROJ'}) &&
38 (not (defined $proj))) {
39 $proj = $ENV{'PBPROJ'};
40}
41
42#
43# We get the pbconf file for that project
44# and use its content
45#
46my ($pbconf) = pb_conf_read("$ENV{'PBETC'}","pbconf");
47pb_log(2,"DEBUG pbconf: ".Dumper($pbconf)."\n");
48
49my %pbconf = %$pbconf;
50if (not defined $proj) {
51 # Take the first as the default project
52 $proj = (keys %pbconf)[0];
53 if (defined $proj) {
54 pb_log(2,"WARNING: using $proj as default project as none has been specified\n");
55 pb_log(2,"Please create a pbconf reference for project $proj in $ENV{'PBETC'}\nif you want to use another project\n");
56 }
57}
58die "No project defined - use env var PBPROJ or -p proj or a pbconf entry in $ENV{'PBETC'}" if (not (defined $proj));
59
60# That's always the environment variable that will be used
61$ENV{'PBPROJ'} = $proj;
62
63if (not defined ($pbconf{$ENV{'PBPROJ'}})) {
64 die "Please create a pbconf reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n";
65}
66
67#
68# Detect the root dir for hosting all the content generated with pb
69#
70# Tree will look like this:
71#
72# maint pbdir PBDIR dev dir (optional) PBDEVDIR
73# | |
74# ------------------------ --------------------
75# | | | |
76# pbproj1 pbproj2 PBPROJ pbproj1 pbproj2 PBDEVPROJ
77# | |
78# --------------------------------------------- ----------
79# * * | | | | * *
80# 1.0 dev pbconf ... build delivery PBCONF 1.0 dev PBDEVROOT
81# | | PBDESTDIR
82# ------ pbrc PBBUILDDIR
83# | |
84# 1.0 dev PBROOT
85# |
86# ----------------------------------
87# | | | |
88# pkg1 pbproj1.pb pbfilter pbcl
89# |
90# -----------------
91# | | |
92# rpm deb pbfilter
93#
94#
95# (*) By default, if no relocation in .pbrc, dev dir is taken in the maint pbdir (when appropriate)
96# Names under a pbproj and the corresponding pbconf should be similar
97#
98
99my ($pbdir) = pb_conf_get_if("pbdir");
100my %pbdir = %$pbdir;
101
102if (not defined $ENV{'PBDIR'}) {
103 if (not defined ($pbdir{$ENV{'PBPROJ'}})) {
104 pb_log(2,"WARNING: no pbdir defined, using /var/cache\n");
105 pb_log(2,"Please create a pbdir reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\nif you want to use another directory\n");
106 }
107 # That's always the environment variable that will be used
108 $ENV{'PBDIR'} = $pbdir{$ENV{'PBPROJ'}};
109}
110# Expand potential env variable in it
111eval { $ENV{'PBDIR'} =~ s/(\$ENV.+\})/$1/eeg };
112
113#
114# Set delivery directory
115#
116$ENV{'PBDESTDIR'}="$ENV{'PBDIR'}/$ENV{'PBPROJ'}/delivery";
117
118#
119# Removes all directory existing below the delivery dir
120# as they are temp dir only
121# Files stay and have to be cleaned up manually if needed
122# those files serves as communication channels between pb phases
123# Removing them prevents a following phase to detect what has been done before
124#
125if (-d $ENV{'PBDESTDIR'}) {
126 opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
127 foreach my $d (readdir(DIR)) {
128 next if ($d =~ /^\./);
129 next if (-f "$ENV{'PBDESTDIR'}/$d");
130 pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
131 }
132 closedir(DIR);
133}
134if (! -d "$ENV{'PBDESTDIR'}") {
135 pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
136}
137
138#
139# Set build directory
140#
141$ENV{'PBBUILDDIR'}="$ENV{'PBDIR'}/$ENV{'PBPROJ'}/build";
142if (! -d "$ENV{'PBBUILDDIR'}") {
143 pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
144}
145
146#
147# Set temp directory
148#
149if (not defined $ENV{'TMPDIR'}) {
150 $ENV{'TMPDIR'}="/tmp";
151}
152$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
153
154#
155# Check pbconf compliance
156#
157$ENV{'PBCONF'} = "$ENV{'PBDIR'}/$ENV{'PBPROJ'}/pbconf";
158
159my ($scheme, $account, $host, $port, $path) = pb_get_uri($pbconf{$ENV{'PBPROJ'}});
160
161if ((not -d "$ENV{'PBCONF'}") || (defined $pbinit)) {
162 pb_cms_checkout($scheme,$pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONF'});
163} else {
164 my $cmsurl = pb_cms_getinfo($scheme,$ENV{'PBCONF'},"URL:");
165 if ($cmsurl !~ /^$scheme/) {
166 pb_rm_rf("$ENV{'PBCONF'}");
167 pb_cms_checkout($scheme,$pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONF'});
168 } elsif ($cmsurl ne $pbconf{$ENV{'PBPROJ'}}) {
169 # The local content doesn't correpond to the repository
170 pb_log(2,"ERROR: Inconsistency detected:\n");
171 pb_log(2,"* $ENV{'PBCONF'} refers to $cmsurl but\n");
172 pb_log(2,"* $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 pb_log(2,"WARNING: no pbroot defined, using $ENV{'PBROOT'}\n");
197 pb_log(2,"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 pb_log(2,"DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n");
223 pb_log(2,"DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n");
224 pb_log(2,"DEBUG: version: ".Dumper($version)."\n");
225 pb_log(2,"DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n");
226 pb_log(2,"DEBUG: supfiles: ".Dumper($supfiles)."\n");
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 pb_log(2,"\nDo not to forget to commit the pbconf directory in your CMS if needed\n");
721 pb_log(2,"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(\%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
750pb_log(2,"$cmt... ");
751#system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log");
752system($cmd);
753if ($? == -1) {
754 pb_log(2,"failed to execute ($cmd) : $!\n");
755 pb_display_file("$ENV{'PBTMP'}/system.log");
756} elsif ($? & 127) {
757 pb_log(2, "child ($cmd) died with signal ".($? & 127).", ".($? & 128) ? 'with' : 'without'." coredump\n");
758 pb_display_file("$ENV{'PBTMP'}/system.log");
759} elsif ($? == 0) {
760 pb_log(2,"OK\n");
761} else {
762 pb_log(2, "child ($cmd) exited with value ".($? >> 8)."\n");
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 @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
809pb_log(2,"DEBUG: param1: ".Dumper(@ptr1)."\n");
810pb_log(2,"DEBUG: param2: ".Dumper(@ptr2)."\n");
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 pb_log(2,"DEBUG: param ptr1: ".Dumper(@ptr1)."\n");
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
872open(CONF,$conffile) || die "Unable to open $conffile";
873while(<CONF>) {
874 if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {
875 pb_log(2,"DEBUG: 1:$1 2:$2 3:$3\n");
876 $h{$1}{$2}=$3;
877 }
878}
879close(CONF);
880
881for my $param (@param) {
882 push @ptr,$h{$param};
883}
884pb_log(2,"DEBUG: h:".Dumper(%h)." param:".Dumper(@param)." ptr:".Dumper(@ptr)."\n");
885return(@ptr);
886}
887
888# Analyze a url passed and return protocol, account, password, server, port, path
889sub pb_get_uri {
890
891my $uri = shift || undef;
892
893# A URL has the format protocol://[ac@]host[:port][path[?query][#fragment]].
894# Cf man URI
895my ($scheme, $authority, $path, $query, $fragment) =
896 $uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;
897my ($account,$host,$port) = $authority =~ m|(?:([^\@]+)\@)?([^:]+)(:(?:[0-9]+))?|;
898pb_log(2,"DEBUG: scheme:$scheme ac:$account host:$host port:$port path:$path\n");
899return($scheme, $account, $host, $port, $path);
900}
901
902
903# Setup environment for CMS system for URL passed
904sub pb_cms_init {
905
906my $proj = shift || undef;
907
908# Use the project URI
909my ($uri) = pb_conf_get("pburl");
910
911# Extract values from that URI
912my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri->{$ENV{'PBPROJ'}});
913
914if ($scheme =~ /^svn/) {
915 $ENV{'PBREVISION'}= pb_cms_getinfo($scheme,$uri->{$ENV{'PBPROJ'}},"Revision:");
916 #$ENV{'PBREVISION'}=`(cd "$ENV{'PBDEVDIR'}" ; svnversion .)`;
917 $ENV{'PBCMSLOGFILE'}="svn.log";
918} elsif (($scheme eq "file") || ($scheme eq "ftp") || ($scheme eq "http")) {
919 $ENV{'PBREVISION'}="flat";
920 $ENV{'PBCMSLOGFILE'}="flat.log";
921} elsif ($scheme eq "cvs") {
922 # Way too slow
923 #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
924 #chomp($ENV{'PBREVISION'});
925 $ENV{'PBREVISION'}="CVS";
926 $ENV{'PBCMSLOGFILE'}="cvs.log";
927 #
928 # Export content if needed
929 #
930 my ($cvsrsh) = pb_conf_get_if("cvsrsh");
931 $ENV{'CVS_RSH'} = $cvsrsh->{$proj} if (defined $cvsrsh->{$proj});
932} else {
933 die "cms $scheme unknown";
934}
935
936#
937#if (not defined $scheme) {
938 # We're an upstream guy
939 # Try to make it easy for us
940 #pb_log(2,"WARNING: Assuming a local project under $ENV{'PBDIR'}/$ENV{'PBPROJ'}:\n");
941 #pb_log(2,"If not, pleaase setup a pbproj entry in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb\n");
942 #return("");
943#}
944
945return($scheme,$uri->{$ENV{'PBPROJ'}});
946}
947
948sub pb_get_date {
949
950return(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
951}
952
953sub pb_cms_export {
954
955my $scheme = shift;
956my $source = shift;
957my $destdir = shift;
958my $tmp;
959my $tmp1;
960
961my @date = pb_get_date();
962
963if ($scheme eq "svn") {
964 if (-d $source) {
965 $tmp = $destdir;
966 } else {
967 $tmp = $destdir."/".basename($source);
968 }
969 pb_system("svn export $source $tmp","Exporting $source from SVN to $tmp");
970} elsif ($scheme eq "flat") {
971 if (-d $source) {
972 $tmp = $destdir;
973 } else {
974 $tmp = $destdir."/".basename($source);
975 }
976 pb_system("cp -a $source $tmp","Exporting $source from DIR to $tmp");
977} elsif ($scheme eq "cvs") {
978 my $dir=dirname($destdir);
979 my $base=basename($destdir);
980 if (-d $source) {
981 $tmp1 = $source;
982 $tmp1 =~ s|$ENV{'PBROOT'}/||;
983 } else {
984 $tmp1 = dirname($source);
985 $tmp1 =~ s|$ENV{'PBROOT'}/||;
986 $tmp1 = $tmp1."/".basename($source);
987 }
988 # CVS needs a relative path !
989 my ($cvsroot) = pb_conf_get("cvsroot");
990 my $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
991 pb_system("cd $dir ; cvs -d $cvsroot->{$ENV{'PBPROJ'}} export -D \"$pbdate\" -d $base $tmp1","Exporting $source from CVS to $destdir");
992} else {
993 die "cms $scheme unknown";
994}
995}
996
997
998sub pb_create_authors {
999
1000my $authors=shift;
1001my $dest=shift;
1002my $scheme=shift;
1003
1004return if ($authors eq "/dev/null");
1005open(SAUTH,$authors) || die "Unable to open $authors";
1006open(DAUTH,"> $dest/AUTHORS") || die "Unable to create $dest/AUTHORS";
1007print DAUTH "Authors of the project are:\n";
1008print DAUTH "===========================\n";
1009while (<SAUTH>) {
1010 my ($nick,$gcos) = split(/:/);
1011 chomp($gcos);
1012 print DAUTH "$gcos";
1013 if (defined $scheme) {
1014 print DAUTH " ($nick under $scheme)\n";
1015 } else {
1016 print DAUTH "\n";
1017 }
1018}
1019close(DAUTH);
1020close(SAUTH);
1021}
1022
1023sub pb_cms_log {
1024my $scheme = shift;
1025my $pkgdir = shift;
1026my $dest = shift;
1027my $chglog = shift;
1028my $authors = shift;
1029
1030pb_create_authors($authors,$dest,$scheme);
1031
1032if ($scheme eq "svn") {
1033 if (! -f "$dest/ChangeLog") {
1034 if (-x "/usr/bin/svn2cl") {
1035 pb_system("/usr/bin/svn2cl --group-by-day --authors=$authors -i -o $dest/ChangeLog $pkgdir","Generating ChangeLog from SVN with svn2cl");
1036 } else {
1037 # To be written from pbcl
1038 pb_system("svn log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
1039 }
1040 }
1041} elsif ($scheme eq "flat") {
1042 if (! -f "$dest/ChangeLog") {
1043 pb_system("echo ChangeLog for $pkgdir > $dest/ChangeLog","Empty ChangeLog file created");
1044 }
1045} elsif ($scheme eq "cvs") {
1046 my $tmp=basename($pkgdir);
1047 # CVS needs a relative path !
1048 if (! -f "$dest/ChangeLog") {
1049 if (-x "/usr/bin/cvs2cl") {
1050 pb_system("/usr/bin/cvs2cl --group-by-day -U $authors -f $dest/ChangeLog $pkgdir","Generating ChangeLog from CVS with cvs2cl");
1051 } else {
1052 # To be written from pbcl
1053 pb_system("cvs log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
1054 }
1055 }
1056} else {
1057 die "cms $scheme unknown";
1058}
1059}
1060
1061sub pb_cms_getinfo {
1062my $scheme = shift;
1063my $dir = shift;
1064my $info = shift || "URL:";
1065
1066my $res = "";
1067my $void = "";
1068
1069if ($scheme =~ /^svn/) {
1070 open(PIPE,"LANGUAGE=C svn info $dir |") || return("");
1071 while (<PIPE>) {
1072 ($void,$res) = split(/^$info/) if (/^$info/);
1073 }
1074 close(PIPE);
1075 chomp($res);
1076} elsif ($scheme eq "flat") {
1077} elsif ($scheme eq "cvs") {
1078} else {
1079 die "cms $scheme unknown";
1080}
1081return($res);
1082}
1083
1084sub pb_cms_copy {
1085my $scheme = shift;
1086my $oldurl = shift;
1087my $newurl = shift;
1088
1089if ($scheme eq "svn") {
1090 pb_system("svn copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
1091} elsif ($scheme eq "flat") {
1092} elsif ($scheme eq "cvs") {
1093} else {
1094 die "cms $scheme unknown";
1095}
1096}
1097
1098sub pb_cms_checkout {
1099my $scheme = shift;
1100my $url = shift;
1101my $destination = shift;
1102
1103if ($scheme =~ /^svn/) {
1104 pb_system("svn co $url $destination","Checking $url to $destination ");
1105} elsif ($scheme eq "flat") {
1106} elsif ($scheme eq "cvs") {
1107} else {
1108 die "cms $scheme unknown";
1109}
1110}
1111
1112sub pb_cms_checkin {
1113my $scheme = shift;
1114my $dir = shift;
1115
1116my $ver = basename($dir);
1117if ($scheme eq "svn") {
1118 pb_system("svn ci -m \"Updated to $ver\" $dir","Checking in $dir");
1119 pb_system("svn up $dir","Updating $dir");
1120} elsif ($scheme eq "flat") {
1121} elsif ($scheme eq "cvs") {
1122} else {
1123 die "cms $scheme unknown";
1124}
1125}
1126
1127sub pb_cms_isdiff {
1128my $scheme = shift;
1129
1130if ($scheme eq "svn") {
1131 open(PIPE,"svn diff $ENV{'PBROOT'} |") || die "Unable to get svn diff from $ENV{'PBROOT'}";
1132 my $l = 0;
1133 while (<PIPE>) {
1134 $l++;
1135 }
1136 return($l);
1137} elsif ($scheme eq "flat") {
1138} elsif ($scheme eq "cvs") {
1139} else {
1140 die "cms $scheme unknown";
1141}
1142}
1143
1144# Get all filters to apply
1145# They're cumulative from less specific to most specific
1146# suffix is .pbf
1147
1148sub pb_get_filters {
1149
1150my @ffiles;
1151my ($ffile00, $ffile0, $ffile1, $ffile2, $ffile3);
1152my ($mfile00, $mfile0, $mfile1, $mfile2, $mfile3);
1153my $pbpkg = shift || die "No package specified";
1154my $dtype = shift || "";
1155my $dfam = shift || "";
1156my $ddir = shift || "";
1157my $dver = shift || "";
1158my $ptr; # returned value pointer on the hash of filters
1159my %ptr;
1160my %h;
1161
1162# Global filter files first, then package specificities
1163if (-d "$ENV{'PBROOT'}/pbfilter") {
1164 $mfile00 = "$ENV{'PBROOT'}/pbfilter/all.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/all.pbf");
1165 $mfile0 = "$ENV{'PBROOT'}/pbfilter/$dtype.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$dtype.pbf");
1166 $mfile1 = "$ENV{'PBROOT'}/pbfilter/$dfam.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$dfam.pbf");
1167 $mfile2 = "$ENV{'PBROOT'}/pbfilter/$ddir.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$ddir.pbf");
1168 $mfile3 = "$ENV{'PBROOT'}/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$ddir-$dver.pbf");
1169
1170 push @ffiles,$mfile00 if (defined $mfile00);
1171 push @ffiles,$mfile0 if (defined $mfile0);
1172 push @ffiles,$mfile1 if (defined $mfile1);
1173 push @ffiles,$mfile2 if (defined $mfile2);
1174 push @ffiles,$mfile3 if (defined $mfile3);
1175}
1176
1177if (-d "$ENV{'PBROOT'}/$pbpkg/pbfilter") {
1178 $ffile00 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/all.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/all.pbf");
1179 $ffile0 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dtype.pbf");
1180 $ffile1 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dfam.pbf");
1181 $ffile2 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir.pbf");
1182 $ffile3 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
1183
1184 push @ffiles,$ffile00 if (defined $ffile00);
1185 push @ffiles,$ffile0 if (defined $ffile0);
1186 push @ffiles,$ffile1 if (defined $ffile1);
1187 push @ffiles,$ffile2 if (defined $ffile2);
1188 push @ffiles,$ffile3 if (defined $ffile3);
1189}
1190if (@ffiles) {
1191 pb_log(2,"DEBUG ffiles: ".Dumper(\@ffiles)."\n");
1192
1193 foreach my $f (@ffiles) {
1194 open(CONF,$f) || next;
1195 while(<CONF>) {
1196 if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {
1197 $h{$1}{$2}=$3;
1198 }
1199 }
1200 close(CONF);
1201
1202 $ptr = $h{"filter"};
1203 pb_log(2,"DEBUG f:".Dumper($ptr)."\n");
1204 }
1205} else {
1206 $ptr = { };
1207}
1208%ptr = %$ptr;
1209return(\%ptr);
1210}
1211
1212# Function which applies filter on pb build files
1213sub pb_filter_file_pb {
1214
1215my $f=shift;
1216my $ptr=shift;
1217my %filter=%$ptr;
1218my $destfile=shift;
1219my $dtype=shift;
1220my $pbsuf=shift;
1221my $pbproj=shift;
1222my $pbpkg=shift;
1223my $pbver=shift;
1224my $pbtag=shift;
1225my $pbrev=shift;
1226my $pbdate=shift;
1227my $defpkgdir = shift;
1228my $extpkgdir = shift;
1229my $pbpackager = shift;
1230my $chglog = shift || undef;
1231
1232pb_log(2,"DEBUG: From $f to $destfile\n");
1233pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
1234open(DEST,"> $destfile") || die "Unable to create $destfile";
1235open(FILE,"$f") || die "Unable to open $f: $!";
1236while (<FILE>) {
1237 my $line = $_;
1238 foreach my $s (keys %filter) {
1239 # Process single variables
1240 pb_log(2,"DEBUG filter{$s}: $filter{$s}\n");
1241 my $tmp = $filter{$s};
1242 next if (not defined $tmp);
1243 # Expand variables if any single one found
1244 pb_log(2,"DEBUG tmp: $tmp\n");
1245 if ($tmp =~ /\$/) {
1246 eval { $tmp =~ s/(\$\w+)/$1/eeg };
1247 # special case for ChangeLog only for pb
1248 } elsif (($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
1249 my $p = $defpkgdir->{$pbpkg};
1250 $p = $extpkgdir->{$pbpkg} if (not defined $p);
1251 pb_changelog($dtype, $pbpkg, $pbver, $pbtag, $pbsuf, $p, \*DEST, $tmp, $chglog);
1252 $tmp = "";
1253 }
1254 $line =~ s|$s|$tmp|;
1255 }
1256 print DEST $line;
1257}
1258close(FILE);
1259close(DEST);
1260}
1261
1262# Function which applies filter on files (external call)
1263sub pb_filter_file_inplace {
1264
1265my $ptr=shift;
1266my %filter=%$ptr;
1267my $destfile=shift;
1268my $pbproj=shift;
1269my $pbpkg=shift;
1270my $pbver=shift;
1271my $pbtag=shift;
1272my $pbrev=shift;
1273my $pbdate=shift;
1274my $pbpackager=shift;
1275
1276my $cp = "$ENV{'PBTMP'}/".basename($destfile);
1277copy($destfile,$cp) || die "Unable to create $cp";
1278
1279pb_filter_file($cp,$ptr,$destfile,$pbproj,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
1280unlink $cp;
1281}
1282
1283# Function which applies filter on files (external call)
1284sub pb_filter_file {
1285
1286my $f=shift;
1287my $ptr=shift;
1288my %filter=%$ptr;
1289my $destfile=shift;
1290my $pbproj=shift;
1291my $pbpkg=shift;
1292my $pbver=shift;
1293my $pbtag=shift;
1294my $pbrev=shift;
1295my $pbdate=shift;
1296my $pbpackager=shift;
1297
1298pb_log(2,"DEBUG: From $f to $destfile\n");
1299pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
1300open(DEST,"> $destfile") || die "Unable to create $destfile";
1301open(FILE,"$f") || die "Unable to open $f: $!";
1302while (<FILE>) {
1303 my $line = $_;
1304 foreach my $s (keys %filter) {
1305 # Process single variables
1306 pb_log(2,"DEBUG filter{$s}: $filter{$s}\n");
1307 my $tmp = $filter{$s};
1308 next if (not defined $tmp);
1309 # Expand variables if any single one found
1310 if ($tmp =~ /\$/) {
1311 eval { $tmp =~ s/(\$\w+)/$1/eeg };
1312 }
1313 $line =~ s|$s|$tmp|;
1314 }
1315 print DEST $line;
1316}
1317close(FILE);
1318close(DEST);
1319}
1320
1321sub pb_log_init {
1322
1323$debug = shift || 0;
1324$LOG = shift || \*STDOUT;
1325
1326}
1327
1328sub pb_log {
1329
1330my $dlevel = shift;
1331my $msg = shift;
1332
1333print $LOG "$msg\n" if ($dlevel >= $debug);
1334}
1335
13361;
Note: See TracBrowser for help on using the repository browser.