Index: config/lp.m4
===================================================================
--- config/lp.m4	(revision 1349)
+++ config/lp.m4	(revision 1349)
@@ -0,0 +1,71 @@
+AC_DEFUN([LX_CHECK_GLPK],
+[
+  AC_ARG_WITH([glpk],
+AS_HELP_STRING([--with-glpk@<:@=PREFIX@:>@], [Search for GLPK under PREFIX or under the default search paths if PREFIX is not given @<:@default@:>@])
+AS_HELP_STRING([--without-glpk], [Disable checking for GLPK]),
+              [], [with_glpk=yes])
+
+  AC_ARG_WITH([glpk-includedir],
+AS_HELP_STRING([--with-glpk-includedir=DIR], [Search for GLPK headers in DIR]),
+              [], [with_glpk_includedir=no])
+
+  AC_ARG_WITH([glpk-libdir],
+AS_HELP_STRING([--with-glpk-libdir=DIR], [Search for GLPK libraries in DIR]),
+              [], [with_glpk_libdir=no])
+
+  if test x"$with_glpk" != x"no"; then
+    AC_MSG_CHECKING([for GLPK])
+
+    if test x"$with_glpk_includedir" != x"no"; then
+      GLPK_CFLAGS="-I$with_glpk_includedir"
+    elif test x"$with_glpk" != x"yes"; then
+      GLPK_CFLAGS="-I$with_glpk/include"
+    fi
+
+    if test x"$with_glpk_libdir" != x"no"; then
+      GLPK_LDFLAGS="-L$with_glpk_libdir"
+    elif test x"$with_glpk" != x"yes"; then
+      GLPK_LDFLAGS="-L$with_glpk/lib"
+    fi
+    GLPK_LIBS="-lglpk"
+
+    lx_save_cxxflags="$CXXFLAGS";
+    lx_save_ldflags="$LDFLAGS";
+    lx_save_libs="$LIBS";
+    CXXFLAGS="$GLPK_CFLAGS"
+    LDFLAGS="$GLPK_LDFLAGS"
+    LIBS="$GLPK_LIBS"
+
+    lx_glpk_test_prog='
+      extern "C" {
+      #include <glpk.h>
+      }
+
+      int main(int argc, char* argv[])
+      {
+        LPX *lp;
+        lp = lpx_create_prob();
+        lpx_delete_prob(lp);
+        return 0;
+      }'
+
+    AC_LANG_PUSH(C++)
+    AC_LINK_IFELSE([$lx_glpk_test_prog], [lx_glpk_found=yes], [])
+    AC_LANG_POP(C++)
+
+    CXXFLAGS="$lx_save_cxxflags"
+    LDFLAGS="$lx_save_ldflags"
+    LIBS="$lx_save_libs"
+
+    if test x"$lx_glpk_found" = x"yes"; then
+      AC_DEFINE([HAVE_GLPK], [1], [Define if GLPK was found])
+      AC_MSG_RESULT([found])
+    else
+      AC_MSG_RESULT([not found])
+    fi
+  fi
+  GLPK_LIBS="$GLPK_LDFLAGS $GLPK_LIBS"
+  AC_SUBST(GLPK_CFLAGS)
+  AC_SUBST(GLPK_LIBS)
+  AM_CONDITIONAL([HAVE_GLPK], [test x"$lx_glpk_found" = x"yes"])
+])
Index: configure.ac
===================================================================
--- configure.ac	(revision 1348)
+++ configure.ac	(revision 1349)
@@ -5,5 +5,5 @@
 AC_CONFIG_SRCDIR([src/lemon/invalid.h])
 AM_CONFIG_HEADER([config.h])
-AC_PREREQ(2.57)
+AC_PREREQ([2.53])
 
 dnl Checks for programs.
@@ -13,10 +13,10 @@
 AC_PROG_LIBTOOL
 
-dnl I know this is not perfect. A better solution will come soon.
 if test $CXX != icc -a $CXX != icpc; then
-  CXXFLAGS="$CXXFLAGS -Wall"
+  CXXFLAGS="$CXXFLAGS -Wall -W"
 fi
 
 dnl Checks for libraries.
+LX_CHECK_GLPK
 
 dnl Checks for header files.
@@ -46,3 +46,4 @@
 src/test/Makefile
 ])
+
 AC_OUTPUT
Index: src/demo/Makefile.am
===================================================================
--- src/demo/Makefile.am	(revision 1342)
+++ src/demo/Makefile.am	(revision 1349)
@@ -1,23 +1,31 @@
 AM_CPPFLAGS = -I$(top_srcdir)/src
 LDADD = $(top_builddir)/src/lemon/libemon.la
+
 EXTRA_DIST = sub_graph_wrapper_demo.dim
 
-noinst_PROGRAMS = 	dim_to_dot 					\
-			sub_graph_wrapper_demo 				\
-			graph_to_eps_demo 				\
-			lp_demo                                         \
-			dim_to_lgf					\
-			min_route
+noinst_PROGRAMS = \
+	dim_to_dot \
+	dim_to_lgf \
+	graph_to_eps_demo \
+	min_route \
+	sub_graph_wrapper_demo
+
+if HAVE_GLPK
+noinst_PROGRAMS += lp_demo
+endif
 
 dim_to_dot_SOURCES = dim_to_dot.cc
-min_route_SOURCES = min_route.cc
 
-sub_graph_wrapper_demo_SOURCES = sub_graph_wrapper_demo.cc \
-	tight_edge_filter_map.h
+dim_to_lgf_SOURCES = dim_to_lgf.cc
 
 graph_to_eps_demo_SOURCES = graph_to_eps_demo.cc
 
