From 2421928859e859dbf73af249272a417df2769dda Mon Sep 17 00:00:00 2001 From: Adonis Ling Date: Tue, 29 Oct 2024 17:35:33 +0800 Subject: [PATCH] feat(toolchain): add musl-obstack --- toolchain/Dockerfile | 2 +- toolchain/generate_toolchan.sh | 39 +++++++++++++++++++++++++++++++--- toolchain/setup_toolchain.sh | 2 +- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/toolchain/Dockerfile b/toolchain/Dockerfile index 73b0347..c7f0b74 100644 --- a/toolchain/Dockerfile +++ b/toolchain/Dockerfile @@ -2,7 +2,7 @@ FROM ubuntu:22.04 AS builder RUN apt update && apt upgrade --yes RUN DEBIAN_FRONTEND=noninteractive apt install --yes \ - build-essential texinfo bison git curl rsync gawk python-is-python3 help2man file + build-essential texinfo bison git curl rsync gawk python-is-python3 help2man file autoconf libtool pkg-config RUN mkdir -p /opt/patchelf RUN curl -L "https://github.com/NixOS/patchelf/releases/download/0.16.1/patchelf-0.16.1-$(uname -m).tar.gz" \ diff --git a/toolchain/generate_toolchan.sh b/toolchain/generate_toolchan.sh index 2875cce..978d784 100755 --- a/toolchain/generate_toolchan.sh +++ b/toolchain/generate_toolchan.sh @@ -23,6 +23,10 @@ declare -r GCC_MD5SUM='2268420ba02dc01821960e274711bde0' declare -r LIBXCRYPT_PACKAGE_URL='https://github.com/besser82/libxcrypt/releases/download/v4.4.36/libxcrypt-4.4.36.tar.xz' declare -r LIBXCRYPT_MD5SUM='b84cd4104e08c975063ec6c4d0372446' +declare -r MUSL_OBSTACK_URL='https://github.com/void-linux/musl-obstack/archive/refs/tags/v1.2.3.tar.gz' +declare -r MUSL_OBSTACK_MD5SUM='e4f1d16aa3187e8d071f656dd2b10a9e' +declare -r MUSL_OBSTACK_NAME='musl-obstack-1.2.3.tar.gz' + function log() { local level="${1}" local message="${2}" @@ -79,8 +83,7 @@ function show_environment() { function download() { local url="${1}" local md5sum="${2}" - local package - package="$(basename "${url}")" + local package="${3:-$(basename "${url}")}" mkdir -p "${PACKAGES_PATH}" pushd "${PACKAGES_PATH}" >/dev/null @@ -100,15 +103,25 @@ function download_all() { download "${GLIBC_PACKAGE_URL}" "${GLIBC_MD5SUM}" download "${GCC_PACKAGE_URL}" "${GCC_MD5SUM}" download "${LIBXCRYPT_PACKAGE_URL}" "${LIBXCRYPT_MD5SUM}" + download "${MUSL_OBSTACK_URL}" "${MUSL_OBSTACK_MD5SUM}" "${MUSL_OBSTACK_NAME}" } function extract_packages() { + local package + pushd "${PACKAGES_PATH}" >/dev/null find . -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} \; + for package in *.tar.xz; do log_info "Extract ${package} ..." - tar -xf "${package}" + tar -Jxf "${package}" + log_info "Extract ${package} successfully!" + done + + for package in *.tar.gz; do + log_info "Extract ${package} ..." + tar -zxf "${package}" log_info "Extract ${package} successfully!" done @@ -353,6 +366,25 @@ function build_libxcrypt() { popd >/dev/null } +function build_musl_obstack() { + local package="${MUSL_OBSTACK_NAME}" + pushd "${package/.tar.gz/}" >/dev/null + + ./bootstrap.sh + + rm -rf build + mkdir build + cd build + + ../configure --prefix="${PREFIX}" + make -j "$(nproc)" + make install + + rm -rf "${PREFIX}/lib/pkgconfig" + + popd >/dev/null +} + function build_final_toolchain() { build_binutils_final build_gcc_final @@ -365,6 +397,7 @@ function build_all() { build_cross_toolchain build_final_toolchain build_libxcrypt + build_musl_obstack popd >/dev/null } diff --git a/toolchain/setup_toolchain.sh b/toolchain/setup_toolchain.sh index a26ee15..60fd283 100755 --- a/toolchain/setup_toolchain.sh +++ b/toolchain/setup_toolchain.sh @@ -54,7 +54,7 @@ function extract_toolchain() { local temp_dir if [[ -d "${prefix}/${TOOLCHAIN_DIRNAME}" ]]; then - log_error "Failed to extract the toolchain due to the target directory already exists." + log_error "Failed to extract the toolchain due to the target directory \033[34;1m${prefix}/${TOOLCHAIN_DIRNAME}\033[0m already exists." fi if ! temp_dir="$(mktemp -d)"; then