commit 39614b7d6548878755f0e40c608a6d60add9b2f9 Author: Denis Benato Date: Fri Dec 6 19:04:37 2024 +0100 m4 non compila diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f8d3349 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/out +/binutils* diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..1f792b0 --- /dev/null +++ b/build.sh @@ -0,0 +1,279 @@ +#!/bin/bash + +export LINUX_VERSION="6.12.1" + +# Function to handle errors +error_handler() { + local exit_code=$? + local line_number=$1 + local file_name=$2 + echo "Error in file: $file_name, line: $line_number, reason: Command exited with status $exit_code" +} + +# Set the trap to catch errors +trap 'error_handler $LINENO $0' ERR + +set -eo pipefail + +if [ ! -d "./sources" ]; then + echo "Run this script from the right directory" + exit 1 +fi + +export BASE_DIR=$(pwd) + +if [ -z "$ARCH" ]; then + echo "You must set a target architecture among supported ones:" + echo "i386" + echo "x86_64" + echo "armv5" + + exit 1 +fi + +if [ -z "$LFS_TGT" ]; then + export LFS_TGT="$ARCH-lfs-linux-gnu" + echo "Target triplet set to '$LFS_TGT'. You can specify another one with the LFS_TGT env var." +fi + +if [ ! -d "$LFS_TGT" ]; then + export LFS="$(pwd)/out/$LFS_TGT/rootfs" + + echo "Target rootfs set to '$LFS_TGT'. You can override this by setting the LFS_TGT env var." +fi + +# test bash +bash --version +echo "" + +# test rsync +rsync --version +echo "" + +# test clang +clang --version +echo "" + +# test lld +ld --version +echo "" + +make --version +echo "" + +# Create the target directory +mkdir -p "$LFS" +export STEPS_DIR="$LFS/../steps/" +mkdir -vp "$STEPS_DIR" + +export LFS_TOOLS="$LFS/tools" +mkdir -vp "$LFS_TOOLS" + +export PATH="$LFS_TOOLS/bin/:$PATH" + +export LFS_BUILD="$LFS/../" + +unset CFLAGS + +# Create a directory layout +if [ ! -d "$LFS/etc" ]; then + mkdir -pv $LFS/{etc,var} $LFS/usr/{bin,lib,sbin} + + for i in bin lib sbin; do + ln -sv usr/$i $LFS/$i + done + + case $ARCH in + x86_64) mkdir -pv $LFS/lib64 ;; + esac +fi + +# Build binutils +if [ ! -f "$STEPS_DIR/binutils" ]; then + if [ ! -d "$LFS_BUILD/binutils" ]; then + tar -xf "$BASE_DIR/sources/binutils-2.43.tar.zst" + mv "binutils-2.43" "$LFS_BUILD/binutils" + fi + cd "$LFS_BUILD/binutils" + + mkdir -vp build + cd build + "../configure" \ + --prefix=$LFS_TOOLS \ + --with-sysroot=$LFS \ + --target=$LFS_TGT \ + --disable-nls \ + --enable-gprofng=no \ + --disable-werror \ + --enable-new-dtags \ + --disable-multilib \ + --enable-default-hash-style=gnu + make configure-host + make -j 32 + make install + + cd "$BASE_DIR" + rm -rf binutils-2.43 + touch "$STEPS_DIR/binutils" +fi + +# Build gcc +if [ ! -f "$STEPS_DIR/gcc" ]; then + if [ ! -d "$LFS_BUILD/gcc" ]; then + tar -xzf "$BASE_DIR/sources/gcc-14.2.0.tar.gz" + mv "gcc-14.2.0" "$LFS_BUILD/gcc" + fi + cd "$LFS_BUILD/gcc/" + tar -xf "$BASE_DIR/sources/mpfr-4.2.1.tar.xz" + mv -v mpfr-4.2.1 mpfr + tar -xf "$BASE_DIR/sources/gmp-6.3.0.tar.xz" + mv -v gmp-6.3.0 gmp + tar -xf "$BASE_DIR/sources/mpc-1.3.1.tar.gz" + mv -v mpc-1.3.1 mpc + + # On x86_64 hosts, set the default directory name for 64-bit libraries to “lib” + case $(uname -m) in + x86_64) + sed -e '/m64=/s/lib64/lib/' \ + -i.orig gcc/config/i386/t-linux64 + ;; + esac + + mkdir -vp build + cd build + + "../configure" \ + --target=$LFS_TGT \ + --prefix=$LFS_TOOLS \ + --with-glibc-version=2.40 \ + --with-sysroot=$LFS \ + --with-newlib \ + --without-headers \ + --enable-default-pie \ + --enable-default-ssp \ + --disable-nls \ + --disable-shared \ + --disable-multilib \ + --disable-threads \ + --disable-libatomic \ + --disable-libgomp \ + --disable-libquadmath \ + --disable-libssp \ + --disable-libvtv \ + --disable-libstdcxx \ + --disable-decimal-float \ + --disable-multilib \ + --enable-languages=c,c++ + make -j 32 # if build fails add --disable-libsanitizer + make install + cd "$BASE_DIR" + rm -rf "$LFS_BUILD/gcc/build" # Do not remove the whole gcc directory: we need it for libstdc++ + touch "$STEPS_DIR/gcc" +fi + +# Install kernel headers +if [ ! -f "$STEPS_DIR/linux-headers" ]; then + if [ ! -d "$LFS_BUILD/linux" ]; then + tar -xzf "$BASE_DIR/sources/linux-$LINUX_VERSION.tar.gz" + mv "linux-$LINUX_VERSION" "$LFS_BUILD/linux" + fi + cd "$LFS_BUILD/linux" + make mrproper + LD="$LFS_TGT-ld" CC="$LFS_TGT-gcc" CXX="$LFS_TGT-g++" AR="$LFS_TGT-ar" RANLIB="$LFS_TGT-ranlib" make headers_install ARCH="$ARCH" INSTALL_HDR_PATH="$LFS/usr" + cd "$BASE_DIR" + rm -rf "$LFS_BUILD/linux" + touch "$STEPS_DIR/linux-headers" +fi + +# build glibc +if [ ! -f "$STEPS_DIR/glibc" ]; then + if [ ! -d "$LFS_BUILD/glibc" ]; then + tar -xzf "$BASE_DIR/sources/glibc-2.40.tar.gz" + mv "glibc-2.40" "$LFS_BUILD/glibc" + fi + cd "$LFS_BUILD/glibc" + + mkdir -vp build + cd build + + echo "rootsbindir=/usr/sbin" > configparms + + "../configure" \ + --prefix=/usr \ + --host=$LFS_TGT \ + --build=$(../scripts/config.guess) \ + --enable-kernel=4.19 \ + --with-headers=$LFS/usr/include \ + --disable-debug \ + --without-selinux \ + --disable-nscd \ + libc_cv_slibdir=/usr/lib + make -j 32 + make DESTDIR=$LFS install + sed '/RTLDLIST=/s@/usr@@g' -i $LFS/usr/bin/ldd + + cd "$BASE_DIR" + rm -rf "$LFS_BUILD/glibc" + touch "$STEPS_DIR/glibc" +fi + +# test the cross toolchain +which -- $LFS_TGT-as || echo $LFS_TGT-as is not in the PATH +echo 'int main(){}' | "$LFS_TGT-gcc" -xc - +"$LFS_TGT-readelf" -l a.out > test_compiler +cat test_compiler | grep ld-linux +rm -v a.out test_compiler + +# build libstdc++ +if [ ! -f "$STEPS_DIR/libstdcxx" ]; then + bash unpack-gcc.sh + cd "$LFS_BUILD/gcc" + + mkdir -vp build_libstdcxx + cd build_libstdcxx + + #PATH="$PATH:$LFS_TOOLS/bin" RANLIB="$LFS_TOOLS/bin/$LFS_TGT-ranlib" AR="$LFS_TOOLS/bin/$LFS_TGT-ar" LD="$LFS_TOOLS/bin/$LFS_TGT-ld" CC="$LFS_TOOLS/bin/$LFS_TGT-gcc" CXX="$LFS_TOOLS/bin/$LFS_TGT-g++" + bash \ + ../libstdc++-v3/configure \ + --host=$LFS_TGT \ + --build=$(../config.guess) \ + --prefix=/usr \ + --disable-multilib \ + --disable-nls \ + --disable-libstdcxx-pch \ + --with-gxx-include-dir=/tools/$LFS_TGT/include/c++/14.2.0 + make -j 32 + make DESTDIR=$LFS install + # Remove the libtool archive files because they are harmful for cross-compilation + rm -v $LFS/usr/lib/lib{stdc++{,exp,fs},supc++}.la + + cd "$BASE_DIR" + rm -rf "$LFS_BUILD/gcc" + touch "$STEPS_DIR/libstdcxx" +fi + +# build m4 +if [ ! -f "$STEPS_DIR/m4" ]; then + if [ ! -d "$LFS_BUILD/m4" ]; then + tar -xzf "$BASE_DIR/sources/m4-1.4.19.tar.gz" + mv "m4-1.4.19" "$LFS_BUILD/m4" + fi + cd "$LFS_BUILD/m4" + + #mkdir -vp build + #cd build + + echo "rootsbindir=/usr/sbin" > configparms + + "./configure" \ + --prefix=/usr \ + --host=$LFS_TGT \ + --build=$(build-aux/config.guess) \ + + make -j 32 + make DESTDIR=$LFS install + + cd "$BASE_DIR" + rm -rf "$LFS_BUILD/m4" + touch "$STEPS_DIR/m4" +fi \ No newline at end of file diff --git a/unpack-gcc.sh b/unpack-gcc.sh new file mode 100644 index 0000000..803a91f --- /dev/null +++ b/unpack-gcc.sh @@ -0,0 +1,21 @@ +if [ ! -d "$LFS_BUILD/gcc" ]; then + tar -xzf "$BASE_DIR/sources/gcc-14.2.0.tar.gz" + mv "gcc-14.2.0" "$LFS_BUILD/gcc" +fi +cd "$LFS_BUILD/gcc/" +tar -xf "$BASE_DIR/sources/mpfr-4.2.1.tar.xz" +mv -v mpfr-4.2.1 mpfr +tar -xf "$BASE_DIR/sources/gmp-6.3.0.tar.xz" +mv -v gmp-6.3.0 gmp +tar -xf "$BASE_DIR/sources/mpc-1.3.1.tar.gz" +mv -v mpc-1.3.1 mpc + +# On x86_64 hosts, set the default directory name for 64-bit libraries to “lib” +case $(uname -m) in +x86_64) + sed -e '/m64=/s/lib64/lib/' \ + -i.orig gcc/config/i386/t-linux64 +;; +esac + +cd "$BASE_DIR" \ No newline at end of file diff --git a/version-check.sh b/version-check.sh new file mode 100755 index 0000000..ba2323b --- /dev/null +++ b/version-check.sh @@ -0,0 +1,90 @@ +#!/bin/bash +# A script to list version numbers of critical development tools + +# If you have tools installed in other directories, adjust PATH here AND +# in ~lfs/.bashrc (section 4.4) as well. + +LC_ALL=C +PATH=/usr/bin:/bin + +bail() { echo "FATAL: $1"; exit 1; } +grep --version > /dev/null 2> /dev/null || bail "grep does not work" +sed '' /dev/null || bail "sed does not work" +sort /dev/null || bail "sort does not work" + +ver_check() +{ + if ! type -p $2 &>/dev/null + then + echo "ERROR: Cannot find $2 ($1)"; return 1; + fi + v=$($2 --version 2>&1 | grep -E -o '[0-9]+\.[0-9\.]+[a-z]*' | head -n1) + if printf '%s\n' $3 $v | sort --version-sort --check &>/dev/null + then + printf "OK: %-9s %-6s >= $3\n" "$1" "$v"; return 0; + else + printf "ERROR: %-9s is TOO OLD ($3 or later required)\n" "$1"; + return 1; + fi +} + +ver_kernel() +{ + kver=$(uname -r | grep -E -o '^[0-9\.]+') + if printf '%s\n' $1 $kver | sort --version-sort --check &>/dev/null + then + printf "OK: Linux Kernel $kver >= $1\n"; return 0; + else + printf "ERROR: Linux Kernel ($kver) is TOO OLD ($1 or later required)\n" "$kver"; + return 1; + fi +} + +# Coreutils first because --version-sort needs Coreutils >= 7.0 +ver_check Coreutils sort 8.1 || bail "Coreutils too old, stop" +ver_check Bash bash 3.2 +ver_check Binutils ld 2.13.1 +ver_check Bison bison 2.7 +ver_check Diffutils diff 2.8.1 +ver_check Findutils find 4.2.31 +ver_check Gawk gawk 4.0.1 +ver_check GCC gcc 5.2 +ver_check "GCC (C++)" g++ 5.2 +ver_check Grep grep 2.5.1a +ver_check Gzip gzip 1.3.12 +ver_check M4 m4 1.4.10 +ver_check Make make 4.0 +ver_check Patch patch 2.5.4 +ver_check Perl perl 5.8.8 +ver_check Python python3 3.4 +ver_check Sed sed 4.1.5 +ver_check Tar tar 1.22 +ver_check Texinfo texi2any 5.0 +ver_check Xz xz 5.0.0 +ver_kernel 4.19 + +if mount | grep -q 'devpts on /dev/pts' && [ -e /dev/ptmx ] +then echo "OK: Linux Kernel supports UNIX 98 PTY"; +else echo "ERROR: Linux Kernel does NOT support UNIX 98 PTY"; fi + +alias_check() { + if $1 --version 2>&1 | grep -qi $2 + then printf "OK: %-4s is $2\n" "$1"; + else printf "ERROR: %-4s is NOT $2\n" "$1"; fi +} +echo "Aliases:" +alias_check awk GNU +alias_check yacc Bison +alias_check sh Bash + +echo "Compiler check:" +if printf "int main(){}" | g++ -x c++ - +then echo "OK: g++ works"; +else echo "ERROR: g++ does NOT work"; fi +rm -f a.out + +if [ "$(nproc)" = "" ]; then + echo "ERROR: nproc is not available or it produces empty output" +else + echo "OK: nproc reports $(nproc) logical cores are available" +fi \ No newline at end of file