From 99e2fefc9d27474e7b110a695e2b1f90d55be60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 9 Nov 2018 22:20:34 +0200 Subject: [PATCH] Use nproc and sysctl -n hw.cpu for default initializing CORES This avoids having to pass --build-arg CORES=n when building the docker images. --- Dockerfile | 2 -- Dockerfile.cross | 4 +--- Dockerfile.dev | 2 -- build-compiler-rt.sh | 2 ++ build-libcxx.sh | 2 ++ build-libssp.sh | 2 ++ build-llvm.sh | 2 ++ build-mingw-w64-libraries.sh | 2 ++ build-mingw-w64.sh | 2 ++ 9 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index b6fe67b..55292bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,8 +13,6 @@ RUN git config --global user.name "LLVM MinGW" && \ WORKDIR /build -ARG CORES=4 - ENV TOOLCHAIN_PREFIX=/opt/llvm-mingw # Build and strip the LLVM installation diff --git a/Dockerfile.cross b/Dockerfile.cross index 738ba7d..5869b6d 100644 --- a/Dockerfile.cross +++ b/Dockerfile.cross @@ -22,8 +22,6 @@ ENV CROSS_TOOLCHAIN_PREFIX=/opt/llvm-mingw-$CROSS_ARCH ENV EXEEXT=.exe ENV HOST=$CROSS_ARCH-w64-mingw32 -ARG CORES=4 - COPY build-llvm.sh . RUN ./build-llvm.sh $CROSS_TOOLCHAIN_PREFIX COPY strip-llvm.sh . @@ -47,7 +45,7 @@ RUN wget -q https://ftp.gnu.org/gnu/binutils/binutils-2.31.1.tar.xz && \ tar -Jxf binutils-2.31.1.tar.xz && \ cd binutils-2.31.1 && \ ./configure --host=$HOST --target=x86_64-w64-mingw32 --prefix=/opt/binutils LDFLAGS="-Wl,-s" && \ - make -j$CORES && \ + make -j$(nproc) && \ make install && \ cp /opt/binutils/x86_64-w64-mingw32/bin/objcopy.exe $CROSS_TOOLCHAIN_PREFIX/bin/binutils-objcopy.exe && \ cp /opt/binutils/x86_64-w64-mingw32/bin/strip.exe $CROSS_TOOLCHAIN_PREFIX/bin/binutils-strip.exe diff --git a/Dockerfile.dev b/Dockerfile.dev index ec1ccef..81f2695 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -13,8 +13,6 @@ RUN git config --global user.name "LLVM MinGW" && \ WORKDIR /build -ARG CORES=4 - ENV TOOLCHAIN_PREFIX=/opt/llvm-mingw # Build LLVM diff --git a/build-compiler-rt.sh b/build-compiler-rt.sh index 4a1da78..8712f49 100755 --- a/build-compiler-rt.sh +++ b/build-compiler-rt.sh @@ -21,6 +21,8 @@ if [ -z "$PREFIX" ]; then fi export PATH=$PREFIX/bin:$PATH +: ${CORES:=$(nproc 2>/dev/null)} +: ${CORES:=$(sysctl -n hw.ncpu 2>/dev/null)} : ${CORES:=4} : ${ARCHS:=${TOOLCHAIN_ARCHS-i686 x86_64 armv7 aarch64}} diff --git a/build-libcxx.sh b/build-libcxx.sh index e9cc586..809c093 100755 --- a/build-libcxx.sh +++ b/build-libcxx.sh @@ -25,6 +25,8 @@ if [ -z "$PREFIX" ]; then fi export PATH=$PREFIX/bin:$PATH +: ${CORES:=$(nproc 2>/dev/null)} +: ${CORES:=$(sysctl -n hw.ncpu 2>/dev/null)} : ${CORES:=4} : ${ARCHS:=${TOOLCHAIN_ARCHS-i686 x86_64 armv7 aarch64}} diff --git a/build-libssp.sh b/build-libssp.sh index aabbeb4..8dea69e 100755 --- a/build-libssp.sh +++ b/build-libssp.sh @@ -9,6 +9,8 @@ fi PREFIX="$1" export PATH=$PREFIX/bin:$PATH +: ${CORES:=$(nproc 2>/dev/null)} +: ${CORES:=$(sysctl -n hw.ncpu 2>/dev/null)} : ${CORES:=4} : ${ARCHS:=${TOOLCHAIN_ARCHS-i686 x86_64 armv7 aarch64}} diff --git a/build-llvm.sh b/build-llvm.sh index d9bc9e6..6ebdb1e 100755 --- a/build-llvm.sh +++ b/build-llvm.sh @@ -22,6 +22,8 @@ if [ -z "$PREFIX" ]; then exit 1 fi +: ${CORES:=$(nproc 2>/dev/null)} +: ${CORES:=$(sysctl -n hw.ncpu 2>/dev/null)} : ${CORES:=4} if [ ! -d llvm ]; then diff --git a/build-mingw-w64-libraries.sh b/build-mingw-w64-libraries.sh index 9a66a42..f11b8af 100755 --- a/build-mingw-w64-libraries.sh +++ b/build-mingw-w64-libraries.sh @@ -9,6 +9,8 @@ fi PREFIX="$1" export PATH=$PREFIX/bin:$PATH +: ${CORES:=$(nproc 2>/dev/null)} +: ${CORES:=$(sysctl -n hw.ncpu 2>/dev/null)} : ${CORES:=4} : ${ARCHS:=${TOOLCHAIN_ARCHS-i686 x86_64 armv7 aarch64}} diff --git a/build-mingw-w64.sh b/build-mingw-w64.sh index 3284f2d..2b767ad 100755 --- a/build-mingw-w64.sh +++ b/build-mingw-w64.sh @@ -23,6 +23,8 @@ else true fi +: ${CORES:=$(nproc 2>/dev/null)} +: ${CORES:=$(sysctl -n hw.ncpu 2>/dev/null)} : ${CORES:=4} : ${ARCHS:=${TOOLCHAIN_ARCHS-i686 x86_64 armv7 aarch64}}