-
-
Save penafieljlm/35c4246998c2cf6a6d3143601eb6f92e to your computer and use it in GitHub Desktop.
Building openvpn3 C++ library with Java bindings on Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
choco install -y git python2 vcbuildtools jdk8 swig | |
$baseDir="C:\work\openvpn3lib\dep" | |
Write-Host "Preparing base dir $baseDir" | |
New-Item -Force "$baseDir\deps" -ItemType Directory | |
Set-Location "$baseDir" | |
Write-Host "Downloading dependencies..." | |
git clone https://github.com/OpenVPN/openvpn3.git openvpn3 | |
git clone https://github.com/OpenVPN/tap-windows.git | |
$(New-Object net.webclient).DownloadFile("https://github.com/chriskohlhoff/asio/archive/master.zip", "$baseDir/deps/asio-master.zip") | |
$(New-Object net.webclient).DownloadFile("https://github.com/lz4/lz4/archive/master.zip", "$baseDir/deps/lz4-master.zip") | |
$(New-Object net.webclient).DownloadFile("https://github.com/ARMmbed/mbedtls/archive/master.zip", "$baseDir/deps/mbedtls-master.zip") | |
$baseDirEscaped=$baseDir.Replace("\", "\\") | |
Write-Host "Writing parms_local.py using escaped base dir $baseDirEscaped" | |
Set-Location "$baseDir\openvpn3\win" | |
@" | |
PARMS = { | |
"OVPN3" : "$baseDirEscaped\\openvpn3", | |
"TAP" : "$baseDirEscaped\\tap-windows", | |
"DEP" : "$baseDirEscaped\\deps", | |
"BUILD" : "$baseDirEscaped\\build", | |
"LIB_VERSIONS" : { | |
"asio" : "asio-master" | |
}, | |
"GTEST_ROOT": "$baseDirEscaped\\googletest" | |
} | |
"@ | Out-File -encoding ascii .\parms_local.py | |
Write-Host "Building dependencies..." | |
python .\buildep.py | |
Write-Host "Patching ovpncli.i with proper paths..." | |
Set-Location "$baseDir\openvpn3\javacli" | |
Get-Content .\ovpncli.i | %{$_ -replace '"ovpncli.hpp"', '"client/ovpncli.hpp"'} | Out-File -encoding ascii .\ovpncli-fix.i | |
Move-Item -Force .\ovpncli-fix.i .\ovpncli.i | |
Write-Host "Creating Java bindings with SWIG tool..." | |
Set-Location "$baseDir\openvpn3" | |
# C:\work\swigwin-3.0.12\swig.exe -c++ -java .\javacli\ovpncli.i | |
swig -c++ -java .\javacli\ovpncli.i | |
Write-Host "Loading MSVC C++ build toolkit environment variables in current shell..." | |
cmd /c @" | |
call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" amd64 && set | |
"@ | Select-String '^([^=]+)=(.*)' | % { $_.Matches } | % { $("`${Env:$($_.Groups[1].Value)}=`"$($_.Groups[2].Value)`"") } > vsenv.ps1 | |
. .\vsenv.ps1 | |
Write-Host "Setting VC++ project environment variables..." | |
${Env:OVPN3_CORE}="$baseDir\openvpn3" | |
${Env:OVPN3_TAP_WINDOWS}="$baseDir\tap-windows" | |
${Env:OVPN3_BUILD}="$baseDir\build" | |
# msbuild ovpn3-core.sln -t:cli /p:Configuration=Release;Platform=x64 | |
Write-Host "Building openvpn3 shared library ovpncli_wrap.dll" | |
cl /LD /DSWIGJAVA /D_WIN32_WINNT=0x0600 /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS ` | |
/DUSE_ASIO /DASIO_STANDALONE /DASIO_NO_DEPRECATED /I "${Env:OVPN3_BUILD}\amd64\asio\asio\include" ` | |
/DUSE_MBEDTLS /I "${Env:OVPN3_BUILD}\amd64\mbedtls\include" ` | |
/DHAVE_LZ4 /I "${Env:OVPN3_BUILD}\amd64\lz4\lib" ` | |
-DTAP_WIN_COMPONENT_ID=tap0901 /I "${Env:OVPN3_TAP_WINDOWS}\src" ` | |
/I "C:\Program Files\Java\jdk1.8.0_152\include" /I "C:\Program Files\Java\jdk1.8.0_152\include\win32" ` | |
/I "${Env:OVPN3_CORE}" /GL /EHsc /MT /W0 /O2 /nologo ` | |
javacli\ovpncli_wrap.cxx client\ovpncli.cpp ` | |
/link kernel32.lib advapi32.lib iphlpapi.lib ole32.lib shell32.lib fwpuclnt.lib rpcrt4.lib ` | |
"${Env:OVPN3_BUILD}\amd64\mbedtls\library\mbedtls.lib" ` | |
"${Env:OVPN3_BUILD}\amd64\lz4\lib\lz4.lib" | |
New-Item -Force "$baseDir\dist" -ItemType Directory | |
$(cmd /c dir /b /s javacli\ovpncli_* javacli\ovpncli*.java javacli\ClientAPI_*.java javacli\SWIGTYPE_*.java) | % { Copy $_ "$baseDir\dist\" -Force } | |
Write-Host "Here are resulting files:" | |
cmd /c dir /b /s "$baseDir\dist" | |
Add-Type -assembly "System.Io.Compression.Filesystem" | |
[Io.Compression.ZipFile]::CreateFromDirectory("$baseDir\dist", "$baseDir\openvpn3-jni-windows.zip") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment