# Makefile for octave jpeg read/write scripts
# Copyright (C) 2000 Andy Adler.
# This code has no warranty whatsoever.
# You may do what you like with this code as long as you leave this copyright
# in place.  If you modify the code then include a notice saying so.
#
# INSTRUCTIONS:
#
# 1. Make sure you have the following files:
#    1) Makefile
#    2) ocjpglib.cc
#    3) jpegsrc.v6b.tar.gz
#       this is available from ftp://ftp.uu.net/graphics/jpeg/
#       and many other places
#
# 2. untar jpegsrc.v6b.tar.gz into the ./jpeg directory
#
# 3. type make (in the current directory)
#     (note, you do not need to make the jpeg sources, 
#        this Makefile will do that for you)
#
# TODO:
#
# 1. Get the writing of files to work
# 2. Fix the jpeg error handler to not break octave
#        
#
# This is modified from the 
# Makefile for Independent JPEG Group's software
# ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6.tar.gz
#
# $Id: Makefile,v 1.2 2000/06/08 04:22:37 andy Exp andy $

CC= gcc

CFLAGS= -O2
# Generally, we recommend defining any configuration symbols in jconfig.h,
# NOT via -D switches here.

LDFLAGS= 
LDLIBS= 


LN= $(CC)
RM= rm -f
MV= mv
AR= ar rc
# second step in .a creation (use "touch" if not needed)
AR2= ranlib

# End of configurable options.

OCTLNKS= imread.oct imwrite.oct
OCTSRC= octjpglib.cc
# source files: JPEG library proper
J= jpeg-6b

LIBSOURCES= $(J)/jcapimin.c $(J)/jcapistd.c $(J)/jccoefct.c $(J)/jccolor.c \
            $(J)/jcdctmgr.c $(J)/jchuff.c $(J)/jcinit.c $(J)/jcmainct.c \
            $(J)/jcmarker.c $(J)/jcmaster.c $(J)/jcomapi.c $(J)/jcparam.c \
            $(J)/jcphuff.c $(J)/jcprepct.c $(J)/jcsample.c $(J)/jctrans.c \
            $(J)/jdapimin.c $(J)/jdapistd.c $(J)/jdatadst.c $(J)/jdatasrc.c \
            $(J)/jdcoefct.c $(J)/jdcolor.c $(J)/jddctmgr.c $(J)/jdhuff.c \
            $(J)/jdinput.c $(J)/jdmainct.c $(J)/jdmarker.c $(J)/jdmaster.c \
            $(J)/jdmerge.c $(J)/jdphuff.c $(J)/jdpostct.c $(J)/jdsample.c \
            $(J)/jdtrans.c $(J)/jerror.c $(J)/jfdctflt.c $(J)/jfdctfst.c \
            $(J)/jfdctint.c $(J)/jidctflt.c $(J)/jidctfst.c $(J)/jidctint.c \
            $(J)/jidctred.c $(J)/jquant1.c $(J)/jquant2.c $(J)/jutils.c \
            $(J)/jmemmgr.c $(J)/rdcolmap.c $(J)/rdppm.c $(J)/wrppm.c  \
            $(J)/rdgif.c $(J)/wrgif.c \
            $(J)/rdbmp.c $(J)/wrbmp.c $(J)/jmemnobs.c

# files included by source files
INCLUDES=   $(J)/jchuff.h $(J)/jdhuff.h $(J)/jdct.h $(J)/jerror.h \
            $(J)/jinclude.h $(J)/jmemsys.h $(J)/jmorecfg.h $(J)/jpegint.h \
            $(J)/jpeglib.h $(J)/jversion.h $(J)/cdjpeg.h $(J)/cderror.h \
            $(J)/transupp.h $(J)/jconfig.h

LIBOBJECTS = $(patsubst %.c,%.o,$(LIBSOURCES))
 
all: $(OCTLNKS)

# build jconfig.h using the configure script from the jpeg lib
$(J)/jconfig.h: $(J)/configure
	echo $(LIBOBJECTS)
	( cd $(J); ./configure )

libjpeg.a: $(J)/jconfig.h $(LIBOBJECTS)
	$(RM) libjpeg.a
	$(AR) libjpeg.a  $(LIBOBJECTS)
	$(AR2) libjpeg.a

$(OCTLNKS): $(OCTSRC) libjpeg.a
	mkoctfile -I$(J) $(OCTSRC) -L. -ljpeg -o octjpglib.oct
	for l in $(OCTLNKS) ; do ln -sf octjpglib.oct $$l ; done

clean:
	-rm $(LIBOBJECTS)
	-rm $(OCTLNKS)
	-rm libjpeg.a octjpglib.o*