--- a/libcli/util/doserr.c
+++ b/libcli/util/doserr.c
@@ -28,6 +28,7 @@ struct werror_code_struct {
 
 static const struct werror_code_struct dos_errs[] =
 {
+#ifdef VERBOSE_ERROR
 	{ "WERR_OK", WERR_OK },
 	{ "WERR_BADFILE", WERR_BADFILE },
 	{ "WERR_ACCESS_DENIED", WERR_ACCESS_DENIED },
@@ -2668,6 +2669,7 @@ static const struct werror_code_struct d
 	{ "WERR_AMBIGUOUS_SYSTEM_DEVICE", WERR_AMBIGUOUS_SYSTEM_DEVICE },
 	{ "WERR_SYSTEM_DEVICE_NOT_FOUND", WERR_SYSTEM_DEVICE_NOT_FOUND },
 	/* END GENERATED-WIN32-ERROR-CODES */
+#endif
 	{ NULL, W_ERROR(0) }
 };
 
@@ -2684,12 +2686,14 @@ const char *win_errstr(WERROR werror)
         static char msg[40];
         int idx = 0;
 
+#ifdef VERBOSE_ERROR
 	while (dos_errs[idx].dos_errstr != NULL) {
 		if (W_ERROR_V(dos_errs[idx].werror) == 
                     W_ERROR_V(werror))
                         return dos_errs[idx].dos_errstr;
 		idx++;
 	}
+#endif
 
 	slprintf(msg, sizeof(msg), "DOS code 0x%08x", W_ERROR_V(werror));
 
@@ -2702,6 +2706,7 @@ struct werror_str_struct {
 };
 
 const struct werror_str_struct dos_err_strs[] = {
+#ifdef VERBOSE_ERROR
 	{ WERR_OK, "Success" },
 	{ WERR_ACCESS_DENIED, "Access is denied" },
 	{ WERR_INVALID_PARAM, "Invalid parameter" },
@@ -5324,6 +5329,7 @@ const struct werror_str_struct dos_err_s
 	{ WERR_AMBIGUOUS_SYSTEM_DEVICE, "The requested system device cannot be identified due to multiple indistinguishable devices potentially matching the identification criteria." },
 	{ WERR_SYSTEM_DEVICE_NOT_FOUND, "The requested system device cannot be found." },
 	/* END GENERATED-WIN32-ERROR-CODES-DESC */
+#endif
 };
 
 
@@ -5334,6 +5340,7 @@ const struct werror_str_struct dos_err_s
 
 const char *get_friendly_werror_msg(WERROR werror)
 {
+#ifdef VERBOSE_ERROR
 	int i = 0;
 
 	for (i = 0; i < ARRAY_SIZE(dos_err_strs); i++) {
@@ -5342,6 +5349,7 @@ const char *get_friendly_werror_msg(WERR
 			return dos_err_strs[i].friendly_errstr;
 		}
 	}
+#endif
 
 	return win_errstr(werror);
 }
--- a/librpc/ndr/libndr.h
+++ b/librpc/ndr/libndr.h
@@ -604,4 +604,20 @@ _PUBLIC_ enum ndr_err_code ndr_push_enum
 
 _PUBLIC_ void ndr_print_bool(struct ndr_print *ndr, const char *name, const bool b);
 
+#ifndef VERBOSE_ERROR
+#define ndr_print_bool(...) do {} while (0)
+#define ndr_print_struct(...) do {} while (0)
+#define ndr_print_null(...) do {} while (0)
+#define ndr_print_enum(...) do {} while (0)
+#define ndr_print_bitmap_flag(...) do {} while (0)
+#define ndr_print_ptr(...) do {} while (0)
+#define ndr_print_union(...) do {} while (0)
+#define ndr_print_bad_level(...) do {} while (0)
+#define ndr_print_array_uint8(...) do {} while (0)
+#define ndr_print_string_array(...) do {} while (0)
+#define ndr_print_string_array(...) do {} while (0)
+#define ndr_print_NTSTATUS(...) do {} while (0)
+#define ndr_print_WERROR(...) do {} while (0)
+#endif
+
 #endif /* __LIBNDR_H__ */
--- a/librpc/ndr/ndr_basic.c
+++ b/librpc/ndr/ndr_basic.c
@@ -31,6 +31,19 @@
 #define NDR_SIVAL(ndr, ofs, v) do { if (NDR_BE(ndr))  { RSIVAL(ndr->data,ofs,v); } else SIVAL(ndr->data,ofs,v); } while (0)
 #define NDR_SIVALS(ndr, ofs, v) do { if (NDR_BE(ndr))  { RSIVALS(ndr->data,ofs,v); } else SIVALS(ndr->data,ofs,v); } while (0)
 
+#undef ndr_print_bool
+#undef ndr_print_struct
+#undef ndr_print_null
+#undef ndr_print_enum
+#undef ndr_print_bitmap_flag
+#undef ndr_print_ptr
+#undef ndr_print_union
+#undef ndr_print_bad_level
+#undef ndr_print_array_uint8
+#undef ndr_print_string_array
+#undef ndr_print_string_array
+#undef ndr_print_NTSTATUS
+#undef ndr_print_WERROR
 
 /*
   check for data leaks from the server by looking for non-zero pad bytes
--- a/librpc/ndr/ndr_string.c
+++ b/librpc/ndr/ndr_string.c
@@ -588,6 +588,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_stri
 	return NDR_ERR_SUCCESS;
 }
 
+#undef ndr_print_string_array
 _PUBLIC_ void ndr_print_string_array(struct ndr_print *ndr, const char *name, const char **a)
 {
 	uint32_t count;
--- a/librpc/rpc/dcerpc_error.c
+++ b/librpc/rpc/dcerpc_error.c
@@ -31,6 +31,7 @@ struct dcerpc_fault_table {
 static const struct dcerpc_fault_table dcerpc_faults[] =
 {
 #define _FAULT_STR(x) { #x , x }
+#ifdef VERBOSE_ERROR
 	_FAULT_STR(DCERPC_NCA_S_COMM_FAILURE),
 	_FAULT_STR(DCERPC_NCA_S_OP_RNG_ERROR),
 	_FAULT_STR(DCERPC_NCA_S_UNKNOWN_IF),
@@ -78,6 +79,7 @@ static const struct dcerpc_fault_table d
 	_FAULT_STR(DCERPC_NCA_S_FAULT_CODESET_CONV_ERROR),
 	_FAULT_STR(DCERPC_NCA_S_FAULT_OBJECT_NOT_FOUND),
 	_FAULT_STR(DCERPC_NCA_S_FAULT_NO_CLIENT_STUB),
+#endif
 	{ NULL, 0 }
 #undef _FAULT_STR
 };
@@ -87,12 +89,14 @@ _PUBLIC_ const char *dcerpc_errstr(TALLO
 	int idx = 0;
 	WERROR werr = W_ERROR(fault_code);
 
+#ifdef VERBOSE_ERROR
 	while (dcerpc_faults[idx].errstr != NULL) {
 		if (dcerpc_faults[idx].faultcode == fault_code) {
 			return dcerpc_faults[idx].errstr;
 		}
 		idx++;
 	}
+#endif
 
 	return win_errstr(werr);
 }
--- a/source3/libsmb/nterr.c
+++ b/source3/libsmb/nterr.c
@@ -702,6 +702,7 @@ const char *nt_errstr(NTSTATUS nt_code)
 					NT_STATUS_DOS_CODE(nt_code));
 	}
 
+#ifdef VERBOSE_ERROR
 	while (nt_errs[idx].nt_errstr != NULL) {
 		if (NT_STATUS_V(nt_errs[idx].nt_errcode) ==
 		    NT_STATUS_V(nt_code)) {
@@ -709,6 +710,7 @@ const char *nt_errstr(NTSTATUS nt_code)
 		}
 		idx++;
 	}
+#endif
 
 	result = talloc_asprintf(talloc_tos(), "NT code 0x%08x",
 				 NT_STATUS_V(nt_code));
@@ -724,12 +726,14 @@ const char *get_friendly_nt_error_msg(NT
 {
 	int idx = 0;
 
+#ifdef VERBOSE_ERROR
 	while (nt_err_desc[idx].nt_errstr != NULL) {
 		if (NT_STATUS_V(nt_err_desc[idx].nt_errcode) == NT_STATUS_V(nt_code)) {
 			return nt_err_desc[idx].nt_errstr;
 		}
 		idx++;
 	}
+#endif
 
 	/* fall back to NT_STATUS_XXX string */
 
@@ -745,6 +749,7 @@ const char *get_nt_error_c_code(NTSTATUS
 	char *result;
 	int idx = 0;
 
+#ifdef VERBOSE_ERROR
 	while (nt_errs[idx].nt_errstr != NULL) {
 		if (NT_STATUS_V(nt_errs[idx].nt_errcode) ==
 		    NT_STATUS_V(nt_code)) {
@@ -752,6 +757,7 @@ const char *get_nt_error_c_code(NTSTATUS
 		}
 		idx++;
 	}
+#endif
 
 	result = talloc_asprintf(talloc_tos(), "NT_STATUS(0x%08x)",
 				 NT_STATUS_V(nt_code));
@@ -767,12 +773,14 @@ NTSTATUS nt_status_string_to_code(const
 {
 	int idx = 0;
 
+#ifdef VERBOSE_ERROR
 	while (nt_errs[idx].nt_errstr != NULL) {
 		if (strcasecmp(nt_errs[idx].nt_errstr, nt_status_str) == 0) {
 			return nt_errs[idx].nt_errcode;
 		}
 		idx++;
 	}
+#endif
 	return NT_STATUS_UNSUCCESSFUL;
 }
 
--- a/lib/tdb/common/tdb_private.h
+++ b/lib/tdb/common/tdb_private.h
@@ -69,7 +69,11 @@ typedef uint32_t tdb_off_t;
 /* NB assumes there is a local variable called "tdb" that is the
  * current context, also takes doubly-parenthesized print-style
  * argument. */
+#ifdef VERBOSE_DEBUG
 #define TDB_LOG(x) tdb->log.log_fn x
+#else
+#define TDB_LOG(x) do {} while(0)
+#endif
 
 #ifdef TDB_TRACE
 void tdb_trace(struct tdb_context *tdb, const char *op);
--- a/source3/script/mkbuildoptions.awk
+++ b/source3/script/mkbuildoptions.awk
@@ -55,7 +55,7 @@ BEGIN {
 	print "****************************************************************************/";
 	print "void build_options(bool screen)";
 	print "{";
-	print "       if ((DEBUGLEVEL < 4) && (!screen)) {";
+	print "       if ((DEBUGLEVEL < 4) || (!screen)) {";
 	print "	       return;";
 	print "       }";
 	print "";
--- a/source3/script/mkbuildoptions-waf.awk
+++ b/source3/script/mkbuildoptions-waf.awk
@@ -55,7 +55,7 @@ BEGIN {
 	print "****************************************************************************/";
 	print "void build_options(bool screen)";
 	print "{";
-	print "       if ((DEBUGLEVEL < 4) && (!screen)) {";
+	print "       if ((DEBUGLEVEL < 4) || (!screen)) {";
 	print "	       return;";
 	print "       }";
 	print "";