--- a/configure.ac
+++ b/configure.ac
@@ -348,11 +348,11 @@ fi
 
 if test "x$debug" = xtrue; then
 	CPPFLAGS="-DDEBUG $CPPFLAGS"
-	CFLAGS=$(echo "$CFLAGS" | sed 's/-g//')
-	CFLAGS="-g $CFLAGS"
+	CFLAGS=$(echo "$CFLAGS" | sed 's/-g[0-9]*//')
+	CFLAGS="-g3 $CFLAGS"
 else
 	CPPFLAGS="-DNDEBUG $CPPFLAGS"
-	CFLAGS=$(echo "$CFLAGS" | sed 's/-O2//;s/-g//')
+	CFLAGS=$(echo "$CFLAGS" | sed 's/-O2//;s/-g[0-9]*//')
 	CFLAGS="-O3 -funroll-loops $CFLAGS"
 fi
 
