fix broken dependencies when building on aarch64
authorJacob Lifshay <programmerjake@gmail.com>
Thu, 21 Jul 2022 03:08:41 +0000 (20:08 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Thu, 21 Jul 2022 03:08:41 +0000 (20:08 -0700)
Makefile
install-deps.sh

index 67f9c5866634ec5b711496efd04561b97aab5c32..a7015370a935ed84a43bd7e79a7bd46993a3b3ab 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,18 @@
 .PHONY: all clean configure
-all: build-ppc64le/benchmarks build-aarch64/benchmarks build-x86_64/benchmarks
+
+host_arch = $(shell uname -m)
+ifeq ($(host_arch),x86_64)
+       enabled_arches = ppc64le aarch64 x86_64
+else ifeq ($(host_arch),aarch64)
+       # debian 10 doesn't have cross-compilers for ppc64le from aarch64
+       enabled_arches = aarch64 x86_64
+else ifeq ($(host_arch),ppc64le)
+       enabled_arches = ppc64le aarch64 x86_64
+else
+       $(error unsupported arch $(host_arch))
+endif
+
+all: $(foreach arch,$(enabled_arches),build-$(arch)/benchmarks)
 
 common_cmake_flags = -S .
 common_cmake_flags += -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE
@@ -7,7 +20,7 @@ common_cmake_flags += -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE
 reset_make_env = "MAKEFLAGS=" "MFLAGS=" "MAKELEVEL=" "MAKE_TERMERR=" "MAKE_TERMOUT="
 
 .installed-dependencies: install-deps.sh
-       ./install-deps.sh
+       ./install-deps.sh $(enabled_arches)
        touch .installed-dependencies
 
 build-ppc64le/Makefile: toolchain-powerpc64le-linux-gnu.cmake CMakeLists.txt .installed-dependencies
@@ -22,7 +35,7 @@ build-x86_64/Makefile: toolchain-x86_64-linux-gnu.cmake CMakeLists.txt .installe
        rm -fr build-x86_64
        env $(reset_make_env) cmake $(common_cmake_flags) -B build-x86_64 -DCMAKE_TOOLCHAIN_FILE=toolchain-x86_64-linux-gnu.cmake
 
-configure: build-ppc64le/Makefile build-aarch64/Makefile build-x86_64/Makefile
+configure: $(foreach arch,$(enabled_arches),build-$(arch)/Makefile)
 
 .PHONY: __force-run
 
index b9c9fd2d95547d9357f23b5be50d6101f207059f..d1acd390589ec9a579c023ed94f41a94e2e4929e 100755 (executable)
@@ -1,14 +1,31 @@
 #!/bin/bash
 set -e
+arches="$*"
+if [[ "$arches" == "" ]]; then
+    arches="x86_64 aarch64 ppc64le"
+fi
 
 # need to install g++ first so the local arch will get filtered out later
 which g++ > /dev/null || (set -x; sudo apt install build-essential g++)
 
 needed=()
 
-which x86_64-linux-gnu-g++ > /dev/null || needed+=(g++-x86-64-linux-gnu)
-which aarch64-linux-gnu-g++ > /dev/null || needed+=(g++-aarch64-linux-gnu)
-which powerpc64le-linux-gnu-g++ > /dev/null || needed+=(g++-powerpc64le-linux-gnu)
+for arch in $arches; do
+    case "$arch" in
+    x86_64)
+        which x86_64-linux-gnu-g++ > /dev/null || needed+=(g++-x86-64-linux-gnu)
+        ;;
+    aarch64)
+        which aarch64-linux-gnu-g++ > /dev/null || needed+=(g++-aarch64-linux-gnu)
+        ;;
+    ppc64le)
+        which powerpc64le-linux-gnu-g++ > /dev/null || needed+=(g++-powerpc64le-linux-gnu)
+        ;;
+    *)
+        echo "unknown arch: $arch" >&2
+        exit 1
+    esac
+done
 which clang++-11 > /dev/null || needed+=(clang-11)
 which make > /dev/null || needed+=(make)
 which cmake > /dev/null || needed+=(cmake)