Skip to content

Commit c159904

Browse files
committed
Coverage
- Add `--enable-gcov` and `gcov` make target for Code coverage - Add `--enable-warn-all` - Add `--with-extra-cxxflags` - Add `--with-extra-ldflags`
1 parent 9c809e0 commit c159904

11 files changed

+459
-3
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ compiler:
1010
- gcc
1111
install: ./autogen.sh
1212
script:
13-
- ./configure
13+
- ./configure --enable-warn-all
1414
- make dist
1515
- tar zxvf *.tar.gz
1616
- cd packetq-[0-9]*
1717
- mkdir build
1818
- cd build
19-
- ../configure
19+
- ../configure --enable-warn-all
2020
- make
2121
- make test
2222
- src/packetq -v

Makefile.am

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# You should have received a copy of the GNU General Public License
1818
# along with PacketQ. If not, see <http://www.gnu.org/licenses/>.
1919

20+
ACLOCAL_AMFLAGS = -I m4
21+
2022
MAINTAINERCLEANFILES = $(srcdir)/Makefile.in \
2123
$(srcdir)/src/config.h.in~ \
2224
$(srcdir)/configure

autogen.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with PacketQ. If not, see <http://www.gnu.org/licenses/>.
2121

22-
autoreconf --force --install --no-recursive
22+
autoreconf --force --install --no-recursive --include=m4

configure.ac

+24
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ AC_CONFIG_HEADER([src/config.h])
2626
# Checks for programs.
2727
AC_PROG_CXX
2828

29+
# Check --enable-warn-all
30+
AC_ARG_ENABLE([warn-all], [AS_HELP_STRING([--enable-warn-all], [Enable all compiler warnings])], [AX_CXXFLAGS_WARN_ALL()])
31+
32+
# Check --with-extra-cxxflags
33+
AC_ARG_WITH([extra-cxxflags], [AS_HELP_STRING([--with-extra-cxxflags=CXXFLAGS], [Add extra CXXFLAGS])], [
34+
AC_MSG_NOTICE([appending extra CXXFLAGS... $withval])
35+
AS_VAR_APPEND(CXXFLAGS, [" $withval"])
36+
])
37+
38+
# Check --with-extra-ldflags
39+
AC_ARG_WITH([extra-ldflags], [AS_HELP_STRING([--with-extra-ldflags=CXXFLAGS], [Add extra LDFLAGS])], [
40+
AC_MSG_NOTICE([appending extra LDFLAGS... $withval])
41+
AS_VAR_APPEND(LDFLAGS, [" $withval"])
42+
])
43+
44+
# Check --enable-gcov
45+
AC_ARG_ENABLE([gcov], [AS_HELP_STRING([--enable-gcov], [Enable coverage testing])], [
46+
coverage_cxxflags="--coverage -g -O0 -fno-inline -fno-inline-small-functions -fno-default-inline"
47+
AC_MSG_NOTICE([enabling coverage testing... $coverage_cxxflags])
48+
AS_VAR_APPEND(CXXFLAGS, [" $coverage_cxxflags"])
49+
])
50+
AM_CONDITIONAL([ENABLE_GCOV], [test "x$enable_gcov" != "xno"])
51+
AM_EXTRA_RECURSIVE_TARGETS([gcov])
52+
2953
# Checks for libraries.
3054
AC_CHECK_LIB([z], [deflate])
3155
AC_CHECK_LIB([socket], socket)

m4/ax_append_flag.m4

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# ===========================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_append_flag.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_APPEND_FLAG(FLAG, [FLAGS-VARIABLE])
8+
#
9+
# DESCRIPTION
10+
#
11+
# FLAG is appended to the FLAGS-VARIABLE shell variable, with a space
12+
# added in between.
13+
#
14+
# If FLAGS-VARIABLE is not specified, the current language's flags (e.g.
15+
# CFLAGS) is used. FLAGS-VARIABLE is not changed if it already contains
16+
# FLAG. If FLAGS-VARIABLE is unset in the shell, it is set to exactly
17+
# FLAG.
18+
#
19+
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION.
20+
#
21+
# LICENSE
22+
#
23+
# Copyright (c) 2008 Guido U. Draheim <[email protected]>
24+
# Copyright (c) 2011 Maarten Bosmans <[email protected]>
25+
#
26+
# Copying and distribution of this file, with or without modification, are
27+
# permitted in any medium without royalty provided the copyright notice
28+
# and this notice are preserved. This file is offered as-is, without any
29+
# warranty.
30+
31+
#serial 8
32+
33+
AC_DEFUN([AX_APPEND_FLAG],
34+
[dnl
35+
AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_SET_IF
36+
AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])])
37+
AS_VAR_SET_IF(FLAGS,[
38+
AS_CASE([" AS_VAR_GET(FLAGS) "],
39+
[*" $1 "*], [AC_RUN_LOG([: FLAGS already contains $1])],
40+
[
41+
AS_VAR_APPEND(FLAGS,[" $1"])
42+
AC_RUN_LOG([: FLAGS="$FLAGS"])
43+
])
44+
],
45+
[
46+
AS_VAR_SET(FLAGS,[$1])
47+
AC_RUN_LOG([: FLAGS="$FLAGS"])
48+
])
49+
AS_VAR_POPDEF([FLAGS])dnl
50+
])dnl AX_APPEND_FLAG

