Skip to content

Commit

Permalink
libpcap: enable windows (#5436)
Browse files Browse the repository at this point in the history
* libpcap: enable  windows

* set precompiled false

* fix mingw

* fix precompiled

* add patch for mingw

* fix msys flex bison
  • Loading branch information
star-hengxing authored Oct 8, 2024
1 parent ac8c8da commit 25314b3
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 12 deletions.
11 changes: 9 additions & 2 deletions packages/b/bison/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ package("bison")

if on_source then
on_source(function (package)
if not package:is_plat("windows") then
if not package:is_plat("windows", "mingw", "msys") then
package:add("urls", "http://ftpmirror.gnu.org/gnu/bison/bison-$(version).tar.gz",
"http://ftp.gnu.org/gnu/bison/bison-$(version).tar.gz")
end
end)
elseif not is_plat("windows") then
elseif not is_plat("windows", "mingw", "msys") then
add_urls("http://ftpmirror.gnu.org/gnu/bison/bison-$(version).tar.gz",
"http://ftp.gnu.org/gnu/bison/bison-$(version).tar.gz")
end
Expand All @@ -20,6 +20,10 @@ package("bison")
add_versions("3.7.6", "69dc0bb46ea8fc307d4ca1e0b61c8c355eb207d0b0c69f4f8462328e74d7b9ea")
add_versions("3.8.2", "06c9e13bdf7eb24d4ceb6b59205a4f67c2c7e7213119644430fe82fbd14a0abb")

if is_subhost("msys") then
add_deps("pacman::bison")
end

on_load("macosx", "linux", "bsd", "windows", function (package)
if package:is_plat("windows") then
package:add("deps", "winflexbison", {private = true})
Expand All @@ -35,6 +39,9 @@ package("bison")
end
end)

on_install("@msys", function (package)
end)

on_install("windows", function (package)
os.cp(path.join(package:dep("winflexbison"):installdir(), "*"), package:installdir())
os.rm(path.join(package:installdir(), "bin", "flex.exe"))
Expand Down
11 changes: 9 additions & 2 deletions packages/f/flex/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ package("flex")

if on_source then
on_source(function (package)
if not package:is_plat("windows") then
if not package:is_plat("windows", "mingw", "msys") then
package:add("urls", "https://github.com/westes/flex/releases/download/v$(version)/flex-$(version).tar.gz")
end
end)
elseif not is_plat("windows") then
elseif not is_plat("windows", "mingw", "msys") then
add_urls("https://github.com/westes/flex/releases/download/v$(version)/flex-$(version).tar.gz")
end

if is_subhost("msys") then
add_deps("pacman::flex")
end

on_load("macosx", "linux", "bsd", "windows", function (package)
if package:is_plat("windows") then
package:add("deps", "winflexbison", {private = true})
Expand All @@ -30,6 +34,9 @@ package("flex")
end
end)

on_install("@msys", function (package)
end)

on_install("windows", function (package)
os.cp(path.join(package:dep("winflexbison"):installdir(), "*"), package:installdir())
os.rm(path.join(package:installdir(), "bin", "bison.exe"))
Expand Down
21 changes: 21 additions & 0 deletions packages/l/libpcap/patches/1.10.5/cmake-mingw.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 851b3cc9..cc2bc97f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3221,13 +3221,16 @@ if(WIN32)
# For compatibility, build the shared library without the "lib" prefix on
# MinGW as well.
#
+ if(BUILD_SHARED_LIBS)
set_target_properties(${LIBRARY_NAME} PROPERTIES
PREFIX ""
OUTPUT_NAME "${LIBRARY_NAME}"
)
+ else()
set_target_properties(${LIBRARY_NAME}_static PROPERTIES
OUTPUT_NAME "${LIBRARY_NAME}"
)
+ endif()
endif()
else(WIN32) # UN*X
if(BUILD_SHARED_LIBS)
30 changes: 30 additions & 0 deletions packages/l/libpcap/patches/1.10.5/cmake-msvc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/rpcapd/CMakeLists.txt b/rpcapd/CMakeLists.txt
index 555d6d40..7446687e 100644
--- a/rpcapd/CMakeLists.txt
+++ b/rpcapd/CMakeLists.txt
@@ -87,13 +87,13 @@ if(WIN32 OR ((CMAKE_USE_PTHREADS_INIT OR PTHREADS_FOUND) AND HAVE_CRYPT))
OSX_ARCHITECTURES "${OSX_EXECUTABLE_ARCHITECTURES}")
endif()

- if(WIN32)
+ if(BUILD_SHARED_LIBS)
target_link_libraries(rpcapd ${LIBRARY_NAME}
${RPCAPD_LINK_LIBRARIES} ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
- else(WIN32)
+ else(BUILD_SHARED_LIBS)
target_link_libraries(rpcapd ${LIBRARY_NAME}_static
${RPCAPD_LINK_LIBRARIES} ${PCAP_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
- endif(WIN32)
+ endif(BUILD_SHARED_LIBS)

######################################
# Install rpcap daemon and man pages
@@ -119,7 +119,7 @@ if(WIN32 OR ((CMAKE_USE_PTHREADS_INIT OR PTHREADS_FOUND) AND HAVE_CRYPT))
# will determine where it goes.
#
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
- install(TARGETS rpcapd DESTINATION bin/amd64)
+ install(TARGETS rpcapd DESTINATION bin)
else(CMAKE_SIZEOF_VOID_P EQUAL 8)
install(TARGETS rpcapd DESTINATION bin)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
43 changes: 36 additions & 7 deletions packages/l/libpcap/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package("libpcap")

set_homepage("https://www.tcpdump.org/")
set_description("the LIBpcap interface to various kernel packet capture mechanism")
set_license("BSD-3-Clause")

add_urls("https://www.tcpdump.org/release/libpcap-$(version).tar.gz", {alias = "home"})
add_urls("https://github.com/the-tcpdump-group/libpcap.git", {alias = "github", version = function (version) return "libpcap-" .. version end})

add_versions("home:1.10.5", "37ced90a19a302a7f32e458224a00c365c117905c2cd35ac544b6880a81488f0")
add_versions("home:1.10.4", "ed19a0383fad72e3ad435fd239d7cd80d64916b87269550159d20e47160ebe5f")
add_versions("home:1.10.3", "2a8885c403516cf7b0933ed4b14d6caa30e02052489ebd414dc75ac52e7559e6")
Expand All @@ -19,16 +19,35 @@ package("libpcap")
add_versions("github:1.10.1", "7b650c9e0ce246aa41ba5463fe8e903efc444c914a3ccb986547350bed077ed6")

add_configs("remote", {description = "Enable remote capture support (requires openssl)", default = true, type = "boolean"})


if is_plat("mingw", "msys") then
add_patches("1.10.5", "patches/1.10.5/cmake-mingw.patch", "6b27886a5be489aa03150790330b5c78320cec3067ca62f3a2fde9565cbeb344")
end

add_deps("cmake", "flex", "bison")
if is_plat("windows", "mingw", "msys") then
add_deps("npcap_sdk")
end

on_load(function (package)
if package:config("remote") then
package:add("deps", "openssl")
if package:is_plat("windows", "mingw", "msys") then
package:add("patches", "1.10.5", "patches/1.10.5/cmake-msvc.patch", "eeb6d0bf9eca935eb97c789cbb6752cbdaff7bf88b533e90b66ef086afbd26b0")
end
end
end)

on_install("linux", "macosx", "android", "bsd", function (package)
on_install("!iphoneos and !wasm", function (package)
io.replace("CMakeLists.txt", "add_subdirectory(testprogs)", "", {plain = true})
if package:is_plat("windows", "mingw", "msys") then
io.replace("CMakeLists.txt", "/x64", "", {plain = true}) -- fix install dir
io.replace("CMakeLists.txt", "${OPENSSL_LIBRARIES}", "${OPENSSL_LIBRARIES} ws2_32 user32 crypt32 advapi32", {plain = true})
if package:is_plat("mingw", "msys") then
io.replace("CMakeLists.txt", "check_function_exists(asprintf HAVE_ASPRINTF)", "", {plain = true})
end
end

local configs = {
"-DDISABLE_AIRPCAP=ON",
"-DDISABLE_DPDK=ON",
Expand All @@ -41,21 +60,31 @@ package("libpcap")
"-DDISABLE_SNF=ON",
"-DDISABLE_TC=ON",
"-DCMAKE_POLICY_DEFAULT_CMP0057=NEW",
"-DUSE_STATIC_RT=OFF", -- Use CMAKE_MSVC_RUNTIME_LIBRARY
}
if package:is_plat("macosx") and package:is_arch("arm64") then
table.insert(configs, "-DCMAKE_OSX_ARCHITECTURES=arm64")
end
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DUSE_STATIC_RT=" .. (package:config("shared") and "OFF" or "ON"))
table.insert(configs, "-DENABLE_REMOTE=" .. (package:config("remote") and "ON" or "OFF"))

local opt = {}
if package:is_plat("windows") then
os.mkdir(path.join(package:buildir(), "rpcapd/pdb"))
end
import("package.tools.cmake").install(package, configs)

if package:config("shared") then
os.rm(path.join(package:installdir("lib"), "lib*.a"))
if package:is_plat("mingw", "msys") then
os.rm(package:installdir("lib/libpcap.a"))
else
os.rm(package:installdir("lib/lib*.a"))
end
os.rm(package:installdir("lib/*_static*"))
else
os.rm(path.join(package:installdir("lib"), "lib*.so"))
os.rm(path.join(package:installdir("lib"), "lib*.dylib"))
os.rm(package:installdir("lib/lib*.so"))
os.rm(package:installdir("lib/lib*.dylib"))
end
end)

Expand Down
5 changes: 4 additions & 1 deletion packages/n/npcap_sdk/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package("npcap_sdk")
set_description("Npcap is the Nmap Project's packet capture (and sending) library for Microsoft Windows.")

set_urls("https://npcap.com/dist/npcap-sdk-$(version).zip")

add_versions("1.13", "dad1f2bf1b02b787be08ca4862f99e39a876c1f274bac4ac0cedc9bbc58f94fd")
add_versions("1.12", "24c4862723f61d28048a24e10eb31d2269b2152a5762410dd1caffc041871337")

on_install("windows", "mingw", function (package)
set_policy("package.precompiled", false)

on_install("windows", "mingw", "msys", function (package)
if package:is_plat("mingw") and package:version():eq("1.13") then
io.replace("Include/Packet32.h", "_Post_invalid_", "", {plain = true})
end
Expand Down

0 comments on commit 25314b3

Please sign in to comment.