Skip to content

Commit

Permalink
[libcap] Normalize (microsoft#33923)
Browse files Browse the repository at this point in the history
* [libcap] Normalize

* Update license

* Finish WIP
  • Loading branch information
dg0yt authored Sep 24, 2023
1 parent 2b0cdcb commit 559cbd3
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 144 deletions.
56 changes: 0 additions & 56 deletions ports/libcap/cap_names.h

This file was deleted.

13 changes: 0 additions & 13 deletions ports/libcap/cap_names.separation.patch

This file was deleted.

49 changes: 49 additions & 0 deletions ports/libcap/configure
Original file line number Diff line number Diff line change
@@ -1 +1,50 @@
#!/bin/sh

set -e

linkage=shared
prefix=
for OPTION; do
case "${OPTION}" in
--prefix=*)
prefix="${OPTION#--prefix=}"
;;
--enable-static)
linkage=static
;;
esac
done

cat > Makefile.vcpkg <<END_MAKEFILE ;
BUILD_OPTIONS = \
"AR=$AR" \
"BUILD_CC=$CC_FOR_BUILD" \
"CC=$CC" \
"RANLIB=$RANLIB" \
"lib=lib" \
"prefix=$prefix"
ifeq ($linkage,shared)
libs := libcap.so libpsx.so
BUILD_OPTIONS += SHARED=yes
else
libs := libcap.a libpsx.a
BUILD_OPTIONS += SHARED=no
endif
all: libcap/cap_names.h
\$(MAKE) -C libcap pcs \$(libs) \$(BUILD_OPTIONS)
libcap/cap_names.h:
\$(MAKE) -C libcap cap_names.h \$(BUILD_OPTIONS)
install: install-cap_names
\$(MAKE) -C libcap install-$linkage \$(BUILD_OPTIONS)
install-cap_names:
mkdir -p -m 0755 "\$(DESTDIR)$prefix/include/sys/libcap-private"
install -m 0644 libcap/cap_names.h "\$(DESTDIR)$prefix/include/sys/libcap-private"
install -m 0644 libcap/cap_names.list.h "\$(DESTDIR)$prefix/include/sys/libcap-private"
END_MAKEFILE
88 changes: 16 additions & 72 deletions ports/libcap/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,85 +1,29 @@
vcpkg_from_git(
OUT_SOURCE_PATH SOURCE_PATH
URL git://git.kernel.org/pub/scm/libs/libcap/libcap.git
FETCH_REF "libcap-${VERSION}"
REF 3c7dda330bd9a154bb5b878d31fd591e4951fe17
PATCHES
cap_names.separation.patch
OUT_SOURCE_PATH SOURCE_PATH
URL git://git.kernel.org/pub/scm/libs/libcap/libcap.git
FETCH_REF "libcap-${VERSION}"
REF 3c7dda330bd9a154bb5b878d31fd591e4951fe17
)
# Note: if libcap version is updated, the according cap_names.h should be updated if necessary.

# SKIP_CONFIGURE is broken https://github.com/microsoft/vcpkg/issues/14389
# so we use patch to create empty configure executable
file(COPY "${CMAKE_CURRENT_LIST_DIR}/configure" DESTINATION "${SOURCE_PATH}")

# This needs to be called before configure
vcpkg_cmake_get_vars(cmake_vars_file)

if(VCPKG_CROSSCOMPILING)
file(COPY "${CMAKE_CURRENT_LIST_DIR}/cap_names.h" DESTINATION "${SOURCE_PATH}/libcap/")
endif ()
file(TOUCH "${SOURCE_PATH}/libcap/_makenames")
file(COPY "${CURRENT_HOST_INSTALLED_DIR}/include/sys/libcap-private/cap_names.list.h" DESTINATION "${SOURCE_PATH}/libcap/")
file(COPY "${CURRENT_HOST_INSTALLED_DIR}/include/sys/libcap-private/cap_names.h" DESTINATION "${SOURCE_PATH}/libcap/")
file(TOUCH "${SOURCE_PATH}/libcap/cap_names.h")
endif()

