Updated treetap, fixed the bootstrap, and replaced ld.lld with mold

This commit is contained in:
Alexander Hill 2025-11-22 20:35:27 -05:00
parent 320a2dbb2e
commit bca382ed71
8 changed files with 189 additions and 97 deletions

View File

@ -1,6 +1,6 @@
#!/bin/zsh -e #!/bin/zsh -e
MICROARCH="skylake" MICROARCH=skylake
TARGET=x86_64-maple-linux-musl TARGET=x86_64-maple-linux-musl
# Set the environment up # Set the environment up
@ -10,22 +10,29 @@ PROCS=$(nproc)
SOURCES=$(pwd)/.treetap/sources SOURCES=$(pwd)/.treetap/sources
SPEC=$(pwd)/sources SPEC=$(pwd)/sources
export AR=llvm-ar export AR=llvm-ar
export AS=llvm-as
if [ ! -z "$CCACHE" ]; then
export CC="$CCACHE clang"
export CXX="$CCACHE clang++"
else
export CC=clang export CC=clang
export CFLAGS="-fuse-ld=lld -O3 -march=$MICROARCH -pipe --sysroot=$BOOTSTRAP/root -Wno-unused-command-line-argument"
export CXX=clang++ export CXX=clang++
fi
export CFLAGS="-fuse-ld=mold -O3 -march=$MICROARCH -pipe --sysroot=$BOOTSTRAP/root -Wno-unused-command-line-argument"
export CXXFLAGS=$CFLAGS export CXXFLAGS=$CFLAGS
export RANLIB=llvm-ranlib export RANLIB=llvm-ranlib
export LD=ld.lld export LD=mold
export LDFLAGS="--sysroot=$BOOTSTRAP/root" export LDFLAGS="--sysroot=$BOOTSTRAP/root"
export TREETAP=$(pwd)/treetap export TREETAP=$(pwd)/treetap
export TT_DIR=$(pwd)/.treetap export TT_DIR=$(pwd)/.treetap
export TT_MICROARCH=$MICROARCH
export TT_SYSROOT=$BOOTSTRAP/root export TT_SYSROOT=$BOOTSTRAP/root
export TT_TARGET=$TARGET export TT_TARGET=$TARGET
# Fetch sources required for a bootstrap # Fetch sources required for a bootstrap
./treetap fetch sources/linux/linux.spec $TREETAP fetch sources/linux/linux.spec
./treetap fetch sources/llvm/llvm.spec $TREETAP fetch sources/llvm/llvm.spec
./treetap fetch sources/musl/musl.spec $TREETAP fetch sources/musl/musl.spec
# Make sure both clang-tblgen and llvm-tblgen are in the PATH. ~ahill # Make sure both clang-tblgen and llvm-tblgen are in the PATH. ~ahill
which clang-tblgen > /dev/null which clang-tblgen > /dev/null
@ -48,22 +55,31 @@ mkdir -p $BOOTSTRAP/build
cd $BOOTSTRAP/build cd $BOOTSTRAP/build
# Define the target for Maple Linux # Define the target for Maple Linux
# NOTE: We run cut on CC and CXX just in case ccache is in use. ~ahill
cat << EOF > $BOOTSTRAP/$TARGET.cmake cat << EOF > $BOOTSTRAP/$TARGET.cmake
set(CMAKE_ASM_COMPILER_TARGET $TARGET) set(CMAKE_ASM_COMPILER_TARGET $TARGET)
set(CMAKE_C_COMPILER $CC) set(CMAKE_C_COMPILER $(echo $CC | cut -d" " -f2))
set(CMAKE_C_COMPILER_TARGET $TARGET) set(CMAKE_C_COMPILER_TARGET $TARGET)
set(CMAKE_C_FLAGS_INIT "$CFLAGS") set(CMAKE_C_FLAGS_INIT "$CFLAGS")
set(CMAKE_CXX_COMPILER $CXX) set(CMAKE_CXX_COMPILER $(echo $CXX | cut -d" " -f2))
set(CMAKE_CXX_COMPILER_TARGET $TARGET) set(CMAKE_CXX_COMPILER_TARGET $TARGET)
set(CMAKE_CXX_FLAGS_INIT "$CXXFLAGS") set(CMAKE_CXX_FLAGS_INIT "$CXXFLAGS")
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_LINKER_TYPE LLD) set(CMAKE_LINKER_TYPE MOLD)
set(CMAKE_SYSROOT "$BOOTSTRAP/root") set(CMAKE_SYSROOT "$BOOTSTRAP/root")
set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_NAME Linux)
EOF EOF
# NOTE: CMake doesn't like dealing with ccache inside of CC/CXX, so we do this
# instead. ~ahill
if [ ! -z "$CCACHE" ]; then
cat << EOF >> $BOOTSTRAP/$TARGET.cmake
set(CMAKE_C_COMPILER_LAUNCHER $CCACHE)
set(CMAKE_CXX_COMPILER_LAUNCHER $CCACHE)
EOF
fi
# Install headers for Linux # Install headers for Linux
LINUX_VERSION=$(sed -En "s/SRC_VERSION=\"?(.+)\"/\1/p" $SPEC/linux/linux.spec) LINUX_VERSION=$(sed -En "s/SRC_VERSION=\"?(.+)\"/\1/p" $SPEC/linux/linux.spec)
@ -83,7 +99,6 @@ cd ..
# Install headers for musl # Install headers for musl
MUSL_VERSION=$(sed -En "s/SRC_VERSION=\"?(.+)\"/\1/p" $SPEC/musl/musl.spec) MUSL_VERSION=$(sed -En "s/SRC_VERSION=\"?(.+)\"/\1/p" $SPEC/musl/musl.spec)
tar xf $SOURCES/musl/$MUSL_VERSION/musl-*.tar* tar xf $SOURCES/musl/$MUSL_VERSION/musl-*.tar*
./treetap fetch sources/busybox/busybox.spec
cd musl-*/ cd musl-*/
# NOTE: Patch for musl 1.2.5 to prevent a character encoding vulnerability. This # NOTE: Patch for musl 1.2.5 to prevent a character encoding vulnerability. This
# should be safe to remove after the next release. ~ahill # should be safe to remove after the next release. ~ahill
@ -119,19 +134,12 @@ cmake --install build-builtins --parallel $PROCS
cd .. cd ..
# Build musl for real this time # Build musl for real this time
cd musl-*/
make clean
# NOTE: LIBCC is required here because it will attempt to link with the build # NOTE: LIBCC is required here because it will attempt to link with the build
# system's runtime if this is not specified. ~ahill # system's runtime if this is not specified. ~ahill
LIBCC="$BOOTSTRAP/root/lib/clang/$LLVM_MAJOR_VERSION/lib/linux/libclang_rt.builtins-x86_64.a" \ LIBCC="$BOOTSTRAP/root/lib/clang/$LLVM_MAJOR_VERSION/lib/linux/libclang_rt.builtins-x86_64.a" \
./configure \ $TREETAP build $SPEC/musl/musl.spec
--bindir=/bin \ $TREETAP package $SPEC/musl/musl.spec
--includedir=/usr/include \ $TREETAP install $TT_DIR/packages/$MICROARCH/musl-*.cpio.xz $BOOTSTRAP/root
--libdir=/lib \
--prefix=/
make -O -j $PROCS
make -O -j $PROCS install DESTDIR=$BOOTSTRAP/root
cd ..
# Include compiler-rt and musl in our environment # Include compiler-rt and musl in our environment
export CFLAGS="$CFLAGS -Qunused-arguments -rtlib=compiler-rt -Wl,--dynamic-linker=/lib/ld-musl-$ARCH.so.1" export CFLAGS="$CFLAGS -Qunused-arguments -rtlib=compiler-rt -Wl,--dynamic-linker=/lib/ld-musl-$ARCH.so.1"
@ -193,7 +201,7 @@ NATIVE_TOOL_DIR=$(dirname $(which llvm-tblgen) | sed -z "s/\n//g")
cd llvm-project-*/ cd llvm-project-*/
cmake -S llvm -B build-llvm \ cmake -S llvm -B build-llvm \
-DCLANG_DEFAULT_CXX_STDLIB=libc++ \ -DCLANG_DEFAULT_CXX_STDLIB=libc++ \
-DCLANG_DEFAULT_LINKER=lld \ -DCLANG_DEFAULT_LINKER=mold \
-DCLANG_DEFAULT_RTLIB=compiler-rt \ -DCLANG_DEFAULT_RTLIB=compiler-rt \
-DCLANG_DEFAULT_UNWINDLIB=libunwind \ -DCLANG_DEFAULT_UNWINDLIB=libunwind \
-DCLANG_TABLEGEN=$NATIVE_TOOL_DIR/clang-tblgen \ -DCLANG_TABLEGEN=$NATIVE_TOOL_DIR/clang-tblgen \
@ -202,30 +210,29 @@ cmake -S llvm -B build-llvm \
-DCMAKE_INSTALL_PREFIX=$BOOTSTRAP/root \ -DCMAKE_INSTALL_PREFIX=$BOOTSTRAP/root \
-DCMAKE_TOOLCHAIN_FILE=$BOOTSTRAP/$TARGET.cmake \ -DCMAKE_TOOLCHAIN_FILE=$BOOTSTRAP/$TARGET.cmake \
-DLLVM_ENABLE_LIBCXX=ON \ -DLLVM_ENABLE_LIBCXX=ON \
-DLLVM_ENABLE_PROJECTS="clang;lld;llvm" \ -DLLVM_ENABLE_PROJECTS="clang;llvm" \
-DLLVM_ENABLE_ZSTD=OFF \ -DLLVM_ENABLE_ZSTD=OFF \
-DLLVM_HOST_TRIPLE=$TARGET \ -DLLVM_HOST_TRIPLE=$TARGET \
-DLLVM_INSTALL_BINUTILS_SYMLINKS=ON \ -DLLVM_INSTALL_BINUTILS_SYMLINKS=ON \
-DLLVM_INSTALL_CCTOOLS_SYMLINKS=ON \ -DLLVM_INSTALL_CCTOOLS_SYMLINKS=ON \
-DLLVM_NATIVE_TOOL_DIR=$NATIVE_TOOL_DIR \ -DLLVM_NATIVE_TOOL_DIR=$NATIVE_TOOL_DIR \
-DLLVM_TABLEGEN=$NATIVE_TOOL_DIR/llvm-tblgen -DLLVM_TABLEGEN=$NATIVE_TOOL_DIR/llvm-tblgen
cmake --build build-llvm cmake --build build-llvm --parallel $PROCS
cmake --install build-llvm --parallel $PROCS cmake --install build-llvm --parallel $PROCS
# NOTE: LLVM doesn't add symlinks for clang/ld, so we'll make them ourselves. # NOTE: LLVM doesn't add symlinks for clang, so we'll make them ourselves.
# ~ahill # ~ahill
ln -s clang $BOOTSTRAP/root/bin/cc ln -s clang $BOOTSTRAP/root/bin/cc
ln -s clang++ $BOOTSTRAP/root/bin/c++ ln -s clang++ $BOOTSTRAP/root/bin/c++
ln -s ld.lld $BOOTSTRAP/root/bin/ld
cd .. cd ..
# Build remaining software with treetap # Build remaining software with treetap
SOURCES=(busybox make) SOURCES=(busybox make mold)
for name in $SOURCES; do for name in $SOURCES; do
$TREETAP fetch $SPEC/$name/$name.spec $TREETAP fetch $SPEC/$name/$name.spec
$TREETAP build $SPEC/$name/$name.spec $TREETAP build $SPEC/$name/$name.spec
$TREETAP package $SPEC/$name/$name.spec $TREETAP package $SPEC/$name/$name.spec
$TREETAP install .treetap/packages/$TARGET/$name-*.cpio.xz $BOOTSTRAP/root $TREETAP install $TT_DIR/packages/$MICROARCH/$name-*.cpio.xz $BOOTSTRAP/root
done done
# Install Treetap # Install Treetap
cp $BOOTSTRAP/../treetap $BOOTSTRAP/root/bin/ cp $TREETAP $BOOTSTRAP/root/bin/

