Rework on scripts

Also we are now using a cross compiler to create the toolchain because
I'm too lazy to do too much scripting lmao.
This commit is contained in:
cowmonk 2025-11-15 20:00:42 -07:00
parent a9a3077633
commit b041f9304f
8 changed files with 45 additions and 43 deletions

View file

@ -1,45 +1,43 @@
IS_MAKE=1
include config.mk
all: build
pull:
@if [ ! -d ./sources ]; then \
@if [ ! -d ${PROOT}/sources ]; then \
echo "Sources Directory Not Found!"; \
mkdir -p ./sources; \
mkdir -p ${PROOT}/sources; \
echo "Pulling Sources..."; \
xargs -a ${SOURCES_FILE} -n1 -P4 -- curl -f -L -S -O --output-dir ./sources || { echo "curl failed"; exit 1; }; \
xargs -a ${SOURCES_FILE} -n1 -P4 -- curl -f -L -S -O --output-dir ${PROOT}/sources || { echo "curl failed"; exit 1; }; \
echo "Pulling cross musl compiler to build toolchain"
curl -f -L -O https://musl.cc/${ARCH}-linux-musl-cross.tgz --output-dir ${PROOT}/sources
echo "done"; \
else \
./scripts/check.sh; \
. ${PROOT}/scripts/check.sh; \
fi
build: init
./scripts/musl-cross.sh
./scripts/elftoolchain-cross.sh
. ${PROOT}/scripts/musl-cross.sh
. ${PROOT}/scripts/elftoolchain-cross.sh
init:
@if [ ! -d ./build/${FROOT} ]; then \
@echo "Making toolchain directory..."; \
mkdir -p ./build/${FROOT}; \
@echo "Making cross directory"; \
mkdir -p ./build/cross; \
echo "Making toolchain directory..."; \
mkdir -p ${PROOT}/build/${FROOT}; \
fi
@echo "updating configuration based on config.mk..."
cp -r config.mk ./scripts/config.sh
sed -i 's/shell //g' ./scripts/config.sh
cp -r config.mk ${PROOT}/scripts/config.sh
sed -i 's/shell //g' ${PROOT}/scripts/config.sh
clean:
rm -rf ./sources
rm -rf ./build
rm -rf ${PROOT}/sources
rm -rf ${PROOT}/build
help:
@echo "musllvm"
@echo "-----------------------"
@echo "commands:"
@echo " all - make all (duh)"
@echo " pull - pull all sources (on first run), second run will check indivdually"
@echo " pull - pull all sources (on first run), second run will check individually"
@echo " build - build will build to toolchain"
@echo " clean - clean up all sources and build artifacts"
@echo " init - sets up everything, run also every time you make changes to config.mk"

View file

@ -7,9 +7,10 @@
# these are shared between the Makefile and scripts
#
ARCH=$(shell uname -m)
SOURCES_FILE=./sources.list
PROOT=${PWD}
SOURCES_FILE=${PROOT}/sources.list
FROOT="${ARCH}-musllvm"
CROSS="./build/cross" # cross directory
CROSS="${PROOT}/build/cross" # cross directory
# MAKEFLAGS to parse the amounto of cores used
MAKEFLAGS="-j$(shell nproc) -l$(shell nproc)"

View file

@ -1,15 +1,15 @@
#!/bin/sh
set -eu
source ./scripts/config.sh
. $PWD/scripts/config.sh
while IFS= read -r url; do \
[ -z "$url" ] && continue; \
fname="$(printf '%s' "$url" | sed -E 's/[?#].*$//' | sed -E 's!.*/!!')"; \
if [ -e "./sources/$fname" ]; then \
if [ -e "$PROOT/sources/$fname" ]; then \
printf "SKIP: %s (already exists)\n" "$fname"; \
else \
printf "GET: %s -> %s\n" "$url" "$fname"; \
curl -f -L -O -S --output-dir "./sources/" "$url" || { printf "ERROR: failed to download %s\n" "$url"; exit 1; }; \
curl -f -L -O -S --output-dir "$PROOT/sources/" "$url" || { printf "ERROR: failed to download %s\n" "$url"; exit 1; }; \
fi; \
done < "$SOURCES_FILE"; \

View file

@ -7,9 +7,10 @@
# these are shared between the Makefile and scripts
#
ARCH=$(uname -m)
SOURCES_FILE=./sources.list
PROOT=${PWD}
SOURCES_FILE=${PROOT}/sources.list
FROOT="${ARCH}-musllvm"
CROSS="./build/cross" # cross directory
CROSS="${PROOT}/build/cross" # cross directory
# MAKEFLAGS to parse the amounto of cores used
MAKEFLAGS="-j$(nproc) -l$(nproc)"

View file

