Browse Source

build: out-of-tree VPATH build, tests run once with colored timing

- Root Makefile: hand-written bootstrap delegating to build/
- Makefile.am: simplified to SUBDIRS + clean-local
- build.sh: delegates to make, autoreconf only
- tests: removed duplicate TESTS run, added colored [PASS]/[FAIL]/[SKIP] with timing
- .gitignore: added /build/ for out-of-tree artifacts

Result: 0 .o files in source dirs, 29/29 tests pass
congestion
Evgeny 5 months ago
parent
commit
0f8df44b2b
  1. 3
      .gitignore
  2. 28
      Makefile
  3. 20
      Makefile.am
  4. 40
      build.sh
  5. 11
      tests/Makefile.am

3
.gitignore vendored

@ -1,3 +1,6 @@
# Build directory (out-of-tree build)
/build/
# Build outputs # Build outputs
*.o *.o
*.lo *.lo

28
Makefile

@ -0,0 +1,28 @@
# Bootstrap Makefile for utun
# All build artifacts (.o) go to build/ directory
# Final binary (utun) is copied to project root
BUILD_DIR = build
all:
@mkdir -p $(BUILD_DIR)
@if test ! -f $(BUILD_DIR)/config.status || test ./configure -nt $(BUILD_DIR)/config.status; then \
echo "Configuring in $(BUILD_DIR)/..."; \
cd $(BUILD_DIR) && ../configure; \
fi
@$(MAKE) -C $(BUILD_DIR)
clean:
-rm -rf $(BUILD_DIR)
distclean: clean
-rm -f config.status config.log config.h stamp-h1
-rm -rf autom4te.cache/
check: all
@$(MAKE) -C $(BUILD_DIR) check
install:
@$(MAKE) -C $(BUILD_DIR) install
.PHONY: all clean distclean check install

20
Makefile.am

@ -1,26 +1,8 @@
# Main Makefile.am for utun - root directory configuration # Main Makefile.am for utun - root directory configuration
# This is the root Makefile.am - tests are defined in tests/Makefile.am
# Basic configuration for root directory
# Order matters: lib -> src -> tests (tests depend on src objects) # Order matters: lib -> src -> tests (tests depend on src objects)
SUBDIRS = lib src tests SUBDIRS = lib src tests
# Build directory for out-of-tree builds
BUILD_DIR = build
# Custom target to run full build in separate directory
.PHONY: fullbuild
fullbuild:
@echo "Building in $(BUILD_DIR)/ directory..."
@$(MKDIR_P) $(BUILD_DIR)
@if test ! -f $(BUILD_DIR)/Makefile; then \
echo "Running configure in $(BUILD_DIR)..."; \
cd $(BUILD_DIR) && $(top_srcdir)/configure; \
fi
@$(MAKE) -C $(BUILD_DIR) all
@echo "Build complete. Binaries copied to project root."
# Clean build directory # Clean build directory
clean-local: clean-local:
-rm -rf $(BUILD_DIR) -rm -rf build/

40
build.sh

