Use -D DEBUG / NDEBUG in Makefiles

Instead of #define DEBUG, we now prefer to use either verbose levels
or, when needed, NDEBUG. Each Makefile was modified to be able to pass
-D NDEBUG to the compiler (but the corresponding lines are commented),
except in the modules where assert is never used, in which case the
Makefile passes -D DEBUG.

Long story short: to totally disable debugging code, comment-out the
"-D DEBUG" lines and uncomment the "-D NDEBUG" lines, in every Makefile.
This commit is contained in:
Matteo Cypriani 2011-07-24 18:58:21 +02:00
parent f008db0e1c
commit 051ce9147c
20 changed files with 25 additions and 17 deletions

1
TODO
View File

@ -1,7 +1,6 @@
* Global
- Makefiles:
° Use -D DEBUG instead of #defines.
° Translate comments & help.
- Use string for network exchanges?
- Mark arguments as const in function headers if needed

View File

@ -23,6 +23,7 @@ OBJS=$(LIB_CIBLE).o
# Flags
LIBOWLPS_DIR = ../libowlps
CFLAGS = -O2 -Wall -Wextra -Wstrict-prototypes -O -I$(LIBOWLPS_DIR)
CFLAGS += -D DEBUG
DEPFLAGS=-MMD
XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
PICFLAG=-fPIC

View File

@ -26,6 +26,7 @@ OBJS=$(LIB_CIBLE).o
# Flags
LIBOWLPS_DIR = ../libowlps
CFLAGS = -O2 -Wall -Wextra -Wstrict-prototypes -O -I$(LIBOWLPS_DIR)
CFLAGS += -D DEBUG
DEPFLAGS=-MMD
XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
PICFLAG=-fPIC

View File

@ -26,6 +26,7 @@ OBJS=$(LIB_CIBLE).o
# Flags
LIBOWLPS_DIR = ../libowlps
CFLAGS = -O2 -Wall -Wextra -Wstrict-prototypes -O -I$(LIBOWLPS_DIR)
CFLAGS += -D DEBUG
DEPFLAGS=-MMD
XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
PICFLAG=-fPIC

View File

@ -7,8 +7,6 @@
#include <sys/param.h>
#define DEBUG
/*

View File

@ -35,6 +35,7 @@ OBJS=$(LIB_CIBLE).o
# Flags
CFLAGS = -O2 -Wall -Wextra -Wstrict-prototypes -O
#CFLAGS += -D NDEBUG
DEPFLAGS=-MMD
XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
PICFLAG=-fPIC

View File

@ -38,6 +38,7 @@ OBJS=$(LIB_CIBLE).o
# Flags
CFLAGS = -O2 -Wall -Wextra -Wstrict-prototypes -O
#CFLAGS += -D NDEBUG
DEPFLAGS=-MMD
XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
PICFLAG=-fPIC

View File

@ -38,6 +38,7 @@ OBJS=$(LIB_CIBLE).o
# Flags
CFLAGS = -O2 -Wall -Wextra -Wstrict-prototypes -O
#CFLAGS += -D NDEBUG
DEPFLAGS=-MMD
XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
PICFLAG=-fPIC

View File

@ -17,7 +17,6 @@
#include <assert.h>
#define DEBUG
owl_bool owl_run = TRUE ;
@ -389,9 +388,9 @@ void owl_sigint_handler(const int num)
owl_run = FALSE ;
#ifdef DEBUG
#ifndef NDEBUG
fprintf(stderr, "\nSignal received: end.\n");
#endif // DEBUG
#endif // NDEBUG
fflush(NULL) ;
}
@ -428,11 +427,11 @@ void owl_close_fd(void *const fd)
const int *const file_desc = fd ;
if (close(*file_desc) != 0)
perror("Error closing file descriptor") ;
#ifdef DEBUG
#ifndef NDEBUG
else
fprintf(stderr, "File descriptor %d closed successfully.\n",
*file_desc) ;
#endif // DEBUG
#endif // NDEBUG
}
@ -452,8 +451,8 @@ void owl_close_file(void *const file)
if (fclose(*stream) != 0)
perror("Error closing stream") ;
#ifdef DEBUG
#ifndef NDEBUG
else
fprintf(stderr, "Stream closed successfully.\n") ;
#endif // DEBUG
#endif // NDEBUG
}

View File

@ -31,6 +31,7 @@ DEPFLAGS=-MMD
XCFLAGS=$(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
PICFLAG=-fPIC
OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\"
#OWLPSFLAGS += -D NDEBUG
LIBS = -pthread -lconfuse -L$(LIBOWLPS_DIR) -lowlps
OS := $(shell uname)

View File

@ -96,10 +96,10 @@ void got_request(owl_captured_request request) ;
void* monitor_requests(void *NULL_value) ;
void free_request_list(void) ;
#ifdef DEBUG
#ifndef NDEBUG
void print_request_list(void) ;
void print_request_info(request_info_list *info) ;
#endif // DEBUG
#endif // NDEBUG
void* listen_for_aps(void *NULL_value) ;
void update_ap(uint8_t mac_addr_bytes[ETHER_ADDR_LEN],

View File

@ -1180,7 +1180,7 @@ void free_ap_list()
#ifdef DEBUG
#ifndef NDEBUG
/*
* Prints the request list.
*/
@ -1259,7 +1259,7 @@ void print_request_info(request_info_list *info)
info->antenna_signal_dbm - 0x100
) ;
}
#endif // DEBUG
#endif // NDEBUG

