# makefile for libpng
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
# For conditions of distribution and use, see copyright notice in png.h

PREFIX?= /usr/local
LIBDIR=	${PREFIX}/lib
MANDIR= ${PREFIX}/man/cat

SHLIB_MAJOR=	0
SHLIB_MINOR=	1.2.7

LIB=	png
SRCS=	png.c pngerror.c pnggccrd.c pngget.c pngmem.c pngpread.c \
	pngread.c pngrio.c pngrtran.c pngrutil.c pngset.c pngtrans.c \
	pngwio.c pngwrite.c pngwtran.c pngwutil.c

HDRS=	png.h pngconf.h

CFLAGS+= -Wall
CPPFLAGS+= -I${.CURDIR} -DPNG_NO_ASSEMBLER_CODE -DPNG_USE_PNGGCCRD

NOPROFILE= Yes

CLEANFILES+= pngtest.o pngtest

MAN=	libpng.3 libpngpf.3 png.5
DOCS=	ANNOUNCE CHANGES LICENSE README libpng.txt

pngtest.o:	pngtest.c
	${CC} ${CPPFLAGS} ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET}

pngtest:	pngtest.o
	${CC} ${LDFLAGS} ${.ALLSRC} -o ${.TARGET} -L${.OBJDIR} -lpng -lz -lm

test:	pngtest
	cd ${.OBJDIR} && env \
		LD_LIBRARY_PATH="${.OBJDIR}" ${.OBJDIR}/pngtest

beforeinstall:
	if [ ! -d ${DESTDIR}${PREFIX}/include/libpng ]; then \
	  ${INSTALL} -d -o root -g wheel ${DESTDIR}${PREFIX}/include/libpng; \
	fi
	if [ ! -d ${DESTDIR}${LIBDIR} ]; then \
	  ${INSTALL} -d -o root -g wheel ${DESTDIR}${LIBDIR}; \
	fi
	if [ ! -d ${DESTDIR}${LIBDIR}/debug ]; then \
	  ${INSTALL} -d -o root -g wheel ${DESTDIR}${LIBDIR}/debug; \
	fi
	if [ ! -d ${DESTDIR}${MANDIR}3 ]; then \
	  ${INSTALL} -d -o root -g wheel ${DESTDIR}${MANDIR}3; \
	fi
	if [ ! -d ${DESTDIR}${MANDIR}5 ]; then \
	  ${INSTALL} -d -o root -g wheel ${DESTDIR}${MANDIR}5; \
	fi
	if [ ! -d ${DESTDIR}${PREFIX}/share/doc/png ]; then \
	  ${INSTALL} -d -o root -g wheel ${DESTDIR}${PREFIX}/share/doc/png; \
	fi

afterinstall:
	@rm -f ${DESTDIR}${LIBDIR}/libpng_pic.a
	@rm -f ${DESTDIR}${LIBDIR}/debug/libpng.a
	@rm -f ${DESTDIR}${PREFIX}/include/png.h
	@rm -f ${DESTDIR}${PREFIX}/include/pngconf.h
	@rmdir ${DESTDIR}${LIBDIR}/debug 2>/dev/null || true
	${INSTALL} ${INSTALL_COPY} -o ${SHAREOWN} -g ${SHAREGRP} \
		-m ${NONBINMODE} ${HDRS} ${DESTDIR}${PREFIX}/include/libpng
	${INSTALL} ${INSTALL_COPY} -o ${SHAREOWN} -g ${SHAREGRP} \
		-m ${NONBINMODE} ${HDRS} ${DESTDIR}${PREFIX}/include
	${INSTALL} ${INSTALL_COPY} -o ${SHAREOWN} -g ${SHAREGRP} \
		-m ${NONBINMODE} ${DOCS} ${DESTDIR}${PREFIX}/share/doc/png

.include <bsd.lib.mk>
