From 657080a7e55843e351fa6ce41e4ce315eab62b67 Mon Sep 17 00:00:00 2001 From: NRK Date: Tue, 9 May 2023 00:34:28 +0000 Subject: config.mk: default to `-O2` and `-DNDEBUG` (#435) assertions are for debugging purposes, and so shouldn't be enabled for "release" builds. disable it by default by using `-DNDEBUG`. `-O2` on gcc/clang will result it slightly better binary. on tcc it'll be ignored. and since -O is specified by POSIX there shouldn't be any portability concern. additionally add a (commented out) recommended debug build for gcc/clang with address and undefined sanitizers turned on. Closes: https://codeberg.org/nsxiv/nsxiv/issues/424 Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/435 Reviewed-by: explosion-mental Reviewed-by: eylles --- config.mk | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'config.mk') diff --git a/config.mk b/config.mk index fdd50a8..44ec692 100644 --- a/config.mk +++ b/config.mk @@ -23,8 +23,11 @@ HAVE_LIBWEBP = $(OPT_DEP_DEFAULT) # Compiler and linker CC = c99 -# CFLAGS, any optimization flags goes here -CFLAGS = -Wall -pedantic +# CFLAGS, any additional compiler flags goes here +CFLAGS = -Wall -pedantic -O2 -DNDEBUG +# Uncomment for a debug build using gcc/clang +# CFLAGS = -Wall -pedantic -g3 -fsanitize=address,undefined +# LDFLAGS = $(CFLAGS) # icons that will be installed via `make icon` ICONS = 16x16.png 32x32.png 48x48.png 64x64.png 128x128.png -- cgit v1.2.3 From 40480596cad8654dca225e7fb136f4151f5df5c0 Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 26 May 2023 07:06:17 +0000 Subject: make assertions opt-in (#447) slight addendum to 657080a7e55843e351fa6ce41e4ce315eab62b67 instead of disabling asserts by adding -DNDEBUG to config.mk, this disables asserts by default in the source code itself. this way, if someone compiles with `make CFLAGS="-O3 -march=native"` without knowing about asserts/-DNDEBUG then he won't accidentally get a build with assertions in it. this basically makes the assertions opt-in, if someone wants it, he'll need to *explicitly* set `-DDEBUG` to get it. so that it's not possible to accidentally end up with assertions enabled. Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/447 Reviewed-by: TAAPArthur --- config.mk | 2 +- nsxiv.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'config.mk') diff --git a/config.mk b/config.mk index 44ec692..20bb2b2 100644 --- a/config.mk +++ b/config.mk @@ -26,7 +26,7 @@ CC = c99 # CFLAGS, any additional compiler flags goes here CFLAGS = -Wall -pedantic -O2 -DNDEBUG # Uncomment for a debug build using gcc/clang -# CFLAGS = -Wall -pedantic -g3 -fsanitize=address,undefined +# CFLAGS = -Wall -pedantic -DDEBUG -g3 -fsanitize=address,undefined # LDFLAGS = $(CFLAGS) # icons that will be installed via `make icon` diff --git a/nsxiv.h b/nsxiv.h index 8011f9e..7e373c2 100644 --- a/nsxiv.h +++ b/nsxiv.h @@ -20,6 +20,10 @@ #ifndef NSXIV_H #define NSXIV_H +#if !defined(DEBUG) && !defined(NDEBUG) + #define NDEBUG +#endif + #include #include -- cgit v1.2.3