-lp_demo_LDADD = $(top_builddir)/src/lemon/libemon.la -lglpk
+min_route_SOURCES = min_route.cc
+
+sub_graph_wrapper_demo_SOURCES = \
+	sub_graph_wrapper_demo.cc \
+	tight_edge_filter_map.h
+
 lp_demo_SOURCES = lp_demo.cc
-
-dim_to_lgf_SOURCES = dim_to_lgf.cc
+lp_demo_CXXFLAGS = $(GLPK_CFLAGS)
+lp_demo_LDFLAGS = $(GLPK_LIBS)
Index: src/lemon/Makefile.am
===================================================================
--- src/lemon/Makefile.am	(revision 1340)
+++ src/lemon/Makefile.am	(revision 1349)
@@ -5,62 +5,68 @@
 
 lib_LTLIBRARIES = libemon.la
-libemon_la_SOURCES =							\
-	lp_base.cc							\
-	lp_glpk.cc							\
+
+libemon_la_SOURCES = \
+	lp_base.cc \
 	lp_skeleton.cc
 
-pkginclude_HEADERS =							\
-	bezier.h							\
-	bfs.h                                                           \
-	dfs.h                                                           \
-	bin_heap.h							\
-	dijkstra.h							\
-	dimacs.h							\
-	error.h  							\
-	fib_heap.h							\
-	full_graph.h							\
-	graph_wrapper.h							\
-	graph_utils.h							\
-	graph_to_eps.h                                                  \
-	invalid.h							\
-	kruskal.h							\
-	list_graph.h							\
-	maps.h								\
-	max_matching.h                                                  \
-	min_cost_flow.h                                                 \
-	suurballe.h                                                     \
-	preflow.h                                                       \
-	path.h                                                          \
-	radix_heap.h                                                    \
-	smart_graph.h							\
-	time_measure.h							\
-	unionfind.h							\
-	xy.h								\
-	concept_check.h							\
-	utility.h							\
-	graph_reader.h							\
-	graph_writer.h							\
-	map_utils.h							\
-	bits/alteration_notifier.h                                      \
-	bits/map_iterator.h						\
-	bits/array_map.h						\
-	bits/default_map.h						\
-	bits/extended_pair.h						\
-	bits/vector_map.h                                               \
-	bits/iterable_graph_extender.h					\
-	bits/extendable_graph_extender.h				\
-	bits/clearable_graph_extender.h					\
-	bits/erasable_graph_extender.h					\
-	bits/undir_graph_extender.h                                     
+if HAVE_GLPK
+libemon_la_SOURCES += lp_glpk.cc
+libemon_la_CXXFLAGS = $(GLPK_CFLAGS)
+libemon_la_LDFLAGS = $(GLPK_LIBS)
+endif
 
-noinst_HEADERS =							\
-	lp_base.h							\
-	lp_glpk.h							\
-	lp_skeleton.h						\
-	concept/graph.h							\
-	concept/graph_component.h					\
-	concept/undir_graph.h						\
-	concept/sym_graph.h						\
-	concept/maps.h							\
-	concept/heap.h							\
+pkginclude_HEADERS = \
+	bezier.h \
+	bfs.h \
+	dfs.h \
+	bin_heap.h \
+	dijkstra.h \
+	dimacs.h \
+	error.h \
+	fib_heap.h \
+	full_graph.h \
+	graph_wrapper.h \
+	graph_utils.h \
+	graph_to_eps.h \
+	invalid.h \
+	kruskal.h \
+	list_graph.h \
+	maps.h \
+	max_matching.h \
+	min_cost_flow.h \
+	suurballe.h \
+	preflow.h \
+	path.h \
+	radix_heap.h \
+	smart_graph.h \
+	time_measure.h \
+	unionfind.h \
+	xy.h \
+	concept_check.h \
+	utility.h \
+	graph_reader.h \
+	graph_writer.h \
+	map_utils.h \
+	bits/alteration_notifier.h \
+	bits/map_iterator.h \
+	bits/array_map.h \
+	bits/default_map.h \
+	bits/extended_pair.h \
+	bits/vector_map.h \
+	bits/iterable_graph_extender.h \
+	bits/extendable_graph_extender.h \
+	bits/clearable_graph_extender.h \
+	bits/erasable_graph_extender.h \
+	bits/undir_graph_extender.h
+
+noinst_HEADERS = \
+	lp_base.h \
+	lp_glpk.h \
+	lp_skeleton.h \
+	concept/graph.h \
+	concept/graph_component.h \
+	concept/undir_graph.h \
+	concept/sym_graph.h \
+	concept/maps.h \
+	concept/heap.h \
 	concept/path.h
Index: src/test/Makefile.am
===================================================================
--- src/test/Makefile.am	(revision 1324)
+++ src/test/Makefile.am	(revision 1349)
@@ -3,4 +3,5 @@
 
 EXTRA_DIST = preflow_graph.dim dijkstra_test.lgf
+
 noinst_HEADERS = \
 	test_tools.h \
@@ -19,7 +20,6 @@
 	graph_utils_test \
 	kruskal_test \
-	lp_test \
-        max_matching_test \
-        maps_test \
+	max_matching_test \
+	maps_test \
 	min_cost_flow_test \
 	suurballe_test \
@@ -33,4 +33,8 @@
 	xy_test \
 	heap_test
+
+if HAVE_GLPK
+check_PROGRAMS += lp_test
+endif
 
 TESTS = $(check_PROGRAMS)
@@ -58,5 +62,5 @@
 heap_test_SOURCES = heap_test.cc
 
-lp_test_LDADD = $(top_builddir)/src/lemon/libemon.la -lglpk
 lp_test_SOURCES = lp_test.cc
-
+lp_test_CXXFLAGS = $(GLPK_CFLAGS)
+lp_test_LDFLAGS = $(GLPK_LIBS)
