[libpng16] Revised config.h handling; added bsconfig.h, deleted pngconfig.h
diff --git a/ANNOUNCE b/ANNOUNCE
index 41b0f3f..1ee9bec 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -55,7 +55,7 @@
     non-suffix rules use unique file names.
 
 Version 1.6.0beta02 [December 17, 2011]
-  Added pngconfig.h file.  This indirect reference to config.h avoids
+  Added bsconfig.h file.  This indirect reference to config.h avoids
     problems with build scripts that search for config.h and find an
     inappropriate one in the standard paths.
 
diff --git a/CHANGES b/CHANGES
index 58e0764..0843e8e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3806,7 +3806,7 @@
     non-suffix rules use unique file names.
 
 Version 1.6.0beta02 [December 17, 2011]
-  Added pngconfig.h file.  This indirect reference to config.h avoids
+  Added bsconfig.h file.  This indirect reference to config.h avoids
     problems with build scripts that search for config.h and find an
     inappropriate one in the standard paths.
 
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c4b7191..522b31e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -128,8 +128,6 @@
 )
 # SOME NEEDED DEFINITIONS
 
-add_definitions(-DPNG_CONFIGURE_LIBPNG)
-
 if(MSVC)
   add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
 endif(MSVC)
diff --git a/Makefile.am b/Makefile.am
index bd82846..39a8408 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -40,7 +40,7 @@
 libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = png.c pngerror.c\
 	pngget.c pngmem.c pngpread.c pngread.c pngrio.c pngrtran.c pngrutil.c\
 	pngset.c pngtrans.c pngwio.c pngwrite.c pngwtran.c pngwutil.c\
-	png.h pngconf.h pngdebug.h pnginfo.h pngpriv.h pngstruct.h pngconfig.h
+	png.h pngconf.h pngdebug.h pnginfo.h pngpriv.h pngstruct.h bsconfig.h
 
 if PNG_ARM_NEON
 libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += arm/filter_neon.S
@@ -48,8 +48,6 @@
 
 nodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = pnglibconf.h
 
-libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_CPPFLAGS = @LIBPNG_DEFINES@
-
 libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LDFLAGS = -no-undefined -export-dynamic \
 	-version-number @PNGLIB_MAJOR@@PNGLIB_MINOR@:@PNGLIB_RELEASE@:0
 
@@ -146,7 +144,7 @@
 	rm -f $@ $*.c $*.tf[123]
 	test -d scripts || mkdir scripts
 	echo '#include "$<"' >$*.c
-	$(DFNCPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) @LIBPNG_DEFINES@\
+	$(DFNCPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)\
 	    $(CPPFLAGS) $(SYMBOL_CFLAGS) $*.c > $*.tf1
 	$(SED) -n -e 's|^.*PNG_DEFN_MAGIC *-\(.*\)- *PNG_DEFN_END.*$$|\1|p'\
 	    $*.tf1 >$*.tf2
@@ -188,7 +186,7 @@
 	mv pnglibconf.tf7 $@
 
 $(libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_OBJECTS): png.h pngconf.h \
-	pnglibconf.h pngpriv.h pngdebug.h pnginfo.h pngstruct.h pngconfig.h
+	pnglibconf.h pngpriv.h pngdebug.h pnginfo.h pngstruct.h
 
 test: check-am
 
diff --git a/bsconfig.h b/bsconfig.h
new file mode 100644
index 0000000..1fef151
--- /dev/null
+++ b/bsconfig.h
@@ -0,0 +1,36 @@
+
+/* bsconfig.h - Build System CONFIGuration
+ *
+ * For conditions of distribution and use, see copyright notice in png.h
+ * Copyright (c) 1998-2011 Glenn Randers-Pehrson
+ * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
+ * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
+ *
+ * Last changed in libpng 1.6.0 [(PENDING RELEASE)]
+ *
+ * This code is released under the libpng license.
+ * For conditions of distribution and use, see the disclaimer
+ * and license in png.h
+ */
+
+/* This file contains includes that provide information itself provided by the
+ * environment that builds libpng.  This file is included by any source file
+ * that needs build-system specific information, including test programs that
+ * are not, themselves, installed.
+ *
+ * It is provided solely to work round shortcomings in existing build systems;
+ * do not *define* anything in this file, simply include other files as
+ * required.
+ */
+
+/* autotools support */
+/* autotools misuse -I to support separate build and source directories, to work
+ * round this the autotools generated file "config.h" is included by this file.
+ *
+ * config.h is created by the "configure" script which also sets HAVE_CONFIG_H.
+ * It is used to enable optimizations that can only be detected at build time by
+ * the configure script.
+ */
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
diff --git a/configure.ac b/configure.ac
index af2fab6..ce3eaab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -97,10 +97,6 @@
 AC_CHECK_LIB([m], [feenableexcept])
 AC_CHECK_FUNCS([feenableexcept])
 
-LIBPNG_DEFINES=-DPNG_CONFIGURE_LIBPNG
-LIBPNG_DEFINES=$LIBPNG_DEFINES
-AC_SUBST(LIBPNG_DEFINES)
-
 AC_MSG_CHECKING([if libraries can be versioned])
 
 AC_MSG_CHECKING([if using Solaris linker])
