changeset 1309:598e3047ce13

Add some preliminary support for non-x86 architectures to mplayer
author jkeil
date Thu, 12 Jul 2001 15:35:52 +0000
parents ffd63a75700c
children db4cfb480538
files Makefile aviheader.c bswap.h configure dec_audio.c dec_video.c demuxer.h dll_init.c libvo/Makefile mp3lib/sr1.c
diffstat 10 files changed, 525 insertions(+), 213 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Jul 12 15:30:15 2001 +0000
+++ b/Makefile	Thu Jul 12 15:35:52 2001 +0000
@@ -16,12 +16,21 @@
 #prefix = /usr/local
 BINDIR = ${prefix}/bin
 # BINDIR = /usr/local/bin
-SRCS = find_sub.c aviprint.c dll_init.c dec_audio.c dec_video.c aviwrite.c aviheader.c asfheader.c demux_avi.c demux_asf.c demux_mpg.c demuxer.c stream.c codec-cfg.c subreader.c linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c cfgparser.c mixer.c dvdauth.c spudec.c $(STREAM_SRCS)
+SRCS = find_sub.c aviprint.c dec_audio.c dec_video.c aviwrite.c aviheader.c asfheader.c demux_avi.c demux_asf.c demux_mpg.c demuxer.c stream.c codec-cfg.c subreader.c linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c cfgparser.c mixer.c dvdauth.c spudec.c $(STREAM_SRCS)
 OBJS = $(SRCS:.c=.o)
 CFLAGS = $(OPTFLAGS) -Iloader -Ilibvo $(CSS_INC) $(EXTRA_INC) # -Wall
 A_LIBS = -Lmp3lib -lMP3 -Llibac3 -lac3 $(ALSA_LIB) $(ESD_LIB)
 VO_LIBS = -Llibvo -lvo $(X_LIBS)
 
+ifeq ($(TARGET_ARCH_X86),yes)
+SRCS += dll_init.c
+LOADER_DEP = loader/libloader.a $(DS_DEP)
+LIB_LOADER = -Lloader -lloader $(DS_LIB)
+else
+LOADER_DEP =
+endif
+
+
 .SUFFIXES: .c .o
 
 # .PHONY: all clean
@@ -64,11 +73,12 @@
 encore/libencore.a:
 	$(MAKE) -C encore
 
-mplayerwithoutlink:	version.h mplayer.o $(OBJS) loader/libloader.a $(DS_DEP) libmpeg2/libmpeg2.a opendivx/libdecore.a $(COMMONLIBS) encore/libencore.a
-	@for a in mp3lib libac3 libmpeg2 libvo opendivx encore loader/DirectShow ; do $(MAKE) -C $$a all ; done
 
-$(PRG):	version.h mplayer.o $(OBJS) loader/libloader.a $(DS_DEP) libmpeg2/libmpeg2.a opendivx/libdecore.a $(COMMONLIBS) encore/libencore.a
-	$(CC) $(CFLAGS) -o $(PRG) mplayer.o $(OBJS) $(XMM_LIBS) $(LIRC_LIBS) $(A_LIBS) -lm $(TERMCAP_LIB) -Lloader -lloader $(DS_LIB) -Llibmpeg2 -lmpeg2 -Lopendivx -ldecore -Llibao2 -lao2 $(VO_LIBS) $(CSS_LIB) -Lencore -lencore $(ARCH_LIBS)
+mplayerwithoutlink:	version.h mplayer.o $(OBJS) $(LOADER_DEP) $(AV_DEP) libmpeg2/libmpeg2.a opendivx/libdecore.a $(COMMONLIBS) encore/libencore.a
+	@for a in mp3lib libac3 libmpeg2 libvo opendivx libavcodec encore loader/DirectShow ; do $(MAKE) -C $$a all ; done
+
+$(PRG):	version.h mplayer.o $(OBJS) $(LOADER_DEP) $(AV_DEP) libmpeg2/libmpeg2.a opendivx/libdecore.a $(COMMONLIBS) encore/libencore.a
+	$(CC) $(CFLAGS) -o $(PRG) mplayer.o $(OBJS) $(XMM_LIBS) $(LIRC_LIBS) $(A_LIBS) -lm $(TERMCAP_LIB) $(LIB_LOADER) $(AV_LIB) -Llibmpeg2 -lmpeg2 -Lopendivx -ldecore -Llibao2 -lao2 $(VO_LIBS) $(CSS_LIB) -Lencore -lencore $(ARCH_LIBS)
 
 $(PRG_FIBMAP): fibmap_mplayer.o
 	$(CC) -o $(PRG_FIBMAP) fibmap_mplayer.o
@@ -98,7 +108,7 @@
 	rm -f *.o *~ $(OBJS)
 
 distclean:
-	@for a in mp3lib libac3 libmpeg2 opendivx encore libvo libao2 loader loader/DirectShow drivers drivers/syncfb ; do $(MAKE) -C $$a distclean ; done
+	@for a in mp3lib libac3 libmpeg2 opendivx libavcodec encore libvo libao2 loader loader/DirectShow drivers drivers/syncfb ; do $(MAKE) -C $$a distclean ; done
 	rm -f *~ $(PRG) $(PRG_FIBMAP) $(PRG_HQ) $(PRG_AVIP) $(PRG_TV) $(OBJS) *.o *.a .depend
 
 dep:	depend
@@ -106,7 +116,7 @@
 depend:
 	./version.sh
 	$(CC) -MM $(CFLAGS) mplayer.c $(SRCS) 1>.depend
-	@for a in mp3lib libac3 libmpeg2 libvo libao2 opendivx encore loader/DirectShow ; do $(MAKE) -C $$a dep ; done
+	@for a in mp3lib libac3 libmpeg2 libvo libao2 opendivx libavcodec encore loader/DirectShow ; do $(MAKE) -C $$a dep ; done
 
 # ./configure must be run if it changed in CVS
 config.h: configure
