1# makefile for libpng
2# Copyright (C) 2002, 2006, 2014 Glenn Randers-Pehrson
3# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8
9# where make install puts libpng.a and png.h
10prefix=/usr/local
11INCPATH=$(prefix)/include
12LIBPATH=$(prefix)/lib
13
14# override DESTDIR= on the make install command line to easily support
15# installing into a temporary location.  Example:
16#
17#    make install DESTDIR=/tmp/build/libpng
18#
19# If you're going to install into a temporary location
20# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
21# you execute make install.
22DESTDIR=
23
24# Where the zlib library and include files are located
25#ZLIBLIB=/usr/local/lib
26#ZLIBINC=/usr/local/include
27ZLIBLIB=../zlib
28ZLIBINC=../zlib
29
30CC = cc
31AR_RC = ar rc
32MKDIR_P = mkdir
33LN_SF = ln -sf
34RANLIB = ranlib
35RM_F = rm -f
36AWK = awk
37SED = sed
38CPP = $(CC) -E
39ECHO = echo
40
41DFNFLAGS = # DFNFLAGS contains -D options to use in the libpng build
42DFA_EXTRA = # extra files that can be used to control configuration
43CPPFLAGS = -I$(ZLIBINC) # -DPNG_DEBUG=5
44CFLAGS = -O # -g
45LDFLAGS = -L. -L$(ZLIBLIB) -lpng -lz -lm
46
47OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
48	pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
49	pngwtran.o pngmem.o pngerror.o pngpread.o
50
51.c.o:
52	$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
53
54all: libpng.a pngtest
55
56# The standard pnglibconf.h exists as scripts/pnglibconf.h.prebuilt,
57# copy this if the following doesn't work.
58pnglibconf.h: pnglibconf.dfn
59	$(RM_F) $@ pnglibconf.c pnglibconf.out pnglibconf.tmp
60	$(ECHO) '#include "pnglibconf.dfn"' >pnglibconf.c
61	$(ECHO) "If '$(CC) -E' crashes try /lib/cpp (e.g. CPP='/lib/cpp')" >&2
62	$(CPP) $(DFNFLAGS) pnglibconf.c >pnglibconf.out
63	$(AWK) -f "scripts/dfn.awk" out="pnglibconf.tmp" pnglibconf.out 1>&2
64	mv pnglibconf.tmp $@
65
66pnglibconf.dfn: scripts/pnglibconf.dfa scripts/options.awk pngconf.h pngusr.dfa $(DFA_XTRA)
67	$(RM_F) $@ pnglibconf.pre pnglibconf.tmp
68	$(ECHO) "Calling $(AWK) from scripts/pnglibconf.mak" >&2
69	$(ECHO) "If 'awk' crashes try a better awk (e.g. AWK='nawk')" >&2
70	$(AWK) -f scripts/options.awk out="pnglibconf.pre"\
71	    version=search pngconf.h scripts/pnglibconf.dfa\
72	    pngusr.dfa $(DFA_XTRA) 1>&2
73	$(AWK) -f scripts/options.awk out="pnglibconf.tmp" pnglibconf.pre 1>&2
74	mv pnglibconf.tmp $@
75
76libpng.a: $(OBJS)
77	$(AR_RC) $@  $(OBJS)
78	$(RANLIB) $@
79
80pngtest: pngtest.o libpng.a
81	$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
82
83test: pngtest
84	./pngtest
85
86install: libpng.a pnglibconf.h
87	-@$(MKDIR_P) $(DESTDIR)$(INCPATH)
88	-@$(MKDIR_P) $(DESTDIR)$(INCPATH)/libpng
89	-@$(MKDIR_P) $(DESTDIR)$(LIBPATH)
90	-@$(RM_F) $(DESTDIR)$(INCPATH)/png.h
91	-@$(RM_F) $(DESTDIR)$(INCPATH)/pngconf.h
92	-@$(RM_F) $(DESTDIR)$(INCPATH)/pnglibconf.h
93	cp png.h $(DESTDIR)$(INCPATH)/libpng
94	cp pngconf.h $(DESTDIR)$(INCPATH)/libpng
95	cp pnglibconf.h $(DESTDIR)$(INCPATH)/libpng
96	chmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h
97	chmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h
98	chmod 644 $(DESTDIR)$(INCPATH)/libpng/pnglibconf.h
99	(cd $(DESTDIR)$(INCPATH); ln -f -s libpng/* .)
100	cp libpng.a $(DESTDIR)$(LIBPATH)
101	chmod 644 $(DESTDIR)$(LIBPATH)/libpng.a
102
103clean:
104	$(RM_F) *.o libpng.a pngtest pngout.png pnglibconf.*
105
106DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
107writelock:
108	chmod a-w *.[ch35] $(DOCS) scripts/*
109
110# DO NOT DELETE THIS LINE -- make depend depends on it.
111
112png.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
113pngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
114pngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
115pngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
116pngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
117pngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
118pngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
119pngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
120pngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
121pngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
122pngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
123pngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
124pngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
125pngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
126pngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
127
128pngtest.o: png.h pngconf.h pnglibconf.h
129