#!/bin/sh # # qemu configure script (c) 2003 Fabrice Bellard # # set temporary file name if test ! -z "$TMPDIR" ; then TMPDIR1="${TMPDIR}" elif test ! -z "$TEMPDIR" ; then TMPDIR1="${TEMPDIR}" else TMPDIR1="/tmp" fi TMPC="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.c" TMPO="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.o" TMPE="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}" TMPS="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.S" # default parameters prefix="" static="no" libdir="lib" cross_prefix="" cc="gcc" gcc3_search="yes" gcc3_list="gcc-3.4 gcc34 gcc-3.3 gcc33 gcc-3.2 gcc32" host_cc="gcc" ar="ar" make="make" install="install" strip="strip" target_list="" case "$XEN_TARGET_ARCH" in x86_32) cpu="i386" ;; powerpc) cpu="powerpc" ;; ia64) cpu="ia64" ;; x86_64) cpu="x86_64" [ `uname -s` = "Linux" ] && libdir="lib64" ;; *) cpu="unknown" ;; esac gprof="no" bigendian="no" mingw32="no" EXESUF="" gdbstub="no" slirp="no" adlib="no" oss="no" dsound="no" coreaudio="no" alsa="no" fmod="no" fmod_lib="" fmod_inc="" vnc_tls="yes" bsd="no" linux="no" kqemu="no" profiler="no" cocoa="no" check_gfx="yes" check_gcc="no" softmmu="yes" linux_user="no" darwin_user="no" build_docs="no" stubdom="no" uname_release="" # OS specific targetos=`uname -s` case $targetos in CYGWIN*) mingw32="yes" OS_CFLAGS="-mno-cygwin" ;; MINGW32*) mingw32="yes" ;; FreeBSD) bsd="yes" oss="yes" if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then kqemu="yes" fi ;; NetBSD) bsd="yes" oss="yes" ;; OpenBSD) bsd="yes" oss="yes" ;; Darwin) bsd="yes" darwin="yes" darwin_user="yes" cocoa="yes" coreaudio="yes" OS_CFLAGS="-mdynamic-no-pic" ;; SunOS) solaris="yes" ;; *) oss="yes" linux="yes" linux_user="yes" if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then kqemu="yes" fi ;; esac if [ "$bsd" = "yes" ] ; then if [ "$darwin" != "yes" ] ; then make="gmake" fi fi if [ "$solaris" = "yes" ] ; then make="gmake" install="ginstall" solarisrev=`uname -r | cut -f2 -d.` if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then if test "$solarisrev" -gt 10 ; then kqemu="yes" fi fi fi # find source path source_path=`dirname "$0"` if [ -z "$source_path" ]; then source_path=`pwd` else source_path=`cd "$source_path"; pwd` fi if test "$source_path" = `pwd` ; then source_path_used="no" else source_path_used="yes" fi for opt do optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` case "$opt" in --help|-h) show_help=yes ;; --prefix=*) prefix="$optarg" ;; --interp-prefix=*) interp_prefix="$optarg" ;; --source-path=*) source_path="$optarg" source_path_used="yes" ;; --cross-prefix=*) cross_prefix="$optarg" ;; --cc=*) cc="$optarg" gcc3_search="no" ;; --host-cc=*) host_cc="$optarg" ;; --make=*) make="$optarg" ;; --install=*) install="$optarg" ;; --extra-cflags=*) CFLAGS="$optarg" ;; --extra-ldflags=*) LDFLAGS="$optarg" ;; --cpu=*) cpu="$optarg" ;; --target-list=*) target_list="$optarg" ;; --enable-gprof) gprof="yes" ;; --static) static="yes" ;; --disable-sdl) sdl="no" ;; --disable-opengl) opengl="no" ;; --enable-coreaudio) coreaudio="yes" ;; --enable-alsa) alsa="yes" ;; --enable-dsound) dsound="yes" ;; --enable-fmod) fmod="yes" ;; --fmod-lib=*) fmod_lib="$optarg" ;; --fmod-inc=*) fmod_inc="$optarg" ;; --disable-vnc-tls) vnc_tls="no" ;; --enable-mingw32) mingw32="yes" ; cross_prefix="i386-mingw32-" ; user="no" ;; --disable-slirp) slirp="no" ;; --enable-adlib) adlib="yes" ;; --disable-kqemu) kqemu="no" ;; --enable-profiler) profiler="yes" ;; --enable-cocoa) cocoa="yes" ; coreaudio="yes" ; sdl="no" ;; --disable-gcc-check) check_gcc="no" ;; --disable-system) softmmu="no" ;; --enable-system) softmmu="yes" ;; --disable-linux-user) linux_user="no" ;; --enable-linux-user) linux_user="yes" ;; --disable-darwin-user) darwin_user="no" ;; --enable-darwin-user) darwin_user="yes" ;; --enable-uname-release=*) uname_release="$optarg" ;; --enable-stubdom) stubdom="yes" ;; esac done # default flags for all hosts CFLAGS="$CFLAGS -Wall -O2 -g -fno-strict-aliasing" LDFLAGS="$LDFLAGS -g" if test x"$show_help" = x"yes" ; then cat << EOF Usage: configure [options] Options: [defaults in brackets after descriptions] EOF echo "Standard options:" echo " --help print this message" echo " --prefix=PREFIX install in PREFIX [$prefix]" echo " --interp-prefix=PREFIX where to find shared libraries, etc." echo " use %M for cpu name [$interp_prefix]" echo " --target-list=LIST set target list [$target_list]" echo "" echo "kqemu kernel acceleration support:" echo " --disable-kqemu disable kqemu support" echo "" echo "Advanced options (experts only):" echo " --source-path=PATH path of source code [$source_path]" echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]" echo " --cc=CC use C compiler CC [$cc]" echo " --host-cc=CC use C compiler CC [$host_cc] for dyngen etc." echo " --make=MAKE use specified make [$make]" echo " --install=INSTALL use specified install [$install]" echo " --static enable static build [$static]" echo " --enable-cocoa enable COCOA (Mac OS X only)" echo " --enable-mingw32 enable Win32 cross compilation with mingw32" echo " --enable-adlib enable Adlib emulation" echo " --enable-coreaudio enable Coreaudio audio driver" echo " --enable-alsa enable ALSA audio driver" echo " --enable-fmod enable FMOD audio driver" echo " --enabled-dsound enable DirectSound audio driver" echo " --disable-vnc-tls disable TLS encryption for VNC server" echo " --enable-system enable all system emulation targets" echo " --disable-system disable all system emulation targets" echo " --enable-linux-user enable all linux usermode emulation targets" echo " --disable-linux-user disable all linux usermode emulation targets" echo " --enable-darwin-user enable all darwin usermode emulation targets" echo " --disable-darwin-user disable all darwin usermode emulation targets" echo " --fmod-lib path to FMOD library" echo " --fmod-inc path to FMOD includes" echo " --enable-uname-release=R Return R for uname -r in usermode emulation" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1 fi cc="${cross_prefix}${cc}" ar="${cross_prefix}${ar}" strip="${cross_prefix}${strip}" # check that the C compiler works. cat > $TMPC </dev/null ; then : C compiler works ok else echo "ERROR: \"$cc\" either does not exist or does not work" exit 1 fi if test "$mingw32" = "yes" ; then linux="no" EXESUF=".exe" oss="no" if [ "$cpu" = "i386" ] ; then kqemu="yes" fi fi # Check for gcc4, error if pre-gcc4 if test "$check_gcc" = "yes" ; then cat > $TMPC <&/dev/null return $? } if "$cc" -o $TMPE $TMPC 2>/dev/null ; then echo "WARNING: \"$cc\" looks like gcc 4.x" found_compat_cc="no" if test "$gcc3_search" = "yes" ; then echo "Looking for gcc 3.x" for compat_cc in $gcc3_list ; do if check_cc "$compat_cc" ; then echo "Found \"$compat_cc\"" cc="$compat_cc" found_compat_cc="yes" break fi done if test "$found_compat_cc" = "no" ; then echo "gcc 3.x not found!" fi fi if test "$found_compat_cc" = "no" ; then echo "QEMU is known to have problems when compiled with gcc 4.x" echo "It is recommended that you use gcc 3.x to build QEMU" echo "To use this compiler anyway, configure with --disable-gcc-check" exit 1; fi fi fi # # Solaris specific configure tool chain decisions # if test "$solaris" = "yes" ; then # # gcc for solaris 10/fcs in /usr/sfw/bin doesn't compile qemu correctly # override the check with --disable-gcc-check # if test "$solarisrev" -eq 10 -a "$check_gcc" = "yes" ; then solgcc=`which $cc` if test "$solgcc" = "/usr/sfw/bin/gcc" ; then echo "Solaris 10/FCS gcc in /usr/sfw/bin will not compiled qemu correctly." echo "please get gcc-3.4.3 or later, from www.blastwave.org using pkg-get -i gcc3" echo "or get the latest patch from SunSolve for gcc" exit 1 fi fi solinst=`which $install 2> /dev/null | /usr/bin/grep -v "no $install in"` if test -z "$solinst" ; then echo "Solaris install program not found. Use --install=/usr/ucb/install or" echo "install fileutils from www.blastwave.org using pkg-get -i fileutils" echo "to get ginstall which is used by default (which lives in /opt/csw/bin)" exit 1 fi if test "$solinst" = "/usr/sbin/install" ; then echo "Error: Solaris /usr/sbin/install is not an appropriate install program." echo "try ginstall from the GNU fileutils available from www.blastwave.org" echo "using pkg-get -i fileutils, or use --install=/usr/ucb/install" exit 1 fi sol_ar=`which ar 2> /dev/null | /usr/bin/grep -v "no ar in"` if test -z "$sol_ar" ; then echo "Error: No path includes ar" if test -f /usr/ccs/bin/ar ; then echo "Add /usr/ccs/bin to your path and rerun configure" fi exit 1 fi fi ########################################## # VNC TLS detection if test "$vnc_tls" = "yes" ; then `pkg-config gnutls` || vnc_tls="no" fi if test "$vnc_tls" = "yes" ; then vnc_tls_cflags=`pkg-config --cflags gnutls` vnc_tls_libs=`pkg-config --libs gnutls` fi ########################################## if test -z "$target_list" ; then # these targets are portable if [ "$softmmu" = "yes
#!/usr/bin/env bash
#
#   Script to install host system binaries along with required libraries.
#
#   Copyright (C) 2012-2017 Jo-Philipp Wich <jo@mein.io>
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