View File

@ -10,6 +10,7 @@ SRC_VERSION="1.36.1"
build() { build() {
tar xf ../$SRC_FILENAME tar xf ../$SRC_FILENAME
cd busybox-*/ cd busybox-*/
cp ../.config .
# NOTE: Like we did with musl before, we don't set CROSS_COMPILE because # NOTE: Like we did with musl before, we don't set CROSS_COMPILE because
# LLVM is smart and doesn't need a compiler to cross-compile code. # LLVM is smart and doesn't need a compiler to cross-compile code.
# With that said, Busybox uses Kbuild, which hard-codes variables like # With that said, Busybox uses Kbuild, which hard-codes variables like
@ -31,6 +32,7 @@ clean() {
} }
package() { package() {
cd busybox-*/
# NOTE: Busybox doesn't have a proper DESTDIR, so we just set CONFIG_PREFIX # NOTE: Busybox doesn't have a proper DESTDIR, so we just set CONFIG_PREFIX
# during the install to work around this limitation. ~ahill # during the install to work around this limitation. ~ahill
make -O -j $TT_PROCS install CONFIG_PREFIX=$TT_INSTALLDIR make -O -j $TT_PROCS install CONFIG_PREFIX=$TT_INSTALLDIR

View File

@ -9,21 +9,7 @@ build() {
cd libressl-*/ cd libressl-*/
# TODO: What even is sharedstatedir and what should Maple Linux do with it? # TODO: What even is sharedstatedir and what should Maple Linux do with it?
# ~ahill # ~ahill
./configure \ ./configure $TT_AUTOCONF_COMMON --disable-static
--bindir=$TT_BINDIR \
--build=$TT_BUILD \
--datarootdir=/usr/share \
--disable-static \
--host=$TT_TARGET \
--includedir=$TT_INCLUDEDIR \
--libdir=$TT_LIBDIR \
--libexecdir=$TT_LIBDIR \
--localstatedir=/var \
--prefix=$TT_PREFIX \
--runstatedir=/run \
--sbindir=$TT_BINDIR \
--sysconfdir=$TT_CONFDIR \
--with-sysroot=$TT_SYSROOT
make -j $TT_PROCS make -j $TT_PROCS
} }

View File

@ -1,5 +1,5 @@
# Maintainer: Alexander Hill <ahill@breadpudding.dev> # Maintainer: Alexander Hill <ahill@breadpudding.dev>
SRC_HASH="1794be4bf974e99a3fe1da4b2b9b1456c02ae9479c942f365441d8d207bd650c" SRC_HASH="ae67086eb04bed7ca11ab880349b5f1ab6f50e1b88cda376eaf8a845b935762b"
SRC_NAME="llvm" SRC_NAME="llvm"
SRC_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.5/llvm-project-21.1.5.src.tar.xz" SRC_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.6/llvm-project-21.1.6.src.tar.xz"
SRC_VERSION="21.1.5" SRC_VERSION="21.1.6"

View File

@ -7,20 +7,7 @@ SRC_VERSION="4.4.1"
build() { build() {
tar xf ../$SRC_FILENAME tar xf ../$SRC_FILENAME
cd make-*/ cd make-*/
./configure \ ./configure $TT_AUTOCONF_COMMON --enable-year2038
--bindir=$TT_BINDIR \
--build=$TT_BUILD \
--datarootdir=/usr/share \
--enable-year2038 \
--host=$TT_TARGET \
--includedir=$TT_INCLUDEDIR \
--libdir=$TT_LIBDIR \
--libexecdir=$TT_LIBDIR \
--localstatedir=/var \
--prefix=$TT_PREFIX \
--runstatedir=/run \
--sbindir=$TT_BINDIR \
--sysconfdir=$TT_CONFDIR
make -O -j $TT_PROCS make -O -j $TT_PROCS
} }
@ -29,5 +16,6 @@ clean() {
} }
package() { package() {
cd make-*/
make -O -j $TT_PROCS install DESTDIR=$TT_INSTALLDIR make -O -j $TT_PROCS install DESTDIR=$TT_INSTALLDIR
} }

24
sources/mold/mold.spec Normal file
View File

@ -0,0 +1,24 @@
# Maintainer: Alexander Hill <ahill@breadpudding.dev>
SRC_FILENAME="mold-2.40.4.tar.gz"
SRC_HASH="69414c702ec1084e1fa8ca16da24f167f549e5e11e9ecd5d70a8dcda6f08c249"
SRC_NAME="mold"
SRC_URL="https://github.com/rui314/mold/archive/refs/tags/v2.40.4.tar.gz"
SRC_VERSION="2.40.4"
build() {
echo "DEBUG: $TT_CMAKE_COMMON"
tar xf ../$SRC_FILENAME
cd mold-*/
cmake -B build $TT_CMAKE_COMMON
cmake --build build --parallel $TT_PROCS
}
clean() {
rm -rf mold-*/
}
package() {
cd mold-*/
cmake --install build --parallel $TT_PROCS
ln -sf mold $TT_INSTALLDIR/bin/ld
}

View File

@ -15,13 +15,7 @@ build() {
# https://www.openwall.com/lists/musl/2025/02/13/1/1 # https://www.openwall.com/lists/musl/2025/02/13/1/1
# https://www.openwall.com/lists/musl/2025/02/13/1/2 # https://www.openwall.com/lists/musl/2025/02/13/1/2
patch -p1 < ../CVE-2025-26519.patch patch -p1 < ../CVE-2025-26519.patch
./configure \ ./configure $TT_AUTOCONF_COMMON
--bindir=$TT_BINDIR \
--build=$TT_BUILD \
--includedir=$TT_INCLUDEDIR \
--libdir=$TT_LIBDIR \
--prefix=$TT_PREFIX \
--target=$TT_TARGET
make -O -j $TT_PROCS make -O -j $TT_PROCS
} }

