diff --git a/.gitignore b/.gitignore index 8994ecda..6de205ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Build directory (out-of-tree build) +/build/ + # Build outputs *.o *.lo diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..30a653e6 --- /dev/null +++ b/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 diff --git a/Makefile.am b/Makefile.am index 521908d8..01e7562c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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/ diff --git a/build.sh b/build.sh index c838defa..98094a67 100644 --- a/build.sh +++ b/build.sh @@ -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 diff --git a/tests/Makefile.am b/tests/Makefile.am index 1924957e..771e36aa 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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; \