Improve the debug output system so that it's controlled by the makefile. Also easier to check for debug enable in preprocessor. Add a debug_print_succ macro for outputting success messages

This commit is contained in:
rexy712
2020-09-27 09:32:58 -07:00
parent 78f664c2a5
commit ffa2b06ff2
4 changed files with 51 additions and 18 deletions

View File

@@ -2,28 +2,45 @@
#define OUR_DICK_CONFIG_HPP
//multiple levels just so i can stop alsa errors without stopping everything else
#define OUR_DICK_DEBUG 1
#define OUR_DICK_ENABLE_COLOR_DEBUG
#ifdef OUR_DICK_DEBUG
#define OUR_DICK_ENABLE_DEBUG_OUTPUT_LEVEL OUR_DICK_DEBUG
#else
#define OUR_DICK_ENABLE_DEBUG_OUTPUT_LEVEL 0
#endif
#if OUR_DICK_ENABLE_DEBUG_OUTPUT_LEVEL > 0
#define OUR_DICK_ENABLE_DEBUG_OUTPUT
#endif
#if OUR_DICK_ENABLE_DEBUG_OUTPUT_LEVEL > 1
#define OUR_DICK_ENABLE_DEBUG_VERBOSE_OUTPUT
#endif
#ifdef OUR_DICK_ENABLE_DEBUG_OUTPUT
#include <cstdio>
#define debug_print(...) (fprintf(stderr, __FILE__":%s:%d: ", __func__, __LINE__), fprintf(stderr, __VA_ARGS__))
#ifdef OUR_DICK_ENABLE_COLOR_DEBUG
#define OUR_DICK_DEBUG_PRINT_RED "\033[38;5;9m"
#define OUR_DICK_DEBUG_PRINT_YEL "\033[38;5;11m"
#define OUR_DICK_DEBUG_PRINT_YELLOW "\033[38;5;11m"
#define OUR_DICK_DEBUG_PRINT_GREEN "\033[38;5;2m"
#define OUR_DICK_DEBUG_PRINT_CLEAR "\033[0m"
#define debug_print_error(...) (fprintf(stderr, OUR_DICK_DEBUG_PRINT_RED __FILE__ ":%s:%d: ", __func__, __LINE__), fprintf(stderr, __VA_ARGS__), fprintf(stderr, OUR_DICK_DEBUG_PRINT_CLEAR))
#define debug_print_warn(...) (fprintf(stderr, OUR_DICK_DEBUG_PRINT_YEL __FILE__ ":%s:%d: ", __func__, __LINE__), fprintf(stderr, __VA_ARGS__), fprintf(stderr, OUR_DICK_DEBUG_PRINT_CLEAR))
#define debug_print_warn(...) (fprintf(stderr, OUR_DICK_DEBUG_PRINT_YELLOW __FILE__ ":%s:%d: ", __func__, __LINE__), fprintf(stderr, __VA_ARGS__), fprintf(stderr, OUR_DICK_DEBUG_PRINT_CLEAR))
#define debug_print_succ(...) (fprintf(stderr, OUR_DICK_DEBUG_PRINT_GREEN __FILE__ ":%s:%d: ", __func__, __LINE__), fprintf(stderr, __VA_ARGS__), fprintf(stderr, OUR_DICK_DEBUG_PRINT_CLEAR))
#else
#define debug_print_error(...) debug_print(__VA_ARGS__)
#define debug_print_warn(...) debug_print(__VA_ARGS__)
#define debug_print_succ(...) debug_print(__VA_ARGS__)
#endif
#else
#define debug_print(...)
#define debug_print_error(...)
#define debug_print_warn(...)
#define debug_print_succ(...)
#endif
#endif

View File

