From 0ddbb95badd55168d188520b1f28a3da98f6f586 Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Sun, 8 Feb 2026 00:35:28 +0100 Subject: [PATCH] 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 --- Makefile | 12 ++++++++---- configure | 48 +++++++++++++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index cc56931..196a16a 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,12 @@ MAKEFLAGS += --no-print-directory # Include source files 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 OBJ_DIR = build OBJS = $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) @@ -34,7 +40,7 @@ all: $(LIBICMP_DEP) $(NAME) # Build local libicmp if needed ifeq ($(BUILD_LOCAL_LIBICMP),yes) -$(LIBICMP_DEP): +$(LIBICMP_DEP): $(LIBICMP_SRCS) $(LIBICMP_HEADERS) @echo "[BUILD] Building local libicmp..." $(MAKE) -C $(LIBICMP_DIR) -f $(LIBICMP_MAKEFILE) $(LIBICMP_BUILD_FLAGS) @echo "[OK] libicmp built successfully" @@ -42,14 +48,12 @@ endif # Link ft_ping $(NAME): $(OBJS) $(LIBICMP_DEP) - @echo "[LINK] Linking $(NAME)..." $(CC) -o $@ $(OBJS) $(LDFLAGS) @echo "[OK] $(NAME) built successfully" # Compile object files $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c @mkdir -p $(dir $@) - @echo "[CC] $<" $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@ # Include dependencies @@ -202,7 +206,7 @@ help: @echo " make or make all Build ft_ping" @echo " make test Run tests (if enabled)" @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 fclean Remove all built files" @echo " make re Rebuild everything" diff --git a/configure b/configure index 37950bf..397f2f2 100755 --- a/configure +++ b/configure @@ -518,14 +518,12 @@ generate_build_mk() { # libicmp-specific configuration if [ "$USE_SYSTEM_LIBICMP" = "yes" ]; then LIBICMP_DEP="" - LIBICMP_BUILD_FLAGS="" ldflags="-licmp" else LIBICMP_DEP="$LIBICMP_PATH" - LIBICMP_BUILD_FLAGS="BUILD_STATIC=$LIBICMP_BUILD_STATIC BUILD_SHARED=$LIBICMP_BUILD_SHARED" cppflags="$cppflags -I $LIBICMP_DIR/includes" ldflags="-L$LIBICMP_DIR -licmp" - + if [ "$FINAL_LIBRARY_TYPE" = "shared" ] && [ "$INSTALL_LIBICMP" = "yes" ]; then ldflags="$ldflags -Wl,-rpath,$LIBDIR" fi @@ -560,11 +558,27 @@ LIBICMP_DEP = $LIBICMP_DEP EOF 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 # libicmp build configuration LIBICMP_BUILD_STATIC = $LIBICMP_BUILD_STATIC 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 EOF @@ -638,32 +652,32 @@ show_summary() { Configuration Summary for $PROJECT_NAME ------------------------------------------------------------------------ -libicmp Source: $([ "$USE_SYSTEM_LIBICMP" = "yes" ] && echo "system ($PREFIX/lib)" || echo "local ($LIBICMP_DIR/)") -Library Type: $FINAL_LIBRARY_TYPE -Compiler: $CC -Installation Prefix: $PREFIX +libicmp Source: $([ "$USE_SYSTEM_LIBICMP" = "yes" ] && echo "system ($PREFIX/lib)" || echo "local ($LIBICMP_DIR/)") +Library Type: $FINAL_LIBRARY_TYPE +Compiler: $CC +Installation Prefix: $PREFIX Build Options: - Debug: $ENABLE_DEBUG - Sanitizers: $ENABLE_SANITIZERS - LTO: $ENABLE_LTO - Strict: $ENABLE_STRICT - Tests: $ENABLE_TESTS$([ "$ENABLE_TESTS" = "yes" ] && echo " ($([ "$SUDO_TESTS" = "yes" ] && echo "with sudo" || echo "without sudo"))" || echo "") + Debug: $ENABLE_DEBUG + Sanitizers: $ENABLE_SANITIZERS + LTO: $ENABLE_LTO + Strict: $ENABLE_STRICT + Tests: $ENABLE_TESTS$([ "$ENABLE_TESTS" = "yes" ] && echo " ($([ "$SUDO_TESTS" = "yes" ] && echo "with sudo" || echo "without sudo"))" || echo "") EOF if [ "$BUILD_LOCAL_LIBICMP" = "yes" ]; then cat << EOF -libicmp Installation: $([ "$INSTALL_LIBICMP" = "yes" ] && echo "yes (to $LIBICMP_PREFIX)" || echo "no (local use only)") +libicmp Installation: $([ "$INSTALL_LIBICMP" = "yes" ] && echo "yes (to $LIBICMP_PREFIX)" || echo "no (local use only)") EOF fi cat << EOF Compiler Flags: - CPPFLAGS: $(echo $CPPFLAGS | sed 's/^-std=c99 -I includes //') - CFLAGS: -Wall -Wextra -Werror -pipe $debug_flags $sanitizer_flags $lto_flags $strict_flags - LDFLAGS: $LDFLAGS + CPPFLAGS: $cppflags + CFLAGS: -Wall -Wextra -Werror -pipe $debug_flags $sanitizer_flags $lto_flags $strict_flags + LDFLAGS: $ldflags ------------------------------------------------------------------------