1# makefile for cygwin on x86
2#   Builds both dll (with import lib) and static lib versions
3#   of the library, and builds two copies of pngtest: one
4#   statically linked and one dynamically linked.
5#
6# Copyright (C) 2002, 2006-2008 Soren Anderson, Charles Wilson,
7#    and Glenn Randers-Pehrson, based on makefile for linux-elf w/mmx by:
8# Copyright (C) 1998-2000 Greg Roelofs
9# Copyright (C) 1996, 1997 Andreas Dilger
10#
11# This code is released under the libpng license.
12# For conditions of distribution and use, see the disclaimer
13# and license in png.h
14
15# This makefile intends to support building outside the src directory
16# if desired. When invoking it, specify an argument to SRCDIR on the
17# command line that points to the top of the directory where your source
18# is located.
19
20ifdef SRCDIR
21VPATH = $(SRCDIR)
22else
23SRCDIR = .
24endif
25
26# Override DESTDIR= on the make install command line to easily support
27# installing into a temporary location.  Example:
28#
29#    make install DESTDIR=/tmp/build/libpng
30#
31# If you're going to install into a temporary location
32# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
33# you execute make install.
34
35DESTDIR=
36
37CC=gcc
38ifdef MINGW
39MINGW_CCFLAGS=-mno-cygwin -I/usr/include/mingw
40MINGW_LDFLAGS=-mno-cygwin -L/usr/lib/mingw
41endif
42
43# Where "make install" puts libpng*.a, *png*.dll, png.h, and pngconf.h
44ifndef prefix
45prefix=/usr
46$(warning You haven't specified a 'prefix=' location. Defaulting to "/usr")
47endif
48exec_prefix=$(prefix)
49
50# Where the zlib library and include files are located
51ZLIBLIB= /usr/lib
52ZLIBINC=
53#ZLIBLIB=../zlib
54#ZLIBINC=../zlib
55
56ALIGN=
57# for i386:
58#ALIGN=-malign-loops=2 -malign-functions=2
59
60WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
61	-Wmissing-declarations -Wtraditional -Wcast-align \
62	-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
63
64### if you don't need thread safety, but want the asm accel
65#CFLAGS= $(strip $(MINGW_CCFLAGS) -DPNG_THREAD_UNSAFE_OK \
66#	$(addprefix -I,$(ZLIBINC)) -W -Wall -O $(ALIGN) -funroll-loops \
67#	-fomit-frame-pointer)  # $(WARNMORE) -g -DPNG_DEBUG=5
68### if you need thread safety and want (minimal) asm accel
69#CFLAGS= $(strip $(MINGW_CCFLAGS) $(addprefix -I,$(ZLIBINC)) \
70#	-W -Wall -O $(ALIGN) -funroll-loops \
71#	-fomit-frame-pointer)  # $(WARNMORE) -g -DPNG_DEBUG=5
72### Normal (non-asm) compilation
73CFLAGS= $(strip $(MINGW_CCFLAGS) $(addprefix -I,$(ZLIBINC)) \
74        -W -Wall -O3 $(ALIGN) -funroll-loops -DPNG_NO_MMX_CODE \
75	-fomit-frame-pointer) # $(WARNMORE) -g -DPNG_DEBUG=5
76
77LIBNAME = libpng12
78PNGMAJ = 0
79CYGDLL = 12
80PNGMIN = 1.2.46
81PNGVER = $(PNGMAJ).$(PNGMIN)
82
83SHAREDLIB=cygpng$(CYGDLL).dll
84STATLIB=libpng.a
85IMPLIB=libpng.dll.a
86SHAREDDEF=libpng.def
87LIBS=$(SHAREDLIB) $(STATLIB)
88EXE=.exe
89
90LDFLAGS=$(strip -L. $(MINGW_LDFLAGS) -lpng $(addprefix -L,$(ZLIBLIB)) -lz)
91LDSFLAGS=$(strip -shared -L.  $(MINGW_LDFLAGS) -Wl,--export-all)
92LDEXTRA=-Wl,--out-implib=$(IMPLIB) $(addprefix -L,$(ZLIBLIB)) -lz
93
94MKDIR_P=/bin/mkdir -pv
95RANLIB=ranlib
96#RANLIB=echo
97
98INCPATH=$(prefix)/include
99LIBPATH=$(exec_prefix)/lib
100
101BINPATH=$(exec_prefix)/bin
102MANPATH=$(prefix)/man
103MAN3PATH=$(MANPATH)/man3
104MAN5PATH=$(MANPATH)/man5
105
106# cosmetic: shortened strings:
107S =$(SRCDIR)
108D =$(DESTDIR)
109DB =$(D)$(BINPATH)
110DI =$(D)$(INCPATH)
111DL =$(D)$(LIBPATH)
112
113OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
114	pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
115	pngwtran.o pngmem.o pngerror.o pngpread.o
116
117OBJSDLL = $(OBJS:.o=.pic.o)
118
119.SUFFIXES: .c .o .pic.o
120
121%.o : %.c
122	$(CC) -c $(CFLAGS) -o $@ $<
123%.pic.o : CFLAGS += -DPNG_BUILD_DLL
124%.pic.o : %.c
125	$(CC) -c $(CFLAGS) -o $@ $<
126
127all: all-static all-shared libpng.pc libpng-config libpng.pc libpng-config
128
129# Make this to verify that "make [...] install" will do what you want.
130buildsetup-tell:
131	@echo  VPATH is set to: \"$(VPATH)\"
132	@echo  prefix is set to: \"$(prefix)\"
133	@echo -e INCPATH,LIBPATH, etc. are set to:'\n' \
134 $(addprefix $(D),$(INCPATH)'\n' $(LIBPATH)'\n' $(BINPATH)'\n' \
135   $(MANPATH)'\n' $(MAN3PATH)'\n' $(MAN5PATH)'\n')'\n'
136
137libpng.pc: scripts/libpng.pc.in
138	@echo -e Making pkg-config file for this libpng installation..'\n' \
139           using PREFIX=\"$(prefix)\"'\n'
140	cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
141	-e s!@exec_prefix@!$(exec_prefix)! \
142	-e s!@libdir@!$(LIBPATH)! \
143	-e s!@includedir@!$(INCPATH)! \
144	-e s!-lpng12!-lpng12\ -lz! > libpng.pc
145
146libpng-config: scripts/libpng-config-head.in scripts/libpng-config-body.in
147	@echo -e Making $(LIBNAME) libpng-config file for this libpng \
148 installation..'\n' using PREFIX=\"$(prefix)\"'\n'
149	( cat $(S)/scripts/libpng-config-head.in; \
150	echo prefix=\"$(prefix)\"; \
151	echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
152	echo L_opts=\"-L$(LIBPATH)\"; \
153	echo libs=\"-lpng$(CYGDLL) -lz\"; \
154	cat $(S)/scripts/libpng-config-body.in ) > libpng-config
155	chmod +x libpng-config
156
157static: all-static
158shared: all-shared
159all-static: $(STATLIB) pngtest-stat$(EXE)
160all-shared: $(SHAREDLIB) pngtest$(EXE)
161
162$(STATLIB): $(OBJS)
163	ar rc $@ $(OBJS)
164	$(RANLIB) $@
165
166$(SHAREDDEF): scripts/pngw32.def
167	cat $< | sed -e '1{G;s/^\(.*\)\(\n\)/EXPORTS/;};2,/^EXPORTS/d' | \
168	sed -e 's/\([^;]*\);/;/' > $@
169
170$(SHAREDLIB): $(OBJSDLL) $(SHAREDDEF)
171	$(CC) $(LDSFLAGS) -o $@ $(OBJSDLL) -L. $(LDEXTRA)
172
173pngtest$(EXE): pngtest.pic.o $(SHAREDLIB)
174	$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
175
176pngtest-stat$(EXE): pngtest.o $(STATLIB)
177	$(CC) -static $(CFLAGS) $< $(LDFLAGS) -o $@
178
179pngtest.pic.o: pngtest.c
180	$(CC) $(CFLAGS) -c $< -o $@
181
182pngtest.o: pngtest.c png.h pngconf.h
183	$(CC) $(CFLAGS) -c $< -o $@
184
185test: test-static test-shared
186
187test-static: pngtest-stat$(EXE)
188	./pngtest-stat $(S)/pngtest.png
189
190test-shared: pngtest$(EXE)
191	./pngtest $(S)/pngtest.png
192
193install-static: $(STATLIB) install-headers install-man
194	-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
195	install -m 644 $(STATLIB) $(DL)/$(LIBNAME).a
196	-@rm -f $(DL)/$(STATLIB)
197	(cd $(DL); ln -sf $(LIBNAME).a $(STATLIB))
198
199install-shared: $(SHAREDLIB) libpng.pc libpng-config install-headers install-man
200	-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
201	-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
202	-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
203	-@/bin/rm -f $(DL)/pkgconfig/$(LIBNAME).pc
204	-@/bin/rm -f $(DL)/pkgconfig/libpng.pc
205	install -m 644 $(IMPLIB) $(DL)/$(LIBNAME).dll.a
206	-@rm -f $(DL)/$(IMPLIB)
207	(cd $(DL); ln -sf $(LIBNAME).dll.a $(IMPLIB))
208	install -s -m 755 $(SHAREDLIB) $(DB)
209	install -m 644 libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
210	(cd $(DL)/pkgconfig; ln -sf $(LIBNAME).pc libpng.pc)
211
212install-headers:
213	-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
214	-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
215	-@rm -f $(DI)/png.h
216	-@rm -f $(DI)/pngconf.h
217	install -m 644 $(S)/png.h $(S)/pngconf.h $(DI)/$(LIBNAME)
218	-@rm -f $(DI)/libpng
219	(cd $(DI); ln -sf $(LIBNAME) libpng; ln -sf $(LIBNAME)/* .)
220
221install-man:
222	-@if [ ! -d $(D)$(MAN3PATH) ]; then $(MKDIR_P) $(D)$(MAN3PATH); fi
223	-@if [ ! -d $(D)$(MAN5PATH) ]; then $(MKDIR_P) $(D)$(MAN5PATH); fi
224	install -m 644 $(S)/libpngpf.3 $(S)/libpng.3 $(D)$(MAN3PATH)
225	install -m 644 $(S)/png.5 $(D)$(MAN5PATH)
226
227install-config: libpng-config
228	-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
229	-@/bin/rm -f $(DB)/libpng-config
230	-@/bin/rm -f $(DB)/$(LIBNAME)-config
231	cp libpng-config $(DB)/$(LIBNAME)-config
232	chmod 755 $(DB)/$(LIBNAME)-config
233	(cd $(DB); ln -sf $(LIBNAME)-config libpng-config)
234
235# Run this to verify that a future `configure' run will pick up the settings
236# you want.
237test-config-install: SHELL=/bin/bash
238test-config-install: $(DB)/libpng-config
239	@echo -e Testing libpng-config functions...'\n'
240	@ for TYRA in LDFLAGS CPPFLAGS CFLAGS LIBS VERSION; \
241   do \
242    printf "(%d)\t %10s =%s\n" $$(($$gytiu + 1)) $$TYRA \
243    "$$($(DB)/libpng-config `echo --$$TYRA |tr '[:upper:]' '[:lower:]'`)"; \
244    gytiu=$$(( $$gytiu + 1 )); \
245   done
246
247install: install-static install-shared install-man install-config
248
249# If you installed in $(DESTDIR), test-installed won't work until you
250# move the library to its final location.  Use test-dd to test it
251# before then.
252
253test-dd:
254	echo
255	echo Testing installed dynamic shared library in $(DL).
256	$(CC) -I$(DI) $(CFLAGS) \
257	   `$(BINPATH)/libpng12-config --cflags` pngtest.c \
258	   -L$(DL) -L$(ZLIBLIB) \
259	   -o pngtestd `$(BINPATH)/libpng12-config --ldflags`
260	./pngtestd pngtest.png
261
262test-installed:
263	$(CC) $(CFLAGS) \
264	   `$(BINPATH)/libpng12-config --cflags` pngtest.c \
265	   -L$(ZLIBLIB) \
266	   -o pngtesti$(EXE) `$(BINPATH)/libpng12-config --ldflags`
267	./pngtesti$(EXE) pngtest.png
268
269clean:
270	/bin/rm -f *.pic.o *.o $(STATLIB) $(IMPLIB) $(SHAREDLIB) \
271	pngtest-stat$(EXE) pngtest$(EXE) pngout.png $(SHAREDDEF) \
272	libpng-config libpng.pc pngtesti$(EXE)
273
274DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
275writelock:
276	chmod a-w *.[ch35] $(DOCS) scripts/*
277
278.PHONY: buildsetup-tell libpng.pc libpng-config test-config-install clean
279
280# DO NOT DELETE THIS LINE -- make depend depends on it.
281
282png.o png.pic.o:		png.h pngconf.h png.c
283pngerror.o pngerror.pic.o:	png.h pngconf.h pngerror.c
284pngrio.o pngrio.pic.o:		png.h pngconf.h pngrio.c
285pngwio.o pngwio.pic.o:		png.h pngconf.h pngwio.c
286pngmem.o pngmem.pic.o:		png.h pngconf.h pngmem.c
287pngset.o pngset.pic.o:		png.h pngconf.h pngset.c
288pngget.o pngget.pic.o:		png.h pngconf.h pngget.c
289pngread.o pngread.pic.o:	png.h pngconf.h pngread.c
290pngrtran.o pngrtran.pic.o:	png.h pngconf.h pngrtran.c
291pngrutil.o pngrutil.pic.o:	png.h pngconf.h pngrutil.c
292pngtrans.o pngtrans.pic.o:	png.h pngconf.h pngtrans.c
293pngwrite.o pngwrite.pic.o:	png.h pngconf.h pngwrite.c
294pngwtran.o pngwtran.pic.o:	png.h pngconf.h pngwtran.c
295pngwutil.o pngwutil.pic.o:	png.h pngconf.h pngwutil.c
296pngpread.o pngpread.pic.o:	png.h pngconf.h pngpread.c
297
298pngtest.o:			png.h pngconf.h pngtest.c
299pngtest-stat.o:			png.h pngconf.h pngtest.c
300
301
302
303