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
if BUILD_BUNDLED_LIBCLI
SUBDIRS = libcli src
if BUILD_TESTS
SUBDIRS += tests
else
SUBDIRS = src
endif
# libicmp uses a simple Makefile (not Autotools); invoke it as a hook.

View file

@ -2,14 +2,5 @@
# autogen.sh - Generate Autotools build files
set -e
# Generate libcli configure first (it's an Autotools submodule)
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"
mkdir -pv m4 build-aux
autoreconf -f --install --verbose

View file

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

View file

@ -1,12 +1,12 @@
bin_PROGRAMS = ft_ping
noinst_LTLIBRARIES = libping_core.la
bin_PROGRAMS = ft_ping
noinst_LTLIBRARIES = libping_core.la
PING_VERSION = 0.0.1
VERSION_HEADER = $(top_srcdir)/includes/version_gen.h
PING_VERSION = 0.0.1
VERSION_HEADER = $(top_srcdir)/includes/version_gen.h
# Version header: generated at build time (embeds git hash + date)
BUILT_SOURCES = $(VERSION_HEADER)
CLEANFILES = $(VERSION_HEADER)
BUILT_SOURCES = $(VERSION_HEADER)
CLEANFILES = $(VERSION_HEADER)
$(VERSION_HEADER): FORCE
@NEW_HEADER=$$(mktemp); \
@ -41,83 +41,78 @@ $(VERSION_HEADER): FORCE
FORCE:
.PHONY: FORCE
libping_core_la_SOURCES = \
cli/parse.c \
cli/handlers/handle_count.c \
cli/handlers/handle_preload.c \
cli/handlers/handle_pattern.c \
cli/handlers/handle_dont_fragment.c \
cli/handlers/handle_linger.c \
cli/handlers/handle_flood.c \
cli/handlers/handle_help.c \
cli/handlers/handle_interval.c \
cli/handlers/handle_quiet.c \
cli/handlers/option_map.c \
cli/handlers/handle_size.c \
cli/handlers/handle_timeout.c \
cli/handlers/handle_tos.c \
cli/handlers/handle_ttl.c \
cli/handlers/handle_version.c \
cli/handlers/handle_verbose.c \
cli/parse_utils/parse_inet_addr.c \
cli/parse_utils/parse_destinations.c \
cli/config_free.c \
cli/messages/help.c \
cli/messages/version.c \
cli/messages/error.c \
core/ping.c \
core/loop.c \
core/send.c \
core/callback.c \
tracker/init.c \
tracker/record_send.c \
tracker/record_recv.c \
output/start.c \
output/packet.c \
output/error.c \
output/summary.c \
output/flood.c \
scheduler/scheduler_arm.c \
scheduler/scheduler_select_tv.c \
scheduler/scheduler_init.c \
stats/stats_get.c \
stats/stats_init.c \
stats/stats_update.c
libping_core_la_SOURCES = \
cli/parse.c \
cli/handlers/handle_count.c \
cli/handlers/handle_preload.c \
cli/handlers/handle_pattern.c \
cli/handlers/handle_dont_fragment.c \
cli/handlers/handle_linger.c \
cli/handlers/handle_flood.c \
cli/handlers/handle_help.c \
cli/handlers/handle_interval.c \
cli/handlers/handle_quiet.c \
cli/handlers/option_map.c \
cli/handlers/handle_size.c \
cli/handlers/handle_timeout.c \
cli/handlers/handle_tos.c \
cli/handlers/handle_ttl.c \
cli/handlers/handle_version.c \
cli/handlers/handle_verbose.c \
cli/parse_utils/parse_inet_addr.c \
cli/parse_utils/parse_destinations.c \
cli/config_free.c \
cli/messages/help.c \
cli/messages/version.c \
cli/messages/error.c \
core/ping.c \
core/loop.c \
core/send.c \
core/callback.c \
tracker/init.c \
tracker/record_send.c \
tracker/record_recv.c \
output/start.c \
output/packet.c \
output/error.c \
output/summary.c \
output/flood.c \
scheduler/scheduler_arm.c \
scheduler/scheduler_select_tv.c \
scheduler/scheduler_init.c \
stats/stats_get.c \
stats/stats_init.c \
stats/stats_update.c
BASE_CFLAGS = -std=c99 $(STRICT_CFLAGS)
BASE_CFLAGS = -std=c99 $(STRICT_CFLAGS)
if ENABLE_DEBUG
EXTRA_CFLAGS = -g -O0
EXTRA_CFLAGS = -g -O0
else
EXTRA_CFLAGS =
EXTRA_CFLAGS =
endif
if ENABLE_SANITIZERS
SANITIZER_FLAGS = -fsanitize=address,undefined
else
SANITIZER_FLAGS =
endif
PING_CPPFLAGS = \
-I $(top_srcdir)/includes \
-I $(top_srcdir)/libicmp/includes \
-I $(top_srcdir)/libcli/include \
-D_GNU_SOURCE
PING_CPPFLAGS = \
-I $(top_srcdir)/includes \
-I $(top_srcdir)/libicmp/includes \
-I $(top_srcdir)/libcli/include \
-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_CFLAGS = $(PING_CFLAGS)
libping_core_la_CPPFLAGS = $(PING_CPPFLAGS)
libping_core_la_CFLAGS = $(PING_CFLAGS)
ft_ping_SOURCES = main.c
ft_ping_CPPFLAGS = $(PING_CPPFLAGS)
ft_ping_CFLAGS = $(PING_CFLAGS)
ft_ping_LDFLAGS = $(SANITIZER_FLAGS)
ft_ping_LDADD = \
libping_core.la \
$(top_srcdir)/libicmp/libicmp.a \
$(top_builddir)/libcli/src/libcli.la \
-lm
ft_ping_SOURCES = main.c
ft_ping_CPPFLAGS = $(PING_CPPFLAGS)
ft_ping_CFLAGS = $(PING_CFLAGS)
ft_ping_LDFLAGS =
ft_ping_LDADD = \
libping_core.la \
$(top_srcdir)/libicmp/libicmp.a \
$(top_builddir)/libcli/src/libcli.la \
-lm
# Build libicmp (simple Makefile) before linking
$(top_srcdir)/libicmp/libicmp.a: FORCE