m4/ax_cflags_warn_all.m4

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# ===========================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_cflags_warn_all.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_CFLAGS_WARN_ALL [(shellvar[, default[, action-if-found[, action-if-not-found]]])]
8+
# AX_CXXFLAGS_WARN_ALL [(shellvar[, default[, action-if-found[, action-if-not-found]]])]
9+
# AX_FCFLAGS_WARN_ALL [(shellvar[, default[, action-if-found[, action-if-not-found]]])]
10+
#
11+
# DESCRIPTION
12+
#
13+
# Specify compiler options that enable most reasonable warnings. For the
14+
# GNU Compiler Collection (GCC), for example, it will be "-Wall". The
15+
# result is added to shellvar, one of CFLAGS, CXXFLAGS or FCFLAGS if the
16+
# first parameter is not specified.
17+
#
18+
# Each of these macros accepts the following optional arguments:
19+
#
20+
# - $1 - shellvar
21+
# shell variable to use (CFLAGS, CXXFLAGS or FCFLAGS if not
22+
# specified, depending on macro)
23+
#
24+
# - $2 - default
25+
# value to use for flags if compiler vendor cannot be determined (by
26+
# default, "")
27+
#
28+
# - $3 - action-if-found
29+
# action to take if the compiler vendor has been successfully
30+
# determined (by default, add the appropriate compiler flags to
31+
# shellvar)
32+
#
33+
# - $4 - action-if-not-found
34+
# action to take if the compiler vendor has not been determined or
35+
# is unknown (by default, add the default flags, or "" if not
36+
# specified, to shellvar)
37+
#
38+
# These macros use AX_COMPILER_VENDOR to determine which flags should be
39+
# returned for a given compiler. Not all compilers currently have flags
40+
# defined for them; patches are welcome. If need be, compiler flags may
41+
# be made language-dependent: use a construct like the following:
42+
#
43+
# [vendor_name], [m4_if(_AC_LANG_PREFIX,[C], VAR="--relevant-c-flags",dnl
44+
# m4_if(_AC_LANG_PREFIX,[CXX], VAR="--relevant-c++-flags",dnl
45+
# m4_if(_AC_LANG_PREFIX,[FC], VAR="--relevant-fortran-flags",dnl
46+
# VAR="$2"; FOUND="no")))],
47+
#
48+
# Note: These macros also depend on AX_PREPEND_FLAG.
49+
#
50+
# LICENSE
51+
#
52+
# Copyright (c) 2008 Guido U. Draheim <[email protected]>
53+
# Copyright (c) 2010 Rhys Ulerich <[email protected]>
54+
# Copyright (c) 2018 John Zaitseff <[email protected]>
55+
#
56+
# This program is free software; you can redistribute it and/or modify it
57+
# under the terms of the GNU General Public License as published by the
58+
# Free Software Foundation; either version 3 of the License, or (at your
59+
# option) any later version.
60+
#
61+
# This program is distributed in the hope that it will be useful, but
62+
# WITHOUT ANY WARRANTY; without even the implied warranty of
63+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
64+
# Public License for more details.
65+
#
66+
# You should have received a copy of the GNU General Public License along
67+
# with this program. If not, see <https://www.gnu.org/licenses/>.
68+
#
69+
# As a special exception, the respective Autoconf Macro's copyright owner
70+
# gives unlimited permission to copy, distribute and modify the configure
71+
# scripts that are the output of Autoconf when processing the Macro. You
72+
# need not follow the terms of the GNU General Public License when using
73+
# or distributing such scripts, even though portions of the text of the
74+
# Macro appear in them. The GNU General Public License (GPL) does govern
75+
# all other use of the material that constitutes the Autoconf Macro.
76+
#
77+
# This special exception to the GPL applies to versions of the Autoconf
78+
# Macro released by the Autoconf Archive. When you make and distribute a
79+
# modified version of the Autoconf Macro, you may extend this special
80+
# exception to the GPL to apply to your modified version as well.
81+
82+
#serial 25
83+
84+
AC_DEFUN([AX_FLAGS_WARN_ALL], [
85+
AX_REQUIRE_DEFINED([AX_PREPEND_FLAG])dnl
86+
AC_REQUIRE([AX_COMPILER_VENDOR])dnl
87+
88+
AS_VAR_PUSHDEF([FLAGS], [m4_default($1,_AC_LANG_PREFIX[]FLAGS)])dnl
89+
AS_VAR_PUSHDEF([VAR], [ac_cv_[]_AC_LANG_ABBREV[]flags_warn_all])dnl
90+
AS_VAR_PUSHDEF([FOUND], [ac_save_[]_AC_LANG_ABBREV[]flags_warn_all_found])dnl
91+
92+
AC_CACHE_CHECK([FLAGS for most reasonable warnings], VAR, [
93+
VAR=""
94+
FOUND="yes"
95+
dnl Cases are listed in the order found in ax_compiler_vendor.m4
96+
AS_CASE("$ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor",
97+
[intel], [VAR="-w2"],
98+
[ibm], [VAR="-qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd"],
99+
[pathscale], [],
100+
[clang], [VAR="-Wall"],
101+
[cray], [VAR="-h msglevel 2"],
102+
[fujitsu], [],
103+
[sdcc], [],
104+
[sx], [VAR="-pvctl[,]fullmsg"],
105+
[portland], [],
106+
[gnu], [VAR="-Wall"],
107+
[sun], [VAR="-v"],
108+
[hp], [VAR="+w1"],
109+
[dec], [VAR="-verbose -w0 -warnprotos"],
110+
[borland], [],
111+
[comeau], [],
112+
[kai], [],
113+
[lcc], [],
114+
[sgi], [VAR="-fullwarn"],
115+
[microsoft], [],
116+
[metrowerks], [],
117+
[watcom], [],
118+
[tcc], [],
119+
[unknown], [
120+
VAR="$2"
121+
FOUND="no"
122+
],
123+
[
124+
AC_MSG_WARN([Unknown compiler vendor returned by [AX_COMPILER_VENDOR]])
125+
VAR="$2"
126+
FOUND="no"
127+
]
128+
)
129+
130+
AS_IF([test "x$FOUND" = "xyes"], [dnl
131+
m4_default($3, [AS_IF([test "x$VAR" != "x"], [AX_PREPEND_FLAG([$VAR], [FLAGS])])])
132+
], [dnl
133+
m4_default($4, [m4_ifval($2, [AX_PREPEND_FLAG([$VAR], [FLAGS])], [true])])
134+
])dnl
135+
])dnl
136+
137+
AS_VAR_POPDEF([FOUND])dnl
138+
AS_VAR_POPDEF([VAR])dnl
139+
AS_VAR_POPDEF([FLAGS])dnl
140+
])dnl AX_FLAGS_WARN_ALL
141+
142+
AC_DEFUN([AX_CFLAGS_WARN_ALL], [dnl
143+
AC_LANG_PUSH([C])
144+
AX_FLAGS_WARN_ALL([$1], [$2], [$3], [$4])
145+
AC_LANG_POP([C])
146+
])dnl
147+
148+
AC_DEFUN([AX_CXXFLAGS_WARN_ALL], [dnl
149+
AC_LANG_PUSH([C++])
150+
AX_FLAGS_WARN_ALL([$1], [$2], [$3], [$4])
151+
AC_LANG_POP([C++])
152+
])dnl
153+
154+
AC_DEFUN([AX_FCFLAGS_WARN_ALL], [dnl
155+
AC_LANG_PUSH([Fortran])
156+
AX_FLAGS_WARN_ALL([$1], [$2], [$3], [$4])
157+
AC_LANG_POP([Fortran])
158+
])dnl

