aboutsummaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2017-07-15 15:31:57 +0200
committerJakub Jirutka <jakub@jirutka.cz>2017-07-15 15:32:30 +0200
commit85005964836fd5beda35e2dec8387c9ca4fdc5c9 (patch)
tree9bc6001b4cc772cfb40b27c1d377e46dbe1d3d56 /testing
parentc3fb7bc3bba604647d545afe621b131ef1f67a37 (diff)
downloadaports-85005964836fd5beda35e2dec8387c9ca4fdc5c9.tar.bz2
aports-85005964836fd5beda35e2dec8387c9ca4fdc5c9.tar.xz
testing/libcoro: new aport
http://software.schmorp.de/pkg/libcoro.html Coroutines (cooperative multitasking) in a portable fashion implemented in C
Diffstat (limited to 'testing')
-rw-r--r--testing/libcoro/APKBUILD83
-rw-r--r--testing/libcoro/test.c26
2 files changed, 109 insertions, 0 deletions
diff --git a/testing/libcoro/APKBUILD b/testing/libcoro/APKBUILD
new file mode 100644
index 0000000000..84cc77402d
--- /dev/null
+++ b/testing/libcoro/APKBUILD
@@ -0,0 +1,83 @@
+# Contributor: Jakub Jirutka <jakub@jirutka.cz>
+# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
+pkgname=libcoro
+pkgver=6.513
+pkgrel=0
+pkgdesc="Coroutines (cooperative multitasking) in a portable fashion implemented in C"
+url="http://software.schmorp.de/pkg/libcoro.html"
+arch="all"
+license="BSD-2"
+makedepends="cvs gzip musl-dev"
+subpackages="$pkgname-dev"
+source="http://dev.alpinelinux.org/archive/$pkgname/$pkgname-$pkgver.tar.gz
+ test.c"
+builddir="$srcdir/$pkgname-$pkgver"
+
+_cvsurl="cvs.schmorp.de/schmorpforge"
+_cvstag="rel-${pkgver/./_}"
+
+snapshot() {
+ local tarball="$pkgname-$pkgver.tar.gz"
+
+ mkdir -p "$srcdir"
+ cd "$srcdir"
+
+ msg "Creating $tarball"
+ cvs -z3 -d :pserver:anonymous@$_cvsurl export -r $_cvstag \
+ -d ${tarball%.tar.gz} $pkgname
+
+ # Create reproducible tarball (always same checksum for same content).
+ tar -c --owner=0 --group=0 --mtime='2017-07-15' ${tarball%.tar.gz} \
+ | gzip -n -9 > "$SRCDEST"/$tarball
+
+ msg "Uploading $tarball"
+ scp "$SRCDEST"/$tarball dev.alpinelinux.org:/archive/$pkgname/
+}
+
+prepare() {
+ default_prepare
+ ln -s "$srcdir"/test.c "$builddir"/
+}
+
+build() {
+ cd "$builddir"
+
+ CFLAGS="-fPIC -pedantic -Wall"
+ case "$CARCH" in
+ x86* | arm* | aarch64) CFLAGS="$CFLAGS -DCORO_ASM";;
+ *) CFLAGS="$CFLAGS -DCORO_SJLJ";;
+ esac
+
+ # Build shared lib.
+ $CC $CFLAGS -O3 -c coro.c
+ $CC $LDFLAGS -shared -o libcoro.so coro.o
+
+ # Build static lib.
+ $CC $CFLAGS -c coro.c -o coro.o
+ ar rc libcoro.a coro.o
+ ranlib libcoro.a
+
+ # Build test.
+ $CC $CFLAGS $LDFLAGS -L. test.c -o test -lcoro
+}
+
+check() {
+ cd "$builddir"
+ LD_LIBRARY_PATH=. ./test
+}
+
+package() {
+ cd "$builddir"
+
+ local abiver=$(sed -En 's/#define\s*CORO_VERSION\s*(\d+)/\1/p' coro.h)
+ local soname="libcoro.so.$abiver"
+
+ install -D -m 755 ${soname%.$abiver} "$pkgdir"/usr/lib/$soname
+ ln -s $soname "$pkgdir"/usr/lib/${soname%.$abiver}
+
+ install -D -m 644 libcoro.a "$pkgdir"/usr/lib/libcoro.a
+ install -D -m 644 coro.h "$pkgdir"/usr/include/coro.h
+}
+
+sha512sums="e4d0bb21333d4fe4f8afdcd8a8b7bb27a97bf30727e2425d9cb04d6b01934972d65c7f9d90fe30f83a933b6e863c8f85377b87945f6739d7bc409602c0d2fbac libcoro-6.513.tar.gz
+643cdbc3e4a9b48d05cd54b9cf436652abd41485def821cfaf682c5efc77c63c9aaff0b40dbaad17c87f9ef16f7b3739360c9d28fa15d61b620f0508fe5a7701 test.c"
diff --git a/testing/libcoro/test.c b/testing/libcoro/test.c
new file mode 100644
index 0000000000..7264837b56
--- /dev/null
+++ b/testing/libcoro/test.c
@@ -0,0 +1,26 @@
+/* Copied from https://github.com/ramonza/libcoro */
+#include <stdio.h>
+
+#include "coro.h"
+
+coro_context ctx, mainctx;
+struct coro_stack stack;
+
+void coro_body(void *arg) {
+ printf("OK\n");
+ coro_transfer(&ctx, &mainctx);
+ printf("Back in coro\n");
+ coro_transfer(&ctx, &mainctx);
+}
+
+int main(int argc, char **argv) {
+ coro_create(&mainctx, NULL, NULL, NULL, 0);
+ coro_stack_alloc(&stack, 0);
+ coro_create(&ctx, coro_body, NULL, stack.sptr, stack.ssze);
+ printf("Created a coro\n");
+ coro_transfer(&mainctx, &ctx);
+ printf("Back in main\n");
+ coro_transfer(&mainctx, &ctx);
+ printf("Back in main again\n");
+ return 0;
+}