VERSION = 0.2.0

INCLUDES = 
LIBS = 

CC = gcc
CFLAGS += -std=c99 -pedantic -Wall -W -Wshadow -Wwrite-strings -Wno-unused -g $(INCLUDES)

LD = gcc
LDFLAGS += $(LIBS)

AR = ar
ARFLAGS = rsc

BINARIES = h264_analyze

all: libh264bitstream.a $(BINARIES)

# h264_slice_data.c: h264_slice_data.in.c process.pl
# 	perl process.pl > h264_slice_data.c < h264_slice_data.in.c

# h264_stream.c: h264_stream.in.c process.pl
# 	perl process.pl > h264_stream.c < h264_stream.in.c

# h264_sei.c: h264_sei.in.c process.pl
# 	perl process.pl > h264_sei.c < h264_sei.in.c

h264_analyze: h264_analyze.o libh264bitstream.a
	$(LD) $(LDFLAGS) -o h264_analyze h264_analyze.o -L. -lh264bitstream -lm

libh264bitstream.a: h264_stream.c h264_nal.c h264_stream.h h264_slice_data.c h264_slice_data.h h264_sei.c h264_sei.h 
	$(CC) $(CFLAGS) -c -o h264_nal.o h264_nal.c
	$(CC) $(CFLAGS) -c -o h264_stream.o h264_stream.c
	$(CC) $(CFLAGS) -c -o h264_slice_data.o h264_slice_data.c
	$(CC) $(CFLAGS) -c -o h264_sei.o h264_sei.c
	$(AR) $(ARFLAGS) libh264bitstream.a h264_stream.o h264_nal.o h264_slice_data.o h264_sei.o  


clean:
	rm -f *.o libh264bitstream.a $(BINARIES)

dox: h264_stream.c h264_stream.h bs.h Doxyfile
	doxygen Doxyfile

dist: clean
	mkdir h264bitstream-$(VERSION)
	tar c --files-from=MANIFEST -f tmp.tar ; cd h264bitstream-$(VERSION) ; tar xf ../tmp.tar ; rm -f ../tmp.tar
	tar czf ../h264bitstream-$(VERSION).tar.gz h264bitstream-$(VERSION)
	rm -rf h264bitstream-$(VERSION)

test:
	./h264_analyze samples/JM_cqm_cabac.264 > tmp1.out
	diff -u samples/JM_cqm_cabac.out tmp1.out
	./h264_analyze samples/x264_test.264 > tmp2.out
	diff -u samples/x264_test.out tmp2.out
	./h264_analyze samples/riverbed-II-360p-48961.264 > tmp3.out
	diff -u samples/riverbed-II-360p-48961.out tmp3.out
