# 
# Copyright (c) 1993 The Regents of the University of California.
# All rights reserved.
# 
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose, without fee, and without written agreement is
# hereby granted, provided that the above copyright notice and the following
# two paragraphs appear in all copies of this software.
# 
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
# OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
# CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# 
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
# ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
# PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
# 

#  
#  $Header: /n/picasso/users/dwallach/vid2/mpeg_encode/RCS/Makefile,v 1.3 1993/01/18 10:20:02 dwallach Exp dwallach $
# 

##############################################################################
#
# Configurable items -- you want to make sure CC points at an ANSI
# compliant C compiler, and that INCLUDE and LIBDIRS specify what's
# necessary for you to include and link against the PBMPLUS libraries.
#
#

################################################################
# PROFILING # use -pg or -p if and only if you want to profile #
################################################################
PROFLAG =

#######################################################
# DEBUGGING # use -g if and only if you want to debug #
#######################################################
DEBUGFLAG =

###############################################################################
# MISSING PROTOTYES # use -DMISSING_PROTOS if your standard headers are wrong #
###############################################################################
PROTOFLAG = 
#PROTOFLAG = -DMISSING_PROTOS

#################################################################
# PBM DIRECTORIES # specify which directories to find pbm stuff #
#################################################################
# directory with libpbm.a, libpgm.a, libppm.a, libpnm.a
PBMLIBDIR = ./pbmplus
# directory with pbm.h, pgm.h, ppm.h, pnm.h
PBMHDRDIR = ./pbmplus

############################################################################
# LIBRARIES # specify library directories; besides pbm, only need math lib #
############################################################################
LIBDIRS = -L$(PBMLIBDIR)

#####################################################################
# COMPILER # specify compiler; should be ANSI-compliant if possible #
#####################################################################
CC = gcc

###################################################
# COMPILER FLAGS # modify for different compilers #
###################################################
# use -DLONG_32 iff
#	1) long's are 32 bits and
#	2) int's are not
#
# if you don't have <netinet/in.h> then you must define one of the following
#	-DFORCE_BIG_ENDIAN
#	-DFORCE_LITTLE_ENDIAN
#
# if you are using a non-ANSI compiler, then use:
#	-DNON_ANSI_COMPILER
#
# one other option:
#	-DHEINOUS_DEBUG_MODE
#
# listed below are some suggested CFLAG lines for various compilers
# 

#	gcc
CFLAGS = $(INCLUDE) -Iheaders -O $(DEBUGFLAG) -Wall -Wmissing-prototypes $(PROFLAG) $(PROTOFLAG)

#	SUN cc
#CFLAGS = $(INCLUDE) -Iheaders -O $(DEBUGFLAG) $(PROFLAG) $(PROTOFLAG) -DNON_ANSI_COMPILER

#	HP cc
#CFLAGS = $(INCLUDE) -Iheaders -O $(DEBUGFLAG) $(PROFLAG) $(PROTOFLAG) -DNON_ANSI_COMPILER

#	DEC ALPHA cc
#CFLAGS = $(INCLUDE) -Iheaders -O -Olimit 1200 $(DEBUGFLAG) $(PROFLAG) $(PROTOFLAG)

# 	SGI cc
#CFLAGS = $(INCLUDE) -Iheaders -O $(DEBUGFLAG) $(PROFLAG) $(PROTOFLAG) -cckr

#	Intel-based SVR4.0 cc
#CFLAGS = $(INCLUDE) -Iheaders -O $(DEBUGFLAG) $(PROFLAG) $(PROTOFLAG) -DLONG_32 -DSVR4 -DSYSV386

#	Intel-based SCO Unix
#CFLAGS = -O -DNDEBUG -m486

#	IBM RS/6000 cc
#CFLAGS = $(INCLUDE) -Iheaders -O $(DEBUGFLAG) $(PROFLAG) $(PROTOFLAG)


#########################################################################
# LIBRARIES # same for most machines; may need to add stuff for sockets #
#########################################################################
#	this works for most machines
LIBS = -lpnm -lppm -lpgm -lpbm -lm

#	Intel-based SVR4.0
#LIBS = -lpnm -lppm -lpgm -lpbm -lm -lsocket -lnsl -lgen

