-
Notifications
You must be signed in to change notification settings - Fork 78
/
build-deps.zsh
executable file
·180 lines (141 loc) · 4.36 KB
/
build-deps.zsh
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env zsh
builtin emulate -L zsh
setopt EXTENDED_GLOB
setopt PUSHD_SILENT
setopt ERR_EXIT
setopt ERR_RETURN
setopt NO_UNSET
setopt PIPE_FAIL
setopt NO_AUTO_PUSHD
setopt NO_PUSHD_IGNORE_DUPS
setopt FUNCTION_ARGZERO
#setopt WARN_CREATE_GLOBAL
#setopt WARN_NESTED_VAR
#setopt XTRACE
run_stages() {
local -a stages=()
local dependency
if (( ${skips[(Ie)all]} + ${skips[(Ie)build]} )) {
stages+=(install fixup)
} else {
stages=(setup)
if (( clean_build )) stages+=(clean)
stages+=(patch config build install fixup)
}
for dependency (${files}) {
function {
local version url hash dir
local -A versions hashes urls
local -a patches
local -a args=()
local arch="${target_config[arch]}"
local targets=(${target})
source "${SCRIPT_HOME}/${dependency}"
if [[ ! ${target} =~ "${(j:|:)targets}" ]] continue
: ${version:=${versions[${target%%-*}]}}
: ${url:=${urls[${target%%-*}]}}
: ${hash:=${hashes[${target%%-*}]}}
: ${dir:=${${url##*/}%.*.*}}
if [[ "${url##*.}" == "git" ]] dir="${name}-${version}"
local stage_name="${name}"
log_output "Initializing build"
for stage (${stages}) {
pushd ${PWD}
if (( ${+functions[${stage}]} )) {
${stage}
unset -f ${stage}
}
popd
}
if [[ -d ${SCRIPT_HOME}/licenses/${name} ]] {
log_status "Install license files"
mkdir -p ${target_config[output_dir]}/licenses/${name} && cp -pR ${SCRIPT_HOME}/licenses/${name} ${target_config[output_dir]}/licenses/
}
log_output "%F{2}DONE%f"
}
}
}
package() {
autoload -Uz log_info log_status
if [[ ${PACKAGE_NAME} == 'qt'* ]] {
local filename="${target%%-*}-deps-${PACKAGE_NAME}-${current_date}-${target_config[arch]}.tar.xz"
} else {
local filename="${target%%-*}-${PACKAGE_NAME}-${current_date}-${target_config[arch]}.tar.xz"
}
pushd ${PWD}
cd ${target_config[output_dir]}
log_info "Package dependencies"
if [[ ${PACKAGE_NAME} != 'qt'* ]] {
log_status "Cleanup unnecessary files"
rm -rf -- lib/^(*.dylib|*.a|*.so*|*.lib|*.framework|*.dSYM|cmake)(N)
rm -rf -- lib/(libpcre*|libpng*|libfreetype.a)(N)
rm -rf -- lib/cmake/MbedTLS(N)
rm -rf -- bin/^(*.exe|*.dll|*.pdb|swig)(N)
if [[ ${PACKAGE_NAME} == ffmpeg ]] rm -rf -- lib/*.a(N)
if [[ -f bin/swig ]] {
swig_lib=(share/swig/*(/))
pushd ${swig_lib:h}
ln -sf ${swig_lib:t} CURRENT
popd
}
if [[ -d share ]] rm -rf share/^(swig|cmake)(N)
if [[ -d cmake ]] rm -rf cmake
if [[ -d man ]] rm -rf man
} else {
rm -rf -- lib/*.(a|la|prl)(N)
}
local -a dsym_files=(**/*.dSYM(N))
if [[ ${target} == macos* ]] && (( #dsym_files )) {
mkdir -p ${target_config[output_dir]}-dSYMs
cp -Rfp ${dsym_files} ${target_config[output_dir]}-dSYMs
rm -rf -- ${dsym_files}
}
mkdir -p share/obs-deps
echo "${current_date}" >! share/obs-deps/VERSION
log_status "Create archive ${filename}"
local -a _tarflags=()
if (( _loglevel > 1 )) _tarflags+='-v'
_tarflags+=(-cJf)
XZ_OPT=-T0 tar ${_tarflags} ${filename} -- *
if [[ ${target} == macos* ]] && (( #dsym_files )) {
dsym_filename="${filename//.tar.xz/-dSYMs.tar.xz}"
log_status "Create archive ${dsym_filename}"
pushd ${target_config[output_dir]}-dSYMs
XZ_OPT=-T0 tar ${_tarflags} ${dsym_filename} -- *
mv -- ${dsym_filename} ${PWD:A:h}
popd
}
mv -- ${filename} ${PWD:A:h}
}
build_dependencies() {
autoload -Uz mkcd log_debug log_output
if (( ! ${+SCRIPT_HOME} )) typeset -g SCRIPT_HOME=${0:A:h}
if (( ! ${+PACKAGE_NAME} )) typeset -g PACKAGE_NAME=${${(s:-:)ZSH_ARGZERO:t:r}[2]}
source "${SCRIPT_HOME}"/utils.zsh/10-bootstrap.zsh
trap '_trap_exit ${deps}' EXIT
trap '_trap_error' ZERR
bootstrap "${@}"
local subdir
if [[ ${PACKAGE_NAME} == 'ffmpeg' ]] {
subdir='deps.ffmpeg'
} elif [[ ${PACKAGE_NAME} == 'qt'* ]] {
subdir='deps.qt'
} else {
subdir="deps.${host_os}"
}
local -a files
if (( #deps )) {
files=(${subdir}/*-(${~${(j:|:)deps}}).zsh)
} elif [[ ${PACKAGE_NAME} == 'qt'* ]] {
files=(${subdir}/${PACKAGE_NAME}.zsh)
} else {
files=(${subdir}/*-*.zsh)
}
log_debug "Using found dependency scripts:\n + ${(j:\n + :)files}"
pushd ${PWD}
mkcd ${work_root}
run_stages
popd
if (( ! #deps )) package
}
build_dependencies "${@}"