cbang: cross compiling

This commit is contained in:
Đoàn Trần Công Danh 2020-05-17 23:23:22 +07:00 committed by Jürgen Buchmüller
parent 368a1e571d
commit 736ce9ffd8
6 changed files with 391 additions and 4 deletions

View file

@ -0,0 +1,52 @@
From 9e22c0114d010a35128aa67b0dc38cc23f4d873f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<congdanhqx@gmail.com>
Date: Sun, 17 May 2020 21:53:46 +0700
Subject: [PATCH 1/5] config/openssl: correct version check
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Current code requires all conditions meet to pass the check, thus,
return false negative for:
- 1.0.2 vs 1.1.0
- 1.1.0 vs 2.0.0
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
---
config/openssl/__init__.py | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git config/openssl/__init__.py config/openssl/__init__.py
index 421271cd..e0d3884a 100644
--- config/openssl/__init__.py
+++ config/openssl/__init__.py
@@ -6,15 +6,18 @@ def check_version(context, version):
context.Message("Checking for openssl version >= %s..." % version)
version = version.split('.')
- src = '#include <openssl/opensslv.h>\nint main() {\nreturn ('
- src += version[0] + '<= (OPENSSL_VERSION_NUMBER >> 28)'
+ src = '''
+ #include <openssl/opensslv.h>
+ int main() {
+ return (OPENSSL_VERSION_NUMBER >= '''
+ src += '(' + version[0] + ' >> 28)'
if 1 < len(version):
- src += ' && ' + version[1] + \
- '<= ((OPENSSL_VERSION_NUMBER >> 20) & 0xf)'
+ src += ' + (' + version[1] + ' >> 20)'
if 2 < len(version):
- src += ' && ' + version[2] + \
- '<= ((OPENSSL_VERSION_NUMBER >> 12) & 0xf)'
- src += ') ? 0 : 1;}\n'
+ src += ' + (' + version[2] + ' >> 12)'
+ src += ''') ? 0 : 1;
+ }
+ '''
ret = context.TryRun(src, '.cpp')[0]
--
2.26.2.672.g232c24e857

View file