--- a/aviheader.c	Thu Jul 12 15:30:15 2001 +0000
+++ b/aviheader.c	Thu Jul 12 15:35:52 2001 +0000
@@ -1,5 +1,5 @@
 
-
+#include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -13,10 +13,89 @@
 #include "wine/vfw.h"
 
 #include "codec-cfg.h"
+#include "bswap.h"
 #include "stheader.h"
 
 #define MIN(a,b) (((a)<(b))?(a):(b))
 
+/*
+ * Some macros to swap little endian structures read from an AVI file
+ * into machine endian format
+ */
+#ifdef WORDS_BIGENDIAN
+#define	le2me_MainAVIHeader(h) {					\
+    (h)->dwMicroSecPerFrame = le2me_32((h)->dwMicroSecPerFrame);	\
+    (h)->dwMaxBytesPerSec = le2me_32((h)->dwMaxBytesPerSec);		\
+    (h)->dwPaddingGranularity = le2me_32((h)->dwPaddingGranularity);	\
+    (h)->dwFlags = le2me_32((h)->dwFlags);				\
+    (h)->dwTotalFrames = le2me_32((h)->dwTotalFrames);			\
+    (h)->dwInitialFrames = le2me_32((h)->dwInitialFrames);		\
+    (h)->dwStreams = le2me_32((h)->dwStreams);				\
+    (h)->dwSuggestedBufferSize = le2me_32((h)->dwSuggestedBufferSize);	\
+    (h)->dwWidth = le2me_32((h)->dwWidth);				\
+    (h)->dwHeight = le2me_32((h)->dwHeight);				\
+}
+
+#define	le2me_AVIStreamHeader(h) {					\
+    (h)->fccType = le2me_32((h)->fccType);				\
+    (h)->fccHandler = le2me_32((h)->fccHandler);			\
+    (h)->dwFlags = le2me_32((h)->dwFlags);				\
+    (h)->wPriority = le2me_16((h)->wPriority);				\
+    (h)->wLanguage = le2me_16((h)->wLanguage);				\
+    (h)->dwInitialFrames = le2me_32((h)->dwInitialFrames);		\
+    (h)->dwScale = le2me_32((h)->dwScale);				\
+    (h)->dwRate = le2me_32((h)->dwRate);				\
+    (h)->dwStart = le2me_32((h)->dwStart);				\
+    (h)->dwLength = le2me_32((h)->dwLength);				\
+    (h)->dwSuggestedBufferSize = le2me_32((h)->dwSuggestedBufferSize);	\
+    (h)->dwQuality = le2me_32((h)->dwQuality);				\
+    (h)->dwSampleSize = le2me_32((h)->dwSampleSize);			\
+    le2me_RECT(&(h)->rcFrame);						\
+}
+#define	le2me_RECT(h) {							\
+    (h)->left = le2me_16((h)->left);					\
+    (h)->top = le2me_16((h)->top);					\
+    (h)->right = le2me_16((h)->right);					\
+    (h)->bottom = le2me_16((h)->bottom);				\
+}
+#define le2me_BITMAPINFOHEADER(h) {					\
+    (h)->biSize = le2me_32((h)->biSize);				\
+    (h)->biWidth = le2me_32((h)->biWidth);				\
+    (h)->biHeight = le2me_32((h)->biHeight);				\
+    (h)->biPlanes = le2me_16((h)->biPlanes);				\
+    (h)->biBitCount = le2me_16((h)->biBitCount);			\
+    (h)->biCompression = le2me_32((h)->biCompression);			\
+    (h)->biSizeImage = le2me_32((h)->biSizeImage);			\
+    (h)->biXPelsPerMeter = le2me_32((h)->biXPelsPerMeter);		\
+    (h)->biYPelsPerMeter = le2me_32((h)->biYPelsPerMeter);		\
+    (h)->biClrUsed = le2me_32((h)->biClrUsed);				\
+    (h)->biClrImportant = le2me_32((h)->biClrImportant);		\
+}
+#define le2me_WAVEFORMATEX(h) {						\
+    (h)->wFormatTag = le2me_16((h)->wFormatTag);			\
+    (h)->nChannels = le2me_16((h)->nChannels);				\
+    (h)->nSamplesPerSec = le2me_32((h)->nSamplesPerSec);		\
+    (h)->nAvgBytesPerSec = le2me_32((h)->nAvgBytesPerSec);		\
+    (h)->nBlockAlign = le2me_16((h)->nBlockAlign);			\
+    (h)->wBitsPerSample = le2me_16((h)->wBitsPerSample);		\
+    (h)->cbSize = le2me_16((h)->cbSize);				\
+}
+#define le2me_AVIINDEXENTRY(h) {					\
+    (h)->ckid = le2me_32((h)->ckid);					\
+    (h)->dwFlags = le2me_32((h)->dwFlags);				\
+    (h)->dwChunkOffset = le2me_32((h)->dwChunkOffset);			\
+    (h)->dwChunkLength = le2me_32((h)->dwChunkLength);			\
+}
+#else
+#define	le2me_MainAVIHeader(h)	    /**/
+#define le2me_AVIStreamHeader(h)    /**/
+#define le2me_RECT(h)		    /**/
+#define le2me_BITMAPINFOHEADER(h)   /**/
+#define le2me_WAVEFORMATEX(h)	    /**/
+#define le2me_AVIINDEXENTRY(h)	    /**/
+#endif
+
+
 static MainAVIHeader avih;
 
 extern void print_avih(MainAVIHeader *h);