DIR="$1"; shift

_cp() {
	cp ${VERBOSE:+-v} -L "$1" "$2" || {
		echo "cp($1 $2) failed" >&2
		exit 1
	}
}

_mv() {
	mv ${VERBOSE:+-v} "$1" "$2" || {
		echo "mv($1 $2) failed" >&2
		exit 1
	}
}

_md() {
	mkdir ${VERBOSE:+-v} -p "$1" || {
		echo "mkdir($1) failed" >&2
		exit 2
	}
}

_ln() {
	ln ${VERBOSE:+-v} -sf "$1" "$2" || {
		echo "ln($1 $2) failed" >&2
		exit 3
	}
}

_relpath() {
	local base="$(readlink -f "$1")"
	local dest="$(readlink -f "$2")"
	local up

	[ -d "$base" ] || base="${base%/*}"
	[ -d "$dest" ] || dest="${dest%/*}"

	while true; do
		case "$base"
			in "$dest"/*)
				echo "$up/${base#$dest/}"
				break
			;;
			*)
				dest="${dest%/*}"
				up="${up:+$up/}.."
			;;
		esac
	done
}

_runas_so() {
	cat <<-EOT | ${CC:-gcc} -x c -fPIC -shared -o "$1" -
		#include <unistd.h>
		#include <stdio.h>
		#include <stdlib.h>

		int mangle_arg0(int argc, char **argv, char **env) {
			char *arg0 = getenv("RUNAS_ARG0");

			if (arg0) {
				argv[0] = arg0;
				unsetenv("RUNAS_ARG0");
			}

			return 0;
		}

		#ifdef __APPLE__
		__attribute__((section("__DATA,__mod_init_func")))
		#else
		__attribute__((section(".init_array")))
		#endif
		static void *mangle_arg0_constructor = &mangle_arg0;
	EOT

	[ -x "$1" ] || {
		echo "compiling preload library failed" >&2
		exit 5
	}
}

_patch_ldso() {
	_cp "$1" "$1.patched"
	sed -i -e 's,/\(usr\|lib\|etc\)/,/###/,g' "$1.patched"

	if "$1.patched" 2>&1 | grep -q -- --library-path; then
		_mv "$1.patched" "$1"
	else
		echo "binary patched ${1##*/} not executable, using original" >&2
		rm -f "$1.patched"
	fi
}

