This commit is contained in:
lohhiiccc 2026-04-23 21:04:15 +02:00
parent 459b5ac959
commit 9999b9595d
5 changed files with 176 additions and 173 deletions

View file

@ -1,9 +1,9 @@
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
if BUILD_BUNDLED_LIBCLI
SUBDIRS = libcli src SUBDIRS = libcli src
else
if BUILD_TESTS SUBDIRS = src
SUBDIRS += tests
endif endif
# libicmp uses a simple Makefile (not Autotools); invoke it as a hook. # libicmp uses a simple Makefile (not Autotools); invoke it as a hook.

View file

@ -2,14 +2,5 @@
# autogen.sh - Generate Autotools build files # autogen.sh - Generate Autotools build files
set -e set -e
mkdir -pv m4 build-aux
# Generate libcli configure first (it's an Autotools submodule) autoreconf -f --install --verbose
if [ -f libcli/autogen.sh ]; then
echo "[autogen] Configuring libcli submodule..."
(cd libcli && ./autogen.sh)
fi
echo "[autogen] Running autoreconf..."
autoreconf -fiv
echo "[autogen] Done. Now run: ./configure && make"

View file

@ -2,7 +2,7 @@ AC_PREREQ([2.69])
AC_INIT([net-tools], [0.0.1], []) AC_INIT([net-tools], [0.0.1], [])
AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIRS([m4]) AC_CONFIG_MACRO_DIRS([m4])
AM_INIT_AUTOMAKE([foreign -Wall subdir-objects]) AM_INIT_AUTOMAKE([foreign -Wall -Werror subdir-objects])
# Compiler: prefer clang # Compiler: prefer clang
AC_PROG_CC AC_PROG_CC
@ -13,48 +13,69 @@ if test "x$GCC" = "xyes" && test "x$CC" = "xgcc"; then
AC_MSG_NOTICE([Using clang]) AC_MSG_NOTICE([Using clang])
fi fi
fi fi
if test "x$ac_cv_env_CFLAGS_set" != "xset"; then
CFLAGS="-O2"
fi
AM_PROG_AR AM_PROG_AR
LT_PREREQ([2.2]) LT_PREREQ([2.2])
LT_INIT LT_INIT
# Strict flags — always enabled, not optional PKG_PROG_PKG_CONFIG
STRICT_CFLAGS="-Wall -Wextra -Werror -Wpedantic -Wconversion -Wshadow"
AC_SUBST([STRICT_CFLAGS]) # --enable-debug
AC_ARG_ENABLE(
[debug],
[AS_HELP_STRING([--enable-debug], [Enable debug build: -g -O0 (default: no)])],
[enable_debug=$enableval],
[enable_debug=no]
)
AM_CONDITIONAL([ENABLE_DEBUG], [test "x$enable_debug" = "xyes"])
# --with-bundled-libcli
AC_ARG_WITH(
[bundled-libcli],
AS_HELP_STRING([--with-bundled-libcli], [force using bundled ./libcli (ignore system)]),
[with_bundled_libcli=yes],
[with_bundled_libcli=no]
)
have_system_libcli=no
AS_IF([test "x$with_bundled_libcli" != "xyes"], [
PKG_CHECK_MODULES(
[LIBCLI], [libcli >= 0.1.0],
[have_system_libcli=yes],
[have_system_libcli=no]
)
])
AM_CONDITIONAL([USE_SYSTEM_LIBCLI], [test "x$have_system_libcli" = "xyes"])
AM_CONDITIONAL([BUILD_BUNDLED_LIBCLI], [test "x$have_system_libcli" != "xyes"])
AC_SUBST([LIBCLI_CFLAGS])
AC_SUBST([LIBCLI_LIBS])
AS_IF([test "x$have_system_libcli" != "xyes"], [AC_CONFIG_SUBDIRS([libcli])])
# libcli: Autotools submodule — configure automatically
AC_CONFIG_SUBDIRS([libcli])
# --enable-tests # --enable-tests
AC_ARG_ENABLE([tests], AC_ARG_ENABLE(
[tests],
[AS_HELP_STRING([--enable-tests], [Build Criterion unit tests (default: no)])], [AS_HELP_STRING([--enable-tests], [Build Criterion unit tests (default: no)])],
[enable_tests=$enableval], [enable_tests=$enableval],
[enable_tests=no]) [enable_tests=no]
)
AM_CONDITIONAL([BUILD_TESTS], [test "x$enable_tests" = "xyes"]) AM_CONDITIONAL([BUILD_TESTS], [test "x$enable_tests" = "xyes"])
AS_IF([test "x$enable_tests" = "xyes"], [ AS_IF([test "x$enable_tests" = "xyes"], [
PKG_CHECK_MODULES([CRITERION], [criterion], [], [ PKG_CHECK_MODULES([CRITERION], [criterion], [], [
AC_MSG_NOTICE([pkg-config could not find criterion -- trying manual detection]) AC_MSG_NOTICE([pkg-config could not find criterion -- trying manual detection])
AC_CHECK_HEADER([criterion/criterion.h], [], [ AC_CHECK_HEADER([criterion/criterion.h], [], [AC_MSG_ERROR([criterion/criterion.h not found])])
AC_MSG_ERROR([criterion/criterion.h not found])])
AC_CHECK_LIB([criterion], [main], AC_CHECK_LIB([criterion], [main],
[CRITERION_LIBS="-lcriterion"], [CRITERION_LIBS="-lcriterion"],
[AC_MSG_ERROR([libcriterion not found])]) [AC_MSG_ERROR([libcriterion not found])])
]) ])
]) ])
# --enable-debug
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug], [Enable debug build: -g -O0 (default: no)])],
[enable_debug=$enableval],
[enable_debug=no])
AM_CONDITIONAL([ENABLE_DEBUG], [test "x$enable_debug" = "xyes"])
# --enable-sanitizers
AC_ARG_ENABLE([sanitizers],
[AS_HELP_STRING([--enable-sanitizers],
[Enable AddressSanitizer and UndefinedBehaviorSanitizer (default: no)])],
[enable_sanitizers=$enableval],
[enable_sanitizers=no])
AM_CONDITIONAL([ENABLE_SANITIZERS], [test "x$enable_sanitizers" = "xyes"])
AC_CONFIG_FILES([ AC_CONFIG_FILES([
Makefile Makefile
@ -62,15 +83,17 @@ AC_CONFIG_FILES([
src/ping/Makefile src/ping/Makefile
tests/Makefile tests/Makefile
]) ])
AC_OUTPUT AC_OUTPUT
AC_MSG_NOTICE([ AC_MSG_NOTICE([
net-tools $VERSION net-tools $VERSION
------------------ ------------------
PREFIX : $prefix
CC : $CC CC : $CC
CFLAGS : $STRICT_CFLAGS CFLAGS : $STRICT_CFLAGS
tests : $enable_tests tests : $enable_tests
debug : $enable_debug debug : $enable_debug
sanitizers : $enable_sanitizers libcli : system=$have_system_libcli (forced bundled=$with_bundled_libcli)
]) ])

View file

@ -92,11 +92,6 @@ else
EXTRA_CFLAGS = EXTRA_CFLAGS =
endif endif
if ENABLE_SANITIZERS
SANITIZER_FLAGS = -fsanitize=address,undefined
else
SANITIZER_FLAGS =
endif
PING_CPPFLAGS = \ PING_CPPFLAGS = \
-I $(top_srcdir)/includes \ -I $(top_srcdir)/includes \
@ -104,7 +99,7 @@ PING_CPPFLAGS = \
-I $(top_srcdir)/libcli/include \ -I $(top_srcdir)/libcli/include \
-D_GNU_SOURCE -D_GNU_SOURCE
PING_CFLAGS = $(BASE_CFLAGS) $(EXTRA_CFLAGS) $(SANITIZER_FLAGS) PING_CFLAGS = $(BASE_CFLAGS) $(EXTRA_CFLAGS)
libping_core_la_CPPFLAGS = $(PING_CPPFLAGS) libping_core_la_CPPFLAGS = $(PING_CPPFLAGS)
libping_core_la_CFLAGS = $(PING_CFLAGS) libping_core_la_CFLAGS = $(PING_CFLAGS)
@ -112,7 +107,7 @@ libping_core_la_CFLAGS = $(PING_CFLAGS)
ft_ping_SOURCES = main.c ft_ping_SOURCES = main.c
ft_ping_CPPFLAGS = $(PING_CPPFLAGS) ft_ping_CPPFLAGS = $(PING_CPPFLAGS)
ft_ping_CFLAGS = $(PING_CFLAGS) ft_ping_CFLAGS = $(PING_CFLAGS)
ft_ping_LDFLAGS = $(SANITIZER_FLAGS) ft_ping_LDFLAGS =
ft_ping_LDADD = \ ft_ping_LDADD = \
libping_core.la \ libping_core.la \
$(top_srcdir)/libicmp/libicmp.a \ $(top_srcdir)/libicmp/libicmp.a \

View file

@ -12,12 +12,6 @@ else
EXTRA_CFLAGS = EXTRA_CFLAGS =
endif endif
if ENABLE_SANITIZERS
SANITIZER_FLAGS = -fsanitize=address,undefined
else
SANITIZER_FLAGS =
endif
TEST_CPPFLAGS = \ TEST_CPPFLAGS = \
-I $(top_srcdir)/includes \ -I $(top_srcdir)/includes \
-I $(top_srcdir)/libicmp/includes \ -I $(top_srcdir)/libicmp/includes \
@ -25,7 +19,7 @@ TEST_CPPFLAGS = \
-I $(top_srcdir)/tests \ -I $(top_srcdir)/tests \
-D_GNU_SOURCE -D_GNU_SOURCE
TEST_CFLAGS = $(BASE_CFLAGS) $(EXTRA_CFLAGS) $(SANITIZER_FLAGS) TEST_CFLAGS = $(BASE_CFLAGS) $(EXTRA_CFLAGS)
TEST_LDADD = \ TEST_LDADD = \
$(top_builddir)/src/ping/libping_core.la \ $(top_builddir)/src/ping/libping_core.la \
@ -36,17 +30,17 @@ TEST_LDADD = \
test_tracker_CPPFLAGS = $(TEST_CPPFLAGS) test_tracker_CPPFLAGS = $(TEST_CPPFLAGS)
test_tracker_CFLAGS = $(TEST_CFLAGS) test_tracker_CFLAGS = $(TEST_CFLAGS)
test_tracker_LDFLAGS = $(SANITIZER_FLAGS) test_tracker_LDFLAGS =
test_tracker_LDADD = $(TEST_LDADD) test_tracker_LDADD = $(TEST_LDADD)
test_stats_CPPFLAGS = $(TEST_CPPFLAGS) test_stats_CPPFLAGS = $(TEST_CPPFLAGS)
test_stats_CFLAGS = $(TEST_CFLAGS) test_stats_CFLAGS = $(TEST_CFLAGS)
test_stats_LDFLAGS = $(SANITIZER_FLAGS) test_stats_LDFLAGS =
test_stats_LDADD = $(TEST_LDADD) test_stats_LDADD = $(TEST_LDADD)
test_send_CPPFLAGS = $(TEST_CPPFLAGS) test_send_CPPFLAGS = $(TEST_CPPFLAGS)
test_send_CFLAGS = $(TEST_CFLAGS) test_send_CFLAGS = $(TEST_CFLAGS)
test_send_LDFLAGS = $(SANITIZER_FLAGS) \ test_send_LDFLAGS = \
-Wl,--wrap=icmp_send_echo \ -Wl,--wrap=icmp_send_echo \
-Wl,--wrap=icmp_should_retry \ -Wl,--wrap=icmp_should_retry \
-Wl,--wrap=icmp_strerror \ -Wl,--wrap=icmp_strerror \