summaryrefslogtreecommitdiff
path: root/functions.sh.in
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2013-10-25 07:07:50 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2013-10-25 07:18:11 +0000
commit0c02afc69441095eba819cbe572b74c45de878b8 (patch)
treee07594a56b41cde64cdb29ee0b3fc4cae60c9b82 /functions.sh.in
parent7a447caf05ec70c35c9df4d5211b9dd3828e6b6a (diff)
downloadabuild-0c02afc69441095eba819cbe572b74c45de878b8.tar.gz
abuild-0c02afc69441095eba819cbe572b74c45de878b8.tar.bz2
abuild-0c02afc69441095eba819cbe572b74c45de878b8.tar.xz
abuild-0c02afc69441095eba819cbe572b74c45de878b8.zip
abuild: move various functions to the shared functions.sh
specifically, every script that reads/parses ./APKBUILD needs to set CARCH.
Diffstat (limited to 'functions.sh.in')
-rwxr-xr-x[-rw-r--r--]functions.sh.in131
1 files changed, 85 insertions, 46 deletions
diff --git a/functions.sh.in b/functions.sh.in
index f1db66c..7631310 100644..100755
--- a/functions.sh.in
+++ b/functions.sh.in
@@ -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
- }
-
- warning() {
- local prompt="${YELLOW}>>> WARNING:${NORMAL}"
- local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
- local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
- printf "${prompt} ${name}${fake}: $@\n" >&2
- }
-
- 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
- }
+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"
+}
- error() {
- echo "$prog: $@" >&2
- }
- ;;
-esac
+if [ -n "$USE_COLORS" ]; then
+ enable_colors
+else
+ disable_colors
+fi
# caller may override
cleanup() {