From 88c5c8ccfc87137975ca64f1b29685604ff513e7 Mon Sep 17 00:00:00 2001 From: Carlton Shepherd Date: Thu, 9 Mar 2023 09:03:28 +0000 Subject: [PATCH] Fix Ubuntu 22.04 issues and add parallelization support (#21) --- Dockerfile | 6 ++-- README.md | 3 ++ i686-elf-tools.sh | 91 ++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 82 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index c34439c..75785f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,10 +7,12 @@ RUN apt-get update && apt-get install -y \ git \ wget \ sudo \ + make \ + lsb-release \ && chmod +x /i686-elf-tools/i686-elf-tools.sh \ - && /i686-elf-tools/i686-elf-tools.sh env \ + && /i686-elf-tools/i686-elf-tools.sh env -parallel \ && rm -rf /var/lib/apt/lists/* \ && rm -rf /opt/mxe/.ccache \ && rm -rf /opt/mxe/pkg -ENTRYPOINT ["/i686-elf-tools/i686-elf-tools.sh"] \ No newline at end of file +ENTRYPOINT ["/i686-elf-tools/i686-elf-tools.sh"] diff --git a/README.md b/README.md index 6def366..14b5225 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ If you experience any issues, you can specify one or more command line arguments * `-bv`/`--binutils-version` - specify the Binutils version to build * `-dv`/`--gdb-version` - specify the GDB version to build * `-64` - compile for x86_64-elf instead of i686-elf +* `-parallel` - build `make` recipes in [parallel](https://www.gnu.org/software/make/manual/html_node/Parallel.html) (`-j4`). To modify the number of jobs executed in parallel, modify `i686-elf-tools.sh` ```sh # Compile binutils and gcc only @@ -96,6 +97,8 @@ e.g. **~/build-i686-elf/build-gcc-7.1.0/gcc_make.log** If you attempt to run `make` and `configure` commands manually that depend on components of the linux i686-elf toolchain, ensure `~/build-i686-elf/linux/output/bin` is on your path, else you may get errors about binaries being missing. +By default, i686-elf-tools will build `make` recipes in parallel. If any arguments are specified to `i686-elf-tools.sh` however, parallel compilation must be opted into by explicitly specifying `-parallel`. + ## Mac OS X Installing an i386-elf toolchain on Mac OS X is - theoretically - outstandingly simple process. Note that the following relies on a third party script and is not supported by me. It may be possible to run *i686-elf-tools.sh* on Mac OS X with a bit of tweaking (like not using `apt-get` to install packages) however this is not supported. diff --git a/i686-elf-tools.sh b/i686-elf-tools.sh index af3a227..51b89a2 100755 --- a/i686-elf-tools.sh +++ b/i686-elf-tools.sh @@ -1,7 +1,7 @@ #!/bin/bash # i686-elf-tools.sh -# v1.3.1 +# v1.3.2 # Define Global Variables @@ -22,7 +22,7 @@ if [ $# -eq 0 ]; then BUILD_GCC=true BUILD_GDB=true ZIP=true - + PARALLEL=true args="binutils gcc gdb zip" else args=$@ @@ -41,6 +41,7 @@ case $key in zip) ZIP=true; ALL_PRODUCTS=false; shift ;; env) ENV_ONLY=true; shift ;; -64) x64=true; shift ;; + -parallel) PARALLEL=true; shift ;; -bv|--binutils-version) BINUTILS_VERSION="$2"; shift; shift ;; -gv|--gcc-version) GCC_VERSION="$2"; shift; shift ;; -dv|--gdb-version) GDB_VERSION="$2"; shift; shift ;; @@ -69,6 +70,7 @@ echo "BINUTILS_VERSION = ${BINUTILS_VERSION}" echo "GCC_VERSION = ${GCC_VERSION}" echo "GDB_VERSION = ${GDB_VERSION}" echo "PATH = ${PATH}" +echo "PARALLEL = ${PARALLEL}" function main { @@ -96,21 +98,58 @@ function main { finalize } - function installPackages { - + pkgList=( + git + autoconf + automake + autopoint + bash + bison + bzip2 + flex + gettext + g++ + gperf + intltool + libffi-dev + libgdk-pixbuf2.0-dev + libtool + libltdl-dev + libssl-dev + libxml-parser-perl + make + python3-mako + openssl + p7zip-full + patch + perl + pkg-config + ruby + scons + sed + unzip + wget + xz-utils + libtool-bin + texinfo + g++-multilib + lzip) echoColor "Installing packages" - sudo -E DEBIAN_FRONTEND=noninteractive apt-get -qq install git \ - autoconf automake autopoint bash bison bzip2 flex gettext\ - g++ gperf intltool libffi-dev libgdk-pixbuf2.0-dev \ - libtool libltdl-dev libssl-dev libxml-parser-perl make python3-mako \ - openssl p7zip-full patch perl pkg-config python ruby scons \ - sed unzip wget xz-utils libtool-bin texinfo g++-multilib lzip -y + # Fix correct python packages on modern Ubuntu versions + if [[ $(lsb_release -a) =~ .*"Ubuntu".*$ ]]; then + pkgList+=(python3 python-is-python3) + else + pkgList+=(python) + fi + + for pkg in ${pkgList[@]}; do + sudo -E DEBIAN_FRONTEND=noninteractive apt-get -qq install $pkg -y + done } # MXE - function installMXE { echoColor "Installing MXE" @@ -121,7 +160,11 @@ function installMXE { cd /opt sudo -E git clone https://github.com/mxe/mxe.git cd mxe - sudo make gcc + if [[ $PARALLEL == true ]]; then + sudo make -j4 gcc + else + sudo make gcc + fi else echoColor " MXE is already installed. You'd better make sure that you've previously made MXE's gcc! (/opt/mxe/usr/bin/i686-w64-mingw32.static-gcc)" fi @@ -266,7 +309,11 @@ function compileBinutils { # Make echoColor " Making (binutils_make.log)" - make >> binutils_make.log + if [[ $PARALLEL == true ]]; then + make -j4 >> binutils_make.log + else + make >> binutils_make.log + fi # Install echoColor " Installing (binutils_install.log)" @@ -309,7 +356,11 @@ function compileGCC { # Make GCC echoColor " Making gcc (gcc_make.log)" - make all-gcc >> gcc_make.log + if [[ $PARALLEL == true ]]; then + make -j4 all-gcc >> gcc_make.log + else + make all-gcc >> gcc_make.log + fi # Install GCC echoColor " Installing gcc (gcc_install.log)" @@ -317,7 +368,11 @@ function compileGCC { # Make libgcc echoColor " Making libgcc (libgcc_make.log)" - make all-target-libgcc >> libgcc_make.log + if [[ $PARALLEL == true ]]; then + make -j4 all-target-libgcc >> libgcc_make.log + else + make all-target-libgcc >> libgcc_make.log + fi # Install libgcc echoColor " Installing libgcc (libgcc_install.log)" @@ -370,7 +425,11 @@ function compileGDB { # Make echoColor " Making (gdb_make.log)" - make >> gdb_make.log + if [[ $PARALLEL == true ]]; then + make -j4 >> gdb_make.log + else + make >> gdb_make.log + fi # Install echoColor " Installing (gdb_install.log)"