#########################################################
# File:         rtppack		                        #
#							#
# Author:	Markus Sebeck				#
#							#
# Date: 	27.07.1998				#
#							#
#########################################################

#################################################################
#								#
# site-specific variables 					#
#								#
#################################################################
# used syntax for directories:
# ...INCDIR	= include-directory
# ...LIBDIR	= library-directory
#

# personal directories ##########################################

TOP		= ../../..#

# machine specific ##############################################

include $(TOP)/Machine.mk

# program specific ##############################################

NAME		= rtppack
LIBNAME		= lib$(NAME).a
BINNAME		= rtppack#			# name of the runable program
ARCHIVENAME	= Pack#				# name of the archive file of the sources
BININSTALLDIR	= $(TOP)/bin/$(ARCH)#	       	# directory where the program is to be installed
LIBINSTALLDIR	= $(TOP)/lib/$(ARCH)#	       	# directory where the library is to be installed

# project directories ###########################################
RTPINCDIR	 = $(TOP)/include/rtp#
NTCODECINCDIR1   = $(TOP)/include/pyra/decoder#
NTCODECINCDIR2   = $(TOP)/include/pyra#

# system directories ############################################

OPENWINLIBDIR	= /usr/openwin/lib#
OPENWINIDIR	= /usr/openwin/include#				# #include <???>

# used files ####################################################
# !: to make the library, rsvp_sim.o has to be removed from OBJECTS

HEADERS = 	\
		sendpacket.h   \
		pyrapack.h   \
		h263rtp.h    \
		rtppack.h    \
		layer_ref.h \
		main.h 

SOURCES =  	\
		sendpacket.c   \
		pyrapack.c   \
		h263rtp.c    \
		rtppack.c    \
		layer_ref.c \
		main.c 

OBJECTS = 	\
		sendpacket.o   \
		pyrapack.o   \
		h263rtp.o    \
		rtppack.o    \
		layer_ref.o

TARFILES = Makefile README $(HEADERS) $(SOURCES)

# stuff needed for compiling ####################################

INCLUDE = -I$(NTCODECINCDIR1) -I$(NTCODECINCDIR2) -I$(RTPINCDIR) $(INCDIR)#
LIBDIRS	= $(LIBDIR)#
LIBS		= -lpyradecoder -lCodebooks -lHuffDecode \
		-lh263decoder -lcommon -lbitIn -lfilter \
		-ljittr -lm# $(NETLIBS) 

LFLAGS	= $(LIBDIRS) $(LIBS)#			# link flags
ifeq ($(ARCH),irix.irix5)
	DFLAGS	= #-g -D_DEBUG_#	#-g	# debug flags
else
	DFLAGS	= ## -ggdb -DDEBUG#	#-g	# debug flags
endif
DEPENDF	= -M #-m#				# dependency flags


#A2PSF	= -nP -2


# make, compile, archive ###############################

CC 	= gcc
CXX	= g++
ifeq ($(ARCH),irix.irix5)
	MAKE = gmake
else
	MAKE = make
endif
MAKED	= makedepend
TAR	= tar#		# to archive all
AR	= ar#		# to create library
#PRINT	= lpr
#A2PS	= a2ps


#########################################################
#########################################################
#							#
# It should not be neccessary to edit the following 	#
# lines!						#
########e################################################

.PHONY: help all clean allclean depend lib install docu tar extract libmip

# some help #############################################

help:
	@echo "\n\nUsage:\tmake <target>"
	@echo "\tPossible targets are:"
	@echo "\t\thelp\t - print this message"
	@echo "\t\tdepend\t - make dependencies"
	@echo "\t\tall\t - compile \`$(BINNAME)\` and \`$(LIBNAME)"\'
	@echo "\t\tproto\t - make prototype file"
	@echo "\t\tclean\t - clean up directory"
	@echo "\t\tallclean - clean up directory and remove programm-file"
	@echo "\t\tcomplete - clean up directory, make dependencies \n\t\t\t   and compile \`$(BINNAME)"
	@echo "\t\tinstall\t - install \`$(BINNAME)\` and \`$(LIBNAME)"\'
	@echo "\t\tdocu\t - create ps-files of headers and sources"
	@echo "\t\ttar\t - create archive of all"
	@echo "\t\ttarnew\t - create new archive of all"
	@echo "\t\textract\t - extract archive of all"
	@echo "\t\tlib\t - create library of object files"
	@echo "\n"


# generate and delete files ##############################

all:
	@echo "\nTARGET all:  ..."
	@$(MAKE) $(LIBNAME)
	@$(MAKE) $(BINNAME)
	@echo "TARGET all:  done.\n"

