<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40242 >

 Checks for libpng are not working too well with some modern environments

 Attached patch improves situation:
 1) Using pkg-config to detect libpng
 2) If (1) fails, use old method, but prefer libpng12 over obsoleted name libpng
 3) Avoid adding unnecessary (duplicate) flags to LDFLAGS



 - ML

diff -Nurd -X.diff_ignore freeciv/configure.ac freeciv/configure.ac
--- freeciv/configure.ac	2008-05-04 16:48:15.000000000 +0300
+++ freeciv/configure.ac	2008-05-13 01:20:19.000000000 +0300
@@ -412,12 +412,6 @@
   AC_DEFINE_UNQUOTED(LOCALEDIR, "./share/locale", [Locale directory (windows)])
 fi  
 
-dnl Check for zlib (needed for libpng)
-AC_CHECK_LIB(z, gzgets, , 
-  AC_MSG_ERROR([Could not find zlib library.]), )
-AC_CHECK_HEADER(zlib.h, , 
-  AC_MSG_ERROR([zlib found but not zlib.h.  
-You may need to install a zlib \"development\" package.]))
 AC_PATH_PROG(GZIP, gzip, "no")
 if test "$GZIP" = "no"; then
   AC_MSG_ERROR([You need the gzip program for compilation.])
diff -Nurd -X.diff_ignore freeciv/m4/win32-client.m4 freeciv/m4/win32-client.m4
--- freeciv/m4/win32-client.m4	2007-09-14 14:44:03.000000000 +0300
+++ freeciv/m4/win32-client.m4	2008-05-13 00:54:45.000000000 +0300
@@ -7,33 +7,42 @@
 [
   if test "$client" = "win32" || test "$client" = "yes" ; then
     if test "$MINGW32" = "yes"; then
-      AC_CHECK_LIB([z], [gzgets],
+      PKG_CHECK_MODULES([PNG], [libpng],
+      [
+        CLIENT_LIBS="-lwsock32 -lcomctl32 -mwindows $PNG_LIBS"
+        CLIENT_CFLAGS="$PNG_CFLAGS"
+      ],
+      [
+        AC_CHECK_LIB([z], [gzgets],
         [
           AC_CHECK_HEADER([zlib.h],
+          [
+            AC_CHECK_LIB([png12], [png_read_image],,
             [
-              AC_CHECK_LIB([png], [png_read_image],
-                [
-                  AC_CHECK_HEADER([png.h],
-                    [
-                      found_client=yes
-                      client=win32
-                      CLIENT_LIBS="-lwsock32 -lcomctl32  -lpng -lz -mwindows"
-                    ],
-                    [
-                      FC_NO_CLIENT([win32], [libpng-dev is needed])
-                    ])
-                ],
-                [
-                  FC_NO_CLIENT([win32], [libpng is needed])
-                ], [-lz])
+              AC_CHECK_LIB([png], [png_read_image],,
+              [
+                FC_NO_CLIENT([win32], [libpng is needed])
+              ])
+            ])
+
+            AC_CHECK_HEADER([png.h],
+            [
+              found_client=yes
+              client=win32
+              CLIENT_LIBS="-lwsock32 -lcomctl32  -lpng -mwindows"
             ],
             [
-              FC_NO_CLIENT([win32], [zlib-dev is needed])
+              FC_NO_CLIENT([win32], [libpng-dev is needed])
             ])
+          ],
+          [
+            FC_NO_CLIENT([win32], [zlib-dev is needed])
+          ])
         ],
         [
           FC_NO_CLIENT([win32], [zlib is needed])
         ])
+      ])
     else
       FC_NO_CLIENT([win32], [mingw32 is needed])
     fi
diff -Nurd -X.diff_ignore freeciv/m4/xaw-client.m4 freeciv/m4/xaw-client.m4
--- freeciv/m4/xaw-client.m4	2007-09-14 14:44:03.000000000 +0300
+++ freeciv/m4/xaw-client.m4	2008-05-13 01:05:27.000000000 +0300
@@ -22,11 +22,25 @@
     fi
 
     dnl Check for libpng
-    AC_CHECK_LIB(png, png_read_image, [X_LIBS="$X_LIBS -lpng -lm"],
-	AC_MSG_ERROR([Could not find PNG library (libpng).]), [-lm -lz])
-    AC_CHECK_HEADER(png.h, ,
+    PKG_CHECK_MODULES([PNG], [libpng],
+    [
+      X_LIBS="$X_LIBS $PNG_LIBS"
+      X_CFLAGS="$X_CFLAGS $PNG_CFLAGS"
+    ],
+    [
+      AC_CHECK_LIB([png12], [png_read_image], [X_LIBS="$X_LIBS -lpng12 -lm"],
+      [
+        AC_CHECK_LIB([png], [png_read_image], [X_LIBS="$X_LIBS -lpng -lm"],
+        [
+          AC_MSG_ERROR([Could not find PNG library.])
+        ])
+      ])
+      AC_CHECK_HEADER([png.h],,
+      [
 	AC_MSG_ERROR([libpng found but not png.h.
-You may need to install a libpng \"development\" package.]))
+You may need to install a libpng \"development\" package.])
+      ])
+    ])
 
     dnl Try to get additional Xpm paths:
     FC_XPM_PATHS
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to