diff --git a/contrib/libtests/config.h b/contrib/libtests/config.h
new file mode 100644
index 0000000..84720a3
--- /dev/null
+++ b/contrib/libtests/config.h
@@ -0,0 +1,17 @@
+
+/*-
+ * config.h
+ *
+ * Copyright (c) 2011 John Cunningham Bowler
+ *
+ * Last changed in libpng 1.6.0 [(PENDING RELEASE)]
+ *
+ * This code is released under the libpng license.
+ * For conditions of distribution and use, see the disclaimer
+ * and license in png.h
+ *
+ * Use the "config.h" generated by configure for libpng.  For indpendent
+ * compilation of the .c files in this directory either make an appropriate
+ * configure script to generate config.h or do not define HAVE_CONFIG_H.
+ */
+#include "../../bsconfig.h"
diff --git a/contrib/libtests/pngstest.c b/contrib/libtests/pngstest.c
index bfc5d99..5fcd3d6 100644
--- a/contrib/libtests/pngstest.c
+++ b/contrib/libtests/pngstest.c
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2011 John Cunningham Bowler
  *
- * Last changed in libpng 1.5.7 [(PENDING RELEASE)]
+ * Last changed in libpng 1.6.0 [(PENDING RELEASE)]
  *
  * This code is released under the libpng license.
  * For conditions of distribution and use, see the disclaimer
@@ -23,7 +23,7 @@
 #include <math.h>
 
 #ifdef HAVE_CONFIG_H
-#  include "../../config.h"
+#  include "config.h"
 #endif
 
 #include "../../png.h"
diff --git a/contrib/libtests/pngvalid.c b/contrib/libtests/pngvalid.c
index a415d51..952bdad 100644
--- a/contrib/libtests/pngvalid.c
+++ b/contrib/libtests/pngvalid.c
@@ -1,7 +1,7 @@
 
 /* pngvalid.c - validate libpng by constructing then reading png files.
  *
- * Last changed in libpng 1.5.7 [(PENDING RELEASE)]
+ * Last changed in libpng 1.6.0 [(PENDING RELEASE)]
  * Copyright (c) 2011 Glenn Randers-Pehrson
  * Written by John Cunningham Bowler
  *
@@ -25,7 +25,7 @@
 
 #include <signal.h>
 
-#include "../../pngconfig.h"
+#include "config.h"
 
 #ifdef HAVE_FEENABLEEXCEPT
 #  include <fenv.h>
diff --git a/contrib/libtests/timepng.c b/contrib/libtests/timepng.c
index 4e825bc..f2d607c 100644
--- a/contrib/libtests/timepng.c
+++ b/contrib/libtests/timepng.c
@@ -2,7 +2,7 @@
  *
  * Copyright (c) 2011 John Cunningham Bowler
  *
- * Last changed in libpng 1.5.7 [(PENDING RELEASE)]
+ * Last changed in libpng 1.6.0 [(PENDING RELEASE)]
  *
  * This code is released under the libpng license.
  * For conditions of distribution and use, see the disclaimer
@@ -23,7 +23,7 @@
 #include <time.h>
 
 #ifdef HAVE_CONFIG_H
-#  include "../../config.h"
+#  include "config.h"
 #endif
 
 #include "../../png.h"
diff --git a/pngconfig.h b/pngconfig.h
deleted file mode 100644
index 88c8b9d..0000000
--- a/pngconfig.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* pngconf.h
- *
- * libpng version 1.6.0beta02 - December 17, 2011
- *
- * Copyright (c) 2011 Glenn Randers-Pehrson
- * Written by John Bowler.
- *
- * This code is released under the libpng license.
- * For conditions of distribution and use, see the disclaimer
- * and license in png.h
- *
- * config.h is created by and PNG_CONFIGURE_LIBPNG is set by the "configure"
- * script.  We may need it here to get the correct configuration on things
- * like limits.
- */
-
-#ifndef PNGCONFIG_H
-#define PNGCONFIG_H
-
-#ifdef PNG_CONFIGURE_LIBPNG
-#  ifdef HAVE_CONFIG_H
-#    include "config.h"
-#  endif
-#endif
-
-#endif /* PNGCONFIG_H */
diff --git a/pngpriv.h b/pngpriv.h
index 98d008f..350787f 100644
--- a/pngpriv.h
+++ b/pngpriv.h
@@ -137,15 +137,8 @@
 /* Added at libpng-1.2.9 */
 /* Moved to pngpriv.h at libpng-1.5.0 */
 
-/* config.h is created by and PNG_CONFIGURE_LIBPNG is set by the "configure"
- * script.  We may need it here to get the correct configuration on things
- * like limits.
- */
-#ifdef PNG_CONFIGURE_LIBPNG
-#  ifdef HAVE_CONFIG_H
-#    include "config.h"
-#  endif
-#endif
+/* Extracted to bsconfig.h at libpng-1.6.0 */
+#include "bsconfig.h"
 
 /* Moved to pngpriv.h at libpng-1.5.0 */
 /* NOTE: some of these may have been used in external applications as
@@ -196,7 +189,7 @@
  * empty if we can't be sure it is supported.  configure builds have already
  * done this work.
  */
-#ifdef PNG_CONFIGURE_LIBPNG
+#ifdef HAVE_CONFIG_H
 #  define PNG_RESTRICT restrict
 #else
    /* Modern compilers support restrict, but assume not for anything not