diff --git a/build.bat b/build.bat index 87234c2..90f73ee 100644 --- a/build.bat +++ b/build.bat @@ -2,6 +2,10 @@ echo uTun Build Script for MSYS2 UCRT64 echo. +rem export http_proxy="http://192.168.29.1:9999" +rem export https_proxy="http://192.168.29.1:9999" + + REM Default MSYS2 path set MSYS2_PATH=C:\msys64 diff --git a/build.sh b/build.sh index fb71f09..d7feb6c 100644 --- a/build.sh +++ b/build.sh @@ -65,16 +65,21 @@ if [ "$CLEAN" -eq 1 ]; then rm -f config.status config.h fi +# On Windows, use direct build to avoid make/autotools issues +if [ "$IS_WINDOWS" -eq 1 ]; then + echo "" + echo "Using direct build for Windows (bypassing make)..." + bash build_direct.sh + exit 0 +fi + +# Linux: use standard autotools build # Check if configure script exists if [ ! -f ./configure ]; then echo "Configure script not found. Generating..." if ! command -v autoreconf &> /dev/null; then echo "Error: autoreconf not found." - if [ "$IS_WINDOWS" -eq 1 ]; then - echo "Install autotools: pacman -S autoconf automake libtool" - else - echo "Install autotools: apt-get install autoconf automake libtool" - fi + echo "Install autotools: apt-get install autoconf automake libtool" exit 1 fi autoreconf -fiv @@ -83,13 +88,7 @@ fi # Run configure if needed if [ ! -f config.status ] || [ config.status -ot configure ]; then echo "Configuring build..." - if [ "$IS_WINDOWS" -eq 1 ]; then - # Windows: configure for mingw - ./configure --prefix=/usr/local --host=x86_64-w64-mingw32 2>&1 | tee configure.log - else - # Linux: standard configure - ./configure --prefix=/usr/local 2>&1 | tee configure.log - fi + ./configure --prefix=/usr/local 2>&1 | tee configure.log else echo "Using existing configuration." fi @@ -97,30 +96,18 @@ fi # Build echo "Compiling with $JOBS..." BUILD_SUCCESS=0 -if [ "$IS_WINDOWS" -eq 1 ]; then - make $JOBS $MAKE_ARGS 2>&1 | tee build_win.log - if [ ${PIPESTATUS[0]} -eq 0 ]; then - BUILD_SUCCESS=1 - fi -else - make $JOBS $MAKE_ARGS 2>&1 | tee build_linux.log - if [ ${PIPESTATUS[0]} -eq 0 ]; then - BUILD_SUCCESS=1 - fi +make $JOBS $MAKE_ARGS 2>&1 | tee build_linux.log +if [ ${PIPESTATUS[0]} -eq 0 ]; then + BUILD_SUCCESS=1 fi if [ $BUILD_SUCCESS -eq 1 ]; then echo "" echo "Build completed successfully!" - if [ "$IS_WINDOWS" -eq 1 ]; then - echo "Binary: src/utun.exe" - echo "Make sure wintun.dll is in the same directory as utun.exe" - else - echo "Binary: src/utun" - fi + echo "Binary: src/utun" else echo "" echo "ERROR: Build failed!" - echo "Check build_win.log (Windows) or build_linux.log (Linux) for details" + echo "Check build_linux.log for details" exit 1 -fi \ No newline at end of file +fi diff --git a/build_direct.sh b/build_direct.sh new file mode 100644 index 0000000..eaf1dd8 --- /dev/null +++ b/build_direct.sh @@ -0,0 +1,79 @@ +#!/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" diff --git a/configure.ac b/configure.ac index 205e0ea..f0d6ea5 100644 --- a/configure.ac +++ b/configure.ac @@ -21,8 +21,47 @@ AC_ARG_WITH([openssl], [with_openssl=yes]) if test "x$with_openssl" = "xyes"; then - AC_CHECK_LIB([crypto], [SHA256_Init], [], [AC_MSG_ERROR([OpenSSL crypto library required. Use --without-openssl to use TinyCrypt instead.])]) - AC_DEFINE([USE_OPENSSL], [1], [Define to use OpenSSL for cryptography]) + # For Windows cross-compilation, check MSYS2 paths + case "$host" in + *mingw* | *msys* | *cygwin* | *win*) + # Try MSYS2 UCRT64 paths + if test -d "/c/msys64/ucrt64/include/openssl"; then + OPENSSL_CFLAGS="-I/c/msys64/ucrt64/include" + OPENSSL_LIBS="-L/c/msys64/ucrt64/lib -lcrypto" + CFLAGS="$CFLAGS $OPENSSL_CFLAGS" + LDFLAGS="$LDFLAGS $OPENSSL_LIBS" + AC_MSG_NOTICE([Using MSYS2 UCRT64 OpenSSL: /c/msys64/ucrt64]) + elif test -d "/ucrt64/include/openssl"; then + OPENSSL_CFLAGS="-I/ucrt64/include" + OPENSSL_LIBS="-L/ucrt64/lib -lcrypto" + CFLAGS="$CFLAGS $OPENSSL_CFLAGS" + LDFLAGS="$LDFLAGS $OPENSSL_LIBS" + AC_MSG_NOTICE([Using MSYS2 UCRT64 OpenSSL: /ucrt64]) + elif test -d "/mingw64/include/openssl"; then + OPENSSL_CFLAGS="-I/mingw64/include" + OPENSSL_LIBS="-L/mingw64/lib -lcrypto" + CFLAGS="$CFLAGS $OPENSSL_CFLAGS" + LDFLAGS="$LDFLAGS $OPENSSL_LIBS" + AC_MSG_NOTICE([Using MSYS2 MINGW64 OpenSSL: /mingw64]) + fi + ;; + esac + + # Save original LIBS + save_LIBS="$LIBS" + # Add crypto library to LIBS for the check + LIBS="-lcrypto $LIBS" + + AC_CHECK_LIB([crypto], [SHA256_Init], + [ + AC_DEFINE([USE_OPENSSL], [1], [Define to use OpenSSL for cryptography]) + ], + [ + AC_MSG_ERROR([OpenSSL crypto library required. Use --without-openssl to use TinyCrypt instead.]) + ]) + + # Restore LIBS (the actual linking will use the flags we set) + LIBS="$save_LIBS" fi AM_CONDITIONAL([USE_OPENSSL], [test "x$with_openssl" = "xyes"]) diff --git a/utun.exe.manifest b/utun.exe.manifest new file mode 100644 index 0000000..6ac6948 --- /dev/null +++ b/utun.exe.manifest @@ -0,0 +1,12 @@ + + + + uTun VPN Tunnel + + + + + + + + diff --git a/wintun.dll b/wintun.dll deleted file mode 100644 index aee04e7..0000000 Binary files a/wintun.dll and /dev/null differ