Lakka-LibreELEC/scripts/unpack

190 lines
6.2 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2018-07-16 18:45:36 +00:00
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv)
2009-03-18 12:02:53 +00:00
. config/options $1
2009-03-18 12:02:53 +00:00
if [ -z "$1" ]; then
echo "usage: $0 package_name"
exit 1
fi
if [ ! -f $PKG_DIR/package.mk ]; then
printf "$(print_color CLR_ERROR "$1: no package.mk file found")\n"
exit 1
fi
2014-01-27 13:05:34 +00:00
$SCRIPTS/get $1
2016-06-08 07:13:39 +00:00
STAMP=$PKG_BUILD/.libreelec-unpack
2014-01-27 13:05:34 +00:00
2009-03-18 12:02:53 +00:00
mkdir -p $BUILD
2017-03-23 14:59:46 +00:00
# Perform a wildcard match on the package to ensure old versions are cleaned too
PKG_DEEPHASH=
for i in $BUILD/$1-*; do
if [ -d $i -a -f "$i/.libreelec-unpack" ] ; then
. "$i/.libreelec-unpack"
if [ "$STAMP_PKG_NAME" = "$1" ]; then
[ -z "${PKG_DEEPHASH}" ] && PKG_DEEPHASH=$(calculate_stamp)
if [ ! "$PKG_DEEPHASH" = "$STAMP_PKG_DEEPHASH" ] ; then
$SCRIPTS/clean $1
fi
fi
2009-03-18 12:02:53 +00:00
fi
done
if [ -d "$PKG_BUILD" -a ! -f "$STAMP" ]; then
# stale pkg build dir
$SCRIPTS/clean $1
fi
[ -f "$STAMP" ] && exit 0
2009-03-18 12:02:53 +00:00
if [ -d "$SOURCES/$1" -o -d "$PKG_DIR/sources" ]; then
printf "%${BUILD_INDENT}c $(print_color CLR_UNPACK "UNPACK") $1\n" ' '>&$SILENT_OUT
export BUILD_INDENT=$((${BUILD_INDENT:-1}+$BUILD_INDENT_SIZE))
2009-03-18 12:02:53 +00:00
# unset functions
unset -f pre_unpack
unset -f unpack
unset -f post_unpack
unset -f pre_patch
unset -f post_patch
2009-03-18 12:02:53 +00:00
. $PKG_DIR/package.mk
if [ "$(type -t pre_unpack)" = "function" ]; then
pre_unpack
fi
if [ "$(type -t unpack)" = "function" ]; then
unpack
else
if [ -n "$PKG_URL" ]; then
$SCRIPTS/extract $1 $BUILD
fi
fi
if [ ! -d $BUILD/$PKG_NAME-$PKG_VERSION ]; then
if [ -n "$PKG_SOURCE_DIR" ]; then
mv $BUILD/$PKG_SOURCE_DIR $BUILD/$PKG_NAME-$PKG_VERSION
elif [ -d $BUILD/$PKG_NAME-$PKG_VERSION* ]; then
mv $BUILD/$PKG_NAME-$PKG_VERSION* $BUILD/$PKG_NAME-$PKG_VERSION
fi
fi
if [ -d "$PKG_DIR/sources" ]; then
[ ! -d "$BUILD/${PKG_NAME}-${PKG_VERSION}" ] && mkdir -p $BUILD/${PKG_NAME}-${PKG_VERSION}
cp -PRf $PKG_DIR/sources/* $BUILD/${PKG_NAME}-${PKG_VERSION}
fi
2015-08-03 12:58:14 +00:00
if [ -z "$PKG_URL" ]; then
mkdir -p "${BUILD}/${PKG_NAME}-${PKG_VERSION}"
fi
if [ "$(type -t post_unpack)" = "function" ]; then
post_unpack
fi
if [ "${PKG_SKIP_PATCHES}" != "yes" ]; then
if [ "$(type -t pre_patch)" = "function" ]; then
pre_patch
fi
if [ "$TARGET_ARCH" = "x86_64" ]; then
PATCH_ARCH="x86"
else
PATCH_ARCH="${TARGET_PATCH_ARCH:-$TARGET_ARCH}"
fi
PATCH_DIRS_PKG=""
PATCH_DIRS_PRJ=""
if [ -n "$PKG_PATCH_DIRS" ]; then
for patch_dir in $PKG_PATCH_DIRS; do
[ -d $PKG_DIR/patches/$patch_dir ] && PATCH_DIRS_PKG="$PATCH_DIRS_PKG $PKG_DIR/patches/$patch_dir/*.patch"
[ -d $PROJECT_DIR/$PROJECT/patches/$PKG_NAME/$patch_dir ] && PATCH_DIRS_PRJ="$PATCH_DIRS_PRJ $PROJECT_DIR/$PROJECT/patches/$PKG_NAME/$patch_dir/*.patch"
[ -d $PROJECT_DIR/$PROJECT/devices/$DEVICE/patches/$PKG_NAME/$patch_dir ] && PATCH_DIRS_PRJ="$PATCH_DIRS_PRJ $PROJECT_DIR/$PROJECT/devices/$DEVICE/patches/$PKG_NAME/$patch_dir/*.patch"
done
fi
2016-12-06 18:25:25 +00:00
for i in $PKG_DIR/patches/*.patch \
$PKG_DIR/patches/$PATCH_ARCH/*.patch \
$PATCH_DIRS_PKG \
$PKG_DIR/patches/$PKG_VERSION/*.patch \
$PKG_DIR/patches/$PKG_VERSION/$PATCH_ARCH/*.patch \
$PROJECT_DIR/$PROJECT/patches/$PKG_NAME/*.patch \
$PROJECT_DIR/$PROJECT/patches/$PKG_NAME/$PATCH_ARCH/*.patch \
$PATCH_DIRS_PRJ \
$PROJECT_DIR/$PROJECT/patches/$PKG_NAME/$PKG_VERSION/*.patch \
$PROJECT_DIR/$PROJECT/devices/$DEVICE/patches/$PKG_NAME/*.patch; do
thisdir="$(dirname "$i")"
if [ "$thisdir" = "$PKG_DIR/patches" ]; then
PATCH_DESC="(common)"
elif [ "$thisdir" = "$PKG_DIR/patches/$PATCH_ARCH" ]; then
PATCH_DESC="(common - $PATCH_ARCH)"
elif [ "$thisdir" = "$PKG_DIR/patches/$PKG_VERSION" ]; then
PATCH_DESC="(common - $PKG_VERSION)"
elif [ "$thisdir" = "$PKG_DIR/patches/$PKG_VERSION/$PATCH_ARCH" ]; then
PATCH_DESC="($PKG_VERSION - $PATCH_ARCH)"
elif [ "$thisdir" = "$PROJECT_DIR/$PROJECT/patches/$PKG_NAME" ]; then
PATCH_DESC="(project)"
elif [ "$thisdir" = "$PROJECT_DIR/$PROJECT/patches/$PKG_NAME/$PATCH_ARCH" ]; then
PATCH_DESC="(project - $PATCH_ARCH)"
elif [ "$thisdir" = "$PROJECT_DIR/$PROJECT/patches/$PKG_NAME/$PKG_VERSION" ]; then
PATCH_DESC="(project - $PKG_VERSION)"
elif [ "$thisdir" = "$PROJECT_DIR/$PROJECT/devices/$DEVICE/patches/$PKG_NAME" ]; then
PATCH_DESC="(device)"
else
if [[ "$thisdir" =~ ^$PKG_DIR/.* ]]; then
PATCH_DESC="(common - $(basename "$thisdir"))"
elif [[ "$thisdir" =~ ^$PROJECT_DIR/.*/devices/.* ]]; then
PATCH_DESC="(device - $(basename "$thisdir"))"
elif [[ "$thisdir" =~ ^$PROJECT_DIR/.* ]]; then
PATCH_DESC="(project - $(basename "$thisdir"))"
else
PATCH_DESC="(unknown - $(basename "$thisdir"))"
fi
fi
2009-03-18 12:02:53 +00:00
if [ -f "$i" ]; then
printf "%${BUILD_INDENT}c $(print_color CLR_APPLY_PATCH "APPLY PATCH") $(print_color CLR_PATCH_DESC "${PATCH_DESC}") ${i#$ROOT/}\n" ' '>&$SILENT_OUT
if grep -qE '^GIT binary patch$|^rename from|^rename to' $i; then
cat $i | git apply --directory=`echo "$PKG_BUILD" | cut -f1 -d\ ` -p1 --verbose --whitespace=nowarn --unsafe-paths >&$VERBOSE_OUT
else
cat $i | patch -d `echo "$PKG_BUILD" | cut -f1 -d\ ` -p1 >&$VERBOSE_OUT
fi
fi
done
if [ "$(type -t post_patch)" = "function" ]; then
post_patch
fi
fi
if [ ! "$PKG_NAME" = "configtools" ] ; then
2017-02-23 11:42:08 +00:00
for config in `find $PKG_BUILD -name config.guess | sed 's/config.guess//'`; do
printf "%${BUILD_INDENT}c $(print_color CLR_FIXCONFIG "FIXCONFIG") $config\n" ' '
[ -f "$config/config.guess" -a -f $TOOLCHAIN/configtools/config.guess ] && \
cp -f $TOOLCHAIN/configtools/config.guess $config
[ -f "$config/config.sub" -a -f $TOOLCHAIN/configtools/config.sub ] && \
cp -f $TOOLCHAIN/configtools/config.sub $config
2017-02-23 11:42:08 +00:00
done
fi
fi
if [ "$PKG_SECTION" != "virtual" ]; then
mkdir -p $PKG_BUILD
rm -f $STAMPS/$1/build_*
PKG_DEEPHASH=$(calculate_stamp)
for i in PKG_NAME PKG_DEEPHASH; do
2017-02-23 11:42:08 +00:00
echo "STAMP_$i=\"${!i}\"" >> $STAMP
done
fi