]> The Tcpdump Group git mirrors - libpcap/blob - build.sh
Fix building without protochain support. (GH #852)
[libpcap] / build.sh
1 #!/bin/sh -e
2
3 # This script runs one build with setup environment variables: CC, CMAKE and
4 # REMOTE.
5 : "${CC:=gcc}"
6 : "${CMAKE:=no}"
7 : "${REMOTE:=no}"
8 : "${LIBPCAP_TAINTED:=no}"
9 : "${MAKE_BIN:=make}"
10
11 . ./build_common.sh
12 # Install directory prefix
13 if [ -z "$PREFIX" ]; then
14 PREFIX=`mktempdir libpcap_build`
15 echo "PREFIX set to '$PREFIX'"
16 DELETE_PREFIX=yes
17 fi
18
19 print_cc_version
20
21 # The norm is to compile without any warnings, but libpcap builds on some OSes
22 # are not warning-free for one or another reason. If you manage to fix one of
23 # these cases, please remember to remove respective exemption below to help any
24 # later warnings in the same matrix subset trigger an error.
25 # shellcheck disable=SC2221,SC2222
26 case `cc_id`/`os_id` in
27 gcc-*/Linux-*)
28 # This warning is a bit odd. It is steadily present in Cirrus CI, but not
29 # in Buildbot. On my Linux system with the same exact distribution and GCC
30 # as Cirrus CI it reproduces only if GCC receives the "-g" flag:
31 # make CFLAGS=-g -- does not reproduce
32 # CFLAGS=-g make -- reproduces
33 # make -- reproduces
34 #
35 # pcap-linux.c:947:8: warning: ignoring return value of 'write', declared
36 # with attribute warn_unused_result [-Wunused-result]
37 #
38 # And even this way it does not make GCC exit with an error when it has
39 # reported the warning and has received the "-Werror" flag. So let's keep
40 # this block no-op for now.
41 ;;
42 clang-*/NetBSD-*)
43 # pcap-bpf.c:1044:18: warning: implicit conversion loses integer precision:
44 # 'uint64_t' (aka 'unsigned long') to 'u_int' (aka 'unsigned int')
45 # [-Wshorten-64-to-32]
46 # pcap-bpf.c:1045:18: warning: implicit conversion loses integer precision:
47 # 'uint64_t' (aka 'unsigned long') to 'u_int' (aka 'unsigned int')
48 # [-Wshorten-64-to-32]
49 # pcap-bpf.c:1274:39: warning: implicit conversion loses integer precision:
50 # 'long' to 'suseconds_t' (aka 'int') [-Wshorten-64-to-32]
51 LIBPCAP_TAINTED=yes
52 ;;
53 clang-*/SunOS-5.11)
54 # (Solaris 11 and OpenIndiana)
55 # pcap-bpf.c:1044:18: warning: implicit conversion loses integer precision:
56 # 'uint64_t' (aka 'unsigned long') to 'u_int' (aka 'unsigned int')
57 # [-Wshorten-64-to-32]
58 # pcap-bpf.c:1045:18: warning: implicit conversion loses integer precision:
59 # 'uint64_t' (aka 'unsigned long') to 'u_int' (aka 'unsigned int')
60 # [-Wshorten-64-to-32]
61 # fad-getad.c:266:52: warning: implicit conversion loses integer precision:
62 # 'uint64_t'(aka 'unsigned long') to 'bpf_u_int32' (aka 'unsigned int')
63 # [-Wshorten-64-to-32]
64 # (Solaris 11)
65 # pcap-bpf.c:1843:22: warning: implicit conversion loses integer precision:
66 # 'long' to 'int' [-Wshorten-64-to-32]
67 # (OpenIndiana)
68 # rpcapd.c:393:18: warning: this function declaration is not a prototype
69 # [-Wstrict-prototypes]
70 [ "`uname -p`" = i386 ] && LIBPCAP_TAINTED=yes
71 ;;
72 suncc-5.1[45]/SunOS-5.11)
73 # "scanner.l", line 257: warning: statement not reached
74 # (186 warnings for scanner.l)
75 #
76 # "./filtertest.c", line 259: warning: statement not reached
77 # "./filtertest.c", line 276: warning: statement not reached
78 # "./filtertest.c", line 281: warning: statement not reached
79 LIBPCAP_TAINTED=yes
80 ;;
81 esac
82 [ "$LIBPCAP_TAINTED" != yes ] && CFLAGS=`cc_werr_cflags`
83
84 if [ "$CMAKE" = no ]; then
85 run_after_echo ./configure --prefix="$PREFIX" --enable-remote="$REMOTE"
86 else
87 # Remove the leftovers from any earlier in-source builds, so this
88 # out-of-source build does not break because of that.
89 # https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#what-is-an-out-of-source-build
90 run_after_echo rm -rf CMakeFiles/ CMakeCache.txt
91 [ ! -d build ] && run_after_echo mkdir build
92 run_after_echo cd build
93 run_after_echo cmake ${CFLAGS:+-DEXTRA_CFLAGS="$CFLAGS"} \
94 -DCMAKE_INSTALL_PREFIX="$PREFIX" -DENABLE_REMOTE="$REMOTE" ..
95 fi
96 run_after_echo "$MAKE_BIN" -s clean
97 if [ "$CMAKE" = no ]; then
98 run_after_echo "$MAKE_BIN" -s ${CFLAGS:+CFLAGS="$CFLAGS"}
99 run_after_echo "$MAKE_BIN" -s testprogs ${CFLAGS:+CFLAGS="$CFLAGS"}
100 else
101 # The "-s" flag is a no-op and CFLAGS is set using -DEXTRA_CFLAGS above.
102 run_after_echo "$MAKE_BIN"
103 run_after_echo "$MAKE_BIN" testprogs
104 fi
105 run_after_echo "$MAKE_BIN" install
106 # VALGRIND_CMD is meant either to collapse or to expand.
107 # shellcheck disable=SC2086
108 if [ "$CMAKE" = no ]; then
109 run_after_echo $VALGRIND_CMD testprogs/findalldevstest
110 run_after_echo "$MAKE_BIN" releasetar
111 else
112 run_after_echo $VALGRIND_CMD run/findalldevstest
113 fi
114 handle_matrix_debug
115 if [ "$DELETE_PREFIX" = yes ]; then
116 run_after_echo rm -rf "$PREFIX"
117 fi
118 # vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent :