diff --unified=3 -r libmpeg3-1.7-orig/Makefile libmpeg3-1.7/Makefile
--- libmpeg3-1.7-orig/Makefile	2006-02-15 07:09:31.000000000 +0200
+++ libmpeg3-1.7/Makefile	2007-09-27 22:25:40.000000000 +0300
@@ -2,7 +2,7 @@
 NASM = nasm
 USE_MMX = 0
 USE_CSS = 1
-A52DIR := $(shell expr a52dec* )
+A52DIR := /usr/include/a52dec
 
 
 ifeq ("$(PREFIX)", "")
@@ -23,29 +23,19 @@
 
 ifeq ($(OBJDIR), alpha)
   USE_MMX = 0
-  ifneq ($(HAVE_CFLAGS), y)
-    CFLAGS := -O4 -arch ev67 -ieee -accept c99_keywords -gcc_messages
-  endif
+  ADD_CFLAGS := -O4 -mieee
 endif
 
 ifeq ($(OBJDIR), i686)
   USE_MMX = 1
-  ifneq ($(HAVE_CFLAGS), y)
-    CFLAGS := -O2 -fomit-frame-pointer -falign-loops=2 -falign-jumps=2 -falign-functions=2 -I/usr/local/include
-  endif
-  CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
+  ADD_CFLAGS = -O2 -fomit-frame-pointer -falign-loops=2 -falign-jumps=2 -falign-functions=2 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
 endif
 
 ifeq ($(OBJDIR), x86_64)
-  ifneq ($(HAVE_CFLAGS), y)
-    CFLAGS := -O2 -fomit-frame-pointer -I/usr/local/include
-  endif
-  CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
-
-
+  ADD_CFLAGS := -O2 -fomit-frame-pointer -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
 endif
 
-
+CFLAGS += $(ADD_CFLAGS)
 
 ifeq ($(USE_CSS), 1)
   CFLAGS += -DHAVE_CSS
@@ -65,7 +55,8 @@
 CFLAGS += \
 	-I. \
 	-I$(A52DIR)/include \
-	-I$(A52DIR)/liba52
+	-I$(A52DIR)/liba52 \
+	-I$(A52DIR)
 
 
 
@@ -117,6 +108,9 @@
 	$(OBJDIR)/video/vlc.o \
 	$(OBJDIR)/workarounds.o
 
+SOBJS = $(OBJS:.o=.lo)
+.SUFFIXES: .lo
+
 #OBJS = \
 #	$(OBJDIR)/audio/ac3.o \
 #	$(OBJDIR)/audio/bit_allocation.o \
@@ -136,45 +130,51 @@
 	$(OBJDIR)/audio \
 	$(OBJDIR)/video
 
-include Makefile.a52
-
-DIRS += $(A52DIRS)
-
+SHLIB=libmpeg3.so
+SHLIB_FULLNAME=$(SHLIB).$(version)
+SHLIB_SONAME=$(SHLIB).$(major)
 
 OUTPUT = $(OBJDIR)/libmpeg3.a
+SHAREDOUTPUT = $(OBJDIR)/$(SHLIB_FULLNAME)
 UTILS = $(OBJDIR)/mpeg3dump $(OBJDIR)/mpeg3peek $(OBJDIR)/mpeg3toc  $(OBJDIR)/mpeg3cat
 
 #$(OBJDIR)/mpeg3split
 
 
-LIBS = -lm -lpthread
+LIBS = -lm -lpthread -la52
 
-$(shell if ! test -d $(OBJDIR) \; then mkdir -p $(OBJDIR) \; fi )
+$(shell if ! test -d $(OBJDIR) ; then mkdir -p $(OBJDIR) ; fi )
 
 $(shell echo $(CFLAGS) > $(OBJDIR)/c_flags)
-$(shell echo $(A52CFLAGS) > $(OBJDIR)/a52_flags)
 $(shell echo $(OBJS) $(ASMOBJS) $(A52OBJS) $(NASMOBJS) > $(OBJDIR)/objs)
 $(shell mkdir -p $(DIRS) )
 
-all: $(OUTPUT) $(UTILS)
+all: $(OUTPUT) $(SHAREDOUTPUT) $(UTILS)
 
 
 $(OUTPUT): $(OBJS) $(ASMOBJS) $(NASMOBJS) $(A52OBJS)
 	ar rcs $(OUTPUT) `cat $(OBJDIR)/objs`
 
-
+$(SHAREDOUTPUT): $(SOBJS)
+	gcc -shared -fPIC -o $(SHAREDOUTPUT) \
+	 $(LIBS) $(SOBJS) \
+	 -Wl,-soname -Wl,$(SHLIB_SONAME)
+	( cd $(OBJDIR); \
+	 ln -sf $(SHLIB_FULLNAME) $(SHLIB); \
+	 ln -sf $(SHLIB_FULLNAME) $(SHLIB_SONAME); \
+	 )
 
 $(OBJDIR)/mpeg3dump: $(OUTPUT) mpeg3dump.c
