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

Last change on this file since 1130 was 1130, checked in by Bruno Cornec, 13 years ago
  • First attempt to fix both #74 and #10 by adding support for additional files under a pbsrc dir, that can be manipulated at build time.
File size: 33.8 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/)) {
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. Patches are located under the pbpatch dir of the pkg.
558#filter PBPATCHSRC = yes
559
560# PBPATCHCMD is replaced by the patches commands if value is yes
561#filter PBPATCHCMD = yes
562
563# PBMULTISRC is replaced by the sources names if value is yes. Sources are located under the pbsrc dir of the pkg.
564#filter PBMULTISRC = yes
565
566# PBTAG is replaced by the tag (\$pb->{'tag'} in code)
567filter PBTAG = \$pb->{'tag'}
568
569# PBREV is replaced by the revision (\$pb->{'rev'} in code)
570filter PBREV = \$pb->{'rev'}
571
572# PBREALPKG is replaced by the package name (\$pb->{'realpkg'} in code)
573filter PBREALPKG = \$pb->{'realpkg'}
574
575# PBPKG is replaced by the package name (\$pb->{'pkg'} in code)
576filter PBPKG = \$pb->{'pkg'}
577
578# PBPROJ is replaced by the project name (\$pb->{'proj'} in code)
579filter PBPROJ = \$pb->{'proj'}
580
581# PBPACKAGER is replaced by the packager name (\$pb->{'packager'} in code)
582filter PBPACKAGER = \$pb->{'packager'}
583
584# PBDESC contains the description of the package
585#filter PBDESC = Bla-Bla
586
587# PBSUMMARY contains a short single line description of the package
588#filter PBSUMMARY = Bla
589
590# PBURL contains the URL of the Web site of the project
591#filter PBURL = http://www.$ENV{'PBPROJ'}.org
592
593# PBLOG is replaced by the changelog if value is yes
594# and should be last as when used we need the %pb hash filled
595#filter PBLOG = yes
596
597EOF
598 close(CONF);
599 open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/rpm.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/rpm.pbf";
600 print CONF << "EOF";
601#
602# \$Id\$
603#
604# Filter for rpm build
605#
606
607# PBGRP is replaced by the RPM group of apps
608#filter PBGRP = Applications/Archiving
609
610# PBLIC is replaced by the license of the application
611#filter PBLIC = GPL
612
613# PBDEP is replaced by the list of dependencies
614#filter PBDEP =
615
616# PBSUF is replaced by the package suffix (\$pb->{'suf'} in code)
617filter PBSUF = \$pb->{'suf'}
618
619# PBOBS is replaced by the Obsolete line
620#filter PBOBS =
621
622EOF
623 close(CONF);
624 open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/fedora.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/fedora.pbf";
625 print CONF << "EOF";
626#
627# \$Id\$
628#
629# Filter for rpm build
630#
631
632# PBGRP is replaced by the RPM group of apps
633# Cf: http://fedoraproject.org/wiki/RPMGroups
634#filter PBGRP = Applications/Archiving
635
636# PBLIC is replaced by the license of the application
637# Cf: http://fedoraproject.org/wiki/Licensing
638#filter PBLIC = GPLv2+
639
640# PBDEP is replaced by the list of dependencies
641#filter PBDEP =
642
643# PBSUF is replaced by the package suffix (\$pb->{'suf'} in code)
644filter PBSUF = %{dist}
645
646# PBOBS is replaced by the Obsolete line
647#filter PBOBS =
648
649EOF
650 close(CONF);
651 foreach my $i (1..7) {
652 open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/fedora-$i.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/fedora-$i.pbf";
653 print CONF << "EOF";
654#
655# \$Id\$
656#
657# Filter for old fedora build
658#
659
660# PBSUF is replaced by the package suffix (\$pb->{'suf'} in code)
661filter PBSUF = \$pb->{'suf'}
662
663EOF
664 close(CONF);
665 }
666 open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/deb.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/deb.pbf";
667 print CONF << "EOF";
668#
669# \$Id\$
670#
671# Filter for debian build
672#
673# PBGRP is replaced by the group of apps
674filter PBGRP = utils
675
676# PBLIC is replaced by the license of the application
677# Cf: http://www.debian.org/legal/licenses/
678#filter PBLIC = GPL
679
680# PBDEP is replaced by the list of dependencies
681#filter PBDEP =
682
683# PBSUG is replaced by the list of suggestions
684#filter PBSUG =
685
686# PBREC is replaced by the list of recommandations
687#filter PBREC =
688
689EOF
690 close(CONF);
691 open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-4.0.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-4.0.pbf";
692 print CONF << "EOF";
693#
694# \$Id\$
695#
696# Filter for debian build
697#
698# PBDEBSTD is replaced by the Debian standard version
699filter PBDEBSTD = 3.6.1
700
701# PBDEBCOMP is replaced by the Debian Compatibility value
702filter PBDEBCOMP = 5
703
704EOF
705 close(CONF);
706 open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-5.0.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-5.0.pbf";
707 print CONF << "EOF";
708#
709# \$Id\$
710#
711# Filter for debian build
712#
713# PBDEBSTD is replaced by the Debian standard version
714filter PBDEBSTD = 3.8.0
715
716# PBDEBCOMP is replaced by the Debian Compatibility value
717filter PBDEBCOMP = 7
718
719EOF
720 close(CONF);
721 open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/md.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/md.pbf";
722 print CONF << "EOF";
723# Specific group for Mandriva for $ENV{'PBPROJ'}
724# Cf: http://wiki.mandriva.com/en/Development/Packaging/Groups
725#filter PBGRP = Archiving/Backup
726
727# PBLIC is replaced by the license of the application
728# Cf: http://wiki.mandriva.com/en/Development/Packaging/Licenses
729#filter PBLIC = GPL
730
731EOF
732 close(CONF);
733 open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/novell.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/novell.pbf";
734 print CONF << "EOF";
735# Specific group for SuSE for $ENV{'PBPROJ'}
736# Cf: http://en.opensuse.org/SUSE_Package_Conventions/RPM_Groups
737#filter PBGRP = Productivity/Archiving/Backup
738
739# PBLIC is replaced by the license of the application
740# Cf: http://en.opensuse.org/Packaging/SUSE_Package_Conventions/RPM_Style#1.6._License_Tag
741#filter PBLIC = GPL
742
743EOF
744 close(CONF);
745 foreach my $pp (@pkgs) {
746 pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/deb") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb";
747 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/control") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/control";
748 print CONF << "EOF";
749Source: PBPKG
750# http://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections
751Section: PBGRP
752Priority: optional
753Maintainer: PBPACKAGER
754Build-Depends: debhelper (>= 4.2.20), PBDEP
755Standards-Version: PBDEBSTD
756Vcs-Svn: svn://svn.PBPROJ.org/svn/PBVER/PBPKG
757Vcs-Browser: http://trac.PBPROJ.org/browser/PBVER/PBPKG
758Homepage: PBURL
759
760Package: PBPKG
761Architecture: amd64 i386 ia64
762# http://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections
763Section: PBGRP
764Priority: optional
765Depends: \${shlibs:Depends}, \${misc:Depends}, PBDEP
766Recommends: PBREC
767Suggests: PBSUG
768Description: PBSUMMARY
769 PBDESC
770 .
771
772EOF
773 close(CONF);
774 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/copyright") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/copyright";
775 print CONF << "EOF";
776This package is debianized by PBPACKAGER
777`date`
778
779The current upstream source was downloaded from
780PBREPO.
781
782Upstream Authors: Put their name here
783
784Copyright:
785
786 This package is free software; you can redistribute it and/or modify
787 it under the terms of the GNU General Public License as published by
788 the Free Software Foundation; version 2 dated June, 1991.
789
790 This package is distributed in the hope that it will be useful,
791 but WITHOUT ANY WARRANTY; without even the implied warranty of
792 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
793 GNU General Public License for more details.
794
795 You should have received a copy of the GNU General Public License
796 along with this package; if not, write to the Free Software
797 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
798 MA 02110-1301, USA.
799
800On Debian systems, the complete text of the GNU General
801Public License can be found in /usr/share/common-licenses/GPL.
802
803EOF
804 close(CONF);
805 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/changelog") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/changelog";
806 print CONF << "EOF";
807PBLOG
808EOF
809 close(CONF);
810 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/compat") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/compat";
811 print CONF << "EOF";
812PBDEBCOMP
813EOF
814 close(CONF);
815 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/$pp.dirs") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/$pp.dirs";
816 print CONF << "EOF";
817EOF
818 close(CONF);
819 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/$pp.docs") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/$pp.docs";
820 print CONF << "EOF";
821INSTALL
822COPYING
823AUTHORS
824NEWS
825README
826EOF
827 close(CONF);
828 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/rules") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/rules";
829 print CONF << 'EOF';
830#!/usr/bin/make -f
831# -*- makefile -*-
832# Sample debian/rules that uses debhelper.
833# GNU copyright 1997 to 1999 by Joey Hess.
834#
835# $Id$
836#
837
838# Uncomment this to turn on verbose mode.
839#export DH_VERBOSE=1
840
841# Define package name variable for a one-stop change.
842PACKAGE_NAME = PBPKG
843
844# These are used for cross-compiling and for saving the configure script
845# from having to guess our platform (since we know it already)
846DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
847DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
848
849CFLAGS = -Wall -g
850
851ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
852 CFLAGS += -O0
853else
854 CFLAGS += -O2
855endif
856ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
857 INSTALL_PROGRAM += -s
858endif
859config.status: configure
860 dh_testdir
861
862 # Configure the package.
863 CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr
864 --mandir=\$${prefix}/share/man
865
866# Build both architecture dependent and independent
867build: build-arch build-indep
868
869# Build architecture dependent
870build-arch: build-arch-stamp
871
872build-arch-stamp: config.status
873 dh_testdir
874
875 # Compile the package.
876 $(MAKE)
877
878 touch build-stamp
879
880# Build architecture independent
881build-indep: build-indep-stamp
882
883build-indep-stamp: config.status
884 # Nothing to do, the only indep item is the manual which is available as html in original source
885 touch build-indep-stamp
886
887# Clean up
888clean:
889 dh_testdir
890 dh_testroot
891 rm -f build-arch-stamp build-indep-stamp #CONFIGURE-STAMP#
892 # Clean temporary document directory
893 rm -rf debian/doc-temp
894 # Clean up.
895 -$(MAKE) distclean
896 rm -f config.log
897ifneq "$(wildcard /usr/share/misc/config.sub)" ""
898 cp -f /usr/share/misc/config.sub config.sub
899endif
900ifneq "$(wildcard /usr/share/misc/config.guess)" ""
901 cp -f /usr/share/misc/config.guess config.guess
902endif
903
904 dh_clean
905
906# Install architecture dependent and independent
907install: install-arch install-indep
908
909# Install architecture dependent
910install-arch: build-arch
911 dh_testdir
912 dh_testroot
913 dh_clean -k -s
914 dh_installdirs -s
915
916 # Install the package files into build directory:
917 # - start with upstream make install
918 $(MAKE) install prefix=$(CURDIR)/debian/$(PACKAGE_NAME)/usr mandir=$(CURDIR)/debian/$(PACKAGE_NAME)/usr/share/man
919 # - copy html manual to temporary location for renaming
920 mkdir -p debian/doc-temp
921 dh_install -s
922
923# Install architecture independent
924install-indep: build-indep
925 dh_testdir
926 dh_testroot
927 dh_clean -k -i
928 dh_installdirs -i
929 dh_install -i
930
931# Must not depend on anything. This is to be called by
932# binary-arch/binary-indep
933# in another 'make' thread.
934binary-common:
935 dh_testdir
936 dh_testroot
937 dh_installchangelogs ChangeLog
938 dh_installdocs
939 dh_installman
940 dh_link
941 dh_strip
942 dh_compress
943 dh_fixperms
944 dh_installdeb
945 dh_shlibdeps
946 dh_gencontrol
947 dh_md5sums
948 dh_builddeb
949
950# Build architecture independant packages using the common target.
951binary-indep: build-indep install-indep
952 $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
953
954# Build architecture dependant packages using the common target.
955binary-arch: build-arch install-arch
956 $(MAKE) -f debian/rules DH_OPTIONS=-a binary-common
957
958# Build architecture depdendent and independent packages
959binary: binary-arch binary-indep
960.PHONY: clean binary
961
962EOF
963 close(CONF);
964 pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/rpm") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/rpm";
965 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/rpm/$pp.spec") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/rpm/$pp.spec";
966 print CONF << 'EOF';
967#
968# $Id$
969#
970# Used if virtual name != real name (perl, ...) - replace hash by percent in the below line
971#define srcname PBPKG
972
973Summary: PBSUMMARY
974Summary(fr): french bla-bla
975
976Name: PBREALPKG
977Version: PBVER
978Release: PBTAGPBSUF
979License: PBLIC
980Group: PBGRP
981Url: PBURL
982Source: PBREPO/PBSRC
983#PBPATCHSRC
984BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(id -u -n)
985#Requires: PBDEP
986
987%description
988PBDESC
989
990%description -l fr
991french desc
992
993%prep
994%setup -q
995# Used if virtual name != real name (perl, ...)
996#%setup -q -n %{srcname}-%{version}
997#PBPATCHCMD
998
999%build
1000%configure
1001make %{?_smp_mflags}
1002
1003%install
1004%{__rm} -rf $RPM_BUILD_ROOT
1005make DESTDIR=$RPM_BUILD_ROOT install
1006
1007%clean
1008%{__rm} -rf $RPM_BUILD_ROOT
1009
1010%files
1011%defattr(-,root,root)
1012%doc ChangeLog
1013%doc INSTALL COPYING README AUTHORS NEWS
1014
1015%changelog
1016PBLOG
1017
1018EOF
1019 close(CONF);
1020 pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/pbfilter") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/pbfilter";
1021 pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/pkg") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/pkg";
1022 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/pkg/pkginfo") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/pkg/pkginfo";
1023 print CONF << 'EOF';
1024#
1025# $Id$
1026#
1027PKG="PBREALPKG"
1028NAME="PBSUMMARY"
1029VERSION="PBVER"
1030# or i386
1031ARCH="all"
1032CATEGORY="application"
1033DESC="PBDESC"
1034EMAIL="PBPACKAGER"
1035VENDOR="PBPACKAGER"
1036HOTLINE="PBURL"
1037EOF
1038 close(CONF);
1039 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/pkg/pbbuild") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/pkg/pbbuild";
1040 print CONF << 'EOF';
1041#
1042# $Id$
1043#
1044#perl Makefile.PL INSTALLDIRS=vendor
1045./configure --prefix=/usr
1046make
1047make install DESTDIR=\$1
1048EOF
1049 close(CONF);
1050 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/pkg/depend") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/pkg/depend";
1051 print CONF << 'EOF';
1052#
1053# $Id$
1054#
1055#P SUNWperl584core Perl 5.8.4 (core)
1056EOF
1057 close(CONF);
1058
1059 }
1060 pb_cms_add($pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONFDIR'});
1061 pb_cms_checkin($pbconf{$ENV{'PBPROJ'}},"$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}",$pbinit);
1062 } else {
1063 pb_log(0,"ERROR: no pbroot defined, used $ENV{'PBROOTDIR'}, without finding $ENV{'PBPROJ'}.pb in it\n");
1064 pb_log(0," Please use -r release in order to be able to initialize your environment correctly\n");
1065 die "Unable to open $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb";
1066 }
1067 }
1068 umask 0022;
1069 return(\%filteredfiles, \%supfiles, \%defpkgdir, \%extpkgdir);
1070} else {
1071 # Setup the variables from what has been stored at the end of cms2build
1072 my ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","pbroot");
1073 $ENV{'PBROOTDIR'} = $var->{$ENV{'PBPROJ'}};
1074
1075 ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","projver");
1076 $ENV{'PBPROJVER'} = $var->{$ENV{'PBPROJ'}};
1077
1078 ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","projtag");
1079 $ENV{'PBPROJTAG'} = $var->{$ENV{'PBPROJ'}};
1080
1081 ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","pbpackager");
1082 $ENV{'PBPACKAGER'} = $var->{$ENV{'PBPROJ'}};
1083
1084 return;
1085}
1086}
1087
1088=head1 WEB SITES
1089
1090The 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/>.
1091
1092=head1 USER MAILING LIST
1093
1094None exists for the moment.
1095
1096=head1 AUTHORS
1097
1098The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
1099
1100=head1 COPYRIGHT
1101
1102Project-Builder.org is distributed under the GPL v2.0 license
1103described in the file C<COPYING> included with the distribution.
1104
1105=cut
1106
11071;
Note: See TracBrowser for help on using the repository browser.