#!/bin/bash set -e bind_cpu="1" build="" cc_flags="" cc_prefix="" config="default" helper_cpu="$(($bind_cpu-1))" mcpu="" mfpu="" # Use explicit path to perf to have a record of the version perf_bin="/usr/lib/linux-tools/$(uname -r)/perf" perf_buildid_dir="global" perf_events="" profiler="none" save_temps=false sysinfo_program="default" toolchain="gnu" OPTS="`getopt -o ve: -l bind:,ccflags:,ccprefix:,config:,event:,helpercpu:,mcpu:,mfpu:,perf-bin:,perf-buildid-dir:,profiler:,save-temps,sysinfo:,toolchain: -- "$@"`" while test $# -gt 1; do case $1 in --bind) bind_cpu="$2"; shift ;; --ccflags) cc_flags="$2"; shift ;; --ccprefix) cc_prefix="$2"; shift ;; --config) config="$2"; shift ;; -e|--event) perf_events="$perf_events -e $2"; shift ;; --helpercpu) helper_cpu="$2"; shift ;; --mcpu) mcpu="$2"; shift ;; --mfpu) mfpu="$2"; shift ;; --perf-bin) perf_bin="$2"; shift ;; --perf-buildid-dir) perf_buildid_dir="$2"; shift ;; --profiler) profiler="$2"; shift ;; --save-temps) save_temps=true ;; --sysinfo) sysinfo_program="$2"; shift ;; --toolchain) toolchain="$2"; shift ;; -v) set -x ;; esac shift done spec=$(cd $1; pwd) shift if ! [ -d "$spec" ]; then echo "ERROR: SPEC directory does not exist: $spec" exit 1 fi if [ $# -gt 0 ]; then echo "ERROR: Extra arguments: $@" exit 1 fi declare -A tools case "$toolchain" in "gnu") tools[cc]="gcc" tools[cxx]="g++" tools[fortran]="gfortran" ;; "llvm") tools[cc]="clang" tools[cxx]="clang++" tools[fortran]="nofortran" ;; *) echo "ERROR: unknown toolchain: $toolchain" exit 1 ;; esac # If ${cc_prefix} has ':', it means in contains at least a host # specification. In that case, keep the last part in ${cc_prefix}, the # rest goes to ${build} for later parsing. case ${cc_prefix} in *:*) build=${cc_prefix%:*} cc_prefix=${cc_prefix##*:} ;; *) ;; esac if [ x"$build" != x"" ]; then # [:][:][:] build_host="$(echo $build | cut -d: -f 1)" build_port="$(echo $build | cut -s -d: -f 2)" parallelize="$(echo $build | cut -s -d: -f 3)" build_type="$(echo $build | cut -s -d: -f 4)" if [ x"$build_host" = x"" ]; then echo "ERROR: wrong --build: $build" exit 1 fi if [ x"$build_port" != x"" ]; then build_port="-p$build_port"; fi if [ x"$parallelize" = x"" ]; then parallelize="$(ssh $build_port $build_host getconf _NPROCESSORS_ONLN)" parallelize="$(($parallelize * 2))" fi if [ x"$build_type" = x"" ]; then build_type="rsync"; fi if [ x"$build_type" = x"rsync" ]; then lock=$spec/bin/ssh-$config.lock count=$spec/bin/ssh-$config.lockcnt rm -f $lock $count for cc in ${tools[cc]} ${tools[cxx]} ${tools[fortran]}; do cat "$(dirname $0)/ssh-cc.sh" | sed \ -e "s#@lock@#$lock#g" \ -e "s#@count@#$count#g" \ -e "s#@build_host@#$build_host#g" \ -e "s#@build_port@#$build_port#g" \ -e "s#@cc_prefix@#$cc_prefix#g" \ -e "s#@cc@#$cc#g" \ -e "s#@spec@#$spec#g" \ > $spec/bin/ssh-$config-$cc chmod +x $spec/bin/ssh-$config-$cc done cat > $spec/bin/ssh-$config-tar < $spec/bin/ssh-$config-$cc < $spec/bin/ssh-$config-tar < $spec/config/$config.tmp if ! diff -u $spec/config/$config.tmp $spec/config/$config.cfg 2>&1 | head -n 8 | grep -q __MD5__; then mv $spec/config/$config.tmp $spec/config/$config.cfg else rm $spec/config/$config.tmp fi