Debian Codegraph @

configure

raw symbols SCIP
1 #!/bin/sh
2
3 # Initialise
4 PKG_CFLAGS=""
5 PKG_LIBS=""
6
7 # Helper function: detect cmake
8 detect_cmake() {
9 if which cmake > /dev/null 2>&1; then
10 return 0
11 fi
12 export PATH=$PATH:/Applications/CMake.app/Contents/bin
13 if which cmake > /dev/null 2>&1; then
14 return 0
15 fi
16 echo "Required 'cmake' not found"
17 exit 1
18 }
19
20 # Helper function: find library paths
21 # Usage: find_lib_paths <lib_name> <default_libs>
22 # Sets: LIB_CFLAGS, LIB_LIBS
23 find_lib_paths() {
24 lib_name=$1
25 default_libs=$2
26 LIB_CFLAGS=""
27 LIB_LIBS="$default_libs"
28
29 if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then
30 LIB_CFLAGS="-I$INCLUDE_DIR"
31 LIB_LIBS="-L$LIB_DIR $LIB_LIBS"
32 echo "Found INCLUDE_DIR $INCLUDE_DIR"
33 echo "Found LIB_DIR $LIB_DIR"
34 elif [ -d "/usr/local/include/$lib_name" ]; then
35 LIB_CFLAGS="-I/usr/local/include"
36 LIB_LIBS="-L/usr/local/lib $LIB_LIBS"
37 elif [ -d "/usr/include/$lib_name" ]; then
38 LIB_CFLAGS="-I/usr/include"
39 LIB_LIBS="-L/usr/lib $LIB_LIBS"
40 elif [ -d "/usr/local/opt/$lib_name" ]; then
41 LIB_CFLAGS="-I/usr/local/opt/$lib_name/include"
42 LIB_LIBS="-L/usr/local/opt/$lib_name/lib $LIB_LIBS"
43 fi
44 }
45
46 # Find compiler and export flags
47 CC=`"${R_HOME}/bin/R" CMD config CC`
48 CFLAGS=`"${R_HOME}/bin/R" CMD config CFLAGS`
49 LDFLAGS=`"${R_HOME}/bin/R" CMD config LDFLAGS`
50 export CC CFLAGS LDFLAGS
51
52 if [ -z "$MACOSX_DEPLOYMENT_TARGET" ]; then
53 MACOSX_DEPLOYMENT_TARGET=`echo $CC | sed -En 's/.*-version-min=([0-9][0-9.]*).*/\1/p'`
54 [ -n "$MACOSX_DEPLOYMENT_TARGET" ] && export MACOSX_DEPLOYMENT_TARGET
55 fi
56
57 # Detect -latomic linker flag for ARM architectures (Raspberry Pi etc.)
58 echo "#include <stdint.h>
59 uint64_t v;
60 int main() {
61 return (int)__atomic_load_n(&v, __ATOMIC_ACQUIRE);
62 }" | ${CC} -xc - -o /dev/null > /dev/null 2>&1
63 if [ $? -ne 0 ]; then
64 echo "Adding -latomic linker flag ..."
65 PKG_LIBS="$PKG_LIBS -latomic"
66 fi
67
68 # Determine whether to compile bundled libraries
69 compile_mbedtls=0
70 compile_nng=0
71
72 if [ -n "$NANONEXT_LIBS" ]; then
73 echo "NANONEXT_LIBS is set... building from source"
74 compile_mbedtls=1
75 compile_nng=1
76 else
77 # Find MbedTLS
78 find_lib_paths "mbedtls" "-lmbedtls -lmbedx509 -lmbedcrypto"
79 MBEDTLS_CFLAGS="$LIB_CFLAGS"
80 MBEDTLS_LIBS="$LIB_LIBS"
81
82 echo "#include <mbedtls/version.h>
83 int main() {
84 #if MBEDTLS_VERSION_MAJOR < 2 || MBEDTLS_VERSION_MAJOR == 2 && MBEDTLS_VERSION_MINOR < 5
85 *(void *) 0 = 0;
86 #endif
87 }" | ${CC} ${MBEDTLS_CFLAGS} -xc - -o /dev/null > /dev/null 2>&1
88 if [ $? -ne 0 ]; then
89 compile_mbedtls=1
90 else
91 echo "Found 'libmbedtls' $MBEDTLS_CFLAGS"
92 PKG_CFLAGS="$MBEDTLS_CFLAGS $PKG_CFLAGS"
93 PKG_LIBS="$MBEDTLS_LIBS $PKG_LIBS"
94 fi
95
96 # Find NNG
97 find_lib_paths "nng" "-lnng"
98 NNG_CFLAGS="$LIB_CFLAGS"
99 NNG_LIBS="$LIB_LIBS"
100
101 echo "#include <nng/nng.h>
102 int main() {
103 #if NNG_MAJOR_VERSION < 1 || NNG_MAJOR_VERSION == 1 && NNG_MINOR_VERSION < 11
104 *(void *) 0 = 0;
105 #endif
106 }" | ${CC} ${NNG_CFLAGS} -xc - -o /dev/null > /dev/null 2>&1
107 if [ $? -ne 0 ]; then
108 compile_nng=1
109 else
110 echo "Found 'libnng' $NNG_CFLAGS"
111 PKG_CFLAGS="$NNG_CFLAGS $PKG_CFLAGS"
112 PKG_LIBS="$NNG_LIBS $PKG_LIBS"
113 fi
114 fi
115
116 # Compile MbedTLS if needed
117 if [ $compile_mbedtls -eq 1 ]; then
118 echo "Existing 'libmbedtls' >= 2.5.0 not found"
119 detect_cmake
120 echo "Compiling 'libmbedtls' from source ..."
121 cmake -S src/mbedtls -B nano-build -DCMAKE_INSTALL_PREFIX=nano-install -DCMAKE_INSTALL_LIBDIR=lib
122 cmake --build nano-build --target install
123 rm -rf nano-build
124 fi
125
126 # Compile NNG if needed
127 if [ $compile_nng -eq 1 ]; then
128 echo "Existing 'libnng' >= 1.11.0 not found"
129 detect_cmake
130 echo "Compiling 'libnng' from source ..."
131 cmake -S src/nng -B nano-build -DCMAKE_INSTALL_PREFIX=nano-install -DCMAKE_INSTALL_LIBDIR=lib
132 cmake --build nano-build --target install
133 rm -rf nano-build
134 fi
135
136 # Set flags for bundled libraries
137 if [ -d "nano-install/lib" ]; then
138 PKG_CFLAGS="-I../nano-install/include -DNNG_STATIC_LIB $PKG_CFLAGS"
139 if [ -f "nano-install/lib/libmbedtls.a" ]; then
140 PKG_LIBS="../nano-install/lib/libnng.a ../nano-install/lib/libmbedtls.a ../nano-install/lib/libmbedx509.a ../nano-install/lib/libmbedcrypto.a $PKG_LIBS"
141 else
142 PKG_LIBS="../nano-install/lib/libnng.a $PKG_LIBS"
143 fi
144 fi
145
146 # Write to Makevars
147 sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars
148
149 # Success
150 exit 0