#!/bin/bash # Direct build script for uTun on Windows with OpenSSL # This script bypasses the complex autotools make dependencies set -e echo "uTun Direct Build Script for Windows with OpenSSL" echo "==================================================" echo "" # Detect MSYS2 environment and set OpenSSL paths if [ -d "/c/msys64/ucrt64/include/openssl" ]; then export CFLAGS="$CFLAGS -I/c/msys64/ucrt64/include" export LDFLAGS="$LDFLAGS -L/c/msys64/ucrt64/lib" echo "Using MSYS2 UCRT64 OpenSSL" elif [ -d "/ucrt64/include/openssl" ]; then export CFLAGS="$CFLAGS -I/ucrt64/include" export LDFLAGS="$LDFLAGS -L/ucrt64/lib" echo "Using MSYS2 UCRT64 OpenSSL" elif [ -d "/mingw64/include/openssl" ]; then export CFLAGS="$CFLAGS -I/mingw64/include" export LDFLAGS="$LDFLAGS -L/mingw64/lib" echo "Using MSYS2 MINGW64 OpenSSL" fi # Run configure if needed if [ ! -f config.status ] || [ config.status -ot configure ]; then echo "" echo "Running configure..." ./configure --prefix=/usr/local --host=x86_64-w64-mingw32 --disable-dependency-tracking 2>&1 | tee configure.log fi # Create necessary directories mkdir -p src/.deps lib/.deps tests/.deps echo "" echo "Building libuasync.a..." cd lib # Build library objects for src in u_async.c ll_queue.c memory_pool.c debug_config.c timeout_heap.c sha256.c platform_compat.c socket_compat.c; do if [ -f "$src" ]; then obj="${src%.c}.o" echo " CC $src" x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -c "$src" -o "$obj" 2>&1 | grep -v "warning:" || true fi done # Create static library ar cru libuasync.a *.o ranlib libuasync.a cd .. echo "" echo "Building utun.exe..." cd src # Build source objects CORE_SOURCES="utun.c utun_instance.c config_parser.c config_updater.c route_lib.c route_bgp.c routing.c tun_if.c tun_route.c etcp.c etcp_connections.c etcp_loadbalancer.c secure_channel.c crc32.c pkt_normalizer.c etcp_api.c tun_windows.c" for src in $CORE_SOURCES; do obj="utun-${src%.c}.o" echo " CC $src" x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I../lib -I../tinycrypt/lib/include -I../tinycrypt/lib/source $CFLAGS -g -O2 -c "$src" -o "$obj" 2>&1 | grep -E "error:|warning:.*deprecated" || true done # Link executable echo " LINK utun.exe" x86_64-w64-mingw32-gcc -o utun.exe utun-*.o ../lib/libuasync.a -lpthread -lm -lws2_32 -liphlpapi -lbcrypt $LDFLAGS -lcrypto 2>&1 | grep -E "error:|undefined reference" || true # Copy to root cp utun.exe ../utun.exe cd .. echo "" echo "Build completed successfully!" echo "Binary: utun.exe" echo "" echo "Make sure wintun.dll is in the same directory as utun.exe"