# Main makefile for the mpeg_edit programme.
#
#  Copyright (C) 1995 Alexis Ashley
# 
#  email:	milamber@ripley.demon.co.uk
#
#  mail:	Mr A S Ashley, 61/63 Underwood Road, Plympton, Plymouth,
#		Devon, PL7 3SZ, ENGLAND
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#                       Mr A S R Ashley B.Eng (Hons)    23rd July 1995

      CC = gcc      
     CPP = g++
      RM = rm -f

DEPFILE  = Dependancies
 SUBDIRS = ui MpegCodec editor xuseless
HEADERS  = 
SOURCES  = main.C globals/version.c
OBJS     = main.o globals/version.o
ARCHIVES = editor/editor.a ui/ui.a MpegCodec/mpeg.a
    LIBS = -lXext -lX11 -lpnm -lppm -lpbm -lpgm -lm
#
#  CPPFLAGS     -Wall     all warnings
#               -pipe     speeds up compilation (remove only if not using g++)
#               -O4       makes g++ optimise the code
#               -DDEBUG   some debugging info on stdout
#               -DDEBUG2  (-DDEBUG needed as well) extra debug info
#
#  CFLAGS       -Wall     all warnings
#               -pipe     speeds up compilation (remove only if not using g++)
#               -O4       makes gcc optimise the code
#
#  SHMEM        -DSH_MEM  enables shared memory
#
#  CACHE_FLAGS
#               -DCACHE_SIZE  sets size of frame cache (in units of 1K)
#               -DCACHE_GRANULARITY  sets how many frames to kill from cache
#                                    when space is needed in the cache
#
# PBMDIR         The location of the pbmplus header files, which is
#                /usr/include/gr on my Linux machine.

PBMDIR      = /usr/include/X11R5/X11
INCLUDES    = -Iglobals -Iui -IMpegCodec -IMpegCodec/decoder \
	      -IMpegCodec/encoder -Ieditor 
CPPFLAGS    = -Wall -pipe -O4
CFLAGS      = -Wall -pipe -O4
SHMEM	    = -DSH_MEM
CACHE_FLAGS = -DCACHE_SIZE=12288 -DCACHE_GRANULARITY=5

.SUFFIXES:	.C $(SUFFIXES) 

.C.o:	
	$(CPP) $(CPPFLAGS) $(INCLUDES) $(EXTRA) -c $< 

all: mpeg_edit

ui.a:
	cd ui && make ui.a EXTRA="$(EXTRA)" CPPFLAGS="$(CPPFLAGS)" \
	CFLAGS="$(CFLAGS)" && cd ..
	
mpeg.a:
	cd MpegCodec && make mpeg.a EXTRA="$(EXTRA)" CPPFLAGS="$(CPPFLAGS)" \
	CFLAGS="$(CFLAGS)" CACHE_FLAGS="$(CACHE_FLAGS)" && cd ..
	
editor.a:
	cd editor && make editor.a EXTRA="$(EXTRA)" CPPFLAGS="$(CPPFLAGS)" \
	CFLAGS="$(CFLAGS)" SHMEM="$(SHMEM)" PBMDIR="$(PBMDIR)" && cd ..
	
mpeg_edit: ui.a mpeg.a editor.a $(DEPFILE) $(OBJS)  
	$(CPP) -o mpeg_edit $(OBJS) $(ARCHIVES) $(LIBS)

ppmtorle: mpeg.a editor.a $(DEPFILE) ppmtorle.o
	$(CPP) -o ppmtorle ppmtorle.o MpegCodec/frame.o editor/yuv.o $(LIBS) 

globals/version.o:	$(ARCHIVES) 
	$(CC) $(CFLAGS) $(EXTRA) -c globals/version.c -o globals/version.o

clean:
	$(RM) mpeg_edit main.o globals/version.o
	set -e; for i in $(SUBDIRS); do cd $$i && make clean && cd .. ; done

dep:	FORCE
	set -e; for i in $(SUBDIRS) ; do cd $$i && make dep EXTRA="$(EXTRA)" \
	CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" SHMEM="$(SHMEM)" \
	PBMDIR="$(PBMDIR)" && cd .. ; done
	$(RM) $(DEPFILE) 	
	make $(DEPFILE)

FORCE:


$(DEPFILE):
	set -e; for i in $(SOURCES) ; do $(CPP) $(INCLUDES) -M $$i >>$(DEPFILE) ; done
	
#
# include a dependency file if one exists
#
#ifeq ($(DEPFILE),$(wildcard $(DEPFILE)))
include $(DEPFILE)
#endif