View File

@ -33,6 +33,7 @@ DEPFLAGS = -MMD
XCFLAGS = $(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
PICFLAG = -fPIC
OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\"
OWLPSFLAGS += -D DEBUG
LIBS = -L$(LIBOWLPS_DIR) -lowlps \
-L$(LIBOWLPSCLIENT_DIR) -lowlps-client

View File

@ -46,6 +46,7 @@ LATHEROS = -L$(TOOLCHAIN_USR)/lib -L$(TOOLCHAIN_USR_2)/lib
IATHEROS = -I$(TOOLCHAIN_USR)/include -I$(TOOLCHAIN_USR_2)/include
LDFLAGS = $(IATHEROS) $(LATHEROS)
OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\"
OWLPSFLAGS += -D DEBUG
## Cibles de compilation standard ##

View File

@ -47,6 +47,7 @@ LATHEROS = -L$(TOOLCHAIN1)/lib -L$(TOOLCHAIN1)/usr/lib \
IATHEROS = -I$(TOOLCHAIN1)/usr/include -I$(TOOLCHAIN2)/usr/include
LDFLAGS = $(IATHEROS) $(LATHEROS)
OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\"
OWLPSFLAGS += -D DEBUG
## Cibles de compilation standard ##

View File

@ -12,7 +12,6 @@
#include <net/if.h>
#define DEBUG
/* Error codes */
#define ERR_BAD_USAGE 1 // Bad program call (bad number of arguments)

View File

@ -34,6 +34,7 @@ XCFLAGS = $(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
PICFLAG = -fPIC
OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\" \
-D USE_CONFIG_FILE -lconfuse -D USE_PTHREAD -pthread
#OWLPSFLAGS += -D NDEBUG
LIBS = -L$(LIBOWLPS_DIR) -lowlps \
-L$(LIBOWLPSCLIENT_DIR) -lowlps-client \
-lpcap -liw

View File

@ -45,6 +45,7 @@ IATHEROS = -I$(TOOLCHAIN_USR)/include -I$(TOOLCHAIN_USR_2)/include
OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\" \
-D USE_PTHREAD -pthread
#OWLPSFLAGS += -D USE_CONFIG_FILE -lconfuse
#OWLPSFLAGS += -D NDEBUG
LDFLAGS = $(OWLPSFLAGS) $(LIBS)

View File

@ -49,6 +49,7 @@ IATHEROS = -I$(TOOLCHAIN1)/usr/include -I$(TOOLCHAIN2)/usr/include
OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\" \
-D USE_PTHREAD -pthread
OWLPSFLAGS += -D USE_CONFIG_FILE -lconfuse
#OWLPSFLAGS += -D NDEBUG
LDFLAGS = $(OWLPSFLAGS) $(LIBS)

View File

@ -1347,10 +1347,10 @@ uint_fast16_t make_packet(uint8_t **packet)
memcpy(&pkt[offset], &my_position_y, sizeof(float)) ;
offset += sizeof(float) ;
memcpy(&pkt[offset], &my_position_z, sizeof(float)) ;
#ifdef DEBUG
#ifndef NDEBUG
offset += sizeof(float) ;
assert(offset == size) ;
#endif // DEBUG
#endif // NDEBUG
*packet = pkt ;
return size ;