diff --git a/configure.ac b/configure.ac
index 17523c15766f0f3fcc84a7c153b8fd971eab3ae5..2ee7673408649464e6fd7369724dabbbf43aa3af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,7 +54,7 @@ PACKAGE_VERSION_NUM=`printf "0x%02x%02x%02x" "$major" "$minor" "$patch"`
 
 AC_SUBST(PACKAGE_VERSION_NUM)
 
-# Checks for command-line options from nghttp2
+# Checks for command-line options from ngtcp2
 AC_ARG_ENABLE([werror],
     [AS_HELP_STRING([--enable-werror],
                     [Turn on compile time warnings])],
@@ -65,6 +65,11 @@ AC_ARG_ENABLE([debug],
                     [Turn on debug output])],
     [debug=$enableval], [debug=no])
 
+if test "x${debug}" = "x${enableval}"; then
+  DEBUGCFLAGS="-Wall -Werror -Wformat -Wfatal-errors -O0 -g3"
+  AC_SUBST([DEBUGCFLAGS])
+fi
+
 # Checks for programs
 AC_PROG_CC
 AC_PROG_CXX
@@ -277,7 +282,7 @@ AC_MSG_NOTICE([summary of build options:
     Test:
       CUnit:          ${have_cunit} (CFLAGS='${CUNIT_CFLAGS}' LIBS='${CUNIT_LIBS}')
     Debug:
-      Debug:          ${debug}
+      Debug:          ${debug} (CFLAGS='${DEBUGCFLAGS}')
     Libs:
       OpenSSL:        ${have_openssl} (CFLAGS='${OPENSSL_CFLAGS}' LIBS='${OPENSSL_LIBS}')
       Libev:          ${have_libev} (CFLAGS='${LIBEV_CFLAGS}' LIBS='${LIBEV_LIBS}')
diff --git a/examples/Makefile.am b/examples/Makefile.am
index eaf03d58ae951e2124995e4847b4706b5c0e216e..7fe37552b256f0e80782e8ca3744ce89a3eb55de 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -21,13 +21,15 @@
 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-AM_CFLAGS = $(WARNCFLAGS)
+AM_CFLAGS = $(WARNCFLAGS) $(DEBUGCFLAGS)
+AM_CXXFLAGS = $(WARNCFLAGS) $(DEBUGCFLAGS)
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/lib/includes \
 	-I$(top_builddir)/lib/includes \
 	@OPENSSL_CFLAGS@ \
 	@LIBEV_CFLAGS@ \
 	@DEFS@
+AM_LDFLAGS = -no-install
 LDADD = $(top_builddir)/lib/libngtcp2.la \
 	@OPENSSL_LIBS@ \
 	@LIBEV_LIBS@
diff --git a/examples/client.cc b/examples/client.cc
index 4d5045d0573963297f8c873e02bea08d304a4231..249d2c99aff02c98c4b7986cd303817c371782c0 100644
--- a/examples/client.cc
+++ b/examples/client.cc
@@ -288,8 +288,6 @@ ssize_t send_client_cleartext(ngtcp2_conn *conn, uint32_t flags,
 namespace {
 int recv_handshake_data(ngtcp2_conn *conn, const uint8_t *data, size_t datalen,
                         void *user_data) {
-  int rv;
-
   auto c = static_cast<Client *>(user_data);
 
   c->write_server_handshake(data, datalen);
@@ -801,7 +799,6 @@ int Client::start_interactive_input() {
 }
 
 int Client::send_interactive_input() {
-  int rv;
   ssize_t nread;
   std::array<uint8_t, 1_k> buf;
 
@@ -823,8 +820,6 @@ int Client::send_interactive_input() {
 }
 
 int Client::stop_interactive_input() {
-  int rv;
-
   should_send_fin_ = true;
   ev_io_stop(loop_, &stdinrev_);
 
@@ -1055,7 +1050,6 @@ int create_sock(Address &remote_addr, const char *addr, const char *port) {
 
 namespace {
 int run(Client &c, const char *addr, const char *port) {
-  int rv;
   Address remote_addr;
 
   auto fd = create_sock(remote_addr, addr, port);
@@ -1110,7 +1104,6 @@ int main(int argc, char **argv) {
   config.fd = -1;
 
   for (;;) {
-    static int flag = 0;
     constexpr static option long_opts[] = {
         {"help", no_argument, nullptr, 'h'},
         {"tx-loss", required_argument, nullptr, 't'},
diff --git a/examples/crypto.cc b/examples/crypto.cc
index 2273c6da620a84ed78ebe594dffaa325c4481261..16186e6ad767280953b7ed397f3bea55bcbcb7b5 100644
--- a/examples/crypto.cc
+++ b/examples/crypto.cc
@@ -100,7 +100,6 @@ int hkdf_expand_label(uint8_t *dest, size_t destlen, const uint8_t *secret,
                       size_t secretlen, const uint8_t *qlabel, size_t qlabellen,
                       const Context &ctx) {
   std::array<uint8_t, 256> info;
-  int rv;
   static constexpr const uint8_t LABEL[] = "tls13 ";
 
   auto p = std::begin(info);
diff --git a/examples/server.cc b/examples/server.cc
index 88f08abb04e1903f0c8b091eca2aa242421c3ba6..7bd1bae303c60e9705e6a6ee4e5e7298aa920440 100644
--- a/examples/server.cc
+++ b/examples/server.cc
@@ -634,7 +634,6 @@ int Handler::on_write() {
 
 int Handler::on_write_stream(Stream &stream) {
   std::array<uint8_t, NGTCP2_MAX_PKTLEN_IPV4> buf;
-  size_t ndatalen;
 
   assert(buf.size() >= max_pktlen_);
 
@@ -765,8 +764,6 @@ void Handler::schedule_retransmit() {
 
 int Handler::recv_stream_data(uint32_t stream_id, uint8_t fin,
                               const uint8_t *data, size_t datalen) {
-  int rv;
-
   debug::print_stream_data(stream_id, data, datalen);
 
   auto it = streams_.find(stream_id);
@@ -776,7 +773,6 @@ int Handler::recv_stream_data(uint32_t stream_id, uint8_t fin,
 
   auto &stream = (*it).second;
 
-  size_t len = 0;
   if (datalen > 0) {
     static constexpr uint8_t start_tag[] = "<blink>";
     static constexpr uint8_t end_tag[] = "</blink>";
@@ -1266,8 +1262,6 @@ int create_sock(const char *addr, const char *port) {
 
 namespace {
 int serve(Server &s, const char *addr, const char *port) {
-  int rv;
-
   auto fd = create_sock(addr, port);
   if (fd == -1) {
     return -1;
@@ -1321,7 +1315,6 @@ int main(int argc, char **argv) {
   config.rx_loss_prob = 0.;
 
   for (;;) {
-    static int flag = 0;
     constexpr static option long_opts[] = {
         {"help", no_argument, nullptr, 'h'},
         {"tx-loss", required_argument, nullptr, 't'},
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 6f9f1a775dca5fbc8925b7f32904acf6985245c3..fe9e9174922a3ddc1364871fd6475c18c2768ecd 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -22,7 +22,7 @@
 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 SUBDIRS = includes
 
-AM_CFLAGS = $(WARNCFLAGS) $(EXTRACFLAG)
+AM_CFLAGS = $(WARNCFLAGS) $(DEBUGCFLAGS) $(EXTRACFLAG)
 AM_CPPFLAGS = -I$(srcdir)/includes -I$(builddir)/includes -DBUILDING_NGTCP2
 
 pkgconfigdir = $(libdir)/pkgconfig
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2323162ca872b3c0bc6aa67a6689b2c24de8d212..f53e4e74f118ac3c4988b466b11f259a0406c067 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -65,6 +65,7 @@ AM_CFLAGS = $(WARNCFLAGS) \
 	-I${top_srcdir}/lib/includes \
 	-I${top_builddir}/lib/includes \
 	@CUNIT_CFLAGS@ @DEFS@
+AM_LDFLAGS = -no-install
 
 TESTS = main