#!/bin/bash # ETCP Monitor Build Script for MSYS2 UCRT64 / MinGW # Usage: ./build.sh # Log is automatically saved to build.log set -e # Capture all output to log file LOG_FILE="build.log" # Function to log and print log() { echo "$1" echo "$1" >> "$LOG_FILE" } # Clear or create log file > "$LOG_FILE" log "================================" log "ETCP Monitor Build Script" log "================================" log "" # Compiler settings CC=${CC:-gcc} CFLAGS="-Wall -O2 -DWIN32_LEAN_AND_MEAN" LDFLAGS="-mwindows" LIBS="-lws2_32 -lcomctl32 -luser32 -lgdi32" TARGET="etcpmon.exe" SRCS="etcpmon_main.c etcpmon_gui.c etcpmon_client.c etcpmon_graph.c" OBJ_FILES="" log "Compiler: $CC" log "Target: $TARGET" log "Sources: $SRCS" log "" # Clean previous build log "[1/5] Cleaning previous build..." rm -f *.o $TARGET # Compile each source file log "" log "[2/5] Compiling source files..." for src in $SRCS; do obj="${src%.c}.o" OBJ_FILES="$OBJ_FILES $obj" log " CC $src -> $obj" $CC $CFLAGS -c -o "$obj" "$src" 2>&1 | tee -a "$LOG_FILE" || { log "[ERROR] Failed to compile $src" exit 1 } done # Link log "" log "[3/5] Linking..." log " LD $OBJ_FILES -> $TARGET" $CC $LDFLAGS -o "$TARGET" $OBJ_FILES $LIBS 2>&1 | tee -a "$LOG_FILE" || { log "[ERROR] Failed to link $TARGET" exit 1 } # Strip debug symbols (optional, for smaller size) log "" log "[4/5] Stripping debug symbols..." strip "$TARGET" 2>/dev/null | tee -a "$LOG_FILE" || true # Verify build log "" log "[5/5] Verifying build..." if [ -f "$TARGET" ]; then FILE_SIZE=$(du -h "$TARGET" | cut -f1) log " OK: $TARGET created ($FILE_SIZE)" # Check dependencies log "" log "Checking dependencies..." if command -v objdump >/dev/null 2>&1; then objdump -p "$TARGET" | grep "DLL Name:" | head -10 | tee -a "$LOG_FILE" || true fi log "" log "================================" log "Build SUCCESS!" log "================================" log "" log "Executable: $TARGET" log "Size: $FILE_SIZE" log "Location: $(pwd)/$TARGET" log "" log "To run:" log " cd $(pwd)" log " ./$TARGET" log "" else log "" log "================================" log "Build FAILED!" log "================================" exit 1 fi