2009-10-24 20:03:06 +00:00
|
|
|
#!/bin/sh
|
2011-06-27 23:36:17 +00:00
|
|
|
#
|
2013-07-05 04:21:13 +00:00
|
|
|
# newapkbuild - generate a new APKBUILD
|
2009-10-24 20:03:06 +00:00
|
|
|
# Copyright (c) 2009 Natanael Copa <natanael.copa@gmail.com>
|
|
|
|
#
|
|
|
|
# Distributed under GPL-2
|
|
|
|
#
|
|
|
|
|
2013-10-25 07:26:05 +00:00
|
|
|
program_version=@VERSION@
|
2009-10-24 20:03:06 +00:00
|
|
|
datadir=@datadir@
|
|
|
|
|
2013-07-05 04:21:16 +00:00
|
|
|
if ! [ -f "$datadir/functions.sh" ]; then
|
|
|
|
echo "$datadir/functions.sh: not found" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
. "$datadir/functions.sh"
|
2009-10-24 20:03:06 +00:00
|
|
|
|
|
|
|
|
2010-05-28 13:52:47 +00:00
|
|
|
is_url() {
|
|
|
|
case "$1" in
|
2013-02-15 12:36:31 +00:00
|
|
|
http://*|https://*|ftp://*) return 0;;
|
2010-05-28 13:52:47 +00:00
|
|
|
esac
|
2010-07-07 18:27:09 +00:00
|
|
|
return 1
|
2010-05-28 13:52:47 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 09:21:50 +00:00
|
|
|
is_github_url() {
|
|
|
|
case $1 in
|
|
|
|
https://github.com/*/*/archive/*.tar.gz) return 0;;
|
|
|
|
esac
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2011-06-27 23:36:17 +00:00
|
|
|
# Build sections
|
2011-06-28 07:18:15 +00:00
|
|
|
build_make() {
|
|
|
|
cat >>APKBUILD<<__EOF__
|
|
|
|
make || return 1
|
|
|
|
__EOF__
|
|
|
|
}
|
|
|
|
|
2011-06-28 07:11:02 +00:00
|
|
|
build_autotools() {
|
2011-03-17 10:47:12 +00:00
|
|
|
cat >>APKBUILD<<__EOF__
|
2013-08-01 12:32:27 +00:00
|
|
|
./configure \\
|
|
|
|
--build=\$CBUILD \\
|
|
|
|
--host=\$CHOST \\
|
|
|
|
--prefix=/usr \\
|
2011-03-17 10:47:12 +00:00
|
|
|
--sysconfdir=/etc \\
|
|
|
|
--mandir=/usr/share/man \\
|
|
|
|
--localstatedir=/var \\
|
|
|
|
|| return 1
|
2011-06-27 23:36:17 +00:00
|
|
|
make || return 1
|
2011-03-17 10:47:12 +00:00
|
|
|
__EOF__
|
|
|
|
}
|
|
|
|
|
2015-04-01 02:30:04 +00:00
|
|
|
build_cmake() {
|
|
|
|
# References:
|
|
|
|
# http://www.cmake.org/Wiki/CMake_Useful_Variables
|
|
|
|
# http://www.vtk.org/Wiki/CMake_Cross_Compiling
|
|
|
|
# This is incomplete: CMAKE_{HOST_,}SYSTEM_PROCESSOR needs to be set,
|
|
|
|
# and likewise CMAKE_FIND_ROOT_PATH and a few other details.
|
|
|
|
|
|
|
|
sed -i -e 's/^\(makedepends="\)/\1cmake /' APKBUILD
|
|
|
|
cat >>APKBUILD<<__EOF__
|
|
|
|
if [ "$CBUILD" != "$CHOST" ]
|
|
|
|
then
|
|
|
|
CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
|
|
|
|
fi
|
|
|
|
cmake \\
|
|
|
|
-DCMAKE_INSTALL_PREFIX=/usr \\
|
|
|
|
-DCMAKE_INSTALL_LIBDIR=lib \\
|
|
|
|
-DBUILD_SHARED_LIBS=True \\
|
|
|
|
-DCMAKE_BUILD_TYPE=Release \\
|
|
|
|
-DCMAKE_CXX_FLAGS="\$CXXFLAGS" \\
|
2015-10-30 08:50:23 +00:00
|
|
|
-DCMAKE_C_FLAGS="\$CFLAGS" \\
|
2015-04-01 02:30:04 +00:00
|
|
|
${CMAKE_CROSSOPTS} \\
|
|
|
|
|| return 1
|
|
|
|
make || return 1
|
|
|
|
__EOF__
|
|
|
|
}
|
|
|
|
|
2011-06-28 07:11:02 +00:00
|
|
|
build_perl() {
|
2011-03-17 10:47:12 +00:00
|
|
|
cat >>APKBUILD<<__EOF__
|
|
|
|
PERL_MM_USE_DEFAULT=1 perl Makefile.PL INSTALLDIRS=vendor || return 1
|
2011-06-27 23:36:17 +00:00
|
|
|
make || return 1
|
|
|
|
__EOF__
|
|
|
|
}
|
|
|
|
|
2011-06-28 07:11:02 +00:00
|
|
|
build_python() {
|
2011-06-27 23:36:17 +00:00
|
|
|
cat >>APKBUILD<<__EOF__
|
|
|
|
python setup.py build || return 1
|
2011-03-17 10:47:12 +00:00
|
|
|
__EOF__
|
|
|
|
}
|
|
|
|
|
2011-06-27 23:36:17 +00:00
|
|
|
# Package sections
|
2011-06-28 07:18:15 +00:00
|
|
|
package_make() {
|
2011-06-27 23:36:17 +00:00
|
|
|
cat >>APKBUILD<<__EOF__
|
|
|
|
make DESTDIR="\$pkgdir" install || return 1
|
|
|
|
__EOF__
|
|
|
|
}
|
|
|
|
|
2011-06-28 07:18:15 +00:00
|
|
|
package_autotools() {
|
|
|
|
package_make
|
|
|
|
}
|
|
|
|
|
2011-06-27 23:36:17 +00:00
|
|
|
package_perl() {
|
2011-03-17 10:47:12 +00:00
|
|
|
cat >>APKBUILD<<__EOF__
|
2011-06-27 23:36:17 +00:00
|
|
|
make DESTDIR="\$pkgdir" install || return 1
|
2011-03-17 10:47:12 +00:00
|
|
|
find "\$pkgdir" \\( -name perllocal.pod -o -name .packlist \\) -delete
|
|
|
|
__EOF__
|
|
|
|
}
|
|
|
|
|
2011-06-27 23:36:17 +00:00
|
|
|
package_python() {
|
|
|
|
cat >>APKBUILD<<__EOF__
|
|
|
|
python setup.py install --prefix=/usr --root="\$pkgdir" || return 1
|
|
|
|
__EOF__
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create new aport from templates
|
2009-10-24 20:03:06 +00:00
|
|
|
newaport() {
|
2010-05-28 13:52:47 +00:00
|
|
|
local newname="${1##*/}"
|
2009-10-24 20:03:06 +00:00
|
|
|
local pn=${newname%-[0-9]*}
|
|
|
|
local pv
|
2010-05-28 13:52:47 +00:00
|
|
|
local source=
|
|
|
|
is_url "$1" && source="$1"
|
|
|
|
|
2013-11-21 09:21:50 +00:00
|
|
|
if is_github_url $source; then
|
|
|
|
if [ -z "$pkgname" ]; then
|
|
|
|
pkgname=${source%/archive/*}
|
|
|
|
pkgname=${pkgname##*/}
|
|
|
|
fi
|
|
|
|
pv=${newname%.t*} #strip .tar.gz .tgz .tar.bz2 etc
|
|
|
|
pv=${pv#*[a-z]}
|
|
|
|
source="$pkgname-$pv.tar.gz::$source"
|
|
|
|
elif [ "$pn" != "$newname" ]; then
|
2009-10-24 20:03:06 +00:00
|
|
|
pv=${newname#$pn-}
|
2010-05-28 13:52:47 +00:00
|
|
|
pv=${pv%.t*} #strip .tar.gz .tgz .tar.bz2 etc
|
2009-10-24 20:03:06 +00:00
|
|
|
fi
|
2011-12-21 15:57:09 +00:00
|
|
|
if [ -z "$pkgname" ]; then
|
|
|
|
pkgname=$pn
|
|
|
|
fi
|
|
|
|
if [ -e "$pkgname"/APKBUILD ] && [ -z "$force" ]; then
|
|
|
|
error "$pkgname/APKBUILD already exist"
|
2009-10-24 20:03:06 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2011-12-21 15:57:09 +00:00
|
|
|
mkdir -p "$pkgname"
|
|
|
|
cd "$pkgname"
|
2011-01-03 13:41:33 +00:00
|
|
|
|
2011-03-17 10:20:57 +00:00
|
|
|
if [ -z "$source" ] && [ -n "$sourceforge" ]; then
|
|
|
|
source="http://downloads.sourceforge.net/$pn/$pn-$pv.tar.gz"
|
|
|
|
fi
|
|
|
|
|
2011-12-21 15:57:09 +00:00
|
|
|
if [ -z "$depends" ] &&[ "$buildtype" = "python" ]; then
|
2011-06-27 23:36:17 +00:00
|
|
|
depends="python"
|
|
|
|
fi
|
|
|
|
|
2011-12-21 15:57:09 +00:00
|
|
|
if [ -z "$makedepends" ] &&[ "$buildtype" = "python" ]; then
|
2011-06-27 23:36:17 +00:00
|
|
|
makedepends="python-dev"
|
|
|
|
else
|
|
|
|
makedepends="\$depends_dev"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Replace pkgver in $source
|
2010-05-28 13:52:47 +00:00
|
|
|
if [ -n "$source" ]; then
|
2010-06-16 14:00:34 +00:00
|
|
|
source=$(echo "$source" | sed "s/$pv/\$pkgver/g")
|
2010-05-28 13:52:47 +00:00
|
|
|
fi
|
2011-01-03 13:41:33 +00:00
|
|
|
|
2011-06-27 23:36:17 +00:00
|
|
|
# Copy init.d scripts if requested
|
2009-10-24 20:03:06 +00:00
|
|
|
if [ -n "$cpinitd" ]; then
|
2011-12-21 15:57:09 +00:00
|
|
|
cp "$datadir"/sample.initd $pkgname.initd
|
|
|
|
cp "$datadir"/sample.confd $pkgname.confd
|
|
|
|
cp "$datadir"/sample.pre-install $pkgname.pre-install
|
|
|
|
cp "$datadir"/sample.post-install $pkgname.post-install
|
2011-01-03 13:41:33 +00:00
|
|
|
install="\$pkgname.pre-install \$pkgname.post-install"
|
|
|
|
source="$source
|
2011-12-21 15:57:09 +00:00
|
|
|
$pkgname.initd
|
|
|
|
$pkgname.confd
|
2011-01-03 13:41:33 +00:00
|
|
|
"
|
|
|
|
fi
|
|
|
|
|
2011-06-27 23:36:17 +00:00
|
|
|
# Generate header with standard variables
|
2011-01-03 13:41:33 +00:00
|
|
|
cat >APKBUILD<<__EOF__
|
|
|
|
# Contributor:${PACKAGER:+" "}${PACKAGER}
|
|
|
|
# Maintainer:${MAINTAINER:+" "}${MAINTAINER}
|
2011-12-21 15:57:09 +00:00
|
|
|
pkgname=$pkgname
|
2011-01-03 13:41:33 +00:00
|
|
|
pkgver=$pv
|
|
|
|
pkgrel=0
|
|
|
|
pkgdesc="$pkgdesc"
|
|
|
|
url="$url"
|
|
|
|
arch="all"
|
|
|
|
license="$license"
|
2011-06-27 23:36:17 +00:00
|
|
|
depends="$depends"
|
|
|
|
depends_dev=""
|
|
|
|
makedepends="$makedepends"
|
2011-01-03 13:41:33 +00:00
|
|
|
install="$install"
|
|
|
|
subpackages="\$pkgname-dev \$pkgname-doc"
|
|
|
|
source="$source"
|
|
|
|
|
|
|
|
__EOF__
|
|
|
|
|
|
|
|
abuild -f fetch unpack
|
2011-06-27 23:36:17 +00:00
|
|
|
# Figure out the _builddir
|
2011-01-03 13:41:33 +00:00
|
|
|
for i in src/*; do
|
|
|
|
if [ -d "$i" ]; then
|
|
|
|
sdir=$i
|
|
|
|
_builddir=$(echo ${i#*/} | sed "s/$pv/\$pkgver/g")
|
|
|
|
_builddir="\"\$srcdir\"/$_builddir"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "_builddir=$_builddir" >> APKBUILD
|
|
|
|
|
2011-06-27 23:36:17 +00:00
|
|
|
# Check if its autotools
|
2011-03-17 10:47:12 +00:00
|
|
|
if [ -z "$buildtype" ]; then
|
|
|
|
if [ -x "$sdir"/configure ]; then
|
|
|
|
buildtype="autotools"
|
2011-03-17 10:51:07 +00:00
|
|
|
elif [ -r "$sdir"/Makefile.PL ] || [ "${pn#perl-}" != "$pn" ]; then
|
2011-03-17 10:47:12 +00:00
|
|
|
buildtype="perl"
|
|
|
|
elif [ -r "$sdir"/waf ]; then
|
|
|
|
buildtype="waf"
|
|
|
|
elif [ -d "$sdir"/cmake ]; then
|
|
|
|
buildtype="cmake"
|
|
|
|
elif [ -r "$sdir"/Makefile ]; then
|
|
|
|
buildtype="make"
|
2011-06-27 23:36:17 +00:00
|
|
|
elif [ -r "$sdir"/setup.py ]; then
|
|
|
|
buildtype="python"
|
2011-03-17 10:47:12 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2011-06-27 23:36:17 +00:00
|
|
|
# Create the prepare() template
|
2011-01-03 13:41:33 +00:00
|
|
|
cat >>APKBUILD<<__EOF__
|
|
|
|
prepare() {
|
|
|
|
local i
|
|
|
|
cd "\$_builddir"
|
|
|
|
for i in \$source; do
|
|
|
|
case \$i in
|
|
|
|
*.patch) msg \$i; patch -p1 -i "\$srcdir"/\$i || return 1;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
__EOF__
|
|
|
|
|
2011-06-27 23:36:17 +00:00
|
|
|
# Create build() function
|
2011-01-03 13:41:33 +00:00
|
|
|
cat >>APKBUILD<<__EOF__
|
|
|
|
build() {
|
|
|
|
cd "\$_builddir"
|
|
|
|
__EOF__
|
2011-03-17 10:47:12 +00:00
|
|
|
|
|
|
|
case "$buildtype" in
|
2011-06-28 07:18:15 +00:00
|
|
|
make)
|
|
|
|
build_make;;
|
2015-04-01 02:30:04 +00:00
|
|
|
cmake)
|
|
|
|
build_cmake;;
|
2011-03-17 10:47:12 +00:00
|
|
|
autotools)
|
2011-06-28 07:11:02 +00:00
|
|
|
build_autotools;;
|
2011-03-17 10:47:12 +00:00
|
|
|
perl)
|
2011-06-28 07:11:02 +00:00
|
|
|
build_perl;;
|
2011-06-27 23:36:17 +00:00
|
|
|
python)
|
2011-06-28 07:11:02 +00:00
|
|
|
build_python;;
|
2011-03-17 10:47:12 +00:00
|
|
|
esac
|
|
|
|
|
2011-01-03 13:41:33 +00:00
|
|
|
cat >>APKBUILD<<__EOF__
|
|
|
|
}
|
|
|
|
|
|
|
|
__EOF__
|
|
|
|
|
2011-06-27 23:36:17 +00:00
|
|
|
# Create package() function
|
2011-01-03 13:41:33 +00:00
|
|
|
cat >>APKBUILD<<__EOF__
|
|
|
|
package() {
|
2011-03-09 11:52:28 +00:00
|
|
|
cd "\$_builddir"
|
2011-01-03 13:41:33 +00:00
|
|
|
__EOF__
|
2011-03-17 10:47:12 +00:00
|
|
|
|
|
|
|
case "$buildtype" in
|
2011-06-28 07:18:15 +00:00
|
|
|
make)
|
|
|
|
package_make;;
|
2011-06-27 23:36:17 +00:00
|
|
|
autotools)
|
|
|
|
package_autotools;;
|
|
|
|
perl)
|
|
|
|
package_perl;;
|
|
|
|
python)
|
|
|
|
package_python;;
|
2011-03-17 10:47:12 +00:00
|
|
|
esac
|
|
|
|
|
2011-06-28 07:14:02 +00:00
|
|
|
if [ -n "$cpinitd" ]; then
|
|
|
|
cat >>APKBUILD<<__EOF__
|
|
|
|
|
|
|
|
install -m755 -D "\$srcdir"/\$pkgname.initd \\
|
|
|
|
"\$pkgdir"/etc/init.d/\$pkgname || return 1
|
|
|
|
install -m644 -D "\$srcdir"/\$pkgname.confd \\
|
|
|
|
"\$pkgdir"/etc/conf.d/\$pkgname || return 1
|
|
|
|
__EOF__
|
|
|
|
fi
|
2011-01-03 13:41:33 +00:00
|
|
|
cat >>APKBUILD<<__EOF__
|
|
|
|
}
|
|
|
|
|
|
|
|
__EOF__
|
2011-12-21 15:57:09 +00:00
|
|
|
abuild -f checksum
|
2009-10-24 20:03:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
2013-07-05 04:21:19 +00:00
|
|
|
cat >&2 <<__EOF__
|
2013-10-25 07:26:05 +00:00
|
|
|
$program $program_version - generate a new APKBUILD
|
2013-10-25 08:03:45 +00:00
|
|
|
Usage: $program [-cfh] [-d DESC] [-l LICENSE] [-n NAME] [-u URL]
|
|
|
|
PKGNAME[-PKGVER]|SRCURL
|
2013-07-05 04:21:19 +00:00
|
|
|
Options:
|
|
|
|
-n Set package name to NAME
|
|
|
|
-d Set package description (pkgdesc) to DESC
|
|
|
|
-l Set package license to LICENSE
|
|
|
|
-u Set package URL
|
|
|
|
-a Create autotools (use ./configure ...)
|
2015-04-01 02:30:04 +00:00
|
|
|
-C Create CMake pakckage (Assume cmake/ is there)
|
2013-07-05 04:21:19 +00:00
|
|
|
-p Create perl package (Assume Makefile.PL is there)
|
|
|
|
-y Create python package (Assume setup.py is there)
|
|
|
|
-s Use sourceforge source URL
|
|
|
|
-c Copy a sample init.d, conf.d, and install script to new directory
|
|
|
|
-f Force even if directory already exist
|
|
|
|
-h Show this help
|
|
|
|
|
|
|
|
__EOF__
|
2009-10-24 20:03:06 +00:00
|
|
|
}
|
|
|
|
|
2011-12-21 15:57:09 +00:00
|
|
|
while getopts "acd:fhl:n:pyu:s" opt; do
|
2009-10-24 20:03:06 +00:00
|
|
|
case $opt in
|
2011-03-17 10:47:12 +00:00
|
|
|
'a') buildtype="autotools";;
|
2009-10-24 20:03:06 +00:00
|
|
|
'c') cpinitd=1;;
|
2015-04-01 02:30:04 +00:00
|
|
|
'C') buildtype="cmake";;
|
2011-01-03 13:41:33 +00:00
|
|
|
'd') pkgdesc="$OPTARG";;
|
2009-10-24 20:03:06 +00:00
|
|
|
'f') force=1;;
|
2013-07-05 04:21:19 +00:00
|
|
|
'h') usage; exit;;
|
2011-01-03 13:41:33 +00:00
|
|
|
'l') license="$OPTARG";;
|
2011-12-21 15:57:09 +00:00
|
|
|
'n') pkgname="$OPTARG";;
|
2011-03-17 10:47:12 +00:00
|
|
|
'p') buildtype="perl";;
|
2011-06-28 07:21:36 +00:00
|
|
|
'y') buildtype="python";;
|
2011-01-03 13:41:33 +00:00
|
|
|
'u') url="$OPTARG";;
|
2011-03-17 10:20:57 +00:00
|
|
|
's') sourceforge=1;;
|
2009-10-24 20:03:06 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(( $OPTIND - 1 ))
|
|
|
|
|
2013-07-05 04:21:13 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
2009-10-24 20:03:06 +00:00
|
|
|
newaport $1 || exit 1
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|