forked from curl/curl-for-win
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibssh2.sh
executable file
·144 lines (111 loc) · 3.98 KB
/
libssh2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/sh -ex
# Copyright 2014-present Viktor Szakats <https://vsz.me/>
# See LICENSE.md
export _NAM
export _VER
export _BAS
export _DST
_NAM="$(basename "$0")"
_NAM="$(echo "${_NAM}" | cut -f 1 -d '.')"
_VER="$1"
_cpu="$2"
(
cd "${_NAM}" || exit
# Detect host OS
case "$(uname)" in
*_NT*) os='win';;
Linux*) os='linux';;
Darwin*) os='mac';;
*BSD) os='bsd';;
esac
# Prepare build
find . -name '*.dll' -delete
find . -name '*.def' -delete
# Build
export ARCH="w${_cpu}"
export LIBSSH2_CFLAG_EXTRAS='-fno-ident -DHAVE_STRTOI64 -DLIBSSH2_DH_GEX_NEW=1 -DHAVE_DECL_SECUREZEROMEMORY=1'
[ "${_cpu}" = '32' ] && LIBSSH2_CFLAG_EXTRAS="${LIBSSH2_CFLAG_EXTRAS} -fno-asynchronous-unwind-tables"
export LIBSSH2_LDFLAG_EXTRAS='-static-libgcc -Wl,--nxcompat -Wl,--dynamicbase'
[ "${_cpu}" = '64' ] && LIBSSH2_LDFLAG_EXTRAS="${LIBSSH2_LDFLAG_EXTRAS} -Wl,--high-entropy-va -Wl,--image-base,0x152000000"
if [ "${_BRANCH#*master*}" = "${_BRANCH}" ]; then
LIBSSH2_LDFLAG_EXTRAS="${LIBSSH2_LDFLAG_EXTRAS} -Wl,-Map,libssh2.map"
fi
export ZLIB_PATH=../../zlib/pkg/usr/local
export WITH_ZLIB=1
export LINK_ZLIB_STATIC=1
[ -d ../openssl ] && export OPENSSL_PATH=../../openssl
if [ -n "${OPENSSL_PATH}" ]; then
# export LINK_OPENSSL_STATIC=yes; export OPENSSL_LIBS_STAT='crypto ssl'
export OPENSSL_LIBPATH="${OPENSSL_PATH}"
export OPENSSL_LIBS_DYN='crypto.dll ssl.dll'
else
export WITH_WINCNG=1
fi
if [ "${_cpu}" = '64' ]; then
export LIBSSH2_DLL_SUFFIX=-x64
fi
export LIBSSH2_DLL_A_SUFFIX=.dll
export CROSSPREFIX="${_CCPREFIX}"
if [ "${CC}" = 'mingw-clang' ]; then
export LIBSSH2_CC="clang${_CCSUFFIX}"
if [ "${os}" != 'win' ]; then
LIBSSH2_CFLAG_EXTRAS="-target ${_TRIPLET} --sysroot ${_SYSROOT} ${LIBSSH2_CFLAG_EXTRAS}"
[ "${os}" = 'linux' ] && LIBSSH2_LDFLAG_EXTRAS="-L$(find "/usr/lib/gcc/${_TRIPLET}" -name '*posix' | head -n 1) ${LIBSSH2_LDFLAG_EXTRAS}"
LIBSSH2_LDFLAG_EXTRAS="-target ${_TRIPLET} --sysroot ${_SYSROOT} ${LIBSSH2_LDFLAG_EXTRAS}"
fi
# LIBSSH2_CFLAG_EXTRAS="${LIBSSH2_CFLAG_EXTRAS} -Xclang -cfguard"
# LIBSSH2_LDFLAG_EXTRAS="${LIBSSH2_LDFLAG_EXTRAS} -Xlinker -guard:cf"
fi
(
cd win32 || exit
${_MAKE} -j 2 clean
${_MAKE} -j 2
)
# Make steps for determinism
readonly _ref='NEWS'
"${_CCPREFIX}strip" --preserve-dates --strip-debug --enable-deterministic-archives win32/*.a
../_peclean.py "${_ref}" win32/*.dll
../_sign.sh "${_ref}" win32/*.dll
touch -c -r "${_ref}" win32/*.dll
touch -c -r "${_ref}" win32/*.def
touch -c -r "${_ref}" win32/*.a
if [ "${_BRANCH#*master*}" = "${_BRANCH}" ]; then
touch -c -r "${_ref}" win32/*.map
fi
# Tests
"${_CCPREFIX}objdump" --all-headers win32/*.dll | grep -a -E -i "(file format|dll name)"
# Create package
_BAS="${_NAM}-${_VER}-win${_cpu}-mingw"
_DST="$(mktemp -d)/${_BAS}"
mkdir -p "${_DST}/docs"
mkdir -p "${_DST}/include"
mkdir -p "${_DST}/lib"
mkdir -p "${_DST}/bin"
(
set +x
for file in docs/*; do
if [ -f "${file}" ] && echo "${file}" | grep -q -a -v -F '.'; then
cp -f -p "${file}" "${_DST}/${file}.txt"
fi
done
)
cp -f -p include/*.h "${_DST}/include/"
cp -f -p win32/*.dll "${_DST}/bin/"
cp -f -p win32/*.def "${_DST}/bin/"
cp -f -p win32/*.a "${_DST}/lib/"
cp -f -p NEWS "${_DST}/NEWS.txt"
cp -f -p COPYING "${_DST}/COPYING.txt"
cp -f -p README "${_DST}/README.txt"
cp -f -p RELEASE-NOTES "${_DST}/RELEASE-NOTES.txt"
# OpenSSL 3.x
[ -d ../openssl ] && [ -f ../openssl/LICENSE.txt ] && cp -f -p ../openssl/LICENSE.txt "${_DST}/COPYING-openssl.txt"
# OpenSSL 1.x
[ -d ../openssl ] && [ -f ../openssl/LICENSE ] && cp -f -p ../openssl/LICENSE "${_DST}/COPYING-openssl.txt"
if [ "${_BRANCH#*master*}" = "${_BRANCH}" ]; then
cp -f -p win32/*.map "${_DST}/bin/"
fi
unix2dos --quiet --keepdate "${_DST}"/*.txt
unix2dos --quiet --keepdate "${_DST}"/docs/*.txt
../_pack.sh "$(pwd)/${_ref}"
../_ul.sh
)