lua-resty-lmdb is an external repository, previous artifact may carry
thus we always clean here

diff --git a/config b/config
index 126c78c..1f0b2aa 100644
--- a/config
+++ b/config
@@ -7,6 +7,8 @@ ngx_module_incs="$ngx_addon_dir/lmdb/libraries/liblmdb $ngx_addon_dir/src"

 . auto/module

+rm -f $ngx_addon_dir/lmdb/libraries/liblmdb/liblmdb.a
+
 LINK_DEPS="$LINK_DEPS $ngx_addon_dir/lmdb/libraries/liblmdb/liblmdb.a"
 CORE_LIBS="$CORE_LIBS $ngx_addon_dir/lmdb/libraries/liblmdb/liblmdb.a"

diff --git a/config.make b/config.make
index 14d8cc2..cf17251 100644
--- a/config.make
+++ b/config.make
@@ -3,7 +3,7 @@ cat <<EOF >>$NGX_MAKEFILE

 $ngx_addon_dir/lmdb/libraries/liblmdb/liblmdb.a:
 	echo "Building liblmdb"; \\
-	\$(MAKE) -C $ngx_addon_dir/lmdb/libraries/liblmdb; \\
+	\$(MAKE) -C $ngx_addon_dir/lmdb/libraries/liblmdb CC=\$(CC) AR=\$(AR); \\
 	echo "Finished building liblmdb"

 EOF
diff --git a/libraries/liblmdb/Makefile b/libraries/liblmdb/Makefile
index c252b50..1054432 100644
--- a/lmdb/libraries/liblmdb/Makefile
+++ b/lmdb/libraries/liblmdb/Makefile
@@ -18,11 +18,11 @@
 # There may be other macros in mdb.c of interest. You should
 # read mdb.c before changing any of them.
 #
-CC	= gcc
-AR	= ar
+CC	?= gcc
+AR	?= ar
 W	= -W -Wall -Wno-unused-parameter -Wbad-function-cast -Wuninitialized
 THREADS = -pthread
 OPT = -O2 -g
-CFLAGS	= $(THREADS) $(OPT) $(W) $(XCFLAGS)
+CFLAGS	+= $(THREADS) $(OPT) $(W) $(XCFLAGS)
 LDLIBS	=
 SOLIBS	=
 SOEXT	= .so
