From 44b7e02721429f7cf9ad72711b96b16ef01f20db Mon Sep 17 00:00:00 2001 From: tbrennan3 Date: Mon, 27 Sep 2010 20:27:29 +0000 Subject: [PATCH] Tweaked the debug building and printing a little - I hope this works OK for everyone. Let me know if not. Tamped down a few warnings. For the demo/server Makefile, made an either/or choice between executable size optimization (normal) or gdb debug info and no optimization. --- bacnet-stack/demo/epics/Makefile | 2 +- bacnet-stack/demo/epics/main.c | 2 +- bacnet-stack/demo/server/Makefile | 18 +++++++++++++----- bacnet-stack/include/debug.h | 7 +++++-- bacnet-stack/lib/Makefile | 2 +- bacnet-stack/src/debug.c | 6 ++++++ 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/bacnet-stack/demo/epics/Makefile b/bacnet-stack/demo/epics/Makefile index 28428395..45103323 100644 --- a/bacnet-stack/demo/epics/Makefile +++ b/bacnet-stack/demo/epics/Makefile @@ -41,7 +41,7 @@ DEBUGGING = OPTIMIZATION = -Os ifeq (${BUILD},debug) OPTIMIZATION = -O0 -DEBUGGING = -g +DEBUGGING = -g -DDEBUG_ENABLED=1 endif # put all the flags together CFLAGS = -Wall $(DEBUGGING) $(OPTIMIZATION) $(INCLUDES) $(DEFINES) diff --git a/bacnet-stack/demo/epics/main.c b/bacnet-stack/demo/epics/main.c index 772fec0e..95b7dc7d 100644 --- a/bacnet-stack/demo/epics/main.c +++ b/bacnet-stack/demo/epics/main.c @@ -903,7 +903,7 @@ int main( bool found = false; BACNET_OBJECT_ID myObject; uint8_t buffer[MAX_PDU] = { 0 }; - BACNET_READ_ACCESS_DATA *rpm_object; + BACNET_READ_ACCESS_DATA *rpm_object = NULL; KEY nextKey; CheckCommandLineArgs(argc, argv); /* Won't return if there is an issue. */ diff --git a/bacnet-stack/demo/server/Makefile b/bacnet-stack/demo/server/Makefile index 9887b7fb..5760cc58 100644 --- a/bacnet-stack/demo/server/Makefile +++ b/bacnet-stack/demo/server/Makefile @@ -37,19 +37,27 @@ LIBRARY1=-L$(BACNET_LIB_DIR),-l$(BACNET_LIB_NAME) LIBRARY2=-lws2_32,-lgcc,-lm,-liphlpapi,-lwinmm LIBRARIES=$(LIBRARY1),$(LIBRARY2) endif + #build for release (default) or debug -DEBUGGING = -OPTIMIZATION = -Os ifeq (${BUILD},debug) +# Use -g to put info for gdb in the executable +DEBUGGING = -g -DDEBUG_ENABLED=1 OPTIMIZATION = -O0 -DEBUGGING = -g +LINK_OPTIMIZATION = ifeq (${BACDL_DEFINE},-DBACDL_BIP=1) DEFINES += -DBIP_DEBUG endif +else +DEBUGGING = +# Use -f optimizations and then link option --gc-sections to reduce executable size. +# Of course, not when you want debug output for gdb! +OPTIMIZATION = -Os -fdata-sections -ffunction-sections +LINK_OPTIMIZATION = -Wl,--gc-sections endif + # put all the flags together -CFLAGS = -Wall $(DEBUGGING) $(OPTIMIZATION) $(INCLUDES) $(DEFINES) -fdata-sections -ffunction-sections -LFLAGS = -Wl,-Map=$(TARGET).map,$(LIBRARIES),--gc-sections +CFLAGS = -Wall $(DEBUGGING) $(OPTIMIZATION) $(INCLUDES) $(DEFINES) +LFLAGS = -Wl,-Map=$(TARGET).map,$(LIBRARIES) $(LINK_OPTIMIZATION) SRCS = main.c diff --git a/bacnet-stack/include/debug.h b/bacnet-stack/include/debug.h index 1362bb8f..1f268119 100644 --- a/bacnet-stack/include/debug.h +++ b/bacnet-stack/include/debug.h @@ -43,16 +43,19 @@ extern "C" { #endif /* __cplusplus */ -#if DEBUG_ENABLED void debug_printf( const char *format, ...); +#if DEBUG_ENABLED + /* Nothing more here */ #else - static void debug_printf( + /* If your compiler supports it, this is more compact: + inline void debug_printf( const char *format, ...) { format = format; } + */ #endif #ifdef __cplusplus } diff --git a/bacnet-stack/lib/Makefile b/bacnet-stack/lib/Makefile index 99fee337..1c477e08 100644 --- a/bacnet-stack/lib/Makefile +++ b/bacnet-stack/lib/Makefile @@ -33,7 +33,7 @@ DEBUGGING = WARNINGS = -Wall -Wmissing-prototypes ifeq (${BUILD},debug) OPTIMIZATION = -O0 -DEBUGGING = -g +DEBUGGING = -g -DDEBUG_ENABLED=1 ifeq (${BACDL_DEFINE},-DBACDL_BIP=1) DEFINES += -DBIP_DEBUG endif diff --git a/bacnet-stack/src/debug.c b/bacnet-stack/src/debug.c index d60ea62f..ab4fb642 100644 --- a/bacnet-stack/src/debug.c +++ b/bacnet-stack/src/debug.c @@ -55,4 +55,10 @@ void debug_printf( return; } +#else +void debug_printf( + const char *format, + ...) { + format = format; +} #endif