Makefile.unx 4.0 KB
Newer Older
1 2
# Sample makefile for rpng-x / rpng2-x / wpng using gcc and make.
# Greg Roelofs
3
# Last modified:  2 June 2007
4 5 6
#
#	The programs built by this makefile are described in the book,
#	"PNG:  The Definitive Guide," by Greg Roelofs (O'Reilly and
7 8 9
#	Associates, 1999).  Go buy a copy, eh?  Well, OK, it's not
#	generally for sale anymore, but it's the thought that counts,
#	right?  (Hint:  http://www.libpng.org/pub/png/book/ )
10 11 12
#
# Invoke this makefile from a shell prompt in the usual way; for example:
#
13
#	make -f Makefile.unx
14 15
#
# This makefile assumes libpng and zlib have already been built or downloaded
16 17 18
# and are installed in /usr/local/{include,lib} or as otherwise indicated by
# the PNG* and Z* macros below.  Edit as appropriate--choose only ONE each of
# the PNGINC, PNGLIBd, PNGLIBs, ZINC, ZLIBd and ZLIBs lines.
19
#
20 21 22 23
# This makefile builds both dynamically and statically linked executables
# (against libpng and zlib, that is), but that can be changed by modifying
# the "EXES =" line.  (You need only one set, but for testing it can be handy
# to have both.)
24 25 26 27


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

28
#PNGDIR = /usr/local/lib
29 30 31
#PNGINC = -I/usr/local/include/libpng16
#PNGLIBd = -L$(PNGDIR) -lpng16 # dynamically linked, installed libpng
#PNGLIBs = $(PNGDIR)/libpng16.a # statically linked, installed libpng
32
# or:
33 34 35
PNGDIR = ../..#	this one is for libpng-x.y.z/contrib/gregbook builds
#PNGDIR = ../libpng
PNGINC = -I$(PNGDIR)
36
PNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng16	# dynamically linked
37 38 39 40
PNGLIBs = $(PNGDIR)/libpng.a		# statically linked, local libpng

ZDIR = /usr/local/lib
#ZDIR = /usr/lib64
41
ZINC = -I/usr/local/include
42 43 44 45 46 47 48
ZLIBd = -L$(ZDIR) -lz			# dynamically linked against zlib
ZLIBs = $(ZDIR)/libz.a			# statically linked against zlib
# or:
#ZDIR = ../zlib
#ZINC = -I$(ZDIR)
#ZLIBd = -Wl,-rpath,$(ZDIR) -L$(ZDIR) -lz  # -rpath allows in-place testing
#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
54
XINC = -I/usr/X11R6/include		# new X distributions (X.org, etc.)
55
XLIB = -L/usr/X11R6/lib -lX11
56
#XLIB = -L/usr/X11R6/lib64 -lX11	# e.g., Red Hat on AMD64
57 58

INCS = $(PNGINC) $(ZINC) $(XINC)
59 60 61
RLIBSd = $(PNGLIBd) $(ZLIBd) $(XLIB) -lm
RLIBSs = $(PNGLIBs) $(ZLIBs) $(XLIB) -lm
WLIBSd = $(PNGLIBd) $(ZLIBd) -lm
62
WLIBSs = $(PNGLIBs) $(ZLIBs) -lm
63 64 65 66

CC = gcc
LD = gcc
RM = rm -f
67 68
CPPFLAGS = $(INCS) -DFEATURE_LOOP
CFLAGS = -O -Wall
69
#CFLAGS = -O -W -Wall -Wextra -pedantic -ansi
70
# [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
71
# [-ansi, -pedantic, -Wextra, and -W can also be used]
72 73 74 75
LDFLAGS =
O = .o
E =

76 77 78 79 80 81 82
RPNG   = rpng-x
RPNG2  = rpng2-x
WPNG   = wpng

RPNGs  = $(RPNG)-static
RPNG2s = $(RPNG2)-static
WPNGs  = $(WPNG)-static
83 84 85 86 87

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

88 89 90 91
STATIC_EXES  = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E)
DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)

EXES = $(STATIC_EXES) $(DYNAMIC_EXES)
92 93 94 95 96


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

.c$(O):
97
	$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
98 99 100 101 102 103


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

all:  $(EXES)

104 105 106
$(RPNGs)$(E): $(ROBJS)
	$(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSs)

107
$(RPNG)$(E): $(ROBJS)
108 109 110 111
	$(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSd)

$(RPNG2s)$(E): $(ROBJS2)
	$(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSs)
112 113

$(RPNG2)$(E): $(ROBJS2)
114 115 116 117
	$(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSd)

$(WPNGs)$(E): $(WOBJS)
	$(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSs)
118 119

$(WPNG)$(E): $(WOBJS)
120
	$(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSd)
121 122 123 124 125 126 127 128 129 130 131 132 133 134

$(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)