Skip to content

Commit

Permalink
Merge branch 'portability/freebsd'
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-klode committed Aug 26, 2016
2 parents 75d238b + 01d207a commit 6a68315
Show file tree
Hide file tree
Showing 44 changed files with 370 additions and 119 deletions.
17 changes: 14 additions & 3 deletions CMake/FindBerkeleyDB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,25 @@
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


# We need NO_DEFAULT_PATH here, otherwise CMake helpfully picks up the wrong
# db.h on BSD systems instead of the Berkeley DB one.
find_path(BERKELEY_DB_INCLUDE_DIRS db.h
/usr/include/db5
${CMAKE_INSTALL_FULL_INCLUDEDIR}/db5
/usr/local/include/db5
/usr/include/db4
/usr/include/db5

${CMAKE_INSTALL_FULL_INCLUDEDIR}/db4
/usr/local/include/db4
/usr/include/db4

${CMAKE_INSTALL_FULL_INCLUDEDIR}
/usr/local/include
/usr/include

NO_DEFAULT_PATH
)

find_library(BERKELEY_DB_LIBRARIES NAMES db )
find_library(BERKELEY_DB_LIBRARIES NAMES db db-5)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Berkeley "Could not find Berkeley DB >= 4.1" BERKELEY_DB_INCLUDE_DIRS BERKELEY_DB_LIBRARIES)
Expand Down
20 changes: 20 additions & 0 deletions CMake/FindIconv.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
find_path(ICONV_INCLUDE_DIR NAMES iconv.h)

find_library(ICONV_LIBRARY NAMES iconv)
if (ICONV_LIBRARY)
set(ICONV_SYMBOL_FOUND "${ICONV_LIBRARY}")
else()
check_function_exists(iconv_open ICONV_SYMBOL_FOUND)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Iconv DEFAULT_MESSAGE ICONV_INCLUDE_DIR ICONV_SYMBOL_FOUND)

if(ICONV_LIBRARY)
set(ICONV_LIBRARIES "${ICONV_LIBRARY}")
else()
set(ICONV_LIBRARIES)
endif()
set(ICONV_INCLUDE_DIRS "${ICONV_INCLUDE_DIR}")

mark_as_advanced(ICONV_LIBRARY ICONV_INCLUDE_DIR)
25 changes: 25 additions & 0 deletions CMake/FindLZ4.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# - Try to find LZ4
# Once done, this will define
#
# LZ4_FOUND - system has LZ4
# LZ4_INCLUDE_DIRS - the LZ4 include directories
# LZ4_LIBRARIES - the LZ4 library
find_package(PkgConfig)

pkg_check_modules(LZ4_PKGCONF liblz4)

find_path(LZ4_INCLUDE_DIRS
NAMES lz4frame.h
PATHS ${LZ4_PKGCONF_INCLUDE_DIRS}
)


find_library(LZ4_LIBRARIES
NAMES lz4
PATHS ${LZ4_PKGCONF_LIBRARY_DIRS}
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LZ4 DEFAULT_MSG LZ4_INCLUDE_DIRS LZ4_LIBRARIES)

mark_as_advanced(LZ4_INCLUDE_DIRS LZ4_LIBRARIES)
25 changes: 25 additions & 0 deletions CMake/FindLZMA.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# - Try to find LZMA
# Once done, this will define
#
# LZMA_FOUND - system has LZMA
# LZMA_INCLUDE_DIRS - the LZMA include directories
# LZMA_LIBRARIES - the LZMA library
find_package(PkgConfig)

pkg_check_modules(LZMA_PKGCONF liblzma)

find_path(LZMA_INCLUDE_DIRS
NAMES lzma.h
PATHS ${LZMA_PKGCONF_INCLUDE_DIRS}
)


find_library(LZMA_LIBRARIES
NAMES lzma
PATHS ${LZMA_PKGCONF_LIBRARY_DIRS}
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LZMA DEFAULT_MSG LZMA_INCLUDE_DIRS LZMA_LIBRARIES)

mark_as_advanced(LZMA_INCLUDE_DIRS LZMA_LIBRARIES)
18 changes: 18 additions & 0 deletions CMake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
/* Define if we have sys/mount.h */
#cmakedefine HAVE_MOUNT_H

/* Define if we have sys/endian.h */
#cmakedefine HAVE_SYS_ENDIAN_H