@@ -61,12 +140,14 @@
   switch(id){
     case ckidAVIMAINHDR:          // read 'avih'
       stream_read(demuxer->stream,(char*) &avih,MIN(size2,sizeof(avih)));
+      le2me_MainAVIHeader(&avih); // swap to machine endian
       chunksize-=MIN(size2,sizeof(avih));
       if(verbose) print_avih(&avih);
       break;
     case ckidSTREAMHEADER: {      // read 'strh'
       AVIStreamHeader h;
       stream_read(demuxer->stream,(char*) &h,MIN(size2,sizeof(h)));
+      le2me_AVIStreamHeader(&h);  // swap to machine endian
       chunksize-=MIN(size2,sizeof(h));
       ++stream_id;
       if(h.fccType==streamtypeVIDEO){
@@ -86,6 +167,7 @@
 //        sh_video->bih=malloc(chunksize); memset(sh_video->bih,0,chunksize);
         if(verbose>=1) printf("found 'bih', %d bytes of %d\n",chunksize,sizeof(BITMAPINFOHEADER));
         stream_read(demuxer->stream,(char*) sh_video->bih,chunksize);
+	le2me_BITMAPINFOHEADER(sh_video->bih);  // swap to machine endian
         chunksize=0;
 //        sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale;
 //        sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
@@ -116,6 +198,7 @@
 //        sh_audio->wf=malloc(chunksize); memset(sh_audio->wf,0,chunksize);
         if(verbose>=1) printf("found 'wf', %d bytes of %d\n",chunksize,sizeof(WAVEFORMATEX));
         stream_read(demuxer->stream,(char*) sh_audio->wf,chunksize);
+	le2me_WAVEFORMATEX(sh_audio->wf);
 	if (sh_audio->wf->cbSize != 0 &&
 	    wf_size < sizeof(WAVEFORMATEX)+sh_audio->wf->cbSize) {
 	    sh_audio->wf=realloc(sh_audio->wf, sizeof(WAVEFORMATEX)+sh_audio->wf->cbSize);
@@ -127,11 +210,14 @@
       break;
     }
     case ckidAVINEWINDEX: if(index_mode){
+      int i;
       demuxer->idx_size=size2>>4;
       if(verbose>=1) printf("Reading INDEX block, %d chunks for %ld frames\n",
         demuxer->idx_size,avih.dwTotalFrames);
       demuxer->idx=malloc(demuxer->idx_size<<4);
       stream_read(demuxer->stream,(char*)demuxer->idx,demuxer->idx_size<<4);
+      for (i = 0; i < demuxer->idx_size; i++)	// swap index to machine endian
+	le2me_AVIINDEXENTRY((AVIINDEXENTRY*)demuxer->idx + i);
       chunksize-=demuxer->idx_size<<4;
       if(verbose>=2) print_index(demuxer->idx,demuxer->idx_size);
       break;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bswap.h	Thu Jul 12 15:35:52 2001 +0000
@@ -0,0 +1,1 @@
+#include "libac3/bswap.h"
--- a/configure	Thu Jul 12 15:30:15 2001 +0000
+++ b/configure	Thu Jul 12 15:35:52 2001 +0000
@@ -6,6 +6,11 @@
 #
 # Changes in reversed order:
 #
+# 2001/07/12 by Juergen Keil
+#  - add support for non-x86 targets
+#  - add autoconf checks for loader/wine
+#  - fix linux 2.2.x kernel check vs. SSE usage
+#
 # 2001/07/04 by Juergen Keil
 #  - autodetect the assembler binary used by the GCC C compiler
 #
@@ -172,18 +177,32 @@
 exit 0
 fi
 
+
 # LGB: Some inital help
 
 echo "You can get detailed help on configure with: $0 --help"
 echo "Please wait while ./configure discovers your software and hardware environment!"
 
+
+system_name=`uname -s 2>&1` # name of operating system: Linux, FreeBSD, NetBSD, SunOS
+host_arch=`uname -p 2>&1`   # host's instruction set or processor type
+case "$host_arch" in
+unknown)		    # Linux returns "unknown" for the processor type
+    case "`uname -m 2>&1`" in
+    i[3-9]86)
+	host_arch=i386;;
+    ppc)
+	host_arch=ppc;;
+    esac
+    ;;
+esac
+
 # Determine our OS name and OS dependent libs
 
-system_name=`uname -s 2>&1`
 if [ "$system_name" = "FreeBSD" ]; then
-_archlibs="-rdynamic -pthread"
+    _archlibs="-rdynamic -pthread"
 else
-_archlibs="-ldl -lpthread"
+    _archlibs="-ldl -lpthread"
 fi
 
 # LGB: temporary files
@@ -206,6 +225,10 @@
 	TMPS="/tmp/${TMPS}"
 fi
 
+cat > $TMPC << EOF
+int main( void ) { return 0; }
+EOF
+
 # ---
 
 # config files
@@ -324,29 +347,34 @@
 fi
 
 
-if [ -r /proc/cpuinfo ]; then
+if [ "$host_arch" = i386 ]; then
+    if [ -r /proc/cpuinfo ]; then
 	# linux with /proc mounted, extract cpu information from it
 	_cpuinfo="cat /proc/cpuinfo"
-elif [ -r /compat/linux/proc/cpuinfo ]; then
+    elif [ -r /compat/linux/proc/cpuinfo ]; then
         # FreeBSD with linux emulation /proc mounted, 
 	# extract cpu information from it
         _cpuinfo="cat /compat/linux/proc/cpuinfo"
-else
+    else
 	# all other OS try to extract cpu information from a small helper
 	# program TOOLS/cpuinfo instead
 	$_cc -o TOOLS/cpuinfo TOOLS/cpuinfo.c
 	_cpuinfo="TOOLS/cpuinfo"
-fi
+    fi
 
-pname=`$_cpuinfo | grep 'model name' | cut -d ':' -f 2`
-pparam=`$_cpuinfo | grep 'features' | cut -d ':' -f 2`
-if [ -z "$pparam" ]; then
-  pparam=`$_cpuinfo | grep 'flags' | cut -d ':' -f 2`
+    pname=`$_cpuinfo | grep 'model name' | cut -d ':' -f 2`
+    pparam=`$_cpuinfo | grep 'features' | cut -d ':' -f 2`
+    if [ -z "$pparam" ]; then
+	pparam=`$_cpuinfo | grep 'flags' | cut -d ':' -f 2`
+    fi
+    pvendor=`$_cpuinfo | grep 'vendor_id' | cut -d ':' -f 2  | cut -d ' ' -f 2`
+    pfamily=`$_cpuinfo | grep 'cpu family' | cut -d ':' -f 2 | cut -d ' ' -f 2`
+    pmodel=`$_cpuinfo | grep -v 'model name' | grep 'model' | cut -d ':' -f 2 | cut -d ' ' -f 2`
+    pstepping=`$_cpuinfo | grep 'stepping' | cut -d ':' -f 2 | cut -d ' ' -f 2`
+else
+    # not an x86 host, cpuinfo stuff is not relevant
+    pname= pparam= pvendor= pfamily= pmodel= pstepping=
 fi
-pvendor=`$_cpuinfo | grep 'vendor_id' | cut -d ':' -f 2  | cut -d ' ' -f 2`
-pfamily=`$_cpuinfo | grep 'cpu family' | cut -d ':' -f 2 | cut -d ' ' -f 2`
-pmodel=`$_cpuinfo | grep -v 'model name' | grep 'model' | cut -d ':' -f 2 | cut -d ' ' -f 2`
-pstepping=`$_cpuinfo | grep 'stepping' | cut -d ':' -f 2 | cut -d ' ' -f 2`
 
 _mmx=no
 _mmx2=no
@@ -371,10 +399,11 @@
 _dga2=no
 _svga=no
 _fbdev=no
-[ x`uname -s` = xLinux ] && _fbdev=yes
+[ "$system_name" = Linux ] && _fbdev=yes
 _lirc=no
 _css=no
 _dshow=yes
+[ "$host_arch" != i386 ] && _dshow=no
 _fastmemcpy=yes
 _streaming=no
 _libavcodec=no
@@ -396,7 +425,7 @@
 _alsa=yes
 _esd=yes
 
-for i in `echo $pparam`; do
+for i in $pparam; do
 
  case "$i" in
   3dnow)
