~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to scripts/cpanflute

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# need this for hostname()
 
4
use File::Basename;
 
5
use Sys::Hostname;
 
6
use Getopt::Long;
 
7
use strict;
 
8
 
 
9
my $MainDir = '/tmp/cpan';
 
10
 
 
11
# set default options, then get options
 
12
my %options=();
 
13
$options{'email'}=(getpwuid($<))[0] . "\@redhat.com" ;
 
14
GetOptions(\%options, "email=s", "n=s", "create") || exit 1;
 
15
 
 
16
my $InputFile = $ARGV[0];
 
17
my $create = '';
 
18
 
 
19
if ($options{'create'}) {
 
20
  $create = '-c';
 
21
}
 
22
 
 
23
my $tarball = basename($InputFile);
 
24
$tarball =~ /(\S+)\-(\S+)\.tar\.gz/;
 
25
my $clm_name=$1;
 
26
my $clm_version=$2;
 
27
 
 
28
my $class = dirname($InputFile);
 
29
$class =~ s/^\.\/[0-9][0-9]_//;
 
30
if ($class ne '.') {
 
31
  $class = "($class)";
 
32
} else {
 
33
  $class = "";
 
34
}
 
35
 
 
36
# Change ::'s to -'s
 
37
$clm_name =~ s/::/-/g;
 
38
 
 
39
my $clm_changelog = get_changelog();
 
40
 
 
41
# complain if either parameter is missing
 
42
($clm_name eq "") && die "Module name not specified\n";
 
43
($clm_version eq "") && die "Module version not specified\n";
 
44
 
 
45
# Create and Open file to create SPEC files.
 
46
mkdir($MainDir, 0755);
 
47
system("cp $InputFile $MainDir");
 
48
my $filename = $clm_name . '.spec'; 
 
49
open (FILE, "> $MainDir/$filename");
 
50
 
 
51
# Print the spec file. Lots of substitutions here.
 
52
print FILE "Summary: $clm_name module for perl $class
 
53
Name: perl-$clm_name
 
54
Version: $clm_version
 
55
Release: 7
 
56
Copyright: distributable
 
57
Group: Applications/CPAN
 
58
Source0: $clm_name-$clm_version.tar.gz
 
59
Url: http://www.cpan.org
 
60
BuildRoot: %{_tmppath}/perl-$clm_name-buildroot/
 
61
BuildRequires: perl >= 0:5.00503
 
62
Requires: perl >= 0:5.00503
 
63
 
 
64
%description
 
65
$clm_name module for perl
 
66
 
 
67
# Provide perl-specific find-{provides,requires}.
 
68
%define __find_provides /usr/lib/rpm/find-provides.perl
 
69
%define __find_requires /usr/lib/rpm/find-requires.perl
 
70
 
 
71
%prep
 
72
%setup -q -n $clm_name-%{version} $create
 
73
 
 
74
%build
 
75
CFLAGS=\"\$RPM_OPT_FLAGS\" perl Makefile.PL
 
76
make
 
77
 
 
78
%clean 
 
79
rm -rf \$RPM_BUILD_ROOT
 
80
 
 
81
%install
 
82
rm -rf \$RPM_BUILD_ROOT
 
83
eval `perl '-V:installarchlib'`
 
84
mkdir -p \$RPM_BUILD_ROOT/\$installarchlib
 
85
make PREFIX=\$RPM_BUILD_ROOT/usr install
 
86
 
 
87
[ -x /usr/lib/rpm/brp-compress ] && /usr/lib/rpm/brp-compress
 
88
 
 
89
find \$RPM_BUILD_ROOT/usr -type f -print | \
 
90
        sed \"s\@^\$RPM_BUILD_ROOT\@\@g\" | \
 
91
        grep -v perllocal.pod | \
 
92
        grep -v \"\\.packlist\" > $clm_name-$clm_version-filelist
 
93
if [ \"\$(cat $clm_name-$clm_version-filelist)X\" = \"X\" ] ; then
 
94
    echo \"ERROR: EMPTY FILE LIST\"
 
95
    exit -1
 
96
fi
 
97
 
 
98
%files -f $clm_name-$clm_version-filelist
 
99
%defattr(-,root,root)
 
100
 
 
101
%changelog
 
102
* $clm_changelog
 
103
- Spec file was autogenerated. 
 
104
";
 
105
close(FILE);
 
106
 
 
107
# Now build the rpm
 
108
create_rcfiles();
 
109
 
 
110
open (LOG, "> $MainDir/LogFile");
 
111
build_rpm();
 
112
close LOG;
 
113
 
 
114
sub cleanup {
 
115
  unlink "$MainDir/$filename";
 
116
  unlink "$MainDir/$tarball";
 
117
}
 
118
 
 
119
sub build_rpm {
 
120
  my $retval;
 
121
 
 
122
  # First, make sure it unpacks cleanely
 
123
  system("rpm --rcfile $MainDir/rpmrc -bp $MainDir/$filename");
 
124
  $retval = $? >> 8;
 
125
  if ($retval != 0) {
 
126
    print "RPM test unpacking failed!\n";
 
127
    print LOG "PREP failed: $filename\n";
 
128
    return;
 
129
  }
 
130
 
 
131
  system("rpm --rcfile $MainDir/rpmrc -bs --rmsource --rmspec --clean $MainDir/$filename");
 
132
  $retval = $? >> 8;
 
133
  if ($retval != 0) {
 
134
    print "RPM building failed!\n";
 
135
    print LOG "SOURCE failed: $filename\n";
 
136
    return;
 
137
  }
 
138
  cleanup();
 
139
}
 
140
 
 
141
sub create_rcfiles {
 
142
    open(MACROS, "> $MainDir/macros");
 
143
    print MACROS qq{
 
144
%_topdir        $MainDir
 
145
%_builddir      %{_topdir}/junk
 
146
%_rpmdir        %{_topdir}
 
147
%_sourcedir     %{_topdir}
 
148
%_specdir       %{_topdir}
 
149
%_srcrpmdir     %{_topdir}/temp
 
150
};
 
151
    close(MACROS);
 
152
  
 
153
    open(RPMRC, "> $MainDir/rpmrc");
 
154
    print RPMRC qq{
 
155
include: /usr/lib/rpm/rpmrc
 
156
macrofiles: /usr/lib/rpm/macros:$MainDir/macros
 
157
};
 
158
    close(RPMRC);
 
159
}
 
160
 
 
161
sub get_changelog {
 
162
  # generate the changelog entry from available system info
 
163
        my ($name);
 
164
 
 
165
        $name = (getpwuid($<))[6];
 
166
        $name = (split(",", $name))[0];
 
167
  return ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")[(localtime)[6]] . " " .
 
168
    ("Jan", "Feb", "Mar", "Apr", "May", "Jun",
 
169
     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")[(localtime)[4]] . " " .
 
170
    (localtime)[3] . " " . (1900+(localtime)[5]) . " " .
 
171
                $name . " <" . $options{'email'} . ">";
 
172
}
 
173