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

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