# Sample makefile for rpng-x / rpng2-x / wpng using gcc and make.
# Greg Roelofs
# Last modified:  16 February 1999
#
#	The programs built by this makefile are described in the book,
#	"PNG:  The Definitive Guide," by Greg Roelofs (O'Reilly and
#	Associates, 1999).  Go buy a copy, eh?  Buy some for friends
#	and family, too.  (Not that this is a blatant plug or anything.)
#
# Invoke this makefile from a shell prompt in the usual way; for example:
#
#	make -f makefile.unx
#
# This makefile assumes libpng and zlib have already been built or downloaded
# and are both installed in /usr/local/{include,lib} (as indicated by the
# PNGPATH and ZPATH macros below).  Edit as appropriate.
#
# This makefile builds statically linked executables (against libpng and zlib,
# that is), but that can be changed by uncommenting the appropriate PNGLIB and
# ZLIB lines.


# macros --------------------------------------------------------------------

PNGPATH = /usr/local
PNGINC = -I$(PNGPATH)/include
#PNGLIB = -L$(PNGPATH)/lib -lpng
PNGLIB = $(PNGPATH)/lib/libpng.a

ZPATH = /usr/local
ZINC = -I$(ZPATH)/include
#ZLIB = -L$(ZPATH)/lib -lz
ZLIB = $(ZPATH)/lib/libz.a

#XPATH = /usr/X11
XPATH = /usr/X11R6
XINC = -I$(XPATH)/include
XLIB = -L$(XPATH)/lib -lX11

INCS = $(PNGINC) $(ZINC) $(XINC)
RLIBS = $(PNGLIB) $(ZLIB) $(XLIB) -lm
WLIBS = $(PNGLIB) $(ZLIB) -lm

CC = gcc
LD = gcc
RM = rm -f
CFLAGS = -O -Wall $(INCS)
# [note that -Wall is a gcc-specific compilation flag ("all warnings on")]
LDFLAGS =
O = .o
E =

RPNG  = rpng-x
RPNG2 = rpng2-x
WPNG  = wpng

ROBJS  = $(RPNG)$(O) readpng$(O)
ROBJS2 = $(RPNG2)$(O) readpng2$(O)
WOBJS  = $(WPNG)$(O) writepng$(O)

EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)


# implicit make rules -------------------------------------------------------

.c$(O):
	$(CC) -c $(CFLAGS) $<


# dependencies --------------------------------------------------------------

all:  $(EXES)

$(RPNG)$(E): $(ROBJS)
	$(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBS)

$(RPNG2)$(E): $(ROBJS2)
	$(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBS)

$(WPNG)$(E): $(WOBJS)
	$(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBS)

$(RPNG)$(O):	$(RPNG).c readpng.h
$(RPNG2)$(O):	$(RPNG2).c readpng2.h
$(WPNG)$(O):	$(WPNG).c writepng.h

readpng$(O):	readpng.c readpng.h
readpng2$(O):	readpng2.c readpng2.h
writepng$(O):	writepng.c writepng.h


# maintenance ---------------------------------------------------------------

clean:
	$(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)
