xref: /aosp_15_r20/external/libpcap/build.sh (revision 8b26181f966a6af5cf6981a6f474313de533bb28)
1*8b26181fSAndroid Build Coastguard Worker#!/bin/sh -e
2*8b26181fSAndroid Build Coastguard Worker
3*8b26181fSAndroid Build Coastguard Worker# This script runs one build with setup environment variables: CC, CMAKE and
4*8b26181fSAndroid Build Coastguard Worker# REMOTE.
5*8b26181fSAndroid Build Coastguard Worker: "${CC:=gcc}"
6*8b26181fSAndroid Build Coastguard Worker: "${CMAKE:=no}"
7*8b26181fSAndroid Build Coastguard Worker: "${REMOTE:=no}"
8*8b26181fSAndroid Build Coastguard Worker: "${LIBPCAP_TAINTED:=no}"
9*8b26181fSAndroid Build Coastguard Worker: "${MAKE_BIN:=make}"
10*8b26181fSAndroid Build Coastguard Worker
11*8b26181fSAndroid Build Coastguard Worker. ./build_common.sh
12*8b26181fSAndroid Build Coastguard Worker# Install directory prefix
13*8b26181fSAndroid Build Coastguard Workerif [ -z "$PREFIX" ]; then
14*8b26181fSAndroid Build Coastguard Worker    PREFIX=`mktempdir libpcap_build`
15*8b26181fSAndroid Build Coastguard Worker    echo "PREFIX set to '$PREFIX'"
16*8b26181fSAndroid Build Coastguard Worker    DELETE_PREFIX=yes
17*8b26181fSAndroid Build Coastguard Workerfi
18*8b26181fSAndroid Build Coastguard Worker
19*8b26181fSAndroid Build Coastguard Workerprint_cc_version
20*8b26181fSAndroid Build Coastguard Worker
21*8b26181fSAndroid Build Coastguard Worker# The norm is to compile without any warnings, but libpcap builds on some OSes
22*8b26181fSAndroid Build Coastguard Worker# are not warning-free for one or another reason.  If you manage to fix one of
23*8b26181fSAndroid Build Coastguard Worker# these cases, please remember to remove respective exemption below to help any
24*8b26181fSAndroid Build Coastguard Worker# later warnings in the same matrix subset trigger an error.
25*8b26181fSAndroid Build Coastguard Worker# shellcheck disable=SC2221,SC2222
26*8b26181fSAndroid Build Coastguard Workercase `cc_id`/`os_id` in
27*8b26181fSAndroid Build Coastguard Workergcc-*/Linux-*)
28*8b26181fSAndroid Build Coastguard Worker    # This warning is a bit odd.  It is steadily present in Cirrus CI, but not
29*8b26181fSAndroid Build Coastguard Worker    # in Buildbot.  On my Linux system with the same exact distribution and GCC
30*8b26181fSAndroid Build Coastguard Worker    # as Cirrus CI it reproduces only if GCC receives the "-g" flag:
31*8b26181fSAndroid Build Coastguard Worker    # make CFLAGS=-g -- does not reproduce
32*8b26181fSAndroid Build Coastguard Worker    # CFLAGS=-g make -- reproduces
33*8b26181fSAndroid Build Coastguard Worker    # make -- reproduces
34*8b26181fSAndroid Build Coastguard Worker    #
35*8b26181fSAndroid Build Coastguard Worker    # pcap-linux.c:947:8: warning: ignoring return value of 'write', declared
36*8b26181fSAndroid Build Coastguard Worker    # with attribute warn_unused_result [-Wunused-result]
37*8b26181fSAndroid Build Coastguard Worker    #
38*8b26181fSAndroid Build Coastguard Worker    # And even this way it does not make GCC exit with an error when it has
39*8b26181fSAndroid Build Coastguard Worker    # reported the warning and has received the "-Werror" flag. So let's keep
40*8b26181fSAndroid Build Coastguard Worker    # this block no-op for now.
41*8b26181fSAndroid Build Coastguard Worker    ;;
42*8b26181fSAndroid Build Coastguard Workerclang-*/NetBSD-*)
43*8b26181fSAndroid Build Coastguard Worker    # pcap-bpf.c:1044:18: warning: implicit conversion loses integer precision:
44*8b26181fSAndroid Build Coastguard Worker    # 'uint64_t' (aka 'unsigned long') to 'u_int' (aka 'unsigned int')
45*8b26181fSAndroid Build Coastguard Worker    # [-Wshorten-64-to-32]
46*8b26181fSAndroid Build Coastguard Worker    # pcap-bpf.c:1045:18: warning: implicit conversion loses integer precision:
47*8b26181fSAndroid Build Coastguard Worker    # 'uint64_t' (aka 'unsigned long') to 'u_int' (aka 'unsigned int')
48*8b26181fSAndroid Build Coastguard Worker    # [-Wshorten-64-to-32]
49*8b26181fSAndroid Build Coastguard Worker    # pcap-bpf.c:1274:39: warning: implicit conversion loses integer precision:
50*8b26181fSAndroid Build Coastguard Worker    # 'long' to 'suseconds_t' (aka 'int') [-Wshorten-64-to-32]
51*8b26181fSAndroid Build Coastguard Worker    LIBPCAP_TAINTED=yes
52*8b26181fSAndroid Build Coastguard Worker    ;;
53*8b26181fSAndroid Build Coastguard Workerclang-15.*/*)
54*8b26181fSAndroid Build Coastguard Worker    # grammar.c:1369:14: warning: variable 'pcap_nerrs' set but not used
55*8b26181fSAndroid Build Coastguard Worker    #   [-Wunused-but-set-variable]
56*8b26181fSAndroid Build Coastguard Worker    LIBPCAP_TAINTED=yes
57*8b26181fSAndroid Build Coastguard Worker    ;;
58*8b26181fSAndroid Build Coastguard Workerclang-*/SunOS-5.11)
59*8b26181fSAndroid Build Coastguard Worker    # (Solaris 11 and OpenIndiana)
60*8b26181fSAndroid Build Coastguard Worker    # pcap-bpf.c:1044:18: warning: implicit conversion loses integer precision:
61*8b26181fSAndroid Build Coastguard Worker    #   'uint64_t' (aka 'unsigned long') to 'u_int' (aka 'unsigned int')
62*8b26181fSAndroid Build Coastguard Worker    #   [-Wshorten-64-to-32]
63*8b26181fSAndroid Build Coastguard Worker    # pcap-bpf.c:1045:18: warning: implicit conversion loses integer precision:
64*8b26181fSAndroid Build Coastguard Worker    #   'uint64_t' (aka 'unsigned long') to 'u_int' (aka 'unsigned int')
65*8b26181fSAndroid Build Coastguard Worker    #   [-Wshorten-64-to-32]
66*8b26181fSAndroid Build Coastguard Worker    # fad-getad.c:266:52: warning: implicit conversion loses integer precision:
67*8b26181fSAndroid Build Coastguard Worker    #   'uint64_t'(aka 'unsigned long') to 'bpf_u_int32' (aka 'unsigned int')
68*8b26181fSAndroid Build Coastguard Worker    #   [-Wshorten-64-to-32]
69*8b26181fSAndroid Build Coastguard Worker    # (Solaris 11)
70*8b26181fSAndroid Build Coastguard Worker    # pcap-bpf.c:1843:22: warning: implicit conversion loses integer precision:
71*8b26181fSAndroid Build Coastguard Worker    #   'long' to 'int' [-Wshorten-64-to-32]
72*8b26181fSAndroid Build Coastguard Worker    # (OpenIndiana)
73*8b26181fSAndroid Build Coastguard Worker    # rpcapd.c:393:18: warning: this function declaration is not a prototype
74*8b26181fSAndroid Build Coastguard Worker    #   [-Wstrict-prototypes]
75*8b26181fSAndroid Build Coastguard Worker    [ "`uname -p`" = i386 ] && LIBPCAP_TAINTED=yes
76*8b26181fSAndroid Build Coastguard Worker    ;;
77*8b26181fSAndroid Build Coastguard Workersuncc-5.1[45]/SunOS-5.11)
78*8b26181fSAndroid Build Coastguard Worker    # "scanner.l", line 257: warning: statement not reached
79*8b26181fSAndroid Build Coastguard Worker    # (186 warnings for scanner.l)
80*8b26181fSAndroid Build Coastguard Worker    #
81*8b26181fSAndroid Build Coastguard Worker    # "./filtertest.c", line 259: warning: statement not reached
82*8b26181fSAndroid Build Coastguard Worker    # "./filtertest.c", line 276: warning: statement not reached
83*8b26181fSAndroid Build Coastguard Worker    # "./filtertest.c", line 281: warning: statement not reached
84*8b26181fSAndroid Build Coastguard Worker    LIBPCAP_TAINTED=yes
85*8b26181fSAndroid Build Coastguard Worker    ;;
86*8b26181fSAndroid Build Coastguard Worker*/Haiku-*)
87*8b26181fSAndroid Build Coastguard Worker    # (GCC 8.3.0 and later, Clang 9.0.1.)
88*8b26181fSAndroid Build Coastguard Worker    # pcap-haiku.cpp:55:21: warning: unused variable 'handlep' [-Wunused-variable]
89*8b26181fSAndroid Build Coastguard Worker    # pcap-haiku.cpp:50:37: warning: unused parameter 'maxPackets' [-Wunused-parameter]
90*8b26181fSAndroid Build Coastguard Worker    # pcap-haiku.cpp:111:47: warning: unused parameter 'buffer' [-Wunused-parameter]
91*8b26181fSAndroid Build Coastguard Worker    # pcap-haiku.cpp:111:59: warning: unused parameter 'size' [-Wunused-parameter]
92*8b26181fSAndroid Build Coastguard Worker    # pcap-haiku.cpp:268:26: warning: unused parameter 'name' [-Wunused-parameter]
93*8b26181fSAndroid Build Coastguard Worker    # pcap-haiku.cpp:274:26: warning: unused parameter 'name' [-Wunused-parameter]
94*8b26181fSAndroid Build Coastguard Worker    # pcap-haiku.cpp:274:58: warning: unused parameter 'errbuf' [-Wunused-parameter]
95*8b26181fSAndroid Build Coastguard Worker    #
96*8b26181fSAndroid Build Coastguard Worker    # (The warnings below come from GCC and Clang in CMake builds after installing
97*8b26181fSAndroid Build Coastguard Worker    # all system updates.)
98*8b26181fSAndroid Build Coastguard Worker    # gencode.c:4143:9: warning: converting a packed 'struct in6_addr' pointer
99*8b26181fSAndroid Build Coastguard Worker    #   (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may
100*8b26181fSAndroid Build Coastguard Worker    #   result in an unaligned pointer value [-Waddress-of-packed-member]
101*8b26181fSAndroid Build Coastguard Worker    # gencode.c:4144:9: warning: converting a packed 'struct in6_addr' pointer
102*8b26181fSAndroid Build Coastguard Worker    #   (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may
103*8b26181fSAndroid Build Coastguard Worker    #   result in an unaligned pointer value [-Waddress-of-packed-member]
104*8b26181fSAndroid Build Coastguard Worker    # gencode.c:7189:9: warning: converting a packed 'struct in6_addr' pointer
105*8b26181fSAndroid Build Coastguard Worker    #   (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may
106*8b26181fSAndroid Build Coastguard Worker    #   result in an unaligned pointer value [-Waddress-of-packed-member]
107*8b26181fSAndroid Build Coastguard Worker    # gencode.c:7190:9: warning: converting a packed 'struct in6_addr' pointer
108*8b26181fSAndroid Build Coastguard Worker    #   (alignment 1) to a 'uint32_t' {aka 'unsigned int'} pointer (alignment 4) may
109*8b26181fSAndroid Build Coastguard Worker    #   result in an unaligned pointer value [-Waddress-of-packed-member]
110*8b26181fSAndroid Build Coastguard Worker    LIBPCAP_TAINTED=yes
111*8b26181fSAndroid Build Coastguard Worker    ;;
112*8b26181fSAndroid Build Coastguard Workeresac
113*8b26181fSAndroid Build Coastguard Worker[ "$LIBPCAP_TAINTED" != yes ] && CFLAGS=`cc_werr_cflags`
114*8b26181fSAndroid Build Coastguard Worker
115*8b26181fSAndroid Build Coastguard Workerif [ "$CMAKE" = no ]; then
116*8b26181fSAndroid Build Coastguard Worker    run_after_echo ./configure --prefix="$PREFIX" --enable-remote="$REMOTE"
117*8b26181fSAndroid Build Coastguard Workerelse
118*8b26181fSAndroid Build Coastguard Worker    # Remove the leftovers from any earlier in-source builds, so this
119*8b26181fSAndroid Build Coastguard Worker    # out-of-source build does not break because of that.
120*8b26181fSAndroid Build Coastguard Worker    # https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#what-is-an-out-of-source-build
121*8b26181fSAndroid Build Coastguard Worker    # (The contents of build/ remaining after an earlier unsuccessful attempt
122*8b26181fSAndroid Build Coastguard Worker    # can fail subsequent build attempts too, sometimes in non-obvious ways,
123*8b26181fSAndroid Build Coastguard Worker    # so remove that directory as well.)
124*8b26181fSAndroid Build Coastguard Worker    run_after_echo rm -rf CMakeFiles/ CMakeCache.txt build/
125*8b26181fSAndroid Build Coastguard Worker    run_after_echo mkdir build
126*8b26181fSAndroid Build Coastguard Worker    run_after_echo cd build
127*8b26181fSAndroid Build Coastguard Worker    run_after_echo cmake ${CFLAGS:+-DEXTRA_CFLAGS="$CFLAGS"} \
128*8b26181fSAndroid Build Coastguard Worker        -DCMAKE_INSTALL_PREFIX="$PREFIX" -DENABLE_REMOTE="$REMOTE" ..
129*8b26181fSAndroid Build Coastguard Workerfi
130*8b26181fSAndroid Build Coastguard Workerrun_after_echo "$MAKE_BIN" -s clean
131*8b26181fSAndroid Build Coastguard Workerif [ "$CMAKE" = no ]; then
132*8b26181fSAndroid Build Coastguard Worker    run_after_echo "$MAKE_BIN" -s ${CFLAGS:+CFLAGS="$CFLAGS"}
133*8b26181fSAndroid Build Coastguard Worker    run_after_echo "$MAKE_BIN" -s testprogs ${CFLAGS:+CFLAGS="$CFLAGS"}
134*8b26181fSAndroid Build Coastguard Workerelse
135*8b26181fSAndroid Build Coastguard Worker    # The "-s" flag is a no-op and CFLAGS is set using -DEXTRA_CFLAGS above.
136*8b26181fSAndroid Build Coastguard Worker    run_after_echo "$MAKE_BIN"
137*8b26181fSAndroid Build Coastguard Worker    run_after_echo "$MAKE_BIN" testprogs
138*8b26181fSAndroid Build Coastguard Workerfi
139*8b26181fSAndroid Build Coastguard Workerrun_after_echo "$MAKE_BIN" install
140*8b26181fSAndroid Build Coastguard Worker# VALGRIND_CMD is meant either to collapse or to expand.
141*8b26181fSAndroid Build Coastguard Worker# shellcheck disable=SC2086
142*8b26181fSAndroid Build Coastguard Workerif [ "$CMAKE" = no ]; then
143*8b26181fSAndroid Build Coastguard Worker    run_after_echo $VALGRIND_CMD testprogs/findalldevstest
144*8b26181fSAndroid Build Coastguard Worker    run_after_echo "$MAKE_BIN" releasetar
145*8b26181fSAndroid Build Coastguard Workerelse
146*8b26181fSAndroid Build Coastguard Worker    run_after_echo $VALGRIND_CMD run/findalldevstest
147*8b26181fSAndroid Build Coastguard Workerfi
148*8b26181fSAndroid Build Coastguard Workerhandle_matrix_debug
149*8b26181fSAndroid Build Coastguard Workerif [ "$DELETE_PREFIX" = yes ]; then
150*8b26181fSAndroid Build Coastguard Worker    run_after_echo rm -rf "$PREFIX"
151*8b26181fSAndroid Build Coastguard Workerfi
152*8b26181fSAndroid Build Coastguard Worker# vi: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab autoindent :
153