diff --git a/Makefile b/Makefile index 57a5067..4def202 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ INCLUDES := source #------------------------------------------------------------------------------- # options for code generation #------------------------------------------------------------------------------- -CFLAGS := -g -Wall -O3 -ffunction-sections -fno-exceptions -fno-rtti\ +CFLAGS := -Wall -O2 -ffunction-sections -fno-exceptions -fno-rtti\ $(MACHDEP) CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ @@ -41,6 +41,11 @@ CXXFLAGS := $(CFLAGS) -std=c++20 ASFLAGS := -g $(ARCH) LDFLAGS = -g $(ARCH) $(RPXSPECS) --entry=_start -Wl,-Map,$(notdir $*.map) +ifeq ($(DEBUG),1) +CXXFLAGS += -DDEBUG -g +CCFLAGS += -DDEBUG -g +endif + LIBS := -lwut -lz #------------------------------------------------------------------------------- diff --git a/source/main.cpp b/source/main.cpp index cb63497..c9df18a 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -3,9 +3,6 @@ #include #include #include -#include -#include -#include #include "fs/DirList.h" #include "module/ModuleDataPersistence.h" @@ -18,10 +15,7 @@ extern "C" uint32_t textStart(); extern "C" void __fini(); int main(int argc, char **argv) { - if (!WHBLogModuleInit()) { - WHBLogCafeInit(); - WHBLogUdpInit(); - } + initLogging(); // We subtract 0x100 to be safe. uint32_t textSectionStart = textStart() - 0x100; @@ -52,8 +46,6 @@ int main(int argc, char **argv) { SetupRelocator(); - WHBLogUdpDeinit(); - nn::act::Initialize(); nn::act::SlotNo slot = nn::act::GetSlotNo(); nn::act::SlotNo defaultSlot = nn::act::GetDefaultAccount(); @@ -65,6 +57,8 @@ int main(int argc, char **argv) { _SYSLaunchMenuWithCheckingAccount(slot); } + deinitLogging(); + __fini(); return 0; } diff --git a/source/utils/logger.c b/source/utils/logger.c new file mode 100644 index 0000000..4862f1d --- /dev/null +++ b/source/utils/logger.c @@ -0,0 +1,37 @@ +#ifdef DEBUG +#include +#include +#include +#include + + +uint32_t moduleLogInit = false; +uint32_t cafeLogInit = false; +uint32_t udpLogInit = false; +#endif // DEBUG + +void initLogging() { +#ifdef DEBUG + if (!(moduleLogInit = WHBLogModuleInit())) { + cafeLogInit = WHBLogCafeInit(); + udpLogInit = WHBLogUdpInit(); + } +#endif // DEBUG +} + +void deinitLogging() { +#ifdef DEBUG + if (moduleLogInit) { + WHBLogMffoduleDeinit(); + moduleLogInit = false; + } + if (cafeLogInit) { + WHBLogCafeDeinit(); + cafeLogInit = false; + } + if (udpLogInit) { + WHBLogUdpDeinit(); + udpLogInit = false; + } +#endif // DEBUG +} \ No newline at end of file diff --git a/source/utils/logger.h b/source/utils/logger.h index efeda1b..5b1bd51 100644 --- a/source/utils/logger.h +++ b/source/utils/logger.h @@ -7,6 +7,8 @@ extern "C" { #endif +#ifdef DEBUG + #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) @@ -18,6 +20,18 @@ extern "C" { WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ } while (0) +#else + +#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0) + +#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0) + +#endif + +void initLogging(); + +void deinitLogging(); + #ifdef __cplusplus } #endif