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

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