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
This commit is contained in:
1 parent
20144e6e6e
commit
a31fe7a612
5 files changed
+50
-52
No files matched your search
@@ -1,3 +1,6 @@
|
||||
# Build directory (out-of-tree build)
|
||||
/build/
|
||||
|
||||
# Build outputs
|
||||
*.o
|
||||
*.lo
|
||||
|
||||
@@ -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
|
||||
+1
-19
@@ -1,26 +1,8 @@
|
||||
# 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)
|
||||
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-local:
|
||||
-rm -rf $(BUILD_DIR)
|
||||
-rm -rf build/
|
||||
@@ -69,17 +69,16 @@ fi
|
||||
if [ "$CLEAN" -eq 1 ]; then
|
||||
echo "Cleaning build..."
|
||||
make clean 2>/dev/null || true
|
||||
rm -f config.status config.h
|
||||
fi
|
||||
|
||||
# Full rebuild: clean everything and regenerate
|
||||
# Full rebuild: regenerate build system
|
||||
if [ "$FULL_REBUILD" -eq 1 ]; then
|
||||
echo ""
|
||||
echo "======================================"
|
||||
echo "FULL REBUILD: autoreconf + configure"
|
||||
echo "FULL REBUILD: autoreconf"
|
||||
echo "======================================"
|
||||
echo ""
|
||||
|
||||
|
||||
# Check for autotools
|
||||
if ! command -v autoreconf &> /dev/null; then
|
||||
echo "Error: autoreconf not found."
|
||||
@@ -90,29 +89,24 @@ if [ "$FULL_REBUILD" -eq 1 ]; then
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Clean generated files
|
||||
echo "Cleaning generated files..."
|
||||
make distclean 2>/dev/null || true
|
||||
rm -f config.status config.h Makefile */Makefile
|
||||
|
||||
# Regenerate build system
|
||||
rm -rf build/
|
||||
|
||||
# Regenerate build system (root Makefile is hand-written, not generated)
|
||||
echo ""
|
||||
echo "Running autoreconf -fi..."
|
||||
autoreconf -fi 2>&1 | tee autoreconf.log
|
||||
|
||||
# Configure
|
||||
echo ""
|
||||
echo "Running configure..."
|
||||
./configure --prefix=/usr/local 2>&1 | tee configure.log
|
||||
|
||||
|
||||
echo ""
|
||||
echo "======================================"
|
||||
echo "Build system regenerated successfully"
|
||||
echo "======================================"
|
||||
echo ""
|
||||
else
|
||||
# Quick/incremental build: only configure if needed
|
||||
# Quick/incremental build: generate configure if needed
|
||||
if [ ! -f ./configure ]; then
|
||||
echo "Configure script not found. Generating..."
|
||||
if ! command -v autoreconf &> /dev/null; then
|
||||
@@ -126,21 +120,13 @@ else
|
||||
fi
|
||||
autoreconf -fiv
|
||||
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
|
||||
|
||||
# Build
|
||||
# Build (all .o files go to build/ directory, binary copied to project root)
|
||||
echo ""
|
||||
echo "Compiling with $JOBS..."
|
||||
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
|
||||
BUILD_SUCCESS=1
|
||||
fi
|
||||
@@ -148,10 +134,10 @@ fi
|
||||
if [ $BUILD_SUCCESS -eq 1 ]; then
|
||||
echo ""
|
||||
echo "Build completed successfully!"
|
||||
echo "Binary: src/utun"
|
||||
echo "Binary: utun"
|
||||
else
|
||||
echo ""
|
||||
echo "ERROR: Build failed!"
|
||||
echo "Check build_linux.log for details"
|
||||
echo "Check build.log for details"
|
||||
exit 1
|
||||
fi
|
||||
+5
-6
@@ -125,9 +125,7 @@ CRYPTO_LIBS = $(TINYCRYPT_OBJS)
|
||||
TINYCRYPT_BUILT = tinycrypt-objects
|
||||
endif
|
||||
|
||||
# Register tests
|
||||
TESTS = $(check_PROGRAMS)
|
||||
|
||||
# Tests run via check-local (with timing and colored output), not TESTS
|
||||
# Build TinyCrypt objects as a group (only when not using OpenSSL)
|
||||
if USE_OPENSSL
|
||||
else
|
||||
@@ -310,6 +308,7 @@ TEST_LOG_DIR = $(top_builddir)/tests/logs
|
||||
# Custom check target that runs tests and saves logs to files
|
||||
check-local:
|
||||
@$(MKDIR_P) $(TEST_LOG_DIR); \
|
||||
G='\033[0;32m'; R='\033[0;31m'; Y='\033[0;33m'; N='\033[0m'; \
|
||||
passed=0; \
|
||||
failed=0; \
|
||||
skipped=0; \
|
||||
@@ -323,12 +322,12 @@ check-local:
|
||||
if "./$$test" > "$$logfile" 2>&1; then \
|
||||
end=$$(date +%s%N); \
|
||||
elapsed_ms=$$(( (end - start) / 1000000 )); \
|
||||
echo "[PASS] $$test ($${elapsed_ms}ms)"; \
|
||||
printf "$${G}[PASS]$${N} %s (%sms)\n" "$$test" "$$elapsed_ms"; \
|
||||
passed=$$((passed + 1)); \
|
||||
else \
|
||||
end=$$(date +%s%N); \
|
||||
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)); \
|
||||
if test -z "$$failed_tests"; then \
|
||||
failed_tests="$$test"; \
|
||||
@@ -337,7 +336,7 @@ check-local:
|
||||
fi; \
|
||||
fi; \
|
||||
else \
|
||||
echo "[SKIP] $$test (not built)"; \
|
||||
printf "$${Y}[SKIP]$${N} %s (not built)\n" "$$test"; \
|
||||
skipped=$$((skipped + 1)); \
|
||||
fi; \
|
||||
done; \
|
||||
|
||||
Reference in new issue
Block a user