@@ -23,10 +23,12 @@ SOURCE_DIRS::=src src/audio src/audio/impl src/graphics src/engine
SOURCES::=
OBJDIR::=obj
DEPDIR::=$(OBJDIR)/dep
LIBDIRS::=
LIBDIRS::=lib
INCLUDE_DIRS::=include
CFLAGS::=-std=c18 -Wall -pedantic -Wextra
CXXFLAGS::=-std=c++17 -Wall -pedantic -Wextra
DEBUG_CFLAGS::=
DEBUG_CXXFLAGS::=-DOUR_DICK_DEBUG=1
EXT::=cpp
LANG::=$(EXT)
MAIN_EXECUTABLE::=tester
@@ -41,6 +43,8 @@ ifneq ($(WINDOWS),1)
CXX::=g++
LDLIBS::=
LDFLAGS::= -lglfw -lglad -ldl -lm -lportaudio -lasound -lsndfile -lpthread
DEBUG_LDLIBS::=
DEBUG_LDFLAGS::=
STRIP::=strip
RANLIB::=ranlib
AR::=ar
@@ -51,8 +55,10 @@ else #windows
MINGW_PREFIX::=x86_64-w64-mingw32-
CC::=$(MINGW_PREFIX)gcc
CXX::=$(MINGW_PREFIX)g++
LDLIBS::=-lglfw -lglad -ldl -lm -lportaudio
LDLIBS::=-lglfw -lglad -ldl -lm -lportaudio -lsndfile -lpthread
LDFLAGS::=
DEBUG_LDLIBS::=
DEBUG_LDFLAGS::=
STRIP::=$(MINGW_PREFIX)strip
RANLIB::=$(MINGW_PREFIX)ranlib
AR::=$(MINGW_PREFIX)ar
@@ -100,13 +106,18 @@ endif
#setup compiler and flags based on language
ifeq ($(LANG),cpp)
COMPILER_FLAGS::=$(CXXFLAGS)
ifneq ($(RELEASE),1)
COMPILER_FLAGS+= $(DEBUG_CXXFLAGS)
endif
COMPILER::=$(CXX)
else ifeq ($(LANG),c)
COMPILER_FLAGS::=$(CFLAGS)
ifneq ($(RELEASE),1)
COMPILER_FLAGS+= $(DEBUG_CFLAGS)
endif
COMPILER::=$(CC)
endif
ifeq ($(RELEASE),1)
#a lot of false strict aliasing warnings from gcc 9
COMPILER_FLAGS+=-O2 -Wno-strict-aliasing
@@ -138,8 +149,13 @@ INTERNAL_LINKFLAGS=$(foreach dir,$(LIBDIRS),-L"$(dir)")
INTERNAL_SOURCES::=$(SOURCES) $(foreach source,$(SOURCE_DIRS),$(foreach ext,$(EXT),$(wildcard $(source)/*.$(ext))))
OBJECTS::=$(addprefix $(OBJDIR)/,$(subst \,.,$(subst /,.,$(addsuffix .o,$(INTERNAL_SOURCES)))))
ALL_COMPILEFLAGS=$(COMPILER_FLAGS) $(INTERNAL_COMPILERFLAGS)
ALL_LINKFLAGS=$(INTERNAL_LINKFLAGS) $(LDFLAGS)
ifeq ($(RELEASE),1)
ALL_LINKFLAGS=$(INTERNAL_LINKFLAGS) $(LDFLAGS)
ALL_LDLIBS=$(LDLIBS)
else
ALL_LINKFLAGS=$(INTERNAL_LINKFLAGS) $(LDFLAGS) $(DEBUG_LDFLAGS)
ALL_LDLIBS=$(LDLIBS) $(DEBUG_LDLIBS)
endif
#just a variable for a newline
define \n
@@ -168,7 +184,7 @@ flags-update: cflags-update ldflags-update
#Link executable
$(MAIN_EXECUTABLE): $(OBJECTS) $(LDFLAGS_TMPFILE)
$(COMPILER) $(OBJECTS) -o "$(basename $@)" $(ALL_LINKFLAGS) $(LDLIBS)
$(COMPILER) $(OBJECTS) -o "$(basename $@)" $(ALL_LINKFLAGS) $(ALL_LDLIBS)
ifeq ($(RELEASE),1)
$(STRIP) --strip-all "$(MAIN_EXECUTABLE)"
endif

View File

@@ -22,12 +22,12 @@
#include <portaudio.h>
#if defined(__gnu_linux__)
#if !defined(OUR_DICK_DEBUG) || OUR_DICK_DEBUG <= 1
#ifdef OUR_DICK_ENABLE_DEBUG_VERBOSE_OUTPUT
#define ENABLE_ALSA_DEBUG
#endif
#endif
#ifdef ENABLE_ALSA_DEBUG
#ifndef ENABLE_ALSA_DEBUG
#include <cstdarg> //va_arg (missing include in alsa headers)
#include <alsa/error.h> //snd_lib_error_set_handler
namespace sfx::detail{
@@ -38,7 +38,7 @@ namespace sfx::detail{
namespace sfx{
pa_system::pa_system(){
#ifdef ENABLE_ALSA_DEBUG
#ifndef ENABLE_ALSA_DEBUG
//silence excessive stderr warnings from alsa
snd_lib_error_set_handler(detail::linux_alsa_error_handler);
#endif

View File

@@ -25,7 +25,7 @@
namespace gfx{
#ifdef OUR_DICK_DEBUG
#ifdef OUR_DICK_ENABLE_DEBUG_OUTPUT
static void APIENTRY our_dick_gl_debug_output(GLenum source, GLenum type, unsigned int /*id*/, GLenum severity,
GLsizei /*length*/, const char* message, const void* /*user_ptr*/)
{
@@ -33,7 +33,7 @@ static void APIENTRY our_dick_gl_debug_output(GLenum source, GLenum type, unsign
const char* typ = "Other";
const char* sev = "Notification";
#if OUR_DICK_DEBUG < 2
#ifndef OUR_DICK_ENABLE_DEBUG_VERBOSE_OUTPUT
if(type != GL_DEBUG_TYPE_ERROR &&
type != GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR &&
(severity == GL_DEBUG_SEVERITY_LOW ||
@@ -143,7 +143,7 @@ static void enable_opengl_debug_context(){
GLFWwindow* current_context = glfwGetCurrentContext();
#if defined(OUR_DICK_DEBUG) && OUR_DICK_DEBUG >= 1
#ifdef OUR_DICK_ENABLE_DEBUG_OUTPUT
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
#else
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_FALSE);
@@ -172,7 +172,7 @@ static void enable_opengl_debug_context(){
}
debug_print("Using opengl profile version %s\n", glGetString(GL_VERSION));
#if defined(OUR_DICK_DEBUG) && OUR_DICK_DEBUG >= 1
#ifdef OUR_DICK_ENABLE_DEBUG_OUTPUT
enable_opengl_debug_context();
#endif
set_swap_interval(m_swap_interval);
@@ -190,7 +190,7 @@ static void enable_opengl_debug_context(){
GLFWwindow* current_context = glfwGetCurrentContext();
#if defined(OUR_DICK_DEBUG) && OUR_DICK_DEBUG >= 1
#ifdef OUR_DICK_ENABLE_DEBUG_OUTPUT
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
#else
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_FALSE);
@@ -220,7 +220,7 @@ static void enable_opengl_debug_context(){
}
debug_print("Using opengl profile version %s\n", glGetString(GL_VERSION));
#if defined(OUR_DICK_DEBUG) && OUR_DICK_DEBUG >= 1
#ifdef OUR_DICK_ENABLE_DEBUG_OUTPUT
enable_opengl_debug_context();
#endif