/* Define if we have machine/endian.h */
#cmakedefine HAVE_MACHINE_ENDIAN_H

/* Define if we have enabled pthread support */
#cmakedefine HAVE_PTHREAD

Expand All @@ -49,6 +55,18 @@
/* The mail address to reach upstream */
#define PACKAGE_MAIL "${PACKAGE_MAIL}"

/* Various directories */
#cmakedefine CMAKE_INSTALL_FULL_BINDIR "${CMAKE_INSTALL_FULL_BINDIR}"
#cmakedefine STATE_DIR "${STATE_DIR}"
#cmakedefine CACHE_DIR "${CACHE_DIR}"
#cmakedefine LOG_DIR "${LOG_DIR}"
#cmakedefine CONF_DIR "${CONF_DIR}"
#cmakedefine LIBEXEC_DIR "${LIBEXEC_DIR}"
#cmakedefine BIN_DIR "${BIN_DIR}"

/* Group of the root user */
#cmakedefine ROOT_GROUP "${ROOT_GROUP}"

#define APT_8_CLEANER_HEADERS
#define APT_9_CLEANER_HEADERS
#define APT_10_CLEANER_HEADERS
Expand Down
9 changes: 9 additions & 0 deletions CMake/endian.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <config.h>

#ifdef HAVE_MACHINE_ENDIAN_H
#include <machine/endian.h>
#endif
#ifdef HAVE_SYS_ENDIAN_H
#include <sys/types.h>
#include <sys/endian.h>
#endif
99 changes: 79 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# set minimum version
project(apt)
cmake_minimum_required(VERSION 3.4.0)
# Generic header locations
include_directories(${PROJECT_BINARY_DIR}/include)


enable_testing()

Expand All @@ -25,8 +28,14 @@ include(CheckStructHasMember)
include(GNUInstallDirs)
include(TestBigEndian)
find_package(Threads)
find_package(PkgConfig)
find_package(LFS REQUIRED)
find_package(Iconv REQUIRED)

if(USE_NLS)
find_package(Intl REQUIRED)
link_libraries(${Intl_LIBRARIES})
include_directories(${Intl_INCLUDE_DIRS})
endif()

# Add large file support
add_compile_options(${LFS_COMPILE_OPTIONS})
Expand Down Expand Up @@ -78,25 +87,27 @@ if (BZIP2_FOUND)
set(HAVE_BZ2 1)
endif()

pkg_check_modules(LZMA liblzma)
find_package(LZMA)
if (LZMA_FOUND)
set(HAVE_LZMA 1)
endif()

pkg_check_modules(LZ4 liblz4)

find_package(LZ4)
if (LZ4_FOUND)
set(HAVE_LZ4 1)
endif()

# Mount()ing and stat()ing and friends
check_symbol_exists(statfs sys/vfs.h HAVE_VFS_H)
check_include_files(sys/params.h HAVE_PARAMS_H)
check_symbol_exists(statfs sys/mount.h HAVE_MOUNT_H)
if (NOT HAVE_VFS_H AND NOT HAVE_MOUNT_H)
message(FATAL_ERROR "Can find neither statvfs() nor statfs()")
endif()

check_function_exists(statvfs HAVE_STATVFS)
if (NOT HAVE_STATVFS)
check_symbol_exists(statfs sys/vfs.h HAVE_VFS_H)
check_symbol_exists(statfs sys/mount.h HAVE_MOUNT_H)
if (NOT HAVE_VFS_H AND NOT HAVE_MOUNT_H)
message(FATAL_ERROR "Can find neither statvfs() nor statfs()")
endif()
configure_file(CMake/statvfs.h.in ${PROJECT_BINARY_DIR}/include/statvfs.h COPYONLY)
endif()

Expand All @@ -111,10 +122,46 @@ check_function_exists(ptsname_r HAVE_PTSNAME_R)
check_function_exists(timegm HAVE_TIMEGM)
test_big_endian(WORDS_BIGENDIAN)

# FreeBSD
add_definitions(-D_WITH_GETLINE=1)

if (CMAKE_USE_PTHREADS_INIT)
set(HAVE_PTHREAD 1)
endif()