@@ -427,161 +456,208 @@
 
 
 _win32libdirnotify=no
-if [ -d /usr/lib/win32 ]; then
- _win32libdir=/usr/lib/win32
-else
- if [ -d /usr/local/lib/win32 ]; then
-  _win32libdir=/usr/local/lib/win32
- else
-# This is our default:
-  _win32libdir=/usr/lib/win32
-  _win32libdirnotify=yes
- fi
+if [ "$host_arch" = i386 ]; then
+    if [ -d /usr/lib/win32 ]; then
+	_win32libdir=/usr/lib/win32
+    elif [ -d /usr/local/lib/win32 ]; then
+	_win32libdir=/usr/local/lib/win32
+    else
+	# This is our default:
+	_win32libdir=/usr/lib/win32
+	_win32libdirnotify=yes
+    fi
 fi
 
-if [ -d libavcodec ]; then
- if [ -f libavcodec/Makefile ]; then
-  _libavcodec=yes
- fi
+
+if [ -d libavcodec -a -f libavcodec/Makefile ]; then
+    _libavcodec=yes
 fi
 
+
 if [ -c /dev/mga_vid ]; then
  _mga=yes
  _syncfb=yes
 fi
 
-proc=pentium
-iproc=586
+
+
+case "$host_arch" in
+i386)
+    _arch="#define ARCH_X86 1"
+    _target_arch="TARGET_ARCH_X86=yes"
+    _words_endian="#undef WORDS_BIGENDIAN"
+    proc=pentium
+    iproc=586
 
-case "$pvendor" in
- AuthenticAMD)
-   case "$pfamily" in
-    3)
-      proc=i386
-      iproc=386
-      ;;
-    4)
-      proc=i486
-      iproc=486
-      ;;
-    5)
-      if [ $pmodel -ge 6 ]; then	# LGB: models are: K5/SSA5 K5 K5 K5 ? ? K6 K6 K6-2 K6-3 
-    	    proc=k6
-      else
-    	    proc=k5
-      fi
-      iproc=586
-      ;;
-    6|7)				# LGB: Though it seems Athlon CPUs returns with "6"
-      proc=k7
-      iproc=686
-      ;;
+    case "$pvendor" in
+    AuthenticAMD)
+	case "$pfamily" in
+	3)
+	    proc=i386
+	    iproc=386
+	    ;;
+	4)
+	    proc=i486
+	    iproc=486
+	    ;;
+	5)
+	    if [ $pmodel -ge 6 ]; then	# LGB: models are: K5/SSA5 K5 K5 K5 ? ? K6 K6 K6-2 K6-3 
+		proc=k6
+	    else
+		proc=k5
+	    fi
+	    iproc=586
+	    ;;
+	6|7)				# LGB: Though it seems Athlon CPUs returns with "6"
+	    proc=k7
+	    iproc=686
+	    ;;
+	*)
+	    proc=pentium
+	    iproc=586
+	    ;;
+	esac
+	;;
+    GenuineIntel)
+	case "$pfamily" in
+	3)
+	    proc=i386
+	    iproc=386
+	    ;;
+	4)
+	    proc=i486
+	    iproc=486
+	    ;;
+	5)
+	    proc=pentium
+	    iproc=586
+	    ;;
+	6)
+	    proc=i686
+	    iproc=686
+	    ;;
+	*)
+	    proc=pentium
+	    iproc=586
+	    ;;
+	esac
+	;;
+    unknown)              # added by Gabucino - upon Tibcu's request
+	case "$pfamily" in
+	3)
+	    proc=i386
+	    iproc=386
+	    ;;
+	4)
+	    proc=i486
+	    iproc=486
+	    ;;
+	*)
+	    proc=pentium
+	    iproc=586
+	    ;;
+	esac
+	;;
     *)
