Source

sbbuilder-buildbot-patching / sbbuilder

#!/usr/bin/perl

##-{{{
=head1 NAME

sbbuilder - A Simple script to create SlackBuild files with directory structure

=head1 SYNOPSIS

sbbuilder --package=foo --version=42 [--user=Bill] [--build=1] ...


    Help Options:
	--package  Name of the package to build SlackBuild for.
	--version  Version of the package to build SlackBuild for.
	--link	   Direct link to the source tarball.
	--help     Show this scripts help information.
	--manual   Read this scripts manual.

=cut


=head1 OPTIONS

=over 8

=item B<--package=>string

Name of the package.

=item B<--version=>string

Version of the package.

=item B<--build=>string

Build number.

=item B<--user=>string

Author of the SlackBuild.

=item B<--ldoptions=>string

Extra ldoptions.

=item B<--type=>string

Type of SlackBuild.  There are 7 types of SlackBuilds :

I<normal> . Default configure; make and make install flags. 

I<perl> . Slackbuild for perl packages.

I<python> . Slackbuild for python packages.

I<noarch> . noarch package? This is for you. 

I<cmake> . Use cmake instead GNU autoconf.

I<waf> . Use waf instead GNU autoconf.

I<scons> . Use scons instead GNU autoconf.

=item B<--link=>string

Enter a download link if you know where you can find the source tarball.

If this option is set and nor package nor version are, sbbuilder will try to
guess them from the file. Alert: No success guaranteed, sbbuilder expects a
standard naming scheme.

Example: sbbuilder --link=http://foobar.com/foo-2.3.tar.gz [--user=Bill] [--build=1] ...


=item B<--configure_options=>string

Pass arguments to the configure script, in general quotes are required.

Example: sbbuilder --link=http://foobar.com/foo-2.3.tar.gz --configure_options="--without-x"

=item B<--add=>string

Add explicit package as dependency. Usually needed when a software has a non binary dependency.

Example: sbbuilder --link=http://foobar.com/foo-2.3.tar.gz --add="package_name >= 1.0-i586-1vl60"

=item B<--exclude=>string

Remove a package from the dependencies list.

Example: sbbuilder --link=http://foobar.com/foo-2.3.tar.gz --exclude="package_name >= 1.0-i586-1vl60"

=item B<--no-configure>

Do not include the execution of a configure script.

=item B<--xdesktop>

Include the generation of a Desktop Entry in the SlackBuild.

=item B<--help>
Show the brief help information.

=item B<--manual>
Read the manual, with examples.

=item B<--version>
Show the version number and exit.

=back

=cut

=head1 DESCRIPTION


  Sbbuilder is a perl script for generating SlackBuilds for the VectorLinux repository. 
  It was written for helping to build packages compliant with Vectorlinux repository standards 
  in a consistent way.
  

=cut


=head1 AUTHORS

kidd,  
rbistolfi

=cut

=head1 LICENSE

GNU General Public License
=cut
##-}}}

use strict;
use warnings;
use Template;
use Getopt::Long;
use Pod::Usage;

# main
my $user;
my $type;
my $package;
my $version;
my $link;
my $build = 1;
my $configure_options;
my $ldflags;
my $manual;
my $help;
my $add;
my $exclude;
my $noconfig;
my $xdesktop;

GetOptions( 
	"user=s"              => \$user,
	"type=s"	      => \$type,
	"package=s"           => \$package,
	"version=s"           => \$version,
	"link=s"              => \$link,
	"build=s"	      => \$build,
	"configure_options=s" => \$configure_options,
	"ldflags=s"           => \$ldflags,
	"manual"    	      => \$manual,
	"help"		      => \$help,
	"add=s"		      => \$add,
	"exclude=s"	      => \$exclude,
	"no-configure"        => \$noconfig,
	"xdesktop"	      => \$xdesktop);

my $message_text = "\nVectorLinux SlackBuild Builder.\n";
my $exit_status   = 1;         
my $verbose_level = 0;
$verbose_level=2 if $manual;

if (!$link and (!$package or !$version)) {
       	pod2usage ({ -message => $message_text ,
	     -exitval => $exit_status  ,  
	     -verbose => $verbose_level,
	     });
}

if ($link and !$package and !$version) {
	($package, $version) = $link =~ m{(?:ht|f)tp.*/(.+)-([^-]+)\.t(ar|gz)}i ;
}

chomp ($user = $user || $ENV{VL_PACKAGER} || `whoami`);
$link =~ s/$package/\$NAME/g if ($link) ;
$link =~ s/$version/\$VERSION/g if ($link);

# Get sbbuilder version
my $sbbversion;
my $ls;

open $ls, "ls /var/log/packages/sbbuilder*|";
while (<$ls>) {
	if (m/sbbuilder/) {
		($sbbversion) = m/sbbuilder-(.+)-.+-\d+vl\d+/ ;
	}
}
#---

my $tt = Template->new({
	INCLUDE_PATH => '/usr/share/sbb/template'});

my $file = 'main.template';
my $vars = {
       	user              => $user,
       	type              => $type,
       	'package'         => $package,
       	version           => $version,
       	'link'            => $link,
        build             => $build,
       	configure_options => $configure_options,
       	ldflags           => $ldflags,
	add		  => $add,
	exclude		  => $exclude,
	sbbversion        => $sbbversion,
	noconfig	  => $noconfig,
	xdesktop	  => $xdesktop,
	};

my $sbText;
$tt->process($file, $vars, \$sbText);
$sbText =~ s/^\s+|\s+$//g;

mkdir "$package" or warn "$!. Failed creating top dir.\n";
mkdir "$package/$version" or warn "$!. Failed creating version folder.\n";
mkdir "$package/$version/src" or warn "$!. Failed creating src folder.\n";
mkdir "$package/$version/src/patches" or warn "$!. Failed creating patches folder.\n";
chdir "$package/$version/src" or die $!;
open my $fh, "+>$package.SlackBuild" or die $!;
print $fh $sbText;
close $fh;
chmod(0777, "$package.SlackBuild") or warn "$!. Failed chmod on SlackBuild";

# vim: set tabstop=4 shiftwidth=4 foldmethod=marker : ##
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.