#!/bin/sh # # functions This file contains functions to be used by all # shell scripts of the mplayerxp # Prefer these macros to full length text ! # These macros only return an error code - NO display is done cc_check() { echo >> "$TMPLOG" cat "$TMPC" >> "$TMPLOG" echo >> "$TMPLOG" echo "$_cc $_inc_extra $_ld_static $_ld_extra $TMPC -o $TMPO $@" >> "$TMPLOG" > "$TMPO" ( "$_cc" $_inc_extra $_ld_static $_ld_extra "$TMPC" -o "$TMPO" "$@" ) >> "$TMPLOG" 2>&1 TMP="$?" echo >> "$TMPLOG" echo "ldd $TMPO" >> "$TMPLOG" ( ldd "$TMPO" ) >> "$TMPLOG" 2>&1 echo >> "$TMPLOG" return "$TMP" } # Display error message, flushes tempfile, exit die() { echo echo "Error: $@" >&2 echo >&2 rm -f "$TMPO" "$TMPC" "$TMPS" "$TMPCPP" echo "Check "$TMPLOG" if you do not understand why it failed." exit 1 } # OS test booleans functions issystem() { test "`echo $_build_os | tr A-Z a-z`" = "`echo $1 | tr A-Z a-z`" } linux() { issystem "Linux" ; return "$?" ; } sunos() { issystem "SunOS" ; return "$?" ; } hpux() { issystem "HP-UX" ; return "$?" ; } irix() { issystem "IRIX" ; return "$?" ; } aix() { issystem "AIX" ; return "$?" ; } cygwin() { issystem "CYGWIN" ; return "$?" ; } mingw32() { issystem "MINGW32" ; return "$?" ; } win32() { cygwin || mingw32 ; return "$?" ; } freebsd() { issystem "FreeBSD" ; return "$?" ; } netbsd() { issystem "NetBSD" ; return "$?" ; } bsdos() { issystem "BSD/OS" ; return "$?" ; } openbsd() { issystem "OpenBSD" ; return "$?" ; } bsd() { freebsd || netbsd || bsdos || openbsd ; return "$?" ; } qnx() { issystem "QNX" ; return "$?" ; } darwin() { issystem "Darwin" ; return "$?" ; } gnu() { issystem "GNU" ; return "$?" ; } morphos() { issystem "MorphOS" ; return "$?" ; } beos() { issystem "BEOS" ; return "$?" ; } # arch test boolean functions x86() { case "$_build_arch" in i*86|x86|x86pc) return 0 ;; *) return 1 ;; esac } x86_64() { case "$_build_arch" in x86_64) return 0 ;; *) return 1 ;; esac } ppc() { case "$host_arch" in ppc) return 0;; *) return 1;; esac } alpha() { case "$_build_arch" in alpha) return 0 ;; *) return 1 ;; esac } # not boolean test: implement the posix shell "!" operator for a # non-posix /bin/sh. # usage: not {command} # returns exit status "success" when the execution of "command" # fails. not() { eval "$@" test $? -ne 0 } # Use this before starting a check echocheck() { echo "============ Checking for $@ ============" >> "$TMPLOG" echo ${_echo_n} "Checking for $@ ... ${_echo_c}" } # Use this to echo the results of a check echores() { echo "Result is: $@" >> "$TMPLOG" echo "##########################################" >> "$TMPLOG" echo "" >> "$TMPLOG" echo "$@" } ############################################################################# # Check how echo works in this /bin/sh case `echo -n` in -n) _echo_n= _echo_c='\c' ;; # SysV echo *) _echo_n='-n ' _echo_c= ;; # BSD echo esac # Guessing target system guess_target() { echocheck "build system type" local config_mak=$1 local config_h=$2 config_guess="../config.guess" config_sub="../config.sub" if test -z "$_target" ; then _target=`$config_guess` test -z "$_target" && echores "cannot guess build type; you must specify one" fi # Canonize it $config_sub sun4 >/dev/null 2>&1 || echores "cannot run $_config_sub" _target=`$config_sub $_target` echores "$_target" _build_cpu=`echo $_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` _build_vendor=`echo $_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` _build_os=`echo $_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` # Printout architecture case "$_build_cpu" in i*86) _build_arch="x86" _icpu=`echo $_build_cpu | sed -n 's/^i\([0-9]*\)$/\1/p'` ;; *) _build_arch=$_build_cpu _icpu=$_build_cpu ;; esac case "$_build_arch" in x86|x86_64|arm|alpha) _def_words_endian="#undef WORDS_BIGENDIAN" ;; *) _def_words_endian='#define WORDS_BIGENDIAN 1' ;; esac _lc_build_arch=`echo $_build_arch | tr [:lower:] [:upper:]` _lc_build_os=`echo $_build_os | tr [:lower:] [:upper:]` _lc_build_sys=$_lc_build_os if win32 ; then _lc_build_os=WIN32 fi if win32 ; then _slibsuf=".dll" else _slibsuf=".so" fi cat > $config_mak << EOF # -------- Generated by guess_target() ----------- TARGET_OS = $_lc_build_os TARGET_SYS = $_lc_build_sys TARGET_ARCH_$_lc_build_arch = yes TARGET_CPU = $_icpu SLIBSUF = $_slibsuf EOF cat > $config_h << EOF /* -------- Generated by guess_target() ----------- */ #ifndef MPXP_CONFIG_ARCH #define MPXP_CONFIG_ARCH 1 #define ARCH_$_lc_build_arch 1 #define __CPU__ $_icpu /* Define if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ $_def_words_endian #define TARGET_$_lc_build_os 1 #define SLIBSUFFIX "$_slibsuf" EOF case "$_lc_build_arch" in X86) echo "#define ARCH_X86_32 1" >> $config_h ;; *) ;; esac } test_optimizations() { local config_mak=$1 local config_h=$2 if (x86||x86_64) ; then extcheck() { echocheck "as support of $1" cat > $TMPC < /dev/null 2>&1 ; then echores "yes" return 0 else echores "failed" echo "It seems that your as does not correctly support $1." echo "To use $1 extensions in MPlayerXP, you need to upgrade your binutils!" return 1 fi return 1 } clobber_check() { echocheck "gcc support of $1" cat > $TMPC < /dev/null 2>&1 ; then echores "yes" return 0 else echores "failed" echo "To use $3 instructions with aggressive optimization you need to upgrade your gcc!" return 1 fi return 1 } _def_mmx='#define CAN_COMPILE_MMX 1' _def_mmx2='#define CAN_COMPILE_MMX2 1' _def_3dnow='#define CAN_COMPILE_3DNOW 1' _def_3dnow2='#define CAN_COMPILE_3DNOW2 1' _def_sse='#define CAN_COMPILE_SSE 1' _def_sse2='#define CAN_COMPILE_SSE2 1' # _def_sse3='#define CAN_COMPILE_SSE3 1' --currently is not used _def_sse3='#undef CAN_COMPILE_SSE3' extcheck "mmx" "emms" || _def_mmx='#undef CAN_COMPILE_MMX' extcheck "mmx2" "sfence" || _def_mmx2='#undef CAN_COMPILE_MMX2' extcheck "3dnow" "femms" || _def_3dnow='#undef CAN_COMPILE_3DNOW' extcheck "3dnow2" "pswapd %%mm0, %%mm0" || _def_3dnow2='#undef CAN_COMPILE_3DNOW2' extcheck "sse" "xorps %%xmm0, %%xmm0" || _def_sse='#undef CAN_COMPILE_SSE' extcheck "sse2" "xorpd %%xmm0, %%xmm0" || _def_sse2='#undef CAN_COMPILE_SSE2' # extcheck "sse3" "haddps %%xmm0, %%xmm0" || _def_sse3='#undef CAN_COMPILE_SSE3' _fpu_clob='#undef FPU_CLOBBERED' _mmx_clob='#undef MMX_CLOBBERED' _sse_clob='#undef SSE_CLOBBERED' clobber_check "FPU_CLOBBERED" '"st","st(1)","st(2)","st(3)","st(4)","st(5)","st(6)","st(7)"' "FPU" && _fpu_clob='#define FPU_CLOBBERED "st","st(1)","st(2)","st(3)","st(4)","st(5)","st(6)","st(7)"' clobber_check "MMX_CLOBBERED" '"mm0","mm1","mm2","mm3","mm4","mm5","mm6","mm7"' "MMX" && _mmx_clob='#define MMX_CLOBBERED "mm0","mm1","mm2","mm3","mm4","mm5","mm6","mm7"' clobber_check "SSE_CLOBBERED" '"xmm0","xmm1","xmm2","xmm3","xmm4","xmm5","xmm6","xmm7"' "SSE" && _sse_clob='#define SSE_CLOBBERED "xmm0","xmm1","xmm2","xmm3","xmm4","xmm5","xmm6","xmm7"' cat >> $config_h << EOF /* Extension defines */ $_def_mmx $_def_mmx2 $_def_3dnow $_def_3dnow2 $_def_sse $_def_sse2 $_def_sse3 $_fpu_clob $_mmx_clob $_sse_clob EOF cat >> $config_mak << EOF # ------------- Need for FFMpeg (like i386) ------------- TARGET_MMX=yes EOF fi if (alpha); then echocheck "CPU type" cat > $TMPC << EOF int main() { unsigned long ver, mask; asm ("implver %0" : "=r" (ver)); asm ("amask %1, %0" : "=r" (mask) : "r" (-1)); printf("%ld-%x\n", ver, ~mask); return 0; } EOF _def_mvi='#undef HAVE_MVI' $_cc -o "$TMPO" "$TMPC" _lc_ver_mask=`$TMPO` case "$_lc_ver_mask" in 0-0) proc="ev4" ;; 1-0) proc="ev5" ;; 1-1) proc="ev56" ;; 1-101) proc="pca56"; _def_mvi='#define HAVE_MVI 1' ;; 2-303) proc="ev6"; _def_mvi='#define HAVE_MVI 1' ;; 2-307) proc="ev67"; _def_mvi='#define HAVE_MVI 1' ;; 2-1307) proc="ev68"; _def_mvi='#define HAVE_MVI 1' ;; esac echores "$proc" cat >> $config_h << EOF $_def_mvi EOF fi cat >> $config_h << EOF #endif /* MPXP_CONFIG_ARCH */ EOF }