aboutsummaryrefslogtreecommitdiffstats
path: root/cpan2tgz
diff options
context:
space:
mode:
authorJason Woodward2004-11-16 05:47:06 +0000
committerJason Woodward2004-11-16 05:47:06 +0000
commitc2678b9bab2c7690ec3e9bb98f7bfc4d7b5ac200 (patch)
tree5fa52d1c24b459a90d47ef65ae906bbc2c8f6c46 /cpan2tgz
parent9b4a09e6bc2eba2822b567499e14fc1cae74c2c6 (diff)
downloadcpan2tgz-c2678b9bab2c7690ec3e9bb98f7bfc4d7b5ac200.tar.gz
initial import
Diffstat (limited to 'cpan2tgz')
-rwxr-xr-xcpan2tgz173
1 files changed, 173 insertions, 0 deletions
diff --git a/cpan2tgz b/cpan2tgz
new file mode 100755
index 0000000..7617773
--- /dev/null
+++ b/cpan2tgz
@@ -0,0 +1,173 @@
+#!/usr/bin/perl
+#
+# cpan2tgz create slackware packages from cpan distributions
+#
+# Jason Woodward
+# woodwardj at jaos dot org
+# http://software.jaos.org
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+use strict;
+use warnings;
+use CPAN;
+use Data::Dumper;
+use Getopt::Long;
+
+$ENV{PATH} = "/bin:/sbin:/usr/bin:/usr/sbin";
+my (%PACKAGE_CACHE_LIST,$recursive,$install_after_building);
+
+usage() unless
+ GetOptions(
+ "recursive" => \$recursive
+ );
+
+usage() unless (scalar(@ARGV) > 0);
+
+foreach my $mod (@ARGV){
+ do_package($mod);
+}
+
+sub do_package {
+ my ($module_name) = @_;
+ return unless $module_name;
+ my $module = CPAN::Shell->expand('Module',$module_name);
+ die "Failed to find $module_name: $!" unless $module;
+
+ $PACKAGE_CACHE_LIST{$module->id()} = 1;
+
+ my $pkg_name = "perl-" . lc((split('/',$module->cpan_file))[-1]);
+ my $final_pkg_version = (split('-',$pkg_name))[-1];
+ (my $final_pkg_name = $pkg_name) =~ s/\-$final_pkg_version//;
+ $pkg_name =~ s/\.tar.*?$//;
+ if( $module->xs_file() ){
+ $pkg_name .= "-i386";
+ }else{
+ $pkg_name .= "-noarch";
+ }
+ $pkg_name .= "-1.tgz";
+ $pkg_name = lc($pkg_name);
+
+ my $dest_dir = "/tmp/" . $module->id();
+
+ my $pack = $CPAN::META->instance('CPAN::Distribution',$module->cpan_file());
+ die "Failed to initialize CPAN::Distribution object for $module_name: $!" unless $pack;
+ eval { $pack->make() or die $!; };
+ if( $@ ){
+ print "make ERROR: $!\n";
+ exit(1);
+ }
+
+ if( scalar( keys %{$pack->prereq_pm()} ) > 0 ){
+ if($recursive){
+ foreach my $dep ( keys %{$pack->prereq_pm()} ){
+ next if defined $PACKAGE_CACHE_LIST{$dep};
+ print "FIXME: I don't deal with xsloader b/c make ?n/a?\n",next if $dep =~ m/xsloader/i;
+ do_package($dep);
+ }
+ }else{
+ print "\n\nStopping.\n[", $module->id(), "] requires ", join(", ", keys %{$pack->prereq_pm()}),"\n";
+ exit(1);
+ }
+ }
+
+ clear_build_dir($dest_dir);
+ system("cd " . $pack->dir() . " && chown -R root.root .");
+ system("cd " . $pack->dir() . " && find . -perm 777 -exec chmod 755 {} \\;");
+ system("cd " . $pack->dir() . " && find . -perm 555 -exec chmod 755 {} \\;");
+ system("cd " . $pack->dir() . " && find . -perm 444 -exec chmod 644 {} \\;");
+ system("cd " . $pack->dir() . " && find . -perm 666 -exec chmod 644 {} \\;");
+ system("cd " . $pack->dir() . " && find . -perm 664 -exec chmod 644 {} \\;");
+ system("cd " . $pack->dir() . " && make install DESTDIR=$dest_dir");
+ die "Failed to install to $dest_dir: $!" unless ( -d $dest_dir );
+ system("cd $dest_dir && mkdir -p ./usr/doc/$final_pkg_name-" . $module->cpan_version);
+ system("cd " . $pack->dir() . " && find . -iregex '.*readme.*' -o -iregex '.*change.*' -o -iregex '.*todo.*' -o -iregex '.*license.*' -o -iregex '.*copying.*' -o -iregex '.*install.*' -o -iregex '.*\.txt' -o -iregex '.*\.html' |xargs -r -iZ cp Z $dest_dir/usr/doc/$final_pkg_name-" . $module->cpan_version . "/");
+
+ open(my $script_fh,">$dest_dir/build.sh") or die "Failed to open build.sh for writing: $!";
+ print $script_fh "cd $dest_dir\n";
+ print $script_fh "find . | xargs file | grep \"executable\" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null\n";
+ print $script_fh "find . | xargs file | grep \"shared object\" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null\n";
+ print $script_fh "find ./usr/share/man/ -name \'*.3\' -exec gzip -9 {} \\;\n";
+ print $script_fh "find ./usr/share/man/ -name \'*.1\' -exec gzip -9 {} \\;\n";
+ print $script_fh "mv ./usr/share/man ./usr/\n" if( -d "$dest_dir/usr/share/man" );
+ print $script_fh "chown -R root.bin ./usr/bin\n" if( -d "$dest_dir/usr/bin" );
+ print $script_fh "chmod 755 ./usr/bin/*\n" if( -d "$dest_dir/usr/bin");
+ print $script_fh "chmod 644 ./usr/man/man?/*\n";
+ print $script_fh "rmdir ./usr/share\n";
+ print $script_fh "mkdir ./install\n";
+ close($script_fh);
+ system("cd $dest_dir && sh build.sh");
+ system("cd $dest_dir && rm build.sh");
+
+ if( scalar(keys %{$pack->prereq_pm()}) > 0 ){
+ open(my $required_fh,">$dest_dir/install/slack-required") or die "Failed to open slack-required for writing: $!";
+ my $deps = $pack->prereq_pm();
+ foreach my $perl_mod_dep ( keys %{$deps} ){
+ my $version = $deps->{$perl_mod_dep};
+ (my $pmd = $perl_mod_dep) =~ s/\:\:/\-/g;
+ if( int($version) > 0 ){
+ print $required_fh "$pmd >= $version\n";
+ }else{
+ print $required_fh "$pmd\n";
+ }
+ }
+ close($required_fh);
+ }
+
+ open(my $desc_fh,">$dest_dir/install/slack-desc") or die "Failed to open slack-desc for writing: $!";
+ print $desc_fh "\n";
+ print $desc_fh "# HOW TO EDIT THIS FILE:\n";
+ print $desc_fh "# The \"handy ruler\" below makes it easier to edit a package description. Line\n";
+ print $desc_fh "# up the first '|' above the ':' following the base package name, and the '|'\n";
+ print $desc_fh "# on the right side marks the last column you can put a character in. You must\n";
+ print $desc_fh "# make exactly 11 lines for the formatting to be correct. It's also\n";
+ print $desc_fh "# customary to leave one space after the ':'.\n";
+ print $desc_fh "\n";
+ print $desc_fh " |-----handy-ruler------------------------------------------------------|\n";
+ print $desc_fh "$final_pkg_name: $final_pkg_name " . $module->cpan_version() . " (perl module)\n";
+ print $desc_fh "$final_pkg_name: \n";
+ print $desc_fh "$final_pkg_name: Packaged by cpan2tgz\n";
+ print $desc_fh "$final_pkg_name: \n";
+ print $desc_fh "$final_pkg_name: cpan2tgz by Jason Woodward <woodwardj\@jaos.org>\n";
+ print $desc_fh "$final_pkg_name: \n";
+ print $desc_fh "$final_pkg_name: \n";
+ print $desc_fh "$final_pkg_name: \n";
+ print $desc_fh "$final_pkg_name: \n";
+ print $desc_fh "$final_pkg_name: http://software.jaos.org/\n";
+ print $desc_fh "$final_pkg_name: \n";
+ close($desc_fh);
+
+ system("cd $dest_dir && makepkg -l y -c n /usr/src/$pkg_name");
+ die "Failed to build package $pkg_name: $!" unless ( -f "/usr/src/$pkg_name" );
+
+ if( $recursive or $install_after_building ){
+ system("installpkg /usr/src/$pkg_name");
+ }
+
+ clear_build_dir($dest_dir);
+
+}
+
+sub usage {
+ print "Usage: $0 [options] [modules(s)]\n";
+ exit(1);
+}
+
+sub clear_build_dir {
+ my ($dest_dir) = @_;
+ return unless $dest_dir;
+ system("rm -r $dest_dir/*") if ( -d $dest_dir );
+ system("rmdir $dest_dir") if ( -d $dest_dir );
+}