@ -1,9 +1,9 @@
#!/bin/sh
set -eu
source ./scripts/config.sh
. $PWD/scripts/config.sh
ELF_TAR=$(ls ./sources/elftoolchain-*.tar.* 2>/dev/null | head -n 1 | xargs basename)
ELF_TAR=$(ls "$PROOT"/sources/elftoolchain-*.tar.* 2>/dev/null | head -n 1 | xargs basename)
if [ -z "$ELF_TAR" ]; then
echo "ERR: No Musl tarball found in sources directory"
exit 1
@ -16,15 +16,15 @@ else
export CC="cc"
fi
if [ ! -d ./build/"$ELF_SOURCE" ]; then
if [ ! -d $PROOT/build/"$ELF_SOURCE" ]; then
echo "Extracting Elftoolchain tarball to ./build/"
tar -xpf ./sources/"$ELF_TAR" -C ./build
tar -xpf $PROOT/sources/"$ELF_TAR" -C ./build
else
echo "Elftoolchain source already extracted."
fi
echo "Buliding musl headers"
if [ -f "./build/$ELF_SOURCE" ]; then
if [ -f "$PROOT/build/$ELF_SOURCE" ]; then
echo "ELFTOOLCHAIN already built, skipping..."
exit
fi
@ -33,7 +33,7 @@ cd ./build/"$ELF_SOURCE"
echo "patching elftoolchain-cross..."
patch -Np1 < ../../patches/elftoolchain/*
patch -Np1 < "$PROOT"/patches/elftoolchain/*
echo "Installing elftoolchain-cross..."

View file

@ -1,9 +1,9 @@
#!/bin/sh
set -eu
source ./scripts/config.sh
. $PWD/scripts/config.sh
LINUX_TAR=$(ls ./sources/linux-*.tar.* 2>/dev/null | head -n 1 | xargs basename)
LINUX_TAR=$(ls "$PROOT"/sources/linux-*.tar.* 2>/dev/null | head -n 1 | xargs basename)
if [ -z "$LINUX_TAR" ]; then
echo "ERR: No Linux tarball found in sources directory"
exit 1
@ -15,18 +15,18 @@ if command -v "clang" >/dev/null 2>&1 && command -v "lld" >/dev/null 2>&1; then
export LLVM_IAS=1
fi
if [ ! -d ./build/"$LINUX_SOURCE" ]; then
if [ ! -d $PROOT/build/"$LINUX_SOURCE" ]; then
echo "Extracting Linux tarball to ./build/"
tar -xpf ./sources/"$LINUX_TAR" -C ./build
tar -xpf $PROOT/sources/"$LINUX_TAR" -C $PROOT/build
else
echo "Linux source already extracted."
fi
echo "Creating target include directory"
mkdir -pv ./build/"$FROOT"/include
mkdir -pv $PROOT/build/"$FROOT"/include
echo "Building Headers"
if [ -d ./build/"$FROOT"/include/linux ]; then
if [ -d $PROOT/build/"$FROOT"/include/linux ]; then
echo "Headers already built, skipping..."
exit
fi
@ -36,5 +36,5 @@ cd ./build/"$LINUX_SOURCE"
make mrproper
make headers
find usr/include -type f ! -name '*.h' -delete
cp -rv usr/include/* ../"$FROOT"/include/
cp -rv usr/include/* $PROOT/build/"$FROOT"/include/

View file

@ -1,9 +1,9 @@
#!/bin/sh
set -eu
source ./scripts/config.sh
. $PWD/scripts/config.sh
MUSL_TAR=$(ls ./sources/musl-*.tar.* 2>/dev/null | head -n 1 | xargs basename)
MUSL_TAR=$(ls "$PROOT"/sources/musl-*.tar.* 2>/dev/null | head -n 1 | xargs basename)
if [ -z "$MUSL_TAR" ]; then
echo "ERR: No Musl tarball found in sources directory"
exit 1
@ -16,7 +16,7 @@ else
export CC="cc"
fi
if [ ! -d ./build/"MUSL_SOURCE" ]; then
if [ ! -d $PROOT/build/"MUSL_SOURCE" ]; then
echo "Extracting Musl tarball to ./build/"
tar -xpf ./sources/"$MUSL_TAR" -C ./build
else
@ -24,15 +24,15 @@ else
fi
echo "Buliding musl headers"
if [ -f "./build/$MUSL_SOURCE" ]; then
if [ -f "$PROOT/build/$MUSL_SOURCE" ]; then
echo "Musl headers already built, skipping..."
exit
fi
cd ./build/"$MUSL_SOURCE"
cd $PROOT/build/"$MUSL_SOURCE"
echo "Installing musl headers..."
./configure \
--prefix=/
DESTDIR=../../$CROSS make ARCH=$(uname -m) install-headers
DESTDIR=$CROSS make ARCH=$(uname -m) install-headers

View file

@ -2,6 +2,8 @@ https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.17.7.tar.xz
https://musl.libc.org/releases/musl-1.2.5.tar.gz
https://pub.sortix.org/libz/libz-1.2.8.2025.03.07.tar.gz
https://github.com/chimera-linux/libatomic-chimera/archive/refs/tags/v0.90.0.tar.gz
https://github.com/Projeto-Pindorama/musl-compat/archive/refs/tags/20251111.tar.gz
https://github.com/libarchive/libarchive/releases/download/v3.8.2/libarchive-3.8.2.tar.gz
https://sourceforge.net/projects/elftoolchain/files/Sources/elftoolchain-0.7.1/elftoolchain-0.7.1.tar.bz2
https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.2/llvm-21.1.2.src.tar.xz
https://github.com/llvm/llvm-project/releases/download/llvmorg-21.1.2/cmake-21.1.2.src.tar.xz