[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: FreeBSD ports->NetBSD pkgsrc Makefile conversion
ksn@tkf.att.ne.jp wrote:
> FreeBSD ports の Makefile を機械的に NetBSD pkgsrc の Makefile に変換す
> ることって無理なんでしょうか。完全自動は無理でも、最低限押えておくべきツ
> ボのようなものってあると思うので、そういう部分だけでも自動変換してくれる
> ツールがあると便利かなあ、FreeBSD ports コレクションから何かかっぱらって
> くる時に少し楽かなあ、と思ったもので。
作ってみました。
sakamoto
--
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# port2pkg.pl
#
echo x - port2pkg.pl
sed 's/^X//' >port2pkg.pl << 'END-of-port2pkg.pl'
X#!/usr/bin/env perl
X#
X# port2pkg.pl
X# Copyright (c) 1999 Kazuki Sakamoto (sakamoto@netbsd.org)
X# $Id: port2pkg.pl,v 1.5 1999/06/07 04:28:58 sakamoto Exp $
X
X$maintainer = "packages\@netbsd.org";
X$makefile = "";
X$master_site_subdir = "";
X@man = ();
X@cat = ();
X
Xif ($#ARGV != 1) {
X print "port2pkg.pl portsdir pkgdir\n";
X exit;
X}
X$portsdir = shift;
X$pkgdir = shift;
X
Xif (! -d "$portsdir") {die "$portsdir: $!\n";}
Xif (! -d "$pkgdir") {
X if (mkdir($pkgdir, 0755) == 0) {
X die "$pkgdir: $!\n";
X }
X}
Xsystem("tar cCf $portsdir - .|tar xCf $pkgdir -");
X
X&read_Makefile();
X&conv_Makefile();
X&conv_PLIST();
X&add_NetBSD_ID();
X
Xsystem("(cd $pkgdir; pkglint)");
X
Xsub read_Makefile {
X open(PORTS, "$portsdir/Makefile")
X || die "$portsdir/Makefile: $!\n";
X while (<PORTS>) {
X if (/\\$/) {
X chop;
X chop;
X }
X $makefile .= $_;
X }
X close(PORTS);
X
X foreach my $line (split(/\n/, $makefile)) {
X $_ = $line;
X if (/^MASTER_SITE_SUBDIR\?*=\s*(.*)/) {
X $master_site_subdir = $1;
X }
X if (/^MAN(.)\?*=\s*(.*)/) {
X $man[$1] .= $2;
X }
X if (/^CAT(.)\?*=\s*(.*)/) {
X $cat[$1] .= $2;
X }
X }
X}
X
Xsub conv_Makefile {
X open(PORTS, "$portsdir/Makefile")
X || die "$portsdir/Makefile: $!\n";
X open(PKG, ">$pkgdir/Makefile")
X || die "$pkgdir/Makefile: $!\n";
X
X print PKG "# \$NetBSD\$\n";
X
X # header
X while (<PORTS>) {
X if (! /^\#/) {last;}
X
X if (/\$(Id: .*)/) {
X print PKG "\# FreeBSD $1\n";
X } else {
X print;
X }
X }
X print PKG;
X
X # body
X my ($nextline, $remove, $master_sites, $noportdocs);
X while (<PORTS>) {
X if (/\\$/) {
X $nextline++;
X if ($remove) {
X next;
X }
X } else {
X $nextline = 0;
X if ($remove) {
X $remove = 0;
X next;
X }
X }
X
X s|^\.include <bsd.port.mk>|.include \"../../mk/bsd.pkg.mk\"|;
X s|^FETCH_(DEPENDS)|BUILD_$1|;
X s|^LIB_(DEPENDS)|$1|;
X s|\$\{PORTSDIR\}|../..|g;
X
X if ($master_site_subdir ne "" &&
X ($master_sites || /^MASTER_SITES\?*=/)) {
X s|([^L][^O][^C][^A][^L])\}|$1:=$master_site_subdir}|g;
X
X if ($nextline) {
X $master_sites = 1;
X } else {
X $master_sites = 0;
X }
X }
X
X if (/(\/usr\/local)/ ||
X /(ldconfig)/i ||
X /(MASTERDIR)/ ||
X /(.*cat.*MESSAGE.*)/i) {
X print "WARN: found \"$1\"\n";
X }
X
X if (/^MAN(.)\?*=/ ||
X /^CAT(.)\?*=/ ||
X /^MASTER_SITE_SUBDIR/) {
X if ($nextline) {
X $remove = 1;
X }
X } elsif (/^(MAINTAINER\?*=)/) {
X print PKG "$1\t$maintainer\n";
X if ($nextline) {
X $remove = 1;
X }
X } elsif ($noportdocs || /^\.if.*NOPORTDOCS/) {
X if (/^\.if/) {
X $noportdocs++;
X if ($noportdocs > 2) {print PKG $_;}
X } elsif (/^\.endif/) {
X $noportdocs--;
X if ($noportdocs > 2) {print PKG $_;}
X } else {
X print PKG $_;
X }
X } else {
X print PKG $_;
X }
X }
X
X close(PORTS);
X close(PKG);
X}
X
Xsub add_manual {
X my ($FILE, $category) = @_;
X
X for (my $i = 1; $i <= 8; $i++) {
X if (!defined(eval "\$$category\[\$i\]")) {next;}
X foreach my $item (sort(split(/[ \t\n]+/,
X eval "\$$category\[\$i\]"))) {
X print $FILE "$category/$category$i/$item\n";
X }
X }
X}
X
Xsub conv_PLIST {
X my ($file);
X if (opendir(PKGDIR, "$portsdir/pkg") == 0) {die "$portsdir/pkg: $!\n";}
X while ($plist = readdir(PKGDIR)) {
X if (!($plist =~ /^PLIST/)) {next;}
X
X open(PORTS, "$portsdir/pkg/$plist")
X || die "$portsdir/pkg/$plist: $!\n";
X open(PKG, ">$pkgdir/pkg/$plist")
X || die "$pkgdir/pkg/$plist: $!\n";
X
X print PKG "\@comment \$NetBSD\$\n";
X my ($cat_added, $man_added);
X while (<PORTS>) {
X if (/^\@.*ldconfig/) {next;}
X if ($cat_added == 0 && /^[d-z]/) {
X &add_manual(PKG, "cat");
X $cat_added++;
X }
X if ($man_added == 0 && /^[n-z]/) {
X &add_manual(PKG, "man");
X $man_added++;
X }
X
X print PKG $_;
X }
X if ($cat_added == 0) {&add_manual(PKG, "cat");}
X if ($man_added == 0) {&add_manual(PKG, "man");}
X
X close(PKG);
X close(PORTS);
X }
X closedir(PKGDIR);
X}
X
Xsub add_NetBSD_ID {
X if (open(MD5, "$portsdir/files/md5")) {
X open(NMD5, ">$pkgdir/files/md5")
X || die "$pkgdir/files/md5: $!\n";
X print NMD5 "\$NetBSD\$\n\n";
X while (<MD5>) {
X print NMD5 $_;
X }
X close(NMD5);
X close(MD5);
X }
X
X if (opendir(PATCHDIR, "$portsdir/patches")) {
X while ($patch = readdir(PATCHDIR)) {
X if ($patch eq "\." || $patch eq "\.."
X || $patch eq "CVS") {next;}
X if (open(PATCH, "$portsdir/patches/$patch")) {
X open(NPATCH, ">$pkgdir/patches/$patch")
X || die "$pkgdir/patches/$patch: $!\n";
X print NPATCH "\$NetBSD\$\n\n";
X while (<PATCH>) {
X if (/FreeBSD/i) {
X print "WARN: $pkgdir/patches/" .
X "$patch includes \"$1\".\n";
X }
X print NPATCH $_;
X }
X close(NPATCH);
X close(PATCH);
X }
X }
X closedir(PATCHDIR);
X }
X}
END-of-port2pkg.pl
exit