fukasawa e60969
# Sample makefile for rpng-x / rpng2-x / wpng using gcc and make.
fukasawa e60969
# Greg Roelofs
fukasawa e60969
# Last modified:  2 June 2007
fukasawa e60969
#
fukasawa e60969
#	The programs built by this makefile are described in the book,
fukasawa e60969
#	"PNG:  The Definitive Guide," by Greg Roelofs (O'Reilly and
fukasawa e60969
#	Associates, 1999).  Go buy a copy, eh?  Well, OK, it's not
fukasawa e60969
#	generally for sale anymore, but it's the thought that counts,
fukasawa e60969
#	right?  (Hint:  http://www.libpng.org/pub/png/book/ )
fukasawa e60969
#
fukasawa e60969
# Invoke this makefile from a shell prompt in the usual way; for example:
fukasawa e60969
#
fukasawa e60969
#	make -f Makefile.unx
fukasawa e60969
#
fukasawa e60969
# This makefile assumes libpng and zlib have already been built or downloaded
fukasawa e60969
# and are installed in /usr/local/{include,lib} or as otherwise indicated by
fukasawa e60969
# the PNG* and Z* macros below.  Edit as appropriate--choose only ONE each of
fukasawa e60969
# the PNGINC, PNGLIBd, PNGLIBs, ZINC, ZLIBd and ZLIBs lines.
fukasawa e60969
#
fukasawa e60969
# This makefile builds both dynamically and statically linked executables
fukasawa e60969
# (against libpng and zlib, that is), but that can be changed by modifying
fukasawa e60969
# the "EXES =" line.  (You need only one set, but for testing it can be handy
fukasawa e60969
# to have both.)
fukasawa e60969
fukasawa e60969
fukasawa e60969
# macros --------------------------------------------------------------------
fukasawa e60969
fukasawa e60969
#PNGDIR = /usr/local/lib
fukasawa e60969
#PNGINC = -I/usr/local/include/libpng16
fukasawa e60969
#PNGLIBd = -L$(PNGDIR) -lpng16 # dynamically linked, installed libpng
fukasawa e60969
#PNGLIBs = $(PNGDIR)/libpng16.a # statically linked, installed libpng
fukasawa e60969
# or:
fukasawa e60969
PNGDIR = ../..#	this one is for libpng-x.y.z/contrib/gregbook builds
fukasawa e60969
#PNGDIR = ../libpng
fukasawa e60969
PNGINC = -I$(PNGDIR)
fukasawa e60969
PNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng16	# dynamically linked
fukasawa e60969
PNGLIBs = $(PNGDIR)/libpng.a		# statically linked, local libpng
fukasawa e60969
fukasawa e60969
ZDIR = /usr/local/lib
fukasawa e60969
#ZDIR = /usr/lib64
fukasawa e60969
ZINC = -I/usr/local/include
fukasawa e60969
ZLIBd = -L$(ZDIR) -lz			# dynamically linked against zlib
fukasawa e60969
ZLIBs = $(ZDIR)/libz.a			# statically linked against zlib
fukasawa e60969
# or:
fukasawa e60969
#ZDIR = ../zlib
fukasawa e60969
#ZINC = -I$(ZDIR)
fukasawa e60969
#ZLIBd = -Wl,-rpath,$(ZDIR) -L$(ZDIR) -lz  # -rpath allows in-place testing
fukasawa e60969
#ZLIBs = $(ZDIR)/libz.a
fukasawa e60969
fukasawa e60969
#XINC = -I/usr/include			# old-style, stock X distributions
fukasawa e60969
#XLIB = -L/usr/lib/X11 -lX11		#  (including SGI IRIX)
fukasawa e60969
#XINC = -I/usr/openwin/include		# Sun workstations (OpenWindows)
fukasawa e60969
#XLIB = -L/usr/openwin/lib -lX11
fukasawa e60969
XINC = -I/usr/X11R6/include		# new X distributions (X.org, etc.)
fukasawa e60969
XLIB = -L/usr/X11R6/lib -lX11
fukasawa e60969
#XLIB = -L/usr/X11R6/lib64 -lX11	# e.g., Red Hat on AMD64
fukasawa e60969
fukasawa e60969
INCS = $(PNGINC) $(ZINC) $(XINC)
fukasawa e60969
RLIBSd = $(PNGLIBd) $(ZLIBd) $(XLIB) -lm
fukasawa e60969
RLIBSs = $(PNGLIBs) $(ZLIBs) $(XLIB) -lm
fukasawa e60969
WLIBSd = $(PNGLIBd) $(ZLIBd) -lm
fukasawa e60969
WLIBSs = $(PNGLIBs) $(ZLIBs) -lm
fukasawa e60969
fukasawa e60969
CC = gcc
fukasawa e60969
LD = gcc
fukasawa e60969
RM = rm -f
fukasawa e60969
CPPFLAGS = $(INCS) -DFEATURE_LOOP
fukasawa e60969
CFLAGS = -O -Wall
fukasawa e60969
#CFLAGS = -O -W -Wall -Wextra -pedantic -ansi
fukasawa e60969
# [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
fukasawa e60969
# [-ansi, -pedantic, -Wextra, and -W can also be used]
fukasawa e60969
LDFLAGS =
fukasawa e60969
O = .o
fukasawa e60969
E =
fukasawa e60969
fukasawa e60969
RPNG   = rpng-x
fukasawa e60969
RPNG2  = rpng2-x
fukasawa e60969
WPNG   = wpng
fukasawa e60969
fukasawa e60969
RPNGs  = $(RPNG)-static
fukasawa e60969
RPNG2s = $(RPNG2)-static
fukasawa e60969
WPNGs  = $(WPNG)-static
fukasawa e60969
fukasawa e60969
ROBJS  = $(RPNG)$(O) readpng$(O)
fukasawa e60969
ROBJS2 = $(RPNG2)$(O) readpng2$(O)
fukasawa e60969
WOBJS  = $(WPNG)$(O) writepng$(O)
fukasawa e60969
fukasawa e60969
STATIC_EXES  = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E)
fukasawa e60969
DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
fukasawa e60969
fukasawa e60969
EXES = $(STATIC_EXES) $(DYNAMIC_EXES)
fukasawa e60969
fukasawa e60969
fukasawa e60969
# implicit make rules -------------------------------------------------------
fukasawa e60969
fukasawa e60969
.c$(O):
fukasawa e60969
	$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