147
treetap
View File

@ -18,6 +18,18 @@
# Changelog # # Changelog #
############# #############
# November 22, 2025 (1.2.0)
# + Added support for the CCACHE environment variable [ahill]
# + Added TT_ARCH [ahill]
# + Added TT_AUTOCONF_COMMON for easy autoconf integration [ahill]
# + Added TT_CMAKE_COMMON for easy CMake integration [ahill]
# + Added TT_MICROARCH for micro-optimization support [ahill]
# * Changed the build path to use TT_MICROARCH instead of TT_TARGET [ahill]
# * Fixed "missing package" error when passing absolute paths to the install
# subcommand [ahill]
# * Prevented xz from deleting package files [ahill]
# + Started printing the version number in the build logs [ahill]
# November 15, 2025 (1.1.0) # November 15, 2025 (1.1.0)
# + Added the ability to incorporate patches into the build [ahill] # + Added the ability to incorporate patches into the build [ahill]
# + Added TT_CONFDIR [ahill] # + Added TT_CONFDIR [ahill]
@ -56,20 +68,42 @@
# SRC_VERSION - The version of the package being built (required) # SRC_VERSION - The version of the package being built (required)
# Treetap Variables: # Treetap Variables:
# TT_BINDIR - The desired path for binaries [scope: source] [default: /bin] # TT_ARCH - The architecture portion of TT_TARGET
# TT_BUILD - The target triple of the build system [scope: source] # [scope: source]
# TT_BUILDDIR - The path to the build directory [scope: source] # TT_AUTOCONF_COMMON - The default autoconf arguments based on the environment
# TT_CONFDIR - The desired path for configuration files [scope: source] [default: /etc] # [scope: source]
# TT_DIR - The path to the treetap directory [scope: global] # TT_BINDIR - The desired path for binaries
# TT_INCLUDEDIR - The desired path for header files [scope: source] [default: /usr/include] # [scope: source] [default: /bin]
# TT_INSTALLDIR - The path to the install directory [scope: source] # TT_BUILD - The target triple of the build system
# TT_LIBDIR - The desired path for libraries [scope: source] [default: /lib] # [scope: source]
# TT_PKGDIR - The path to the package directory [scope: global] # TT_BUILDDIR - The path to the build directory
# TT_PREFIX - The desired prefix for the package [scope: source] [default: /] # [scope: source]
# TT_PROCS - The number of processors on the build system [scope: source] # TT_CMAKE_COMMON - The default CMake arguments based on the environment
# TT_SYSROOT - The sysroot of the target system [scope: global] # [scope: source]
# TT_TARGET - The target triple of the target system [scope: source] # TT_CONFDIR - The desired path for configuration files
# TT_VERSION - The version of treetap being used [scope: global] # [scope: source] [default: /etc]
# TT_DIR - The path to the treetap directory
# [scope: global]
# TT_INCLUDEDIR - The desired path for header files
# [scope: source] [default: /usr/include]
# TT_INSTALLDIR - The path to the install directory
# [scope: source]
# TT_LIBDIR - The desired path for libraries
# [scope: source] [default: /lib]
# TT_MICROARCH - The microarchitecture to optimize for
# [scope: source]
# TT_PKGDIR - The path to the package directory
# [scope: global]
# TT_PREFIX - The desired prefix for the package
# [scope: source] [default: /]
# TT_PROCS - The number of processors on the build system
# [scope: source]
# TT_SYSROOT - The sysroot of the target system
# [scope: global]
# TT_TARGET - The target triple of the target system
# [scope: source]
# TT_VERSION - The version of treetap being used
# [scope: global]
#################### ####################
# Global Variables # # Global Variables #
@ -78,7 +112,7 @@
[ -z "$TT_DIR" ] && TT_DIR="$(pwd)/.treetap" [ -z "$TT_DIR" ] && TT_DIR="$(pwd)/.treetap"
[ -z "$TT_PKGDIR" ] && TT_PKGDIR="$TT_DIR/packages" [ -z "$TT_PKGDIR" ] && TT_PKGDIR="$TT_DIR/packages"
[ -z "$TT_SYSROOT" ] && TT_SYSROOT=/ [ -z "$TT_SYSROOT" ] && TT_SYSROOT=/
TT_VERSION="1.1.0" TT_VERSION="1.2.0"
##################### #####################
# Utility Functions # # Utility Functions #
@ -107,6 +141,10 @@ package_check() {
[ -z "$2" ] && (echo "package_check: Missing sysroot"; exit 1) [ -z "$2" ] && (echo "package_check: Missing sysroot"; exit 1)
[ ! -f "$1" ] && (echo "package_check: Package file \"$1\" not found"; exit 1) [ ! -f "$1" ] && (echo "package_check: Package file \"$1\" not found"; exit 1)
[ ! -d "$2" ] && (echo "package_check: Sysroot \"$2\" not found"; exit 1) [ ! -d "$2" ] && (echo "package_check: Sysroot \"$2\" not found"; exit 1)
case "$1" in
"/"*) PKG_FULLPATH=$1 ;;
*) PKG_FULLPATH=$(pwd)/$1 ;;
esac
true true
} }
@ -132,14 +170,65 @@ source_spec() {
[ -z "$TT_BINDIR" ] && TT_BINDIR=/bin [ -z "$TT_BINDIR" ] && TT_BINDIR=/bin
TT_BUILD=$(clang -dumpmachine) TT_BUILD=$(clang -dumpmachine)
[ -z "$TT_TARGET" ] && TT_TARGET=$TT_BUILD [ -z "$TT_TARGET" ] && TT_TARGET=$TT_BUILD
TT_BUILDDIR="$TT_DIR/sources/$SRC_NAME/$SRC_VERSION/$TT_TARGET"
[ -z "$TT_CONFDIR" ] && TT_CONFDIR=/etc [ -z "$TT_CONFDIR" ] && TT_CONFDIR=/etc
[ -z "$TT_INCLUDEDIR" ] && TT_INCLUDEDIR=/usr/include [ -z "$TT_INCLUDEDIR" ] && TT_INCLUDEDIR=/usr/include
TT_INSTALLDIR="$TT_BUILDDIR/install"
[ -z "$TT_LIBDIR" ] && TT_LIBDIR=/lib [ -z "$TT_LIBDIR" ] && TT_LIBDIR=/lib
[ -z "$TT_PREFIX" ] && TT_PREFIX=/ [ -z "$TT_PREFIX" ] && TT_PREFIX=/
[ -z "$TT_PROCS" ] && TT_PROCS=$(nproc) [ -z "$TT_PROCS" ] && TT_PROCS=$(nproc)
# Attempt to guess TT_MICROARCH if it isn't defined
TT_ARCH=$(echo $TT_TARGET | cut -d"-" -f1)
if [ -z "$TT_MICROARCH" ]; then
case "$TT_ARCH" in
"x86_64") TT_MICROARCH="skylake";;
*)
echo "TT_MICROARCH not defined for $TT_ARCH"
exit 1
;;
esac
fi
# Apply TT_MICROARCH to CFLAGS/CXXFLAGS
CFLAGS="-march=$TT_MICROARCH $CFLAGS"
CXXFLAGS="-march=$TT_MICROARCH $CXXFLAGS"
# Last, but certainly not least, let's define where we want the build to
# occur and where to put the artifacts. ~ahill
TT_BUILDDIR="$TT_DIR/sources/$SRC_NAME/$SRC_VERSION/$TT_MICROARCH"\
TT_INSTALLDIR="$TT_BUILDDIR/install"
# Create convenience variables
TT_AUTOCONF_COMMON=$(echo "--bindir=$TT_BINDIR \
--build=$TT_BUILD \
--datarootdir=/usr/share \
--host=$TT_TARGET \
--includedir=$TT_INCLUDEDIR \
--libdir=$TT_LIBDIR \
--libexecdir=$TT_LIBDIR \
--localstatedir=/var \
--prefix=$TT_PREFIX \
--runstatedir=/run \
--sbindir=$TT_BINDIR \
--sysconfdir=$TT_CONFDIR \
--target=$TT_TARGET \
--with-sysroot=$TT_SYSROOT" | xargs)
TT_CMAKE_COMMON=$(echo "-DCMAKE_ASM_COMPILER_TARGET=$TT_TARGET \
-DCMAKE_C_COMPILER_TARGET=$TT_TARGET \
-DCMAKE_CXX_COMPILER_TARGET=$TT_TARGET \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$TT_INSTALLDIR" | xargs)
# NOTE: CMake doesn't like having a space in CC and CXX, so we manually
# define a few things if CCACHE is set. ~ahill
if [ ! -z "$CCACHE" ]; then
TT_CMAKE_COMMON=$(echo "$TT_CMAKE_COMMON \
-DCMAKE_C_COMPILER=$(echo $CC | cut -d" " -f2) \
-DCMAKE_C_COMPILER_LAUNCHER=$CCACHE \
-DCMAKE_CXX_COMPILER=$(echo $CXX | cut -d" " -f2)
-DCMAKE_CXX_COMPILER_LAUNCHER=$CCACHE" | xargs)
fi
true true
} }
@ -152,10 +241,9 @@ package_install() {
[ ! -z "$2" ] && TT_SYSROOT=$2 [ ! -z "$2" ] && TT_SYSROOT=$2
package_check $1 $TT_SYSROOT package_check $1 $TT_SYSROOT
echo "Installing $(basename $1)" echo "Installing $(basename $1)"
FULLPATH=$(pwd)/$1
PUSHD=$(pwd) PUSHD=$(pwd)
cd $TT_SYSROOT cd $TT_SYSROOT
xz -cd $FULLPATH | cpio -idmu --quiet xz -cdk $PKG_FULLPATH | cpio -idmu --quiet
cd $PUSHD cd $PUSHD
exit 0 exit 0
} }
@ -165,10 +253,9 @@ package_uninstall() {
[ ! -z "$2" ] && TT_SYSROOT=$2 [ ! -z "$2" ] && TT_SYSROOT=$2
package_check $1 $TT_SYSROOT package_check $1 $TT_SYSROOT
echo "Uninstalling $(basename $1)" echo "Uninstalling $(basename $1)"
FULLPATH=$(pwd)/$1
PUSHD=$(pwd) PUSHD=$(pwd)
cd $TT_SYSROOT cd $TT_SYSROOT
xz -cd $FULLPATH | cpio -it --quiet | tail -n +2 | sort -r | while read path; do xz -cdk $PKG_FULLPATH | cpio -it --quiet | tail -n +2 | sort -r | while read path; do
if [ -d $path ]; then if [ -d $path ]; then
rmdir --ignore-fail-on-non-empty $path rmdir --ignore-fail-on-non-empty $path
else else
@ -189,17 +276,22 @@ source_build() {
echo $SRC_PATCHES | sha256sum -c - > /dev/null echo $SRC_PATCHES | sha256sum -c - > /dev/null
# Is this even the right way to check a return value? ~ahill # Is this even the right way to check a return value? ~ahill
if [ ! "$?" = "0" ]; then if [ ! "$?" = "0" ]; then
echo "Failed to validate patches for $SRC_NAME $SRC_VERSION" echo "Failed to validate patches for $SRC_NAME $SRC_VERSION for $TT_MICROARCH ($TT_TARGET)"
exit 1 exit 1
fi fi
echo $SRC_PATCHES | while read line; do echo $SRC_PATCHES | while read line; do
cp $(echo $line | cut -d" " -f2) $TT_BUILDDIR/ cp $(echo $line | cut -d" " -f2) $TT_BUILDDIR/
done done
fi fi
echo "Building $SRC_NAME $SRC_VERSION" echo "Building $SRC_NAME $SRC_VERSION for $TT_MICROARCH"
PUSHD=$(pwd) PUSHD=$(pwd)
cd $TT_BUILDDIR cd $TT_BUILDDIR
build > build-$(date +%Y%m%d%H%M%S).log 2>&1 # Please don't use this in your build script. This is meant for
# troubleshooting purposes. ~ahill
TT_BUILD_LOG=build-$(date +%Y%m%d%H%M%S).log
echo "Build started with treetap $TT_VERSION at $(date)" > $TT_BUILD_LOG
build >> $TT_BUILD_LOG 2>&1
echo "Build finished at $(date)" >> $TT_BUILD_LOG
cd $PUSHD cd $PUSHD
exit 0 exit 0
} }
@ -244,14 +336,13 @@ source_package() {
source_spec $1 source_spec $1
mkdir -p $TT_BUILDDIR mkdir -p $TT_BUILDDIR
mkdir -p $TT_INSTALLDIR mkdir -p $TT_INSTALLDIR
mkdir -p $TT_PKGDIR/$TT_TARGET mkdir -p $TT_PKGDIR/$TT_MICROARCH
PUSHD=$(pwd) PUSHD=$(pwd)
cd $TT_BUILDDIR cd $TT_BUILDDIR
echo "Moving artifacts for $SRC_NAME $SRC_VERSION" echo "Archiving $SRC_NAME $SRC_VERSION for $TT_MICROARCH"
package > package-$(date +%Y%m%d%H%M%S).log package > package-$(date +%Y%m%d%H%M%S).log
echo "Archiving $SRC_NAME $SRC_VERSION"
cd $TT_INSTALLDIR cd $TT_INSTALLDIR
find | cpio -o --quiet | xz -cz > "$TT_PKGDIR/$TT_TARGET/$SRC_NAME-$SRC_VERSION.cpio.xz" find | cpio -o --quiet | xz -cz > "$TT_PKGDIR/$TT_MICROARCH/$SRC_NAME-$SRC_VERSION-$TT_MICROARCH.cpio.xz"
rm -rf $TT_INSTALLDIR rm -rf $TT_INSTALLDIR
cd $PUSHD cd $PUSHD
exit 0 exit 0