-      proc=pentium
-      iproc=586
-      ;;
-   esac
-   ;;
- GenuineIntel)
-   case "$pfamily" in
-    3)
-      proc=i386
-      iproc=386
-      ;;
-    4)
-      proc=i486
-      iproc=486
-      ;;
-    5)
-      proc=pentium
-      iproc=586
-      ;;
-    6)
-      proc=i686
-      iproc=686
-      ;;
-    *)
-      proc=pentium
-      iproc=586
-      ;;
-   esac
-   ;;
- unknown)              # added by Gabucino - upon Tibcu's request
-   case "$pfamily" in
-    3)
-      proc=i386
-      iproc=386
-      ;;
-    4)
-      proc=i486
-      iproc=486
-      ;;
-    *)
-      proc=pentium
-      iproc=586
-      ;;
-   esac
-   ;;
- *)
-   proc=pentium
-   iproc=586
-   ;;
+	proc=pentium
+	iproc=586
+	;;
+    esac
+
+    # check that gcc supports our cpu, if not, fallback to pentium
+    # LGB: check -mcpu and -march swithing step by step with enabling
+    # to fall back till 386.
+
+    #echo -n "Checking your GCC CPU optimalization abilities: "
+    if [ "$proc" = "k7" ]; then
+	#echo -n "trying k7  "
+	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=athlon
+    fi
+    if [ "$proc" = "athlon" ]; then
+	#echo -n "trying athlon  "
+	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=pentiumpro
+    fi
+    if [ "$proc" = "k6" ]; then
+	#echo -n "trying k6  "
+	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=k5
+    fi
+    if [ "$proc" = "k5" ]; then
+	#echo -n "trying k5  "
+	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=pentium
+    fi
+    if [ "$proc" = "i686" ]; then
+	#echo -n "trying i686  "
+	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=pentiumpro
+    fi
+    if [ "$proc" = "pentiumpro" ]; then
+	#echo -n "trying pentiumpro  "
+	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=pentium
+    fi
+    if [ "$proc" = "pentium" ]; then
+	#echo -n "trying pentium  "
+	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=i486
+    fi
+    if [ "$proc" = "i486" ]; then
+	#echo -n "trying i486  "
+	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=i386
+    fi
+    if [ "$proc" = "i386" ]; then
+	#echo -n "trying i386  "
+	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=error
+    fi
+    if [ "$proc" = "error" ]; then
+	echo
+	echo "Your gcc does not support even \"i386\" for '-march' and '-mcpu'." >&2
+	rm -f $TMPC $TMPO $TMPS
+	exit
+    fi
+
+    _march="-march=$proc"
+    _mcpu="-mcpu=$proc"
+    #echo "DONE (${proc})."
+    ;;
+
+
+sparc)
+    _arch="#define ARCH_SPARC 1"
+    _target_arch="TARGET_ARCH_SPARC=yes"
+    _words_endian="#define WORDS_BIGENDIAN 1"
+    iproc=sparc
+    proc=v8
+    _march=""
+    _mcpu="-mcpu=$proc"
+    ;;
+
+# Untested:
+#ppc)
+#    _arch="#define ARCH_PPC 1"
+#    _target_arch="TARGET_ARCH_PPC=yes"
+#    _words_endian="#define WORDS_BIGENDIAN 1"
+#    iproc=ppc
+#    proc=
+#    _march=""
+#    _mcpu=""
+#    ;;
+
+# Untested:
+#alpha)
+#    _arch="#define ARCH_ALPHA 1"
+#    _target_arch="TARGET_ARCH_ALPHA=yes"
+#    _words_endian="#undef WORDS_BIGENDIAN"
+#    iproc=alpha
+#    proc=
+#    _march=""
+#    _mcpu=""
+#    ;;
+
+*)
+    echo "The architecture of your CPU ($host_arch) is not supported by this configure script"
+    exit 1
+    ;;
 esac
 
 # ---
 
-cat > $TMPC << EOF
-int main( void ) { return 0; }
-EOF
-
-# check that gcc supports our cpu, if not, fallback to pentium
-# LGB: check -mcpu and -march swithing step by step with enabling
-# to fall back till 386.
-
-#echo -n "Checking your GCC CPU optimalization abilities: "
-if [ "$proc" = "k7" ]; then
-#	echo -n "trying k7  "
-	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=athlon
-fi
-if [ "$proc" = "athlon" ]; then
-#	echo -n "trying athlon  "
-	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=pentiumpro
-fi
-if [ "$proc" = "k6" ]; then
-#	echo -n "trying k6  "
-	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=k5
-fi
-if [ "$proc" = "k5" ]; then
-#	echo -n "trying k5  "
-	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=pentium
-fi
-if [ "$proc" = "i686" ]; then
-#	echo -n "trying i686  "
-	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=pentiumpro
-fi
-if [ "$proc" = "pentiumpro" ]; then
-#	echo -n "trying pentiumpro  "
-	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=pentium
-fi
-if [ "$proc" = "pentium" ]; then
-#	echo -n "trying pentium  "
-	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=i486
-fi
-if [ "$proc" = "i486" ]; then
-#	echo -n "trying i486  "
-	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=i386
-fi
-if [ "$proc" = "i386" ]; then
-#	echo -n "trying i386  "
-	$_cc $TMPC -o $TMPO -march=$proc -mcpu=$proc > /dev/null 2>&1 || proc=error
-fi
-if [ "$proc" = "error" ]; then
-	echo
-	echo "Your gcc does not support even \"i386\" for '-march' and '-mcpu'." >&2
-	rm -f $TMPC $TMPO $TMPS
-	exit
-fi
-#echo "DONE (${proc})."
 
 
 $_cc $_extraincdir $_extralibdir $TMPC -o $TMPO -lvgagl -lvga > /dev/null 2>&1 && _svga=yes
@@ -717,7 +793,43 @@
 
 
 # ---
