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

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