#
# libavcodec Makefile
# (c) 2000, 2001, 2002 Fabrice Bellard
#
include ./config.mak
include ./config.cpu

VPATH=$(SRC_PATH)/libavcodec

# NOTE: -I.. is needed to include config.h
CFLAGS= $(OPTFLAGS) -g -Wall -O2 -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE
LDFLAGS= -g

OBJS= common.o utils.o mem.o allcodecs.o \
      mpegvideo.o h263.o jrevdct.o jfdctfst.o jfdctint.o\
      mpegaudio.o ac3enc.o mjpeg.o resample.o dsputil.o \
      motion_est.o imgconvert.o imgresample.o msmpeg4.o \
      mpeg12.o h263dec.o svq1.o rv10.o mpegaudiodec.o pcm.o simple_idct.o \
      ratecontrol.o adpcm.o eval.o dv.o error_resilience.o \
      wmadec.o fft.o mdct.o mace.o huffyuv.o opts.o cyuv.o \
      raw.o  vp3.o h264.o indeo3.o  golomb.o ffv1.o ra144.o  ra288.o \
      4xm.o cabac.o asv1.o vcr1.o cljr.o
ASM_OBJS=

	
# i386 mmx specific stuff
ifeq ($(TARGET_MMX),yes)
OBJS += i386/fdct_mmx.o i386/cputest.o \
	i386/dsputil_mmx.o i386/mpegvideo_mmx.o \
	i386/idct_mmx.o i386/motion_est_mmx.o \
	i386/simple_idct_mmx.o
endif

# post proc files
# uncomplete ? OBJS += 	libpostproc/postprocess.o

SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S)
OBJS := $(OBJS) $(ASM_OBJS)

LIB= libavcodec.a
TESTS= imgresample-test dct-test motion-test fft-test

all: $(LIB) $(SLIB)
tags:

tests: apiexample cpuid_test $(TESTS)

$(LIB): $(OBJS)
	rm -f $@
	$(AR) rc $@ $(OBJS)
	$(RANLIB) $@

$(SLIB): $(OBJS)
	$(CC) $(SHFLAGS) -o $@ $(OBJS) $(EXTRALIBS)

dsputil.o: dsputil.c dsputil.h

# specific sse code
%_sse.o : %_sse.c
	$(CC) $(CFLAGS) -msse -c -o $@ $< 

# specific 3dnow code
%_3dnow.o : %_3dnow.c
	$(CC) $(CFLAGS) -m3dnow -c -o $@ $< 

%.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $< 

%.o: %.S
	$(CC) $(CFLAGS) -c -o $@ $<


# depend only used by mplayer now
dep:	depend

depend:
	$(CC) -MM $(CFLAGS) $(SRCS) 1>.depend