-# try to detect type of audio supported on this machine
+# check availability of some header files
+
+cat > $TMPC << EOF
+#include <malloc.h>
+int main( void ) { return 0; }
+EOF
+
+_malloc_h=no
+$_cc -o $TMPO $TMPC 2> /dev/null && _malloc_h=yes
+
+
+cat > $TMPC << EOF
+#include <alloca.h>
+int main( void ) { return 0; }
+EOF
+
+_alloca_h=no
+$_cc -o $TMPO $TMPC 2> /dev/null && _alloca_h=yes
+
+
+cat > $TMPC << EOF
+#include <sys/mman.h>
+int main( void ) { return 0; }
+EOF
+
+_sys_mman_h=no
+$_cc -o $TMPO $TMPC 2> /dev/null && _sys_mman_h=yes
+
+
+cat > $TMPC << EOF
+#include <dlfcn.h>
+int main( void ) {  return 0; }
+EOF
+
+_libdl=no
+$_cc -o $TMPO $TMPC -ldl 2> /dev/null && _libdl=yes
+
 
 cat > $TMPC << EOF
 #include <sys/soundcard.h>
@@ -728,6 +840,9 @@
 $_cc -o $TMPO $TMPC 2> /dev/null && _sys_soundcard_h=yes
 
 
+# ---
+# try to detect type of audio supported on this machine
+
 cat > $TMPC << EOF
 #include <sys/soundcard.h>
 int main( void ) {  int arg = SNDCTL_DSP_SETFRAGMENT; }
@@ -1085,24 +1200,24 @@
 fi
 
 # Checking kernel version...
-_k_verc_problem=no
-if [ "$system_name" != "FreeBSD" ];then
-kernel_version=`uname -r 2>&1`
-echo $_echo_n "Checking $system_name kernel version ... $_echo_c"
-case $kernel_version in
-    '') kernel_version="?.??"; _k_verc_fail=yes;;
-    [0-1].[0-99].[0-99]|2.[0-3].[0-99])
-	_k_verc_problem=yes;;
-esac
-if [ $_k_verc_problem = 'yes' ] && [ $_sse = 'yes' ]; then
-_k_verc_fail=yes
-fi
-if [ ! -z "$_k_verc_fail" ]; then
-echo "$kernel_version, fail"
-echo "WARNING! You want to run mplayer on this system then be prepared for problems"
-else
-echo "$kernel_version, ok"
-fi
+if [ "$system_name" = "Linux" ];then
+    _k_verc_problem=no
+    kernel_version=`uname -r 2>&1`
+    echo $_echo_n "Checking $system_name kernel version ... $_echo_c"
+    case "$kernel_version" in
+	'') kernel_version="?.??"; _k_verc_fail=yes;;
+	[0-1].[0-9].[0-9]*|2.[0-3].[0-9]*)
+	    _k_verc_problem=yes;;
+    esac
+    if [ $_k_verc_problem = 'yes' ] && [ "$_sse" = 'yes' ]; then
+	_k_verc_fail=yes
+    fi
+    if [ ! -z "$_k_verc_fail" ]; then
+	echo "$kernel_version, fail"
+	echo "WARNING! If you want to run mplayer on this system, be prepared for problems"
+    else
+	echo "$kernel_version, ok"
+    fi
 fi
 
 if [ "$_xmga" = "autodetect" ]; then
@@ -1115,15 +1230,19 @@
 
 # to screen.
 echo "Install prefix: $_prefix"
-echo "Checking for cpu vendor ... $pvendor ( $pfamily:$pmodel:$pstepping )"
-echo "Checking for cpu type ... $pname"
+if [ "$host_arch" = i386 ]; then
+    echo "Checking for cpu vendor ... $pvendor ( $pfamily:$pmodel:$pstepping )"
+    echo "Checking for cpu type ... $pname"
+fi
 echo "Optimizing to ... $proc"
-echo "Checking for mmx support ... $_mmx"
-echo "Checking for mmx2 support ... $_mmx2"
-echo "Checking for 3dnow support ... $_3dnow"
-echo "Checking for 3dnowex support ... $_3dnowex"
-echo "Checking for sse support ... $_sse"
-echo "Checking for mtrr support ... $_mtrr"
+if [ "$host_arch" = i386 ]; then
+    echo "Checking for mmx support ... $_mmx"
+    echo "Checking for mmx2 support ... $_mmx2"
+    echo "Checking for 3dnow support ... $_3dnow"
+    echo "Checking for 3dnowex support ... $_3dnowex"
+    echo "Checking for sse support ... $_sse"
+    echo "Checking for mtrr support ... $_mtrr"
+fi
 echo "Screen size ... ${_x}x${_y}"
 echo "Checking for X11 libs ... $_x11libdir"
 echo "Checking for X11 headers ... $_x11incdir"
@@ -1257,9 +1376,9 @@
 fi
 
 if [ "$_kstat" = "yes" ]; then
-  _have_kstat="#define	HAVE_KSTAT 1"
+  _have_libkstat="#define HAVE_LIBKSTAT 1"
 else
-  _have_kstat="#undef	HAVE_KSTAT"
+  _have_libkstat="#undef HAVE_LIBKSTAT"
 fi
 
 if [ "$_xmmp" = "yes" ]; then
@@ -1317,13 +1436,37 @@
  _have_soundcard_h='#undef  HAVE_SYS_SOUNDCARD_H'
 fi
 
+if [ "$_malloc_h" = "yes" ]; then
+ _have_malloc_h='#define HAVE_MALLOC_H 1'
+else
+ _have_malloc_h='#undef  HAVE_MALLOC_H'
+fi
+
+if [ "$_alloca_h" = "yes" ]; then
+ _have_alloca_h='#define HAVE_ALLOCA_H 1'
+else
+ _have_alloca_h='#undef  HAVE_ALLOCA_H'
+fi
+
+if [ "$_sys_mman_h" = "yes" ]; then
+ _have_mman_h='#define HAVE_SYS_MMAN_H 1'
+else
+ _have_mman_h='#undef  HAVE_SYS_MMAN_H'
+fi
+
+if [ "$_libdl" = "yes" ]; then
+ _have_libdl='#define HAVE_LIBDL 1'
+else
+ _have_libdl='#undef  HAVE_LIBDL'
+fi
+
 
 # Checking for CFLAGS
 if [ "$_profile" != "" ] || [ "$_debug" != "" ]; then
