##################################
#                                #
#     Libjpeg v1.03 Makefile     #
#     by Eric Vannier            #
#                                #
#                                #
##################################

VERSION= 1.03

# replace this definition if you are using PGCC!
#PGCC = true

CC = gcc
AR = ar


LIB = libjpeg.a
INC = jpeg.h

SRCDIR =./src
OBJDIR =./obj
LIBDEST = $(DJDIR)/lib/$(LIB)
INCDEST = $(DJDIR)/include/$(INC)


CPLIBDEST = $(subst /,\,$(LIBDEST))
CPINCDEST = $(subst /,\,$(INCDEST))



CP = copy
RM = del

ifdef PGCC
OPTFLAGS = -mpentium -O6 -ffast-math -fomit-frame-pointer
else
OPTFLAGS = -m486 -O3 -ffast-math -fomit-frame-pointer
endif

INCFLAGS = -I.
WFLAGS = -Wall -W -Wno-unused

CFLAGS = $(INCFLAGS) $(WFLAGS) $(OPTFLAGS)

CLIBFILES= jcapimin jcapistd jctrans jcparam jdatadst jcinit \
        jcmaster jcmarker jcmainct jcprepct jccoefct jccolor \
        jcsample jchuff jcphuff jcdctmgr jfdctfst jfdctflt \
        jfdctint jpegc
DLIBFILES= jdapimin jdapistd jdtrans jdatasrc jdmaster \
        jdinput jdmarker jdhuff jdphuff jdmainct jdcoefct \
        jdpostct jddctmgr jidctfst jidctflt jidctint jidctred \
        jdsample jdcolor jquant1 jquant2 jdmerge jpegd

COMFILES= jcomapi jutils jerror jmemmgr jmemnobs

CLIBOBJECTS = $(addsuffix .o,$(CLIBFILES))
DLIBOBJECTS = $(addsuffix .o,$(DLIBFILES))
COMOBJECTS  = $(addsuffix .o,$(COMFILES))

CLIBSRC = $(addsuffix .c,$(CLIBFILES))
DLIBSRC = $(addsuffix .c,$(DLIBFILES))
COMSRC  = $(addsuffix .c,$(COMFILES))

OBJ = $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS) 
R_OBJ = $(addprefix $(OBJDIR)/, $(OBJ))

SRC = $(addprefix ..\, $(OBJ))

all : msg $(LIB) install
	@echo All done.
	@echo To use jpeg, include jpeg.h and allegro.h
	@echo and link with liballeg.a and libjpeg.a
	@echo Example command line: gcc foo.c -o foo.exe -ljpeg -lalleg 
	
	@echo for any problems, do not hesitate to contact me
	@echo Have a look at readme.1st
	@echo Have fun !
msg :
	@echo Compiling the version $(VERSION) of libjpeg. Please wait...


# Dependancy removed since it is already compiled, and the sources are provided
$(LIB) : $(R_OBJ)
	$(AR) rs $@ $(R_OBJ)	
	
$(OBJDIR)/%.o : $(SRCDIR)/%.c
	$(CC) -c $(CFLAGS) -o $@ $< 

install : $(LIBDEST) $(INCDEST) 

$(LIBDEST) : $(LIB)
	$(CP) $(LIB) $(CPLIBDEST)

$(INCDEST) : $(INC)
	$(CP) $(INC) $(CPINCDEST)

test : sample.exe

sample.exe : sample.o libjpeg.a
	$(CC)  -s -o $@ sample.o libjpeg.a -lalleg

sample.o : sample.c ./jpeg.h
	$(CC) -c -o $@ $(CFLAGS) sample.c

clean :
	$(RM) $(subst /,\,$(OBJDIR))\*.o
	$(RM) $(LIB)
