Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit d53f227

Browse files
author
Paulo Gomes
committed
Support execution outside container
Signed-off-by: Paulo Gomes <[email protected]>
1 parent e22c016 commit d53f227

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

hack/static.sh

+41-16
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,24 @@ LIBSSH2_URL="${LIBSSH2_URL:-https://github.com/libssh2/libssh2/archive/refs/tags
1010
# provide better performance (i.e. intel/cloudflare) or that are better maintained.
1111
LIBZ_URL="${LIBZ_URL:-https://github.com/madler/zlib/archive/refs/tags/v1.2.11.tar.gz}"
1212

13-
BUILD_ROOT_DIR="/build"
13+
TARGET_DIR="${TARGET_DIR:-/usr/local/$(xx-info triple)}"
14+
BUILD_ROOT_DIR="${BUILD_ROOT_DIR:-/build}"
1415
SRC_DIR="${BUILD_ROOT_DIR}/src"
1516

17+
18+
TARGET_ARCH="$(uname -m)"
19+
if command -v xx-info; then
20+
TARGET_ARCH="$(xx-info march)"
21+
fi
22+
23+
C_COMPILER="/usr/bin/gcc"
24+
CMAKE_PARAMS=""
25+
if command -v xx-clang; then
26+
C_COMPILER="/usr/bin/xx-clang"
27+
CMAKE_PARAMS="$(xx-clang --print-cmake-defines)"
28+
fi
29+
30+
1631
function download_source(){
1732
mkdir -p "$2"
1833

@@ -25,9 +40,12 @@ function build_libz(){
2540
download_source "${LIBZ_URL}" "${SRC_DIR}/libz"
2641
pushd "${SRC_DIR}/libz"
2742

28-
./configure --static \
29-
--archs="-arch $(xx-info march)" \
30-
--prefix="/usr/local/$(xx-info triple)"
43+
if [ "${TARGET_ARCH}" = "$(uname -m)" ]; then
44+
./configure --static --prefix="${TARGET_DIR}"
45+
else
46+
./configure --static --prefix="${TARGET_DIR}" \
47+
--archs="-arch ${TARGET_ARCH}"
48+
fi
3149

3250
make install
3351

@@ -38,17 +56,17 @@ function build_openssl(){
3856
download_source "${OPENSSL_URL}" "${SRC_DIR}/openssl"
3957
pushd "${SRC_DIR}/openssl"
4058

41-
target_name="$(xx-info march)"
59+
target_name="${TARGET_ARCH}"
4260
if [ "${target_name}" = "armv7l" ]; then
4361
# openssl does not have a specific armv7l
4462
# using generic32 instead.
4563
target_name=generic32
4664
fi
4765

4866
./Configure "linux-${target_name}" threads no-shared zlib -fPIC -DOPENSSL_PIC \
49-
--prefix="/usr/local/$(xx-info triple)" \
50-
--with-zlib-include="/usr/local/$(xx-info triple)/include" \
51-
--with-zlib-lib="/usr/local/$(xx-info triple)/lib" \
67+
--prefix="${TARGET_DIR}" \
68+
--with-zlib-include="${TARGET_DIR}/include" \
69+
--with-zlib-lib="${TARGET_DIR}/lib" \
5270
--openssldir=/etc/ssl
5371

5472
make
@@ -65,9 +83,9 @@ function build_libssh2(){
6583
mkdir -p build
6684
pushd build
6785

68-
cmake "$(xx-clang --print-cmake-defines)" \
69-
-DCMAKE_C_COMPILER="/usr/bin/xx-clang" \
70-
-DCMAKE_INSTALL_PREFIX="/usr/local/$(xx-info triple)" \
86+
cmake "${CMAKE_PARAMS}" \
87+
-DCMAKE_C_COMPILER="${C_COMPILER}" \
88+
-DCMAKE_INSTALL_PREFIX="${TARGET_DIR}" \
7189
-DBUILD_SHARED_LIBS=OFF \
7290
-DCMAKE_C_FLAGS=-fPIC \
7391
-DCRYPTO_BACKEND=OpenSSL \
@@ -90,9 +108,9 @@ function build_libgit2(){
90108

91109
pushd build
92110

93-
cmake "$(xx-clang --print-cmake-defines)" \
94-
-DCMAKE_C_COMPILER="/usr/bin/xx-clang" \
95-
-DCMAKE_INSTALL_PREFIX="/usr/local/$(xx-info triple)" \
111+
cmake "${CMAKE_PARAMS}" \
112+
-DCMAKE_C_COMPILER="${C_COMPILER}" \
113+
-DCMAKE_INSTALL_PREFIX="${TARGET_DIR}" \
96114
-DTHREADSAFE:BOOL=ON \
97115
-DBUILD_CLAR:BOOL:BOOL=OFF \
98116
-DBUILD_SHARED_LIBS=OFF \
@@ -104,8 +122,8 @@ function build_libgit2(){
104122
-DUSE_BUNDLED_ZLIB:BOOL=ON \
105123
-DUSE_HTTPS:STRING=OpenSSL \
106124
-DREGEX_BACKEND:STRING=builtin \
107-
-DCMAKE_INCLUDE_PATH="/usr/local/$(xx-info triple)/include" \
108-
-DCMAKE_LIBRARY_PATH="/usr/local/$(xx-info triple)/lib" \
125+
-DCMAKE_INCLUDE_PATH="${TARGET_DIR}/include" \
126+
-DCMAKE_LIBRARY_PATH="${TARGET_DIR}/lib" \
109127
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
110128
..
111129

@@ -115,4 +133,11 @@ function build_libgit2(){
115133
popd
116134
}
117135

136+
function all(){
137+
build_libz
138+
build_openssl
139+
build_libssh2
140+
build_libgit2
141+
}
142+
118143
"$@"

0 commit comments

Comments
 (0)