.PHONY: all test check clean distclean
.PRECIOUS: Makefile
.SUFFIXES: .c .o .a

CC = @CC@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
LD = @LD@
LDFLAGS = @LDFLAGS@
AR = @AR@
ARFLAGS = @ARFLAGS@
RANLIB = @RANLIB@
RM_F = @RM_F@

@USE_SYSTEM_ZLIB_FALSE@ZDIR = ../zlib
@USE_SYSTEM_LIBPNG_FALSE@PNGDIR = ../libpng

OPNGREDUC_LIB = libopngreduc.a

OPNGREDUC_OBJS = opngreduc.o

@USE_SYSTEM_ZLIB_FALSE@OPNGREDUC_DEPINCLUDE_ZLIB = -I$(ZDIR)
@USE_SYSTEM_ZLIB_TRUE@OPNGREDUC_DEPINCLUDE_ZLIB =
@USE_SYSTEM_LIBPNG_FALSE@OPNGREDUC_DEPINCLUDE_LIBPNG = -I$(PNGDIR)
@USE_SYSTEM_LIBPNG_TRUE@OPNGREDUC_DEPINCLUDE_LIBPNG =
OPNGREDUC_DEPINCLUDES = \
  $(OPNGREDUC_DEPINCLUDE_ZLIB) \
  $(OPNGREDUC_DEPINCLUDE_LIBPNG)

all: $(OPNGREDUC_LIB)

test:

check: test

.c.o:
	$(CC) -c $(CPPFLAGS) $(CFLAGS) $(OPNGREDUC_DEPINCLUDES) -o $@ $<

$(OPNGREDUC_LIB): $(OPNGREDUC_OBJS)
	$(AR) $(ARFLAGS) $@ $(OPNGREDUC_OBJS)
	$(RANLIB) $@

opngreduc.o: opngreduc.c opngreduc.h

clean:
	-$(RM_F) $(OPNGREDUC_LIB) $(OPNGREDUC_OBJS)

distclean: clean
	-$(RM_F) Makefile
