refactor: improve build configuration and output

- Track libicmp sources for proper dependency rebuilds
- Remove verbose build output (CC and LINK messages)
- Fix typo in help message (uninstal -> uninstall)
- Pass compiler flags to libicmp build
- Align configuration summary output
This commit is contained in:
lohhiiccc 2026-02-08 00:35:28 +01:00
parent 741576d01e
commit 0ddbb95bad
2 changed files with 39 additions and 21 deletions

View file

@ -22,6 +22,12 @@ MAKEFLAGS += --no-print-directory
# Include source files # Include source files
include sources.mk include sources.mk
# Get libicmp sources for dependency tracking if building locally
ifeq ($(BUILD_LOCAL_LIBICMP),yes)
LIBICMP_SRCS = $(shell find $(LIBICMP_DIR)/src -type f -name '*.c' 2>/dev/null)
LIBICMP_HEADERS = $(wildcard $(LIBICMP_DIR)/includes/*.h)
endif
# Build Directories # Build Directories
OBJ_DIR = build OBJ_DIR = build
OBJS = $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) OBJS = $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
@ -34,7 +40,7 @@ all: $(LIBICMP_DEP) $(NAME)
# Build local libicmp if needed # Build local libicmp if needed
ifeq ($(BUILD_LOCAL_LIBICMP),yes) ifeq ($(BUILD_LOCAL_LIBICMP),yes)
$(LIBICMP_DEP): $(LIBICMP_DEP): $(LIBICMP_SRCS) $(LIBICMP_HEADERS)
@echo "[BUILD] Building local libicmp..." @echo "[BUILD] Building local libicmp..."
$(MAKE) -C $(LIBICMP_DIR) -f $(LIBICMP_MAKEFILE) $(LIBICMP_BUILD_FLAGS) $(MAKE) -C $(LIBICMP_DIR) -f $(LIBICMP_MAKEFILE) $(LIBICMP_BUILD_FLAGS)
@echo "[OK] libicmp built successfully" @echo "[OK] libicmp built successfully"
@ -42,14 +48,12 @@ endif
# Link ft_ping # Link ft_ping
$(NAME): $(OBJS) $(LIBICMP_DEP) $(NAME): $(OBJS) $(LIBICMP_DEP)
@echo "[LINK] Linking $(NAME)..."
$(CC) -o $@ $(OBJS) $(LDFLAGS) $(CC) -o $@ $(OBJS) $(LDFLAGS)
@echo "[OK] $(NAME) built successfully" @echo "[OK] $(NAME) built successfully"
# Compile object files # Compile object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
@echo "[CC] $<"
$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@ $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@
# Include dependencies # Include dependencies
@ -202,7 +206,7 @@ help:
@echo " make or make all Build ft_ping" @echo " make or make all Build ft_ping"
@echo " make test Run tests (if enabled)" @echo " make test Run tests (if enabled)"
@echo " make install Install to PREFIX ($(PREFIX))" @echo " make install Install to PREFIX ($(PREFIX))"
@echo " make uninstal Uninstall from system" @echo " make uninstall Uninstall from system"
@echo " make clean Remove object files" @echo " make clean Remove object files"
@echo " make fclean Remove all built files" @echo " make fclean Remove all built files"
@echo " make re Rebuild everything" @echo " make re Rebuild everything"

24
configure vendored
View file

@ -518,11 +518,9 @@ generate_build_mk() {
# libicmp-specific configuration # libicmp-specific configuration
if [ "$USE_SYSTEM_LIBICMP" = "yes" ]; then if [ "$USE_SYSTEM_LIBICMP" = "yes" ]; then
LIBICMP_DEP="" LIBICMP_DEP=""
LIBICMP_BUILD_FLAGS=""
ldflags="-licmp" ldflags="-licmp"
else else
LIBICMP_DEP="$LIBICMP_PATH" LIBICMP_DEP="$LIBICMP_PATH"
LIBICMP_BUILD_FLAGS="BUILD_STATIC=$LIBICMP_BUILD_STATIC BUILD_SHARED=$LIBICMP_BUILD_SHARED"
cppflags="$cppflags -I $LIBICMP_DIR/includes" cppflags="$cppflags -I $LIBICMP_DIR/includes"
ldflags="-L$LIBICMP_DIR -licmp" ldflags="-L$LIBICMP_DIR -licmp"
@ -560,11 +558,27 @@ LIBICMP_DEP = $LIBICMP_DEP
EOF EOF
if [ "$BUILD_LOCAL_LIBICMP" = "yes" ]; then if [ "$BUILD_LOCAL_LIBICMP" = "yes" ]; then
local libicmp_cflags="-Wall -Wextra -Werror -pipe -Wpedantic -Wconversion"
local libicmp_cppflags="-std=c99 -I includes -D_POSIX_C_SOURCE=199309L"
libicmp_cflags="$libicmp_cflags $debug_flags"
if [ "$ENABLE_SANITIZERS" = "yes" ]; then
libicmp_cflags="$libicmp_cflags $sanitizer_flags"
fi
if [ "$ENABLE_LTO" = "yes" ]; then
libicmp_cflags="$libicmp_cflags $lto_flags"
fi
cat >> "$BUILD_MK" << EOF cat >> "$BUILD_MK" << EOF
# libicmp build configuration # libicmp build configuration
LIBICMP_BUILD_STATIC = $LIBICMP_BUILD_STATIC LIBICMP_BUILD_STATIC = $LIBICMP_BUILD_STATIC
LIBICMP_BUILD_SHARED = $LIBICMP_BUILD_SHARED LIBICMP_BUILD_SHARED = $LIBICMP_BUILD_SHARED
LIBICMP_BUILD_FLAGS = $LIBICMP_BUILD_FLAGS LIBICMP_CC = $CC
LIBICMP_CPPFLAGS = $libicmp_cppflags
LIBICMP_CFLAGS = $libicmp_cflags
LIBICMP_BUILD_FLAGS = BUILD_STATIC=\$(LIBICMP_BUILD_STATIC) BUILD_SHARED=\$(LIBICMP_BUILD_SHARED) CC=\$(LIBICMP_CC) CPPFLAGS="\$(LIBICMP_CPPFLAGS)" CFLAGS="\$(LIBICMP_CFLAGS)"
LIBICMP_MAKEFILE = $LIBICMP_MAKEFILE LIBICMP_MAKEFILE = $LIBICMP_MAKEFILE
EOF EOF
@ -661,9 +675,9 @@ EOF
cat << EOF cat << EOF
Compiler Flags: Compiler Flags:
CPPFLAGS: $(echo $CPPFLAGS | sed 's/^-std=c99 -I includes //') CPPFLAGS: $cppflags
CFLAGS: -Wall -Wextra -Werror -pipe $debug_flags $sanitizer_flags $lto_flags $strict_flags CFLAGS: -Wall -Wextra -Werror -pipe $debug_flags $sanitizer_flags $lto_flags $strict_flags
LDFLAGS: $LDFLAGS LDFLAGS: $ldflags
------------------------------------------------------------------------ ------------------------------------------------------------------------