mirror of
https://gitlab.alpinelinux.org/alpine/abuild.git
synced 2025-01-11 09:19:40 +00:00
abuild: move various functions to the shared functions.sh
specifically, every script that reads/parses ./APKBUILD needs to set CARCH.
This commit is contained in:
parent
7a447caf05
commit
0c02afc694
104
abuild.in
104
abuild.in
@ -11,54 +11,32 @@ sysconfdir=@sysconfdir@
|
||||
abuildrepo_base=@abuildrepo@
|
||||
datadir=@datadir@
|
||||
|
||||
program=${0##*/}
|
||||
abuild_path=$(readlink -f $0)
|
||||
|
||||
if ! [ -f "$datadir/functions.sh" ]; then
|
||||
echo "$datadir/functions.sh: not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
. "$datadir/functions.sh"
|
||||
|
||||
# defaults
|
||||
BUILD_BASE="build-base"
|
||||
FAKEROOT=${FAKEROOT:-"fakeroot"}
|
||||
|
||||
: ${SUDO_APK:=abuild-apk}
|
||||
: ${APK:=apk}
|
||||
: ${ADDUSER:=abuild-adduser}
|
||||
: ${ADDGROUP:=abuild-addgroup}
|
||||
: ${FAKEROOT:="fakeroot"}
|
||||
: ${SUDO_APK:="abuild-apk"}
|
||||
: ${APK:="apk"}
|
||||
: ${ADDUSER:="abuild-adduser"}
|
||||
: ${ADDGROUP:="abuild-addgroup"}
|
||||
|
||||
apk_opt_wait="--wait 30"
|
||||
|
||||
# read config
|
||||
ABUILD_CONF=${ABUILD_CONF:-"$sysconfdir/abuild.conf"}
|
||||
[ -f "$ABUILD_CONF" ] && . "$ABUILD_CONF"
|
||||
|
||||
default_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"
|
||||
}
|
||||
|
||||
monochrome() {
|
||||
NORMAL=""
|
||||
STRONG=""
|
||||
RED=""
|
||||
GREEN=""
|
||||
YELLOW=""
|
||||
BLUE=""
|
||||
}
|
||||
|
||||
#colors
|
||||
if [ -n "$USE_COLORS" ]; then
|
||||
default_colors
|
||||
fi
|
||||
|
||||
# run optional log command for remote logging
|
||||
logcmd() {
|
||||
${ABUILD_LOG_CMD:-true} "$@"
|
||||
return 0
|
||||
}
|
||||
|
||||
# functions
|
||||
# we override the default msg, warning and error as we want the pkgname
|
||||
msg() {
|
||||
[ -n "$quiet" ] && return 0
|
||||
local prompt="$GREEN>>>${NORMAL}"
|
||||
@ -67,12 +45,6 @@ msg() {
|
||||
printf "${prompt} ${name}${fake}: %s\n" "$1" >&2
|
||||
}
|
||||
|
||||
msg2() {
|
||||
[ -n "$quiet" ] && return 0
|
||||
# ">>> %s"
|
||||
printf " %s\n" "$1" >&2
|
||||
}
|
||||
|
||||
warning() {
|
||||
local prompt="${YELLOW}>>> WARNING:${NORMAL}"
|
||||
local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
|
||||
@ -80,11 +52,6 @@ warning() {
|
||||
printf "${prompt} ${name}${fake}: %s\n" "$1" >&2
|
||||
}
|
||||
|
||||
warning2() {
|
||||
# ">>> WARNING:
|
||||
printf " %s\n" "$1" >&2
|
||||
}
|
||||
|
||||
error() {
|
||||
local prompt="${RED}>>> ERROR:${NORMAL}"
|
||||
local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
|
||||
@ -93,17 +60,6 @@ error() {
|
||||
logcmd "ERROR: $pkgname: $1"
|
||||
}
|
||||
|
||||
error2() {
|
||||
# ">>> ERROR:
|
||||
printf " %s\n" "$1" >&2
|
||||
}
|
||||
|
||||
set_xterm_title() {
|
||||
if [ "$TERM" = xterm ] && [ -n "$USE_COLORS" ]; then
|
||||
printf "\033]0;$1\007" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
cross_compiling() {
|
||||
test "$CBUILD" != "$CHOST" -a -n "$CBUILDROOT"
|
||||
}
|
||||
@ -1862,30 +1818,11 @@ snapshot() {
|
||||
fi
|
||||
}
|
||||
|
||||
hostspec_to_arch() {
|
||||
case "$1" in
|
||||
arm*-*-*-*eabi) echo "armel" ;;
|
||||
arm*-*-*-*eabihf) echo "armhf" ;;
|
||||
i[0-9]86-*-*-*) echo "x86" ;;
|
||||
x86_64-*-*-*) echo "x86_64" ;;
|
||||
*) echo "unknown" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
hostspec_to_libc() {
|
||||
case "$1" in
|
||||
*-*-*-uclibc*) echo "uclibc" ;;
|
||||
*-*-*-musl*) echo "musl" ;;
|
||||
*-*-*-gnu*) echo "eglibc" ;;
|
||||
*) echo "uclibc" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
usage() {
|
||||
echo "$program $abuild_ver"
|
||||
echo "usage: $program [options] [-i PKG] [-P REPODEST] [-p PKGDEST]"
|
||||
echo "$prog $abuild_ver"
|
||||
echo "usage: $prog [options] [-i PKG] [-P REPODEST] [-p PKGDEST]"
|
||||
echo " [-s SRCDEST] [cmd] ..."
|
||||
echo " $program [-c] -n PKGNAME[-PKGVER]"
|
||||
echo " $prog [-c] -n PKGNAME[-PKGVER]"
|
||||
echo "Options:"
|
||||
echo " -c Enable colored output"
|
||||
echo " -d Disable dependency checking"
|
||||
@ -1932,7 +1869,7 @@ unset force
|
||||
unset recursive
|
||||
while getopts "cdfFhi:kimnp:P:qrRs:u" opt; do
|
||||
case $opt in
|
||||
'c') default_colors
|
||||
'c') enable_colors
|
||||
color_opt="-c";;
|
||||
'd') nodeps=1;;
|
||||
'f') force="-f";;
|
||||
@ -1940,7 +1877,7 @@ while getopts "cdfFhi:kimnp:P:qrRs:u" opt; do
|
||||
'h') usage;;
|
||||
'i') install_after="$install_after $OPTARG";;
|
||||
'k') keep="-k";;
|
||||
'm') monochrome
|
||||
'm') disable_colors
|
||||
color_opt="-m";;
|
||||
'n') die "Use newapkbuild to create new aports";;
|
||||
'p') PKGDEST=$OPTARG;;
|
||||
@ -1975,13 +1912,6 @@ repo=${repo##*/}
|
||||
SRCDEST=${SRCDEST:-$startdir}
|
||||
PKGDEST=${PKGDEST:-$startdir}
|
||||
|
||||
[ -z "$CBUILD" ] && CBUILD="$CHOST"
|
||||
[ -z "$CTARGET" ] && CTARGET="$CHOST"
|
||||
[ -z "$CARCH" ] && CARCH="$(hostspec_to_arch $CHOST)"
|
||||
[ -z "$CLIBC" ] && CLIBC="$(hostspec_to_libc $CHOST)"
|
||||
[ -z "$CTARGET_ARCH" ] && CTARGET_ARCH="$(hostspec_to_arch $CTARGET)"
|
||||
[ -z "$CTARGET_LIBC" ] && CTARGET_LIBC="$(hostspec_to_libc $CTARGET)"
|
||||
|
||||
# set a default CC
|
||||
: ${CC:=gcc}
|
||||
export CC
|
||||
|
129
functions.sh.in
Normal file → Executable file
129
functions.sh.in
Normal file → Executable file
@ -3,6 +3,25 @@
|
||||
sysconfdir=@sysconfdir@
|
||||
prog=${0##*/}
|
||||
|
||||
hostspec_to_arch() {
|
||||
case "$1" in
|
||||
arm*-*-*-*eabi) echo "armel" ;;
|
||||
arm*-*-*-*eabihf) echo "armhf" ;;
|
||||
i[0-9]86-*-*-*) echo "x86" ;;
|
||||
x86_64-*-*-*) echo "x86_64" ;;
|
||||
*) echo "unknown" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
hostspec_to_libc() {
|
||||
case "$1" in
|
||||
*-*-*-uclibc*) echo "uclibc" ;;
|
||||
*-*-*-musl*) echo "musl" ;;
|
||||
*-*-*-gnu*) echo "eglibc" ;;
|
||||
*) echo "uclibc" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
readconfig() {
|
||||
local _APORTSDIR _BUILDDIR _PKGDEST _SRCPKGDEST _REPODEST _SRCDEST
|
||||
local _CARCH _CHOST _CTARGET _CPPFLAGS _CFLAGS _CXXFLAGS _LDFLAGS
|
||||
@ -64,10 +83,17 @@ readconfig() {
|
||||
MAKEFLAGS=${_MAKEFLAGS-$MAKEFLAGS}
|
||||
PACKAGER=${_PACKAGER-$PACKAGER}
|
||||
USE_COLORS=${_USE_COLORS-$USE_COLORS}
|
||||
|
||||
[ -z "$CBUILD" ] && CBUILD="$CHOST"
|
||||
[ -z "$CTARGET" ] && CTARGET="$CHOST"
|
||||
[ -z "$CARCH" ] && CARCH="$(hostspec_to_arch $CHOST)"
|
||||
[ -z "$CLIBC" ] && CLIBC="$(hostspec_to_libc $CHOST)"
|
||||
[ -z "$CTARGET_ARCH" ] && CTARGET_ARCH="$(hostspec_to_arch $CTARGET)"
|
||||
[ -z "$CTARGET_LIBC" ] && CTARGET_LIBC="$(hostspec_to_libc $CTARGET)"
|
||||
|
||||
}
|
||||
readconfig
|
||||
|
||||
|
||||
# expects $1 to be a package directory in the aports tree ('foo' or 'main/foo')
|
||||
# outputs APKBUILD's path if successful
|
||||
aports_buildscript() {
|
||||
@ -92,55 +118,68 @@ any_buildscript() {
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# output functions
|
||||
case $prog in
|
||||
abuild)
|
||||
if [ -n "$USE_COLORS" ]; then
|
||||
NORMAL="\033[1;0m"
|
||||
STRONG="\033[1;1m"
|
||||
RED="\033[1;31m"
|
||||
GREEN="\033[1;32m"
|
||||
YELLOW="\033[1;33m"
|
||||
BLUE="\033[1;34m"
|
||||
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
|
||||
}
|
||||
|
||||
msg() {
|
||||
local prompt="$GREEN>>>${NORMAL}"
|
||||
local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
|
||||
local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
|
||||
if [ -z "$quiet" ]; then
|
||||
printf "${prompt} ${name}${fake}: $@\n" >&2
|
||||
fi
|
||||
}
|
||||
disable_colors() {
|
||||
NORMAL=""
|
||||
STRONG=""
|
||||
RED=""
|
||||
GREEN=""
|
||||
YELLOW=""
|
||||
BLUE=""
|
||||
}
|
||||
|
||||
warning() {
|
||||
local prompt="${YELLOW}>>> WARNING:${NORMAL}"
|
||||
local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
|
||||
local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
|
||||
printf "${prompt} ${name}${fake}: $@\n" >&2
|
||||
}
|
||||
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"
|
||||
}
|
||||
|
||||
error() {
|
||||
local prompt="${RED}>>> ERROR:${NORMAL}"
|
||||
local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
|
||||
local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
|
||||
printf "${prompt} ${name}${fake}: $@\n" >&2
|
||||
}
|
||||
;;
|
||||
*)
|
||||
msg() {
|
||||
# Here we write to stdout, but abuild's fancier messages write to stderr
|
||||
if [ -z "$quiet" ]; then
|
||||
echo "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
error() {
|
||||
echo "$prog: $@" >&2
|
||||
}
|
||||
;;
|
||||
esac
|
||||
if [ -n "$USE_COLORS" ]; then
|
||||
enable_colors
|
||||
else
|
||||
disable_colors
|
||||
fi
|
||||
|
||||
# caller may override
|
||||
cleanup() {
|
||||
|
Loading…
Reference in New Issue
Block a user