/
nghttp3.sh
executable file
·118 lines (89 loc) · 3.4 KB
/
nghttp3.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
#!/bin/sh
# Copyright 2014-present Viktor Szakats. See LICENSE.md
# shellcheck disable=SC3040
set -o xtrace -o errexit -o nounset; [ -n "${BASH:-}${ZSH_NAME:-}" ] && set -o pipefail
export _NAM
export _VER
export _OUT
export _BAS
export _DST
_NAM="$(basename "$0")"
_NAM="$(echo "${_NAM}" | cut -f 1 -d '.')"
_VER="$1"
(
cd "${_NAM}" || exit 0
# Cross-tasks
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='
else
opt_gmsys=''
fi
# Build
rm -r -f pkg CMakeFiles CMakeCache.txt cmake_install.cmake
find . -name '*.o' -delete
find . -name '*.obj' -delete
find . -name '*.a' -delete
find . -name '*.lo' -delete
find . -name '*.la' -delete
find . -name '*.lai' -delete
find . -name '*.Plo' -delete
find . -name '*.pc' -delete
_CFLAGS="${_OPTM} -fno-ident -DNDEBUG -Wa,--noexecstack"
[ "${_CPU}" = 'x86' ] && _CFLAGS="${_CFLAGS} -fno-asynchronous-unwind-tables"
options=''
options="${options} -DCMAKE_SYSTEM_NAME=Windows"
options="${options} -DCMAKE_BUILD_TYPE=Release"
options="${options} -DENABLE_LIB_ONLY=1"
options="${options} -DENABLE_STATIC_LIB=1"
options="${options} -DCMAKE_RC_COMPILER=${_CCPREFIX}windres"
options="${options} -DCMAKE_INSTALL_MESSAGE=NEVER"
options="${options} -DCMAKE_INSTALL_PREFIX=/usr/local"
# We do not need C++ with ENABLE_LIB_ONLY, so make sure to skip the
# detection logic and all the potential detection issues with it.
options="${options} -DCMAKE_CXX_COMPILER_WORKS=1"
if [ "${CC}" = 'mingw-clang' ]; then
unset CC
[ "${_OS}" = 'linux' ] && _CFLAGS="-L$(find "/usr/lib/gcc/${_TRIPLET}" -name '*posix' | head -n 1) ${_CFLAGS}"
# _CFLAGS="${_CFLAGS} -Xclang -cfguard"
# shellcheck disable=SC2086
cmake . ${options} ${opt_gmsys} \
"-DCMAKE_SYSROOT=${_SYSROOT}" \
"-DCMAKE_LIBRARY_ARCHITECTURE=${_TRIPLET}" \
"-DCMAKE_C_COMPILER_TARGET=${_TRIPLET}" \
"-DCMAKE_C_COMPILER=clang${_CCSUFFIX}" \
"-DCMAKE_C_FLAGS=${_CFLAGS}"
else
unset CC
# shellcheck disable=SC2086
cmake . ${options} ${opt_gmsys} \
"-DCMAKE_C_COMPILER=${_CCPREFIX}gcc" \
"-DCMAKE_C_FLAGS=-static-libgcc ${_CFLAGS}"
fi
make --jobs 2 install "DESTDIR=$(pwd)/pkg"
# DESTDIR= + CMAKE_INSTALL_PREFIX
_pkg='pkg/usr/local'
# Delete the implib, we need the static lib only
rm -f ${_pkg}/lib/*.dll.a
# Make steps for determinism
readonly _ref='ChangeLog'
"${_CCPREFIX}strip" --preserve-dates --strip-debug --enable-deterministic-archives ${_pkg}/lib/*.a
touch -c -r "${_ref}" ${_pkg}/include/nghttp3/*.h
touch -c -r "${_ref}" ${_pkg}/lib/pkgconfig/*.pc
touch -c -r "${_ref}" ${_pkg}/lib/*.a
# Create package
_OUT="${_NAM}-${_VER}${_REVSUFFIX}${_PKGSUFFIX}"
_BAS="${_NAM}-${_VER}${_PKGSUFFIX}"
_DST="$(mktemp -d)/${_BAS}"
mkdir -p "${_DST}/include/nghttp3"
mkdir -p "${_DST}/lib/pkgconfig"
cp -f -p ${_pkg}/include/nghttp3/*.h "${_DST}/include/nghttp3/"
cp -f -p ${_pkg}/lib/*.a "${_DST}/lib/"
cp -f -p ${_pkg}/lib/pkgconfig/*.pc "${_DST}/lib/pkgconfig/"
cp -f -p ChangeLog "${_DST}/ChangeLog.txt"
cp -f -p AUTHORS "${_DST}/AUTHORS.txt"
cp -f -p COPYING "${_DST}/COPYING.txt"
cp -f -p README.rst "${_DST}/"
../_pkg.sh "$(pwd)/${_ref}"
)