MACH = $(shell ascmach)

PROGNAME = mpeg_play
EXENAME  = $(BINDIR)/$(PROGNAME)
INCLUDES = -I/usr/include/X11
OBJS     = util.o video.o parseblock.o motionvector.o decoders.o \
           fs2.o fs2fast.o fs4.o hybrid.o hybriderr.o 2x2.o \
		   floatdct.o gdith.o gray.o mono.o main.o jrevdct.o \
		   16bit.o util32.o ordered.o ordered2.o mb_ordered.o \
		   readfile.o ctrlbar.o

#
# Directories
#
BINDIR = ../bin/$(MACH)
OBJDIR = $(MACH)

#
# Tools
#
CC    = gcc-2.8.1
LD    = $(CC)
MKDIR = mkdir -p
RM    = rm -f

#
# Flags
#
#	Set CFLAGS.  Below are def's for some machines.  Uncomment the
#	appropriate one or make one of your own. If you want the player
#       to gather statistics about the video stream, add -DANALYSIS to
#       CFLAGS. If you do NOT want to use shared memory, remove
#       -DSH_MEM from CFLAGS.
#       Use -DSIG_ONE_PARAM if the function passed to signal takes
#         one parameter (linux, Solaris)
#         Do not use it if it takes none (SunOS, HPUX, Ultrix, OSF1, )
#         It works either way, (i think), just gets rid of a warning.
#       Use -NDEBUG for speed, -DDEBUG for resiliance.  On invalid MPEG
#         streams a DEBUG compiled mpeg_play will exit gracefully, while
#         a NDEBUG one will dump core.  But NDEBUG is faster.
#       Use -DQUIET to have mpeg_play print little by default (useful for
#         when it is called by another program like netscape).
#       Use -DQUALITY if you want the default to play streams that conform
#         strictly to the MPEG standard but take longer to display by defualt.
#         It is also available as -quality on at runtime
#       Use -DFLOATDCT to enable using the computationally expensive but
#         accurate floating point DCT through the -quality parameter.
#       Use -DDEFAULT_ORDERED_DITHER to use ORDERED_DITHER instead of
#         ORDERED2_DITHER.  On some machines (e.g., Intel Pentiums),
#         ORDERED_DITHER is much faster than ORDERED2_DITHER.
#       Use -DNOCONTROLS to totally disable the X user interface.  See
#         also HDRS, OBJS, and SRCS below.
CFLAGS    = -O -DQUIET -DNDEBUG
CPPFLAGS  = $(INCLUDES)
LDFLAGS   =
LIBS      =
SYSLIBS   = -lX11 -lm

###############################################################################
CC_IRIX_6.5           = cc
CFLAGS_IRIX_6.5       = -O -o32 -DQUIET -DNDEBUG
LDFLAGS_IRIX_6.5      = -o32

CC_Linux_2.2.5-15smp      = cc
LDFLAGS_Linux_2.2.5-15smp = -L/usr/X11R6/lib -static
###############################################################################

#
# Override
#
ifneq ($(CC_$(MACH)),)
  CC = $(CC_$(MACH))
endif
ifneq ($(CFLAGS_$(MACH)),)
  CFLAGS = $(CFLAGS_$(MACH))
endif
ifneq ($(LDFLAGS_$(MACH)),)
  LDFLAGS = $(LDFLAGS_$(MACH))
endif
ifneq ($(SYSLIBS_$(MACH)),)
  SYSLIBS = $(SYSLIBS_$(MACH))
endif

###############################################################################
# how to create objects from source files
$(OBJDIR)/%.o: %.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
###############################################################################

.PHONY: all title mkdir clean
.SILENT:

all: title mkdir $(EXENAME)

title:
	echo `uname -n` $(MACH)

mkdir:
	if [ ! -d $(BINDIR) ]; then $(MKDIR) $(BINDIR); fi
	if [ ! -d $(OBJDIR) ]; then $(MKDIR) $(OBJDIR); fi

clean:
	$(RM) $(addprefix $(OBJDIR)/,$(OBJS))
	$(RM) $(EXENAME)

$(EXENAME): $(addprefix $(OBJDIR)/,$(OBJS))
	$(LD) $(LDFLAGS) -o $@ $^ $(LIBS) $(SYSLIBS)
	echo "    Made $(EXENAME)"
