The CFLAGS that are in the %common-strict-cflags in scripts/guix.scm have been validated with both GCC and CLANG and they are useful to find potential issues in the code or code that won't compile on Android.
However while the scripts/guix.scm script is really useful to test commits once they are ready, it is less convenient to use it when fixing issues in commits that are still being worked on. This is because it is not as fast as building libsamsung-ipc directly because: - it requires a clean source directory to work (this can be done with make distclean) so we can't reuse the current build output - libsamsung-ipc source code is copied and built 5 times (in different configurations) As for the implementation, AM_CFLAGS was used instead of appending to the default CFLAGS as CFLAGS is meant to be a variable for users. The effect is that both are independent, so if users don't want strict CFLAGS, they would need to not use --enable-strict-cflags. Signed-off-by: Denis 'GNUtoo' Carikli <gnu...@cyberdimension.org> --- configure.ac | 19 ++++++++- samsung-ipc/Makefile.am | 4 ++ samsung-ipc/tests/Makefile.am | 4 ++ scripts/strict-cflags.scm | 78 +++++++++++++++++++++++++++++++++++ tools/Makefile.am | 4 ++ tools/ipc-modem/Makefile.am | 4 ++ 6 files changed, 111 insertions(+), 2 deletions(-) create mode 100755 scripts/strict-cflags.scm diff --git a/configure.ac b/configure.ac index 1f83a58..32f285b 100644 --- a/configure.ac +++ b/configure.ac @@ -20,6 +20,10 @@ PKG_CHECK_MODULES(OPENSSL, openssl >= $OPENSSL_REQUIRED) AC_SUBST(OPENSSL_CFLAGS) AC_SUBST(OPENSSL_LIBS) +#------------------------------------------------------------------------------ +# strict cflags +AC_SUBST(STRICT_CFLAGS) + #------------------------------------------------------------------------------ # valgrind AC_SUBST(VALGRIND) @@ -38,6 +42,14 @@ AC_ARG_ENABLE(debug, [debug="no"]) AM_CONDITIONAL( [WANT_DEBUG], [test x"$debug" = x"yes"]) +#------------------------------------------------------------------------------ +AC_ARG_ENABLE(strict-cflags, + [AS_HELP_STRING([--enable-strict-cflags], + [Build with strict cflags (default=disabled)])], + [strict_cflags=$enableval], + [strict_cflags="no"]) +AM_CONDITIONAL( [WANT_STRICT_CFLAGS], [test x"$strict_cflags" = x"yes"]) + #------------------------------------------------------------------------------ # TODO: GCC has --enable-checking= for extensive runtime checks and one of the # available values is valgrind, so it would be a good idea to convert to @@ -71,6 +83,10 @@ AC_CONFIG_FILES([ #------------------------------------------------------------------------------ +AS_IF([test x"$strict_cflags" = x"yes"], + [STRICT_CFLAGS=`$srcdir/scripts/strict-cflags.scm`], + []) + AS_IF([test x"$valgrind_tests" = x"yes"], [: ${CFLAGS="-ggdb3 -O0"}], [test x"$debug" = x"yes"], [: ${CFLAGS="-ggdb -O0"}], []) @@ -94,7 +110,7 @@ echo "------------------------------------------------------------------------" echo echo "Compiler flags:" echo -echo " CFLAGS..................: $CFLAGS" +echo " CFLAGS..................: $CFLAGS $STRICT_CFLAGS" echo echo echo "Configuration Options:" @@ -108,4 +124,3 @@ echo echo "------------------------------------------------------------------------" echo echo "Now type 'make' to compile and 'make install' to install this package." - diff --git a/samsung-ipc/Makefile.am b/samsung-ipc/Makefile.am index 9ffaa03..95f4954 100644 --- a/samsung-ipc/Makefile.am +++ b/samsung-ipc/Makefile.am @@ -6,6 +6,10 @@ AM_CFLAGS = \ $(OPENSSL_CFLAGS) \ $(NULL) +if WANT_STRICT_CFLAGS +AM_CFLAGS += $(STRICT_CFLAGS) +endif + if WANT_DEBUG AM_CFLAGS += -DDEBUG endif diff --git a/samsung-ipc/tests/Makefile.am b/samsung-ipc/tests/Makefile.am index 1a7a56b..8147a7b 100644 --- a/samsung-ipc/tests/Makefile.am +++ b/samsung-ipc/tests/Makefile.am @@ -6,6 +6,10 @@ AM_CFLAGS = \ $(OPENSSL_CFLAGS) \ $(NULL) +if WANT_STRICT_CFLAGS +AM_CFLAGS += $(STRICT_CFLAGS) +endif + if WANT_DEBUG AM_CFLAGS += -DDEBUG endif diff --git a/scripts/strict-cflags.scm b/scripts/strict-cflags.scm new file mode 100755 index 0000000..29b5e03 --- /dev/null +++ b/scripts/strict-cflags.scm @@ -0,0 +1,78 @@ +#!/usr/bin/env sh +# -*- mode: scheme; coding: utf-8 -*- +exec guile --no-auto-compile -s "$0" "$@" +!# +;;; Copyright © 2022 Denis Carikli <gnu...@cyberdimension.org> +;;; +;;; This file is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; This file is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. +;;; The guix.scm file is a convention: A file named guix.scm is +;;; found in several project source code, either in the top +;;; directory or in sub-directories like contrib for instance. + +(use-modules (ice-9 textual-ports)) +(use-modules (ice-9 eval-string)) + +(define (extract-cflags expression) + (string-join + ;; TODO: remove trailing whitespaces instead of using cdr + (cdr + (cdr + (string-split + (eval-string (object->string expression)) + #\ )))) + ) + +(define (extract-common-strict-cflags expression) + (car (cdr (cdr expression)))) + +(define (parse-expression expression) + (if (match-expression expression) + (display + (string-append + (extract-cflags (extract-common-strict-cflags expression)) + "\n")))) + +(define (read-expression port) + (let ((expression (read port))) + (if (not (eof-object? expression)) + ((lambda () + (parse-expression expression) + (read-expression port)))))) + +(define (match-expression-later expression) + (if (string=? (object->string (car expression)) "%common-strict-cflags") + #t + (if (not (eq? (cdr expression) '())) + (match-expression-later (cdr expression)) + #f))) + +(define (match-expression expression) + (if (string=? (object->string (car expression)) "define") + (if (string=? + (object->string (car (cdr expression))) + "%common-strict-cflags") + #t + (if (not (eq? (cdr expression) '())) + (match-expression (cdr expression)) + #f)) + (if (not (eq? (cdr expression) '())) + (match-expression (cdr expression)) + #f))) + +(let ((port (open-input-file + (string-append + (dirname (car (command-line))) + "/guix.scm")))) + (read-expression port) + (close-port port)) diff --git a/tools/Makefile.am b/tools/Makefile.am index 5d79235..0360a6e 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -5,6 +5,10 @@ AM_CFLAGS = \ $(LIBCURL_CFLAGS) \ $(NULL) +if WANT_STRICT_CFLAGS +AM_CFLAGS += $(STRICT_CFLAGS) +endif + bin_PROGRAMS = \ https-send-sms \ ipc-test \ diff --git a/tools/ipc-modem/Makefile.am b/tools/ipc-modem/Makefile.am index 069f082..2f6b537 100644 --- a/tools/ipc-modem/Makefile.am +++ b/tools/ipc-modem/Makefile.am @@ -4,6 +4,10 @@ AM_CFLAGS = \ -I$(top_srcdir)/include \ $(NULL) +if WANT_STRICT_CFLAGS +AM_CFLAGS += $(STRICT_CFLAGS) +endif + bin_PROGRAMS = ipc-modem # TODO: Find a way to make test more modular and represent each run of the -- 2.36.1 _______________________________________________ Replicant mailing list Replicant@osuosl.org https://lists.osuosl.org/mailman/listinfo/replicant