Skip to content

Commit dc98de9

Browse files
committed
Add support for toxcore built with autotools.
autotools builds toxcore and toxav as separate libs. This adds support for both ways of having toxcore installed. Fixes #52.
1 parent 4e42ec7 commit dc98de9

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
FROM ubuntu:16.04
2-
1+
FROM ubuntu:18.04
2+
LABEL maintainer="[email protected]"
33

44
RUN apt-get update \
55
&& apt-get install --no-install-recommends -y ca-certificates cmake gcc g++ git libopus-dev libsodium-dev libvpx-dev pkg-config python-dev \
@@ -11,7 +11,7 @@ COPY pytox /build/pytox/
1111

1212
WORKDIR /build
1313
RUN git clone https://github.com/TokTok/c-toxcore /build/c-toxcore \
14-
&& cmake -B/build/c-toxcore/_build -H/build/c-toxcore -DBOOTSTRAP_DAEMON=OFF \
14+
&& cmake -B/build/c-toxcore/_build -H/build/c-toxcore -DBOOTSTRAP_DAEMON=OFF -DMUST_BUILD_TOXAV=ON \
1515
&& make -C/build/c-toxcore/_build install -j"$(nproc)" \
1616
&& python setup.py install \
1717
&& rm -r /build/*

pytox/util.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ void PyStringUnicode_AsStringAndSize(PyObject* object, const char** str,
6969
Py_ssize_t* len)
7070
{
7171
#if PY_MAJOR_VERSION < 3
72-
PyString_AsStringAndSize(object, str, len);
72+
char *mstr;
73+
PyString_AsStringAndSize(object, &mstr, len);
74+
*str = mstr;
7375
#else
7476
# if PY_MINOR_VERSION == 2
7577
*str = (char *)PyUnicode_AS_DATA(object);

setup.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import os
2+
import shlex
3+
import subprocess # nosec
24

35
from distutils.core import setup, Extension
46

5-
def supports_av():
6-
os.system("""
7-
echo 'extern int toxav_new(); int (*x)() = &toxav_new; int main(){}' \\
8-
| cc $LDFLAGS -xc - -ltoxcore \\
9-
> /dev/null 2>&1
10-
""")
7+
TOXAV_TEST_CODE = b"""
8+
extern int toxav_new();
9+
int (*x)() = &toxav_new;
10+
int main(){}
11+
"""
12+
13+
def supports_av(libs):
14+
ldflags = shlex.split(os.environ.get("LDFLAGS", ""))
15+
proc = subprocess.Popen( # nosec
16+
["cc", "-xc", "-"] + ldflags + libs,
17+
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
18+
# Wait for process to terminate; ignore stdout/stderr.
19+
proc.communicate(TOXAV_TEST_CODE)
20+
1121
if os.path.exists("a.out"):
1222
os.remove("a.out")
1323
return True
@@ -30,9 +40,13 @@ def supports_av():
3040
"-fno-strict-aliasing",
3141
]
3242

33-
if supports_av():
43+
if supports_av(["-ltoxcore"]):
44+
sources.append("pytox/av.c")
45+
cflags.append("-DENABLE_AV")
46+
elif supports_av(["-ltoxcore", "-ltoxav"]):
3447
sources.append("pytox/av.c")
3548
cflags.append("-DENABLE_AV")
49+
libraries.append("toxav")
3650
else:
3751
print("Warning: AV support not found, disabled.")
3852

0 commit comments

Comments
 (0)