diff --git a/Makefile.inc.in b/Makefile.inc.in
index 62178ddab1d7ac13e217348e78ce5a39d81e8e0c..e5f3ad51a0483974dbcf77d9a1a60e417e9c480b 100644
--- a/Makefile.inc.in
+++ b/Makefile.inc.in
@@ -68,6 +68,8 @@ CXXFLAGS_WX        = @WX_CXXFLAGS@
 CPPFLAGS_WX        = @WX_CPPFLAGS@
 LIBS_WX            = @WX_LIBS@ -lz
 
+LIBS_AGG           = @AGG_LIBS@
+
 CPPFLAGS_BOOST     = @BOOST_CPPFLAGS@
 LIBS_BOOST         = @BOOST_LDFLAGS@ @BOOST_FILESYSTEM_LIB@ @BOOST_LOCALE_LIB@ @BOOST_REGEX_LIB@ @BOOST_SYSTEM_LIB@ @BOOST_THREAD_LIB@ @BOOST_CHRONO_LIB@
 
diff --git a/assdraw/Makefile b/assdraw/Makefile
index 23f2479d6794bd31fc11af144b539dba437092b4..e5c66c448a0b2f73bda40256d561a5dfb2314bf7 100644
--- a/assdraw/Makefile
+++ b/assdraw/Makefile
@@ -41,4 +41,4 @@ assdraw_SOURCES := \
 assdraw_CPPFLAGS := -I$(d)
 assdraw_CXXFLAGS := $(CXXFLAGS_WX)
 assdraw_OBJ      := $(assdraw_SOURCES:.cpp=.o)
-assdraw_LIBS     := $(LIBS_WX)
+assdraw_LIBS     := $(LIBS_WX) $(LIBS_AGG)
diff --git a/configure.ac b/configure.ac
index f32d3d58d9b3942191c6e3eef4e8329bfef036f9..4dc7923b82f390c1b848c7c6488fa0d8b37f3448 100644
--- a/configure.ac
+++ b/configure.ac
@@ -343,6 +343,25 @@ int main(void) {
 AS_IF([test x$agi_cv_with_iconv_const = xyes],
       [AC_DEFINE(AGI_ICONV_CONST, 1, [Enable if iconv expects the in argument to be const])])
 
+######
+## agg
+######
+if test "x$build_linux" = "xyes"
+then
+    AC_CHECK_HEADERS([agg2/agg_config.h], [], [not_found_agg="yes"], [
+#ifdef HAVE_FOO_H
+# include <agg2/agg_config.h>
+#endif
+    ])
+    AS_IF([test "x$not_found_agg" = "xyes"], [
+        AC_MSG_ERROR([con't find agg2, it's needed to compile assdraw])
+    ], [
+        AC_MSG_NOTICE([agg2 was found, will compile assdraw])
+    ])
+    AGG_LIBS=${AGG_LIBS:--lagg}
+    AC_SUBST(AGG_LIBS)
+fi
+
 ###############
 # Audio Players
 ###############