Added python as a new template

With -q ('-q' for the moment, please change that) a template
APKBUILD file for a python module is created. 'depends' and
'makedepends' are filled with standard values.
This commit is contained in:
Fabian Affolter 2011-06-27 23:36:17 +00:00 committed by Natanael Copa
parent 74cb9068f4
commit 50dd6eab65
1 changed files with 74 additions and 32 deletions

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
#
# script to generate a new APKBUILD # Script to generate a new APKBUILD
# Copyright (c) 2009 Natanael Copa <natanael.copa@gmail.com> # Copyright (c) 2009 Natanael Copa <natanael.copa@gmail.com>
# #
# Distributed under GPL-2 # Distributed under GPL-2
@ -14,7 +14,7 @@ datadir=@datadir@
prog=${0##*/} prog=${0##*/}
# source $PACKAGER # Source $PACKAGER
for i in $sysconfdir/abuild.conf $HOME/.abuild/abuild.conf; do for i in $sysconfdir/abuild.conf $HOME/.abuild/abuild.conf; do
if [ -f "$i" ]; then if [ -f "$i" ]; then
. $i . $i
@ -32,6 +32,7 @@ is_url() {
return 1 return 1
} }
# Build sections
config_autotools() { config_autotools() {
cat >>APKBUILD<<__EOF__ cat >>APKBUILD<<__EOF__
./configure --prefix=/usr \\ ./configure --prefix=/usr \\
@ -40,22 +41,54 @@ config_autotools() {
--infodir=/usr/share/info \\ --infodir=/usr/share/info \\
--localstatedir=/var \\ --localstatedir=/var \\
|| return 1 || return 1
make || return 1
__EOF__ __EOF__
} }
config_perl() { config_perl() {
cat >>APKBUILD<<__EOF__ cat >>APKBUILD<<__EOF__
PERL_MM_USE_DEFAULT=1 perl Makefile.PL INSTALLDIRS=vendor || return 1 PERL_MM_USE_DEFAULT=1 perl Makefile.PL INSTALLDIRS=vendor || return 1
make || return 1
__EOF__ __EOF__
} }
cleanup_perl() { config_python() {
cat >>APKBUILD<<__EOF__ cat >>APKBUILD<<__EOF__
python setup.py build || return 1
__EOF__
}
# Package sections
package_autotools() {
cat >>APKBUILD<<__EOF__
make DESTDIR="\$pkgdir" install || return 1
rm -f "\$pkgdir"/usr/lib/*.la
__EOF__
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
}
package_perl() {
cat >>APKBUILD<<__EOF__
make DESTDIR="\$pkgdir" install || return 1
find "\$pkgdir" \\( -name perllocal.pod -o -name .packlist \\) -delete find "\$pkgdir" \\( -name perllocal.pod -o -name .packlist \\) -delete
__EOF__ __EOF__
} }
# create new aport from templates package_python() {
cat >>APKBUILD<<__EOF__
python setup.py install --prefix=/usr --root="\$pkgdir" || return 1
__EOF__
}
# Create new aport from templates
newaport() { newaport() {
local newname="${1##*/}" local newname="${1##*/}"
local pn=${newname%-[0-9]*} local pn=${newname%-[0-9]*}
@ -78,12 +111,22 @@ newaport() {
source="http://downloads.sourceforge.net/$pn/$pn-$pv.tar.gz" source="http://downloads.sourceforge.net/$pn/$pn-$pv.tar.gz"
fi fi
# replace pkgver in $source if [ -z "$depends" ] &&[ "$buildtype" == "python" ]; then
depends="python"
fi
if [ -z "$makedepends" ] &&[ "$buildtype" == "python" ]; then
makedepends="python-dev"
else
makedepends="\$depends_dev"
fi
# Replace pkgver in $source
if [ -n "$source" ]; then if [ -n "$source" ]; then
source=$(echo "$source" | sed "s/$pv/\$pkgver/g") source=$(echo "$source" | sed "s/$pv/\$pkgver/g")
fi fi
# copy init.d scripts if requested # Copy init.d scripts if requested
if [ -n "$cpinitd" ]; then if [ -n "$cpinitd" ]; then
cp "$datadir"/sample.initd $pn.initd cp "$datadir"/sample.initd $pn.initd
cp "$datadir"/sample.confd $pn.confd cp "$datadir"/sample.confd $pn.confd
@ -96,7 +139,7 @@ newaport() {
" "
fi fi
# generate header with standard variables # Generate header with standard variables
cat >APKBUILD<<__EOF__ cat >APKBUILD<<__EOF__
# Contributor:${PACKAGER:+" "}${PACKAGER} # Contributor:${PACKAGER:+" "}${PACKAGER}
# Maintainer:${MAINTAINER:+" "}${MAINTAINER} # Maintainer:${MAINTAINER:+" "}${MAINTAINER}
@ -107,9 +150,9 @@ pkgdesc="$pkgdesc"
url="$url" url="$url"
arch="all" arch="all"
license="$license" license="$license"
depends= depends="$depends"
depends_dev= depends_dev=""
makedepends="\$depends_dev" makedepends="$makedepends"
install="$install" install="$install"
subpackages="\$pkgname-dev \$pkgname-doc" subpackages="\$pkgname-dev \$pkgname-doc"
source="$source" source="$source"
@ -117,7 +160,7 @@ source="$source"
__EOF__ __EOF__
abuild -f fetch unpack abuild -f fetch unpack
# figure out the _builddir # Figure out the _builddir
for i in src/*; do for i in src/*; do
if [ -d "$i" ]; then if [ -d "$i" ]; then
sdir=$i sdir=$i
@ -127,7 +170,7 @@ __EOF__
done done
echo "_builddir=$_builddir" >> APKBUILD echo "_builddir=$_builddir" >> APKBUILD
# check if its autotools # Check if its autotools
if [ -z "$buildtype" ]; then if [ -z "$buildtype" ]; then
if [ -x "$sdir"/configure ]; then if [ -x "$sdir"/configure ]; then
buildtype="autotools" buildtype="autotools"
@ -139,11 +182,13 @@ __EOF__
buildtype="cmake" buildtype="cmake"
elif [ -r "$sdir"/Makefile ]; then elif [ -r "$sdir"/Makefile ]; then
buildtype="make" buildtype="make"
elif [ -r "$sdir"/setup.py ]; then
buildtype="python"
fi fi
fi fi
# create the prepare() template # Create the prepare() template
cat >>APKBUILD<<__EOF__ cat >>APKBUILD<<__EOF__
prepare() { prepare() {
local i local i
@ -157,7 +202,7 @@ prepare() {
__EOF__ __EOF__
# create build() # Create build() function
cat >>APKBUILD<<__EOF__ cat >>APKBUILD<<__EOF__
build() { build() {
cd "\$_builddir" cd "\$_builddir"
@ -168,33 +213,28 @@ __EOF__
config_autotools;; config_autotools;;
perl) perl)
config_perl;; config_perl;;
python)
config_python;;
esac esac
cat >>APKBUILD<<__EOF__ cat >>APKBUILD<<__EOF__
make || return 1
} }
__EOF__ __EOF__
# create package() function # Create package() function
cat >>APKBUILD<<__EOF__ cat >>APKBUILD<<__EOF__
package() { package() {
cd "\$_builddir" cd "\$_builddir"
make DESTDIR="\$pkgdir" install || return 1
rm -f "\$pkgdir"/usr/lib/*.la
__EOF__ __EOF__
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
case "$buildtype" in case "$buildtype" in
perl) cleanup_perl;; autotools)
package_autotools;;
perl)
package_perl;;
python)
package_python;;
esac esac
cat >>APKBUILD<<__EOF__ cat >>APKBUILD<<__EOF__
@ -208,19 +248,20 @@ usage() {
echo "usage: $prog [-cfh] [-d DESC] [-l LICENSE] [-u URL] PKGNAME[-PKGVER]" echo "usage: $prog [-cfh] [-d DESC] [-l LICENSE] [-u URL] PKGNAME[-PKGVER]"
echo "Options:" echo "Options:"
echo " -a Create autotools (use ./configure ...)" echo " -a Create autotools (use ./configure ...)"
echo " -c Copy a sample init.d, conf.d and install script to new directory" echo " -c Copy a sample init.d, conf.d, and install script to new directory"
echo " -d Set package description (pkgdesc) to DESC" echo " -d Set package description (pkgdesc) to DESC"
echo " -f Force even if directory already exist" echo " -f Force even if directory already exist"
echo " -h Show this help" echo " -h Show this help"
echo " -l Set package license to LICENSE" echo " -l Set package license to LICENSE"
echo " -p Create perl package (Assume Makefile.PL is there)" echo " -p Create perl package (Assume Makefile.PL is there)"
echo " -q Create python package (Assume setup.py is there)"
echo " -u Set package URL" echo " -u Set package URL"
echo " -s Use sourceforge source url" echo " -s Use sourceforge source URL"
echo "" echo ""
exit 0 exit 0
} }
while getopts "acd:fhl:pu:s" opt; do while getopts "acd:fhl:pqu:s" opt; do
case $opt in case $opt in
'a') buildtype="autotools";; 'a') buildtype="autotools";;
'c') cpinitd=1;; 'c') cpinitd=1;;
@ -229,6 +270,7 @@ while getopts "acd:fhl:pu:s" opt; do
'h') usage;; 'h') usage;;
'l') license="$OPTARG";; 'l') license="$OPTARG";;
'p') buildtype="perl";; 'p') buildtype="perl";;
'q') buildtype="python";;
'u') url="$OPTARG";; 'u') url="$OPTARG";;
's') sourceforge=1;; 's') sourceforge=1;;
esac esac