From 3bf7e2117fc91326f97284695b208fae781bb42a Mon Sep 17 00:00:00 2001
From: Ekaterina Vaartis <vaartis@cock.li>
Date: Thu, 2 May 2019 21:01:12 +0300
Subject: [PATCH] New package: Chipmunk2D-7.0.2

---
 common/shlibs                                 |  1 +
 srcpkgs/Chipmunk2D-devel                      |  1 +
 .../patches/backport-zero-division.patch      | 35 +++++++++++++++++++
 srcpkgs/Chipmunk2D/patches/musl-sysctl.patch  | 14 ++++++++
 srcpkgs/Chipmunk2D/template                   | 28 +++++++++++++++
 srcpkgs/Chipmunk2D/update                     |  1 +
 6 files changed, 80 insertions(+)
 create mode 120000 srcpkgs/Chipmunk2D-devel
 create mode 100644 srcpkgs/Chipmunk2D/patches/backport-zero-division.patch
 create mode 100644 srcpkgs/Chipmunk2D/patches/musl-sysctl.patch
 create mode 100644 srcpkgs/Chipmunk2D/template
 create mode 100644 srcpkgs/Chipmunk2D/update

diff --git a/common/shlibs b/common/shlibs
index 9857067a1ad..0da392eb775 100644
--- a/common/shlibs
+++ b/common/shlibs
@@ -3461,3 +3461,4 @@ libgrpc.so.7 grpc-1.19.1_1
 libgrpc_cronet.so.7 grpc-1.19.1_1
 libgrpc_unsecure.so.7 grpc-1.19.1_1
 libgrpcpp_channelz.so.1 grpc-1.19.1_1
+libchipmunk.so.7 Chipmunk2D-7.0.2_1
diff --git a/srcpkgs/Chipmunk2D-devel b/srcpkgs/Chipmunk2D-devel
new file mode 120000
index 00000000000..30953c01c83
--- /dev/null
+++ b/srcpkgs/Chipmunk2D-devel
@@ -0,0 +1 @@
+Chipmunk2D
\ No newline at end of file
diff --git a/srcpkgs/Chipmunk2D/patches/backport-zero-division.patch b/srcpkgs/Chipmunk2D/patches/backport-zero-division.patch
new file mode 100644
index 00000000000..8c95a2ac832
--- /dev/null
+++ b/srcpkgs/Chipmunk2D/patches/backport-zero-division.patch
@@ -0,0 +1,35 @@
+From 6a5767cc5a6c8f88f8cc689c0916ddc0111308fe Mon Sep 17 00:00:00 2001
+From: Bram Stolk <b.stolk@gmail.com>
+Date: Fri, 30 Mar 2018 19:21:26 -0700
+Subject: [PATCH] Fix issue #144 of division by zero when setting zero mass,
+ zero moment.
+
+---
+ src/cpBody.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git src/cpBody.c src/cpBody.c
+index a8e0797..8ad2bc9 100644
+--- src/cpBody.c
++++ src/cpBody.c
+@@ -258,7 +258,7 @@ cpBodySetMass(cpBody *body, cpFloat mass)
+ 	
+ 	cpBodyActivate(body);
+ 	body->m = mass;
+-	body->m_inv = 1.0f/mass;
++	body->m_inv = mass == 0.0f ? INFINITY : 1.0f/mass;
+ 	cpAssertSaneBody(body);
+ }
+ 
+@@ -275,7 +275,7 @@ cpBodySetMoment(cpBody *body, cpFloat moment)
+ 	
+ 	cpBodyActivate(body);
+ 	body->i = moment;
+-	body->i_inv = 1.0f/moment;
++	body->i_inv = moment == 0.0f ? INFINITY : 1.0f/moment;
+ 	cpAssertSaneBody(body);
+ }
+ 
+-- 
+2.21.0
+
diff --git a/srcpkgs/Chipmunk2D/patches/musl-sysctl.patch b/srcpkgs/Chipmunk2D/patches/musl-sysctl.patch
new file mode 100644
index 00000000000..7b154bc62a8
--- /dev/null
+++ b/srcpkgs/Chipmunk2D/patches/musl-sysctl.patch
@@ -0,0 +1,14 @@
+diff --git src/cpHastySpace.c src/cpHastySpace.c
+index 8dca425..e087df8 100644
+--- src/cpHastySpace.c
++++ src/cpHastySpace.c
+@@ -8,7 +8,9 @@
+ 
+ //#include <sys/param.h >
+ #ifndef _WIN32
++#ifdef __APPLE__
+ #include <sys/sysctl.h>
++#endif
+ #include <pthread.h>
+ #else
+ #ifndef WIN32_LEAN_AND_MEAN
diff --git a/srcpkgs/Chipmunk2D/template b/srcpkgs/Chipmunk2D/template
new file mode 100644
index 00000000000..142051ec0a4
--- /dev/null
+++ b/srcpkgs/Chipmunk2D/template
@@ -0,0 +1,28 @@
+# Template file for 'Chipmunk2D'
+pkgname=Chipmunk2D
+version=7.0.2
+revision=1
+wrksrc="Chipmunk2D-Chipmunk-${version}"
+build_style=cmake
+configure_args="-DBUILD_DEMOS=NO"
+short_desc="Fast and lightweight 2D game physics library"
+maintainer="Ekaterina Vaartis <vaartis@cock.li>"
+license="MIT"
+homepage="http://chipmunk-physics.net/"
+distfiles="https://github.com/slembcke/Chipmunk2D/archive/Chipmunk-${version}.tar.gz"
+checksum=6b6d8d5d910c4442fb9c8c4c46a178126d8c21d075cdb3ce439a7f8d8757b0ca
+
+post_install() {
+	vlicense LICENSE.txt
+}
+
+Chipmunk2D-devel_package() {
+	short_desc+=" - development files"
+	depends="${sourcepkg}>=${version}_${revision}"
+
+	pkg_install() {
+		vmove usr/include
+		vmove "usr/lib/*.a"
+		vmove "usr/lib/*.so"
+	}
+}
diff --git a/srcpkgs/Chipmunk2D/update b/srcpkgs/Chipmunk2D/update
new file mode 100644
index 00000000000..e75cea43752
--- /dev/null
+++ b/srcpkgs/Chipmunk2D/update
@@ -0,0 +1 @@
+pkgname=Chipmunk
