source: devel/pb/lib/ProjectBuilder/Env.pm @ 1066

Revision 1066, 33.6 KB checked in by bruno, 3 years ago (diff)

r3935@dhcp184-49-175-19: bruno | 2010-06-26 08:40:49 +0200

  • Adds new "Walt Disney" feature: possibility to deliver in multiple variable dirs, and not just / and test
Line 
1#!/usr/bin/perl -w
2#
3# Project Builder Env module
4# Env subroutines brought by the the Project-Builder project
5# which can be easily used by pbinit scripts
6#
7# $Id$
8#
9# Copyright B. Cornec 2007
10# Provided under the GPL v2
11
12package ProjectBuilder::Env;
13
14use strict 'vars';
15use Data::Dumper;
16use English;
17use File::Basename;
18use File::stat;
19use POSIX qw(strftime);
20use lib qw (lib);
21use ProjectBuilder::Base;
22use ProjectBuilder::Conf;
23use ProjectBuilder::CMS;
24
25# Inherit from the "Exporter" module which handles exporting functions.
26 
27use Exporter;
28 
29# Export, by default, all the functions into the namespace of
30# any code which uses this module.
31 
32our @ISA = qw(Exporter);
33our @EXPORT = qw(pb_env_init pb_env_init_pbrc);
34
35=pod
36
37=head1 NAME
38
39ProjectBuilder::Env, part of the project-builder.org
40
41=head1 DESCRIPTION
42
43This modules provides environment functions suitable for pbinit calls.
44
45=head1 USAGE
46
47=over 4
48
49=item B<pb_env_init_pbrc>
50
51This function setup/use the configuration file in the HOME directory
52It sets up environment variables (PBETC)
53
54=cut
55
56sub pb_env_init_pbrc {
57
58$ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
59
60if (! -f $ENV{'PBETC'}) {
61        pb_log(0, "No existing $ENV{'PBETC'} found, creating one as template\n");
62        open(PBRC, "> $ENV{'PBETC'}") || die "Unable to create $ENV{'PBETC'}";
63        print PBRC << "EOF";
64#
65# Define for each project the URL of its pbconf repository
66# No default option allowed here as they need to be all different
67#
68#pbconfurl example = svn+ssh://svn.example.org/svn/pb/projects/example/pbconf
69#pbconfurl pb = svn+ssh://svn.project-builder.org/mondo/svn/pb/pbconf
70
71# Under that dir will take place everything related to pb
72# If you want to use VMs/chroot/..., then use \$ENV{'HOME'} to make it portable
73# to your VMs/chroot/...
74# if not defined then /var/cache
75#pbdefdir default = \$ENV{'HOME'}/pb/projects
76#pbdefdir pb = \$ENV{'HOME'}
77
78# If not defined, pbconfdir is under pbdefdir/pbproj/pbconf
79#pbconfdir pb = \$ENV{'HOME'}/pb/pbconf
80
81# If not defined, pbprojdir is under pbdefdir/pbproj
82# Only defined if we have access to the dev of the project
83#pbprojdir example = \$ENV{'HOME'}/example/svn
84
85# We have commit acces to these
86#pburl example = cvs+ssh://user\@example.cvs.sourceforge.net:/cvsroot/example
87#pburl pb = svn+ssh://svn.project-builder.org/mondo/svn/pb
88
89# I mask my real login on the ssh machines here
90#sshlogin example = user
91
92# where to find Build System infos:
93#vmpath default = /home/qemu
94#vepath default = /home/rinse
95
96# Overwrite generic setup
97#vmport pb = 2223
98#vmport example = 2224
99EOF
100        }
101
102# We only have one configuration file for now.
103pb_conf_add("$ENV{'PBETC'}");
104}
105
106=item B<pb_env_init>
107
108This function setup the environment for project-builder.
109The first parameter is the project if given on the command line.
110The second parameter is a flag indicating whether we should setup up the pbconf environment or not.
111The third parameter is the action passed to pb.
112It sets up environement variables (PBETC, PBPROJ, PBDEFDIR, PBBUILDDIR, PBROOTDIR, PBDESTDIR, PBCONFDIR, PBPROJVER)
113
114=cut
115
116sub pb_env_init {
117
118my $proj=shift || undef;
119my $pbinit=shift || undef;
120my $action=shift;
121my $ver;
122my $tag;
123
124pb_env_init_pbrc();
125
126#
127# Check project name
128# Could be with env var PBPROJ
129# or option -p
130# if not define take the first in conf file
131#
132if ((defined $ENV{'PBPROJ'}) &&
133        (not (defined $proj))) {
134        $proj = $ENV{'PBPROJ'};
135}
136
137#
138# We get the pbconf file for that project
139# and use its content
140#
141my ($pbconf) = pb_conf_get("pbconfurl");
142pb_log(2,"DEBUG pbconfurl: ".Dumper($pbconf)."\n");
143
144my %pbconf = %$pbconf;
145if (not defined $proj) {
146        # Take the first as the default project
147        $proj = (keys %pbconf)[0];
148        if (defined $proj) {
149                pb_log(1,"WARNING: using $proj as default project as none has been specified\n");
150                pb_log(1,"         Please either create a pbconfurl reference for project $proj in $ENV{'PBETC'}\n");
151                pb_log(1,"         or call pb with the -p project option or use the env var PBPROJ\n");
152                pb_log(1,"         if you want to use another project\n");
153        }
154}
155die "No project defined - use env var PBPROJ or -p proj or a pbconfurl entry in $ENV{'PBETC'}" if (not (defined $proj));
156
157# That's always the environment variable that will be used
158$ENV{'PBPROJ'} = $proj;
159pb_log(2,"PBPROJ: $ENV{'PBPROJ'}\n");
160
161if (not defined ($pbconf{$ENV{'PBPROJ'}})) {
162        die "Please create a pbconfurl reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n";
163}
164
165# Adds a potential conf file now as it's less
166# important than the project conf file
167my ($vmpath,$vepath) = pb_conf_get_if("vmpath","vepath");
168pb_conf_add("$vmpath->{$ENV{'PBPROJ'}}/.pbrc") if ((defined $vmpath) && (-f "$vmpath->{$ENV{'PBPROJ'}}/.pbrc"));
169pb_conf_add("$vepath->{$ENV{'PBPROJ'}}/.pbrc") if ((defined $vepath) && (-f "$vepath->{$ENV{'PBPROJ'}}/.pbrc"));
170
171#
172# Detect the root dir for hosting all the content generated with pb
173#
174=over 4
175
176 Tree will look like this:
177
178             maint pbdefdir                         PBDEFDIR            dev dir (optional)
179                  |                                                        |
180            ------------------------                                --------------------
181            |                      |                                |                  |
182         pbproj1                pbproj2             PBPROJ       pbproj1           pbproj2   PBPROJDIR
183            |                                                       |
184  ---------------------------------------------                ----------
185  *      *        *       |        |          |                *        *
186 tag    dev    pbconf    ...     build     delivery PBCONFDIR dev      tag                 
187  |               |                           |     PBDESTDIR           |
188  ---          ------                        pbrc   PBBUILDDIR       -------
189    |          |    |                                                |     |
190   1.1        dev  tag                                              1.0   1.1                PBDIR
191                    |
192                 -------
193                 |     |
194                1.0   1.1                           PBROOTDIR
195                       |
196               ----------------------------------
197               |          |           |         |
198             pkg1      pbproj1.pb   pbfilter   pbcl
199               |
200        -----------------
201        |      |        |
202       rpm    deb    pbfilter
203
204
205 (*) By default, if no relocation in .pbrc, dev dir is taken in the maint pbdefdir (when appropriate)
206 Names under a pbproj and the corresponding pbconf should be similar
207
208=cut
209
210my ($pbdefdir) = pb_conf_get_if("pbdefdir");
211
212if (not defined $ENV{'PBDEFDIR'}) {
213        if ((not defined $pbdefdir) || (not defined $pbdefdir->{$ENV{'PBPROJ'}})) {
214                pb_log(1,"WARNING: no pbdefdir defined, using /var/cache\n");
215                pb_log(1,"         Please create a pbdefdir reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n");
216                pb_log(1,"         if you want to use another directory\n");
217                $ENV{'PBDEFDIR'} = "/var/cache";
218        } else {
219                # That's always the environment variable that will be used
220                $ENV{'PBDEFDIR'} = $pbdefdir->{$ENV{'PBPROJ'}};
221        }
222}
223# Expand potential env variable in it
224eval { $ENV{'PBDEFDIR'} =~ s/(\$ENV.+\})/$1/eeg };
225
226pb_log(2,"PBDEFDIR: $ENV{'PBDEFDIR'}\n");
227
228# Need to do that earlier as it's used potentialy in pb_cms_add
229pb_temp_init();
230pb_log(2,"PBTMP: $ENV{'PBTMP'}\n");
231
232# Put under CMS the PBPROJ dir
233if ($action =~ /^newproj$/) {
234        if (! -d "$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}") {
235                # TODO: There is also the need to do
236                # svn import "$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}" svn://repo
237                # in case it doesn't exist there
238                pb_mkdir_p("$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}") || die "Unable to recursively create $ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}";
239        }
240        pb_cms_add($pbconf{$ENV{'PBPROJ'}},"$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}");
241}
242
243#
244# Set delivery directory
245#
246$ENV{'PBDESTDIR'}="$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}/delivery";
247
248pb_log(2,"PBDESTDIR: $ENV{'PBDESTDIR'}\n");
249#
250# Removes all directory existing below the delivery dir
251# as they are temp dir only except when called from pbinit
252# Files stay and have to be cleaned up manually if needed
253# those files serves as communication channels between pb phases
254# Removing them prevents a following phase to detect what has been done before
255#
256if ((-d $ENV{'PBDESTDIR'}) && ($action !~ /pbinit/)) {
257        opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
258        foreach my $d (readdir(DIR)) {
259                next if ($d =~ /^\./);
260                next if (-f "$ENV{'PBDESTDIR'}/$d");
261                pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
262        }
263        closedir(DIR);
264}
265if (! -d "$ENV{'PBDESTDIR'}") {
266        pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
267}
268
269#
270# Set build directory
271#
272$ENV{'PBBUILDDIR'}="$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}/build";
273if (! -d "$ENV{'PBBUILDDIR'}") {
274        pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
275}
276
277pb_log(2,"PBBUILDDIR: $ENV{'PBBUILDDIR'}\n");
278
279#
280# The following part is only useful when in cms2something or newsomething
281# In VMs/VEs we want to skip that by providing good env vars.
282# return values in that case are useless
283#
284if (($action =~ /^cms2/) || ($action =~ /^newver$/) || ($action =~ /pbinit/) || ($action =~ /^newproj$/) || ($action =~ /^announce/) || ($action =~ /^web/)) {
285
286        #
287        # Check pbconf cms compliance
288        #
289        pb_cms_compliant("pbconfdir",'PBCONFDIR',"$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}/pbconf",$pbconf{$ENV{'PBPROJ'}},$pbinit);
290
291        # Check where is our PBROOTDIR (release tag name can't be guessed the first time)
292        #
293        if (not defined $ENV{'PBROOTDIR'}) {
294                if (! -f ("$ENV{'PBDESTDIR'}/pbrc")) {
295                        $ENV{'PBROOTDIR'} = "$ENV{'PBCONFDIR'}";
296                        pb_log(1,"WARNING: no pbroot defined, using $ENV{'PBROOTDIR'}\n");
297                        pb_log(1,"         Please use -r release if you want to use another release\n");
298                        die "No directory found under $ENV{'PBCONFDIR'}" if (not defined $ENV{'PBROOTDIR'});
299                } else {
300                        my ($pbroot) = pb_conf_read_if("$ENV{'PBDESTDIR'}/pbrc","pbroot");
301                        # That's always the environment variable that will be used
302                        die "Please remove inconsistent $ENV{'PBDESTDIR'}/pbrc" if ((not defined $pbroot) || (not defined $pbroot->{$ENV{'PBPROJ'}}));
303                        $ENV{'PBROOTDIR'} = $pbroot->{$ENV{'PBPROJ'}};
304                }
305        } else {
306                # transform in full path if relative
307                $ENV{'PBROOTDIR'} = "$ENV{'PBCONFDIR'}/$ENV{'PBROOTDIR'}" if ($ENV{'PBROOTDIR'} !~ /^\//);
308                pb_mkdir_p($ENV{'PBROOTDIR'}) if (defined $pbinit);
309                die "$ENV{'PBROOTDIR'} is not a directory" if (not -d $ENV{'PBROOTDIR'});
310        }
311
312        # Adds that conf file to the list to consider
313        pb_conf_add("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb") if (-f "$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb");
314
315        return if ($action =~ /^newver$/);
316
317        my %version = ();
318        my %defpkgdir = ();
319        my %extpkgdir = ();
320        my %filteredfiles = ();
321        my %supfiles = ();
322       
323        if ((-f "$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb") and (not defined $pbinit)) {
324
325                # List of pkg to build by default (mandatory)
326                # TODO: projtag could be with a 1 default value
327                my ($defpkgdir,$pbpackager, $pkgv, $pkgt) = pb_conf_get("defpkgdir","pbpackager","projver","projtag");
328                # List of additional pkg to build when all is called (optional)
329                # Valid version names (optional)
330                # List of files to filter (optional)
331                # Project version and tag (optional)
332                my ($extpkgdir, $version, $filteredfiles, $supfiles) = pb_conf_get_if("extpkgdir","version","filteredfiles","supfiles");
333                pb_log(2,"DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n");
334                pb_log(2,"DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n");
335                pb_log(2,"DEBUG: version: ".Dumper($version)."\n");
336                pb_log(2,"DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n");
337                pb_log(2,"DEBUG: supfiles: ".Dumper($supfiles)."\n");
338                # Global
339                %defpkgdir = %$defpkgdir;
340                %extpkgdir = %$extpkgdir if (defined $extpkgdir);
341                %version = %$version if (defined $version);
342                %filteredfiles = %$filteredfiles if (defined $filteredfiles);
343                %supfiles = %$supfiles if (defined $supfiles);
344                #
345                # Get global Version/Tag
346                #
347                if (not defined $ENV{'PBPROJVER'}) {
348                        if ((defined $pkgv) && (defined $pkgv->{$ENV{'PBPROJ'}})) {
349                                $ENV{'PBPROJVER'}=$pkgv->{$ENV{'PBPROJ'}};
350                        } else {
351                                die "No projver found in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb";
352                        }
353                }
354                die "Invalid version name $ENV{'PBPROJVER'} in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb" if (($ENV{'PBPROJVER'} !~ /[0-9.]+/) && (not defined $version) && ($ENV{'PBPROJVER'} =~ /$version{$ENV{'PBPROJ'}}/));
355               
356                if (not defined $ENV{'PBPROJTAG'}) {
357                        if ((defined $pkgt) && (defined $pkgt->{$ENV{'PBPROJ'}})) {
358                                $ENV{'PBPROJTAG'}=$pkgt->{$ENV{'PBPROJ'}};
359                        } else {
360                                die "No projtag found in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb";
361                        }
362                }
363                die "Invalid tag name $ENV{'PBPROJTAG'} in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb" if ($ENV{'PBPROJTAG'} !~ /[0-9.]+/);
364       
365       
366                if (not defined $ENV{'PBPACKAGER'}) {
367                        if ((defined $pbpackager) && (defined $pbpackager->{$ENV{'PBPROJ'}})) {
368                                $ENV{'PBPACKAGER'}=$pbpackager->{$ENV{'PBPROJ'}};
369                        } else {
370                                die "No pbpackager found in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb";
371                        }
372                }
373        } else {
374                if (defined $pbinit) {
375                        my @pkgs = @ARGV;
376                        @pkgs = ("pkg1") if (not @pkgs);
377       
378                        open(CONF,"> $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb") || die "Unable to create $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb";
379                        print CONF << "EOF";
380#
381# Project Builder configuration file
382# For project $ENV{'PBPROJ'}
383#
384# \$Id\$
385#
386
387#
388# What is the project URL
389#
390#pburl $ENV{'PBPROJ'} = svn://svn.$ENV{'PBPROJ'}.org/$ENV{'PBPROJ'}/devel
391#pburl $ENV{'PBPROJ'} = svn://svn+ssh.$ENV{'PBPROJ'}.org/$ENV{'PBPROJ'}/devel
392#pburl $ENV{'PBPROJ'} = cvs://cvs.$ENV{'PBPROJ'}.org/$ENV{'PBPROJ'}/devel
393#pburl $ENV{'PBPROJ'} = http://www.$ENV{'PBPROJ'}.org/src/$ENV{'PBPROJ'}-devel.tar.gz
394#pburl $ENV{'PBPROJ'} = ftp://ftp.$ENV{'PBPROJ'}.org/src/$ENV{'PBPROJ'}-devel.tar.gz
395#pburl $ENV{'PBPROJ'} = file:///src/$ENV{'PBPROJ'}-devel.tar.gz
396#pburl $ENV{'PBPROJ'} = dir:///src/$ENV{'PBPROJ'}-devel
397
398# Repository
399#pbrepo $ENV{'PBPROJ'} = ftp://ftp.$ENV{'PBPROJ'}.org
400#pbml $ENV{'PBPROJ'} = $ENV{'PBPROJ'}-announce\@lists.$ENV{'PBPROJ'}.org
401#pbsmtp $ENV{'PBPROJ'} = localhost
402
403# Check whether project is well formed
404# when downloading from ftp/http/...
405# (containing already a directory with the project-version name)
406#pbwf $ENV{'PBPROJ'} = 1
407
408#
409# Packager label
410#
411#pbpackager $ENV{'PBPROJ'} = William Porte <bill\@$ENV{'PBPROJ'}.org>
412#
413
414# For delivery to a machine by SSH (potentially the FTP server)
415# Needs hostname, account and directory
416#
417#sshhost $ENV{'PBPROJ'} = www.$ENV{'PBPROJ'}.org
418#sshlogin $ENV{'PBPROJ'} = bill
419#sshdir $ENV{'PBPROJ'} = /$ENV{'PBPROJ'}/ftp
420#sshport $ENV{'PBPROJ'} = 22
421
422#
423# For Virtual machines management
424# Naming convention to follow: distribution name (as per ProjectBuilder::Distribution)
425# followed by '-' and by release number
426# followed by '-' and by architecture
427# a .vmtype extension will be added to the resulting string
428# a QEMU rhel-3-i286 here means that the VM will be named rhel-3-i386.qemu
429#
430#vmlist $ENV{'PBPROJ'} = mandrake-10.1-i386,mandrake-10.2-i386,mandriva-2006.0-i386,mandriva-2007.0-i386,mandriva-2007.1-i386,mandriva-2008.0-i386,redhat-7.3-i386,redhat-9-i386,fedora-4-i386,fedora-5-i386,fedora-6-i386,fedora-7-i386,fedora-8-i386,rhel-3-i386,rhel-4-i386,rhel-5-i386,suse-10.0-i386,suse-10.1-i386,suse-10.2-i386,suse-10.3-i386,sles-9-i386,sles-10-i386,gentoo-nover-i386,debian-3.1-i386,debian-4.0-i386,ubuntu-6.06-i386,ubuntu-7.04-i386,ubuntu-7.10-i386,mandriva-2007.0-x86_64,mandriva-2007.1-x86_64,mandriva-2008.0-x86_64,fedora-6-x86_64,fedora-7-x86_64,fedora-8-x86_64,rhel-4-x86_64,rhel-5-x86_64,suse-10.2-x86_64,suse-10.3-x86_64,sles-10-x86_64,gentoo-nover-x86_64,debian-4.0-x86_64,ubuntu-7.04-x86_64,ubuntu-7.10-x86_64,solaris-10-x86_64
431
432#
433# Valid values for vmtype are
434# qemu, (vmware, xen, ... TBD)
435#vmtype $ENV{'PBPROJ'} = qemu
436
437# Hash for VM stuff on vmtype
438#vmntp default = pool.ntp.org
439
440# We suppose we can commmunicate with the VM through SSH
441#vmhost $ENV{'PBPROJ'} = localhost
442#vmlogin $ENV{'PBPROJ'} = pb
443#vmport $ENV{'PBPROJ'} = 2222
444
445# Timeout to wait when VM is launched/stopped
446#vmtmout default = 120
447
448# per VMs needed paramaters
449#vmopt $ENV{'PBPROJ'} = -m 384 -daemonize
450#vmpath $ENV{'PBPROJ'} = /home/qemu
451#vmsize $ENV{'PBPROJ'} = 5G
452
453#
454# For Virtual environment management
455# Naming convention to follow: distribution name (as per ProjectBuilder::Distribution)
456# followed by '-' and by release number
457# followed by '-' and by architecture
458# a .vetype extension will be added to the resulting string
459# a chroot rhel-3-i286 here means that the VE will be named rhel-3-i386.chroot
460#
461#velist $ENV{'PBPROJ'} = fedora-7-i386
462
463# VE params
464#vetype $ENV{'PBPROJ'} = chroot
465#ventp default = pool.ntp.org
466#velogin $ENV{'PBPROJ'} = pb
467#vepath $ENV{'PBPROJ'} = /var/cache/rpmbootstrap
468#rbsconf $ENV{'PBPROJ'} = /etc/mock
469#verebuild $ENV{'PBPROJ'} = false
470
471#
472# Global version/tag for the project
473#
474#projver $ENV{'PBPROJ'} = devel
475#projtag $ENV{'PBPROJ'} = 1
476
477# Hash of valid version names
478
479# Additional repository to add at build time
480# addrepo centos-5-x86_64 = http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm,ftp://ftp.project-builder.org/centos/5/pb.repo
481# addrepo centos-5-x86_64 = http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm,ftp://ftp.project-builder.org/centos/5/pb.repo
482#version $ENV{'PBPROJ'} = devel,stable
483
484# Is it a test version or a production version
485testver $ENV{'PBPROJ'} = true
486# Which upper target dir for delivery
487delivery $ENV{'PBPROJ'} = test
488
489# Additional repository to add at build time
490# addrepo centos-5-x86_64 = http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm,ftp://ftp.project-builder.org/centos/5/pb.repo
491# addrepo centos-4-x86_64 = http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el4.rf.x86_64.rpm,ftp://ftp.project-builder.org/centos/4/pb.repo
492
493# Adapt to your needs:
494# Optional if you need to overwrite the global values above
495#
496EOF
497               
498                        foreach my $pp (@pkgs) {
499                                print CONF << "EOF";
500#pkgver $pp = stable
501#pkgtag $pp = 3
502EOF
503                        }
504                        foreach my $pp (@pkgs) {
505                                print CONF << "EOF";
506# Hash of default package/package directory
507#defpkgdir $pp = dir-$pp
508EOF
509                        }
510       
511                        print CONF << "EOF";
512# Hash of additional package/package directory
513#extpkgdir minor-pkg = dir-minor-pkg
514
515# List of files per pkg on which to apply filters
516# Files are mentioned relatively to pbroot/defpkgdir
517EOF
518                        foreach my $pp (@pkgs) {
519                                print CONF << "EOF";
520#filteredfiles $pp = Makefile.PL,configure.in,install.sh,$pp.8
521#supfiles $pp = $pp.init
522
523# For perl modules, names are different depending on distro
524# Here perl-xxx for RPMs, libxxx-perl for debs, ...
525# So the package name is indeed virtual
526#namingtype $pp = perl
527EOF
528                        }
529                        close(CONF);
530                        pb_mkdir_p("$ENV{'PBROOTDIR'}/pbfilter") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter";
531                        open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/all.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/all.pbf";
532                        print CONF << "EOF";
533#
534# \$Id\$
535#
536# Filter for all files
537#
538#
539# PBREPO is replaced by the root URL to access the repository
540filter PBREPO = \$pb->{'repo'}
541
542# PBSRC is replaced by the source package location after the repo
543#filter PBSRC = src/%{name}-%{version}.tar.gz
544# Used if virtual name != real name (perl, ...)
545#filter PBSRC = src/%{srcname}-%{version}.tar.gz
546
547# PBVER is replaced by the version (\$pb->{'ver'} in code)
548filter PBVER = \$pb->{'ver'}
549
550# PBDATE is replaced by the date (\$pb->{'date'} in code)
551filter PBDATE = \$pb->{'date'}
552
553# PBPATCHSRC is replaced by the patches names if value is yes
554#filter PBPATCHSRC = yes
555
556# PBPATCHCMD is replaced by the patches commands if value is yes
557#filter PBPATCHCMD = yes
558
559# PBTAG is replaced by the tag (\$pb->{'tag'} in code)
560filter PBTAG = \$pb->{'tag'}
561
562# PBREV is replaced by the revision (\$pb->{'rev'} in code)
563filter PBREV = \$pb->{'rev'}
564
565# PBREALPKG is replaced by the package name (\$pb->{'realpkg'} in code)
566filter PBREALPKG = \$pb->{'realpkg'}
567
568# PBPKG is replaced by the package name (\$pb->{'pkg'} in code)
569filter PBPKG = \$pb->{'pkg'}
570
571# PBPROJ is replaced by the project name (\$pb->{'proj'} in code)
572filter PBPROJ = \$pb->{'proj'}
573
574# PBPACKAGER is replaced by the packager name (\$pb->{'packager'} in code)
575filter PBPACKAGER = \$pb->{'packager'}
576
577# PBDESC contains the description of the package
578#filter PBDESC = Bla-Bla
579
580# PBSUMMARY contains a short single line description of the package
581#filter PBSUMMARY = Bla
582
583# PBURL contains the URL of the Web site of the project
584#filter PBURL = http://www.$ENV{'PBPROJ'}.org
585
586# PBLOG is replaced by the changelog if value is yes
587# and should be last as when used we need the %pb hash filled
588#filter PBLOG = yes
589
590EOF
591                        close(CONF);
592                        open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/rpm.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/rpm.pbf";
593                        print CONF << "EOF";
594#
595# \$Id\$
596#
597# Filter for rpm build
598#
599
600# PBGRP is replaced by the RPM group of apps
601#filter PBGRP = Applications/Archiving
602
603# PBLIC is replaced by the license of the application
604#filter PBLIC = GPL
605
606# PBDEP is replaced by the list of dependencies
607#filter PBDEP =
608
609# PBSUF is replaced by the package suffix (\$pb->{'suf'} in code)
610filter PBSUF = \$pb->{'suf'}
611
612# PBOBS is replaced by the Obsolete line
613#filter PBOBS =
614
615EOF
616                        close(CONF);
617                        open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/fedora.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/fedora.pbf";
618                        print CONF << "EOF";
619#
620# \$Id\$
621#
622# Filter for rpm build
623#
624
625# PBGRP is replaced by the RPM group of apps
626# Cf: http://fedoraproject.org/wiki/RPMGroups
627#filter PBGRP = Applications/Archiving
628
629# PBLIC is replaced by the license of the application
630# Cf: http://fedoraproject.org/wiki/Licensing
631#filter PBLIC = GPLv2+
632
633# PBDEP is replaced by the list of dependencies
634#filter PBDEP =
635
636# PBSUF is replaced by the package suffix (\$pb->{'suf'} in code)
637filter PBSUF = %{dist}
638
639# PBOBS is replaced by the Obsolete line
640#filter PBOBS =
641
642EOF
643                        close(CONF);
644                        foreach my $i (1..7) {
645                                open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/fedora-$i.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/fedora-$i.pbf";
646                                print CONF << "EOF";
647#
648# \$Id\$
649#
650# Filter for old fedora build
651#
652
653# PBSUF is replaced by the package suffix (\$pb->{'suf'} in code)
654filter PBSUF = \$pb->{'suf'}
655
656EOF
657                                close(CONF);
658                        }
659                        open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/deb.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/deb.pbf";
660                        print CONF << "EOF";
661#
662# \$Id\$
663#
664# Filter for debian build
665#
666# PBGRP is replaced by the group of apps
667filter PBGRP = utils
668
669# PBLIC is replaced by the license of the application
670# Cf: http://www.debian.org/legal/licenses/
671#filter PBLIC = GPL
672
673# PBDEP is replaced by the list of dependencies
674#filter PBDEP =
675
676# PBSUG is replaced by the list of suggestions
677#filter PBSUG =
678
679# PBREC is replaced by the list of recommandations
680#filter PBREC =
681
682EOF
683                        close(CONF);
684                        open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-4.0.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-4.0.pbf";
685                        print CONF << "EOF";
686#
687# \$Id\$
688#
689# Filter for debian build
690#
691# PBDEBSTD is replaced by the Debian standard version
692filter PBDEBSTD = 3.6.1
693
694# PBDEBCOMP is replaced by the Debian Compatibility value
695filter PBDEBCOMP = 5
696
697EOF
698                        close(CONF);
699                        open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-5.0.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-5.0.pbf";
700                        print CONF << "EOF";
701#
702# \$Id\$
703#
704# Filter for debian build
705#
706# PBDEBSTD is replaced by the Debian standard version
707filter PBDEBSTD = 3.8.0
708
709# PBDEBCOMP is replaced by the Debian Compatibility value
710filter PBDEBCOMP = 7
711
712EOF
713                        close(CONF);
714                        open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/md.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/md.pbf";
715                        print CONF << "EOF";
716# Specific group for Mandriva for $ENV{'PBPROJ'}
717# Cf: http://wiki.mandriva.com/en/Development/Packaging/Groups
718#filter PBGRP = Archiving/Backup
719
720# PBLIC is replaced by the license of the application
721# Cf: http://wiki.mandriva.com/en/Development/Packaging/Licenses
722#filter PBLIC = GPL
723
724EOF
725                        close(CONF);
726                        open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/novell.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/novell.pbf";
727                        print CONF << "EOF";
728# Specific group for SuSE for $ENV{'PBPROJ'}
729# Cf: http://en.opensuse.org/SUSE_Package_Conventions/RPM_Groups
730#filter PBGRP = Productivity/Archiving/Backup
731
732# PBLIC is replaced by the license of the application
733# Cf: http://en.opensuse.org/Packaging/SUSE_Package_Conventions/RPM_Style#1.6._License_Tag
734#filter PBLIC = GPL
735
736EOF
737                        close(CONF);
738                        foreach my $pp (@pkgs) {
739                                pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/deb") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb";
740                                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/control") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/control";
741                                print CONF << "EOF";
742Source: PBPKG
743# http://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections
744Section: PBGRP
745Priority: optional
746Maintainer: PBPACKAGER
747Build-Depends: debhelper (>= 4.2.20), PBDEP
748Standards-Version: PBDEBSTD
749Vcs-Svn: svn://svn.PBPROJ.org/svn/PBVER/PBPKG
750Vcs-Browser: http://trac.PBPROJ.org/browser/PBVER/PBPKG
751Homepage: PBURL
752
753Package: PBPKG
754Architecture: amd64 i386 ia64
755# http://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections
756Section: PBGRP
757Priority: optional
758Depends: \${shlibs:Depends}, \${misc:Depends}, PBDEP
759Recommends: PBREC
760Suggests: PBSUG
761Description: PBSUMMARY
762 PBDESC
763 .
764
765EOF
766                                close(CONF);
767                                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/copyright") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/copyright";
768                                print CONF << "EOF";
769This package is debianized by PBPACKAGER
770`date`
771
772The current upstream source was downloaded from
773PBREPO.
774
775Upstream Authors: Put their name here
776
777Copyright:
778
779   This package is free software; you can redistribute it and/or modify
780   it under the terms of the GNU General Public License as published by
781   the Free Software Foundation; version 2 dated June, 1991.
782
783   This package is distributed in the hope that it will be useful,
784   but WITHOUT ANY WARRANTY; without even the implied warranty of
785   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
786   GNU General Public License for more details.
787
788   You should have received a copy of the GNU General Public License
789   along with this package; if not, write to the Free Software
790   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
791   MA 02110-1301, USA.
792
793On Debian systems, the complete text of the GNU General
794Public License can be found in /usr/share/common-licenses/GPL.
795
796EOF
797                                close(CONF);
798                                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/changelog") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/changelog";
799                                print CONF << "EOF";
800PBLOG
801EOF
802                                close(CONF);
803                                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/compat") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/compat";
804                                print CONF << "EOF";
805PBDEBCOMP
806EOF
807                                close(CONF);
808                                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/$pp.dirs") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/$pp.dirs";
809                                print CONF << "EOF";
810EOF
811                                close(CONF);
812                                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/$pp.docs") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/$pp.docs";
813                                print CONF << "EOF";
814INSTALL
815COPYING
816AUTHORS
817NEWS
818README
819EOF
820                                close(CONF);
821                                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/rules") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/rules";
822                                print CONF << 'EOF';
823#!/usr/bin/make -f
824# -*- makefile -*-
825# Sample debian/rules that uses debhelper.
826# GNU copyright 1997 to 1999 by Joey Hess.
827#
828# $Id$
829#
830
831# Uncomment this to turn on verbose mode.
832#export DH_VERBOSE=1
833
834# Define package name variable for a one-stop change.
835PACKAGE_NAME = PBPKG
836
837# These are used for cross-compiling and for saving the configure script
838# from having to guess our platform (since we know it already)
839DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
840DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
841
842CFLAGS = -Wall -g
843
844ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
845        CFLAGS += -O0
846else
847        CFLAGS += -O2
848endif
849ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
850        INSTALL_PROGRAM += -s
851endif
852config.status: configure
853        dh_testdir
854
855        # Configure the package.
856        CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr
857 --mandir=\$${prefix}/share/man
858
859# Build both architecture dependent and independent
860build: build-arch build-indep
861
862# Build architecture dependent
863build-arch: build-arch-stamp
864
865build-arch-stamp:  config.status
866        dh_testdir
867
868        # Compile the package.
869        $(MAKE)
870
871        touch build-stamp
872
873# Build architecture independent
874build-indep: build-indep-stamp
875
876build-indep-stamp:  config.status
877        # Nothing to do, the only indep item is the manual which is available as html in original source
878        touch build-indep-stamp
879
880# Clean up
881clean:
882        dh_testdir
883        dh_testroot
884        rm -f build-arch-stamp build-indep-stamp #CONFIGURE-STAMP#
885        # Clean temporary document directory
886        rm -rf debian/doc-temp
887        # Clean up.
888        -$(MAKE) distclean
889        rm -f config.log
890ifneq "$(wildcard /usr/share/misc/config.sub)" ""
891        cp -f /usr/share/misc/config.sub config.sub
892endif
893ifneq "$(wildcard /usr/share/misc/config.guess)" ""
894        cp -f /usr/share/misc/config.guess config.guess
895endif
896
897        dh_clean
898
899# Install architecture dependent and independent
900install: install-arch install-indep
901
902# Install architecture dependent
903install-arch: build-arch
904        dh_testdir
905        dh_testroot
906        dh_clean -k -s
907        dh_installdirs -s
908
909        # Install the package files into build directory:
910        # - start with upstream make install
911        $(MAKE) install prefix=$(CURDIR)/debian/$(PACKAGE_NAME)/usr mandir=$(CURDIR)/debian/$(PACKAGE_NAME)/usr/share/man
912        # - copy html manual to temporary location for renaming
913        mkdir -p debian/doc-temp
914        dh_install -s
915
916# Install architecture independent
917install-indep: build-indep
918        dh_testdir
919        dh_testroot
920        dh_clean -k -i
921        dh_installdirs -i
922        dh_install -i
923
924# Must not depend on anything. This is to be called by
925# binary-arch/binary-indep
926# in another 'make' thread.
927binary-common:
928        dh_testdir
929        dh_testroot
930        dh_installchangelogs ChangeLog
931        dh_installdocs
932        dh_installman
933        dh_link
934        dh_strip
935        dh_compress
936        dh_fixperms
937        dh_installdeb
938        dh_shlibdeps
939        dh_gencontrol
940        dh_md5sums
941        dh_builddeb
942
943# Build architecture independant packages using the common target.
944binary-indep: build-indep install-indep
945        $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
946
947# Build architecture dependant packages using the common target.
948binary-arch: build-arch install-arch
949        $(MAKE) -f debian/rules DH_OPTIONS=-a binary-common
950
951# Build architecture depdendent and independent packages
952binary: binary-arch binary-indep
953.PHONY: clean binary
954
955EOF
956                                close(CONF);
957                                pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/rpm") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/rpm";
958                                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/rpm/$pp.spec") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/rpm/$pp.spec";
959                                print CONF << 'EOF';
960#
961# $Id$
962#
963# Used if virtual name != real name (perl, ...)
964#%define srcname        PBPKG
965
966Summary:        PBSUMMARY
967Summary(fr):    french bla-bla
968
969Name:           PBREALPKG
970Version:        PBVER
971Release:        PBTAGPBSUF
972License:        PBLIC
973Group:          PBGRP
974Url:            PBURL
975Source:         PBREPO/PBSRC
976#PBPATCHSRC
977BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(id -u -n)
978#Requires:       PBDEP
979
980%description
981PBDESC
982
983%description -l fr
984french desc
985
986%prep
987%setup -q
988# Used if virtual name != real name (perl, ...)
989#%setup -q -n %{srcname}-%{version}
990#PBPATCHCMD
991
992%build
993%configure
994make %{?_smp_mflags}
995
996%install
997%{__rm} -rf $RPM_BUILD_ROOT
998make DESTDIR=$RPM_BUILD_ROOT install
999
1000%clean
1001%{__rm} -rf $RPM_BUILD_ROOT
1002
1003%files
1004%defattr(-,root,root)
1005%doc ChangeLog
1006%doc INSTALL COPYING README AUTHORS NEWS
1007
1008%changelog
1009PBLOG
1010
1011EOF
1012                                close(CONF);
1013                                pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/pbfilter") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/pbfilter";
1014                                pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/pkg") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/pkg";
1015                                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/pkg/pkginfo") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/pkg/pkginfo";
1016                                print CONF << 'EOF';
1017#
1018# $Id$
1019#
1020PKG="PBREALPKG"
1021NAME="PBSUMMARY"
1022VERSION="PBVER"
1023# or i386
1024ARCH="all"
1025CATEGORY="application"
1026DESC="PBDESC"
1027EMAIL="PBPACKAGER"
1028VENDOR="PBPACKAGER"
1029HOTLINE="PBURL"
1030EOF
1031                                close(CONF);
1032                                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/pkg/pbbuild") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/pkg/pbbuild";
1033                                print CONF << 'EOF';
1034#
1035# $Id$
1036#
1037#perl Makefile.PL INSTALLDIRS=vendor
1038./configure --prefix=/usr
1039make
1040make install DESTDIR=\$1
1041EOF
1042                                close(CONF);
1043                                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/pkg/depend") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/pkg/depend";
1044                                print CONF << 'EOF';
1045#
1046# $Id$
1047#
1048#P SUNWperl584core       Perl 5.8.4 (core)
1049EOF
1050                                close(CONF);
1051       
1052                        }
1053                        pb_cms_add($pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONFDIR'});
1054                        pb_cms_checkin($pbconf{$ENV{'PBPROJ'}},"$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}",$pbinit);
1055                } else {
1056                        pb_log(0,"ERROR: no pbroot defined, used $ENV{'PBROOTDIR'}, without finding $ENV{'PBPROJ'}.pb in it\n");
1057                        pb_log(0,"       Please use -r release in order to be able to initialize your environment correctly\n");
1058                        die "Unable to open $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb";
1059                }
1060        }
1061        umask 0022;
1062        return(\%filteredfiles, \%supfiles, \%defpkgdir, \%extpkgdir);
1063} else {
1064        # Setup the variables from what has been stored at the end of cms2build
1065        my ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","pbroot");
1066        $ENV{'PBROOTDIR'} = $var->{$ENV{'PBPROJ'}};
1067
1068        ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","projver");
1069        $ENV{'PBPROJVER'} = $var->{$ENV{'PBPROJ'}};
1070
1071        ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","projtag");
1072        $ENV{'PBPROJTAG'} = $var->{$ENV{'PBPROJ'}};
1073
1074        ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","pbpackager");
1075        $ENV{'PBPACKAGER'} = $var->{$ENV{'PBPROJ'}};
1076
1077        return;
1078}
1079}
1080
1081=back
1082
1083=head1 WEB SITES
1084
1085The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
1086
1087=head1 USER MAILING LIST
1088
1089None exists for the moment.
1090
1091=head1 AUTHORS
1092
1093The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
1094
1095=head1 COPYRIGHT
1096
1097Project-Builder.org is distributed under the GPL v2.0 license
1098described in the file C<COPYING> included with the distribution.
1099
1100=cut
1101
11021;
Note: See TracBrowser for help on using the repository browser.