@ -69,17 +69,16 @@ fi
if [ "$CLEAN" -eq 1 ]; then if [ "$CLEAN" -eq 1 ]; then
echo "Cleaning build..." echo "Cleaning build..."
make clean 2>/dev/null || true make clean 2>/dev/null || true
rm -f config.status config.h
fi fi
# Full rebuild: clean everything and regenerate # Full rebuild: regenerate build system
if [ "$FULL_REBUILD" -eq 1 ]; then if [ "$FULL_REBUILD" -eq 1 ]; then
echo "" echo ""
echo "======================================" echo "======================================"
echo "FULL REBUILD: autoreconf + configure" echo "FULL REBUILD: autoreconf"
echo "======================================" echo "======================================"
echo "" echo ""
# Check for autotools # Check for autotools
if ! command -v autoreconf &> /dev/null; then if ! command -v autoreconf &> /dev/null; then
echo "Error: autoreconf not found." echo "Error: autoreconf not found."
@ -90,29 +89,24 @@ if [ "$FULL_REBUILD" -eq 1 ]; then
fi fi
exit 1 exit 1
fi fi
# Clean generated files # Clean generated files
echo "Cleaning generated files..." echo "Cleaning generated files..."
make distclean 2>/dev/null || true make distclean 2>/dev/null || true
rm -f config.status config.h Makefile */Makefile rm -rf build/
# Regenerate build system # Regenerate build system (root Makefile is hand-written, not generated)
echo "" echo ""
echo "Running autoreconf -fi..." echo "Running autoreconf -fi..."
autoreconf -fi 2>&1 | tee autoreconf.log autoreconf -fi 2>&1 | tee autoreconf.log
# Configure
echo ""
echo "Running configure..."
./configure --prefix=/usr/local 2>&1 | tee configure.log
echo "" echo ""
echo "======================================" echo "======================================"
echo "Build system regenerated successfully" echo "Build system regenerated successfully"
echo "======================================" echo "======================================"
echo "" echo ""
else else
# Quick/incremental build: only configure if needed # Quick/incremental build: generate configure if needed
if [ ! -f ./configure ]; then if [ ! -f ./configure ]; then
echo "Configure script not found. Generating..." echo "Configure script not found. Generating..."
if ! command -v autoreconf &> /dev/null; then if ! command -v autoreconf &> /dev/null; then
@ -126,21 +120,13 @@ else
fi fi
autoreconf -fiv autoreconf -fiv
fi fi
# Run configure if needed
if [ ! -f config.status ] || [ config.status -ot configure ]; then
echo "Configuring build..."
./configure --prefix=/usr/local 2>&1 | tee configure.log
else
echo "Using existing configuration."
fi
fi fi
# Build # Build (all .o files go to build/ directory, binary copied to project root)
echo "" echo ""
echo "Compiling with $JOBS..." echo "Compiling with $JOBS..."
BUILD_SUCCESS=0 BUILD_SUCCESS=0
make $JOBS $MAKE_ARGS 2>&1 | tee build_linux.log make $JOBS $MAKE_ARGS 2>&1 | tee build.log
if [ ${PIPESTATUS[0]} -eq 0 ]; then if [ ${PIPESTATUS[0]} -eq 0 ]; then
BUILD_SUCCESS=1 BUILD_SUCCESS=1
fi fi
@ -148,10 +134,10 @@ fi
if [ $BUILD_SUCCESS -eq 1 ]; then if [ $BUILD_SUCCESS -eq 1 ]; then
echo "" echo ""
echo "Build completed successfully!" echo "Build completed successfully!"
echo "Binary: src/utun" echo "Binary: utun"
else else
echo "" echo ""
echo "ERROR: Build failed!" echo "ERROR: Build failed!"
echo "Check build_linux.log for details" echo "Check build.log for details"
exit 1 exit 1
fi fi

11
tests/Makefile.am

@ -125,9 +125,7 @@ CRYPTO_LIBS = $(TINYCRYPT_OBJS)
TINYCRYPT_BUILT = tinycrypt-objects TINYCRYPT_BUILT = tinycrypt-objects
endif endif
# Register tests # Tests run via check-local (with timing and colored output), not TESTS
TESTS = $(check_PROGRAMS)
# Build TinyCrypt objects as a group (only when not using OpenSSL) # Build TinyCrypt objects as a group (only when not using OpenSSL)
if USE_OPENSSL if USE_OPENSSL
else else
@ -310,6 +308,7 @@ TEST_LOG_DIR = $(top_builddir)/tests/logs
# Custom check target that runs tests and saves logs to files # Custom check target that runs tests and saves logs to files
check-local: check-local:
@$(MKDIR_P) $(TEST_LOG_DIR); \ @$(MKDIR_P) $(TEST_LOG_DIR); \
G='\033[0;32m'; R='\033[0;31m'; Y='\033[0;33m'; N='\033[0m'; \
passed=0; \ passed=0; \
failed=0; \ failed=0; \
skipped=0; \ skipped=0; \
@ -323,12 +322,12 @@ check-local:
if "./$$test" > "$$logfile" 2>&1; then \ if "./$$test" > "$$logfile" 2>&1; then \
end=$$(date +%s%N); \ end=$$(date +%s%N); \
elapsed_ms=$$(( (end - start) / 1000000 )); \ elapsed_ms=$$(( (end - start) / 1000000 )); \
echo "[PASS] $$test ($${elapsed_ms}ms)"; \ printf "$${G}[PASS]$${N} %s (%sms)\n" "$$test" "$$elapsed_ms"; \
passed=$$((passed + 1)); \ passed=$$((passed + 1)); \
else \ else \
end=$$(date +%s%N); \ end=$$(date +%s%N); \
elapsed_ms=$$(( (end - start) / 1000000 )); \ elapsed_ms=$$(( (end - start) / 1000000 )); \
echo "[FAIL] $$test ($${elapsed_ms}ms) (see $$logfile)"; \ printf "$${R}[FAIL]$${N} %s (%sms) (see %s)\n" "$$test" "$$elapsed_ms" "$$logfile"; \
failed=$$((failed + 1)); \ failed=$$((failed + 1)); \
if test -z "$$failed_tests"; then \ if test -z "$$failed_tests"; then \
failed_tests="$$test"; \ failed_tests="$$test"; \
@ -337,7 +336,7 @@ check-local:
fi; \ fi; \
fi; \ fi; \
else \ else \
echo "[SKIP] $$test (not built)"; \ printf "$${Y}[SKIP]$${N} %s (not built)\n" "$$test"; \
skipped=$$((skipped + 1)); \ skipped=$$((skipped + 1)); \
fi; \ fi; \
done; \ done; \

Loading…
Cancel
Save