#!/bin/sh # # nspluginwrapper configure script (C) 2005-2007 Gwenole Beauchesne # derived from qemu configure script, (C) 2003 Fabrice Bellard # PACKAGE=nspluginwrapper # set temporary file name mkdir -p tmp TMPDIR1="./tmp" TMPC="${TMPDIR1}/npw-conf-${RANDOM}-$$-${RANDOM}.c" TMPO="${TMPDIR1}/npw-conf-${RANDOM}-$$-${RANDOM}.o" TMPE="${TMPDIR1}/npw-conf-${RANDOM}-$$-${RANDOM}" TMPS="${TMPDIR1}/npw-conf-${RANDOM}-$$-${RANDOM}.S" # default parameters prefix="/usr" lib32="" lib64="" x_base_dirs="" biarch="guess" build_viewer="guess" linux_only="guess" cc="gcc -std=c99" cxx="g++" host_os=`uname -s | tr '[A-Z]' '[a-z]'` host_cpu=`uname -m` target_os="linux" target_cpu="i386" case "$host_cpu" in i386|i486|i586|i686|i86pc|BePC) host_cpu="i386" ;; ia64) host_cpu="ia64" ;; "Power Macintosh"|ppc) host_cpu="ppc" ;; ppc64) host_cpu="ppc64" ;; sparc) host_cpu="sparc" ;; sparc64) host_cpu="sparc64" ;; amd64|amd64) host_cpu="amd64" ;; *) host_cpu="unknown" ;; esac bigendian="no" # find source path # XXX: we assume an absolute path is given when launching configure, # except in './configure' case. source_path=${0%configure} source_path=${source_path%/} source_path_used="yes" if test -z "$source_path" -o "$source_path" = "." ; then source_path=`pwd` source_path_used="no" fi for opt do case "$opt" in --prefix=*) prefix=`echo $opt | cut -d '=' -f 2` ;; --pkglibdir=*) pkglibdir=`echo $opt | cut -d '=' -f 2` ;; --target-os=*) target_os=`echo $opt | cut -d '=' -f 2 | tr '[A-Z]' '[a-z]'` ;; --target-cpu=*) target_cpu=`echo $opt | cut -d '=' -f 2 | sed -e 's/^i.86$/i386/'` ;; --generic-build) linux_only="no" ;; --with-biarch) biarch="yes" ;; --without-biarch) biarch="no" ;; --with-viewer) build_viewer="yes" ;; --without-viewer) build_viewer="no" ;; --with-lib32=*) lib32=`echo $opt | cut -d '=' -f 2` ;; --with-lib64=*) lib64=`echo $opt | cut -d '=' -f 2` ;; --with-x11-prefix=*) x_base_dirs=`echo $opt | cut -d '=' -f 2` ;; --with-cc=*) cc=`echo $opt | cut -d '=' -f 2` ;; --with-cxx=*) cxx=`echo $opt | cut -d '=' -f 2` ;; esac done # check for linux only build if test "$linux_only" = "guess"; then if test "$host_os" = "linux" -a "$target_os" = "linux"; then linux_only="yes" else linux_only="no" fi fi # check for biarch build if test "$biarch" = "guess"; then case $host_cpu:$target_cpu in amd64:i386 | ppc64:ppc) biarch="yes" ;; *) biarch="no" ;; esac fi # check for viewer builds if test "$build_viewer" = "guess"; then build_viewer="no" case $host_os in linux) if test "$host_cpu" = "$target_cpu" -o "$biarch" = "yes"; then build_viewer="yes" fi ;; esac fi # check for libdir name if test -z "$lib64"; then case $host_os in linux) # test if the compiler is 64bit echo 'int i;' > $TMPC nspluginwrapper_64bit_output=no if $cc -o $TMPO -c $TMPC; then case `/usr/bin/file $TMPO` in *"ELF 64"*) nspluginwrapper_64bit_output=yes ;; esac fi rm -f $TMPC $TMPO ;; esac case $host_cpu:$nspluginwrapper_64bit_output in ppc64:yes | s390x:yes | sparc64:yes | amd64:yes) lib64="lib64" ;; *) lib64="lib" ;; esac fi if test -z "$lib32"; then lib32="lib" fi # check for installation root if test -z "$pkglibdir"; then pkglibdir="$prefix/lib/$PACKAGE" fi # check for __attribute__((visibility())) support cat > $TMPC << EOF int foo __attribute__((visibility("hidden"))) = 1; int bar __attribute__((visibility("protected"))) = 1; EOF has_visibility_attribute=no if $cc -Werror -S $TMPC -o $TMPS >/dev/null 2>&1; then if grep '\.hidden.*foo' $TMPS >/dev/null; then if grep '\.protected.*bar' $TMPS >/dev/null; then has_visibility_attribute=yes fi fi fi rm -f $TMPC $TMPS # check for .init_array/.fini_array support cat > $TMPC << EOF static int x = -1; int main(void) { return x; } int foo(void) { x = 0; } int (*fp)(void) __attribute__((section(".init_array"))) = foo; EOF has_initfini_array=no if $cc -Werror $TMPC -o $TMPE >/dev/null 2>&1; then if $TMPE; then has_initfini_array=yes fi fi rm -f $TMPC $TMPE # check for egrep program if echo a | (grep -E '(a|b)') >/dev/null 2>&1; then EGREP='grep -E' else EGREP='egrep' fi # check for __stack_chk_fail() in target GNU C library if test "$biarch" = "yes"; then glibc_header_dir="/usr/include" libc_provides_ssp=no if test -f $glibc_header_dir/features.h \ && $EGREP '^[ ]*#[ ]*define[ ]+__GNU_LIBRARY__[ ]+([1-9][0-9]|[6-9])' \ $glibc_header_dir/features.h > /dev/null; then if $EGREP '^[ ]*#[ ]*define[ ]+__GLIBC__[ ]+([1-9][0-9]|[3-9])' \ $glibc_header_dir/features.h > /dev/null; then libc_provides_ssp=yes elif $EGREP '^[ ]*#[ ]*define[ ]+__GLIBC__[ ]+2' \ $glibc_header_dir/features.h > /dev/null \ && $EGREP '^[ ]*#[ ]*define[ ]+__GLIBC_MINOR__[ ]+([1-9][0-9]|[4-9])' \ $glibc_header_dir/features.h > /dev/null; then libc_provides_ssp=yes fi fi fi # check for compiler flag check_cc_option() { echo "int i;" > $TMPC if $cc $* -c $TMPC -o $TMPO > /dev/null 2>&1; then rm -f $TMPC $TMPO return 0 fi rm -f $TMPC return 1 } # check for CFLAGS if test -z "$CFLAGS"; then CFLAGS="-O2 -g" if check_cc_option -mtune=generic $CFLAGS; then CFLAGS="$CFLAGS -mtune=generic" fi fi if test "$biarch" = "yes" -a -z "$CFLAGS_32"; then CFLAGS_32="-m32 -O2 -g" if check_cc_option -mtune=generic $CFLAGS_32; then CFLAGS_32="$CFLAGS_32 -mtune=generic" fi fi # check for pkg-config pkgconfig=`which pkg-config` if test -z "$pkgconfig"; then echo "pkg-config not found" exit 1 fi # check for Glib 2.0 compile CFLAGS if $pkgconfig --exists glib-2.0; then GLIB_CFLAGS=`$pkgconfig --cflags glib-2.0` GLIB_LDFLAGS=`$pkgconfig --libs glib-2.0` else echo "GLIB 2.0 environment not found" exit 1 fi cat > $TMPC << EOF #include int main(void) { (void) g_main_pending(); return 0; } EOF if ! $cc $CFLAGS $GLIB_CFLAGS $GLIB_LDFLAGS $TMPC -o $TMPE > /dev/null 2>&1; then echo "GLIB 2.0 environment not usable" rm -f $TMPC exit 1 fi rm -f $TMPC $TMPE # check for GTK+ 2.0 compile CFLAGS if test "$build_viewer" = "yes"; then if $pkgconfig --exists gtk+-2.0; then GTK_CFLAGS=`$pkgconfig --cflags gtk+-2.0` GTK_LDFLAGS=`$pkgconfig --libs gtk+-2.0` else echo "GTK+ 2.0 environment not found" exit 1 fi cat > $TMPC << EOF #include int main(void) { gtk_main_quit(); return 0; } EOF if ! $cc $CFLAGS $GTK_CFLAGS $GTK_LDFLAGS $TMPC -o $TMPE > /dev/null 2>&1; then echo "GTK+ 2.0 environment not usable" rm -f $TMPC exit 1 fi rm -f $TMPC $TMPE fi # check for X11 base dir if test -z "$x_base_dirs"; then x_base_dirs=" /usr /usr/X11R6 /usr/local/X11R6 $prefix " fi for dir in $x_base_dirs; do x_include_dir="$dir/include" if test -f $x_include_dir/X11/Intrinsic.h; then x_lib_dir="$dir/$lib64" if test -f $x_lib_dir/libX11.so; then x_base_dir=$dir break fi fi done if test -z "$x_base_dir"; then echo "X11 environment not found" exit 1 fi # big/little endian test cat > $TMPC << EOF #include int main(int argc, char ** argv){ volatile uint32_t i=0x01234567; return (*((uint8_t*)(&i))) == 0x67; } EOF if $cc -o $TMPE $TMPC 2>/dev/null ; then $TMPE && bigendian="yes" else echo "big/little test failed" fi rm -f $TMPO $TMPC $TMPE $TMPS # floating point endian test cat > $TMPC << EOF /* This will not work unless sizeof(double) == 8. */ extern char sizeof_double_must_be_8 [sizeof(double) == 8 ? 1 : -1]; /* This structure must have no internal padding. */ struct possibility { char prefix[8]; double candidate; char postfix[8]; }; #define C(cand) { "\nformat:", cand, ":tamrof\n" } struct possibility table [] = { C( 3.25724264705901305206e+01), /* @@IEEEFP - IEEE 754 */ C( 3.53802595280598432000e+18), /* D__float - VAX */ C( 5.32201830133125317057e-19), /* D.PDP-10 - PDP-10 - the dot is 0x13a */ C( 1.77977764695171661377e+10), /* IBMHEXFP - s/390 format, ascii */ C(-5.22995989424860458374e+10) /* IBMHEXFP - s/390 format, EBCDIC */ }; EOF if $cc -o $TMPO -c $TMPC 2>/dev/null; then od -c $TMPO | sed 's/^[0-7]*[ ]*/ / s/\*/./g s/ \\n/*/g s/ [0-9][0-9][0-9]/./g s/ \\[^ ]/./g' | tr -d ' ' | tr -s '*' ' ' | fold | sed '$a\ ' > $TMPE if grep 'format:.@IEEEF.:tamrof' $TMPE >/dev/null 2>&1; then float_format='IEEE (big-endian)' elif grep 'format:.I@@PFE.:tamrof' $TMPE >/dev/null 2>&1; then float_format='IEEE (big-endian)' elif grep 'format:.FEEEI@.:tamrof' $TMPE >/dev/null 2>&1; then float_format='IEEE (little-endian)' elif grep 'format:.EFP@@I.:tamrof' $TMPE >/dev/null 2>&1; then float_format='IEEE (little-endian)' elif grep 'format:.__floa.:tamrof' $TMPE >/dev/null 2>&1; then float_format='VAX D-float' elif grep 'format:..PDP-1.:tamrof' $TMPE >/dev/null 2>&1; then float_format='PDP-10' elif grep 'format:.BMHEXF.:tamrof' $TMPE >/dev/null 2>&1; then float_format='IBM 370 hex' else echo "unknown floating point format" exit 1 fi fbigendian= case $float_format in 'IEEE (big-endian)') if test "$bigendian" = "no"; then fbigendian=1 fi ;; 'IEEE (little-endian)') if test "$bigendian" = "yes"; then fbigendian=0 fi ;; *) echo "unsupported floating point format $float_format" exit 1 ;; esac else echo "floating point endian test failed" fi rm -f $TMPO $TMPC $TMPE # print configure help if test x"$1" = x"-h" -o x"$1" = x"--help" ; 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 " --pkglibdir=ROOT install private files in ROOT [$pkglibdir]" echo " --target-os=OS build plugin support for target OS [$target_os]" echo " --target-cpu=CPU build plugin support for target CPU [$target_cpu]" echo " --with-viewer build viewer [$build_viewer]" echo "" echo "Advanced options (experts only):" echo " --source-path=PATH path of source code [$source_path]" echo " --generic-build don't use system-specific additions" echo " --with-biarch build both 32-bit and 64-bit components at once" echo " --with-lib32=NAME use NAME as the 32-bit library dir name [$lib32]" echo " --with-lib64=NAME use NAME as the 64-bit library dir name [$lib64]" echo " --with-x11-prefix=PREFIX use PREFIX as the X11 base dir [autodetect]" echo " --with-cc=CC use C compiler CC [$cc]" echo " --with-cxx=CXX use C++ compiler CXX [$cxx]" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1 fi echo "Install prefix $prefix" echo "nspluginwrapper root dir $pkglibdir" echo "Bi-arch build $biarch" echo "Build viewer $build_viewer" echo "Build for Linux only $linux_only" echo "32-bit library dir name $lib32" echo "64-bit library dir name $lib64" echo "Source path $source_path" echo "C compiler $cc" echo "C++ compiler $cxx" echo "host OS $host_os" echo "host CPU $host_cpu" echo "host big endian $bigendian" echo "target OS $target_os" echo "target CPU $target_cpu" config_mak="config-host.mak" echo "# Automatically generated by configure - do not modify" > $config_mak config_h="config-host.h" echo "/* Automatically generated by configure - do not modify */" > $config_h echo "CC=$cc" >> $config_mak echo "CXX=$cxx" >> $config_mak echo "CFLAGS=$CFLAGS" >> $config_mak echo "GLIB_CFLAGS=$GLIB_CFLAGS" >> $config_mak echo "GLIB_LDFLAGS=$GLIB_LDFLAGS" >> $config_mak echo "GTK_CFLAGS=$GTK_CFLAGS" >> $config_mak echo "GTK_LDFLAGS=$GTK_LDFLAGS" >> $config_mak if test "$biarch" = "yes"; then echo "LDFLAGS_32=-m32" >> $config_mak echo "CFLAGS_32=$CFLAGS_32" >> $config_mak else echo 'CFLAGS_32=$(CFLAGS)' >> $config_mak fi if test "$host_os" = "linux"; then echo "OS=linux" >> $config_mak echo "#define HOST_LINUX 1" >> $config_h echo "#define HOST_OS \"linux\"" >> $config_h elif test "$host_os" = "dragonfly"; then echo "OS=dragonfly" >> $config_mak echo "#define HOST_DRAGONFLY 1" >> $config_h echo "#define HOST_OS \"dragonfly\"" >> $config_h elif test "$host_os" = "freebsd"; then echo "OS=freebsd" >> $config_mak echo "#define HOST_FREEBSD 1" >> $config_h echo "#define HOST_OS \"freebsd\"" >> $config_h elif test "$host_os" = "netbsd"; then echo "OS=netbsd" >> $config_mak echo "#define HOST_NETBSD 1" >> $config_h echo "#define HOST_OS \"netbsd\"" >> $config_h else echo "Unsupported OS" exit 1 fi if test "$host_cpu" = "i386" ; then echo "ARCH=i386" >> $config_mak echo "#define HOST_I386 1" >> $config_h echo "#define HOST_ARCH \"i386\"" >> $config_h elif test "$host_cpu" = "amd64" ; then echo "ARCH=amd64" >> $config_mak echo "#define HOST_X86_64 1" >> $config_h echo "#define HOST_ARCH \"amd64\"" >> $config_h elif test "$host_cpu" = "ppc" ; then echo "ARCH=ppc" >> $config_mak echo "#define HOST_PPC 1" >> $config_h echo "#define HOST_ARCH \"ppc\"" >> $config_h elif test "$host_cpu" = "ppc64" ; then echo "ARCH=ppc64" >> $config_mak echo "#define HOST_PPC64 1" >> $config_h echo "#define HOST_ARCH \"ppc64\"" >> $config_h elif test "$host_cpu" = "sparc" ; then echo "ARCH=sparc" >> $config_mak echo "#define HOST_SPARC 1" >> $config_h echo "#define HOST_ARCH \"sparc\"" >> $config_h elif test "$host_cpu" = "sparc64" ; then echo "ARCH=sparc64" >> $config_mak echo "#define HOST_SPARC64 1" >> $config_h echo "#define HOST_ARCH \"sparc64\"" >> $config_h elif test "$host_cpu" = "ia64" ; then echo "ARCH=ia64" >> $config_mak echo "#define HOST_IA64 1" >> $config_h echo "#define HOST_ARCH \"ia64\"" >> $config_h else echo "Unsupported CPU" exit 1 fi if test "$bigendian" = "yes" ; then echo "WORDS_BIGENDIAN=yes" >> $config_mak echo "#define WORDS_BIGENDIAN 1" >> $config_h fi if test -n "$fbigendian" ; then echo "#define FLOAT_WORDS_BIGENDIAN $fbigendian" >> $config_h fi echo "SRC_PATH=$source_path" >> $config_mak echo "build_viewer=$build_viewer" >> $config_mak echo "biarch=$biarch" >> $config_mak echo "lib32=$lib32" >> $config_mak echo "lib64=$lib64" >> $config_mak echo "prefix=$prefix" >> $config_mak echo "bindir=$prefix/bin" >> $config_mak libdir="$prefix/$lib64" echo "libdir=$libdir" >> $config_mak echo "#define LIB \"$lib64\"" >> $config_h echo "#define LIBDIR \"$libdir\"" >> $config_h echo "x11prefix=$x_base_dir" >> $config_mak VERSION=`sed < $source_path/$PACKAGE.spec -n '/^\%define version[ ]*/s///p'` RELEASE=`sed < $source_path/$PACKAGE.spec -n '/^\%define release[ ]*/s///p'` SVNDATE=`sed < $source_path/$PACKAGE.spec -n '/^\%define svndate[ ]*/s///p'` if test -z "$SVNDATE"; then SVNDATE=`date '+%Y%m%d'` fi SNAPSHOT=0 if echo "$RELEASE" | grep -q ^0; then SNAPSHOT=1 fi echo "VERSION=$VERSION" >> $config_mak echo "SVNDATE=$SVNDATE" >> $config_mak echo "SNAPSHOT=$SNAPSHOT" >> $config_mak echo "#define NPW_SNAPSHOT $SNAPSHOT" >> $config_h if test "$SNAPSHOT" = "1"; then echo "#define NPW_VERSION \"$VERSION-Pre ($SVNDATE)\"" >> $config_h else echo "#define NPW_VERSION \"$VERSION\"" >> $config_h fi echo "pkglibdir=$pkglibdir" >> $config_mak echo "#define NPW_LIBDIR \"$pkglibdir\"" >> $config_h if test "$has_visibility_attribute" = "yes"; then echo "#define attribute_hidden __attribute__((visibility(\"hidden\")))" >> $config_h echo "#define attribute_protected __attribute__((visibility(\"protected\")))" >> $config_h else echo "#define attribute_hidden" >> $config_h echo "#define attribute_protected" >> $config_h fi if test "$has_initfini_array" = "yes"; then echo "#define HAVE_INITFINI_ARRAY 1" >> $config_h else echo "#undef HAVE_INITFINI_ARRAY" >> $config_h fi if test "$libc_provides_ssp" = "yes"; then echo "#define TARGET_LIBC_PROVIDES_SSP 1" >> $config_h else echo "#undef TARGET_LIBC_PROVIDES_SSP" >> $config_h fi config_mak="config.mak" echo "# Automatically generated by configure - do not modify" > $config_mak echo "include config-host.mak" >> $config_mak config_h="config.h" echo "/* Automatically generated by configure - do not modify */" > $config_h echo "#include \"config-host.h\"" >> $config_h if test "$linux_only" = "yes"; then echo "#define BUILD_LINUX_ONLY 1" >> $config_h fi if test "$target_os" = "linux"; then echo "TARGET_OS=linux" >> $config_mak echo "#define TARGET_OS \"linux\"" >> $config_h echo "#define TARGET_LINUX 1" >> $config_h elif test "$target_os" = "solaris"; then echo "TARGET_OS=solaris" >> $config_mak echo "#define TARGET_OS \"solaris\"" >> $config_h echo "#define TARGET_SOLARIS 1" >> $config_h else echo "Unsupported target OS" exit 1 fi if test "$target_cpu" = "i386" ; then echo "TARGET_ARCH=i386" >> $config_mak echo "#define TARGET_ARCH \"i386\"" >> $config_h echo "#define TARGET_I386 1" >> $config_h elif test "$target_cpu" = "amd64" ; then echo "TARGET_ARCH=amd64" >> $config_mak echo "#define TARGET_ARCH \"amd64\"" >> $config_h echo "#define TARGET_X86_64 1" >> $config_h elif test "$target_cpu" = "ppc" ; then echo "TARGET_ARCH=ppc" >> $config_mak echo "#define TARGET_ARCH \"ppc\"" >> $config_h echo "#define TARGET_PPC 1" >> $config_h else echo "Unsupported target CPU" exit 1 fi # build tree in object directory if source path is different from current one if test "$source_path_used" = "yes" ; then case $source_path in ..*) sp1=.. ;; esac ln -sf $source_path/Makefile Makefile fi