fukasawa e60969
fukasawa e60969
fukasawa e60969
# dependencies --------------------------------------------------------------
fukasawa e60969
fukasawa e60969
all:  $(EXES)
fukasawa e60969
fukasawa e60969
$(RPNGs)$(E): $(ROBJS)
fukasawa e60969
	$(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSs)
fukasawa e60969
fukasawa e60969
$(RPNG)$(E): $(ROBJS)
fukasawa e60969
	$(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSd)
fukasawa e60969
fukasawa e60969
$(RPNG2s)$(E): $(ROBJS2)
fukasawa e60969
	$(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSs)
fukasawa e60969
fukasawa e60969
$(RPNG2)$(E): $(ROBJS2)
fukasawa e60969
	$(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSd)
fukasawa e60969
fukasawa e60969
$(WPNGs)$(E): $(WOBJS)
fukasawa e60969
	$(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSs)
fukasawa e60969
fukasawa e60969
$(WPNG)$(E): $(WOBJS)
fukasawa e60969
	$(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSd)
fukasawa e60969
fukasawa e60969
$(RPNG)$(O):	$(RPNG).c readpng.h
fukasawa e60969
$(RPNG2)$(O):	$(RPNG2).c readpng2.h
fukasawa e60969
$(WPNG)$(O):	$(WPNG).c writepng.h
fukasawa e60969
fukasawa e60969
readpng$(O):	readpng.c readpng.h
fukasawa e60969
readpng2$(O):	readpng2.c readpng2.h
fukasawa e60969
writepng$(O):	writepng.c writepng.h
fukasawa e60969
fukasawa e60969
fukasawa e60969
# maintenance ---------------------------------------------------------------
fukasawa e60969
fukasawa e60969
clean:
fukasawa e60969
	$(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)