aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-11-15 14:21:44 -0800
committerGuy Harris <guy@alum.mit.edu>2017-11-15 14:21:44 -0800
commit11d0ea401aac9e2d2bc1fabf2b790e678632c72f (patch)
tree130fbe3b2959d59e6c81c79c7af88fa560f7bbe3
parente7b32b003ec7a715ed33aff402a0fe4395eb20ee (diff)
Use compiler tests to determine how to define _U_.
One less thing that has to be done in autotools and CMake.
-rw-r--r--CMakeLists.txt5
-rw-r--r--Makefile.in3
-rw-r--r--aclocal.m438
-rwxr-xr-xconfigure49
-rw-r--r--configure.ac3
-rw-r--r--pcap-int.h1
-rw-r--r--tests/can_set_rfmon_test.c2
-rw-r--r--tests/capturetest.c2
-rw-r--r--tests/filtertest.c2
-rw-r--r--tests/opentest.c2
-rw-r--r--tests/reactivatetest.c2
-rw-r--r--tests/selpolltest.c2
-rw-r--r--tests/threadsignaltest.c2
-rw-r--r--tests/valgrindtest.c2
-rw-r--r--varattrs.h59
15 files changed, 78 insertions, 96 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5b307403..4d57446c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -247,11 +247,6 @@ add_definitions(-DBUILDING_PCAP)
if(MSVC)
add_definitions(-D__STDC__)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
- add_definitions("-D_U_=")
-elseif(CMAKE_COMPILER_IS_GNUCXX)
- add_definitions("-D_U_=__attribute__((unused))")
-else(MSVC)
- add_definitions("-D_U_=")
endif(MSVC)
if(USE_STATIC_RT)
diff --git a/Makefile.in b/Makefile.in
index 136e84e0..4a803467 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -155,7 +155,8 @@ HDR = $(PUBHDR) \
rpcapd/win32-svc.h \
sf-pcap.h \
sf-pcap-ng.h \
- sunatmpos.h
+ sunatmpos.h \
+ varattrs.h
TESTS = \
@VALGRINDTEST@ \
diff --git a/aclocal.m4 b/aclocal.m4
index f922759f..4362d4ff 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1101,49 +1101,11 @@ ac_cv___attribute__=yes,
ac_cv___attribute__=no)])
if test "$ac_cv___attribute__" = "yes"; then
AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__])
-else
- #
- # We can't use __attribute__, so we can't use __attribute__((unused)),
- # so we define _U_ to an empty string.
- #
- V_DEFS="$V_DEFS -D_U_=\"\""
fi
AC_MSG_RESULT($ac_cv___attribute__)
])
dnl
-dnl Test whether __attribute__((unused)) can be used without warnings
-dnl
-
-AC_DEFUN(AC_C___ATTRIBUTE___UNUSED, [
-AC_MSG_CHECKING([whether __attribute__((unused)) can be used without warnings])
-AC_CACHE_VAL(ac_cv___attribute___unused, [
-save_CFLAGS="$CFLAGS"
-CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
-AC_COMPILE_IFELSE([
- AC_LANG_SOURCE([[
-#include <stdlib.h>
-#include <stdio.h>
-
-int
-main(int argc __attribute((unused)), char **argv __attribute((unused)))
-{
- printf("Hello, world!\n");
- return 0;
-}
- ]])],
-ac_cv___attribute___unused=yes,
-ac_cv___attribute___unused=no)])
-CFLAGS="$save_CFLAGS"
-if test "$ac_cv___attribute___unused" = "yes"; then
- V_DEFS="$V_DEFS -D_U_=\"__attribute__((unused))\""
-else
- V_DEFS="$V_DEFS -D_U_=\"\""
-fi
-AC_MSG_RESULT($ac_cv___attribute___unused)
-])
-
-dnl
dnl Checks to see if tpacket_stats is defined in linux/if_packet.h
dnl If so then pcap-linux.c can use this to report proper statistics.
dnl
diff --git a/configure b/configure
index 30c6bdc1..8b9a8ea6 100755
--- a/configure
+++ b/configure
@@ -3870,59 +3870,10 @@ if test "$ac_cv___attribute__" = "yes"; then
$as_echo "#define HAVE___ATTRIBUTE__ 1" >>confdefs.h
-else
- #
- # We can't use __attribute__, so we can't use __attribute__((unused)),
- # so we define _U_ to an empty string.
- #
- V_DEFS="$V_DEFS -D_U_=\"\""
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv___attribute__" >&5
$as_echo "$ac_cv___attribute__" >&6; }
-if test "$ac_cv___attribute__" = "yes"; then
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether __attribute__((unused)) can be used without warnings" >&5
-$as_echo_n "checking whether __attribute__((unused)) can be used without warnings... " >&6; }
-if ${ac_cv___attribute___unused+:} false; then :
- $as_echo_n "(cached) " >&6
-else
-
-save_CFLAGS="$CFLAGS"
-CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-
-
-#include <stdlib.h>
-#include <stdio.h>
-
-int
-main(int argc __attribute((unused)), char **argv __attribute((unused)))
-{
- printf("Hello, world!\n");
- return 0;
-}
-
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
- ac_cv___attribute___unused=yes
-else
- ac_cv___attribute___unused=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-
-CFLAGS="$save_CFLAGS"
-if test "$ac_cv___attribute___unused" = "yes"; then
- V_DEFS="$V_DEFS -D_U_=\"__attribute__((unused))\""
-else
- V_DEFS="$V_DEFS -D_U_=\"\""
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv___attribute___unused" >&5
-$as_echo "$ac_cv___attribute___unused" >&6; }
-
-fi
#
# Try to arrange for large file support.
diff --git a/configure.ac b/configure.ac
index a20f376a..7f16399c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,9 +28,6 @@ AC_LBL_C_INIT(V_CCOPT, V_INCLS)
AC_LBL_SHLIBS_INIT
AC_LBL_C_INLINE
AC_C___ATTRIBUTE__
-if test "$ac_cv___attribute__" = "yes"; then
- AC_C___ATTRIBUTE___UNUSED
-fi
#
# Try to arrange for large file support.
diff --git a/pcap-int.h b/pcap-int.h
index d1ea4a15..516b49c3 100644
--- a/pcap-int.h
+++ b/pcap-int.h
@@ -38,6 +38,7 @@
#include <pcap/pcap.h>
+#include "varattrs.h"
#include "fmtutils.h"
/*
diff --git a/tests/can_set_rfmon_test.c b/tests/can_set_rfmon_test.c
index 88661d63..ea4f0c40 100644
--- a/tests/can_set_rfmon_test.c
+++ b/tests/can_set_rfmon_test.c
@@ -19,6 +19,8 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+#include "varattrs.h"
+
#ifndef lint
static const char copyright[] _U_ =
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
diff --git a/tests/capturetest.c b/tests/capturetest.c
index 1cebae01..573239f2 100644
--- a/tests/capturetest.c
+++ b/tests/capturetest.c
@@ -19,6 +19,8 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+#include "varattrs.h"
+
#ifndef lint
static const char copyright[] _U_ =
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
diff --git a/tests/filtertest.c b/tests/filtertest.c
index 9d597396..380cb73e 100644
--- a/tests/filtertest.c
+++ b/tests/filtertest.c
@@ -19,6 +19,8 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+#include "varattrs.h"
+
#ifndef lint
static const char copyright[] _U_ =
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
diff --git a/tests/opentest.c b/tests/opentest.c
index 79c9c941..bad38eb0 100644
--- a/tests/opentest.c
+++ b/tests/opentest.c
@@ -19,6 +19,8 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+#include "varattrs.h"
+
#ifndef lint
static const char copyright[] _U_ =
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
diff --git a/tests/reactivatetest.c b/tests/reactivatetest.c
index f3485cbd..42b2c3b8 100644
--- a/tests/reactivatetest.c
+++ b/tests/reactivatetest.c
@@ -19,6 +19,8 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+#include "varattrs.h"
+
#ifndef lint
static const char copyright[] _U_ =
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
diff --git a/tests/selpolltest.c b/tests/selpolltest.c
index f8005d6e..dbd1c424 100644
--- a/tests/selpolltest.c
+++ b/tests/selpolltest.c
@@ -19,6 +19,8 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+#include "varattrs.h"
+
#ifndef lint
static const char copyright[] _U_ =
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
diff --git a/tests/threadsignaltest.c b/tests/threadsignaltest.c
index 2a493223..bd46f936 100644
--- a/tests/threadsignaltest.c
+++ b/tests/threadsignaltest.c
@@ -19,6 +19,8 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+#include "varattrs.h"
+
#ifndef lint
static const char copyright[] _U_ =
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
diff --git a/tests/valgrindtest.c b/tests/valgrindtest.c
index 6bb6d4f6..ef387c97 100644
--- a/tests/valgrindtest.c
+++ b/tests/valgrindtest.c
@@ -19,6 +19,8 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+#include "varattrs.h"
+
/*
* This doesn't actually test libpcap itself; it tests whether
* valgrind properly handles the APIs libpcap uses. If it doesn't,
diff --git a/varattrs.h b/varattrs.h
new file mode 100644
index 00000000..05bfe8cd
--- /dev/null
+++ b/varattrs.h
@@ -0,0 +1,59 @@
+/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
+/*
+ * Copyright (c) 1993, 1994, 1995, 1996, 1997
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the Computer Systems
+ * Engineering Group at Lawrence Berkeley Laboratory.
+ * 4. Neither the name of the University nor of the Laboratory may be used
+ * to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef varattrs_h
+#define varattrs_h
+
+#include <pcap/compiler-tests.h>
+
+/*
+ * Attributes to apply to variables, using various compiler-specific
+ * extensions.
+ */
+
+#if __has_attribute(unused) \
+ || PCAP_IS_AT_LEAST_GNUC_VERSION(2,0)
+ /*
+ * Compiler with support for __attribute__((unused)), or GCC 2.0 and
+ * later, so it supports __attribute__((unused)).
+ */
+ #define _U_ __attribute__((unused))
+#else
+ /*
+ * We don't know of any way to mark a variable as unused.
+ */
+ #define _U_
+#endif
+
+#endif