forked from HandBrake/HandBrake-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-tools
executable file
·125 lines (115 loc) · 3.21 KB
/
build-tools
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
#!/bin/bash
# vars
SELF="${BASH_SOURCE[0]}"
SELF_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd -P)
SELF_DIR="${SELF_DIR:-$(pwd)}"
TOOLS_DIR="${SELF_DIR}/tools"
BUILD_DIR="${TOOLS_DIR}/local/build"
INSTALL_DIR="${TOOLS_DIR}/local"
SYS_NAME=$(uname | awk '{ print tolower($0)}')
TOOLS=('discount')
TOOLS_EXTRA=('zlib' 'libpng' 'pngquant' 'zopfli')
# args
OPTIND=1
OPTSPEC=":-:"
OPTARRAY=('--all') # all short and long options
while getopts "${OPTSPEC}" OPT; do
case "${OPT}" in
-)
case "${OPTARG}" in
all)
TOOLS=("${TOOLS[@]}" "${TOOLS_EXTRA[@]}")
;;
all=*)
# Option with prohibited value
echo "option --${OPTARG%%=*} takes no value" >&2
exit 1
;;
*)
if [[ "${OPTERR}" == 1 ]]; then
# Invalid option specified
echo "invalid option: --${OPTARG}" >&2
exit 1
fi
;;
esac
;;
:)
# Option without required value
echo "option -${OPTARG} requires a value" >&2
exit 1
;;
\?)
# Invalid option specified
echo "invalid option: -${OPTARG}" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
# discount
function build_discount {
./configure.sh --prefix="${INSTALL_DIR}" || return 1
make || return 1
make install || return 1
}
# zlib
function build_zlib {
./configure --static --prefix="${INSTALL_DIR}" || return 1
make || return 1
make install || return 1
rm -f "${INSTALL_DIR}/lib/libz*.dylib"
}
# libpng
function build_libpng {
if [[ "${SYS_NAME}" == "darwin" ]]; then
cp scripts/makefile.darwin Makefile
elif [[ "${SYS_NAME}" == "linux" ]]; then
cp scripts/makefile.linux Makefile
else
return 1
fi
make libpng.a prefix="${INSTALL_DIR}" ZLIBINC="${INSTALL_DIR}/include" ZLIBLIB="${INSTALL_DIR}/lib" || return 1
make install-static prefix="${INSTALL_DIR}" || return 1
}
# pngquant
function build_pngquant {
./configure --extra-cflags="-I${INSTALL_DIR}/include" --extra-ldflags="-L${INSTALL_DIR}/lib -lz" --prefix="${INSTALL_DIR}" --with-libpng="${INSTALL_DIR}" --without-cocoa || return 1
sed -i.sedbak -e 's:-L/usr/lib -lz::g' config.mk || return 1
rm -f config.mk.sedbak
make || return 1
make install || return 1
}
# zopfli
function build_zopfli {
make zopfli zopflipng || return 1
cp zopfli zopflipng "${INSTALL_DIR}/bin" || return 1
}
# main
rm -rf "${INSTALL_DIR}"
rm -rf "${BUILD_DIR}"
mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}"
ERROR=false
echo "Building:"
for TOOL in "${TOOLS[@]}"; do
echo " ${TOOL}"
cp -R "${TOOLS_DIR}/${TOOL}" "${BUILD_DIR}/"
rm -rf "${BUILD_DIR}/${TOOL}/.git"
cd "${BUILD_DIR}/${TOOL}"
if ! build_${TOOL} >/dev/null 2>&1; then
ERROR=true
echo "Unable to build tool: ${TOOL}" >&2
break
fi
done
# clean up
if [[ "${ERROR}" != true ]]; then
rm -rf "${BUILD_DIR}"
fi
# done
if [[ "${ERROR}" == true ]]; then
exit 1
fi
echo "Complete."
exit 0