blob: 5af43b184520c711277a1e2e80a2b63d4ee566d0 [file] [log] [blame]
Glenn Randers-Pehrson3c6df192010-02-08 15:40:53 -06001# makefile for libpng.a and libpng15.so on Linux ELF with gcc
Glenn Randers-Pehrson5c5db5a2011-01-21 23:23:34 -06002# Copyright (C) 1998, 1999, 2002, 2006, 2008, 2010-2011 Greg Roelofs
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -05003# and Glenn Randers-Pehrson
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -06004# Copyright (C) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrson3e61d792009-06-24 09:31:28 -05005#
Glenn Randers-Pehrsonbfbf8652009-06-26 21:46:52 -05006# This code is released under the libpng license.
Glenn Randers-Pehrsonc332bbc2009-06-25 13:43:50 -05007# For conditions of distribution and use, see the disclaimer
Glenn Randers-Pehrson037023b2009-06-24 10:27:36 -05008# and license in png.h
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -06009
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -060010# Modified for Debian by Junichi Uekawa and Josselin Mouette
11# Major modifications are:
12# * link libpng explicitly with libz and libm
Glenn Randers-Pehrson3c6df192010-02-08 15:40:53 -060013# * $(OLDSO).15 is a symlink rather than a different library
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -060014# * versioned symbols
15
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -060016# Library name:
Glenn Randers-Pehrson3c6df192010-02-08 15:40:53 -060017LIBNAME = libpng15
18PNGMAJ = 15
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -060019
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -060020# Shared library names:
21LIBSO=$(LIBNAME).so
22LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -060023LIBSOREL=$(LIBSOMAJ).$(RELEASE)
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -060024OLDSO=libpng.so
Glenn Randers-Pehrson3c6df192010-02-08 15:40:53 -060025OLDSOMAJ=libpng.so.15
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -060026
27# Utilities:
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -060028AR_RC=ar rc
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -060029CC=gcc
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -060030MKDIR_P=mkdir -p
31LN_SF=ln -sf
32RANLIB=ranlib
33RM_F=/bin/rm -f
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -060034
Glenn Randers-Pehrson3c6df192010-02-08 15:40:53 -060035# where "make install" puts libpng15.a, libpng15.so*,
Glenn Randers-Pehrson72531442010-04-17 08:17:51 -050036# libpng15/png.h, libpng15/pngconf.h, and libpng15/pnglibconf.h
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -060037# Prefix must be a full pathname.
38prefix=/usr/local
Glenn Randers-Pehrsonad310542006-04-18 05:31:20 -050039exec_prefix=$(prefix)
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -060040
41# Where the zlib library and include files are located.
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -060042ZLIBLIB=/usr/local/lib
43ZLIBINC=/usr/local/include
44# ZLIBLIB=../zlib
45# ZLIBINC=../zlib
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -060046
47ALIGN=
48# for i386:
49#ALIGN=-malign-loops=2 -malign-functions=2
50
51WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
52 -Wmissing-declarations -Wtraditional -Wcast-align \
53 -Wstrict-prototypes -Wmissing-prototypes #-Wconversion
54
55# for pgcc version 2.95.1, -O3 is buggy; don't use it.
56
Glenn Randers-Pehrson03f9b022009-12-04 08:40:41 -060057CFLAGS=-W -Wall -D_REENTRANT -O2 \
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -060058 $(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5
59
Glenn Randers-Pehrson3c6df192010-02-08 15:40:53 -060060LDFLAGS=-L. -lpng15
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -060061LDFLAGS_A=libpng.a -lz -lm
62LIBADDFLAGS=-lz -lm
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -060063
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -060064
65INCPATH=$(prefix)/include
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -060066LIBPATH=$(exec_prefix)/lib
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -060067MANPATH=$(prefix)/man
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -060068BINPATH=$(exec_prefix)/bin
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -060069
70# override DESTDIR= on the make install command line to easily support
71# installing into a temporary location. Example:
72#
73# make install DESTDIR=/tmp/build/libpng
74#
75# If you're going to install into a temporary location
76# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
77# you execute make install.
78DESTDIR=
79
80DB=$(DESTDIR)$(BINPATH)
81DI=$(DESTDIR)$(INCPATH)
82DL=$(DESTDIR)$(LIBPATH)
83DM=$(DESTDIR)$(MANPATH)
84
85OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
86 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
87 pngwtran.o pngmem.o pngerror.o pngpread.o
88
89OBJSDLL = $(OBJS:.o=.pic.o)
90
91.SUFFIXES: .c .o .pic.o
92
93.c.pic.o:
94 $(CC) -c $(CFLAGS) -fPIC -o $@ $*.c
95
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -050096all: libpng.a $(LIBSO) pngtest pngtest-static libpng.pc libpng-config
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -060097
Glenn Randers-Pehrson72531442010-04-17 08:17:51 -050098# see scripts/pnglibconf.mak for more options
Glenn Randers-Pehrson8c667862010-08-24 16:16:35 -050099pnglibconf.h: scripts/pnglibconf.h.prebuilt
100 cp scripts/pnglibconf.h.prebuilt $@
Glenn Randers-Pehrson72531442010-04-17 08:17:51 -0500101
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600102libpng.a: $(OBJS)
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600103 $(AR_RC) $@ $(OBJS)
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600104 $(RANLIB) $@
105
106libpng.pc:
Glenn Randers-Pehrson glennrp@comcast.net7ecf7bd2009-05-02 15:36:08 -0500107 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
108 -e s!@exec_prefix@!$(exec_prefix)! \
109 -e s!@libdir@!$(LIBPATH)! \
110 -e s!@includedir@!$(INCPATH)! \
Glenn Randers-Pehrson3c6df192010-02-08 15:40:53 -0600111 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600112
Glenn Randers-Pehrson72531442010-04-17 08:17:51 -0500113libpng.syms: png.h pngconf.h pnglibconf.h
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600114 $(CC) $(CFLAGS) -E -DPNG_BUILDSYMS -DPNG_INTERNAL png.h |\
Glenn Randers-Pehrson3c6df192010-02-08 15:40:53 -0600115 awk -F '[\t [\\]();]' -v PNGMAJ=$(PNGMAJ) 'BEGIN{printf("PNG15_%s {global:\n",PNGMAJ)}\
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600116 { for (i=1;i+2<=NF;++i)\
117 if ($$(i)=="PNG_FUNCTION_EXPORT" && $$(i+2)=="END")\
118 print $$(i+1) ";";\
119 for (i=1;i+1<=NF;++i)\
120 if ($$(i)=="PNG_DATA_EXPORT")\
121 print $$(i+1) ";";}\
122 END{print "local: *; };"}' >$@.new
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600123 $(RM_F) $@
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600124 mv $@.new $@
125
126libpng-config:
127 ( cat scripts/libpng-config-head.in; \
128 echo prefix=\"$(prefix)\"; \
129 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600130 echo L_opts=\"\"; \
131 echo R_opts=\"\"; \
Glenn Randers-Pehrson3c6df192010-02-08 15:40:53 -0600132 echo libs=\"-lpng15\"; \
133 echo all_libs=\"-lpng15 $(LIBADDFLAGS)\"; \
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600134 cat scripts/libpng-config-body.in ) > libpng-config
135 chmod +x libpng-config
136
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -0600137$(LIBSO): $(LIBSOMAJ)
138 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600139
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600140$(LIBSOMAJ): $(OBJSDLL) libpng.syms
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -0600141 $(CC) -shared -Wl,-soname,$(LIBSOMAJ) \
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600142 -Wl,-version-script,libpng.syms \
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600143 -o $(LIBSOMAJ) \
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600144 $(OBJSDLL)
145
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -0600146pngtest: pngtest.o $(LIBSO)
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600147 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
148
149pngtest-static: pngtest.o libpng.a
150 $(CC) -o pngtest-static $(CFLAGS) pngtest.o $(LDFLAGS_A)
151
152test: pngtest pngtest-static
153 @echo ""
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -0600154 @echo " Running pngtest dynamically linked with $(LIBSO):"
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600155 @echo ""
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600156 LD_LIBRARY_PATH=".:${LD_LIBRARY_PATH}" ./pngtest
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600157 @echo ""
158 @echo " Running pngtest statically linked with libpng.a:"
159 @echo ""
160 ./pngtest-static
161
Glenn Randers-Pehrson72531442010-04-17 08:17:51 -0500162install-headers: png.h pngconf.h pnglibconf.h
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600163 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
164 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
Glenn Randers-Pehrson72531442010-04-17 08:17:51 -0500165 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
166 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
167 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600168 -@$(RM_F) $(DI)/libpng
169 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600170
171install-static: install-headers libpng.a
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600172 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600173 cp libpng.a $(DL)/$(LIBNAME).a
174 chmod 644 $(DL)/$(LIBNAME).a
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600175 -@$(RM_F) $(DL)/libpng.a
176 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600177
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600178install-shared: install-headers $(LIBSOMAJ) libpng.pc
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600179 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600180 -@$(RM_F) $(DL)/$(LIBSO)
181 -@$(RM_F) $(DL)/$(LIBSOREL)
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -0600182 -@$(RM_F) $(DL)/$(OLDSO)
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600183 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
184 chmod 755 $(DL)/$(LIBSOREL)
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600185 (cd $(DL); \
Glenn Randers-Pehrsone3f3c4e2010-02-07 18:08:50 -0600186 $(LN_SF) $(LIBSOREL) $(LIBSO); \
187 $(LN_SF) $(LIBSO) $(OLDSO))
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600188 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
189 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
190 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600191 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
192 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600193 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600194
195install-man: libpng.3 libpngpf.3 png.5
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600196 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
197 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
198 -@$(RM_F) $(DM)/man3/libpng.3
199 -@$(RM_F) $(DM)/man3/libpngpf.3
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600200 cp libpng.3 $(DM)/man3
201 cp libpngpf.3 $(DM)/man3
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600202 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
203 -@$(RM_F) $(DM)/man5/png.5
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600204 cp png.5 $(DM)/man5
205
206install-config: libpng-config
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600207 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
208 -@$(RM_F) $(DB)/libpng-config
209 -@$(RM_F) $(DB)/$(LIBNAME)-config
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600210 cp libpng-config $(DB)/$(LIBNAME)-config
211 chmod 755 $(DB)/$(LIBNAME)-config
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600212 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600213
214install: install-static install-shared install-man install-config
215
216# If you installed in $(DESTDIR), test-installed won't work until you
217# move the library to its final location. Use test-dd to test it
218# before then.
219
220test-dd:
221 echo
222 echo Testing installed dynamic shared library in $(DL).
223 $(CC) -I$(DI) -I$(ZLIBINC) \
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600224 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
Glenn Randers-Pehrson6bc53be2006-06-16 07:52:03 -0500225 -L$(DL) -L$(ZLIBLIB) -Wl, -rpath,$(DL) -Wl,-rpath,$(ZLIBLIB) \
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600226 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600227 ./pngtestd pngtest.png
228
229test-installed:
230 $(CC) -I$(ZLIBINC) \
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600231 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600232 -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) \
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600233 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600234 ./pngtesti pngtest.png
235
236clean:
Glenn Randers-Pehrson5c60b232006-03-07 07:09:22 -0600237 $(RM_F) *.o libpng.a libpng.syms pngtest pngout.png libpng-config \
Glenn Randers-Pehrson4deeb792006-03-22 16:21:59 -0600238 $(LIBSO) $(LIBSOMAJ)* pngtest-static pngtesti \
Glenn Randers-Pehrson72531442010-04-17 08:17:51 -0500239 libpng.pc pnglibconf.h
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600240
241DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
242writelock:
243 chmod a-w *.[ch35] $(DOCS) scripts/*
244
245# DO NOT DELETE THIS LINE -- make depend depends on it.
246
Glenn Randers-Pehrson72531442010-04-17 08:17:51 -0500247png.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
248pngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
249pngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
250pngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
251pngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
252pngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
253pngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
254pngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
255pngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
256pngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
257pngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
258pngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
259pngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
260pngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
261pngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
Glenn Randers-Pehrsone6474622006-03-04 16:50:47 -0600262
Glenn Randers-Pehrson72531442010-04-17 08:17:51 -0500263pngtest.o: png.h pngconf.h pnglibconf.h