Skip to content

Commit 2baf480

Browse files
authored
Merge pull request #1728 from cyrossignol/fix-depends
Fix Windows cross-compilation in newer environments
2 parents f1e130d + 8dd8363 commit 2baf480

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

configure.ac

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ AC_ARG_ENABLE([lcov],
157157
[enable lcov testing (default is no)])],
158158
[use_lcov=yes],
159159
[use_lcov=no])
160-
160+
161161
AC_ARG_ENABLE([lcov-branch-coverage],
162162
[AS_HELP_STRING([--enable-lcov-branch-coverage],
163163
[enable lcov testing branch coverage (default is no)])],
@@ -741,6 +741,22 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([
741741
]
742742
)
743743

744+
dnl check for gmtime_r(), fallback to gmtime_s() if that is unavailable
745+
dnl fail if neither are available.
746+
AC_MSG_CHECKING(for gmtime_r)
747+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ctime>]],
748+
[[ gmtime_r((const time_t *) nullptr, (struct tm *) nullptr); ]])],
749+
[ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_GMTIME_R, 1, [Define this symbol if gmtime_r is available]) ],
750+
[ AC_MSG_RESULT(no);
751+
AC_MSG_CHECKING(for gmtime_s);
752+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ctime>]],
753+
[[ gmtime_s((struct tm *) nullptr, (const time_t *) nullptr); ]])],
754+
[ AC_MSG_RESULT(yes)],
755+
[ AC_MSG_RESULT(no); AC_MSG_ERROR(Both gmtime_r and gmtime_s are unavailable) ]
756+
)
757+
]
758+
)
759+
744760
# Check for different ways of gathering OS randomness
745761
AC_MSG_CHECKING(for Linux getrandom syscall)
746762
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>
@@ -1228,7 +1244,7 @@ AC_SUBST(MINIUPNPC_CPPFLAGS)
12281244
AC_SUBST(MINIUPNPC_LIBS)
12291245
AC_SUBST(CRYPTO_LIBS)
12301246
AC_SUBST(SSL_LIBS)
1231-
AC_SUBST(CURL_LIBS)
1247+
AC_SUBST(CURL_LIBS)
12321248
AC_SUBST(LIBZIP_LIBS)
12331249
AC_SUBST(EVENT_LIBS)
12341250
AC_SUBST(EVENT_PTHREADS_LIBS)
@@ -1286,7 +1302,7 @@ case ${OS} in
12861302
;;
12871303
esac
12881304

1289-
echo
1305+
echo
12901306
echo "Options used to compile and link:"
12911307
echo " with wallet = $enable_wallet"
12921308
echo " with gui / qt = $bitcoin_enable_qt"
@@ -1300,7 +1316,7 @@ echo " with bench = $use_bench"
13001316
echo " with upnp = $use_upnp"
13011317
echo " debug enabled = $enable_debug"
13021318
echo " werror = $enable_werror"
1303-
echo
1319+
echo
13041320
echo " target os = $TARGET_OS"
13051321
echo " build os = $BUILD_OS"
13061322
echo
@@ -1312,4 +1328,4 @@ echo " CXXFLAGS = $CXXFLAGS"
13121328
echo " LDFLAGS = $LDFLAGS"
13131329
echo " AS = $CCAS"
13141330
echo " ASFLAGS = $CCASFLAGS"
1315-
echo
1331+
echo

depends/packages/bzip2.mk

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ define $(package)_config_cmds
2626
endef
2727

2828
define $(package)_build_cmds
29-
$($(package)_build_opts) $(MAKE) install PREFIX=local_build
29+
$($(package)_build_opts) $(MAKE) libbz2.a
3030
endef
3131

3232
define $(package)_stage_cmds
33-
cp -a local_build/. $($(package)_staging_dir)/$(host_prefix)
33+
mkdir $($(package)_staging_prefix_dir)/include && \
34+
cp -f bzlib.h $($(package)_staging_prefix_dir)/include && \
35+
mkdir $($(package)_staging_prefix_dir)/lib && \
36+
cp -f libbz2.a $($(package)_staging_prefix_dir)/lib
3437
endef
35-

depends/patches/bzip2/Makefile.patch

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
+++ Makefile 2019-10-28 13:31:36.918640240 -0400
33
@@ -15,10 +15,10 @@
44
SHELL=/bin/sh
5-
5+
66
# To assist in cross-compiling
77
-CC=gcc
88
-AR=ar
@@ -12,15 +12,6 @@
1212
+# AR=ar
1313
+# RANLIB=ranlib
1414
+# LDFLAGS=
15-
15+
1616
BIGFILES=-D_FILE_OFFSET_BITS=64
1717
CFLAGS=-Wall -Winline -O2 -g $(BIGFILES)
18-
@@ -35,7 +35,7 @@
19-
decompress.o \
20-
bzlib.o
21-
22-
-all: libbz2.a bzip2 bzip2recover test
23-
+all: libbz2.a bzip2 bzip2recover
24-
25-
bzip2: libbz2.a bzip2.o
26-
$(CC) $(CFLAGS) $(LDFLAGS) -o bzip2 bzip2.o -L. -lbz2

src/util/time.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,26 @@ void MilliSleep(int64_t n)
101101
std::string FormatISO8601DateTime(int64_t nTime) {
102102
struct tm ts;
103103
time_t time_val = nTime;
104-
#ifdef _MSC_VER
105-
gmtime_s(&ts, &time_val);
104+
#ifdef HAVE_GMTIME_R
105+
if (gmtime_r(&time_val, &ts) == nullptr) {
106106
#else
107-
gmtime_r(&time_val, &ts);
107+
if (gmtime_s(&ts, &time_val) != 0) {
108108
#endif
109+
return {};
110+
}
109111
return strprintf("%04i-%02i-%02iT%02i:%02i:%02iZ", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec);
110112
}
111113

112114
std::string FormatISO8601Date(int64_t nTime) {
113115
struct tm ts;
114116
time_t time_val = nTime;
115-
#ifdef _MSC_VER
116-
gmtime_s(&ts, &time_val);
117+
#ifdef HAVE_GMTIME_R
118+
if (gmtime_r(&time_val, &ts) == nullptr) {
117119
#else
118-
gmtime_r(&time_val, &ts);
120+
if (gmtime_s(&ts, &time_val) != 0) {
119121
#endif
122+
return {};
123+
}
120124
return strprintf("%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday);
121125
}
122126

0 commit comments

Comments
 (0)