View file

@ -1,59 +1,53 @@
check_PROGRAMS = test_tracker test_stats test_send
check_PROGRAMS = test_tracker test_stats test_send
test_tracker_SOURCES = test_support.c ping/tracker/test_tracker.c
test_stats_SOURCES = test_support.c ping/stats/test_stats.c
test_send_SOURCES = test_support.c send/test_do_send.c
test_tracker_SOURCES = test_support.c ping/tracker/test_tracker.c
test_stats_SOURCES = test_support.c ping/stats/test_stats.c
test_send_SOURCES = test_support.c send/test_do_send.c
BASE_CFLAGS = -std=c99 $(STRICT_CFLAGS)
BASE_CFLAGS = -std=c99 $(STRICT_CFLAGS)
if ENABLE_DEBUG
EXTRA_CFLAGS = -g -O0
EXTRA_CFLAGS = -g -O0
else
EXTRA_CFLAGS =
EXTRA_CFLAGS =
endif
if ENABLE_SANITIZERS
SANITIZER_FLAGS = -fsanitize=address,undefined
else
SANITIZER_FLAGS =
endif
TEST_CPPFLAGS = \
-I $(top_srcdir)/includes \
-I $(top_srcdir)/libicmp/includes \
-I $(top_srcdir)/libcli/include \
-I $(top_srcdir)/tests \
-D_GNU_SOURCE
TEST_CPPFLAGS = \
-I $(top_srcdir)/includes \
-I $(top_srcdir)/libicmp/includes \
-I $(top_srcdir)/libcli/include \
-I $(top_srcdir)/tests \
-D_GNU_SOURCE
TEST_CFLAGS = $(BASE_CFLAGS) $(EXTRA_CFLAGS)
TEST_CFLAGS = $(BASE_CFLAGS) $(EXTRA_CFLAGS) $(SANITIZER_FLAGS)
TEST_LDADD = \
$(top_builddir)/src/ping/libping_core.la \
$(top_srcdir)/libicmp/libicmp.a \
$(top_builddir)/libcli/src/libcli.la \
$(CRITERION_LIBS) \
-lm
TEST_LDADD = \
$(top_builddir)/src/ping/libping_core.la \
$(top_srcdir)/libicmp/libicmp.a \
$(top_builddir)/libcli/src/libcli.la \
$(CRITERION_LIBS) \
-lm
test_tracker_CPPFLAGS = $(TEST_CPPFLAGS)
test_tracker_CFLAGS = $(TEST_CFLAGS)
test_tracker_LDFLAGS =
test_tracker_LDADD = $(TEST_LDADD)
test_tracker_CPPFLAGS = $(TEST_CPPFLAGS)
test_tracker_CFLAGS = $(TEST_CFLAGS)
test_tracker_LDFLAGS = $(SANITIZER_FLAGS)
test_tracker_LDADD = $(TEST_LDADD)
test_stats_CPPFLAGS = $(TEST_CPPFLAGS)
test_stats_CFLAGS = $(TEST_CFLAGS)
test_stats_LDFLAGS =
test_stats_LDADD = $(TEST_LDADD)
test_stats_CPPFLAGS = $(TEST_CPPFLAGS)
test_stats_CFLAGS = $(TEST_CFLAGS)
test_stats_LDFLAGS = $(SANITIZER_FLAGS)
test_stats_LDADD = $(TEST_LDADD)
test_send_CPPFLAGS = $(TEST_CPPFLAGS)
test_send_CFLAGS = $(TEST_CFLAGS)
test_send_LDFLAGS = \
-Wl,--wrap=icmp_send_echo \
-Wl,--wrap=icmp_should_retry \
-Wl,--wrap=icmp_strerror \
-Wl,--wrap=ping_scheduler_arm
test_send_LDADD = $(TEST_LDADD)
test_send_CPPFLAGS = $(TEST_CPPFLAGS)
test_send_CFLAGS = $(TEST_CFLAGS)
test_send_LDFLAGS = $(SANITIZER_FLAGS) \
-Wl,--wrap=icmp_send_echo \
-Wl,--wrap=icmp_should_retry \
-Wl,--wrap=icmp_strerror \
-Wl,--wrap=ping_scheduler_arm
test_send_LDADD = $(TEST_LDADD)
TESTS = test_tracker test_stats test_send
TESTS = test_tracker test_stats test_send
# Version header needed by test_main.c
BUILT_SOURCES = $(top_srcdir)/includes/version_gen.h
BUILT_SOURCES = $(top_srcdir)/includes/version_gen.h