• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Sample makefile for rpng-win / rpng2-win / wpng using mingw32-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 DOS-prompt window via:
12#
13#	make -f Makefile.mingw32
14#
15# This makefile assumes libpng and zlib have already been built or downloaded
16# and are in subdirectories at the same level as the current subdirectory
17# (as indicated by the PNGDIR and ZDIR macros below).  It makes no assumptions
18# at all about the mingw32 installation tree (W32DIR).  Edit as appropriate.
19#
20# Note that the names of the dynamic and static libpng and zlib libraries
21# used below may change in later releases of the libraries.  This makefile
22# builds both statically and dynamically linked executables by default.
23# (You need only one set, but for testing it can be handy to have both.)
24
25
26# macros --------------------------------------------------------------------
27
28#PNGDIR = ../..#		for libpng-x.y.z/contrib/gregbook builds
29PNGDIR = ../libpng-win32
30PNGINC = -I$(PNGDIR)
31PNGLIBd = $(PNGDIR)/libpng.dll.a	# dynamically linked
32PNGLIBs = $(PNGDIR)/libpng.a		# statically linked, local libpng
33
34#ZDIR = ../../../zlib-win32#	for libpng-x.y.z/contrib/gregbook builds
35ZDIR = ../zlib-win32
36ZINC = -I$(ZDIR)
37ZLIBd = $(ZDIR)/libzdll.a
38ZLIBs = $(ZDIR)/libz.a
39
40# change this to be the path where mingw32 installs its stuff:
41W32DIR =
42#W32DIR = /usr/local/cross-tools/i386-mingw32msvc
43W32INC = -I$(W32DIR)/include
44W32LIB = $(W32DIR)/lib/libuser32.a $(W32DIR)/lib/libgdi32.a
45
46CC = gcc
47#CC = i386-mingw32msvc-gcc #	e.g., Linux -> Win32 cross-compilation
48LD = $(CC)
49RM = rm -f
50CPPFLAGS = $(INCS)
51CFLAGS = -O -Wall $(MINGW_CCFLAGS)
52# [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
53# [-ansi, -pedantic and -W can also be used]
54LDFLAGS = $(MINGW_LDFLAGS)
55O = .o
56E = .exe
57
58INCS = $(PNGINC) $(ZINC) $(W32INC)
59RLIBSd = $(PNGLIBd) $(ZLIBd) $(W32LIB) -lm
60RLIBSs = $(PNGLIBs) $(ZLIBs) $(W32LIB) -lm
61WLIBSd = $(PNGLIBd) $(ZLIBd)
62WLIBSs = $(PNGLIBs) $(ZLIBs)
63
64RPNG   = rpng-win
65RPNG2  = rpng2-win
66WPNG   = wpng
67
68ROBJSd  = $(RPNG)$(O) readpng.pic$(O)
69ROBJS2d = $(RPNG2)$(O) readpng2.pic$(O)
70WOBJSd  = $(WPNG)$(O) writepng.pic$(O)
71
72RPNGs  = $(RPNG)-static
73RPNG2s = $(RPNG2)-static
74WPNGs  = $(WPNG)-static
75
76ROBJSs  = $(RPNG)$(O) readpng$(O)
77ROBJS2s = $(RPNG2)$(O) readpng2$(O)
78WOBJSs  = $(WPNG)$(O) writepng$(O)
79
80STATIC_EXES  = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E)
81DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
82
83EXES = $(STATIC_EXES) $(DYNAMIC_EXES)
84
85
86# implicit make rules -------------------------------------------------------
87
88.c$(O):
89	$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
90
91%.pic$(O): %.c
92	$(CC) -c $(CPPFLAGS) $(CFLAGS) -DPNG_BUILD_DLL -o $@ $<
93
94
95# dependencies --------------------------------------------------------------
96
97all:  $(EXES)
98
99$(RPNGs)$(E): $(ROBJSs)
100	$(LD) $(LDFLAGS) -o $@ $(ROBJSs) $(RLIBSs)
101
102$(RPNG)$(E): $(ROBJSd)
103	$(LD) $(LDFLAGS) -o $@ $(ROBJSd) $(RLIBSd)
104
105$(RPNG2s)$(E): $(ROBJS2s)
106	$(LD) $(LDFLAGS) -o $@ $(ROBJS2s) $(RLIBSs)
107
108$(RPNG2)$(E): $(ROBJS2d)
109	$(LD) $(LDFLAGS) -o $@ $(ROBJS2d) $(RLIBSd)
110
111$(WPNGs)$(E): $(WOBJSs)
112	$(LD) $(LDFLAGS) -o $@ $(WOBJSs) $(WLIBSs)
113
114$(WPNG)$(E): $(WOBJSd)
115	$(LD) $(LDFLAGS) -o $@ $(WOBJSd) $(WLIBSd)
116
117$(RPNG)$(O):	$(RPNG).c readpng.h
118$(RPNG2)$(O):	$(RPNG2).c readpng2.h
119$(WPNG)$(O):	$(WPNG).c writepng.h
120
121readpng$(O) readpng.pic$(O):	readpng.c readpng.h
122readpng2$(O) readpng2.pic$(O):	readpng2.c readpng2.h
123writepng$(O) writepng.pic$(O):	writepng.c writepng.h
124
125
126# maintenance ---------------------------------------------------------------
127
128clean:
129	$(RM) $(EXES)
130	$(RM) $(ROBJSs) $(ROBJS2s) $(WOBJSs)
131	$(RM) $(ROBJSd) $(ROBJS2d) $(WOBJSd)
132