This adds a configure option, --enable-gcc-compile-warnings which controls which CFLAGS to pass to gcc. It defaults to -Wall but can with the configure argument be turned to different levels.
Signed-off-by: Anton Lundin glance@acc.umu.se ---
I think i kinda over-did-it, but hey.
I had something quite close laying around from another project so i picked the whole thingie.
configure.ac | 26 ++++++++++++++++++++++++++ examples/Makefile.am | 2 +- src/Makefile.am | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac index 047b3f0..78de1df 100644 --- a/configure.ac +++ b/configure.ac @@ -28,6 +28,32 @@ LT_PREREQ([2.2.0]) LT_INIT([win32-dll]) LT_PROG_RC
+# If were running gcc, give the option for some warnings, and enable -Wall by default +WARNING_CFLAGS="" +AC_ARG_ENABLE([gcc-compile-warnings], + [AS_HELP_STRING([--enable-gcc-compile-warnings=@<:@no/yes/maximum/error@:>@], + [Turn on compiler warnings @<:@default=yes@:>@])], + [case "$enableval" in + no) + ;; + '' | yes) + WARNING_CFLAGS="-Wall" + ;; + maximum) + WARNING_CFLAGS="-Wall -Wextra -pedantic" + ;; + error) + WARNING_CFLAGS="-Wall -Werror -Wextra -pedantic" + ;; + *) + AC_MSG_ERROR([Unknown argument '$enableval' to --enable-gcc-compile-warnings]) + ;; + esac], + [WARNING_CFLAGS="-Wall"]) +AS_IF([test "x$GCC" = "xyes"], [ + AC_SUBST([WARNING_CFLAGS]) +]) + # Logging support. AC_ARG_ENABLE([logging], [AS_HELP_STRING([--enable-logging=@<:@yes/no@:>@], diff --git a/examples/Makefile.am b/examples/Makefile.am index d77db45..32a5e72 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,4 +1,4 @@ -AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include +AM_CPPFLAGS = $(WARNING_CFLAGS) -I$(top_builddir)/include -I$(top_srcdir)/include LDADD = $(top_builddir)/src/libdivecomputer.la
bin_PROGRAMS = \ diff --git a/src/Makefile.am b/src/Makefile.am index 821bc1b..1c110b8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -AM_CFLAGS = $(LIBUSB_CFLAGS) +AM_CFLAGS = $(WARNING_CFLAGS) $(LIBUSB_CFLAGS)
lib_LTLIBRARIES = libdivecomputer.la
On 2015-01-06 23:28, Anton Lundin wrote:
This adds a configure option, --enable-gcc-compile-warnings which controls which CFLAGS to pass to gcc. It defaults to -Wall but can with the configure argument be turned to different levels.
Signed-off-by: Anton Lundin glance@acc.umu.se
I think i kinda over-did-it, but hey.
I had something quite close laying around from another project so i picked the whole thingie.
You don't really need a new option to use specific CFLAGS (or others). Just pass them to the configure script (or make) directly:
./configure CFLAGS='...'
or
make CFLAGS='...'
I always build with -Wall -Wextra -pedantic using the first variant (which means I only have to set the right options once).
Jef
On 08 January, 2015 - Jef Driesen wrote:
On 2015-01-06 23:28, Anton Lundin wrote:
This adds a configure option, --enable-gcc-compile-warnings which controls which CFLAGS to pass to gcc. It defaults to -Wall but can with the configure argument be turned to different levels.
Signed-off-by: Anton Lundin glance@acc.umu.se
I think i kinda over-did-it, but hey.
I had something quite close laying around from another project so i picked the whole thingie.
You don't really need a new option to use specific CFLAGS (or others). Just pass them to the configure script (or make) directly:
./configure CFLAGS='...'
or
make CFLAGS='...'
I always build with -Wall -Wextra -pedantic using the first variant (which means I only have to set the right options once).
Yes, i know, but its usually good practise to make sure a -Wall is there by default. Thats why i wrote this one.
//Anton
On 08 January, 2015 - Anton Lundin wrote:
On 08 January, 2015 - Jef Driesen wrote:
On 2015-01-06 23:28, Anton Lundin wrote:
This adds a configure option, --enable-gcc-compile-warnings which controls which CFLAGS to pass to gcc. It defaults to -Wall but can with the configure argument be turned to different levels.
Signed-off-by: Anton Lundin glance@acc.umu.se
I think i kinda over-did-it, but hey.
I had something quite close laying around from another project so i picked the whole thingie.
You don't really need a new option to use specific CFLAGS (or others). Just pass them to the configure script (or make) directly:
./configure CFLAGS='...'
or
make CFLAGS='...'
I always build with -Wall -Wextra -pedantic using the first variant (which means I only have to set the right options once).
Yes, i know, but its usually good practise to make sure a -Wall is there by default. Thats why i wrote this one.
I still would like to see such flags added by default. Yes, you can enable them yourself, but as noted earlier, the conception of this patch was due to that it would ease development to have them enabled by default.
Do you disagree?
//Anton