CHECK_INCLUDE_FILES(machine/endian.h HAVE_MACHINE_ENDIAN_H)
CHECK_INCLUDE_FILES(sys/endian.h HAVE_SYS_ENDIAN_H)
CHECK_INCLUDE_FILES(endian.h HAVE_ENDIAN_H)
if (NOT HAVE_ENDIAN_H)
if (HAVE_MACHINE_ENDIAN_H OR HAVE_SYS_ENDIAN_H)
configure_file(CMake/endian.h.in ${PROJECT_BINARY_DIR}/include/endian.h)
else()
message(FATAL_ERROR "Cannot find endian.h")
endif()
endif()


include(CheckTypeSize)
set(CMAKE_EXTRA_INCLUDE_FILES "signal.h")
check_type_size("sig_t" SIG_T LANGUAGE "CXX")
check_type_size("sighandler_t" SIGHANDLER_T LANGUAGE "CXX")
set(CMAKE_EXTRA_INCLUDE_FILES)
if (NOT HAVE_SIGHANDLER_T)
if (HAVE_SIG_T)
add_definitions(-Dsighandler_t=sig_t)
else()
message(FATAL_ERROR "Platform defines neither sig_t nor sighandler_t")
endif()
endif()

# Handle resolving
check_function_exists(res_init HAVE_LIBC_RESOLV)
if(HAVE_LIBC_RESOLV)
set(RESOLV_LIBRARIES)
else()
set(RESOLV_LIBRARIES -lresolv)
endif()

