Build: Fix Windows build with OpenSSL support
- Added automatic OpenSSL detection for MSYS2 UCRT64 in configure.ac - Simplified build.sh to use direct build script on Windows - Added build_direct.sh for bypassing make/autotools issues - Fixed CFLAGS/LDFLAGS to include OpenSSL paths - Binary now correctly links with libcrypto-3-x64.dll Fixes linker errors for uECC_* and tc_* functions when using OpenSSL.
This commit is contained in:
1 parent
8a3cdaf759
commit
47f2f8a025
6 files changed
+153
-32
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
fi
|
||||
@@ -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"
|
||||
+41
-2
@@ -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"])
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<assemblyIdentity version="1.0.0.0" name="utun.exe" type="win32"/>
|
||||
<description>uTun VPN Tunnel</description>
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
|
||||
<security>
|
||||
<requestedPrivileges>
|
||||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
|
||||
</requestedPrivileges>
|
||||
</security>
|
||||
</trustInfo>
|
||||
</assembly>
|
||||
BIN
Binary file not shown.
Reference in new issue
Block a user