clean:
	@echo "\nTARGET clean: ...\c"
	@$(RM) *.o *~ *.bak core a.out
	@echo " done.\n"

allclean: 
	@echo "\nTARGET allclean: ..."
	@$(MAKE) clean
	@$(RM) $(LIBNAME) $(BINNAME)
	@echo "TARGET allclean:   done.\n"

$(BINNAME): $(OBJECTS) main.o
	@echo "\n"RULE $(BINNAME) ..."\n"
	$(CC) $(OPTFLAGS) $(LIBDIRS) main.o $(OBJECTS) -o $(BINNAME) $(LIBS)
	@echo RULE $(BINNAME): "  done.\n"

$(LIBNAME): $(OBJECTS)
	@echo "\n"RULE $(LIBNAME) ..."\n"
	@$(RM) $@
	ar cr $@ $(OBJECTS)
	$(RANLIB) $@
	@echo RULE $(LIBNAME): "  done.\n"

proto:
	$(CPROTO) -e -v $(INCLUDE) $(CFLAGS) $(SRCS) > tmp.p
	mv tmp.p $(TOP)/include/$(NAME).p

%.o: %.c %.h
	@echo "\n"RULE $@ ...
	$(CC) $(OPTFLAGS) $(CFLAGS) $(INCLUDE) $(DFLAGS) $< -c -o $@	
	@echo " done.\n"

##	$(CC) $(OPTFLAGS) $(CFLAGS) $(INCLUDE) $(DFLAGS) -I$(g++LIB) $< -c -o $@	

%.o: %.c
	@echo "\n"RULE $@ ...
	$(CC) $(OPTFLAGS) $(CFLAGS) $(INCLUDE) $(DFLAGS) $< -c -o $@	
	@echo " done.\n"

#$(OBJECTS): Machine.mk Makefile

#main.o:	Machine.mk Makefile main.c

complete:
	@$(MAKE) clean
	@$(MAKE) depend
	@$(MAKE) all

# create dependencies ####################################

depend:
	makedepend $(INCLUDE) $(SOURCES)



# create archive for libraries ###########################

#lib:
#	$(MAKE) lib$(ARCHIVENAME).a

#lib$(ARCHIVENAME).a : lib$(ARCHIVENAME).a($(LIBOBJS))

# uses implicit rule with $(AR)

# useful stuff ###########################################

install: $(BINNAME) $(LIBNAME)
	@echo "\n"installing $(BINNAME) in $(BININSTALLDIR) ..."\c"
	@cp $(BINNAME) $(BININSTALLDIR)/
	@echo "\n"installing $(LIBNAME) in $(LIBINSTALLDIR) ..."\c"
	@cp $(LIBNAME) $(LIBINSTALLDIR)/
	@echo " done.\n"
#	@$(MAKE) all
# 	@chmod ugo+x $(INSTALLDIR)/$(BINNAME)

#docu: $(HEADERS) $(SOURCES) Makefile
#	@$(A2PS) $(A2PSF) $(HEADERS) > headers.ps
#	@$(A2PS) $(A2PSF) $(SOURCES) > sources.ps
#	@$(A2PS) $(A2PSF) Makefile > makefile.ps

tarnew: $(TARFILES)
	@$(TAR) -cvf $(ARCHIVENAME).tar $(TARFILES)

#	@$(TAR) -cvf $(ARCHIVENAME).tar $(HEADERS) $(SOURCES) $(FILES)


tar: $(TARFILES)
	@$(TAR) -uvf $(ARCHIVENAME).tar $(TARFILES)

#	@$(TAR) -uvf $(ARCHIVENAME).tar $(HEADERS) $(SOURCES) $(FILES)


extract:
	@$(TAR) -xvf $(ARCHIVENAME).tar

# checkin:
#	@set -e; for i in $(RCSFILES) do; 
 

$(BINNAME): $(TOP)/lib/$(ARCH)/libCodebooks.a
$(BINNAME): $(TOP)/lib/$(ARCH)/libHuffDecode.a
$(BINNAME): $(TOP)/lib/$(ARCH)/libh263decoder.a
$(BINNAME): $(TOP)/lib/$(ARCH)/libpyradecoder.a
$(BINNAME): $(TOP)/lib/$(ARCH)/libcommon.a
$(BINNAME): $(TOP)/lib/$(ARCH)/libbitIn.a
$(BINNAME): $(TOP)/lib/$(ARCH)/libfilter.a
$(BINNAME): $(TOP)/lib/$(ARCH)/libdisplay.a

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