Skip to content

Commit e2274c5

Browse files
committed
build: osx: attempt to work with homebrew keg-only packages
1 parent ad2028f commit e2274c5

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ bench_sign_LDFLAGS = -static
6868
bench_inv_SOURCES = src/bench_inv.c
6969
bench_inv_LDADD = $(COMMON_LIB) $(SECP_LIBS)
7070
bench_inv_LDFLAGS = -static
71+
bench_inv_CPPFLAGS = $(SECP_INCLUDES)
7172
endif
7273

7374
if USE_TESTS
7475
noinst_PROGRAMS += tests
7576
tests_SOURCES = src/tests.c
76-
tests_CPPFLAGS = -DVERIFY $(SECP_TEST_INCLUDES)
77+
tests_CPPFLAGS = -DVERIFY $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
7778
tests_LDADD = $(COMMON_LIB) $(SECP_LIBS) $(SECP_TEST_LIBS)
7879
tests_LDFLAGS = -static
7980
TESTS = tests

build-aux/m4/bitcoin_secp.m4

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ fi
7878
dnl
7979
AC_DEFUN([SECP_GMP_CHECK],[
8080
if test x"$has_gmp" != x"yes"; then
81-
AC_CHECK_HEADER(gmp.h,[AC_CHECK_LIB(gmp, __gmpz_init,[has_gmp=yes; GMP_LIBS=-lgmp; AC_DEFINE(HAVE_LIBGMP,1,[Define this symbol if libgmp is installed])])])
81+
CPPFLAGS_TEMP="$CPPFLAGS"
82+
CPPFLAGS="$GMP_CPPFLAGS $CPPFLAGS"
83+
LIBS_TEMP="$LIBS"
84+
LIBS="$GMP_LIBS $LIBS"
85+
AC_CHECK_HEADER(gmp.h,[AC_CHECK_LIB(gmp, __gmpz_init,[has_gmp=yes; GMP_LIBS="$GMP_LIBS -lgmp"; AC_DEFINE(HAVE_LIBGMP,1,[Define this symbol if libgmp is installed])])])
86+
CPPFLAGS="$CPPFLAGS_TEMP"
87+
LIBS="$LIBS_TEMP"
8288
fi
8389
if test x"$set_field" = x"gmp" && test x"$has_gmp" != x"yes"; then
8490
AC_MSG_ERROR([$set_field field support explicitly requested but libgmp was not found])

configure.ac

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,35 @@ case $host in
3333
esac
3434

3535
case $host_os in
36-
darwin*)
37-
CPPFLAGS="$CPPFLAGS -I/opt/local/include"
38-
LDFLAGS="$LDFLAGS -L/opt/local/lib"
39-
;;
36+
*darwin*)
37+
if test x$cross_compiling != xyes; then
38+
AC_PATH_PROG([BREW],brew,)
39+
if test x$BREW != x; then
40+
dnl These Homebrew packages may be keg-only, meaning that they won't be found
41+
dnl in expected paths because they may conflict with system files. Ask
42+
dnl Homebrew where each one is located, then adjust paths accordingly.
43+
44+
openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
45+
gmp_prefix=`$BREW --prefix gmp 2>/dev/null`
46+
if test x$openssl_prefix != x; then
47+
PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
48+
export PKG_CONFIG_PATH
49+
fi
50+
if test x$gmp_prefix != x; then
51+
GMP_CPPFLAGS="-I$gmp_prefix/include"
52+
GMP_LIBS="-L$gmp_prefix/lib"
53+
fi
54+
else
55+
AC_PATH_PROG([PORT],port,)
56+
dnl if homebrew isn't installed and macports is, add the macports default paths
57+
dnl as a last resort.
58+
if test x$PORT != x; then
59+
CPPFLAGS="$CPPFLAGS -isystem /opt/local/include"
60+
LDFLAGS="$LDFLAGS -L/opt/local/lib"
61+
fi
62+
fi
63+
fi
64+
;;
4065
esac
4166

4267
CFLAGS="$CFLAGS -W"
@@ -236,6 +261,7 @@ fi
236261

237262
if test x"$set_field" = x"gmp" || test x"$set_bignum" = x"gmp"; then
238263
SECP_LIBS="$SECP_LIBS $GMP_LIBS"
264+
SECP_INCLUDES="$SECP_INCLUDES $GMP_CPPFLAGS"
239265
fi
240266

241267
if test x"$use_endomorphism" = x"yes"; then
@@ -256,4 +282,10 @@ AC_SUBST(YASM_BINFMT)
256282
AM_CONDITIONAL([USE_ASM], [test x"$set_field" == x"64bit_asm"])
257283
AM_CONDITIONAL([USE_TESTS], [test x"$use_tests" != x"no"])
258284
AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" != x"no"])
285+
286+
dnl make sure nothing new is exported so that we don't break the cache
287+
PKGCONFIG_PATH_TEMP="$PKG_CONFIG_PATH"
288+
unset PKG_CONFIG_PATH
289+
PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP"
290+
259291
AC_OUTPUT

0 commit comments

Comments
 (0)