From 50dd6eab6504e165b225ee0c1a73fa5fff2cbbc7 Mon Sep 17 00:00:00 2001
From: Fabian Affolter <fabian@affolter-engineering.ch>
Date: Mon, 27 Jun 2011 23:36:17 +0000
Subject: [PATCH] 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.
---
 newapkbuild.in | 106 ++++++++++++++++++++++++++++++++++---------------
 1 file changed, 74 insertions(+), 32 deletions(-)

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