# Configure some variables like package, version and architecture.
set(PACKAGE ${PROJECT_NAME})
set(PACKAGE_MAIL "APT Development Team <deity@lists.debian.org>")
Expand All @@ -124,14 +171,26 @@ if (NOT DEFINED COMMON_ARCH)
execute_process(COMMAND dpkg-architecture -qDEB_HOST_ARCH
OUTPUT_VARIABLE COMMON_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
if (NOT DEFINED ROOT_GROUP)
execute_process(COMMAND id -gn root
OUTPUT_VARIABLE ROOT_GROUP OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Found root group: ${ROOT_GROUP}")
endif()
set(ROOT_GROUP "${ROOT_GROUP}" CACHE STRING "Group of root (e.g.: wheel or root)")

# Set various directories
set(STATE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt" CACHE PATH "Your /var/lib/apt")
set(CACHE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/cache/apt" CACHE PATH "Your /var/cache/apt")
set(LOG_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/apt" CACHE PATH "Your /var/log/apt")
set(CONF_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt" CACHE PATH "Your /etc/apt")
set(LIBEXEC_DIR "${CMAKE_INSTALL_FULL_LIBEXECDIR}/apt" CACHE PATH "Your /usr/libexec/apt")
set(BIN_DIR "${CMAKE_INSTALL_FULL_BINDIR}")


# Configure our configuration headers (config.h and apti18n.h)
configure_file(CMake/config.h.in ${PROJECT_BINARY_DIR}/include/config.h)
configure_file(CMake/apti18n.h.in ${PROJECT_BINARY_DIR}/include/apti18n.h)

# Generic header locations
include_directories(${PROJECT_BINARY_DIR}/include)

# Add our subdirectories
add_subdirectory(vendor)
add_subdirectory(apt-pkg)
Expand All @@ -154,13 +213,13 @@ endif()

# Create our directories.
install_empty_directories(
${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt/apt.conf.d
${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt/preferences.d
${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt/sources.list.d
${CMAKE_INSTALL_FULL_SYSCONFDIR}/apt/trusted.gpg.d
${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/cache/apt/archives/partial
${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt/lists/partial
${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt/mirrors/partial
${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/apt/periodic
${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/apt
${CONF_DIR}/apt.conf.d
${CONF_DIR}/preferences.d
${CONF_DIR}/sources.list.d
${CONF_DIR}/trusted.gpg.d
${CACHE_DIR}/archives/partial
${STATE_DIR}/lists/partial
${STATE_DIR}/mirrors/partial
${STATE_DIR}/periodic
${LOG_DIR}
)
2 changes: 1 addition & 1 deletion apt-inst/deb/debfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool debDebFile::ExtractTarMember(pkgDirStream &Stream,const char *Name)
Member = AR.FindMember(std::string(Name).append(c->Extension).c_str());
if (Member == NULL)
continue;
Compressor = c->Binary;
Compressor = c->Name;
break;
}

Expand Down
11 changes: 8 additions & 3 deletions apt-pkg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ target_include_directories(apt-pkg
PRIVATE ${ZLIB_INCLUDE_DIRS}
${BZIP2_INCLUDE_DIR}
${LZMA_INCLUDE_DIRS}
${LZ4_INCLUDE_DIRS})
${LZ4_INCLUDE_DIRS}
${ICONV_DIRECTORIES}
)

target_link_libraries(apt-pkg
PRIVATE -lutil -ldl -lresolv
PRIVATE -lutil ${CMAKE_DL_LIBS} ${RESOLV_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${ZLIB_LIBRARIES}
${BZIP2_LIBRARIES}
${LZMA_LIBRARIES}
${LZ4_LIBRARIES})
${LZ4_LIBRARIES}
${ICONV_LIBRARIES}
)
set_target_properties(apt-pkg PROPERTIES VERSION ${MAJOR}.${MINOR})
set_target_properties(apt-pkg PROPERTIES SOVERSION ${MAJOR})
add_version_script(apt-pkg)
Expand Down
9 changes: 5 additions & 4 deletions apt-pkg/acquire-item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static void ReportMirrorFailureToCentral(pkgAcquire::Item const &I, std::string
<< FailCode << std::endl;
#endif
string const report = _config->Find("Methods::Mirror::ProblemReporting",
"/usr/lib/apt/apt-report-mirror-failure");
LIBEXEC_DIR "/apt-report-mirror-failure");
if(!FileExists(report))
return;

Expand Down Expand Up @@ -2047,7 +2047,7 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile) /*{{{*/
HashStringList ServerHashes;
unsigned long long ServerSize = 0;

auto const &posix = std::locale("C.UTF-8");
auto const &posix = std::locale::classic();
for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
{
std::string tagname = *type;
Expand Down Expand Up @@ -3439,7 +3439,7 @@ void pkgAcqChangelog::Init(std::string const &DestDir, std::string const &DestFi
TemporaryDirectory = tmpname;

ChangeOwnerAndPermissionOfFile("Item::QueueURI", TemporaryDirectory.c_str(),
SandboxUser.c_str(), "root", 0700);
SandboxUser.c_str(), ROOT_GROUP, 0700);

DestFile = flCombine(TemporaryDirectory, DestFileName);
if (DestDir.empty() == false)
Expand Down Expand Up @@ -3487,7 +3487,8 @@ std::string pkgAcqChangelog::URI(pkgCache::VerIterator const &Ver) /*{{{*/
pkgCache::PkgIterator const Pkg = Ver.ParentPkg();
if (Pkg->CurrentVer != 0 && Pkg.CurrentVer() == Ver)
{
std::string const basename = std::string("/usr/share/doc/") + Pkg.Name() + "/changelog";
std::string const root = _config->FindDir("Dir");
std::string const basename = root + std::string("usr/share/doc/") + Pkg.Name() + "/changelog";
std::string const debianname = basename + ".Debian";
if (FileExists(debianname))
return "copy://" + debianname;
Expand Down
4 changes: 2 additions & 2 deletions apt-pkg/acquire-worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ bool pkgAcquire::Worker::QueueItem(pkgAcquire::Queue::QItem *Item)
{
std::string const SandboxUser = _config->Find("APT::Sandbox::User");
ChangeOwnerAndPermissionOfFile("Item::QueueURI", Item->Owner->DestFile.c_str(),
SandboxUser.c_str(), "root", 0600);
SandboxUser.c_str(), ROOT_GROUP, 0600);
}

if (Debug == true)
Expand Down Expand Up @@ -788,7 +788,7 @@ void pkgAcquire::Worker::PrepareFiles(char const * const caller, pkgAcquire::Que
{
if (RealFileExists(Itm->Owner->DestFile))
{
ChangeOwnerAndPermissionOfFile(caller, Itm->Owner->DestFile.c_str(), "root", "root", 0644);
ChangeOwnerAndPermissionOfFile(caller, Itm->Owner->DestFile.c_str(), "root", ROOT_GROUP, 0644);
std::string const filename = Itm->Owner->DestFile;
for (pkgAcquire::Queue::QItem::owner_iterator O = Itm->Owners.begin(); O != Itm->Owners.end(); ++O)
{
Expand Down
Loading

0 comments on commit 6a68315

Please sign in to comment.