From 00555ee1fe5ddf8dbf3901715752d8833b12c1c0 Mon Sep 17 00:00:00 2001 From: Mauricio Cardenas Date: Sat, 12 Jul 2025 12:18:19 -0600 Subject: [PATCH] build: add cmake fix: CMake definition for cmake specific files feat: add cmake lists to drivers and kmi fix: revert unnecesary changes fix: missing .c file fix: typos and names chore: add build specific version number and add comments feat: add last cmakelists fix: fix compilation issues feat: fix names feat: add manpages feat: cmake working --- .cmake/FindSNMP.cmake | 19 + .gitignore | 4 + CMakeLists.txt | 569 ++++++++++++++++++ build/.gitignore | 2 + conf/CMakeLists.txt | 31 + man/CMakeLists.txt | 17 + messages/CMakeLists.txt | 43 ++ src/CMakeLists.txt | 51 ++ src/iosched/CMakeLists.txt | 18 + src/kmi/CMakeLists.txt | 21 + src/libltfs/CMakeLists.txt | 18 + src/libltfs/arch/time_internal.c | 5 +- src/libltfs/ltfs.h | 2 +- src/tape_drivers/CMakeLists.txt | 15 + src/tape_drivers/freebsd/cam/CMakeLists.txt | 16 + src/tape_drivers/generic/file/CMakeLists.txt | 11 + .../generic/itdtimg/CMakeLists.txt | 12 + .../linux/lin_tape/CMakeLists.txt | 15 + src/tape_drivers/linux/sg/CMakeLists.txt | 17 + .../netbsd/scsipi-ibmtape/CMakeLists.txt | 16 + src/tape_drivers/osx/iokit/CMakeLists.txt | 16 + src/utils/CMakeLists.txt | 24 + 22 files changed, 939 insertions(+), 3 deletions(-) create mode 100644 .cmake/FindSNMP.cmake create mode 100644 CMakeLists.txt create mode 100644 build/.gitignore create mode 100644 conf/CMakeLists.txt create mode 100644 man/CMakeLists.txt create mode 100644 messages/CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 src/iosched/CMakeLists.txt create mode 100644 src/kmi/CMakeLists.txt create mode 100644 src/libltfs/CMakeLists.txt create mode 100644 src/tape_drivers/CMakeLists.txt create mode 100644 src/tape_drivers/freebsd/cam/CMakeLists.txt create mode 100644 src/tape_drivers/generic/file/CMakeLists.txt create mode 100644 src/tape_drivers/generic/itdtimg/CMakeLists.txt create mode 100644 src/tape_drivers/linux/lin_tape/CMakeLists.txt create mode 100644 src/tape_drivers/linux/sg/CMakeLists.txt create mode 100644 src/tape_drivers/netbsd/scsipi-ibmtape/CMakeLists.txt create mode 100644 src/tape_drivers/osx/iokit/CMakeLists.txt create mode 100644 src/utils/CMakeLists.txt diff --git a/.cmake/FindSNMP.cmake b/.cmake/FindSNMP.cmake new file mode 100644 index 00000000..732e5ecb --- /dev/null +++ b/.cmake/FindSNMP.cmake @@ -0,0 +1,19 @@ +# TODO: Improve the use of SNMP, right now this flags are not added to the build. +# TODO: Test the use of SNMP +option(ENABLE_SNMP "Force to use ICU6x (unorm2) functions" OFF) +if(ENABLE_SNMP) + pkg_check_modules(SNMP REQUIRED "net-snmp>=5.3" IMPORTED_TARGET) + find_program(NETSNMP_CONFIG_BIN net-snmp-config REQUIRED) + if(NETSNMP_CONFIG_BIN) + exec_program(${NETSNMP_CONFIG_BIN} ARGS --cflags OUTPUT_VARIABLE _NETSNMP_CFLAGS) + exec_program(${NETSNMP_CONFIG_BIN} ARGS --libs OUTPUT_VARIABLE _NETSNMP_LIBS) + + string(REGEX REPLACE "[\"\r\n]" " " _NETSNMP_CFLAGS "${_NETSNMP_CFLAGS}") + string(REGEX REPLACE "[\"\r\n]" " " _NETSNMP_LIBS "${_NETSNMP_LIBS}") + set(NETSNMP_CFLAGS ${_NETSNMP_CFLAGS} CACHE STRING "CFLAGS for net-snmp lib") + set(NETSNMP_LIBS ${_NETSNMP_LIBS} CACHE STRING "linker options for net-snmp lib") + set(NETSNMP_FOUND TRUE CACHE BOOL "net-snmp is found") + else() + set (NETSNMP_FOUND FALSE CACHE BOOL "net-snmp is not found") + endif() +endif() diff --git a/.gitignore b/.gitignore index 0711b11e..629a7d85 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# Files generated by cmake +__cmake_systeminformation +.cache + # Files generated by ./autogen.sh Makefile.in aclocal.m4 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..499fa352 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,569 @@ +cmake_minimum_required(VERSION 3.26) +project(ltfs + LANGUAGES C) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/.cmake") +set(VERSION "2.5.0.0 (Prelim cmake)") +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +include(CheckSymbolExists REQUIRED) +include(CheckTypeSize REQUIRED) +include(CheckLibraryExists REQUIRED) +include(CheckIncludeFiles REQUIRED) +include(GNUInstallDirs REQUIRED) + +find_package(SNMP REQUIRED) +find_package(PkgConfig REQUIRED) +find_package(Threads REQUIRED) +find_package(ICU COMPONENTS uc) +find_package(LibXml2 REQUIRED) + +check_type_size(time_t SIZEOF_TIME_T) +add_compile_definitions(_GNU_SOURCE __CMAKE_BUILD) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Debug) +endif() + +if(CMAKE_BUILD_TYPE STREQUAL Debug) + set(BASE_DIR ${CMAKE_BINARY_DIR}/target) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BASE_DIR}/lib/ltfs) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BASE_DIR}/lib/ltfs) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BASE_DIR}/bin) + + set(CFG_DIR "${CMAKE_BINARY_DIR}/conf") + make_directory("${BASE_DIR}/ltfs") +else() + set(BASE_DIR "${CMAKE_INSTALL_PREFIX}") + set(CFG_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}") +endif() + +pkg_check_modules(FUSE REQUIRED "fuse>=2.6.0" IMPORTED_TARGET) +target_compile_definitions(PkgConfig::FUSE INTERFACE + _FILE_OFFSET_BITS=64 +) + +if(APPLE) + pkg_check_modules(UUID REQUIRED "uuid>=1.6" IMPORTED_TARGET) +else() + pkg_check_modules(UUID REQUIRED "uuid>=1.36" IMPORTED_TARGET) +endif() + +add_subdirectory(messages) +add_subdirectory(src) + +# TODO: SET ALL THESE FLAGS +# dnl +# dnl Handle --enable-message-checker (default:no) +# dnl +# AC_MSG_CHECKING([whether to compile in message checking mode]) +# AC_ARG_ENABLE([message-checker], +# [AS_HELP_STRING([--enable-message-checker],[compile in message checking mode (may be binary is defunct)])], +# [use_msg_check=$enableval], +# [use_msg_check=no] +# ) +# AC_MSG_RESULT([$use_msg_check]) + +# dnl +# dnl Check for warning treatment +# dnl +# AC_MSG_CHECKING([enable warnings as errors]) +# AC_ARG_ENABLE([warning-as-error], +# [AS_HELP_STRING([--enable-warning-as-error],[Treates warnings as errors])], +# [warning_as_error=$enableval], +# [warning_as_error=no] +# ) +# AC_MSG_RESULT([$warning_as_error]) + +# dnl +# dnl Handle --enable-fast (default:no) +# dnl +# AC_MSG_CHECKING([whether to enable optimizations]) +# AC_ARG_ENABLE([fast], +# [AS_HELP_STRING([--enable-fast],[compile with optimization enabled])], +# [use_fast=$enableval], +# [use_fast=no] +# ) +# AC_MSG_RESULT([$use_fast]) + +# if test "x${use_fast}" != "xno" +# then +# if test "x${use_debug}" != "xno" +# then +# AC_MSG_ERROR([Cannot specify --enable-fast and --enable-debug at the same time.]) +# fi +# fi + +# dnl +# dnl Handle --enable-livelink (default:yes) +# dnl +# AC_MSG_CHECKING([whether to enable livelink mode support [default=yes] ]) +# AC_ARG_ENABLE([livelink], +# [AS_HELP_STRING([--enable-livelink],[compile with livelink mode support [default=yes]])], +# [livelink=$enableval], +# [livelink=yes] +# ) +# AC_MSG_RESULT([$livelink]) + +# dnl +# dnl Handle --enable-snmp (default:yes) +# dnl +# AC_MSG_CHECKING([whether to enable snmp or not]) +# AC_ARG_ENABLE([snmp], +# [AS_HELP_STRING([--enable-snmp],[Support SNMP or not])], +# [snmp=$enableval], +# [snmp=yes] +# ) +# AC_MSG_RESULT([$snmp]) + +# dnl +# dnl Handle --enable-new-locking (default: yes) +# dnl +# AC_MSG_CHECKING([whether to enable new locking system or not]) +# AC_ARG_ENABLE([new-locking], +# [AS_HELP_STRING([--enable-new-locking],[Use new locking system or not])], +# [use_new_locking=$enableval], +# [use_new_locking=yes] +# ) +# AC_MSG_RESULT([$use_new_locking]) + +# dnl +# dnl Handle --enable-lin-tape (default:no, Linux Only) +# dnl +# AC_MSG_CHECKING([whether to enable lin_tape or not (Linux Only)]) +# AC_ARG_ENABLE([lintape], +# [AS_HELP_STRING([--enable-lintape],[Support IBM's lin_tape driver or not])], +# [lintape=$enableval], +# [lintape=no] +# ) +# AC_MSG_RESULT([$lintape]) + +# dnl +# dnl Handle --enable-buggy-ifs (default:no, Linux/MacOS Only) +# dnl +# AC_MSG_CHECKING([whether to enable handling of buggy I/Fs or not (Linux/MacOS Only)]) +# AC_ARG_ENABLE([buggy_ifs], +# [AS_HELP_STRING([--enable-buggy-ifs],[Support handling of buggy I/Fs for tape drivers])], +# [buggy_ifs=$enableval], +# [buggy_ifs=no] +# ) +# AC_MSG_RESULT([$buggy_ifs]) + +# dnl +# dnl Handle --enable-xml-indent (default:no) +# dnl +# AC_MSG_CHECKING([whether to enable xml indentation for index]) +# AC_ARG_ENABLE([xml_indent], +# [AS_HELP_STRING([--enable-xml-indent],[Enable XML indentation for index])], +# [xml_indent=$enableval], +# [xml_indent=no] +# ) +# AC_MSG_RESULT([$xml_indent]) + +# dnl +# dnl Handle --enable-format-spec25 (default:no) +# dnl +# AC_MSG_CHECKING([whether to enable format spec 2.5 support or not]) +# AC_ARG_ENABLE([format_spec25], +# [AS_HELP_STRING([--enable-format-spec25],[Support format spec 2.5])], +# [format_spec25=$enableval], +# [format_spec25=no] +# ) +# AC_MSG_RESULT([$format_spec25]) + +# dnl +# dnl Handle extra compile flags for tape driver +# dnl +# if test "x${buggy_ifs}" = "xyes" +# then +# if test "x${host_linux}" = "xyes" +# then +# AM_EXTRA_CPPFLAGS="${AM_EXTRA_CPPFLAGS} -DSUPPORT_BUGGY_IFS" +# AC_ARG_VAR([buggy_ifs], [compile with SUPPORT_BUGGY_IFS enabled]) +# fi +# if test "x${host_mac}" = "xyes" +# then +# AM_EXTRA_CPPFLAGS="${AM_EXTRA_CPPFLAGS} -DSUPPORT_BUGGY_IFS" +# AC_ARG_VAR([buggy_ifs], [compile with SUPPORT_BUGGY_IFS enabled]) +# fi +# fi + +# +# Handle default backends +# +if (NOT DEFINED DEFAULT_TAPE) + if(LINUX) + set(DEFAULT_TAPE sg) + elseif(APPLE) + set(DEFAULT_TAPE iokit) + elseif(BSD) + if(FREEBSD) + set(DEFAULT_TAPE cam) + elseif(NETBSD) + set(DEFAULT_TAPE scsipi-ibmtape) + endif() + endif() +elseif (NOT ENABLE_LINTAPE AND DEFAULT_TAPE STREQUAL "xlin_tape") + message(FATAL_ERROR "lin_tape is not enabled -DENABLE_LINTAPE is required.") +endif() + +set(DEFAULT_IOSCHED "unified" CACHE STRING "default I/O scheduler plugin, e.g. unified") +set(DEFAULT_KMI "none" CACHE STRING "default key manager interface plugin, e.g. none") + +# dnl +# dnl Check for genrb +# dnl +# AC_PATH_PROG(GENRB, genrb, no) +# if test "x${GENRB}" = "xno" +# then +# AC_MSG_ERROR([genrb was not found]) +# fi + +# dnl +# dnl Check for pkgdata +# dnl +# AC_PATH_PROG(PKGDATA, pkgdata, no) +# if test "x${PKGDATA}" = "xno" +# then +# AC_MSG_ERROR([pkgdata was not found]) +# fi + +# dnl +# dnl Check for FUSE, libuuid, and libxml2 +# dnl +# PKG_CHECK_MODULES([FUSE_MODULE], [fuse >= 2.6.0]) +# PKG_CHECK_MODULES([LIBXML2_MODULE], [libxml-2.0 >= 2.6.16]) + +# if test "x${host_mac}" = "xyes" +# then +# PKG_CHECK_MODULES([UUID_MODULE], [uuid >= 1.6]) +# else +# PKG_CHECK_MODULES([UUID_MODULE], [uuid >= 1.36]) +# fi + +# dnl +# dnl Check for pthreads and clock_gettime +# dnl +# AC_CHECK_LIB(pthread, pthread_create,, +# [AC_MSG_ERROR([required library pthread missing])]) + +# if test "x${host_mac}" = "xno" +# then +# AC_CHECK_LIB(rt, clock_gettime,, +# [AC_MSG_ERROR([required library rt missing])]) +# fi + +# dnl +# dnl Check for libcam, libbsdxml (expat), libmt and libexecinfo on FreeBSD +# dnl +# if test "x${host_freebsd}" = "xyes" +# then +# AC_CHECK_LIB(cam, cam_open_device,, +# [AC_MSG_ERROR([required library cam missing])]) +# AC_CHECK_LIB(bsdxml, XML_ParserCreate,, +# [AC_MSG_ERROR([required library bsdxml missing])]) +# AC_CHECK_LIB(mt, mt_status_free,, +# [AC_MSG_ERROR([required library mt missing])]) +# AC_CHECK_LIB(execinfo, backtrace,, +# [AC_MSG_ERROR([required library execinfo missing])]) + +# fi + +# dnl +# dnl Check for libexecinfo on NetBSD +# dnl +# if test "x${host_netbsd}" = "xyes" +# then +# AC_CHECK_LIB(execinfo, backtrace,, +# [AC_MSG_ERROR([required library execinfo missing])]) + +# fi + +# dnl +# dnl Check for ICU +# dnl +# AC_MSG_CHECKING(ICU version) +# ICU_MODULE_VERSION="`pkg-config --modversion icu-i18n 2> /dev/null`"; +# ICU_MODULE_CFLAGS="`pkg-config --cflags icu-i18n 2> /dev/null`"; +# ICU_MODULE_LIBS="`pkg-config --libs icu-i18n 2> /dev/null`"; +# AC_MSG_RESULT([$ICU_MODULE_VERSION]) + +# if test -z "$ICU_MODULE_VERSION" +# then +# PKG_CHECK_MODULES([ICU_MODULE], [icu-uc >= 0.21]) +# fi + +# AC_MSG_CHECKING([for using ICU6x (unorm2) functions forcibly]) +# AC_ARG_ENABLE([icu_6x], +# [AS_HELP_STRING([--enable-icu-6x],[Force to use ICU6x (unorm2) functions])], +# [icu_6x=$enableval], +# [icu_6x=no] +# ) +# AC_MSG_RESULT([$icu_6x]) + +# if test "x${icu_6x}" = "xyes" +# then +# AM_EXTRA_CPPFLAGS="${AM_EXTRA_CPPFLAGS} -D USE_UNORM2" +# else +# AC_MSG_CHECKING(for using unorm2 functions) +# if test "${ICU_MODULE_VERSION%%.*}" -ge "56" +# then +# AM_EXTRA_CPPFLAGS="${AM_EXTRA_CPPFLAGS} -D USE_UNORM2" +# AC_MSG_RESULT(yes) +# else +# AC_MSG_RESULT(no) +# fi +# fi + +# dnl +# dnl Check for SNMP +# dnl +# SNMP_ENABLE="" +# SNMP_MODULE_CFLAGS="" +# SNMP_MODULE_LIBS_A="" +# SNMP_MODULE_LIBS="" +# if test "x${snmp}" != "xno" +# then +# SNMP_ENABLE="-D ENABLE_SNMP" +# SNMP_MODULE_CFLAGS="`net-snmp-config --cflags 2> /dev/null`"; +# SNMP_MODULE_LIBS_A="`net-snmp-config --agent-libs 2> /dev/null`"; +# SNMP_MODULE_LIBS="`net-snmp-config --libs 2> /dev/null`"; +# if test -z "$SNMP_MODULE_LIBS_A" +# then +# PKG_CHECK_MODULES([SNMP_MODULE], [net-snmp >= 5.3]) +# fi + +# if test -z "$SNMP_MODULE_LIBS" +# then +# PKG_CHECK_MODULES([SNMP_MODULE], [net-snmp >= 5.3]) +# fi +# fi + +# dnl +# dnl Check for headers, types, structures, compiler characteristics +# dnl +# AC_CHECK_HEADERS([fcntl.h limits.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/mount.h sys/time.h termios.h unistd.h sys/sysctl.h]) +# AC_HEADER_STDBOOL +# AC_TYPE_MODE_T +# AC_TYPE_OFF_T +# AC_TYPE_SIZE_T +# AC_TYPE_SSIZE_T +# AC_TYPE_UINT8_T +# AC_TYPE_UINT16_T +# AC_TYPE_UINT32_T +# AC_TYPE_UINT64_T +# AC_CHECK_SIZEOF([time_t]) +# AC_STRUCT_ST_BLOCKS +# AC_CHECK_MEMBERS([struct stat.st_blksize]) +# AC_CHECK_MEMBERS([struct stat.st_rdev]) +# AC_C_INLINE + +# dnl +# dnl Check for library functions +# dnl +# AC_FUNC_MALLOC +# #AC_FUNC_MKTIME +# AC_FUNC_STRNLEN +# AC_CHECK_FUNCS([bzero memchr memset mkdir rmdir strcasecmp strdup strerror strndup strrchr strstr]) + +# dnl +# dnl Check xmlTextReaderSetup is existed +# dnl +# AC_CHECK_FUNC([xmlTextReaderSetup], [AC_DEFINE(HAVE_XML_READER_SETUP, [1], [Define to 1 if you have xmlTextReaderSetup])], []) +# if test "x$ac_cv_func_xmlTextReaderSetup" = "xno"; then +# AC_CHECK_LIB(xml2, xmlTextReaderSetup, [AC_DEFINE(HAVE_XML_READER_SETUP, [1], [Define to 1 if you have xmlTextReaderSetup])], []) +# fi + +# dnl +# dnl Check XML_PARSE_HUGE is defined +# dnl +# SAVE_CFLAGS=$CFLAGS +# CFLAGS="$CFLAGS ${LIBXML2_MODULE_CFLAGS}" +# AC_MSG_CHECKING(for XML_PARSE_HUGE) +# AC_CACHE_VAL(ac_cv_xml_huge, +# AC_COMPILE_IFELSE( +# [AC_LANG_PROGRAM([#include ], +# [int foo = XML_PARSE_HUGE; return 0;])], +# [ac_cv_xml_huge=yes], +# [ac_cv_xml_huge=no] +# )) +# AC_MSG_RESULT($ac_cv_xml_huge) +# CFLAGS="$SAVE_CFLAGS" + +# if test "x$ac_cv_xml_huge" = "xyes"; then +# AC_DEFINE(HAVE_XML_PARSE_HUGE, [1], [Define to 1 if you have XML_PARSE_HUGE]) +# fi + +# AC_MSG_CHECKING([if compiling with clang]) + +# AC_COMPILE_IFELSE( +# [AC_LANG_PROGRAM([], [[ +# #ifndef __clang__ +# not clang +# #endif +# ]])], +# [CLANG=yes], [CLANG=no]) + +# AC_MSG_RESULT([$CLANG]) + +# dnl +# dnl Update flags +# dnl Sets CFLAGS to force optimization and debugging options, which isn't quite kosher +# dnl +# AM_CPPFLAGS="-D_GNU_SOURCE -I\$(top_srcdir)/src -DLTFS_CONFIG_FILE='\"${sysconfdir}/ltfs.conf\"' -DLTFS_BASE_DIR='\"${prefix}\"'" +# AM_CFLAGS="-Wall -Wsign-compare -fsigned-char ${FUSE_MODULE_CFLAGS} ${UUID_MODULE_CFLAGS} ${LIBXML2_MODULE_CFLAGS} ${ICU_MODULE_CFLAGS} ${SNMP_ENABLE} ${SNMP_MODULE_CFLAGS}" + +# if test "x$use_fast" = "xyes" +# then +# OPT_FLAGS="-D_FORTIFY_SOURCE=2 -O2 -g -fno-strict-aliasing" +# else +# OPT_FLAGS="-D_FORTIFY_SOURCE=0 -O0 -ggdb" +# if test "x$CLANG" = 'xno' +# then +# AM_CFLAGS="${AM_CFLAGS} -fkeep-inline-functions -rdynamic" +# fi +# if test "x$use_debug" = "xyes" +# then +# AM_CPPFLAGS="${AM_CPPFLAGS} -DDEBUG -DTRACE" +# fi +# fi + +# if test "x$use_msg_check" = "xyes" +# then +# AM_CPPFLAGS="${AM_CPPFLAGS} -DMSG_CHECK" +# fi + +# if test "x$warning_as_error" = "xyes" +# then +# AM_CFLAGS="${AM_CFLAGS} -Werror" +# fi + +# if test "x$use_new_locking" = "xyes" +# then +# AM_CPPFLAGS="${AM_CPPFLAGS} -DUSE_NEW_LOCKING" +# fi + +# if test "x$livelink" = "xno" +# then +# AM_CPPFLAGS="${AM_CPPFLAGS} -DPOSIXLINK_ONLY" +# fi + +# if test "x$livelink" = "xno" +# then +# AM_CPPFLAGS="${AM_CPPFLAGS} -DPOSIXLINK_ONLY" +# fi + +# if test "x$xml_indent" = "xyes" +# then +# AM_CPPFLAGS="${AM_CPPFLAGS} -DINDENT_INDEXES" +# fi + +# if test "x$format_spec25" = "xyes" +# then +# AM_CPPFLAGS="${AM_CPPFLAGS} -DFORMAT_SPEC25" +# fi + +# dnl +# dnl Specify CPU specific optimizer options for CRC calculation +# dnl +# AC_MSG_CHECKING([for SSE4.2]) +# CRC_OPTIMIZE="-O2" + +# if test "x$GCC" = 'xyes' -a "x$CLANG" = 'xno' +# then +# GCC_VERSION=`$CC -dumpversion` +# GCC_VERSION_MAJOR=$(echo $GCC_VERSION | cut -d'.' -f1) +# GCC_VERSION_MINOR=$(echo $GCC_VERSION | cut -d'.' -f2) +# SSE42=no + +# if test ${GCC_VERSION_MAJOR} -ge 4 -a ${GCC_VERSION_MINOR} -ge 3 +# then +# SSE42=yes +# fi + +# if test ${GCC_VERSION_MAJOR} -ge 8 -a ${GCC_VERSION_MINOR} -ge 0 -a "x$warning_as_error" = "xyes" +# then +# AM_CFLAGS="${AM_CFLAGS} -Wno-stringop-truncation" +# fi + +# if test "x${SSE42}" = "xyes" +# then +# case x"$target_cpu" in +# xx86_64 | xamd64) +# AC_MSG_RESULT([yes, x86_64]) +# CRC_OPTIMIZE="-msse4.2 -O2 -D__SSE42__" +# ;; +# xi*86) +# AC_MSG_RESULT([yes, x86]) +# CRC_OPTIMIZE="-msse4.2 -O2 -D__SSE42__" +# ;; +# *) +# AC_MSG_RESULT([no, unsupported cpu]) +# ;; +# esac +# else +# AC_MSG_RESULT([no, gcc version]) +# fi +# elif test "x$CLANG" = 'xyes' +# then +# case x"$target_cpu" in +# xx86_64 | xamd64) +# AC_MSG_RESULT([yes, x86_64]) +# CRC_OPTIMIZE="-msse4.2 -O2 -D__SSE42__" +# ;; +# xi*86) +# AC_MSG_RESULT([yes, x86]) +# CRC_OPTIMIZE="-msse4.2 -O2 -D__SSE42__" +# ;; +# *) +# AC_MSG_RESULT([no, unsupported cpu $target_cpu]) +# ;; +# esac +# else +# AC_MSG_RESULT([no, non-gcc]) +# fi + +# dnl +# dnl Configure standard options +# dnl +# if test -x /usr/local/bin/gsed +# then +# SED='gsed' +# else +# SED='sed' +# fi + +# if test "x${host_mac}" = "xno" +# then +# MODULE_CHECK_LD='-Wl,--no-undefined,--as-needed' +# AM_LDFLAGS="${AM_LDFLAGS} -ldl" +# fi + +# AM_CFLAGS=`echo ${AM_CFLAGS} | ${SED} 's|-D_FORTIFY_SOURCE=. ||g'` +# AM_LDFLAGS="${AM_LDFLAGS} ${MODULE_CHECK_LD} ${FUSE_MODULE_LIBS} ${UUID_MODULE_LIBS} ${LIBXML2_MODULE_LIBS} ${ICU_MODULE_LIBS} ${SNMP_MODULE_LIBS_A} ${SNMP_MODULE_LIBS}" +# CFLAGS="${CFLAGS} ${OPT_FLAGS}" + +# dnl +# dnl Define options +# dnl +# AM_CONDITIONAL([PLATFORM_LINUX], [test "x${host_linux}" = "xyes"]) +# AM_CONDITIONAL([ENABLE_LIN_TAPE], [test "x${lintape}" = "xyes"]) +# AM_CONDITIONAL([PLATFORM_MAC], [test "x${host_mac}" = "xyes"]) +# AM_CONDITIONAL([PLATFORM_FREEBSD], [test "x${host_freebsd}" = "xyes"]) +# AM_CONDITIONAL([PLATFORM_NETBSD], [test "x${host_netbsd}" = "xyes"]) +# AM_CONDITIONAL([CHK_MESSAGE], [test "x${use_msg_check}" = "xyes"]) +# AM_CONDITIONAL([OSS], [true]) + +# AC_SUBST(CFLAGS) +# AC_SUBST(CRC_OPTIMIZE) +# AC_SUBST(AM_CPPFLAGS) +# AC_SUBST(AM_EXTRA_CPPFLAGS) +# AC_SUBST(AM_CFLAGS) +# AC_SUBST(AM_LDFLAGS) + +set(prefix "${BASE_DIR}/ltfs" CACHE INTERNAL "Base installation directory (equivalent to Autotools' prefix)") +set(exec_prefix "${BASE_DIR}/bin" CACHE INTERNAL "Directory for architecture-dependent executables (like Autotools' exec_prefix)") +set(libdir "${BASE_DIR}/lib" CACHE INTERNAL "Directory for installing libraries (like Autotools' libdir)") +set(includedir "${BASE_DIR}/include" CACHE INTERNAL "Directory for installing header files (like Autotools' includedir)") +set(PACKAGE ${PROJECT_NAME} CACHE INTERNAL "Package name (equivalent to Autotools' PACKAGE)") +add_subdirectory(conf) +add_subdirectory(man) +configure_file(ltfs.pc.in ltfs.pc) diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/build/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/conf/CMakeLists.txt b/conf/CMakeLists.txt new file mode 100644 index 00000000..7f169803 --- /dev/null +++ b/conf/CMakeLists.txt @@ -0,0 +1,31 @@ +# NOTE: This can be done using an .in file with @VARS@ but somehow this is done using sed +set(PLAT_OPTS) +if(ENABLE_LINTAPE) + list(APPEND PLAT_OPTS "plugin tape lin_tape ${libdir}/ltfs/libtape_lin_tape.so") +endif() + +if(LINUX) + list(APPEND PLAT_OPTS "plugin tape sg ${libdir}/ltfs/libtape_sg.so") +elseif(APPLE) + list(APPEND PLAT_OPTS "plugin tape iokit ${libdir}/ltfs/libtape_iokit.so") +elseif(BSD) + if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + list(APPEND PLAT_OPTS "plugin tape cam ${libdir}/ltfs/libtape-cam.so") + elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") + list(APPEND PLAT_OPTS "plugin tape scsipi-ibmtape ${libdir}/ltfs/libtape_scsipi_ibmtape.so") + endif() +endif() + +file(REAL_PATH "ltfs.conf.in" CONFIG_FILE) +file(COPY_FILE "ltfs.conf.local" "${CFG_DIR}/ltfs.conf.local") +add_custom_command(OUTPUT "ltfs.conf" + COMMAND sed -e "s!__PLATFORM_DRIVERS__!${PLAT_OPTS}!" ${CONFIG_FILE} > .tmp1 + COMMAND sed -e "s!__LIBDIR__!${libdir}!" .tmp1 > .tmp2 + COMMAND sed -e "s!__DEFAULT_TAPE__!${DEFAULT_TAPE}!" .tmp2 > .tmp1 + COMMAND sed -e "s!__DEFAULT_IOSCHED__!${DEFAULT_IOSCHED}!" .tmp1 > .tmp2 + COMMAND sed -e "s!__DEFAULT_KMI__!${DEFAULT_KMI}!" .tmp2 > .tmp1 + COMMAND sed -e "s!__CONFDIR__!${CFG_DIR}!" .tmp1 > ltfs.conf + DEPENDS ${CONFIG_FILE} + BYPRODUCTS .tmp1 .tmp2 +) +add_custom_target("conf" ALL DEPENDS "ltfs.conf") diff --git a/man/CMakeLists.txt b/man/CMakeLists.txt new file mode 100644 index 00000000..23e74d73 --- /dev/null +++ b/man/CMakeLists.txt @@ -0,0 +1,17 @@ +set(MANPAGES + mkltfs + ltfsck + ltfs + ltfs_ordered_copy + ltfsindextool +) + +add_custom_target(man) +foreach(NAME IN LISTS MANPAGES) + file(REAL_PATH "sgml/${NAME}.sgml" SOURCE) + add_custom_target("man_${NAME}" + docbook2man ${SOURCE} # 2> /dev/null + DEPENDS ${SOURCE} + ) + add_dependencies(man "man_${NAME}") +endforeach() diff --git a/messages/CMakeLists.txt b/messages/CMakeLists.txt new file mode 100644 index 00000000..04d75044 --- /dev/null +++ b/messages/CMakeLists.txt @@ -0,0 +1,43 @@ +set(MESSAGES_LIBS + bin_ltfs + bin_ltfsck + bin_ltfsindextool + bin_mkltfs + internal_error + iosched_fcfs + iosched_unified + kmi_flatfile + kmi_simple + libltfs + tape_common + tape_freebsd_cam + tape_generic_file + tape_generic_itdtimg + tape_iokit + tape_linux_lin_tape + tape_linux_sg +) +set(LIBS) +foreach(NAME IN LISTS MESSAGES_LIBS) + file(GLOB SRCS "${NAME}/*.txt") + set(OUT "lib${NAME}.a") + list(APPEND LIBS ${OUT}) + + make_directory("${CMAKE_CURRENT_BINARY_DIR}/res_${NAME}") + add_custom_command(OUTPUT ${OUT} + COMMAND ${ICU_GENRB_EXECUTABLE} -q ${SRCS} 1> /dev/null + COMMAND ls *.res > paths.txt + COMMAND ${ICU_PKGDATA_EXECUTABLE} -m static -p ${NAME} -q paths.txt 1> /dev/null + COMMAND cp ${OUT} .. + DEPENDS ${SRCS} + BYPRODUCTS res_${NAME} + WORKING_DIRECTORY res_${NAME} + ) + + # Define the library as an imported CMake lib + add_library("lib${NAME}" STATIC IMPORTED GLOBAL) + set_target_properties("lib${NAME}" PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/lib${NAME}.a") + add_dependencies("lib${NAME}" "messages") +endforeach() +# Do this to not rebuild the entire message libraries every run +add_custom_target(messages ALL DEPENDS ${LIBS}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..2da8282a --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,51 @@ +add_executable(ltfs_bin main.c ltfs_fuse.c) +target_link_libraries(ltfs_bin + Threads::Threads + PkgConfig::FUSE + LibXml2::LibXml2 + PkgConfig::UUID + ICU::uc + ltfs +) +set_property(TARGET ltfs_bin PROPERTY OUTPUT_NAME ltfs) +target_include_directories(ltfs_bin BEFORE PUBLIC "." ) + +add_compile_definitions( + LTFS_CONFIG_FILE="${CFG_DIR}/ltfs.conf" + LTFS_BASE_DIR="${BASE_DIR}" + PACKAGE_VERSION="${VERSION}" + PACKAGE_NAME="${PROJECT_NAME}" +) + +add_subdirectory(libltfs) +add_subdirectory(iosched) +add_subdirectory(kmi) +add_subdirectory(tape_drivers) +add_subdirectory(tape_drivers/generic/file) +add_subdirectory(tape_drivers/generic/itdtimg) +add_subdirectory(utils) + +option(ENABLE_LINTAPE "Support IBM's lin_tape driver or not" OFF) +if(ENABLE_LINTAPE) + add_subdirectory(tape_drivers/linux/lin_tape) +endif() + +if(LINUX) + add_subdirectory(tape_drivers/linux/sg) +elseif(APPLE) + add_subdirectory(tape_drivers/osx/iokit) +elseif(BSD) + if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + add_subdirectory(tape_drivers/freebsd/cam) + elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") + add_subdirectory(tape_drivers/netbsd/scsipi-ibmtape) + endif() +endif() + +option(ICU_6X "Force to use ICU6x (unorm2) functions" OFF) +string(REPLACE "." ";" ICU_VERSION_ARRAY ${ICU_VERSION}) +list(GET ICU_VERSION_ARRAY 0 ICU_VERSION_MAJOR) +if(ICU_6X OR ICU_VERSION_MAJOR GREATER_EQUAL "56") + add_compile_definitions(USE_UNORM2) + message(STATUS "Using ICU6x funtions") +endif() diff --git a/src/iosched/CMakeLists.txt b/src/iosched/CMakeLists.txt new file mode 100644 index 00000000..b0c2600a --- /dev/null +++ b/src/iosched/CMakeLists.txt @@ -0,0 +1,18 @@ +add_library(iosched-fcfs SHARED fcfs.c) +target_link_libraries(iosched-fcfs + PkgConfig::FUSE + ltfs + libiosched_fcfs +) +target_include_directories(iosched-fcfs BEFORE PUBLIC "..") + +add_library(iosched-unified SHARED + unified.c + cache_manager.c +) +target_link_libraries(iosched-unified + PkgConfig::FUSE + ltfs + libiosched_unified +) +target_include_directories(iosched-unified BEFORE PUBLIC "..") diff --git a/src/kmi/CMakeLists.txt b/src/kmi/CMakeLists.txt new file mode 100644 index 00000000..caedc0c2 --- /dev/null +++ b/src/kmi/CMakeLists.txt @@ -0,0 +1,21 @@ +add_library(kmi-simple SHARED + simple.c + key_format_ltfs.c +) +target_link_libraries(kmi-simple + PkgConfig::FUSE + ltfs + libkmi_simple +) +target_include_directories(kmi-simple BEFORE PUBLIC "..") + +add_library(kmi-flatfile SHARED + flatfile.c + key_format_ltfs.c +) +target_link_libraries(kmi-flatfile + PkgConfig::FUSE + ltfs + libkmi_flatfile +) +target_include_directories(kmi-flatfile BEFORE PUBLIC "..") diff --git a/src/libltfs/CMakeLists.txt b/src/libltfs/CMakeLists.txt new file mode 100644 index 00000000..c193e443 --- /dev/null +++ b/src/libltfs/CMakeLists.txt @@ -0,0 +1,18 @@ +file(GLOB_RECURSE LIBLTFS_SRCS LIST_DIRECTORIES false "*.c") +add_library(ltfs SHARED ${LIBLTFS_SRCS}) +target_include_directories(ltfs BEFORE PUBLIC "..") + +target_link_libraries(ltfs + Threads::Threads + PkgConfig::FUSE + LibXml2::LibXml2 + PkgConfig::UUID + libbin_ltfs + liblibltfs + libinternal_error + libtape_common +) + +if(ENABLE_SNMP) + target_link_libraries(ltfs PkgConfig::SNMP) +endif() diff --git a/src/libltfs/arch/time_internal.c b/src/libltfs/arch/time_internal.c index a6bae2ce..5e14ecc1 100644 --- a/src/libltfs/arch/time_internal.c +++ b/src/libltfs/arch/time_internal.c @@ -56,14 +56,15 @@ #include "libltfs/ltfslogging.h" #include "libltfs/arch/time_internal.h" -#ifdef __APPLE__ +// TODO: Fix definition of SIZEOF_TIME_T in cmake +#if defined(__APPLE__) || defined(__CMAKE_BUILD) /* * In OSX environment time_t is always 64-bit width. * It is specified by compile option of Makefile.osx because autoconf architecture is * not used under OSX. */ #define SIZEOF_TIME_T (8) -#else +#elif !defined(__CMAKE_BUILD) #include "config.h" #endif diff --git a/src/libltfs/ltfs.h b/src/libltfs/ltfs.h index ec518f1a..22aaf6cf 100644 --- a/src/libltfs/ltfs.h +++ b/src/libltfs/ltfs.h @@ -184,7 +184,7 @@ enum ltfs_index_type { #define LTFS_NO_BARCODE "NO_BARCODE" -#ifndef __APPLE_MAKEFILE__ +#if !defined(__APPLE_MAKEFILE__) && !defined(__CMAKE_BUILD) #include "config.h" #endif diff --git a/src/tape_drivers/CMakeLists.txt b/src/tape_drivers/CMakeLists.txt new file mode 100644 index 00000000..f93f12c0 --- /dev/null +++ b/src/tape_drivers/CMakeLists.txt @@ -0,0 +1,15 @@ +add_library(tape_reed_solomon_crc SHARED + reed_solomon_crc.c +) +target_link_libraries(tape_reed_solomon_crc + PkgConfig::FUSE + ltfs +) + +add_library(tape_crc32c_crc SHARED + crc32c_crc.c +) +target_link_libraries(tape_crc32c_crc + PkgConfig::FUSE + ltfs +) diff --git a/src/tape_drivers/freebsd/cam/CMakeLists.txt b/src/tape_drivers/freebsd/cam/CMakeLists.txt new file mode 100644 index 00000000..3fa22efd --- /dev/null +++ b/src/tape_drivers/freebsd/cam/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library(tape-cam SHARED + cam_cmn.c + cam_tc.c + ../../vendor_compat.c + ../../ibm_tape.c + ../../hp_tape.c + ../../quantum_tape.c +) +target_link_libraries(tape-cam + PkgConfig::FUSE + ltfs + libtape_freebsd_cam + tape_reed_solomon_crc + tape_crc32c_crc +) +target_include_directories(tape-cam BEFORE PUBLIC "../..") diff --git a/src/tape_drivers/generic/file/CMakeLists.txt b/src/tape_drivers/generic/file/CMakeLists.txt new file mode 100644 index 00000000..3145a7d1 --- /dev/null +++ b/src/tape_drivers/generic/file/CMakeLists.txt @@ -0,0 +1,11 @@ +add_library(tape-file SHARED + filedebug_tc.c + filedebug_conf_tc.c + ../../ibm_tape.c +) +target_link_libraries(tape-file + PkgConfig::FUSE + ltfs + libtape_generic_file +) +target_include_directories(tape-file BEFORE PUBLIC "../..") diff --git a/src/tape_drivers/generic/itdtimg/CMakeLists.txt b/src/tape_drivers/generic/itdtimg/CMakeLists.txt new file mode 100644 index 00000000..7609ccb4 --- /dev/null +++ b/src/tape_drivers/generic/itdtimg/CMakeLists.txt @@ -0,0 +1,12 @@ +add_library(tape-itdtimg SHARED + itdtimg_tc.c + ../../ibm_tape.c +) +target_link_libraries(tape-itdtimg + PkgConfig::FUSE + ltfs + libtape_generic_itdtimg + tape_reed_solomon_crc + tape_crc32c_crc +) +target_include_directories(tape-itdtimg BEFORE PUBLIC "../..") diff --git a/src/tape_drivers/linux/lin_tape/CMakeLists.txt b/src/tape_drivers/linux/lin_tape/CMakeLists.txt new file mode 100644 index 00000000..5bad87a3 --- /dev/null +++ b/src/tape_drivers/linux/lin_tape/CMakeLists.txt @@ -0,0 +1,15 @@ +add_library(tape_lintape SHARED + lin_tape_ibmtape.c + ../../vendor_compat.c + ../../ibm_tape.c + ../../hp_tape.c + ../../quantum_tape.c +) +target_link_libraries(tape_lintape + PkgConfig::FUSE + ltfs + libtape_linux_lin_tape + tape_reed_solomon_crc + tape_crc32c_crc +) +target_include_directories(tape_lintape BEFORE PUBLIC "../..") diff --git a/src/tape_drivers/linux/sg/CMakeLists.txt b/src/tape_drivers/linux/sg/CMakeLists.txt new file mode 100644 index 00000000..cf85d10a --- /dev/null +++ b/src/tape_drivers/linux/sg/CMakeLists.txt @@ -0,0 +1,17 @@ +add_library(tape_sg SHARED + sg_scsi_tape.c + sg_tape.c + ../../vendor_compat.c + ../../ibm_tape.c + ../../hp_tape.c + ../../quantum_tape.c + ../../open_factor.c +) +target_link_libraries(tape_sg + PkgConfig::FUSE + ltfs + libtape_linux_sg + tape_reed_solomon_crc + tape_crc32c_crc +) +target_include_directories(tape_sg BEFORE PUBLIC "../..") diff --git a/src/tape_drivers/netbsd/scsipi-ibmtape/CMakeLists.txt b/src/tape_drivers/netbsd/scsipi-ibmtape/CMakeLists.txt new file mode 100644 index 00000000..bdbd03da --- /dev/null +++ b/src/tape_drivers/netbsd/scsipi-ibmtape/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library(libtape_sg_ibmtape SHARED + scsipi_scsi_tape.c + scsipi_ibmtape.c + ../../vendor_compat.c + ../../ibm_tape.c + ../../hp_tape.c + ../../quantum_tape.c +) +target_link_libraries(libtape_sg_ibmtape + PkgConfig::FUSE + ltfs + libtape_linux_sg_ibmtape + tape_reed_solomon_crc + tape_crc32c_crc +) +target_include_directories(tape_sg_ibmtape BEFORE PUBLIC "../..") diff --git a/src/tape_drivers/osx/iokit/CMakeLists.txt b/src/tape_drivers/osx/iokit/CMakeLists.txt new file mode 100644 index 00000000..03b15001 --- /dev/null +++ b/src/tape_drivers/osx/iokit/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library(tape_iokit SHARED + scsipi_scsi_tape.c + scsipi_ibmtape.c + ../../vendor_compat.c + ../../ibm_tape.c + ../../hp_tape.c + ../../quantum_tape.c +) +target_link_libraries(tape_iokit + PkgConfig::FUSE + ltfs + libtape_iokit + tape_reed_solomon_crc + tape_crc32c_crc +) +target_include_directories(tape_iokit BEFORE PUBLIC "../..") diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt new file mode 100644 index 00000000..01380b01 --- /dev/null +++ b/src/utils/CMakeLists.txt @@ -0,0 +1,24 @@ +add_executable(mkltfs mkltfs.c) +target_link_libraries(mkltfs + ICU::uc + ltfs + libbin_mkltfs +) +target_include_directories(mkltfs BEFORE PUBLIC ".") + +add_executable(ltfsck ltfsck.c) +target_link_libraries(ltfsck + ICU::uc + ltfs + libbin_ltfsck +) +target_include_directories(ltfsck BEFORE PUBLIC ".") + +add_executable(ltfsindextool ltfsindextool.c) +target_link_libraries(ltfsindextool + ICU::uc + ltfs + libbin_ltfsindextool + libbin_mkltfs +) +target_include_directories(ltfsindextool BEFORE PUBLIC ".")