vcpkg_configure_make(
SOURCE_PATH "${SOURCE_PATH}"
COPY_SOURCE
SOURCE_PATH "${SOURCE_PATH}"
COPY_SOURCE
DETERMINE_BUILD_TRIPLET
)

include("${cmake_vars_file}")
list(APPEND libcap_OPTIONS "prefix=${CURRENT_INSTALLED_DIR}" "CC=${VCPKG_DETECTED_CMAKE_C_COMPILER}" "AR=${VCPKG_DETECTED_CMAKE_AR}" "RANLIB=${VCPKG_DETECTED_CMAKE_RANLIB}")

if (NOT VCPKG_CROSSCOMPILING)
# patch decouples cap_names.h target from libcap.* for cross compile compatibility,
# so for host=target build we manually make it
vcpkg_build_make(SUBPATH libcap
BUILD_TARGET cap_names.h
LOGFILE_ROOT "configure"
OPTIONS
${libcap_OPTIONS}
)
endif ()

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
vcpkg_build_make(SUBPATH libcap
BUILD_TARGET libcap.a
LOGFILE_ROOT "build"
OPTIONS
${libcap_OPTIONS}
)
else()
vcpkg_build_make(SUBPATH libcap
BUILD_TARGET libcap.so
LOGFILE_ROOT "build"
OPTIONS
${libcap_OPTIONS}
)
endif()

vcpkg_build_make(SUBPATH libcap
BUILD_TARGET libcap.pc
LOGFILE_ROOT "pkgconfig"
OPTIONS
${libcap_OPTIONS}
vcpkg_install_make(
MAKEFILE "Makefile.vcpkg"
)
vcpkg_fixup_pkgconfig()

file(INSTALL "${SOURCE_PATH}/libcap/include/" DESTINATION "${CURRENT_PACKAGES_DIR}/include" FILES_MATCHING PATTERN "*.h")

set(BUILD_DIR_RELEASE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(INSTALL "${BUILD_DIR_RELEASE}/libcap/libcap.a" DESTINATION "${CURRENT_PACKAGES_DIR}/lib")
else()
file(INSTALL "${BUILD_DIR_RELEASE}/libcap/libcap.so" DESTINATION "${CURRENT_PACKAGES_DIR}/lib" FOLLOW_SYMLINK_CHAIN)
endif()

set(BUILD_DIR_DEBUG "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(INSTALL "${BUILD_DIR_DEBUG}/libcap/libcap.a" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib")
else()
file(INSTALL "${BUILD_DIR_DEBUG}/libcap/libcap.so" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib" FOLLOW_SYMLINK_CHAIN)
endif()

file(INSTALL "${BUILD_DIR_RELEASE}/libcap/libcap.pc" DESTINATION "${CURRENT_PACKAGES_DIR}/lib/pkgconfig")
file(INSTALL "${BUILD_DIR_DEBUG}/libcap/libcap.pc" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/License")

vcpkg_fixup_pkgconfig()
9 changes: 7 additions & 2 deletions ports/libcap/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
"name": "libcap",
"version": "2.69",
"description": "capability library: includes libcap2 file caps, setcap, getcap and capsh",
"port-version": 1,
"description": "A library for getting and setting POSIX.1e (formerly POSIX 6) draft 15 capabilities.",
"homepage": "https://git.kernel.org/pub/scm/libs/libcap/libcap.git",
"license": "BSD-3-Clause",
"license": "BSD-3-Clause OR GPL-2.0-only",
"supports": "linux",
"dependencies": [
{
"name": "libcap",
"host": true
},
{
"name": "vcpkg-cmake-get-vars",
"host": true
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -3994,7 +3994,7 @@
},
"libcap": {
"baseline": "2.69",
"port-version": 0
"port-version": 1
},
"libcbor": {
"baseline": "0.10.2",
Expand Down
5 changes: 5 additions & 0 deletions versions/l-/libcap.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "3f8091b1a094e5a0ab51652478289c040e98e7ca",
"version": "2.69",
"port-version": 1
},
{
"git-tree": "78c061106eac6df0a86b27df684998c780c70008",
"version": "2.69",
Expand Down

0 comments on commit 559cbd3

Please sign in to comment.