1# Sample makefile for rpng-x / rpng2-x / wpng using gcc and make. 2# Greg Roelofs 3# Last modified: 2 June 2007 4# 5# The programs built by this makefile are described in the book, 6# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and 7# Associates, 1999). Go buy a copy, eh? Well, OK, it's not 8# generally for sale anymore, but it's the thought that counts, 9# right? (Hint: http://www.libpng.org/pub/png/book/ ) 10# 11# Invoke this makefile from a shell prompt in the usual way; for example: 12# 13# make -f Makefile.unx 14# 15# This makefile assumes libpng and zlib have already been built or downloaded 16# and are installed in /usr/local/{include,lib} or as otherwise indicated by 17# the PNG* and Z* macros below. Edit as appropriate--choose only ONE each of 18# the PNGINC, PNGLIBd, PNGLIBs, ZINC, ZLIBd and ZLIBs lines. 19# 20# This makefile builds both dynamically and statically linked executables 21# (against libpng and zlib, that is), but that can be changed by modifying 22# the "EXES =" line. (You need only one set, but for testing it can be handy 23# to have both.) 24 25 26# macros -------------------------------------------------------------------- 27 28#PNGDIR = /usr/local/lib 29#PNGINC = -I/usr/local/include/libpng12 30#PNGLIBd = -L$(PNGDIR) -lpng12 # dynamically linked, installed libpng 31#PNGLIBs = $(PNGDIR)/libpng12.a # statically linked, installed libpng 32# or: 33PNGDIR = ../..# this one is for libpng-x.y.z/contrib/gregbook builds 34#PNGDIR = ../libpng 35PNGINC = -I$(PNGDIR) 36PNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng12 # dynamically linked 37PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng 38 39ZDIR = /usr/local/lib 40#ZDIR = /usr/lib64 41ZINC = -I/usr/local/include 42ZLIBd = -L$(ZDIR) -lz # dynamically linked against zlib 43ZLIBs = $(ZDIR)/libz.a # statically linked against zlib 44# or: 45#ZDIR = ../zlib 46#ZINC = -I$(ZDIR) 47#ZLIBd = -Wl,-rpath,$(ZDIR) -L$(ZDIR) -lz # -rpath allows in-place testing 48#ZLIBs = $(ZDIR)/libz.a 49 50#XINC = -I/usr/include # old-style, stock X distributions 51#XLIB = -L/usr/lib/X11 -lX11 # (including SGI IRIX) 52#XINC = -I/usr/openwin/include # Sun workstations (OpenWindows) 53#XLIB = -L/usr/openwin/lib -lX11 54XINC = -I/usr/X11R6/include # new X distributions (X.org, etc.) 55XLIB = -L/usr/X11R6/lib -lX11 56#XLIB = -L/usr/X11R6/lib64 -lX11 # e.g., Red Hat on AMD64 57 58INCS = $(PNGINC) $(ZINC) $(XINC) 59RLIBSd = $(PNGLIBd) $(ZLIBd) $(XLIB) -lm 60RLIBSs = $(PNGLIBs) $(ZLIBs) $(XLIB) -lm 61WLIBSd = $(PNGLIBd) $(ZLIBd) -lm 62WLIBSs = $(PNGLIBs) $(ZLIBs) 63 64CC = gcc 65LD = gcc 66RM = rm -f 67CFLAGS = -O -Wall $(INCS) -DFEATURE_LOOP 68# [note that -Wall is a gcc-specific compilation flag ("most warnings on")] 69# [-ansi, -pedantic and -W can also be used] 70LDFLAGS = 71O = .o 72E = 73 74RPNG = rpng-x 75RPNG2 = rpng2-x 76WPNG = wpng 77 78RPNGs = $(RPNG)-static 79RPNG2s = $(RPNG2)-static 80WPNGs = $(WPNG)-static 81 82ROBJS = $(RPNG)$(O) readpng$(O) 83ROBJS2 = $(RPNG2)$(O) readpng2$(O) 84WOBJS = $(WPNG)$(O) writepng$(O) 85 86STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E) 87DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) 88 89EXES = $(STATIC_EXES) $(DYNAMIC_EXES) 90 91 92# implicit make rules ------------------------------------------------------- 93 94.c$(O): 95 $(CC) -c $(CFLAGS) $< 96 97 98# dependencies -------------------------------------------------------------- 99 100all: $(EXES) 101 102$(RPNGs)$(E): $(ROBJS) 103 $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSs) 104 105$(RPNG)$(E): $(ROBJS) 106 $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSd) 107 108$(RPNG2s)$(E): $(ROBJS2) 109 $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSs) 110 111$(RPNG2)$(E): $(ROBJS2) 112 $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSd) 113 114$(WPNGs)$(E): $(WOBJS) 115 $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSs) 116 117$(WPNG)$(E): $(WOBJS) 118 $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSd) 119 120$(RPNG)$(O): $(RPNG).c readpng.h 121$(RPNG2)$(O): $(RPNG2).c readpng2.h 122$(WPNG)$(O): $(WPNG).c writepng.h 123 124readpng$(O): readpng.c readpng.h 125readpng2$(O): readpng2.c readpng2.h 126writepng$(O): writepng.c writepng.h 127 128 129# maintenance --------------------------------------------------------------- 130 131clean: 132 $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS) 133