m4/ax_compiler_vendor.m4

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# ===========================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_compiler_vendor.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_COMPILER_VENDOR
8+
#
9+
# DESCRIPTION
10+
#
11+
# Determine the vendor of the C, C++ or Fortran compiler. The vendor is
12+
# returned in the cache variable $ax_cv_c_compiler_vendor for C,
13+
# $ax_cv_cxx_compiler_vendor for C++ or $ax_cv_fc_compiler_vendor for
14+
# (modern) Fortran. The value is one of "intel", "ibm", "pathscale",
15+
# "clang" (LLVM), "cray", "fujitsu", "sdcc", "sx", "portland" (PGI), "gnu"
16+
# (GCC), "sun" (Oracle Developer Studio), "hp", "dec", "borland",
17+
# "comeau", "kai", "lcc", "sgi", "microsoft", "metrowerks", "watcom",
18+
# "tcc" (Tiny CC) or "unknown" (if the compiler cannot be determined).
19+
#
20+
# To check for a Fortran compiler, you must first call AC_FC_PP_SRCEXT
21+
# with an appropriate preprocessor-enabled extension. For example:
22+
#
23+
# AC_LANG_PUSH([Fortran])
24+
# AC_PROG_FC
25+
# AC_FC_PP_SRCEXT([F])
26+
# AX_COMPILER_VENDOR
27+
# AC_LANG_POP([Fortran])
28+
#
29+
# LICENSE
30+
#
31+
# Copyright (c) 2008 Steven G. Johnson <[email protected]>
32+
# Copyright (c) 2008 Matteo Frigo
33+
# Copyright (c) 2018-19 John Zaitseff <[email protected]>
34+
#
35+
# This program is free software: you can redistribute it and/or modify it
36+
# under the terms of the GNU General Public License as published by the
37+
# Free Software Foundation, either version 3 of the License, or (at your
38+
# option) any later version.
39+
#
40+
# This program is distributed in the hope that it will be useful, but
41+
# WITHOUT ANY WARRANTY; without even the implied warranty of
42+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
43+
# Public License for more details.
44+
#
45+
# You should have received a copy of the GNU General Public License along
46+
# with this program. If not, see <https://www.gnu.org/licenses/>.
47+
#
48+
# As a special exception, the respective Autoconf Macro's copyright owner
49+
# gives unlimited permission to copy, distribute and modify the configure
50+
# scripts that are the output of Autoconf when processing the Macro. You
51+
# need not follow the terms of the GNU General Public License when using
52+
# or distributing such scripts, even though portions of the text of the
53+
# Macro appear in them. The GNU General Public License (GPL) does govern
54+
# all other use of the material that constitutes the Autoconf Macro.
55+
#
56+
# This special exception to the GPL applies to versions of the Autoconf
57+
# Macro released by the Autoconf Archive. When you make and distribute a
58+
# modified version of the Autoconf Macro, you may extend this special
59+
# exception to the GPL to apply to your modified version as well.
60+
61+
#serial 30
62+
63+
AC_DEFUN([AX_COMPILER_VENDOR], [dnl
64+
AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor, [dnl
65+
dnl If you modify this list of vendors, please add similar support
66+
dnl to ax_compiler_version.m4 if at all possible.
67+
dnl
68+
dnl Note: Do NOT check for GCC first since some other compilers
69+
dnl define __GNUC__ to remain compatible with it. Compilers that
70+
dnl are very slow to start (such as Intel) are listed first.
71+
72+
vendors="
73+
intel: __ICC,__ECC,__INTEL_COMPILER
74+
ibm: __xlc__,__xlC__,__IBMC__,__IBMCPP__,__ibmxl__
75+
pathscale: __PATHCC__,__PATHSCALE__
76+
clang: __clang__
77+
cray: _CRAYC
78+
fujitsu: __FUJITSU
79+
sdcc: SDCC,__SDCC
80+
sx: _SX
81+
portland: __PGI
82+
gnu: __GNUC__
83+
sun: __SUNPRO_C,__SUNPRO_CC,__SUNPRO_F90,__SUNPRO_F95
84+
hp: __HP_cc,__HP_aCC
85+
dec: __DECC,__DECCXX,__DECC_VER,__DECCXX_VER
86+
borland: __BORLANDC__,__CODEGEARC__,__TURBOC__
87+
comeau: __COMO__
88+
kai: __KCC
89+
lcc: __LCC__
90+
sgi: __sgi,sgi
91+
microsoft: _MSC_VER
92+
metrowerks: __MWERKS__
93+
watcom: __WATCOMC__
94+
tcc: __TINYC__
95+
unknown: UNKNOWN
96+
"
97+
for ventest in $vendors; do
98+
case $ventest in
99+
*:)
100+
vendor=$ventest
101+
continue
102+
;;
103+
*)
104+
vencpp="defined("`echo $ventest | sed 's/,/) || defined(/g'`")"
105+
;;
106+
esac
107+
108+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
109+
#if !($vencpp)
110+
thisisanerror;
111+
#endif
112+
]])], [break])
113+
done
114+
115+
ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=`echo $vendor | cut -d: -f1`
116+
])
117+
])dnl

0 commit comments

Comments
 (0)