forked from curl/curl-for-win
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
libssh2_cmake.sh
executable file
·191 lines (148 loc) · 6.12 KB
/
libssh2_cmake.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/sh -ex
# Copyright 2014-2019 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 '.' | cut -f 1 -d '_')"
_VER="$1"
_cpu="$2"
(
cd "${_NAM}" || exit
# Cross-tasks
# Detect host OS
case "$(uname)" in
*_NT*) os='win';;
Linux*) os='linux';;
Darwin*) os='mac';;
*BSD) os='bsd';;
esac
if [ "${os}" = 'win' ]; then
opt_gmsys='-GMSYS Makefiles'
# Without this option, the value '/usr/local' becomes 'msys64/usr/local'
export MSYS2_ARG_CONV_EXCL='-DCMAKE_INSTALL_PREFIX='
fi
# Build
rm -fr pkg
find . -name '*.a' -type f -delete
find . -name '*.pc' -type f -delete
for pass in 'static' 'shared'; do
rm -fr CMakeFiles CMakeCache.txt cmake_install.cmake
find . -name '*.o' -type f -delete
find . -name '*.obj' -type f -delete
find . -name '*.lo' -type f -delete
find . -name '*.la' -type f -delete
find . -name '*.lai' -type f -delete
find . -name '*.Plo' -type f -delete
_CFLAGS="-m${_cpu} -fno-ident"
[ "${_cpu}" = '32' ] && _CFLAGS="${_CFLAGS} -fno-asynchronous-unwind-tables"
_LDFLAGS='-Wl,--nxcompat -Wl,--dynamicbase'
[ "${_cpu}" = '64' ] && _LDFLAGS="${_LDFLAGS} -Wl,--high-entropy-va -Wl,--image-base,0x152000000"
if [ "${_BRANCH#*master*}" = "${_BRANCH}" ]; then
_LDFLAGS="${_LDFLAGS} -Wl,-Map,libssh2.map"
fi
options=''
options="${options} -DCMAKE_SYSTEM_NAME=Windows"
options="${options} -DCMAKE_BUILD_TYPE=Release"
[ "${pass}" = 'static' ] && options="${options} -DBUILD_SHARED_LIBS=0"
[ "${pass}" = 'shared' ] && options="${options} -DBUILD_SHARED_LIBS=1"
options="${options} -DBUILD_EXAMPLES=0"
options="${options} -DBUILD_TESTING=0"
options="${options} -DENABLE_ZLIB_COMPRESSION=1"
options="${options} -DZLIB_INCLUDE_DIR:PATH=$(pwd)/../zlib/pkg/usr/local/include"
options="${options} -DZLIB_LIBRARY:FILEPATH=$(pwd)/../zlib/pkg/usr/local/lib/libz.a"
options="${options} -DCRYPTO_BACKEND=OpenSSL"
options="${options} -DOPENSSL_ROOT_DIR=$(pwd)/../openssl/pkg/C:/Windows/System32/OpenSSL/"
options="${options} -DOPENSSL_INCLUDE_DIR=$(pwd)/../openssl/pkg/C:/Windows/System32/OpenSSL/include"
options="${options} -DOPENSSL_LIBRARIES=$(pwd)/../openssl/pkg/C:/Windows/System32/OpenSSL/lib"
options="${options} -DOPENSSL_CRYPTO_LIBRARY=$(pwd)/../openssl/pkg/C:/Windows/System32/OpenSSL/lib"
options="${options} -DCMAKE_RC_COMPILER=${_CCPREFIX}windres"
options="${options} -DCMAKE_INSTALL_MESSAGE=NEVER"
options="${options} -DCMAKE_INSTALL_PREFIX=/usr/local"
# https://cmake.org/cmake/help/v3.11/manual/cmake-properties.7.html#properties-on-targets
[ "${pass}" = 'shared' ] && [ "${_cpu}" = '64' ] && options="${options} -DCMAKE_RELEASE_POSTFIX=-x64"
if [ "${CC}" = 'mingw-clang' ]; then
unset CC
[ "${os}" = 'linux' ] && _CFLAGS="-L$(find "/usr/lib/gcc/${_TRIPLET}" -name '*posix' | head -n 1) ${_CFLAGS}"
# '-DMINGW=1' required to detect OpenSSL
# shellcheck disable=SC2086
cmake . ${options} "${opt_gmsys}" \
"-DMINGW=1" \
"-DCMAKE_SYSROOT=${_SYSROOT}" \
"-DCMAKE_LIBRARY_ARCHITECTURE=${_TRIPLET}" \
"-DCMAKE_C_COMPILER_TARGET=${_TRIPLET}" \
"-DCMAKE_C_COMPILER=clang${_CCSUFFIX}" \
"-DCMAKE_C_FLAGS=${_CFLAGS}" \
"-DCMAKE_SHARED_LINKER_FLAGS=-static-libgcc ${_LDFLAGS}"
else
unset CC
# shellcheck disable=SC2086
cmake . ${options} "${opt_gmsys}" \
"-DCMAKE_C_COMPILER=${_CCPREFIX}gcc" \
"-DCMAKE_C_FLAGS=-static-libgcc ${_CFLAGS}" \
"-DCMAKE_SHARED_LINKER_FLAGS=${_LDFLAGS}"
fi
make -j 2 install "DESTDIR=$(pwd)/pkg" # VERBOSE=1
done
# DESTDIR= + CMAKE_INSTALL_PREFIX
_pkg='pkg/usr/local'
ls -l ${_pkg}/bin/*.dll
ls -l ${_pkg}/lib/*.a
# Stick to the name used by GNU Make builds
[ "${_cpu}" = '32' ] && mv -f ${_pkg}/lib/liblibssh2.dll.a ${_pkg}/lib/libssh2.dll.a
[ "${_cpu}" = '64' ] && mv -f ${_pkg}/lib/liblibssh2-x64.dll.a ${_pkg}/lib/libssh2.dll.a
# curl makefile.m32 assumes a certain layout.
# Also make sure to copy the static library only:
mkdir -p "${_pkg}/win32/"
cp -f -p ${_pkg}/lib/libssh2.a "${_pkg}/win32/"
# Make steps for determinism
readonly _ref='NEWS'
"${_CCPREFIX}strip" -p --enable-deterministic-archives -g ${_pkg}/lib/*.a
"${_CCPREFIX}strip" -p -s ${_pkg}/bin/*.dll
../_peclean.py "${_ref}" ${_pkg}/bin/*.dll
../_sign.sh "${_ref}" ${_pkg}/bin/*.dll
touch -c -r "${_ref}" ${_pkg}/bin/*.dll
touch -c -r "${_ref}" ${_pkg}/lib/*.a
touch -c -r "${_ref}" ${_pkg}/lib/pkgconfig/*.pc
if [ "${_BRANCH#*master*}" = "${_BRANCH}" ]; then
touch -c -r "${_ref}" ${_pkg}/bin/*.map
touch -c -r "${_ref}" ${_pkg}/bin/*.def || true
fi
# Tests
"${_CCPREFIX}objdump" -x ${_pkg}/bin/*.dll | grep -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}/bin"
mkdir -p "${_DST}/lib"
mkdir -p "${_DST}/lib/pkgconfig"
mkdir -p "${_DST}/include"
(
set +x
for file in docs/*; do
if [ -f "${file}" ] && [ "${file}" != 'Makefile' ] && echo "${file}" | grep -q -v -F '.'; then
cp -f -p "${file}" "${_DST}/${file}.txt"
fi
done
)
cp -f -p ${_pkg}/include/*.h "${_DST}/include/"
cp -f -p ${_pkg}/bin/*.dll "${_DST}/bin/"
cp -f -p ${_pkg}/lib/*.a "${_DST}/lib/"
cp -f -p ${_pkg}/lib/pkgconfig/*.pc "${_DST}/lib/pkgconfig/"
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"
[ -d ../openssl ] && cp -f -p ../openssl/LICENSE "${_DST}/LICENSE-openssl.txt"
if [ "${_BRANCH#*master*}" = "${_BRANCH}" ]; then
cp -f -p ${_pkg}/bin/*.map "${_DST}/bin/"
cp -f -p ${_pkg}/bin/*.def "${_DST}/bin/" || true
fi
unix2dos -q -k "${_DST}"/*.txt
unix2dos -q -k "${_DST}"/docs/*.txt
../_pack.sh "$(pwd)/${_ref}"
../_ul.sh
)