_patch_glibc() {
	_cp "$1" "$1.patched"
	sed -i -e 's,/usr/\(\(lib\|share\)/locale\),/###/\1,g' "$1.patched"

	if "$1.patched" 2>&1 | grep -q -- GNU; then
		_mv "$1.patched" "$1"
	else
		echo "binary patched ${1##*/} not executable, using original" >&2
		rm -f "$1.patched"
	fi
}

for LDD in ${PATH//://ldd }/ldd; do
	"$LDD" --version >/dev/null 2>/dev/null && break
	LDD=""
done

[ -n "$LDD" -a -x "$LDD" ] || LDD=

for BIN in "$@"; do
	[ -n "$BIN" -a -n "$DIR" ] || {
		echo "Usage: $0 <destdir> <executable> ..." >&2
		exit 1
	}

	[ ! -d "$DIR/lib" ] && {
		_md "$DIR/lib"
		_md "$DIR/usr"
		_ln "../lib" "$DIR/usr/lib"
	}

	[ ! -x "$DIR/lib/runas.so" ] && {
		_runas_so "$DIR/lib/runas.so"
	}

	LDSO=""

	[ -n "$LDD" ] && [ -x "$BIN" ] && file "$BIN" | grep -sqE "ELF.*(executable|interpreter)" && {
		for token in $("$LDD" "$BIN" 2>/dev/null); do
			case "$token" in */*.so*)
				dest="$DIR/lib/${token##*/}"
				ddir="${dest%/*}"

				case "$token" in
					*/ld-*.so*) LDSO="${token##*/}" ;;
				esac

				[ -f "$token" -a ! -f "$dest" ] && {
					_md "$ddir"
					_cp "$token" "$dest"
					case "$token" in
						*/ld-*.so*) _patch_ldso "$dest" ;;
						*/libc.so.6) _patch_glibc "$dest" ;;
					esac
				}
			;; esac
		done
	}

	# is a dynamically linked executable
	if [ -n "$LDSO" ]; then
		echo "Bundling ${BIN##*/}"

		RUNDIR="$(readlink -f "$BIN")"; RUNDIR="${RUNDIR%/*}"
		RUN="${LDSO#ld-}"; RUN="run-${RUN%%.so*}.sh"
		REL="$(_relpath "$DIR/lib" "$BIN")"

		_mv "$BIN" "$RUNDIR/.${BIN##*/}.bin"

		cat <<-EOF > "$BIN"
			#!/usr/bin/env bash
			dir="\$(dirname "\$0")"
			export RUNAS_ARG0="\$0"
			export LD_PRELOAD="\$dir/${REL:+$REL/}runas.so"
			exec "\$dir/${REL:+$REL/}$LDSO" --library-path "\$dir/${REL:+$REL/}" "\$dir/.${BIN##*/}.bin" "\$@"
		EOF

		chmod ${VERBOSE:+-v} 0755 "$BIN"
	fi
done