blob: 1295ee2ec3dfca3f168cebfbe3021dfddaf4b0fc (
plain) (
blame)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
# /usr/share/abuild/functions.sh
sysconfdir=@sysconfdir@
program=${0##*/}
arch_to_hostspec() {
case "$1" in
aarch64) echo "aarch64-foxkit-linux-musl" ;;
armel) echo "armv5-foxkit-linux-musleabi" ;;
armhf) echo "armv6-foxkit-linux-muslgnueabihf" ;;
armv7) echo "armv7-foxkit-linux-musleabihf" ;;
i528) echo "pentium4-foxkit-linux-musl" ;;
m68k) echo "m68k-foxkit-linux-musl" ;;
mips) echo "mips-foxkit-linux-musl" ;;
mipsel) echo "mipsel-foxkit-linux-musl" ;;
mips32) echo "mips32-foxkit-linux-musl" ;;
mips32el) echo "mips32el-foxkit-linux-musl" ;;
pmmx) echo "i586-foxkit-linux-musl" ;;
ppc) echo "powerpc-foxkit-linux-musl" ;;
ppc64) echo "powerpc64-foxkit-linux-musl" ;;
ppc64le) echo "powerpc64le-foxkit-linux-musl" ;;
s390x) echo "s390x-foxkit-linux-musl" ;;
sparc) echo "sparc-foxkit-linux-musl" ;;
sparc64) echo "sparc64-foxkit-linux-musl" ;;
x86) echo "i486-foxkit-linux-musl" ;;
x86_64) echo "x86_64-foxkit-linux-musl" ;;
*) echo "unknown" ;;
esac
}
hostspec_to_arch() {
case "$1" in
aarch64*-*-*-*) echo "aarch64" ;;
arm*-*-*-*eabi) echo "armel" ;; # non-hardfloat ARMs
armv6*-*-*-*eabihf) echo "armhf" ;;
armv7*-*-*-*eabihf) echo "armv7" ;;
i486-*-*-*) echo "x86" ;;
i586-*-*-*) echo "pmmx" ;;
m68k-*-*-*) echo "m68k" ;;
mips-*-*-*) echo "mips" ;;
mipsel-*-*-*) echo "mipsel" ;;
mips32-*-*-*) echo "mips32" ;;
mips32el-*-*-*) echo "mips32el" ;;
pentium4-*-*-*) echo "i528" ;;
powerpc-*-*-*) echo "ppc" ;;
powerpc64-*-*-*) echo "ppc64" ;;
powerpc64le-*-*-*) echo "ppc64le" ;;
s390x-*-*-*) echo "s390x" ;;
sparc64-*-*-*) echo "sparc64" ;;
sparc*-*-*-*) echo "sparc" ;; # sparc, sparclite, ...
x86_64-*-*-*) echo "x86_64" ;;
*) echo "unknown" ;;
esac
}
hostspec_to_libc() {
case "$1" in
*-*-*-uclibc*) echo "uclibc" ;;
*-*-*-musl*) echo "musl" ;;
*-*-*-gnu*) echo "glibc" ;;
*) echo "unknown" ;;
esac
}
readconfig() {
local _APORTSDIR _BUILDDIR _PKGDEST _SRCPKGDEST _REPODEST _SRCDEST
local _CARCH _CHOST _CTARGET _CPPFLAGS _CFLAGS _CXXFLAGS _LDFLAGS
local _JOBS _MAKEFLAGS _PACKAGER _USE_COLORS _ABUILD_GIT
local gitbase=
[ -n "${APORTSDIR+x}" ] && _APORTSDIR=$APORTSDIR
[ -n "${BUILDDIR+x}" ] && _BUILDDIR=$BUILDDIR
[ -n "${PKGDEST+x}" ] && _PKGDEST=$PKGDEST
[ -n "${SRCPKGDEST+x}" ] && _SRCPKGDEST=$SRCPKGDEST
[ -n "${REPODEST+x}" ] && _REPODEST=$REPODEST
[ -n "${SRCDEST+x}" ] && _SRCDEST=$SRCDEST
[ -n "${CARCH+x}" ] && _CARCH=$CARCH
[ -n "${CHOST+x}" ] && _CHOST=$CHOST
[ -n "${CTARGET+x}" ] && _CTARGET=$CTARGET
[ -n "${CPPFLAGS+x}" ] && _CPPFLAGS=$CPPFLAGS
[ -n "${CFLAGS+x}" ] && _CFLAGS=$CFLAGS
[ -n "${CXXFLAGS+x}" ] && _CXXFLAGS=$CXXFLAGS
[ -n "${LDFLAGS+x}" ] && _LDFLAGS=$LDFLAGS
[ -n "${JOBS+x}" ] && _JOBS=$JOBS
[ -n "${MAKEFLAGS+x}" ] && _MAKEFLAGS=$MAKEFLAGS
[ -n "${PACKAGER+x}" ] && _PACKAGER=$PACKAGER
[ -n "${USE_COLORS+x}" ] && _USE_COLORS="$USE_COLORS"
[ -n "${ABUILD_GIT+x}" ] && _ABUILD_GIT=$ABUILD_GIT
: ${ABUILD_CONF:=$sysconfdir/abuild.conf}
: ${ABUILD_USERDIR:=$HOME/.abuild}
: ${ABUILD_USERCONF:=$ABUILD_USERDIR/abuild.conf}
[ -f "$ABUILD_CONF" ] && . "$ABUILD_CONF"
[ -f "$ABUILD_USERCONF" ] && . "$ABUILD_USERCONF"
ABUILD_GIT=${_ABUILD_GIT-$ABUILD_GIT}
if [ -z "$ABUILD_GIT" ]; then
ABUILD_GIT=$(command -v git) || ABUILD_GIT=true
fi
APORTSDIR=${_APORTSDIR-$APORTSDIR}
gitbase=$($ABUILD_GIT rev-parse --show-toplevel 2>/dev/null) || true # already is -P
if [ -d "$APORTSDIR" ]; then
APORTSDIR=$(cd "$APORTSDIR"; pwd -P)
elif [ -z "$APORTSDIR" ] && [ -d "$HOME/aports" ]; then
APORTSDIR=$(cd "$HOME/aports"; pwd -P)
else
if [ -n "$gitbase" ]; then
case $($ABUILD_GIT config remote.origin.url) in
*/aports) APORTSDIR=$gitbase ;;
*) APORTSDIR= ;;
esac
else
APORTSDIR=
fi
fi
# source any .abuild file at the aports root, but only if we are currently in aports tree
[ -n "$APORTSDIR" ] && [ -f "$APORTSDIR/.abuild" ] && [ "$APORTSDIR" = "$gitbase" ] && . "$APORTSDIR/.abuild"
BUILDDIR=${_BUILDDIR-$BUILDDIR}
PKGDEST=${_PKGDEST-$PKGDEST}
SRCPKGDEST=${_SRCPKGDEST-$SRCPKGDEST}
REPODEST=${_REPODEST-$REPODEST}
SRCDEST=${_SRCDEST-$SRCDEST}
CARCH=${_CARCH-$CARCH}
CHOST=${_CHOST-$CHOST}
CTARGET=${_CTARGET-$CTARGET}
CPPFLAGS=${_CPPFLAGS-$CPPFLAGS}
CFLAGS=${_CFLAGS-$CFLAGS}
CXXFLAGS=${_CXXFLAGS-$CXXFLAGS}
LDFLAGS=${_LDFLAGS-$LDFLAGS}
JOBS=${_JOBS-$JOBS}
MAKEFLAGS=${_MAKEFLAGS-$MAKEFLAGS}
PACKAGER=${_PACKAGER-$PACKAGER}
USE_COLORS=${_USE_COLORS-$USE_COLORS}
[ -z "$CBUILD" ] && CBUILD="$(gcc -dumpmachine)"
[ -z "$CHOST" ] && CHOST="$CBUILD"
[ -z "$CTARGET" ] && CTARGET="$CHOST"
[ "$(arch_to_hostspec $CBUILD)" != "unknown" ] && CBUILD="$(arch_to_hostspec $CBUILD)"
[ "$(arch_to_hostspec $CHOST)" != "unknown" ] && CHOST="$(arch_to_hostspec $CHOST)"
[ "$(arch_to_hostspec $CTARGET)" != "unknown" ] && CTARGET="$(arch_to_hostspec $CTARGET)"
[ -z "$CARCH" ] && CARCH="$(hostspec_to_arch $CHOST)"
[ -z "$CLIBC" ] && CLIBC="$(hostspec_to_libc $CHOST)"
[ -z "$CBUILD_ARCH" ] && CBUILD_ARCH="$(hostspec_to_arch $CBUILD)"
[ -z "$CTARGET_ARCH" ] && CTARGET_ARCH="$(hostspec_to_arch $CTARGET)"
[ -z "$CTARGET_LIBC" ] && CTARGET_LIBC="$(hostspec_to_libc $CTARGET)"
if [ "$CHOST" != "$CTARGET" ]; then
# setup environment for creating cross compiler
[ -z "$CBUILDROOT" ] && export CBUILDROOT="$HOME/sysroot-$CTARGET_ARCH/"
elif [ "$CBUILD" != "$CHOST" ]; then
# setup build root
[ -z "$CBUILDROOT" ] && export CBUILDROOT="$HOME/sysroot-$CTARGET_ARCH/"
# prepare pkg-config for cross building
[ -z "$PKG_CONFIG_PATH" ] && export PKG_CONFIG_PATH="${CBUILDROOT}/usr/lib/pkgconfig/"
[ -z "$PKG_CONFIG_SYSROOT_DIR" ] && export PKG_CONFIG_SYSROOT_DIR="${CBUILDROOT}"
# libtool bug workaround for extra rpaths
[ -z "$lt_cv_sys_lib_dlsearch_path_spec" ] && \
export lt_cv_sys_lib_dlsearch_path_spec="${CBUILDROOT}/lib ${CBUILDROOT}/usr/lib /usr/lib /lib /usr/local/lib"
# setup cross-compiler
if [ -z "$CROSS_COMPILE" ]; then
export CROSS_COMPILE="${CHOST}-"
export HOSTCC="$CC"
export HOSTCXX="$CXX"
export HOSTLD="$LD"
export HOSTCPPFLAGS="$CPPFLAGS"
export HOSTCXXFLAGS="$CXXFLAGS"
export HOSTCFLAGS="$CFLAGS"
export HOSTLDFLAGS="$LDFLAGS"
export CC=${CROSS_COMPILE}gcc
export CXX=${CROSS_COMPILE}g++
export LD=${CROSS_COMPILE}ld
export CPPFLAGS="--sysroot=${CBUILDROOT} $CPPFLAGS"
export CXXFLAGS="--sysroot=${CBUILDROOT} $CXXFLAGS"
export CFLAGS="--sysroot=${CBUILDROOT} $CFLAGS"
export LDFLAGS="--sysroot=${CBUILDROOT} $LDFLAGS"
fi
fi
return 0
}
readconfig
# expects $1 to be a package directory in the aports tree ('foo' or 'main/foo')
# outputs APKBUILD's path if successful
aports_buildscript() {
[ -n "$APORTSDIR" ] || return 1
if [ "${1#*/}" != "$1" ]; then
( cd "$APORTSDIR/$1" && [ -f APKBUILD ] && echo "$PWD/APKBUILD" )
else
( cd "$APORTSDIR"/*/"$1" && [ -f APKBUILD ] && echo "$PWD/APKBUILD" )
fi
}
# expects $1 to be a file, or a directory containing an APKBUILD, or a package directory in the aports tree
# outputs APKBUILD's path if successful (doesn't verify that it's a valid APKBUILD)
any_buildscript() {
if [ -f "$1" ]; then
echo "$1"
elif [ -d "$1" ]; then
[ -f "$1/APKBUILD" ] || return 1
echo "$1/APKBUILD"
else
aports_buildscript "$1" || return 1
fi
}
# output functions
msg() {
[ -n "$quiet" ] && return 0
local prompt="$GREEN>>>${NORMAL}"
printf "${prompt} %s\n" "$1" >&2
}
msg2() {
[ -n "$quiet" ] && return 0
# ">>> %s"
printf " %s\n" "$1" >&2
}
warning() {
local prompt="${YELLOW}>>> WARNING:${NORMAL}"
printf "${prompt} %s\n" "$1" >&2
}
warning2() {
# ">>> WARNING: %s\n"
printf " %s\n" "$1" >&2
}
error() {
local prompt="${RED}>>> ERROR:${NORMAL}"
printf "${prompt} %s\n" "$1" >&2
}
error2() {
# ">>> ERROR:
printf " %s\n" "$1" >&2
}
set_xterm_title() {
if [ "$TERM" = xterm ] && [ -n "$USE_COLORS" ]; then
printf "\033]0;$1\007" >&2
fi
}
disable_colors() {
NORMAL=""
STRONG=""
RED=""
GREEN=""
YELLOW=""
BLUE=""
}
enable_colors() {
NORMAL="\033[1;0m"
STRONG="\033[1;1m"
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
}
if [ "$USE_COLORS" = force ]; then
enable_colors
elif [ -n "$USE_COLORS" ] && [ -t 1 ]; then
enable_colors
else
disable_colors
fi
# caller may override
cleanup() {
return 0
}
die() {
error "$@"
cleanup
exit 1
}
|