@ -0,0 +1,47 @@
From a2d81dfceb153d6388dcff63d8be1140cad7a33e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<congdanhqx@gmail.com>
Date: Sun, 17 May 2020 22:26:09 +0700
Subject: [PATCH 2/5] config/openssl: check OPENSSL_VERSION in compile time
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
All of required information are available at compile time, use compile
time check to support cross compiling.
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
---
config/openssl/__init__.py | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git config/openssl/__init__.py config/openssl/__init__.py
index e0d3884a..580d72e7 100644
--- config/openssl/__init__.py
+++ config/openssl/__init__.py
@@ -9,17 +9,19 @@ def check_version(context, version):
src = '''
#include <openssl/opensslv.h>
int main() {
- return (OPENSSL_VERSION_NUMBER >= '''
+ int a[(OPENSSL_VERSION_NUMBER >= '''
src += '(' + version[0] + ' >> 28)'
if 1 < len(version):
src += ' + (' + version[1] + ' >> 20)'
if 2 < len(version):
src += ' + (' + version[2] + ' >> 12)'
- src += ''') ? 0 : 1;
+ src += ''')];
+ a[0] = 0;
+ return 0;
}
'''
- ret = context.TryRun(src, '.cpp')[0]
+ ret = context.TryCompile(src, '.cpp')
context.Result(ret)
return ret
--
2.26.2.672.g232c24e857

View file

@ -0,0 +1,119 @@
From df79b8912f92083e7ef51353e762fa1c67b2593b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<congdanhqx@gmail.com>
Date: Sun, 17 May 2020 22:44:25 +0700
Subject: [PATCH 3/5] libevent: use compile time sizeof check
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Taken from https://github.com/scons/scons/wiki/AutoconfRecipes#ac_check_sizeof
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
---
src/libevent/SConscript | 81 +++++++++++++++++++++++++++++++++++++----
1 file changed, 73 insertions(+), 8 deletions(-)
diff --git src/libevent/SConscript src/libevent/SConscript
index 89e770c1..2e8373f9 100644
--- src/libevent/SConscript
+++ src/libevent/SConscript
@@ -18,22 +18,87 @@ conf.AddTest('CheckSYS_TIMERFD_H', CheckSYS_TIMERFD_H)
# sizeof
+# https://github.com/scons/scons/wiki/AutoconfRecipes#ac_check_sizeof
+# Sensible default for common types on common platforms.
+_DEFAULTS_SIZEOF = {
+ 'short' : [2],
+ 'int' : [4, 2],
+ 'long' : [4, 8],
+ 'long long' : [8, 4],
+ 'unsigned short' : [2],
+ 'unsigned int' : [4, 2],
+ 'unsigned long' : [4, 8],
+ 'unsigned long long' : [8, 4],
+ 'float' : [4],
+ 'double' : [8],
+ 'long double' : [12],
+ 'size_t' : [4, 8],
+}
+
def CheckSizeOf(ctx, type, includes = None):
+ """This check can be used to get the size of a given type,
+ or to check whether the type is of expected size.
+
+ Arguments:
+ - type : str
+ the type to check
+ - includes : sequence
+ list of headers to include in the test code before testing the type
+ Returns:
+ status : int
+ 0 if the check failed, or the found size of the type
+ if the check succeeded."""
+ minsz = 0
+ maxsz = 16
+
src = '''
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
- int main() {printf("%d", (int)sizeof(''' + type + ''')); return 0;}
+ #include <stdint.h>
'''
+ if includes:
+ src += "\n".join("#include <%s>\n" % i for i in includes)
- if includes is not None:
- for inc in includes:
- src = '#include <%s>\n%s' % (inc, src)
+ ext = '.c'
+ # test code taken from autoconf: this is a pretty clever hack to find that
+ # a type is of a given size using only compilation. This speeds things up
+ # quite a bit compared to straightforward code using TryRun
+ src += r"""
+typedef %s scons_check_type;
- ctx.Message('Checking size of ' + type + '... ')
- ret = ctx.TryRun(src + '\n', '.c')
- ctx.Result(ret[0])
- return ret[1]
+int main()
+{
+ static int test_array[1 - 2 * ((long int) sizeof(scons_check_type) > %d)];
+ test_array[0] = 0;
+
+ return 0;
+}
+"""
+
+ # Only check if the given size is the right one
+ ctx.Message('Checking size of %s ... ' % type)
+
+ # Try sensible defaults first
+ try:
+ szrange = _DEFAULTS_SIZEOF[type]
+ except KeyError:
+ szrange = []
+ szrange.extend(range(minsz, maxsz))
+ st = 0
+
+ # Actual test
+ for sz in szrange:
+ st = ctx.TryCompile(src % (type, sz), ext)
+ if st:
+ break
+
+ if st:
+ ctx.Result('%d' % sz)
+ return sz
+ else:
+ ctx.Result('Failed !')
+ return 0
conf.AddTest('CheckSizeOf', CheckSizeOf)
--
2.26.2.672.g232c24e857

View file

@ -0,0 +1,73 @@
From b31932609b9019f7f72efdc3d67ea16971a34c76 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<congdanhqx@gmail.com>
Date: Sun, 17 May 2020 22:47:26 +0700
Subject: [PATCH 4/5] libevent: use TryCompile if applicable
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
---
src/libevent/SConscript | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git src/libevent/SConscript src/libevent/SConscript
index 2e8373f9..f9dceaa5 100644
--- src/libevent/SConscript
+++ src/libevent/SConscript
@@ -117,9 +117,9 @@ def CheckDecl(ctx, decl, includes = None):
src = '#include <%s>\n%s' % (inc, src)
ctx.Message('Checking for decl ' + decl + '... ')
- ret = ctx.TryRun(src + '\n', '.c')
- ctx.Result(ret[0])
- return ret[0]
+ ret = ctx.TryCompile(src + '\n', '.c')
+ ctx.Result(ret)
+ return ret
conf.AddTest('CheckDecl', CheckDecl)
@@ -133,9 +133,9 @@ def CheckStruct(ctx, struct, includes = None):
src = '#include <%s>\n%s' % (inc, src)
ctx.Message('Checking for struct ' + struct + '... ')
- ret = ctx.TryRun(src + '\n', '.c')
- ctx.Result(ret[0])
- return ret[0]
+ ret = ctx.TryCompile(src + '\n', '.c')
+ ctx.Result(ret)
+ return ret
conf.AddTest('CheckStruct', CheckStruct)
@@ -153,9 +153,9 @@ def CheckType(ctx, type, includes = None, defs = None):
src = '#define %s\n%s' % (d, src)
ctx.Message('Checking for type ' + type + '... ')
- ret = ctx.TryRun(src + '\n', '.c')
- ctx.Result(ret[0])
- return ret[0]
+ ret = ctx.TryCompile(src + '\n', '.c')
+ ctx.Result(ret)
+ return ret
conf.AddTest('CheckType', CheckType)
@@ -177,9 +177,9 @@ def CheckStructMember(ctx, struct, member, includes = None):
src = '#include <%s>\n%s' % (inc, src)
ctx.Message('Checking for %s in struct %s... ' % (member, struct))
- ret = ctx.TryRun(src + '\n', '.c')
- ctx.Result(ret[0])
- return ret[0]
+ ret = ctx.TryCompile(src + '\n', '.c')
+ ctx.Result(ret)
+ return ret
conf.AddTest('CheckStructMember', CheckStructMember)
--
2.26.2.672.g232c24e857

View file

@ -0,0 +1,90 @@
From 9239db8606320967e9e8526f68acd3e641c60ebb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<congdanhqx@gmail.com>
Date: Sun, 17 May 2020 22:56:41 +0700
Subject: [PATCH 5/5] libevent: use C++ to check for signature of
gethostbyname_r
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
C++ by definition requires matching prototype (both number of arguments,
order of arguments, and type of arguments) to be compilable.
Use this property to check for signature of gethostbyname_r(3) at
compile time in order to support cross compiling.
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
---
src/libevent/SConscript | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git src/libevent/SConscript src/libevent/SConscript
index f9dceaa5..be56e29a 100644
--- src/libevent/SConscript
+++ src/libevent/SConscript
@@ -184,6 +184,14 @@ def CheckStructMember(ctx, struct, member, includes = None):
conf.AddTest('CheckStructMember', CheckStructMember)
+def CheckCompileCxx(ctx, msg, src):
+ ctx.Message('Checking for %s... ' % msg)
+ ret = ctx.TryCompile(src + '\n', '.cpp')
+ ctx.Result(ret)
+ return ret
+
+conf.AddTest('CheckCompileCxx', CheckCompileCxx)
+
# General compile and run check
def CheckRun(ctx, msg, src):
ctx.Message('Checking for %s... ' % msg)
@@ -213,6 +221,9 @@ structs = 'addrinfo in6_addr sockaddr_in6 sockaddr_storage'
sizeof = ['int', 'long', 'long long', 'off_t', 'short', 'size_t', 'void *']
gethostbyname_r_3_arg_src = '''
+ #ifndef __cplusplus
+ #error must be compiled as cxx
+ #endif
#define _BSD_SOURCE
#include <netdb.h>
int main(int argc, char **argv) {
@@ -224,6 +235,9 @@ gethostbyname_r_3_arg_src = '''
'''
gethostbyname_r_5_arg_src = '''
+ #ifndef __cplusplus
+ #error must be compiled as cxx
+ #endif
#define _BSD_SOURCE
#include <netdb.h>
int main(int argc, char **argv) {
@@ -237,6 +251,9 @@ gethostbyname_r_5_arg_src = '''
'''
gethostbyname_r_6_arg_src = '''
+ #ifndef __cplusplus
+ #error must be compiled as cxx
+ #endif
#define _BSD_SOURCE
#include <netdb.h>
int main(int argc, char **argv) {
@@ -336,13 +353,13 @@ def get_event_config_defs():
if 'HAVE_EPOLL_CREATE' in defs: defs['HAVE_EPOLL'] = '1'
# gethostbyname_r
- if conf.CheckRun('3 arg gethostbyname_r()', gethostbyname_r_3_arg_src):
+ if conf.CheckCompileCxx('3 arg gethostbyname_r()', gethostbyname_r_3_arg_src):
defs['HAVE_GETHOSTBYNAME_R_3_ARG'] = '1'
- if conf.CheckRun('5 arg gethostbyname_r()', gethostbyname_r_5_arg_src):
+ if conf.CheckCompileCxx('5 arg gethostbyname_r()', gethostbyname_r_5_arg_src):
defs['HAVE_GETHOSTBYNAME_R_5_ARG'] = '1'
- if conf.CheckRun('6 arg gethostbyname_r()', gethostbyname_r_6_arg_src):
+ if conf.CheckCompileCxx('6 arg gethostbyname_r()', gethostbyname_r_6_arg_src):
defs['HAVE_GETHOSTBYNAME_R_6_ARG'] = '1'
--
2.26.2.672.g232c24e857

View file

@ -3,7 +3,7 @@ pkgname=cbang
version=1.4.0
revision=1
build_style=scons
make_build_args="prefix=/usr sharedlib=1 staticlib=1"
make_build_args="sharedlib=1 staticlib=1"
make_install_args="${make_build_args}"
hostmakedepends="pkg-config"
makedepends="boost-devel bzip2-devel expat-devel leveldb-devel libevent-devel
@ -14,10 +14,16 @@ license="LGPL-2.1-only"
homepage="https://github.com/CauldronDevelopmentLLC/cbang"
distfiles="https://github.com/CauldronDevelopmentLLC/cbang/archive/${version}.tar.gz>${pkgname}-${version}.tar.gz"
checksum=332a776ab026c30aa1666ad2482e1bf77fa5c41e3e2f7cde9ff2d98cfd3b4026
nocross="Cannot cross build with scons"
do_install() {
scons ${make_install_args} prefix=${DESTDIR}/usr install
pre_build() {
make_build_args+=" prefix=$DESTDIR/usr"
}
pre_install() {
make_install_args+=" prefix=$DESTDIR/usr"
}
post_install() {
# Create missing symbolic links for the shared library
ln -sf libcbang0.so.0.0.1 ${DESTDIR}/usr/lib/libcbang.so.0.0
ln -sf libcbang0.so.0.0.1 ${DESTDIR}/usr/lib/libcbang.so.0