clean: 
	rm -f *.o *~ .depend $(LIB) $(SLIB) *.so i386/*.o i386/*~ \
	   armv4l/*.o armv4l/*~ \
	   mlib/*.o mlib/*~ \
	   alpha/*.o alpha/*~ \
	   ppc/*.o ppc/*~ \
	   ps2/*.o ps2/*~ \
	   liba52/*.o liba52/*~ \
	   apiexample $(TESTS)

distclean: clean
	rm -f Makefile.bak .depend
top_distdir = ../
DIST386= \
	i386/cputest.c \
	i386/dsputil_mmx.c \
	i386/dsputil_mmx_avg.h \
	i386/dsputil_mmx_rnd.h \
	i386/fdct_mmx.c \
	i386/fft_sse.c \
	i386/idct_mmx.c \
	i386/mmx.h \
	i386/motion_est_mmx.c \
	i386/mpegvideo_mmx.c \
	i386/mpegvideo_mmx_template.c \
	i386/simple_idct_mmx.c
DISTFILES= $(DIST386) \
	Makefile \
	a52dec.c \
	ac3.h \
	ac3dec.c \
	ac3enc.c \
	ac3tab.h \
	adpcm.c \
	allcodecs.c \
	apiexample.c \
	avcodec.c \
	avcodec.h \
	bswap.h \
	common.c \
	common.h \
	config.h \
	config.h \
	config.mak \
	cyuv.c \
	dct-test.c \
	dsputil.c \
	dsputil.h \
	dv.c \
	dvdata.h \
	error_resilience.c \
	eval.c \
	fastmemcpy.h \
	fdctref.c \
	fft-test.c \
	fft.c \
	h263.c \
	h263data.h \
	h263dec.c \
	huffyuv.c \
	imgconvert.c \
	imgresample.c \
	jfdctfst.c \
	jfdctint.c \
	jrevdct.c \
	mace.c \
	mdct.c \
	mem.c \
	mjpeg.c \
	motion_est.c \
	motion_est_template.c \
	motion_test.c \
	mp3lameaudio.c \
	mpeg12.c \
	mpeg12data.h \
	mpeg4data.h \
	mpegaudio.c \
	mpegaudio.h \
	mpegaudiodec.c \
	mpegaudiodectab.h \
	mpegaudiotab.h \
	mpegvideo.c \
	mpegvideo.h \
	msmpeg4.c \
	msmpeg4data.h \
	oggvorbis.c \
	oggvorbis.h \
	opts.c \
	os_support.h \
	pcm.c \
	ratecontrol.c \
	raw.c \
	resample.c \
	rv10.c \
	simple_idct.c \
	simple_idct.h \
	svq1.c \
	svq1_cb.h \
	utils.c \
	wmadata.h \
	wmadec.c \
	wmv2.c \
	golomb.c \
	indeo3.c \
	svq3.c \
	indeo3data.h \
	golomb.h \
	vp3.c \
	vp3data.h \
	h264.c \
	h264data.h \
	imgconvert_template.h \
	ffv1.c \
	ra144.h \
	ra288.h \
	ra144.c \
	ra288.c  \
	golomb.c \
	4xm.c \
	cabac.c \
	cabac.h \
	golomb.h \
	svq1_vlc.h \
	asv1.c vcr1.c cljr.c \
	mdec.c

srcdir= .
distdir: $(DISTFILES)
	mkdir $(distdir)/i386
	@for file in $(DISTFILES); do \
	if test -f $$file; then d=.; else d=$(srcdir); fi; \
	dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
	if test "$$dir" != "$$file" && test "$$dir" != "."; then \
	$(mkinstalldirs) "$(distdir)/$$dir"; \
	fi; \
	if test -d $$d/$$file; then \
	cp -pR $$d/$$file $(distdir) \
	|| exit 1; \
	else \
	test -f $(distdir)/$$file \
	|| cp -p $$d/$$file $(distdir)/$$file \
	|| exit 1; \
	fi; \
	done

# api example program
apiexample: apiexample.c $(LIB)
	$(CC) $(CFLAGS) -o $@ $< $(LIB) $(EXTRALIBS) -lm

# cpuid test
cpuid_test: i386/cputest.c
	$(CC) $(CFLAGS) -D__TEST__ -o $@ $<

# testing progs

imgresample-test: imgresample.c
	$(CC) $(CFLAGS) -DTEST -o $@ $^ -lm

dct-test: dct-test.o jfdctfst.o jfdctint.o i386/fdct_mmx.o\
          fdctref.o jrevdct.o i386/idct_mmx.o simple_idct.o i386/simple_idct_mmx.o
	$(CC) -o $@ $^ -lm

motion-test: motion_test.o $(LIB)
	$(CC) -o $@ $^ -lm

fft-test: fft-test.o fft.o mdct.o
	$(CC) -o $@ $^ -lm

install: all

installlib: all
	echo "nothing to install"
#
# include dependency files if they exist
#

#ifneq ($(wildcard .depend),)
#include .depend
#endif
