freebsd-ports/Tools/scripts/mkptools/mkpskel
Neil Blakey-Milner 43a1c1abf7 Some minor additions so that we act a bit more like NetBSD's url2pkg; we
now autogenerate MASTER_SITES if we're given an URL.  Also check the
PKGMAINTAINER environment variable.

Submitted by:	Tomasz Luchowski <zuntum@eik.pl>
2001-02-02 15:00:42 +00:00

287 lines
6.6 KiB
Perl
Executable File

#!/usr/bin/perl -w
#
# Copyright (c) 2000 Neil Blakey-Milner
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# a script to gain a bit of knowledge about a supplied distfile
use strict;
use vars qw/ $opt_n /;
use File::Basename qw( basename dirname );
use Getopt::Std qw( getopts );
my ($filename, $ver, $initdir, $distdir, $wrkdir, $tmpdir);
my ($makefile, $wrksrc);
my (%cap);
chomp($initdir = `pwd`);
$cap{"MAINTAINER"} = ($ENV{"MAINTAINER"} || $ENV{"PKGMAINTAINER"} || "ports\@freebsd.org");
getopts('n');
&usage if $#ARGV != 0;
$filename = $ARGV[0];
if ($filename =~ m#^(f|ht)tp\://#) {
print `fetch $filename`;
$cap{"MASTER_SITES"} = dirname($filename) . '/';
$filename = basename($filename);
}
chdir(dirname($filename));
chomp($distdir = `pwd`);
chdir ($initdir);
&chk_extract; # .tar.gz vs .tgz vs .tar.bz2, &c.
&enh_distname;
if ($opt_n) {
print "filename is $filename\n";
print "PORTNAME is " . $cap{"PORTNAME"} . "\n";
print "PORTVERSION is " . $cap{"PORTVERSION"} . "\n";
exit;
}
&bareskel;
&md5;
&writemk;
exit;
sub bareskel {
$tmpdir = $cap{'PORTNAME'};
$tmpdir .= ".$$" while -e $tmpdir;
mkdir($tmpdir,0777);
`printf "\n" > $tmpdir/pkg-plist`;
`printf "\n" > $tmpdir/pkg-descr`;
`printf "A\n" > $tmpdir/pkg-comment`;
}
sub writemk {
my (%tmp);
my ($key);
my ($distname);
$distname = $cap{"PORTNAME"};
foreach $key (keys %cap) {
$tmp{$key} = $cap{$key};
}
open(MAKEFILE, ">$tmpdir/Makefile");
my ($date);
chomp($date = `date +"\%d \%b \%Y"`);
print MAKEFILE <<EOF;
# New ports collection makefile for: $distname
# Date created: $date
# Whom: makeport.pl
#
# \$FreeBSD\$
#
EOF
print MAKEFILE "PORTNAME= " . $tmp{"PORTNAME"} . "\n";
print MAKEFILE "PORTVERSION= " . $tmp{"PORTVERSION"} . "\n";
delete($tmp{"PORTNAME"});
delete($tmp{"PORTVERSION"});
print MAKEFILE "CATEGORIES= misc\n";
foreach $key (keys %tmp) {
my($tmp) = $tmp{$key};
if (($key eq "DISTNAME") || ($key eq "EXTRACT_SUFX")) {
print MAKEFILE "$key=\t$tmp\n";
delete($tmp{$key});
}
}
if ($tmp{"MASTER_SITES"}) {
print MAKEFILE "MASTER_SITES= ". $tmp{"MASTER_SITES"} . "\n\n";
delete($tmp{"MASTER_SITES"});
}
print MAKEFILE "\nMAINTAINER=\t" . $tmp{"MAINTAINER"} . "\n\n";
delete($tmp{"MAINTAINER"});
if ($tmp{"LIB_DEPENDS"}) {
print MAKEFILE "LIB_DEPENDS=". $tmp{"LIB_DEPENDS"} . "\n\n";
delete($tmp{"LIB_DEPENDS"});
}
#second group
foreach $key (keys %tmp) {
my($tmp) = $tmp{$key};
print MAKEFILE "$key=\t$tmp\n";
}
print MAKEFILE "# -- eos --\n\n";
print MAKEFILE ".include <bsd.port.mk>\n";
close (MAKEFILE);
}
sub md5 {
my $tmp = basename($filename);
chdir ($initdir);
`md5 $filename | perl -pe "s#$filename#$tmp#" > $tmpdir/distinfo`;
}
sub chk_extract {
my $tmp = basename($filename);
$tmp =~ s/(\.tgz)$// && do {
$cap{"DISTNAME"} = $tmp;
$cap{"EXTRACT_SUFX"} = $1;
return;
};
$tmp =~ s/(\.tar\.bz2)$// && do {
$cap{"DISTNAME"} = $tmp;
$cap{"EXTRACT_SUFX"} = $1 if ($1 ne ".tar.bz2");
$cap{"USE_BZIP2"} = "YES";
return;
};
$tmp =~ s/(\.tar)$// && do {
$cap{"DISTNAME"} = $tmp;
$cap{"EXTRACT_SUFX"} = $1;
return;
};
$tmp =~ s/(\.tar.*)$// && do {
$cap{"DISTNAME"} = $tmp;
$cap{"EXTRACT_SUFX"} = $1 if ($1 ne ".tar.gz");
return;
};
}
sub add_extsuffix {
return if $cap{"EXTRACT_SUFX"};
if ($cap{"USE_BZIP2"}) {
$cap{"EXTRACT_SUFX"} = ".tar.bz2";
} else {
$cap{"EXTRACT_SUFX"} = ".tar.gz";
}
}
sub enh_distname {
my($changes) = 0;
my($play) = $cap{"DISTNAME"};
#print "starting play...\n";
my($firstshot) = 0;
my($portname, $portversion);
if (defined($play) eq "") {
die "can't make heads or tails of $filename";
}
while ($changes == 0) {
$changes = 1;
$firstshot++;
$_ = $play;
#print "using $play\n";
/^(.*[0-9][a-z]?)([-._][a-z]*)$/i && do {
print "Door #1\n";
$cap{"DISTNAME"} = $1;
$play = $1;
&add_extsuffix;
$cap{"EXTRACT_SUFX"} = $2 . $cap{"EXTRACT_SUFX"};
$changes = 0;
next;
};
/^([a-z]*)([0-9]+)([-._])([0-9]+([-._]).*)$/i && do {
print "Door #2\n";
if ($5 eq $3) {
$play = "$1-$2.$4";
#$cap{"PORTNAME"} = $1;
#$cap{"PORTVERSION"} = "$2.$4";
$portname = $1;
$portversion = "$2.$4";
$changes = 0;
next;
}
};
/^(.*?[^-._])([0-9])([-._])([^v]?[0-9]*[a-z]*)([-._]?)(.*)$/i &&( $firstshot == 1) && do {
print "Door #4\n";
if (($5 eq $3) || ($5 eq "")) {
#$cap{"PORTNAME"} = $1;
#$cap{"PORTVERSION"} = "$2$3$4$5$6";
$portname = $1;
$portversion = "$2$3$4$5$6";
next;
}
};
/^(.*?)([-._])(v?)((?:[0-9][-._])*[0-9][a-z]?.*)$/i && do {
print "Door #3\n";
my($tmp);
$tmp = $1;
$ver = "$4";
if ($ver =~ /^(.*)([-._])([0-9]?)([a-z])[a-z]+([0-9]?)$/) {
print "Door #3.1\n";
my($foo) = "";
#print "1 - $1\n";
#print "2 - $2\n";
#print "3 - $3\n";
#print "4 - $4\n";
#print "5 - $5\n";
$foo = "." if $2;
#$ver = "$1$foo$3$4$5";
$ver = "$1$foo$3$4$5";
}
$portname = $tmp;
$portversion = $ver;
next;
};
}
if (defined($portversion) eq "") {
die "can't make heads or tails of $filename";
}
$portversion =~ s/_/./g;
$portversion =~ s/-/./g;
$cap{"PORTNAME"} = $portname;
$cap{"PORTVERSION"} = $portversion;
my ($temp1);
my ($temp2);
$temp1 = $cap{"DISTNAME"};
$temp2 = $cap{"PORTNAME"} . "-" . $cap{"PORTVERSION"};
if ($temp1 eq $temp2) {
delete($cap{"DISTNAME"});
}
}
sub usage {
print STDERR <<"EOF";
usage: $0 filename
generates a ports skeleton for port based on filename
EOF
exit;
}