forked from curl/curl-for-win
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
c-ares.sh
executable file
·146 lines (113 loc) · 4.19 KB
/
c-ares.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
#!/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 '.')"
_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 '*.obj' -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"
[ "${_cpu}" = '32' ] && _CFLAGS="${_CFLAGS} -fno-asynchronous-unwind-tables"
_LDFLAGS='-Wl,--nxcompat -Wl,--dynamicbase'
[ "${_cpu}" = '64' ] && _LDFLAGS="${_LDFLAGS} -Wl,--high-entropy-va -Wl,--image-base,0x154000000"
options=''
options="${options} -DCMAKE_SYSTEM_NAME=Windows"
options="${options} -DCMAKE_BUILD_TYPE=Release"
options="${options} -DCARES_STATIC=1"
options="${options} -DCARES_STATIC_PIC=1"
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_C_COMPILER=clang${_CCSUFFIX}" \
"-DCMAKE_C_FLAGS=${_CFLAGS}" \
'-DCMAKE_EXE_LINKER_FLAGS=-static-libgcc' \
"-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"
# DESTDIR= + CMAKE_INSTALL_PREFIX
_pkg='pkg/usr/local'
ls -l ${_pkg}/bin/*.exe
ls -l ${_pkg}/bin/*.dll
ls -l ${_pkg}/lib/*.a
# Stick to the name used by GNU Make builds
mv -f ${_pkg}/lib/libcares_static.a ${_pkg}/lib/libcares.a
# curl makefile.m32 assumes the headers and lib to be in the same directory.
# Make sure to copy the static library only:
cp -f -p ${_pkg}/include/*.h "${_pkg}/"
cp -f -p ${_pkg}/lib/libcares.a "${_pkg}/"
# Make steps for determinism
readonly _ref='RELEASE-NOTES'
"${_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/*.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
# 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"
cp -f -p ${_pkg}/include/*.h "${_DST}/include/"
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}/"
cp -f -p CHANGES "${_DST}/CHANGES.txt"
cp -f -p RELEASE-NOTES "${_DST}/RELEASE-NOTES.txt"
unix2dos -q -k "${_DST}"/*.md
unix2dos -q -k "${_DST}"/*.txt
# ../_pack.sh "$(pwd)/${_ref}"
# ../_ul.sh
)