This repository has been archived by the owner on Jan 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
153 lines (139 loc) · 3.43 KB
/
build.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
# exit immediately upon error
set -e
MINOR=0
PATCH=0
function make_zip() {
local folder
local "${@}"
find "$folder" # prints paths of all files to be zipped
7z a -tzip -r "$folder.zip" $folder
}
get_git_date() {
local folder
local "${@}"
pushd "$folder" > /dev/null
git show -s --format=%ci HEAD | sed 's/\([0-9]\{4\}\)-\([0-9][0-9]\)-\([0-9][0-9]\).*/\1\2\3/'
popd > /dev/null
}
get_git_hash() {
local folder
local "${@}"
pushd "$folder" > /dev/null
git show -s --format=%h HEAD
popd > /dev/null
}
get_version() {
local folder
local "${@}"
echo -n "$(get_git_date folder=$folder).$MINOR.$PATCH-$(get_git_hash folder=$folder)"
}
cflags_runtime() {
local runtime
local configuration
local "${@}"
echo -n "-${runtime^^}"
case "$configuration" in
release)
echo ""
;;
debug)
echo "d"
;;
*)
return 1
esac
}
target_id() {
local base
local extra
local visual_studio
local linkage
local runtime
local configuration
local platform
local "${@}"
echo -n "$base-$(get_version folder=$base)"
[[ ! -z $extra ]] && echo -n "-${extra}"
echo -n "-$visual_studio-$linkage-$runtime-$configuration-$platform"
}
x264_options_linkage() {
local linkage
local "${@}"
case "$linkage" in
shared)
echo "--enable-shared"
;;
static)
echo "--enable-static"
;;
*)
return 1
esac
}
x264_options() {
local prefix
local linkage
local runtime
local configuration
local "${@}"
echo -n " --prefix=$prefix"
echo -n " $(x264_options_linkage linkage=$linkage)"
echo -n " --extra-cflags=$(cflags_runtime runtime=$runtime configuration=$configuration)"
}
function build_x264() {
local prefix
local linkage
local runtime
local configuration
local "${@}"
# install license file
mkdir -p "$prefix/share/doc/x264"
cp "x264/COPYING" "$prefix/share/doc/x264/license.txt"
# run configure, make, make install
pushd x264
# use latest config.guess to ensure that we can detect msys2
curl "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD" > config.guess
# hotpatch configure script so we get the right compiler, compiler_style, and compiler flags
sed -i 's/host_os = mingw/host_os = msys/' configure
CC=cl ./configure $(x264_options prefix=$prefix linkage=$linkage runtime=$runtime configuration=$configuration) || (tail -30 config.log && exit 1)
make
make install
# rename import libraries
if [ "$linkage" = "shared" ]
then
pushd "$prefix/lib/"
for file in *.dll.lib; do mv "$file" "${file/.dll.lib/.lib}"; done
popd
fi
# delete pkgconfig files (not useful for msvc)
rm -rf "$prefix/lib/pkgconfig"
popd
}
function make_all() {
local visual_studio
local linkage
local runtime
local configuration
local platform
local "${@}"
# ensure link.exe is the one from msvc
mv /usr/bin/link /usr/bin/link1
which link
# ensure cl.exe can be called
which cl
cl
local x264_folder=$(target_id base=x264 visual_studio=$visual_studio linkage=$linkage runtime=$runtime configuration=$configuration platform=$platform)
local x264_prefix=$(readlink -f $x264_folder)
build_x264 prefix=$x264_prefix linkage=$linkage runtime=$runtime configuration=$configuration
make_zip folder=$x264_folder
mv /usr/bin/link1 /usr/bin/link
}
set -xe
# bash starts in msys home folder, so first go to project folder
cd $(cygpath "$APPVEYOR_BUILD_FOLDER")
make_all \
visual_studio=${TOOLSET,,} \
linkage=${LINKAGE,,} \
runtime=${RUNTIME_LIBRARY,,} \
configuration=${Configuration,,} \
platform=${Platform,,}