Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
710 lines (628 sloc) 21.2 KB
#!/bin/bash
CAVEATS=()
pushd() {
command pushd "$@" > /dev/null
}
popd() {
command popd "$@" > /dev/null
}
pushd_src() {
pushd "$SRCDIR"
}
popd_src() {
popd
}
do_configure() {
fetch_file 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=7d3d27baf8107b630586c962c057e22149653deb' 5aee40a0666b38552df04e875939c10776cae149 config.guess CONFIGGUESS
fetch_file 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=7d3d27baf8107b630586c962c057e22149653deb' 1663dc7d1066e931fec23175357a9acc72ea545d config.sub CONFIGSUB
local STARTTIME="$SECONDS"
# replace config.sub and config.guess with newer ones
find "$SRCDIR" -name config.sub -exec install -v "$CACHEDIR/config.sub" {} \;
find "$SRCDIR" -name config.guess -exec install -v "$CACHEDIR/config.guess" {} \;
NORM_EXTRAOPTS=()
fgrep -q 'Generated by GNU Autoconf' "$SRCDIR/configure" && NORM_EXTRAOPTS+=(--disable-static --enable-shared --enable-fast-install)
fgrep -q disable-static "$SRCDIR/configure" && NORM_EXTRAOPTS+=(--disable-static)
fgrep -q enable-shared "$SRCDIR/configure" && NORM_EXTRAOPTS+=(--enable-shared)
fgrep -q disable-fast-install "$SRCDIR/configure" && NORM_EXTRAOPTS+=(--enable-fast-install)
fgrep -q enable-fast-install "$SRCDIR/configure" && NORM_EXTRAOPTS+=(--enable-fast-install)
fgrep -q disable-silent-rules "$SRCDIR/configure" && NORM_EXTRAOPTS+=(--disable-silent-rules)
fgrep -q disable-dependency-tracking "$SRCDIR/configure" && NORM_EXTRAOPTS+=(--disable-dependency-tracking)
fgrep -q enable-rpath "$SRCDIR/configure" && NORM_EXTRAOPTS+=(--enable-rpath)
log "Configuring $FORMULA ${NORM_EXTRAOPTS[@]} --prefix=\"$PREFIX\" $@"
"$SRCDIR"/configure "${NORM_EXTRAOPTS[@]}" --prefix="$PREFIX" "$@" || return 1
local ELAPSED="$(($SECONDS - $STARTTIME))"
log "Configuring $FORMULA took $ELAPSED seconds"
}
do_cmake() {
local STARTTIME="$SECONDS"
log "Configuring $FORMULA $@"
cmake "$SRCDIR" -DCMAKE_INSTALL_PREFIX=$ESCAPED_PREFIX \
-DCMAKE_BUILD_TYPE=Release \
-Wno-dev \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DCMAKE_MACOSX_RPATH=1 \
-DCMAKE_SYSTEM_PREFIX_PATH=$ESCAPED_PREFIX \
-DCMAKE_INCLUDE_PATH=$ESCAPED_PREFIX/include \
-DCMAKE_LIBRARY_PATH:PATH="$PREFIX/lib" \
-DCMAKE_C_FLAGS="$CPPFLAGS" \
-DCMAKE_CXX_FLAGS="$CPPFLAGS" \
-DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS" "$@"
local ELAPSED="$(($SECONDS - $STARTTIME))"
log "Configuring $FORMULA took $ELAPSED seconds"
}
do_auto_configure() {
if [ -e "$SRCDIR"/configure ]; then
do_configure "$@" || return 1
elif [ -e "$SRCDIR"/CMakeLists.txt ] && hash cmake 2>/dev/null; then
do_cmake "$@" || return 1
else
log "Couldn't figure out how to configure formula '$FORMULA', bailing out"
return 1
fi
}
do_make() {
local STARTTIME="$SECONDS"
log "Making $FORMULA $@"
local PARALLEL="-j$NUMJOBS"
[ "$NOPARALLEL" = "1" ] && PARALLEL=
[ "$NEEDV1" = "1" ] && set V=1 "$@"
make $PARALLEL "$@" || return 1
local ELAPSED="$(($SECONDS - $STARTTIME))"
log "Making $FORMULA took $ELAPSED seconds"
}
do_install() {
local STARTTIME="$SECONDS"
log "Installing $FORMULA $@"
make install "$@" || return 1
local ELAPSED="$(($SECONDS - $STARTTIME))"
log "Installing $FORMULA took $ELAPSED seconds"
}
do_make_and_install() {
do_make "$@" || return 1
do_install "$@" || return 1
}
do_test() {
if ! is_without tests; then
local STARTTIME="$SECONDS"
log "Doing tests for $FORMULA"
env - PATH="$PATH" CTEST_OUTPUT_ON_FAILURE=1 make check "$@" ||
env - PATH="$PATH" CTEST_OUTPUT_ON_FAILURE=1 make test "$@" ||
env - PATH="$PATH" CTEST_OUTPUT_ON_FAILURE=1 make tests "$@" || return 1
local ELAPSED="$(($SECONDS - $STARTTIME))"
log "Doing tests for $FORMULA took $ELAPSED seconds"
fi
}
do_compile_notest() {
pushd_src || return 1
do_auto_configure "$@" || return 1
do_make_and_install || return 1
popd || return 1
}
do_compile_test() {
pushd_src || return 1
do_auto_configure "$@" || return 1
do_make || return 1
do_test || return 1
do_install || return 1
popd || return 1
}
do_compile_outside_notest() {
BUILDDIR="$SRCDIR"-build
rm -rf "$BUILDDIR" || return 1
mkdir -p "$BUILDDIR" || return 1
pushd "$BUILDDIR" || return 1
do_auto_configure "$@" || return 1
do_make_and_install || return 1
popd || return 1
}
do_compile_outside_test() {
BUILDDIR="$SRCDIR"-build
rm -rf "$BUILDDIR" || return 1
mkdir -p "$BUILDDIR" || return 1
pushd "$BUILDDIR" || return 1
do_auto_configure "$@" || return 1
do_make || return 1
do_test || return 1
do_install || return 1
popd || return 1
}
check_input_filter_exists_and_set() {
if ! hash "$1" 2>/dev/null; then
log_error "Error: \"$1\" is not available, you must install it."
log_error
log_error Try:
log_error " norm install $1"
exit 1
fi
export INPUT_FILTER="$@"
}
do_untar() {
[ -z "$1" ] && set -- "$CACHEDIR/$TARNAME"
[ -z "$2" ] && set -- "$1" "$SRCDIR"
local INPUT_TARFILE="$1"
local OUTPUT_DIR="$2"
shift 2
INPUT_FILTER="cat"
## we can't rely on tar being able to identify .xz -- some users had systems that had tar so old it didn't know about .xz or .bz2
case "$INPUT_TARFILE" in
*.tar) check_input_filter_exists_and_set cat ;;
*.tar.gz |*.tgz) check_input_filter_exists_and_set gzip -d ;;
*.tar.bz2|*.tbz) check_input_filter_exists_and_set bzip2 -d ;;
*.tar.xz |*.txz) check_input_filter_exists_and_set xz -d ;;
*) log "Couldn't identify tar format for $INPUT_TARFILE" && return 1;;
esac
cat "$INPUT_TARFILE" | $INPUT_FILTER | tar xf - -C "$OUTPUT_DIR" --strip-components 1 "$@" || return 1
return 0
}
##
## unpacks source code
## sets global SRCDIR and TARNAME
##
## usage: do_unpack <-- gets filename from fetch_source
##
## alternative usage: do_unpack foo-1.2.3.tar.bz2
do_unpack() {
[ -f "$CACHEDIR/$1" ] && TARNAME="$1" && shift
[ -z "$TARNAME" ] && log "TARNAME is empty!" && return 1
SRCDIR="$COMPILEDIR/$FORMULA/$TARNAME"
log "Unpacking $TARNAME"
rm -rf "$SRCDIR" || return 1
mkdir -p "$SRCDIR" || return 1
do_untar "$CACHEDIR/$TARNAME" "$SRCDIR" "$@" || return 1
log "Unpacked $TARNAME"
}
##
## unpacks source code inside other formula's source code
##
## usage: intree_unpack <-- unpacks into same directory of do_unpack'ed formula
## usage: intree_unpack tools/clang <-- unpacks into tools/clang subdirectory
intree_unpack() {
log "Unpacking $TARNAME into $SRCDIR/$1"
pushd_src
if [ -n "$1" ]; then
mkdir -p "$1"
do_untar "$CACHEDIR/$TARNAME" "$1"
fi
if [ -z "$1" ]; then
# mv -n would've worked better, but not all versions of mv have that flag
mkdir -p "$TARNAME"
do_untar "$CACHEDIR/$TARNAME" "$TARNAME"
for x in "$TARNAME"/*; do
local file=${x#$TARNAME/}
[ ! -e "$file" ] && ln -s "$x" .
done
fi
popd
log "Unpacked $TARNAME into $SRCDIR/$1"
}
##
## unpacks source code and applies debian patches
## sets global TARNAME and DEBPATCH
##
## usage: do_undebian <-- gets filenames from fetch_source and fetch_debian
##
## alternative usage: do_undebian foo-1.2.3.orig.tar.bz2 foo-1.2.3.debian.tar.gz
do_undebian() {
[ -f "$CACHEDIR/$1" ] && TARNAME="$1"
[ -f "$CACHEDIR/$2" ] && DEBPATCH="$2"
[ -z "$DEBPATCH" ] && log_error "Error: do_undebian was called but fetch_debian was not called in this formula" && exit 1
## sets SRCDIR
do_unpack "$TARNAME" || return 1
do_debianize "$DEBPATCH" || return 1
}
##
## applies debian patches, sets global DEBPATCH
##
## usage: do_debianize <-- gets filename from fetch_debian
##
## alternative usage: do_debianize foo-1.2.3.debian.tar.gz
do_debianize() {
[ -f "$CACHEDIR/$1" ] && DEBPATCH="$1"
[ -z "$DEBPATCH" ] && log_error "Error: do_debianize was called but fetch_debian was not called in this formula" && exit 1
do_undebian_overlay "$DEBPATCH"
do_debian_patches
}
do_undebian_overlay() {
[ -f "$CACHEDIR/$1" ] && DEBPATCH="$1"
[ -z "$DEBPATCH" ] && log_error "Error: do_undebian_overlay was called but fetch_debian was not called in this formula" && exit 1
## unpack debian overlay -- try tar, gzip, xz, bz
INPUT_FILTER="cat"
case "$DEBPATCH" in
*.diff) check_input_filter_exists_and_set cat ;;
*.diff.gz) check_input_filter_exists_and_set gzip -d ;;
*.diff.xz) check_input_filter_exists_and_set xz -d ;;
*.diff.bz2) check_input_filter_exists_and_set bzip2 -d ;;
*) do_untar "$CACHEDIR/$DEBPATCH" "$SRCDIR" --strip-components 0 && return 0 ;;
esac
cat "$CACHEDIR/$DEBPATCH" | $INPUT_FILTER | patch -f -p1 -i - -d "$SRCDIR" || return 1
}
do_debian_patches() {
## apply debian patches
local SERIES="$SRCDIR"/debian/patches/series
local SERIES2="$SRCDIR"/debian/patches-applied/series
local PATCHES="$SRCDIR"/debian/patches/*.patch
if [ -e "$SERIES" ]; then
PATCHES=`cat "$SERIES"|sed -e "s/#.*$//g" -e "s|^|$SRCDIR/debian/patches/|"`
elif [ -e "$SERIES2" ]; then
PATCHES=`cat "$SERIES2"|sed -e "s/#.*$//g" -e "s|^|$SRCDIR/debian/patches-applied/|"`
fi
for i in $PATCHES; do
[ -e "$i" ] || continue
[ ! -d "$i" ] || continue
log Applying patch "$i"
patch -f -p1 -i "$i" -d "$SRCDIR" ||
patch -f -p0 -i "$i" -d "$SRCDIR" ||
patch -f -p2 -i "$i" -d "$SRCDIR" || true
done
}
##
## unpacks source code, applies debian patches, runs configure, make, install
##
## usage: do_undebian_compile <-- gets filenames from fetch_source and fetch_debian
##
## alternative usage: do_undebian_compile foo-1.2.3.orig.tar.bz2 foo-1.2.3.debian.tar.gz
do_undebian_compile_test() {
if [ -f "$CACHEDIR/$1" -a -f "$CACHEDIR/$2" ]; then
TARNAME="$1"
DEBPATCH="$2"
shift 2
fi
do_undebian || return 1
do_compile_test "$@" || return 1
}
##
## same as do_undebian_compile, but run test suite before install
##
do_undebian_compile_notest() {
if [ -f "$CACHEDIR/$1" -a -f "$CACHEDIR/$2" ]; then
TARNAME="$1"
DEBPATCH="$2"
shift 2
fi
do_undebian || return 1
do_compile_notest "$@" || return 1
}
##
## unpacks source code, runs do_compile_test
##
## usage: do_unpack_compile <-- gets filename from fetch_source
do_unpack_compile_test() {
if [ -f "$CACHEDIR/$1" ]; then
TARNAME="$1"
shift 1
fi
do_unpack "$TARNAME" || return 1
do_compile_test "$@" || return 1
}
##
## same as do_unpack_compile_test, but doesn't run test suite before install
##
do_unpack_compile_notest() {
if [ -f "$CACHEDIR/$1" ]; then
TARNAME="$1"
shift 1
fi
do_unpack "$TARNAME" || return 1
do_compile_notest "$@" || return 1
}
##
## applies a patch in $SRCDIR, takes it from 'patches' directory in NORM
## default is -p1, but you can override that after patchname
##
## usage: do_patch gcc-4.9.2-multiarch-support.patch
## usage: do_patch binutils-multiarch-support.patch -p2
##
do_patch() {
local PATCHNAME="$1"
shift
local FULLPATH="$NORMDIR/patches/$PATCHNAME"
if [ ! -e "$FULLPATH" ]; then
FULLPATH="$CACHEDIR/$PATCHNAME"
fi
if [ ! -e "$FULLPATH" ]; then
log "do_patch() was given a filename that doesn't exist"
return 1
fi
patch -p1 -f -i "$FULLPATH" -d "$SRCDIR" "$@" || return 1
}
do_patch_inline() {
patch -p1 -l -N -f -d "$SRCDIR" "$@" || return 1
}
do_autoreconf() {
pushd_src || return 1
autoreconf -f -i -v || return 1
popd || return 1
}
## usage: compile_formula FORMULA [what formula asked for this one]
## note about force option -- it's passed as parameter so forcing formula A won't force formula B that A depends on
compile_formula() {
local COMPILING_FOR force FORMULA
local DATE=`LANG=C LC_ALL=C date`
[ "$1" == "-f" ] && force=-f && shift
FORMULA="$1"
[ ! -e "$NORMDIR"/packages/"$FORMULA" ] && log_error "Error: Formula file '$FORMULA' does not exist" && return 1
local SHA1SUM=`$SHASUM_BIN "$NORMDIR/packages/$FORMULA" | cut -f1 -d' '`
[ -n "$2" ] && COMPILING_FOR="$2"
local STATEDIR="$PREFIX"/var/norm
local NEEDS_INSTALLING=true
[[ -e "$STATEDIR"/"$FORMULA".installed ]] && fgrep -q "$SHA1SUM" "$STATEDIR"/"$FORMULA".installed && local NEEDS_INSTALLING=false
[[ -n "$force" ]] && local NEEDS_INSTALLING=true
if [[ "$NEEDS_INSTALLING" == "true" ]]; then
[ -z "$COMPILING_FOR" ] && log "Building formula: $FORMULA" \
|| log "Building formula: $FORMULA -- dependency of $COMPILING_FOR"
## scan if we need bzip2 or xz
fgrep -q '.xz' "$NORMDIR"/packages/"$FORMULA" && needs_tool xz
fgrep -q '.bz2' "$NORMDIR"/packages/"$FORMULA" && needs_tool bzip2
unset DEBPATCH
local STARTTIME="$SECONDS"
. "$NORMDIR"/packages/"$FORMULA"
mkdir -p `dirname "$STATEDIR/$FORMULA"`
local ELAPSED="$(($SECONDS - $STARTTIME))"
log_success "$ELAPSED"
echo "[$DATE] $SHA1SUM $ELAPSED $COMPILING_FOR" >> "$STATEDIR/$FORMULA".installed
## remove artifacts
if [[ -z "$norm_keep_sources" && -n "$COMPILEDIR" && -n "$FORMULA" ]]; then
rm -rf "$COMPILEDIR/$FORMULA"
fi
else
[ -z "$COMPILING_FOR" ] && log "Formula already installed: $FORMULA"
echo "[$DATE] $SHA1SUM 0 $COMPILING_FOR" >> "$STATEDIR/$FORMULA".installed
fi
}
toolbinary() {
case "$1" in
tcl) echo "tclsh" ;;
intltool) echo "intltoolize" ;;
libtool) echo "libtoolize" ;;
*) echo "$1" ;;
esac
}
needs_tool() {
for i; do
local binary=$(toolbinary $i)
if ! hash "$binary" 2>/dev/null; then
log "System does not have tool $i, will build our own"
compile_formula "$i" $FORMULA
fi
done
}
depends_on() {
for i; do
compile_formula "$i" $FORMULA
done
}
do_download() {
[[ -z $2 ]] && log "do_download() needs two arguments" && return 1
local URL="$1"
local SAVETO="$2"
case "$DOWNLOADER" in
wget) wget "$URL" -O "$SAVETO" ;;
curl) curl --fail -L -R "$URL" -o "$SAVETO" ;;
*) log "\$DOWNLOADER is unknown ($DOWNLOADER)" && return 1 ;;
esac
}
check_sha1() {
local FILEPATH="$1"
local SHA1="$2"
## if file does not exist, do nothing
[ -s "$FILEPATH" ] || return 1
## get SHA1
local SHA1SUM=`$SHASUM_BIN "$FILEPATH" | cut -f1 -d' '`
## if no hash provided, print it and do nothing
if [ -z "$SHA1" ]; then
log "For future -- SHA1 of $FILENAME is $SHA1SUM"
return 0
fi
## we're good to go, compare the checksums
if [ "$SHA1SUM" != "$SHA1" ]; then
log "SHA1sum mismatch! $SHA1SUM vs $SHA1 for file $FILEPATH"
return 1
fi
## they match
return 0;
}
##
## usage: fetch_file http://example.com/file.tar.gz AABBCC [optional_output_filename]
## sets FILENAME
fetch_file() {
[ -z "$1" ] && log "fetch_file() needs at least 1 argument" && return 1
local URL="$1"
local SHA1="$2"
local VARNAME="FILENAME"
[ -n "$4" ] && VARNAME="$4"
export $VARNAME=`basename -- "$URL"`
[ -n "$3" ] && export $VARNAME="$3"
local FILEPATH="$CACHEDIR/${!VARNAME}"
mkdir -p "$CACHEDIR"
if ! check_sha1 "$FILEPATH" "$SHA1"; then
log "Downloading $URL"
rm -f "$FILEPATH"
local TEMPFILE=`mktemp "$FILEPATH.XXXXXX"`
do_download "$URL" "$TEMPFILE" || (rm -f "$TEMPFILE" && return 1)
mv -f "$TEMPFILE" "$FILEPATH"
fi
if ! check_sha1 "$FILEPATH" "$SHA1"; then
return 1
fi
}
##
## usage: fetch_source http://example.com/file.tar.gz AABBCC [optional_output_filename]
## sets TARNAME
fetch_source() {
local URL="$1"
local CHECKSUM="$2"
local NEWNAME="${FORMULA}"_`basename -- "$URL"`
[ -n "$3" ] && NEWNAME="$3"
fetch_file "$URL" "$CHECKSUM" "$NEWNAME" "TARNAME"
}
##
## usage: fetch_debian http://example.com/file.tar.gz AABBCC [optional_output_filename]
## sets DEBPATCH
fetch_debian() {
local URL="$1"
local CHECKSUM="$2"
local NEWNAME="$3"
DEBPATCH="${FORMULA}_"`basename -- "$URL"`
[ -z "$NEWNAME" ] && NEWNAME="$DEBPATCH"
fetch_file "$URL" "$CHECKSUM" "$NEWNAME"
}
##
## example: test_cc 'int main() { return 0;}' -O2
test_cc() {
CODE="$1"
shift
[[ -z $QUIET ]] && echo -n "Testing if $CC compiles '$CODE' $@... "
TEMPFILE=`mktemp`
ERRFILE=`mktemp`
echo "$CODE" | $CC -x c "$@" -Werror -o "$TEMPFILE" - 2>"$ERRFILE" || true
local STATUS=${PIPESTATUS[1]}
rm -f "$TEMPFILE" "$ERRFILE"
[[ -z $QUIET && $STATUS == 0 ]] && echo "yes"
[[ -z $QUIET && $STATUS != 0 ]] && echo "no"
[ -n "$STATUS" ] && return $STATUS
return 1
}
##
## example: test_cc 'int main() { return 0;}' -O2
test_cc_quiet() {
local QUIET=1
test_cc "$@"
}
##
## example: cc_checkflags -Wl,-Bsymbolic -O2
cc_checkflags() {
[[ -z $QUIET ]] && echo -n "Testing if $CC supports $@... "
test_cc_quiet 'int main() { return 0;}' "$@"
local STATUS=$?
[[ $STATUS == 0 ]] && [[ -z $QUIET ]] && echo "yes"
[[ $STATUS != 0 ]] && [[ -z $QUIET ]] && echo "no"
return $STATUS
}
##
## check if compiler will accept the flag
## first one accepted is added to specified variable
##
## example: cc_addflag EXTRA_CFLAGS -march=native -march=core2 -march=i686
## example: cc_addflag EXTRA_CFLAGS -Wextra -W
cc_addflag() {
[ -z "$1" -o -z "$2" ] && return
local value VARNAME=$1
shift 1
for value; do
[[ "${!VARNAME}" =~ (^| )$value( |$) ]] && return # already have it
cc_checkflags $CFLAGS ${!VARNAME} $value || continue
export $VARNAME="${!VARNAME} $value"
return
done
}
##
## check if compiler will accept the flags
## any flag that gets accepted will be added to specified variable
cc_addflags() {
[ -z "$1" -o -z "$2" ] && return
local value VARNAME=$1
shift 1
for value; do
[[ "${!VARNAME}" =~ (^| )$value( |$) ]] && continue # already have it
cc_checkflags $CFLAGS ${!VARNAME} $value || continue
export $VARNAME="${!VARNAME} $value"
done
}
## test_cc_expr "fcntl.h" "int a = O_CLOEXEC"
test_cc_expr() {
test_cc "#define _GNU_SOURCE
#include <$1>
int main() { $2; return 0;}"
}
## test_cc_value "fcntl.h" "O_CLOEXEC"
test_cc_value() {
test_cc_expr "$1" "int a = $2"
}
## test_cc_func "stdio.h" 'printf("Hello, world!\n");'
test_cc_func() {
test_cc_expr "$1" "$2"
}
is_cc_clang() {
RES=`$CC --version 2>&1 | fgrep clang | wc -l`
[[ $RES == 1 ]] && return 0
return 1
}
## Example: have_gcc 4.7
have_gcc() {
[ -z "$1" ] && log "have_gcc() needs an argument" && return 1
local HAVE_GCC_RAW=`$CC -dumpversion`
local HAVE_GCC=`echo "$HAVE_GCC_RAW" | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$/&00/'`
local ASKED_GCC=`echo "$1" | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$/&00/'`
[ "$HAVE_GCC" -lt "$ASKED_GCC" ] && return 1
return 0
}
## Example: require_gcc 4.7
## Same as have_gcc, but prints a message doesn't print a message
requires_gcc() {
[ -z "$1" ] && log "require_gcc() needs an argument" && return 1
if ! have_gcc "$1"; then
local NEED_GCC_RAW="$1"
shift
local HAVE_GCC_RAW=`$CC -dumpversion`
log "Formula $FORMULA needs GCC at least $NEED_GCC_RAW $@"
log "You have $HAVE_GCC_RAW"
log ""
log "Type 'norm install gcc' to install fresh gcc"
exit 1 ## we don't want onerror() to type 'formula failed to build'
fi
return 0
}
add_to_ccache() {
mkdir -p $PREFIX/bin/ccache_wrap
for name in "$@"; do
ln -fs ../ccache $PREFIX/bin/ccache_wrap/"$name"
done
}
add_caveat() {
CAVEATS+=("Formula $FORMULA has a message for you:")
for line; do
CAVEATS+=("$line")
done
CAVEATS+=("")
}
is_without() {
[ -z "$1" ] && return 1
[[ "$1" == *" "* ]] && return ## don't allow whitespace
local name=is_without_${1}
[ -n "${!name}" ] && return 0
return 1
}
is_with() {
[ -z "$1" ] && return 1
[[ "$1" == *" "* ]] && return ## don't allow whitespace
local name=is_with_${1}
[ -n "${!name}" ] && return 0
return 1
}
set_without() {
[ -z "$1" ] && return
[[ "$1" == *" "* ]] && return ## don't allow whitespace
log Setting without "$1"
printf -v "is_without_${1}" %s "1"
}
set_with() {
[ -z "$1" ] && return
[[ "$1" == *" "* ]] && return ## don't allow whitespace
log Setting with "$1"
printf -v "is_with_${1}" %s "1"
}
in_array() {
local haystack="${1}[@]"
local needle="${2}"
for i in ${!haystack}; do
if [[ ${i} == ${needle} ]]; then
return 0
fi
done
return 1
}
## oneliners that control default behaviour
do_compile() { do_compile_notest "$@" || return 1; }
do_compile_outside() { do_compile_outside_notest "$@" || return 1; }
do_undebian_compile() { do_undebian_compile_notest "$@"; }
do_unpack_compile() { do_unpack_compile_notest "$@"; }