-	$(CC) `cat $(OBJDIR)/c_flags` -o $(OBJDIR)/mpeg3dump mpeg3dump.c $(OUTPUT) $(LIBS)
+	$(CC) `cat $(OBJDIR)/c_flags` -o $(OBJDIR)/mpeg3dump mpeg3dump.c $(SHAREDOUTPUT) $(LIBS)
 
 $(OBJDIR)/mpeg3peek: $(OUTPUT) mpeg3peek.c
-	$(CC) `cat $(OBJDIR)/c_flags` -o $(OBJDIR)/mpeg3peek mpeg3peek.c $(OUTPUT) $(LIBS)
+	$(CC) `cat $(OBJDIR)/c_flags` -o $(OBJDIR)/mpeg3peek mpeg3peek.c $(SHAREDOUTPUT) $(LIBS)
 
 $(OBJDIR)/mpeg3toc: $(OUTPUT) mpeg3toc.c
-	$(CC) `cat $(OBJDIR)/c_flags` -o $(OBJDIR)/mpeg3toc mpeg3toc.c $(OUTPUT) $(LIBS)
+	$(CC) `cat $(OBJDIR)/c_flags` -o $(OBJDIR)/mpeg3toc mpeg3toc.c $(SHAREDOUTPUT) $(LIBS)
 
 $(OBJDIR)/mpeg3cat: $(OUTPUT) mpeg3cat.c
-	$(CC) `cat $(OBJDIR)/c_flags` -o $(OBJDIR)/mpeg3cat mpeg3cat.c $(OUTPUT) $(LIBS)
+	$(CC) `cat $(OBJDIR)/c_flags` -o $(OBJDIR)/mpeg3cat mpeg3cat.c $(SHAREDOUTPUT) $(LIBS)
 
 #$(OBJDIR)/mpeg3split: $(OUTPUT)
 #	$(CC) `cat $(OBJDIR)/c_flags` -o $(OBJDIR)/mpeg3split mpeg3split.c $(OUTPUT) $(LIBS)
@@ -191,9 +191,17 @@
 		-ldl
 
 install: 
-	cp $(UTILS) $(PREFIX)/bin
-#	cp $(OUTPUT) $(PREFIX)/lib
-#	cp libmpeg3.h mpeg3private.h $(PREFIX)/include
+	install -d $(PREFIX)/bin
+	install -m 755 $(UTILS) $(PREFIX)/bin
+
+	install -d $(PREFIX)/lib
+	cp -dp $(OUTPUT) $(SHAREDOUTPUT) $(OBJDIR)/$(SHLIB_SONAME) $(PREFIX)/lib
+
+	install -d $(PREFIX)/include/audio
+	install -d $(PREFIX)/include/video
+	install -m 644 *.h $(PREFIX)/include
+	install -m 644 audio/*.h $(PREFIX)/include/audio
+	install -m 644 video/*.h $(PREFIX)/include/video
 
 clean:
 	rm -rf $(OBJDIR)
@@ -206,7 +214,9 @@
 	cat *.c *.h audio/*.c audio/*.h video/*.c video/*.h | wc
 
 $(OBJS): 
-	$(CC) -c `cat $(OBJDIR)/c_flags` $(subst $(OBJDIR)/,, $*.c) -o $*.o
+	$(CC) -c -D_REENTRANT `cat $(OBJDIR)/c_flags` $(subst $(OBJDIR)/,, $*.c) -o $*.o
+$(SOBJS): 
+	$(CC) -c -D_REENTRANT -fPIC `cat $(OBJDIR)/c_flags` $(subst $(OBJDIR)/,, $*.c) -o $*.lo
 $(ASMOBJS): 
 	$(CC) -c `cat $(OBJDIR)/c_flags` $(subst $(OBJDIR)/,, $*.S) -o $*.o
 $(NASMOBJS): 
diff --unified=3 -r libmpeg3-1.7-orig/audio/Makefile libmpeg3-1.7/audio/Makefile
--- libmpeg3-1.7-orig/audio/Makefile	2005-04-21 06:59:42.000000000 +0300
+++ libmpeg3-1.7/audio/Makefile	2007-09-27 22:06:13.000000000 +0300
@@ -18,7 +18,7 @@
 all: $(OBJS)
 
 .c.o:
-	$(CC) -c `./c_flags` $*.c
+	$(CC) -c -fPIC `./c_flags` $*.c
 
 .s.o:
 	$(CC) -f elf $*.s
diff --unified=3 -r libmpeg3-1.7-orig/video/Makefile libmpeg3-1.7/video/Makefile
--- libmpeg3-1.7-orig/video/Makefile	2005-04-21 06:59:42.000000000 +0300
+++ libmpeg3-1.7/video/Makefile	2007-09-27 22:06:45.000000000 +0300
@@ -19,7 +19,7 @@
 all: $(OBJS) $(MMXOBJS2)
 
 .c.o:
-	$(CC) -c `./c_flags` $*.c
+	$(CC) -c -fPIC `./c_flags` $*.c
 
 .s.o:
 	$(NASM) -f elf $*.s
