summaryrefslogtreecommitdiff
path: root/pkgtools/url2pkg
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2006-10-02 16:49:30 +0000
committerrillig <rillig@pkgsrc.org>2006-10-02 16:49:30 +0000
commit19beef2685c4e62ca2ea96c54fb41a66480776f1 (patch)
tree17a49066f5163b4bb72029d9becce2d3ae8e58b7 /pkgtools/url2pkg
parent28dbf6e215b05a88dd639c1d2bc4629aa871c78c (diff)
downloadpkgsrc-19beef2685c4e62ca2ea96c54fb41a66480776f1.tar.gz
Took over maintainership from Hubert.
Rewrote url2pkg in Perl, enhancing it in several ways: - Packages for Perl modules using MakeMaker can be generated almost completely. The only thing that usually needs to be filled out after running url2pkg is the DESCR file. - USE_LANGUAGES is filled automatically. - After generating the initial Makefile, the editor is run to let the user edit the Makefile. These changes are preserved as much as possible. (This had not been the case before.) - Extending url2pkg has been made much easier by splitting the tasks that do the "magic" into small subroutines and by adding a detailed description of what these routines are supposed to do. Set the version number to 2.0.
Diffstat (limited to 'pkgtools/url2pkg')
-rw-r--r--pkgtools/url2pkg/DESCR12
-rw-r--r--pkgtools/url2pkg/Makefile37
-rw-r--r--pkgtools/url2pkg/PLIST5
-rw-r--r--pkgtools/url2pkg/files/MakeMaker.pm70
-rwxr-xr-xpkgtools/url2pkg/files/url2pkg244
-rw-r--r--pkgtools/url2pkg/files/url2pkg.86
-rw-r--r--pkgtools/url2pkg/files/url2pkg.pl431
7 files changed, 534 insertions, 271 deletions
diff --git a/pkgtools/url2pkg/DESCR b/pkgtools/url2pkg/DESCR
index 68c3939f3e9..c060cd4f35f 100644
--- a/pkgtools/url2pkg/DESCR
+++ b/pkgtools/url2pkg/DESCR
@@ -1,9 +1,3 @@
-Shellscript that will take an URL of a source .tar.gz (or other)
-file, and perform some steps to generate a package:
-
- - setup a basic Makefile
- - run "make fetch" and "make makesum"
- - generate a dummy pkg/PLIST
- - run "make extract"
- - try to find out the WRKSRC (if needed)
- - try to find out of this package uses GNU auto-configure
+The url2pkg program creates a new pkgsrc package from only the URL of a
+distribution file. It is intended to help pkgsrc developers create new
+packages quickly and easily.
diff --git a/pkgtools/url2pkg/Makefile b/pkgtools/url2pkg/Makefile
index 40d3ffe824f..0099f5b3400 100644
--- a/pkgtools/url2pkg/Makefile
+++ b/pkgtools/url2pkg/Makefile
@@ -1,31 +1,38 @@
-# $NetBSD: Makefile,v 1.43 2006/06/12 17:02:23 reed Exp $
+# $NetBSD: Makefile,v 1.44 2006/10/02 16:49:30 rillig Exp $
#
-DISTNAME= url2pkg-1.34
-CATEGORIES= pkgtools sysutils
-MASTER_SITES= # Nothing
-DISTFILES= # Nothing
+DISTNAME= url2pkg-2.0
+CATEGORIES= pkgtools
+MASTER_SITES= # none
+DISTFILES= # none
-MAINTAINER= hubertf@NetBSD.org
-HOMEPAGE= # Nothing
+MAINTAINER= rillig@NetBSD.org
+HOMEPAGE= http://www.NetBSD.org/Documentation/pkgsrc/creating.html
COMMENT= Tool to automate initial steps in building a package
PKG_INSTALLATION_TYPES= overwrite pkgviews
WRKSRC= ${WRKDIR}
-EXTRACT_ONLY= # empty
NO_CHECKSUM= yes
-NO_CONFIGURE= yes
-USE_LANGUAGES= # empty
+NO_BUILD= yes
+USE_LANGUAGES= # none
+USE_TOOLS+= perl:run
-INSTALLATION_DIRS= bin ${PKGMANDIR}/man8
+INSTALLATION_DIRS= bin ${PKGMANDIR}/man8 lib/url2pkg/ExtUtils
-do-build:
- ${SED} -e 's|@MAKE@|${MAKE}|g' \
- < ${FILESDIR}/url2pkg > ${WRKSRC}/url2pkg
+do-extract:
+ cp ${FILESDIR}/url2pkg.pl ${WRKSRC}/
+
+SUBST_CLASSES+= up
+SUBST_STAGE.up= do-configure
+SUBST_FILES.up= url2pkg.pl
+SUBST_SED.up= -e 's,@MAKE@,'${MAKE:Q}',g'
+SUBST_SED.up+= -e 's,@PERL@,${PERL5},g'
+SUBST_SED.up+= -e 's,@PERLLIBDIR@,${PREFIX}/lib/url2pkg,g'
do-install:
- ${INSTALL_SCRIPT} ${WRKSRC}/url2pkg ${PREFIX}/bin/url2pkg
+ ${INSTALL_SCRIPT} ${WRKSRC}/url2pkg.pl ${PREFIX}/bin/url2pkg
${INSTALL_MAN} ${FILESDIR}/url2pkg.8 ${PREFIX}/${PKGMANDIR}/man8
+ ${INSTALL_DATA} ${FILESDIR}/MakeMaker.pm ${PREFIX}/lib/url2pkg/ExtUtils/
.include "../../mk/bsd.pkg.mk"
diff --git a/pkgtools/url2pkg/PLIST b/pkgtools/url2pkg/PLIST
index ad838824b46..d1749367a14 100644
--- a/pkgtools/url2pkg/PLIST
+++ b/pkgtools/url2pkg/PLIST
@@ -1,3 +1,6 @@
-@comment $NetBSD: PLIST,v 1.1 2001/10/31 21:19:12 zuntum Exp $
+@comment $NetBSD: PLIST,v 1.2 2006/10/02 16:49:30 rillig Exp $
bin/url2pkg
+lib/url2pkg/ExtUtils/MakeMaker.pm
man/man8/url2pkg.8
+@dirrm lib/url2pkg/ExtUtils
+@dirrm lib/url2pkg
diff --git a/pkgtools/url2pkg/files/MakeMaker.pm b/pkgtools/url2pkg/files/MakeMaker.pm
new file mode 100644
index 00000000000..7889d50f25e
--- /dev/null
+++ b/pkgtools/url2pkg/files/MakeMaker.pm
@@ -0,0 +1,70 @@
+# -*-perl-*-
+
+# This is a drop-in replacement for the MakeMaker Perl module. Instead
+# of generating a Makefile, it extracts the dependency information for
+# other Perl modules. It is used to simplify the generation of pkgsrc
+# packages for Perl modules.
+
+package ExtUtils::MakeMaker;
+
+use strict;
+use warnings;
+
+BEGIN {
+ use Exporter;
+ use vars qw(@ISA @EXPORT);
+ @ISA = qw(Exporter);
+ @EXPORT = qw(WriteMakefile);
+}
+
+use constant pkgsrcdir => "../..";
+
+# Finds and returns the category a given package lies in.
+# If the package does not exist, C<undef> is returned.
+# If the package exists more than once, it is unspecified which
+# of the categories is returned.
+sub find_category($) {
+ my ($pkg) = @_;
+ my $retval;
+
+ opendir(D, pkgsrcdir) or die;
+ foreach my $cat (readdir(D)) {
+ next if ($cat =~ qr"^\.");
+
+ if (-d (sprintf("%s/%s/%s", pkgsrcdir, $cat, $pkg))) {
+ $retval = $cat;
+ }
+ }
+ closedir(D);
+ return $retval;
+}
+
+sub WriteMakefile(%) {
+ my (%options) = @_;
+
+ if (exists($options{"PREREQ_PM"})) {
+ my $deps = $options{"PREREQ_PM"};
+
+ foreach my $dep (sort(keys(%{$deps}))) {
+ my ($ver, $pkgbase, $category);
+
+ $ver = $deps->{$dep};
+ ($pkgbase = "p5-${dep}") =~ s/::/-/g;
+ $category = find_category($pkgbase);
+
+ if (defined($category)) {
+ printf("%s>=%s:../../%s/%s\n", $pkgbase, $ver, $category, $pkgbase);
+
+ } else {
+ # If the package does not exist but the
+ # Perl module can be loaded, assume that
+ # no extra dependency is needed. Otherwise fail.
+ if (!eval(sprintf("use %s %s; 1;", $dep, $ver))) {
+ die("$0: ERROR: No pkgsrc package found for dependency ${dep}>=${ver}.\n$@\n");
+ }
+ }
+ }
+ }
+}
+
+1;
diff --git a/pkgtools/url2pkg/files/url2pkg b/pkgtools/url2pkg/files/url2pkg
deleted file mode 100755
index d3c6686da55..00000000000
--- a/pkgtools/url2pkg/files/url2pkg
+++ /dev/null
@@ -1,244 +0,0 @@
-#!/bin/sh
-#
-# $NetBSD: url2pkg,v 1.38 2006/06/12 17:02:23 reed Exp $
-#
-# url2pkg
-# (c) 1999-2002 Hubert Feyrer <hubert@feyrer.de>
-#
-
-if [ "$MAKE" = "" ]; then
- MAKE=@MAKE@
-fi
-
-if [ "$PKGEDITOR" != "" ]; then
- editor="$PKGEDITOR"
-elif [ "$EDITOR" != "" ]; then
- editor="$EDITOR"
-else
- editor="vi"
-fi
-
-if [ "$PKGMAINTAINER" != "" ]; then
- email_maintainer="$PKGMAINTAINER"
-elif [ "$REPLYTO" != "" ]; then
- email_maintainer="$REPLYTO"
-else
- email_maintainer="INSERT_YOUR_MAIL_ADDRESS_HERE"
-fi
-
-if [ ! -f ../../mk/bsd.pkg.mk ]; then
- echo "Run this in .../pkgsrc/foo/bar !"
- exit 1
-fi
-
-if [ ! -f w*/.extract_done ]; then
- if [ "$1" = "" ]; then
- echo -n 'URL: '
- read url
- else
- url="$1"
- fi
-
- found=0
- for A in `cat ../../mk/fetch/sites.mk`; do
- if [ "`expr "$A" : ".*+="`" -gt 0 ]; then
- master_site="`echo $A|cut -f1 -d +`"
- fi
- if [ ! "${A}" = "\\" ]; then
- if [ `expr "$url" : "$A"` -gt 0 ]; then
- found=1
- DISTNAME=`expr "$url" : '.*/\([^/?]*\)'`
- name=`expr "$url" : "${A}\(.*\)/[^/]*\$"`
- MASTER_SITES="\${${master_site}:=${name}/}"
- case "${master_site}" in
- "MASTER_SITE_SOURCEFORGE")
- HOMEPAGE="http://$name.sourceforge.net/" ; ;;
- "MASTER_SITE_GNU")
- HOMEPAGE="http://www.gnu.org/software/$name/" ; ;;
- esac
- HOMEPAGE=`expr "$url" : '\(.*/\)[^/]*$'`
- break
- fi
- fi
- done
-
- if [ $found = 0 ]; then
- prdownloads="http://prdownloads.sourceforge.net/"
- if [ `expr "$url" : "$prdownloads.*"` -gt 0 ]; then
- DISTNAME=`expr "$url" : '.*/\([^/?]*\)'`
- sfname=`expr "$url" : "${prdownloads}\(.*\)/[^/]*\$"`
- MASTER_SITES='${MASTER_SITE_SOURCEFORGE:='"$sfname"'/}'
- HOMEPAGE="http://$sfname.sourceforge.net/"
- found=1
- fi
- fi
-
- if [ $found = 0 ]; then
- DISTNAME=`expr "$url" : '.*/\([^/]*\)$'`
- MASTER_SITES=`expr "$url" : '\(.*/\)[^/]*$'`
- HOMEPAGE=$MASTER_SITES
- fi
-
- case "$DISTNAME" in
- *.tgz) EXTRACT_SUFX=".tgz"
- DISTNAME=`expr ${DISTNAME} : '\(.*\)\.[^.]*'`
- ;;
- *.tar.Z) EXTRACT_SUFX=.tar.Z
- DISTNAME=`expr ${DISTNAME} : '\(.*\)\.[^.]*\.[^.]*'`
- ;;
- *.tar.gz) EXTRACT_SUFX=.tar.gz
- DISTNAME=`expr ${DISTNAME} : '\(.*\)\.[^.]*\.[^.]*'`
- ;;
- *.tar.bz2) EXTRACT_SUFX=.tar.bz2
- DISTNAME=`expr ${DISTNAME} : '\(.*\)\.[^.]*\.[^.]*'`
- ;;
- *) EXTRACT_SUFX=`expr ${DISTNAME} : '.*\(\.[^.]*\)'`
- DISTNAME=`expr ${DISTNAME} : '\(.*\)\.[^.]*'`
- ;;
- esac
-
- if [ -f Makefile ]; then
- mv Makefile Makefile.BAK
- fi
-
- category=`pwd | sed 's|^.*/\([^/]*\)/[^/]*$|\1|'`
- (
- echo '# $'NetBSD'$'
- echo '#'
- echo ""
- echo "DISTNAME= $DISTNAME"
- echo "CATEGORIES= $category"
- echo "MASTER_SITES= $MASTER_SITES"
- if [ "$EXTRACT_SUFX" != ".tar.gz" ]; then
- echo "EXTRACT_SUFX= ${EXTRACT_SUFX}"
- fi
- echo ""
- echo "MAINTAINER= $email_maintainer"
- echo "HOMEPAGE= $HOMEPAGE"
- echo "COMMENT= SHORT_DESCRIPTION_OF_THE_PACKAGE"
- echo ""
- echo '.include "../../mk/bsd.pkg.mk"'
- ) >Makefile
-
- echo '@comment $'NetBSD'$' > PLIST
- touch distinfo
-
- ${editor} +5 Makefile
-
- echo "Running 'make makesum' ..."
- $MAKE makesum
-
- echo "Running 'make extract' ..."
- $MAKE extract
-fi
-
-#
-# Exec Artificial Intelligence Modules here ...
-#
-wrksrc=`cd w* ; echo *`
-if [ "$wrksrc" != "$DISTNAME" ]; then
- WRKSRC="\${WRKDIR}/$wrksrc"
-fi
-
-wsrcdir=`echo w*`/$wrksrc
-configure=$wsrcdir/configure
-echo checking $configure XXX
-if [ -x $configure ]; then
- if $configure --version | egrep \
- 'configure generated by autoconf version|Free Software Foundation' \
- >/dev/null 2>&1 ; then
- GNU_CONFIGURE=yes
- else
- HAS_CONFIGURE=yes
- fi
-
- if find $wsrcdir -name \*.mo -o -name \*.gmo >/dev/null ; then
- USE_PKGLOCALEDIR=yes
- fi
-
- GCONF2_SCHEMAS=`find $wsrcdir -name \*.schemas -o -name \*.schemas.in* \
- | sed -e 's|^.*/||' -e 's/.in.in$//' -e 's/.in$//'`
-fi
-
-ltconfig=$wsrcdir/ltconfig
-ltmain=$wsrcdir/ltmain.sh
-libtool=\${WRKSRC}/libtool
-echo checking libtool: $ltconfig
-if [ -f $ltconfig -o -f $ltmain ]; then
- USE_LIBTOOL=yes
-fi
-
-PKGCONFIGS=`cd $wsrcdir && find * -name \*.pc.in -a ! -name \*-uninstalled.pc.in -type f`
-
-echo "Fixing up Makefile."
-(
- sed '/^.include/d' <Makefile
-
- if [ "${WRKSRC}" != "" ]; then
- echo "WRKSRC= $WRKSRC"
- fi
-
- if [ "${USE_PKGLOCALEDIR}" != "" ]; then
- echo "USE_PKGLOCALEDIR= $USE_PKGLOCALEDIR"
- fi
-
- if [ "${USE_LIBTOOL}" != "" ]; then
- echo "USE_LIBTOOL= $USE_LIBTOOL"
- fi
-
- if [ "${PKGCONFIGS}" != "" ]; then
- echo "USE_TOOLS+= pkg-config"
- fi
-
- if [ "${HAS_CONFIGURE}" != "" ]; then
- echo "HAS_CONFIGURE= $HAS_CONFIGURE"
- fi
- if [ "${GNU_CONFIGURE}" != "" ]; then
- echo "GNU_CONFIGURE= $GNU_CONFIGURE"
- fi
-
- echo
-
- for i in $PKGCONFIGS ; do
- echo "PKGCONFIG_OVERRIDE+= $i"
- done
-
- echo
-
- if [ -n "$GCONF2_SCHEMAS" ]; then
- echo 'CONFIGURE_ENV+= GCONF_SCHEMA_FILE_DIR="${PREFIX}/share/gconf/schemas/"'
- echo 'MAKE_ENV+= GCONF_SCHEMA_FILE_DIR="${PREFIX}/share/gconf/schemas/"'
-
- echo ""
-
- for i in $GCONF2_SCHEMAS ; do
- echo "GCONF2_SCHEMAS+= $i"
- done
-
- echo ""
- echo '.include "../../devel/GConf2/schemas.mk"'
- fi
-
- if [ -d $wsrcdir/libltdl ]; then
- echo '.include "../../devel/libltdl/convenience.mk"'
- fi
-
- echo '.include "../../mk/bsd.pkg.mk"'
-) >Makefile.$$
-mv Makefile.$$ Makefile
-
-echo ""
-echo "Contents of $wsrcdir:"
-ls -la $wsrcdir
-
-if [ ! -f DESCR ]; then
- touch DESCR
-fi
-
-# GNU Autoconf scripts will create this file... remove it.
-[ -f configure.lineno ] && rm configure.lineno
-
-echo ""
-echo "Remember to correct CATEGORIES, HOMEPAGE, COMMENT, and DESCR when you're done!"
-echo ""
-echo "Good luck! (See pkgsrc/doc/pkgsrc.txt for some more help :-)"
diff --git a/pkgtools/url2pkg/files/url2pkg.8 b/pkgtools/url2pkg/files/url2pkg.8
index 84987370466..dcdfc05453d 100644
--- a/pkgtools/url2pkg/files/url2pkg.8
+++ b/pkgtools/url2pkg/files/url2pkg.8
@@ -1,4 +1,4 @@
-.\" $NetBSD: url2pkg.8,v 1.7 2006/10/01 15:09:05 rillig Exp $
+.\" $NetBSD: url2pkg.8,v 1.8 2006/10/02 16:49:30 rillig Exp $
.\"
.\" Copyright (c) 2001 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -39,7 +39,7 @@
.Os
.Sh NAME
.Nm url2pkg
-.Nd Automatic NetBSD package generator
+.Nd Automatic pkgsrc package generator
.Sh SYNOPSIS
.Nm
.Op Ar URL
@@ -114,6 +114,8 @@ package for the software that can be found at
.Sh AUTHORS
.Nm
was written by
+.An Roland Illig Aq rillig@NetBSD.org ,
+enhancing the previous version by
.An Hubert Feyrer Aq hubertf@NetBSD.org .
.br
This man page was written by
diff --git a/pkgtools/url2pkg/files/url2pkg.pl b/pkgtools/url2pkg/files/url2pkg.pl
new file mode 100644
index 00000000000..8440b883bb3
--- /dev/null
+++ b/pkgtools/url2pkg/files/url2pkg.pl
@@ -0,0 +1,431 @@
+#! @PERL@
+# $NetBSD: url2pkg.pl,v 1.1 2006/10/02 16:49:30 rillig Exp $
+#
+
+use strict;
+use warnings;
+
+#
+# Build-time Configuration.
+#
+
+my $make = '@MAKE@';
+my $perllibdir = '@PERLLIBDIR@';
+
+use constant true => 1;
+use constant false => 0;
+
+#
+# Some helper subroutines.
+#
+
+sub run_editor($$) {
+ my ($fname, $lineno) = @_;
+
+ my $editor = $ENV{"PKGEDITOR"} || $ENV{"EDITOR"} || "vi";
+
+ system { $editor } ($editor, "+${lineno}", $fname);
+}
+
+sub get_maintainer() {
+
+ return $ENV{"PKGMAINTAINER"} || $ENV{"REPLYTO"} || "INSERT_YOUR_MAIL_ADDRESS_HERE";
+}
+
+sub print_section($$) {
+ my ($f, $vars) = @_;
+
+ if (scalar(@{$vars}) == 0) {
+ return;
+ }
+
+ my $width = 0;
+ foreach my $var (@{$vars}) {
+ my $len = length($var->[0]);
+ $width = ($len > $width) ? $len : $width;
+ }
+
+ foreach my $var (@{$vars}) {
+ my $len = length($var->[0]) + 1;
+ my $adjlen = (($width + 1 + 1) + 7) &-8;
+ my $ntabs = (7 + $adjlen - $len) / 8;
+ printf $f ("%s=%s%s\n", $var->[0], "\t" x $ntabs, $var->[1]);
+ }
+ printf $f ("\n");
+}
+
+#
+# Introduction to the magic_* subroutines.
+#
+# The following routines are called after the distfiles have been
+# downloaded and extracted. They may inspect the extracted files
+# to automatically define some variables in the package Makefile.
+#
+# The following variables may be used in the magic_* subroutines:
+# $distname contains the package name, including the version number.
+# $abs_wrkdir is an absolute pathname to the working directory, which
+# contains the extracted distfiles. $abs_wrksrc is the absolute pathname
+# to a subdirectory of $abs_wrkdir, in which you can usually find the
+# package-provided Makefiles or configure scripts.
+#
+# The following lists may be extended by the magic_* routines and
+# will later appear in the package Makefile: @depends and @build_depends
+# contain the dependencies of the package, in the form
+# "package>=version". @includes is a list of pathnames relative to the
+# package path. All these files will be included at the bottom of the
+# Makefile. @build_vars is a list of [varname, value] items that contain
+# variables that will be defined in the fourth paragraph of the package
+# Makefile, where the build configuration takes place. The @extra_vars
+# are similar to the @build_vars, but separated by an empty line in the
+# Makefile. The @todo items are inserted below the second paragraph in
+# the Makefile.
+#
+
+my ($distname, $abs_wrkdir, $abs_wrksrc);
+my (@depends, @build_depends, @includes, @build_vars, @extra_vars, @todo);
+my ($pkgname);
+
+#
+# And now to the real magic_* subroutines.
+#
+
+sub magic_configure() {
+ my $gnu_configure = false;
+
+ open(CONF, "<", "${abs_wrksrc}/configure") or return;
+ while (defined(my $line = <CONF>)) {
+ if ($line =~ qr"autoconf|Free Software Foundation"i) {
+ $gnu_configure = true;
+ last;
+ }
+ }
+ close(CONF);
+
+ my $varname = ($gnu_configure ? "GNU_CONFIGURE" : "HAS_CONFIGURE");
+ push(@build_vars, [$varname, "yes"]);
+}
+
+sub magic_gconf2_schemas() {
+ my $gconf2_files = `cd $abs_wrksrc && find * -type f -name "*.schemas" -o -name "*.schemas.in*" -print 2>/dev/null | sed -e 's|^.*/||' -e 's/.in.in\$//' -e 's/.in\$//'`;
+ if ($gconf2_files =~ qr"\S") {
+ push(@build_vars, ["CONFIGURE_ENV+", "GCONF_SCHEMA_FILE_DIR=\${PREFIX:Q}/share/gconf/schemas/"]);
+ push(@build_vars, ["MAKE_ENV+", "GCONF_SCHEMA_FILE_DIR=\${PREFIX:Q}/share/gconf/schemas/"]);
+ foreach my $f (split(qr"\s+", $gconf2_files)) {
+ push(@extra_vars, ["GCONF2_SCHEMAS+", $f]);
+ }
+ push(@includes, "../../devel/GConf2/schemas.mk");
+ }
+}
+
+sub magic_libtool() {
+ if (-f "${abs_wrksrc}/ltconfig" || -f "${abs_wrksrc}/ltmain.sh") {
+ push(@build_vars, ["USE_LIBTOOL", "yes"]);
+ }
+ if (-d "${abs_wrksrc}/libltdl") {
+ push(@includes, "../../devel/libltdl/convenience.mk");
+ }
+}
+
+sub magic_perlmod() {
+ if (-f "${abs_wrksrc}/Build.PL") {
+
+ # It's a Module::Build module. Dependencies cannot yet be
+ # extracted automatically.
+ push(@todo, "Look for the dependencies in Build.PL.");
+
+ push(@build_vars, ["PERL5_MODULE_TYPE", "Module::Build"]);
+
+ } elsif (-f "${abs_wrksrc}/Makefile.PL") {
+ open(DEPS, "cd ${abs_wrksrc} && perl -I${perllibdir} Makefile.PL |") or die;
+ while (defined(my $dep = <DEPS>)) {
+ chomp($dep);
+ push(@depends, $dep);
+ }
+ close(DEPS) or die;
+
+ } else {
+ return;
+ }
+
+ my $packlist = $distname;
+ $packlist =~ s/-[0-9].*//;
+ $packlist =~ s/-/\//g;
+ push(@build_vars, ["PERL5_PACKLIST", "auto/${packlist}/.packlist"]);
+ push(@includes, "../../lang/perl5/module.mk");
+ $pkgname = "p5-\${DISTNAME}";
+}
+
+sub magic_pkg_config() {
+ my $pkg_config_files = `cd $abs_wrksrc && find * -type f -name "*.pc.in" -a ! -name "*-uninstalled.pc.in" -print 2>/dev/null`;
+ if ($pkg_config_files =~ qr"\S") {
+ push(@build_vars, ["USE_TOOLS+", "pkg-config"]);
+ }
+ foreach my $f (split(qr"\s+", $pkg_config_files)) {
+ push(@extra_vars, ["PKGCONFIG_OVERRIDE+", $f]);
+ }
+}
+
+sub magic_po() {
+ if (`cd $abs_wrksrc && find * -type f -name "*.mo" -o -name "*.gmo" -print 2>/dev/null` =~ qr"\S") {
+ push(@build_vars, ["USE_PKGLOCALEDIR", "yes"]);
+ }
+}
+
+sub magic_use_languages() {
+ my $c_files = `cd $abs_wrksrc && find * -type f -name "*.c" -print 2>/dev/null`;
+ my $cxx_files = `cd $abs_wrksrc && find * -type f "(" -name "*.cpp" -o -name "*.cc" -o -name "*.C" ")" -print 2>/dev/null`;
+ my $f_files = `cd $abs_wrksrc && find * -type f -name "*.f" -print 2>/dev/null`;
+ my $languages = {};
+
+ $c_files =~ qr"\S" and $languages->{"c"} = true;
+ $cxx_files =~ qr"\S" and $languages->{"c++"} = true;
+ $f_files =~ qr"\S" and $languages->{"f"} = true;
+
+ my $use_languages = join(" ", sort(keys(%{$languages})));
+ if ($use_languages eq "") {
+ $use_languages = "# none";
+ }
+ if ($use_languages ne "c") {
+ push(@build_vars, ["USE_LANGUAGES", $use_languages]);
+ }
+}
+
+#
+# Subroutines for generating the initial package and adjusting it after
+# the distfiles have been extracted.
+#
+
+sub generate_initial_package($) {
+ my ($url) = @_;
+ my ($found, $master_site);
+ my ($master_sites, $distfile, $homepage, $dist_sufx, $category);
+
+ $found = false;
+ open(SITES, "<", "../../mk/fetch/sites.mk") or die;
+ while (defined(my $line = <SITES>)) {
+ chomp($line);
+
+ if ($line =~ qr"^(MASTER_SITE_.*)\+=") {
+ $master_site = $1;
+
+ } elsif ($line =~ qr"^\t(.*?)(?:\s+\\)$") {
+ my ($site) = ($1);
+
+ if (index($url, $site) == 0) {
+ $found = true;
+
+ if ($url =~ qr"^\Q${site}\E(.+)/([^/]+)$") {
+ my $subdir = $1;
+ $distfile = $2;
+
+ $master_sites = "\${${master_site}:=${subdir}/}";
+ if ($master_site eq "MASTER_SITE_SOURCEFORGE") {
+ $homepage = "http://${subdir}.sourceforge.net/";
+ } elsif ($master_site eq "MASTER_SITE_GNU") {
+ $homepage = "http://www.gnu.org/software/${subdir}/";
+ } else {
+ $homepage = substr($url, 0, -length($distfile));
+ }
+ } else {
+ $master_sites = "\${${master_site}}";
+ }
+ }
+ }
+ }
+
+ if (!$found) {
+ if ($url =~ qr"^http://prdownloads\.sourceforge\.net/([^/]*)/[^/]*\?download$") {
+ my $pkgbase = $1;
+ $distfile = $2;
+
+ $master_sites = "\${MASTER_SITE_SOURCEFORGE:=${pkgbase}/}";
+ $homepage = "http://${pkgbase}.sourceforge.net/";
+ $found = true;
+ }
+ }
+
+ if (!$found) {
+ if ($url =~ qr"^(.*/)(.*)$") {
+ ($master_sites, $distfile) = ($1, $2);
+ $homepage = $master_sites;
+ } else {
+ die("$0: ERROR: Invalid URL: ${url}\n");
+ }
+ }
+
+ if ($distfile =~ qr"^(.*)(\.tgz|\.tar\.Z|\.tar\.gz|\.tar\.bz2)$") {
+ ($distname, $dist_sufx) = ($1, $2);
+ } elsif ($distfile =~ qr"^(.*)(\.[^.]+)$") {
+ ($distname, $dist_sufx) = ($1, $2);
+ } else {
+ ($distname, $dist_sufx) = ($distfile, "# none");
+ }
+
+ # ignore errors.
+ rename("Makefile", "Makefile-url2pkg.bak");
+
+ `pwd` =~ qr".*/([^/]+)/[^/]+$" or die;
+ $category = $1;
+
+ open(MF, ">", "Makefile") or die;
+ print MF ("# \$NetBSD\$\n");
+ print MF ("#\n");
+ print MF ("\n");
+ print_section(*MF, [
+ ["DISTNAME", $distname],
+ ["CATEGORIES", $category],
+ ["MASTER_SITES", $master_sites],
+ ($dist_sufx ne ".tar.gz"
+ ? ["EXTRACT_SUFX", $dist_sufx]
+ : ())
+ ]);
+ print_section(*MF, [
+ ["MAINTAINER", get_maintainer()],
+ ["HOMEPAGE", $homepage],
+ ["COMMENT", "SHORT_DESCRIPTION_OF_THE_PACKAGE"]
+ ]);
+ print MF ("# url2pkg-marker (please do not remove this line.)\n");
+ print MF (".include \"../../mk/bsd.pkg.mk\"\n");
+ close(MF) or die;
+
+ open(PLIST, ">", "PLIST") or die;
+ print PLIST ("\@comment \$NetBSD\$\n");
+ close(PLIST) or die;
+
+ open(DI, ">", "distinfo") or die;
+ close(DI) or die;
+
+ open(DESCR, ">", "DESCR") or die;
+ close(DESCR) or die;
+
+ run_editor("Makefile", 5);
+
+ print ("url2pkg> Running \"make makesum\" ...\n");
+ (system { $make } ($make, "makesum")) == 0 or die;
+
+ print ("url2pkg> Running \"make extract\" ...\n");
+ (system { $make } ($make, "extract")) == 0 or die;
+}
+
+sub adjust_package_from_extracted_distfiles()
+{
+ my ($seen_marker);
+
+ chomp($abs_wrkdir = `${make} show-var VARNAME=WRKDIR`);
+
+ #
+ # Determine the value of WRKSRC.
+ #
+ my @files = ();
+ opendir(WRKDIR, $abs_wrkdir) or die;
+ while (defined(my $f = readdir(WRKDIR))) {
+ next if $f =~ qr"^\.";
+ push(@files, $f);
+ }
+ closedir(WRKDIR);
+ if (@files == 1) {
+ if ($files[0] ne $distname) {
+ push(@build_vars, ["WRKSRC", "\${WRKDIR}/$files[0]"]);
+ }
+ $abs_wrksrc = "${abs_wrkdir}/$files[0]";
+ } else {
+ push(@build_vars, ["WRKSRC", "\${WRKDIR}"]);
+ $abs_wrksrc = $abs_wrkdir;
+ }
+
+ magic_configure();
+ magic_gconf2_schemas();
+ magic_libtool();
+ magic_perlmod();
+ magic_pkg_config();
+ magic_po();
+ magic_use_languages();
+
+ print("url2pkg> Adjusting the Makefile.\n");
+
+ open(MF1, "<", "Makefile") or die;
+ open(MF2, ">", "Makefile-url2pkg.new") or die;
+
+ # Copy the user-edited part of the Makefile.
+ while (defined(my $line = <MF1>)) {
+ if ($line =~ qr"^# url2pkg-marker\b") {
+ $seen_marker = true;
+ last;
+ }
+ print MF2 ($line);
+
+ # Note: This is not elegant, but works.
+ if (defined($pkgname) && $line =~ qr"^DISTNAME=(\t+)") {
+ print MF2 ("PKGNAME=$1${pkgname}\n");
+ }
+ }
+
+ if (scalar(@todo) != 0) {
+ foreach my $todo (@todo) {
+ print MF2 ("# TODO: ${todo}\n");
+ }
+ print MF2 ("\n");
+ }
+
+ my @depend_vars;
+ foreach my $bd (@build_depends) {
+ push(@depend_vars, ["BUILD_DEPENDS+", $bd]);
+ }
+ foreach my $d (@depends) {
+ push(@depend_vars, ["DEPENDS+", $d]);
+ }
+ print_section(*MF2, \@depend_vars);
+
+ print_section(*MF2, \@build_vars);
+ print_section(*MF2, \@extra_vars);
+
+ foreach my $f (@includes) {
+ print MF2 (".include \"${f}\"\n");
+ }
+
+ # Copy the rest of the user-edited part of the Makefile.
+ while (defined(my $line = <MF1>)) {
+ print MF2 ($line);
+ }
+
+ close(MF1);
+ close(MF2) or die;
+ if ($seen_marker) {
+ rename("Makefile-url2pkg.new", "Makefile") or die;
+ } else {
+ unlink("Makefile-url2pkg.new");
+ die("$0: ERROR: didn't find the url2pkg marker in the file.\n");
+ }
+
+}
+
+sub main() {
+ my $url;
+
+ if (!-f "../../mk/bsd.pkg.mk") {
+ die("$0 must be run from a package directory (.../pkgsrc/category/package).");
+ }
+
+ my @extract_cookie = <w*/.extract_done>;
+ if (scalar(@extract_cookie) == 0) {
+ if (scalar(@ARGV) == 0) {
+ print("URL: ");
+ $url = <STDIN>;
+ } else {
+ $url = shift(@ARGV);
+ }
+
+ generate_initial_package($url);
+ } else {
+ chomp($distname = `${make} show-var VARNAME=DISTNAME`);
+ }
+
+ adjust_package_from_extracted_distfiles();
+
+ print("\n");
+ print("Remember to correct CATEGORIES, HOMEPAGE, COMMENT, and DESCR when you're done!\n");
+ print("\n");
+ print("Good luck! (See pkgsrc/doc/pkgsrc.txt for some more help :-)\n");
+}
+
+main();