forked from curl/curl-for-win
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrotli.sh
executable file
·138 lines (104 loc) · 3.89 KB
/
brotli.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
#!/bin/sh -ex
# Copyright 2017-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 '.')"
_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 CMakeFiles CMakeCache.txt cmake_install.cmake
find . -name '*.o' -type f -delete
find . -name '*.a' -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
find . -name '*.pc' -type f -delete
_CFLAGS="-m${_cpu} -fno-ident -DMINGW_HAS_SECURE_API"
[ "${_cpu}" = '32' ] && _CFLAGS="${_CFLAGS} -fno-asynchronous-unwind-tables"
options=''
options="${options} -DCMAKE_SYSTEM_NAME=Windows"
options="${options} -DCMAKE_BUILD_TYPE=Release"
options="${options} -DCMAKE_INSTALL_MESSAGE=NEVER"
options="${options} -DCMAKE_INSTALL_PREFIX=/usr/local"
if [ "${CC}" = 'mingw-clang' ]; then
unset CC
[ "${os}" = 'linux' ] && _CFLAGS="-L$(find "/usr/lib/gcc/${_TRIPLET}" -name '*posix' | head -n 1) ${_CFLAGS}"
# shellcheck disable=SC2086
cmake . ${options} "${opt_gmsys}" \
"-DCMAKE_SYSROOT=${_SYSROOT}" \
"-DCMAKE_LIBRARY_ARCHITECTURE=${_TRIPLET}" \
"-DCMAKE_C_COMPILER_TARGET=${_TRIPLET}" \
"-DCMAKE_CXX_COMPILER_TARGET=${_TRIPLET}" \
"-DCMAKE_C_COMPILER=clang${_CCSUFFIX}" \
"-DCMAKE_CXX_COMPILER=clang++${_CCSUFFIX}" \
"-DCMAKE_C_FLAGS=${_CFLAGS}" \
'-DCMAKE_EXE_LINKER_FLAGS=-static-libgcc' \
'-DCMAKE_SHARED_LINKER_FLAGS=-static-libgcc'
else
unset CC
# shellcheck disable=SC2086
cmake . ${options} "${opt_gmsys}" \
"-DCMAKE_C_COMPILER=${_CCPREFIX}gcc" \
"-DCMAKE_CXX_COMPILER=${_CCPREFIX}g++" \
"-DCMAKE_C_FLAGS=-static-libgcc ${_CFLAGS}"
fi
make -j 2 install "DESTDIR=$(pwd)/pkg"
# DESTDIR= + CMAKE_INSTALL_PREFIX
_pkg='pkg/usr/local'
# Remove '-static' suffixes from static lib names to make these behave
# like other most other projects do.
# for fn in ${_pkg}/lib/*-static.a; do mv "${fn}" "$(echo "${fn}" | sed 's|-static||')"; done
# Make steps for determinism
readonly _ref='docs/brotli.1'
"${_CCPREFIX}strip" -p --enable-deterministic-archives -g ${_pkg}/lib/*.a
"${_CCPREFIX}strip" -p -s ${_pkg}/bin/*.exe
"${_CCPREFIX}strip" -p -s ${_pkg}/bin/*.dll
../_peclean.py "${_ref}" ${_pkg}/bin/*.exe
../_peclean.py "${_ref}" ${_pkg}/bin/*.dll
../_sign.sh "${_ref}" ${_pkg}/bin/*.exe
../_sign.sh "${_ref}" ${_pkg}/bin/*.dll
touch -c -r "${_ref}" ${_pkg}/include/brotli/*.h
touch -c -r "${_ref}" ${_pkg}/bin/*.exe
touch -c -r "${_ref}" ${_pkg}/bin/*.dll
touch -c -r "${_ref}" ${_pkg}/lib/pkgconfig/*.pc
touch -c -r "${_ref}" ${_pkg}/lib/*.a
# Tests
"${_CCPREFIX}objdump" -x ${_pkg}/bin/*.exe | grep -E -i "(file format|dll name)"
"${_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}"
mkdir -p "${_DST}/bin"
mkdir -p "${_DST}/lib/pkgconfig"
mkdir -p "${_DST}/include/brotli"
cp -f -p ${_pkg}/include/brotli/*.h "${_DST}/include/brotli/"
cp -f -p ${_pkg}/bin/*.exe "${_DST}/bin/"
cp -f -p ${_pkg}/bin/*.dll "${_DST}/bin/"
cp -f -p ${_pkg}/lib/pkgconfig/*.pc "${_DST}/lib/pkgconfig/"
cp -f -p ${_pkg}/lib/*.a "${_DST}/lib/"
cp -f -p README.md "${_DST}/README.md"
unix2dos -q -k "${_DST}"/*.md
../_pack.sh "$(pwd)/${_ref}"
../_ul.sh
)