#	Intel-based SCO Unix
#LIBS = -lX11 -lsocket -lmalloc -lPW -lc_s -lm -lppm -lpnm -lpgm -lpbm


###############
# OTHER STUFF #
###############
PURIFY =

#
# End of configurable options.  Just type make and have fun.
##############################################################################

INCLUDE = -I$(PBMHDRDIR) 

MP_BASE_OBJS = mfwddct.o postdct.o huff.o bitio.o mheaders.o
MP_BASE_SRCS = mfwddct.c postdct.c huff.c bitio.c mheaders.c
MP_ENCODE_OBJS = iframe.o pframe.o bframe.o psearch.o bsearch.o block.o
MP_ENCODE_SRCS = iframe.c pframe.c bframe.c psearch.c bsearch.c block.c
MP_OTHER_OBJS = mpeg.o subsample.o param.o rgbtoycc.o \
	readframe.o combine.o jrevdct.o frame.o fsize.o
MP_OTHER_SRCS = mpeg.c subsample.c param.c rgbtoycc.c \
	readframe.c combine.c jrevdct.c frame.c fsize.c
MP_PARALLEL_OBJS = parallel.o
MP_PARALLEL_SRCS = parallel.c
MP_ALL_SRCS = $(MP_BASE_SRCS) $(MP_OTHER_SRCS) $(MP_ENCODE_SRCS) \
	      $(MP_PARALLEL_SRCS) main.c
MP_ALL_OBJS = $(MP_BASE_OBJS) $(MP_OTHER_OBJS) $(MP_ENCODE_OBJS) \
	      $(MP_PARALLEL_OBJS) main.o
MP_INCLUDE = mproto.h mtypes.h huff.h bitio.h
MP_MISC = Makefile huff.table parse_huff.pl


all: $(ANSI2KNR) mpeg_encode

#########
# TESTS #
#########

test:
	rm -f tmp.stat
	./mpeg_encode -stat tmp.stat ../test/ts.param
	csh ../test/diffscript tmp.stat ../test/ts.stat /tmp/ts.mpg ../test/ts.mpg
	

############
# BINARIES #
############

mpeg_encode: $(ANSI2KNR) $(MP_ALL_OBJS)
	$(PURIFY) $(CC) $(CFLAGS) -o $@ $(MP_ALL_OBJS) $(LIBDIRS) $(LIBS)

profile: $(ANSI2KNR) $(MP_ALL_OBJS)
	$(PURIFY) $(CC) -Bstatic -pg $(CFLAGS) -o $@ $(MP_ALL_OBJS) $(LIBDIRS) $(LIBS)

#########
# OTHER #
#########

#
# Perl is necessary if you want to modify the Huffman RLE encoding table.
#
PERL = perl

# The following stuff is for the Huffman encoding tables.  It's commented-out
# because you probably don't want to change this.  If you do, then uncommment
# it.
#
# huff.h: huff.c
#
# huff.c: parse_huff.pl huff.table
#	$(PERL) parse_huff.pl huff.table

headers.o: headers.c
	$(CC) $(CFLAGS) -c headers.c

depend: huff.c
	makedepend -- $(CFLAGS) -- $(MP_ALL_SRCS)

wc:;		wc -l *.[ch] headers/*.h *.pl *.table
ci:;		ci -l $(MP_ALL_SRCS) $(MP_INCLUDE) $(MP_MISC)
tags: $(MP_ALL_SRCS)
	ctags -t $(MP_ALL_SRCS)

new:
	rm -f *.o core *~ gmon.out
	make depend

clean:
	rm -f *.o core *~ gmon.out
	make depend
	make tags
	make all

#
# WARNING: this assumes you're using GNU indent...
#
indent:;	indent -T FILE -T int8 -T int16 -T int32 -T uint8 -T uint16 -T uint32  -T BitBucket -T MpegFrame -T Block -T FlatBlock $(MP_ALL_SRCS)

spotless: clean	
	rm -f huff.c huff.h *.pure.a
	cd pbmplus; make clean

##############################################################################
# DO NOT DELETE THIS LINE -- make depend depends on it.
