Imported from libpng-1.2.9beta4.tar
diff --git a/Makefile.am b/Makefile.am
index 2227788..b5e3571 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,31 +1,60 @@
-# test
+# Makefile.am:
+#   Source file for Makefile.in (and hence Makefile)
+#
+# Makefile.am need only be changed on a major version number
+# change (e.g. libpng12 --> libpng13).  In that case seach
+# this file for every instance of the old base name (libpng12)
+# and change to the new one (libpng13), then change the
+# -version-number settings below so that the new values have
+# the correct major part (first field).
+
+PNGLIB_BASENAME= libpng@PNGLIB_MAJOR@
+
+# libpng does not follow GNU file name conventions
+AUTOMAKE_OPTIONS = foreign
+
+# test programs - run on make check, make distcheck
 check_PROGRAMS= pngtest
 pngtest_SOURCES = pngtest.c
 pngtest_LDADD = libpng.la
 TESTS = test-pngtest.sh
 TESTS_ENVIRONMENT= srcdir=$(srcdir) 
-dist_man_MANS= libpng.3 libpngpf.3 png.5
-include_HEADERS= png.h pngconf.h 
-bin_SCRIPTS=libpng-config libpng12-config 
 
-#rules to build libpng
-lib_LTLIBRARIES=libpng12.la libpng.la
+# man pages
+dist_man_MANS= libpng.3 libpngpf.3 png.5
+
+# generate the -config scripts if required
+binconfigs= libpng-config libpng12-config 
+EXTRA_SCRIPTS= libpng-config libpng12-config 
+bin_SCRIPTS= @binconfigs@
+
+# rules to build libpng, only build the old library on request
+lib_LTLIBRARIES=libpng12.la @compatlib@
+EXTRA_LTLIBRARIES= libpng.la
 libpng12_la_SOURCES = png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
 	pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
 	pngwtran.c pngmem.c pngerror.c pngpread.c \
 	png.h pngconf.h 
 libpng_la_SOURCES = $(libpng12_la_SOURCES)
-libpng12_la_LDFLAGS = -no-undefined -export-dynamic -version-info \
-$(LIBPNG12_VERSION_INFO)
-libpng_la_LDFLAGS = -no-undefined -export-dynamic -version-info \
-$(LIBPNG3_VERSION_INFO)
+# MAJOR UPGRADE: the version-number settings below must be changed.
+libpng12_la_LDFLAGS = -no-undefined -export-dynamic \
+	-version-number 0:@PNGLIB_MINOR@:0
+# -rpath is needed as automake doesn't know the directory
+libpng_la_LDFLAGS = -rpath '$(libdir)' -no-undefined -export-dynamic \
+	-version-number 3:@PNGLIB_MINOR@:0
 
 #distribute headers in /usr/include/libpng/*
+pkgincludedir= $(includedir)/$(PNGLIB_BASENAME)
 pkginclude_HEADERS= png.h pngconf.h
 
+# pkg-config stuff, note that libpng.pc is always required in order
+# to get the correct library
+pkgconfigdir = @pkgconfigdir@
+pkgconfig_DATA = libpng.pc libpng12.pc
+
 #extra source distribution files.
 EXTRA_DIST= \
-	NEWS AUTHORS ChangeLog INSTALL KNOWNBUG COPYING README TODO Y2KINFO \
+	ANNOUNCE ChangeLog INSTALL KNOWNBUG LICENSE README TODO Y2KINFO \
 	pngtest.png pngbar.png pngnow.png pngbar.jpg autogen.sh \
 	${srcdir}/projects/cbuilder5/* \
 	${srcdir}/projects/beos/* \
@@ -41,38 +70,28 @@
 	$(TESTS) \
 	example.c libpng.txt pnggccrd.c pngvcrd.c 
 
-CLEANFILES= pngout.png libpng.pc libpng12.pc libpng-config libpng12-config
+CLEANFILES= pngout.png libpng12.pc libpng12-config
 
+$(PNGLIB_BASENAME).pc: libpng.pc
+	cp libpng.pc $@
 
-libpng.pc:
-	cat ${srcdir}/scripts/libpng.pc.in | \
-	sed -e 's,[@]PREFIX[@],$(prefix),' \
-	  -e 's,[@]INCLUDEDIR[@],$(includedir),' \
-	  -e 's,[@]EXEC_PREFIX[@],$(exec_prefix),' > libpng.pc
+$(PNGLIB_BASENAME)-config: libpng-config
+	cp libpng-config $@
 
-libpng12.pc: libpng.pc
-	cp libpng.pc libpng12.pc
+# install the .../include headers as links to the new ones
+install-data-hook:
+	cd $(DESTDIR)$(includedir); rm -f png.h pngconf.h
+	cd $(DESTDIR)$(includedir); $(LN_S) $(PNGLIB_BASENAME)/png.h png.h
+	cd $(DESTDIR)$(includedir); $(LN_S) $(PNGLIB_BASENAME)/pngconf.h pngconf.h
 
- 
-install-data-local: libpng.pc libpng12.pc
-	@INSTALL@ -d $(DESTDIR)@PKGCONFIGDIR@
-	@INSTALL_DATA@ libpng.pc $(DESTDIR)@PKGCONFIGDIR@
-	@INSTALL_DATA@ libpng12.pc $(DESTDIR)@PKGCONFIGDIR@
- 
-uninstall-local:
-	rm -f $(DESTDIR)@PKGCONFIGDIR@/libpng.pc
-	rm -f $(DESTDIR)@PKGCONFIGDIR@/libpng12.pc
-
-libpng-config:
-	( cat ${srcdir}/scripts/libpng-config-head.in; \
-	echo prefix=\"$(prefix)\"; \
-	echo I_opts=\"-I$(includedir)\"; \
-	echo L_opts=\"-L$(libdir)\"; \
-	echo R_opts=\"-Wl,-rpath,$(libdir)\"; \
-	echo libs=\"-lpng12 -lz -lm\"; \
-	cat ${srcdir}/scripts/libpng-config-body.in ) > libpng-config
-	chmod 755 libpng-config
-
-libpng12-config: libpng-config
-	cp libpng-config libpng12-config
-	chmod 755 libpng12-config
+# do evil things to libpng to cause libpng12 to be used, if
+# the compat library is not being built do nothing.
+install-exec-hook:
+	@if test -n "@compatlib@"; then\
+		set -x;\
+		cd $(DESTDIR)$(libdir);\
+		for ext in a la so; do\
+			rm -f libpng.$$ext;\
+			$(LN_S) $(PNGLIB_BASENAME).$$ext libpng.$$ext;\
+		done;\
+	fi