#!/bin/bash -e # # Simple script to build risu for all architectures # # Copyright (c) 2017 Linaro Limited # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html # # Contributors: # Peter Maydell (Linaro) - initial implementation # Simple usage usage() { cat <<-EOF Usage: $0 [options] Options include: --static build a static binary --use-docker[=tags] use docker cross compile If specifying docker the default will be to use the any qemu:debian-FOO-cross targets available on your system. EOF exit 1 } while [[ "$1" = -* ]]; do opt="$1"; shift arg= if [[ "$opt" = *=* ]]; then arg="${opt#*=}" opt="${opt%%=*}" fi case "$opt" in --static) CONF="--static" ;; --use-docker) if [ -z "$arg" ]; then default_tags=$(docker images qemu --format "{{.Repository}}:{{.Tag}}" | grep "\(arm\|ppc64el\|m68k\|i386\).*cross$") docker_tags=$(echo $default_tags | sed 's/\n/\s/g' ) else docker_tags="$arg" fi ;; --help) usage ;; *) usage ;; esac done # # If you are developing your primary architecture directly out of the # source tree you can confuse any out-of-tree builds thanks to random # crap in your VPATH. Let's detect that and save some hair pulling. # if [ -e Makefile.in ]; then echo "Cleaning in-src-tree build" make distclean fi # Debian stretch and Ubuntu Xenial have cross compiler packages for # all of these: # gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu gcc-m68k-linux-gnu # gcc-powerpc64le-linux-gnu gcc-powerpc64-linux-gnu # If docker is enabled we just brute force the various images until we # can set the one that has a workable cross compiler. DOCKER_RUN="docker run --rm -u $(id -u) -v $(pwd):$(pwd) -w $(pwd)" program_exists() { if [[ ! -z "$docker_tags" && ! "$1" == "x86_64-linux-gnu-gcc" ]]; then use_docker_tag="" for tag in $docker_tags; do if ${DOCKER_RUN} ${tag} /bin/bash -c "command -v $1 >/dev/null"; then use_docker_tag=$tag return fi done fi command -v "$1" >/dev/null 2>&1 } # powerpc64-linux-gnu doesn't work at the moment, so not yet listed. for triplet in i386-linux-gnu i686-linux-gnu x86_64-linux-gnu \ aarch64-linux-gnu arm-linux-gnueabihf \ m68k-linux-gnu \ powerpc64le-linux-gnu powerpc64-linux-gnu ; do if ! program_exists "${triplet}-gcc"; then echo "Skipping ${triplet}: no compiler found" continue else echo "Building ${triplet} on ${use_docker_tag:-host}..." fi # Do a complete rebuild from scratch, because it's cheap enough. rm -rf build/${triplet} mkdir -p build/${triplet} CONFIGURE="cd build/${triplet} && CROSS_PREFIX="${triplet}-" ../../configure ${CONF}" MAKE="make -C build/${triplet} EXTRA_CFLAGS=-Werror" if [ -z "$use_docker_tag" ]; then /bin/bash -c "${CONFIGURE}" ${MAKE} else ${DOCKER_RUN} $use_docker_tag /bin/bash -c "${CONFIGURE}" ${DOCKER_RUN} $use_docker_tag /bin/bash -c "${MAKE}" fi done # Now run risugen for all architectures mkdir -p build/risuout set -o pipefail # detect failures in pipeline for f in *.risu; do echo "Running risugen on $f..." # The grep is a quick hack to avoid flooding the terminal with an # enormous list of patterns. Ideally we should make risugen # have a --quiet option or similar. ./risugen --numinsns 10000 $f build/risuout/$f.out | grep -v '^Generating code using patterns' done