- CFLAGS="-W -Wall -O2 -march=$proc -mcpu=$proc $_debug $_profile"
+ CFLAGS="-W -Wall -O2 $_march $_mcpu $_debug $_profile"
 else
 if test -z "$CFLAGS"; then
- CFLAGS="-O4 -march=$proc -mcpu=$proc -pipe -ffast-math -fomit-frame-pointer"
+ CFLAGS="-O4 $_march $_mcpu -pipe -ffast-math -fomit-frame-pointer"
 fi
 fi
 # Under FreeBSD (maybe other systems as well?) we have to add to CFLAGS
@@ -1522,7 +1665,7 @@
 prefix = $_prefix
 AR=ar
 CC=$_cc
-# OPTFLAGS=-O4 $_profile $_debug -march=$proc -mcpu=$proc -pipe -fomit-frame-pointer -ffast-math
+# OPTFLAGS=-O4 $_profile $_debug $_march $_mcpu -pipe -fomit-frame-pointer -ffast-math
 OPTFLAGS=$CFLAGS
 EXTRA_INC=$_extraincdir
 WIN32_PATH=-DWIN32_PATH=\"$_win32libdir\"
@@ -1537,15 +1680,17 @@
 CSS_LIB = $_csslib
 CSS_INC = $_cssinc
 SDL_INC = $_sdlcflags
-DS_DEP = $_dshowdep $_lavcdep
-DS_LIB = $_dshowlib $_lavclib
+DS_DEP = $_dshowdep
+DS_LIB = $_dshowlib
+AV_DEP = $_lavcdep
+AV_LIB = $_lavclib
 ALSA_LIB = $_alsalib
 ESD_LIB = $_esdlib
 ARCH_LIBS = $_archlibs
 STREAM_SRCS = $_streamingsrcs
 
 # --- Some stuff for autoconfigure ----
-TARGET_ARCH_X86=yes
+$_target_arch
 TARGET_CPU=$iproc
 TARGET_MMX=$_cfg_mmx
 TARGET_MMX2=$_cfg_mmx2
@@ -1609,10 +1754,21 @@
 /* Define this if your system has the header file for the OSS sound interface */
 $_have_soundcard_h
 
+/* Define this if your system has the "malloc.h" header file */
+$_have_malloc_h
+
+/* Define this if your system has the "alloca.h" header file */
+$_have_alloca_h
+
+/* Define this if your system has the "sys/mman.h" header file */
+$_have_mman_h
+
+
+/* Define this if you have the elf dynamic linker -ldl library */
+$_have_libdl
 
 /* Define this if you have the kstat kernel statistics library */
-$_have_kstat
-
+$_have_libkstat
 
 /* LIRC (remote control, see www.lirc.org) support: */
 $_lircdefs
@@ -1649,9 +1805,9 @@
 
 /* Define if your processor stores words with the most significant
    byte first (like Motorola and SPARC, unlike Intel and VAX).  */
-/* #define WORDS_BIGENDIAN */
+$_words_endian
 
-#define ARCH_X86
+$_arch
 
 /* Define this to any prefered value from 386 up to infinity with step 100 */
 #define __CPU__ $iproc
@@ -1756,13 +1912,19 @@
  echo "version might work. Use --enable-sdl to force usage of libSDL."
 fi
 
-if [ $_win32libdirnotify = yes ]; then
- echo "Failed to find a WIN32 codecs dir at $_win32libdir!"
- echo "Create it and copy the DLL files there! (You can get them from your windows"
- echo "directory or download them from:"
- echo "ftp://thot.banki.hu/esp-team/linux/MPlayer/w32codec.zip"
+if [ "$host_arch" = i386 ]; then
+    if [ $_win32libdirnotify = yes ]; then
+	echo "Failed to find a WIN32 codecs dir at $_win32libdir!"
+	echo "Create it and copy the DLL files there! (You can get them from your windows"
+	echo "directory or download them from:"
+	echo "ftp://thot.banki.hu/esp-team/linux/MPlayer/w32codec.zip"
+    else
+	echo "Ok, found Win32 codecs directory at $_win32libdir."
+    fi
 else
- echo "Ok, found Win32 codecs directory at $_win32libdir."
+    echo "NOTE: WIN32 codec DLLs are not supported on your CPU ($host_arch)."
+    echo "You may encounter a few AVI files that cannot be played due to"
+    echo "missing opensource video/audio codec support."
 fi
 
 # Last move:
