Commit 85005964 authored by Jakub Jirutka's avatar Jakub Jirutka

testing/libcoro: new aport

http://software.schmorp.de/pkg/libcoro.html
Coroutines (cooperative multitasking) in a portable fashion implemented in C
parent c3fb7bc3
# 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"
/* 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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment