2024-08-05 15:14:09 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
if (( $# != 1 )); then
|
|
|
|
echo "No arguments given for $0" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-08-06 16:07:02 +03:00
|
|
|
if [[ -z $BANAN_ROOT_DIR ]]; then
|
2024-12-03 20:18:24 +02:00
|
|
|
export BANAN_ROOT_DIR="$(realpath $(dirname $(realpath $0))/..)"
|
2024-08-06 16:07:02 +03:00
|
|
|
fi
|
|
|
|
|
2024-08-05 15:14:09 +03:00
|
|
|
source "$BANAN_ROOT_DIR/script/config.sh"
|
2024-08-06 16:07:02 +03:00
|
|
|
|
2024-08-05 15:14:09 +03:00
|
|
|
export PATH="$BANAN_TOOLCHAIN_PREFIX/bin:$PATH"
|
|
|
|
|
2024-08-22 14:23:16 +03:00
|
|
|
export PKG_CONFIG_DIR=''
|
2024-08-06 16:07:02 +03:00
|
|
|
export PKG_CONFIG_SYSROOT_DIR="$BANAN_SYSROOT"
|
|
|
|
export PKG_CONFIG_LIBDIR="$PKG_CONFIG_SYSROOT_DIR/usr/lib/pkgconfig"
|
|
|
|
export PKG_CONFIG_PATH="$PKG_CONFIG_SYSROOT_DIR/usr/share/pkgconfig"
|
|
|
|
|
2024-08-09 17:08:07 +03:00
|
|
|
export CC="$BANAN_TOOLCHAIN_TRIPLE-gcc"
|
|
|
|
export CXX="$BANAN_TOOLCHAIN_TRIPLE-g++"
|
|
|
|
export LD="$BANAN_TOOLCHAIN_TRIPLE-ld"
|
2024-08-22 14:23:16 +03:00
|
|
|
export AR="$BANAN_TOOLCHAIN_TRIPLE-ar"
|
|
|
|
export RANLIB="$BANAN_TOOLCHAIN_TRIPLE-ranlib"
|
|
|
|
export READELF="$BANAN_TOOLCHAIN_TRIPLE-readelf"
|
|
|
|
export OBJCOPY="$BANAN_TOOLCHAIN_TRIPLE-objcopy"
|
|
|
|
export OBJDUMP="$BANAN_TOOLCHAIN_TRIPLE-objdump"
|
|
|
|
export STRIP="$BANAN_TOOLCHAIN_TRIPLE-strip"
|
|
|
|
export CXXFILT="$BANAN_TOOLCHAIN_TRIPLE-c++filt"
|
2024-08-09 17:08:07 +03:00
|
|
|
|
2024-12-03 20:18:24 +02:00
|
|
|
export CMAKE_TOOLCHAIN_FILE="$BANAN_TOOLCHAIN_DIR/Toolchain.txt"
|
|
|
|
|
2024-12-03 20:16:18 +02:00
|
|
|
pushd "$BANAN_ROOT_DIR" >/dev/null
|
|
|
|
./bos all && ./bos install || exit 1
|
|
|
|
popd >/dev/null
|
2024-08-05 15:14:09 +03:00
|
|
|
|
2024-09-05 14:49:23 +03:00
|
|
|
if [ "$BANAN_ARCH" = "i686" ]; then
|
|
|
|
export LDFLAGS="-shared-libgcc"
|
|
|
|
fi
|
|
|
|
|
2024-08-05 15:14:09 +03:00
|
|
|
clean() {
|
|
|
|
find . -mindepth 1 -maxdepth 1 -not -name 'patches' -not -name 'build.sh' -exec rm -rf {} +
|
|
|
|
}
|
|
|
|
|
2024-08-09 17:08:07 +03:00
|
|
|
configure() {
|
2024-08-06 16:07:02 +03:00
|
|
|
configure_options=("--host=$BANAN_ARCH-banan_os" '--prefix=/usr')
|
2024-08-09 17:08:07 +03:00
|
|
|
configure_options+=("${CONFIGURE_OPTIONS[@]}")
|
|
|
|
./configure "${configure_options[@]}" || exit 1
|
|
|
|
}
|
2024-08-05 15:14:09 +03:00
|
|
|
|
2024-08-09 17:08:07 +03:00
|
|
|
build() {
|
2024-08-05 15:14:09 +03:00
|
|
|
make -j$(nproc) || exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
install() {
|
|
|
|
make install "DESTDIR=$BANAN_SYSROOT" || exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
source $1
|
|
|
|
|
|
|
|
if [ -z $NAME ] || [ -z $VERSION ] || [ -z $DOWNLOAD_URL ]; then
|
|
|
|
echo "Port does not set needed environment variables" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
for dependency in "${DEPENDENCIES[@]}"; do
|
|
|
|
pushd "../$dependency" >/dev/null
|
|
|
|
pwd
|
|
|
|
if ! ./build.sh; then
|
|
|
|
echo "Failed to install dependency '$dependency' of port '$NAME'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
popd >/dev/null
|
|
|
|
done
|
|
|
|
|
|
|
|
build_dir="$NAME-$VERSION-$BANAN_ARCH"
|
|
|
|
|
2024-08-06 16:07:02 +03:00
|
|
|
if [ ! -d "$build_dir" ]; then
|
2024-08-07 16:07:59 +03:00
|
|
|
rm -f ".compile_hash"
|
2024-08-06 16:07:02 +03:00
|
|
|
fi
|
|
|
|
|
2024-08-05 15:14:09 +03:00
|
|
|
if [ "$VERSION" = "git" ]; then
|
|
|
|
regex="(.*/.*\.git)#(.*)"
|
|
|
|
|
|
|
|
if [[ $DOWNLOAD_URL =~ $regex ]]; then
|
|
|
|
REPO_URL="${BASH_REMATCH[1]}"
|
|
|
|
COMMIT="${BASH_REMATCH[2]}"
|
|
|
|
|
|
|
|
if [ -d "$build_dir" ]; then
|
|
|
|
pushd $build_dir >/dev/null
|
|
|
|
if [ ! "$(git rev-parse HEAD)" = "$COMMIT" ]; then
|
|
|
|
clean
|
|
|
|
fi
|
|
|
|
popd >/dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "$build_dir" ]; then
|
|
|
|
git clone "$REPO_URL" "$build_dir" || exit 1
|
|
|
|
|
|
|
|
pushd "$build_dir" >/dev/null
|
|
|
|
git checkout "$COMMIT" || exit 1
|
2024-08-06 16:07:02 +03:00
|
|
|
if [ -d ../patches ]; then
|
2024-08-05 15:14:09 +03:00
|
|
|
for patch in ../patches/*; do
|
|
|
|
git apply "$patch" || exit 1
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
popd >/dev/null
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Invalid format in DOWNLOAD_URL" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
2024-08-22 14:23:16 +03:00
|
|
|
regex='.*/(.*)#(.*)'
|
2024-08-05 15:14:09 +03:00
|
|
|
if [[ $DOWNLOAD_URL =~ $regex ]]; then
|
2024-08-22 14:23:16 +03:00
|
|
|
FILE_NAME="${BASH_REMATCH[1]}"
|
|
|
|
FILE_HASH="${BASH_REMATCH[2]}"
|
2024-08-05 15:14:09 +03:00
|
|
|
|
2024-08-22 14:23:16 +03:00
|
|
|
if [ -f "$FILE_NAME" ]; then
|
|
|
|
if ! echo "$FILE_HASH $FILE_NAME" | sha256sum --check >/dev/null; then
|
2024-08-05 15:14:09 +03:00
|
|
|
clean
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-08-22 14:23:16 +03:00
|
|
|
if [ ! -f "$FILE_NAME" ]; then
|
2024-08-05 15:14:09 +03:00
|
|
|
wget "$DOWNLOAD_URL" || exit 1
|
|
|
|
fi
|
|
|
|
|
2024-08-22 14:23:16 +03:00
|
|
|
if ! echo "$FILE_HASH $FILE_NAME" | sha256sum --check >/dev/null; then
|
|
|
|
echo "File hash does not match" >&2
|
2024-08-05 15:14:09 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-08-22 14:23:16 +03:00
|
|
|
regex='(.*\.tar\..*)'
|
|
|
|
if [[ $FILE_NAME =~ $regex ]] && [ ! -d "$build_dir" ]; then
|
|
|
|
tar xf "$FILE_NAME" || exit 1
|
2024-08-05 15:14:09 +03:00
|
|
|
|
|
|
|
: "${TAR_CONTENT:=$NAME-$VERSION}"
|
|
|
|
mv "$TAR_CONTENT" "$build_dir" || exit 1
|
|
|
|
|
|
|
|
if [ -d patches ]; then
|
|
|
|
for patch in ./patches/*; do
|
2024-08-06 16:07:02 +03:00
|
|
|
patch -ruN -p1 -d "$build_dir" < "$patch" || exit 1
|
2024-08-05 15:14:09 +03:00
|
|
|
done
|
|
|
|
fi
|
2024-08-22 14:23:16 +03:00
|
|
|
else
|
|
|
|
if [ ! -d "$build_dir" ]; then
|
|
|
|
mkdir -p "$build_dir" || exit 1
|
|
|
|
fi
|
2024-08-05 15:14:09 +03:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Invalid format in DOWNLOAD_URL" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
needs_compile=1
|
2024-08-07 16:07:59 +03:00
|
|
|
if [ -f ".compile_hash" ]; then
|
|
|
|
sha256sum --check ".compile_hash" &>/dev/null
|
2024-08-05 15:14:09 +03:00
|
|
|
needs_compile=$?
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd "$build_dir"
|
|
|
|
|
|
|
|
if (( $needs_compile )); then
|
2024-08-09 17:08:07 +03:00
|
|
|
configure
|
2024-08-05 15:14:09 +03:00
|
|
|
build
|
2024-08-07 16:07:59 +03:00
|
|
|
sha256sum "$BANAN_SYSROOT/usr/lib/libc.a" > "../.compile_hash"
|
2024-08-05 15:14:09 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
install
|