--- a/dec_audio.c	Thu Jul 12 15:30:15 2001 +0000
+++ b/dec_audio.c	Thu Jul 12 15:35:52 2001 +0000
@@ -75,6 +75,10 @@
 
 switch(driver){
 case 4:
+#ifndef	ARCH_X86
+  printf("Win32/ACM audio codec unavailable on non-x86 CPU -> force nosound :(\n");
+  driver=0;
+#else
   // Win32 ACM audio codec:
   if(init_acm_audio_codec(sh_audio)){
     sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
@@ -88,6 +92,7 @@
     printf("Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n");
     driver=0;
   }
+#endif
   break;
 case 7:
 #ifndef USE_DIRECTSHOW
@@ -149,6 +154,7 @@
 sh_audio->a_buffer_len=0;
 
 switch(driver){
+#ifdef ARCH_X86
 case 4: {
     int ret=acm_decode_audio(sh_audio,sh_audio->a_buffer,4096,sh_audio->a_buffer_size);
     if(ret<0){
@@ -158,6 +164,7 @@
     sh_audio->a_buffer_len=ret;
     break;
 }
+#endif
 case 2: {
     // AVI PCM Audio:
     WAVEFORMATEX *h=sh_audio->wf;
@@ -320,6 +327,7 @@
         }
         //printf("{3:%d}",avi_header.idx_pos);fflush(stdout);
         break;
+#ifdef ARCH_X86
       case 4:
 //        len=sh_audio->audio_out_minsize; // optimal decoded fragment size
 //        if(len<minlen) len=minlen; else
@@ -327,6 +335,7 @@
 //        len=acm_decode_audio(sh_audio,buf,len);
         len=acm_decode_audio(sh_audio,buf,minlen,maxlen);
         break;
+#endif
 
 #ifdef USE_DIRECTSHOW
       case 7: // DirectShow
--- a/dec_video.c	Thu Jul 12 15:30:15 2001 +0000
+++ b/dec_video.c	Thu Jul 12 15:35:52 2001 +0000
@@ -76,6 +76,7 @@
 unsigned int out_fmt=sh_video->codec->outfmt[sh_video->outfmtidx];
 
 switch(sh_video->codec->driver){
+#ifdef ARCH_X86
  case 2: {
    if(!init_video_codec(sh_video,0)) {
 //     GUI_MSG( mplUnknowError )
@@ -142,6 +143,13 @@
    break;
 #endif
  }
+#else	/* !ARCH_X86 */
+ case 2:
+ case 4:
+ case 6:
+   fprintf(stderr,"MPlayer does not support win32 codecs on non-x86 platforms!\n");
+   return 0;
+#endif	/* !ARCH_X86 */
  case 3: {  // OpenDivX
    if(verbose) printf("OpenDivX video codec\n");
    { DEC_PARAM dec_param;
@@ -319,7 +327,9 @@
   }
 #endif
   case 6:
-  case 2: {
+  case 2:
+#ifdef ARCH_X86
+  {
     HRESULT ret;
     unsigned int t=GetTimer();
     unsigned int t2;
@@ -368,6 +378,10 @@
     }
     break;
   }
+#else
+    printf("Win32 video codec unavailable on non-x86 CPU -> force nosound :(\n");
+    break;
+#endif
   case 1: {
         int in_frame=0;
         int t=0;
--- a/demuxer.h	Thu Jul 12 15:30:15 2001 +0000
+++ b/demuxer.h	Thu Jul 12 15:35:52 2001 +0000
@@ -1,3 +1,5 @@
+
+#include "config.h"
 
 #define MAX_PACKS 4096
 #define MAX_PACK_BYTES 0x800000
@@ -143,7 +145,11 @@
 static inline int avi_stream_id(unsigned int id){
   unsigned char *p=(unsigned char *)&id;
   unsigned char a,b;
+#if WORDS_BIGENDIAN
+  a=p[3]-'0'; b=p[2]-'0';
+#else
   a=p[0]-'0'; b=p[1]-'0';
+#endif
   if(a>9 || b>9) return 100; // invalid ID
   return a*10+b;
 }
--- a/dll_init.c	Thu Jul 12 15:30:15 2001 +0000
+++ b/dll_init.c	Thu Jul 12 15:35:52 2001 +0000
@@ -11,7 +11,7 @@
 
 #include "loader.h"
 //#include "wine/mmreg.h"
-//#include "wine/vfw.h"
+#include "wine/vfw.h"
 #include "wine/avifmt.h"
 
 #include "codec-cfg.h"
--- a/libvo/Makefile	Thu Jul 12 15:30:15 2001 +0000
+++ b/libvo/Makefile	Thu Jul 12 15:35:52 2001 +0000
@@ -3,9 +3,13 @@
 
 LIBNAME = libvo.a
 
-SRCS=aclib.c osd.c font_load.c rgb15to16mmx.c yuv2rgb_mmx.c yuv2rgb.c video_out.c vo_null.c vo_pgm.c vo_md5.c vo_odivx.c x11_common.c $(OPTIONAL_SRCS)
+SRCS=aclib.c osd.c font_load.c yuv2rgb.c video_out.c vo_null.c vo_pgm.c vo_md5.c vo_odivx.c x11_common.c $(OPTIONAL_SRCS)
 OBJS=$(SRCS:.c=.o)
 
+ifeq ($(TARGET_ARCH_X86),yes)
+SRCS += rgb15to16mmx.c yuv2rgb_mmx.c
+endif
+
 CFLAGS  = $(OPTFLAGS) -I. -I.. $(SDL_INC) $(X11_INC) $(EXTRA_INC) -DMPG12PLAY
 # -I/usr/X11R6/include/
 
--- a/mp3lib/sr1.c	Thu Jul 12 15:30:15 2001 +0000
+++ b/mp3lib/sr1.c	Thu Jul 12 15:35:52 2001 +0000
@@ -123,7 +123,15 @@
 //  if(MP3_frames>=7741) printf("getbits_fast: bits=%d  bitsleft=%d  wordptr=%x\n",number_of_bits,bitsleft,wordpointer);
   if((bitsleft-=number_of_bits)<0) return 0;
   if(!number_of_bits) return 0;
+#if	ARCH_X86
   rval = bswap_16(*((unsigned short *)wordpointer));
+#else
+  /*
+   * we may not be able to address unaligned 16-bit data on non-x86 cpus.
+   * Fall back to some portable code.
+   */
+  rval = wordpointer[0] << 8 | wordpointer[1];
+#endif
          rval <<= bitindex;
          rval &= 0xffff;
          bitindex += number_of_bits;
@@ -158,7 +166,19 @@
 
 LOCAL int stream_head_read(unsigned char *hbuf,unsigned long *newhead){
   if(mp3_read(hbuf,4) != 4) return FALSE;
+#if ARCH_X86
   *newhead = bswap_32(*((unsigned long *)hbuf));
+#else
+  /*
+   * we may not be able to address unaligned 32-bit data on non-x86 cpus.
+   * Fall back to some portable code.
+   */
+  *newhead = 
+      hbuf[0] << 24 |
+      hbuf[1] << 16 |
+      hbuf[2] <<  8 |
+      hbuf[3];
+#endif
   return TRUE;
 }