Porting to freebsd: initial, compile ok, most tests ok.

This commit is contained in:
proller 2016-12-24 01:03:10 +00:00
parent 2552e7de4b
commit 4bc003c4c1
38 changed files with 408 additions and 101 deletions

View File

@ -1,12 +1,12 @@
project (ClickHouse)
cmake_minimum_required (VERSION 2.6)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Require at least gcc 5
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5 AND NOT CMAKE_VERSION VERSION_LESS 2.8.9)
message (FATAL_ERROR "GCC version must be at least 5! For example, if GCC 5 is available under gcc-5, g++-5 names, do the following: export CC=gcc-5 CXX=g++-5; rm -rf CMakeCache.txt CMakeFiles; and re run cmake or ./release.")
endif ()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Require at least clang 3.8
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8)
message (FATAL_ERROR "Clang version must be at least 3.8!")
@ -16,7 +16,11 @@ else ()
endif ()
if (APPLE)
set (APPLE_EXTRA_CXX_FLAG "-Dexp10=__exp10") # Also needed for libc++
set (PLATFORM_EXTRA_CXX_FLAG "-Dexp10=__exp10") # Also needed for libc++
endif ()
if (CMAKE_SYSTEM MATCHES "FreeBSD")
set (PLATFORM_EXTRA_CXX_FLAG "-DCLOCK_MONOTONIC_COARSE=CLOCK_MONOTONIC_FAST")
endif ()
cmake_policy (SET CMP0014 OLD) # Ignore warning about CMakeLists.txt in each directory
@ -85,16 +89,16 @@ if (GLIBC_COMPATIBILITY)
set (GLIBC_COMPATIBILITY_LINK_FLAGS "-Wl,--wrap=memcpy")
endif ()
if ("${CXX11_ABI}" STREQUAL ENABLE)
if (CXX11_ABI STREQUAL ENABLE)
set (CXX11_ABI_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=1")
elseif ("${CXX11_ABI}" STREQUAL DISABLE)
elseif (CXX11_ABI STREQUAL DISABLE)
set (CXX11_ABI_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0")
else ()
set (CXX11_ABI_FLAGS "")
endif ()
set (CMAKE_BUILD_COLOR_MAKEFILE ON)
set (CMAKE_CXX_FLAGS "-std=gnu++1y ${APPLE_EXTRA_CXX_FLAG} -fno-omit-frame-pointer ${COMMON_WARNING_FLAGS} ${CXX_WARNING_FLAGS} ${MACHINE_FLAGS} ${GLIBC_COMPATIBILITY_COMPILE_FLAGS} ${CXX11_ABI_FLAGS}")
set (CMAKE_CXX_FLAGS "-std=gnu++1y ${PLATFORM_EXTRA_CXX_FLAG} -fno-omit-frame-pointer ${COMMON_WARNING_FLAGS} ${CXX_WARNING_FLAGS} ${MACHINE_FLAGS} ${GLIBC_COMPATIBILITY_COMPILE_FLAGS} ${CXX11_ABI_FLAGS}")
set (CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g")
set (CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline")
@ -104,8 +108,12 @@ set (CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
set (CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g")
set (CMAKE_C_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline")
if (NOT APPLE AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_SYSTEM MATCHES "FreeBSD"))
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
endif ()
if (NOT APPLE)
set (CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ ${GLIBC_COMPATIBILITY_LINK_FLAGS} ${CXX11_ABI_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GLIBC_COMPATIBILITY_LINK_FLAGS} ${CXX11_ABI_FLAGS}")
endif ()
# -fuse-ld=gold - fix linkage for gcc-5.4, gcc-6.1
@ -127,44 +135,46 @@ if (ENABLE_TESTS)
endif (ENABLE_TESTS)
# Installation prefix
set (CMAKE_INSTALL_PREFIX /usr)
if (NOT CMAKE_SYSTEM MATCHES "FreeBSD")
set (CMAKE_INSTALL_PREFIX /usr)
endif ()
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libcityhash/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/liblz4/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libdivide/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libdouble-conversion/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libcpuid/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libzstd/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libfarmhash/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libmetrohash/src)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libsparsehash/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libre2/)
include_directories (${ClickHouse_BINARY_DIR}/contrib/libre2/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libzookeeper/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libtcmalloc/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/Foundation/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/Util/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/Net/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/NetSSL_OpenSSL/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/Data/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/Data/MySQL/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/Data/ODBC/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/Data/SQLite/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/Crypto/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/XML/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/JSON/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/MongoDB/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libpoco/Zip/include/)
include_directories (${ClickHouse_SOURCE_DIR}/contrib/libboost/boost_1_62_0/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libcityhash/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/liblz4/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libdivide/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libdouble-conversion/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libcpuid/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libzstd/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libfarmhash/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libmetrohash/src)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libsparsehash/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libre2/)
include_directories (BEFORE ${ClickHouse_BINARY_DIR}/contrib/libre2/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libzookeeper/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libtcmalloc/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libpoco/Foundation/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libpoco/Util/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libpoco/Net/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libpoco/NetSSL_OpenSSL/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libpoco/Data/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libpoco/Data/MySQL/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libpoco/Data/ODBC/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libpoco/Data/SQLite/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libpoco/Crypto/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libpoco/XML/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libpoco/JSON/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libpoco/MongoDB/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libpoco/Zip/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libboost/boost_1_62_0/)
include_directories (${ClickHouse_SOURCE_DIR}/libs/libcommon/include/)
include_directories (${ClickHouse_BINARY_DIR}/libs/libcommon/include/)
include_directories (${ClickHouse_SOURCE_DIR}/libs/libdaemon/include/)
include_directories (${ClickHouse_SOURCE_DIR}/libs/libpocoext/include/)
include_directories (${ClickHouse_SOURCE_DIR}/libs/libmysqlxx/include/)
include_directories (${ClickHouse_SOURCE_DIR}/libs/libzkutil/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/libs/libcommon/include/)
include_directories (BEFORE ${ClickHouse_BINARY_DIR}/libs/libcommon/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/libs/libdaemon/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/libs/libpocoext/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/libs/libmysqlxx/include/)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/libs/libzkutil/include/)
include_directories (${ClickHouse_SOURCE_DIR}/dbms/include)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/dbms/include)
include_directories (/usr/local/include/)

View File

@ -17,7 +17,7 @@ macro (create_init_script daemonname)
set (tmp_file_name ${filename}.init)
set (SED_INPLACE_SUFFIX "")
if (APPLE)
if (APPLE OR CMAKE_SYSTEM MATCHES "FreeBSD")
set (SED_INPLACE_SUFFIX "''")
endif ()
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${tmp_file_name}

View File

@ -18,6 +18,7 @@ find_path (GLIB_INCLUDE_DIR NAMES glib.h HINTS ${GLIB_INCLUDE_HINTS})
find_path (GLIB_CONFIG_INCLUDE_DIR NAMES glibconfig.h HINTS ${GLIB_INCLUDE_HINTS})
include_directories (${GLIB_INCLUDE_DIR})
include_directories (${GLIB_CONFIG_INCLUDE_DIR})
if (APPLE)
set (INTL_HINTS "/usr/local/opt/gettext/lib")
if (USE_STATIC_LIBRARIES)
@ -34,6 +35,19 @@ if (APPLE)
find_library (CORE_FOUNDATION_LIB CoreFoundation)
find_library (CARBON_LIB Carbon)
set (GLIB_LIBS ${GLIB_LIB} ${INTL_LIB} ${ICONV_LIB} ${CORE_FOUNDATION_LIB} ${CARBON_LIB})
else (APPLE)
elseif (CMAKE_SYSTEM MATCHES "FreeBSD")
set (ICONV_HINTS "")
set (INTL_HINTS "")
if (USE_STATIC_LIBRARIES)
find_library (ICONV_LIB libiconv.a HINTS ${ICONV_HINTS})
find_library (INTL_LIB libintl.a HINTS ${INTL_HINTS})
else ()
find_library (ICONV_LIB iconv HINTS ${ICONV_HINTS})
find_library (INTL_LIB intl HINTS ${INTL_HINTS})
endif ()
set (GLIB_LIBS ${GLIB_LIB} ${INTL_LIB} ${ICONV_LIB})
else ()
set (GLIB_LIBS ${GLIB_LIB})
endif (APPLE)
endif ()

View File

@ -1,9 +1,9 @@
set (MYSQL_HINTS "/usr/local/opt/mysql/lib")
set (MYSQL_INCLUDE_HINTS "/usr/local/opt/mysql/include")
set (MYSQL_LIB_PATHS "/usr/local/opt/mysql/lib" "/usr/local/lib/mysql/")
set (MYSQL_INCLUDE_PATHS "/usr/local/opt/mysql/include")
if (USE_STATIC_LIBRARIES)
find_library (STATIC_MYSQLCLIENT_LIB libmysqlclient.a HINTS ${MYSQL_HINTS})
find_library (STATIC_MYSQLCLIENT_LIB libmysqlclient.a PATHS ${MYSQL_LIB_PATHS})
else ()
find_library (MYSQLCLIENT_LIB mysqlclient HINTS ${MYSQL_HINTS})
find_library (MYSQLCLIENT_LIB mysqlclient PATHS ${MYSQL_LIB_PATHS})
endif ()
find_path (MYSQL_INCLUDE_DIR NAMES mysql.h PATH_SUFFIXES mysql HINTS ${MYSQL_INCLUDE_HINTS})
find_path (MYSQL_INCLUDE_DIR NAMES mysql.h PATH_SUFFIXES mysql PATHS ${MYSQL_INCLUDE_PATHS})
include_directories (${MYSQL_INCLUDE_DIR})

View File

@ -123,6 +123,7 @@ static int get_total_cpus(void)
#endif
#if defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__ || defined __bsdi__ || defined __QNX__
#include <sys/types.h>
#include <sys/sysctl.h>
static int get_total_cpus(void)

View File

@ -138,18 +138,22 @@ if (UNIX AND NOT ANDROID )
# Standard 'must be' defines
if (APPLE)
add_definitions( -DPOCO_HAVE_IPv6 -DPOCO_NO_STAT64)
set(SYSLIBS dl)
else (APPLE)
set(SYSLIBS ${CMAKE_DL_LIBS})
elseif (CMAKE_SYSTEM MATCHES "FreeBSD")
add_definitions(-D__BSD_VISIBLE ) # better #include <sys/cdefs.h>
add_definitions(-D_XOPEN_SOURCE=700 -D_REENTRANT -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DPOCO_HAVE_IPv6)
set(SYSLIBS pthread ${CMAKE_DL_LIBS} rt)
else ()
add_definitions(-D_XOPEN_SOURCE=500 -D_REENTRANT -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DPOCO_HAVE_FD_EPOLL -DPOCO_HAVE_IPv6)
set(SYSLIBS pthread dl rt)
endif (APPLE)
set(SYSLIBS pthread ${CMAKE_DL_LIBS} rt)
endif ()
endif(UNIX AND NOT ANDROID )
if (CMAKE_SYSTEM MATCHES "SunOS")
add_definitions( -DPOCO_OS_FAMILY_UNIX )
# Standard 'must be' defines
add_definitions( -D_XOPEN_SOURCE=500 -D_REENTRANT -D_THREAD_SAFE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 )
set(SYSLIBS pthread socket xnet nsl resolv rt dl)
set(SYSLIBS pthread socket xnet nsl resolv rt ${CMAKE_DL_LIBS})
endif(CMAKE_SYSTEM MATCHES "SunOS")
if (CMAKE_COMPILER_IS_MINGW)

View File

@ -16,7 +16,7 @@ if(WIN32)
else()
set(SYSLIBS ${SYSLIBS} "ws2_32.lib" "iphlpapi.lib")
endif()
elseif(NOT APPLE)
elseif(NOT APPLE AND NOT CMAKE_SYSTEM MATCHES "FreeBSD")
if (USE_STATIC_LIBRARIES)
set(SYSLIBS ${SYSLIBS} "libanl.a")
else()

View File

@ -34,7 +34,7 @@
/// set default DNS timeout to 60 seconds
const Poco::Timespan Poco::Net::DNS::DEFAULT_DNS_TIMEOUT = Poco::Timespan(60, 0);
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
/** getaddrinfo иногда работает бесконечно долго.
* Этот код использует getaddrinfo_a c некоторым таймаутом.
*
@ -224,7 +224,7 @@ HostEntry DNS::hostByName(const std::string& hostname, const Poco::Timespan * ti
struct addrinfo hints;
std::memset(&hints, 0, sizeof(hints));
hints.ai_flags = hintFlags;
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
int rc = GetAddrinfo::instance().getaddrinfo(hostname.c_str(), NULL, &hints, &pAI, timeout_);
#else
(void)timeout_;
@ -278,7 +278,7 @@ HostEntry DNS::hostByAddress(const IPAddress& address, const Poco::Timespan * ti
struct addrinfo hints;
std::memset(&hints, 0, sizeof(hints));
hints.ai_flags = hintFlags;
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
int rc = GetAddrinfo::instance().getaddrinfo(fqname, NULL, &hints, &pAI, timeout_);
#else
(void)timeout_;

View File

@ -1,4 +1,5 @@
find_path(MYSQL_INCLUDE_DIR mysql.h
PATHS
/usr/include/mysql
/usr/local/include/mysql
/opt/mysql/mysql/include

View File

@ -8,6 +8,14 @@ add_definitions(
-fno-builtin-memalign -fno-builtin-posix_memalign -fno-builtin-valloc -fno-builtin-pvalloc
)
if(CMAKE_SYSTEM MATCHES "FreeBSD" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_definitions(-Wno-unused-but-set-variable)
endif()
if(CMAKE_SYSTEM MATCHES "FreeBSD")
add_definitions(-D_GNU_SOURCE)
endif()
include_directories (include src)
message(STATUS "Building: tcmalloc_minimal_internal")

View File

@ -45,7 +45,7 @@
#define TC_VERSION_STRING "gperftools 2.5"
/* For struct mallinfo, if it's defined. */
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
# include <malloc.h>
#else
struct mallinfo {

View File

@ -73,7 +73,7 @@
#define HAVE_FCNTL_H 1
/* Define to 1 if you have the <features.h> header file. */
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#define HAVE_FEATURES_H 1
#endif
@ -99,7 +99,7 @@
//#define HAVE_LIBUNWIND_H 1
/* Define to 1 if you have the <linux/ptrace.h> header file. */
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#define HAVE_LINUX_PTRACE_H 1
#endif
@ -107,7 +107,9 @@
#define HAVE_LINUX_SIGEV_THREAD_ID 1
/* Define to 1 if you have the <malloc.h> header file. */
#if !defined(__FreeBSD__)
#define HAVE_MALLOC_H 1
#endif
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
@ -122,7 +124,7 @@
#define HAVE_POLL_H 1
/* define if libc has program_invocation_name */
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#define HAVE_PROGRAM_INVOCATION_NAME 1
#endif
@ -155,7 +157,8 @@
#define HAVE_STRING_H 1
/* Define to 1 if the system has the type `struct mallinfo'. */
#ifndef __APPLE__
//#if !defined(__APPLE__) && !defined(__FreeBSD__)
#if !defined(__APPLE__)
#define HAVE_STRUCT_MALLINFO 1
#endif
@ -211,7 +214,7 @@
#define HAVE___ATTRIBUTE__ 1
/* Define to 1 if compiler supports __environ */
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#define HAVE___ENVIRON 1
#endif

View File

@ -1,5 +1,5 @@
include_directories (include)
include_directories (/usr/include/mysql)
include_directories (BEFORE include)
#include_directories (/usr/include/mysql)
add_subdirectory (src)
@ -50,7 +50,7 @@ list(REMOVE_ITEM dbms_sources
src/Databases/DatabaseCloud.cpp
src/Common/StringUtils.cpp)
if (APPLE)
if (APPLE OR CMAKE_SYSTEM MATCHES "FreeBSD")
list(REMOVE_ITEM dbms_headers
include/DB/Common/AIO.h
include/DB/IO/WriteBufferAIO.h
@ -109,6 +109,12 @@ if (APPLE)
set(APPLE_ICONV_LIB iconv)
endif()
if (CMAKE_SYSTEM MATCHES "FreeBSD")
set(PLATFORM_LIBS "execinfo")
else()
set(PLATFORM_LIBS "")
endif()
target_link_libraries(dbms
common
zkutil
@ -125,7 +131,9 @@ target_link_libraries(dbms
PocoDataODBC
PocoMongoDB
${APPLE_ICONV_LIB}
dl ${LTDL_LIB})
${PLATFORM_LIBS}
${CMAKE_DL_LIBS}
${LTDL_LIB})
add_dependencies (dbms
common

View File

@ -1,6 +1,6 @@
#pragma once
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#include <malloc.h>
#endif
#include <cstdlib>
@ -133,7 +133,7 @@ public:
*/
void * realloc(void * buf, size_t old_size, size_t new_size, size_t alignment = 0)
{
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
if (old_size < MMAP_THRESHOLD && new_size < MMAP_THRESHOLD && alignment <= MALLOC_MIN_ALIGNMENT)
{
if (current_memory_tracker)

View File

@ -1,7 +1,7 @@
#pragma once
#include <string.h>
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#include <malloc.h>
#endif
#include <cstdlib>

View File

@ -1,5 +1,7 @@
#pragma once
#include <common/exp10.h>
#include <DB/DataTypes/DataTypesNumberFixed.h>
#include <DB/Functions/IFunction.h>

View File

@ -13,6 +13,8 @@
#include <common/LocalDate.h>
#include <common/LocalDateTime.h>
#include <common/exp10.h>
#include <DB/Core/Types.h>
#include <DB/Core/StringRef.h>
#include <DB/Common/Exception.h>

View File

@ -1,4 +1,4 @@
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#include <malloc.h>
#endif
#include <execinfo.h>

View File

@ -1,18 +1,26 @@
#ifndef __APPLE__
#include <sys/prctl.h>
#else
#if defined(__APPLE__)
#include <pthread.h>
#elif defined(__FreeBSD__)
#include <pthread.h>
#include <pthread_np.h>
#else
#include <sys/prctl.h>
#endif
#include <DB/Common/Exception.h>
#include <DB/Common/setThreadName.h>
void setThreadName(const char * name)
{
#ifndef __APPLE__
if (0 != prctl(PR_SET_NAME, name, 0, 0, 0))
#else
#if defined(__FreeBSD__)
pthread_set_name_np(pthread_self(), name);
return;
#elif defined(__APPLE__)
if (0 != pthread_setname_np(name))
#else
if (0 != prctl(PR_SET_NAME, name, 0, 0, 0))
#endif
DB::throwFromErrno("Cannot set thread name with prctl(PR_SET_NAME...)");
}

View File

@ -1,4 +1,4 @@
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#include <sched.h>
#endif
@ -18,7 +18,7 @@
void setAffinity()
{
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(0, &mask);

View File

@ -1,4 +1,4 @@
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#include <malloc.h>
#endif
#include <ext/bit_cast.hpp>

View File

@ -1,6 +1,6 @@
#include <DB/IO/createReadBufferFromFileBase.h>
#include <DB/IO/ReadBufferFromFile.h>
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#include <DB/IO/ReadBufferAIO.h>
#endif
#include <DB/Common/ProfileEvents.h>
@ -14,7 +14,7 @@ namespace ProfileEvents
namespace DB
{
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__FreeBSD__)
namespace ErrorCodes
{
extern const int NOT_IMPLEMENTED;
@ -31,7 +31,7 @@ std::unique_ptr<ReadBufferFromFileBase> createReadBufferFromFileBase(const std::
}
else
{
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
ProfileEvents::increment(ProfileEvents::CreatedReadBufferAIO);
return std::make_unique<ReadBufferAIO>(filename_, buffer_size_, flags_, existing_memory_);
#else

View File

@ -1,6 +1,6 @@
#include <DB/IO/createWriteBufferFromFileBase.h>
#include <DB/IO/WriteBufferFromFile.h>
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#include <DB/IO/WriteBufferAIO.h>
#endif
#include <DB/Common/ProfileEvents.h>
@ -15,7 +15,7 @@ namespace ProfileEvents
namespace DB
{
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__FreeBSD__)
namespace ErrorCodes
{
extern const int NOT_IMPLEMENTED;
@ -33,7 +33,7 @@ WriteBufferFromFileBase * createWriteBufferFromFileBase(const std::string & file
}
else
{
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
ProfileEvents::increment(ProfileEvents::CreatedWriteBufferAIO);
return new WriteBufferAIO(filename_, buffer_size_, flags_, mode, existing_memory_);
#else

View File

@ -63,7 +63,7 @@ add_check (hashing_read_buffer)
add_executable (io_operators operators.cpp ${SRCS})
target_link_libraries (io_operators dbms)
if (NOT APPLE)
if (NOT APPLE AND NOT CMAKE_SYSTEM MATCHES "FreeBSD")
add_executable(write_buffer_aio write_buffer_aio.cpp)
target_link_libraries (write_buffer_aio dbms ${Boost_FILESYSTEM_LIBRARY})

View File

@ -1,3 +1,5 @@
#include <common/exp10.h>
#include <DB/Parsers/CommonParsers.h>
#include <DB/Parsers/ParserSampleRatio.h>
#include <DB/Parsers/ASTSampleRatio.h>

View File

@ -413,7 +413,11 @@ int Server::main(const std::vector<std::string> & args)
catch (const Poco::Net::DNSException & e)
{
/// Better message when IPv6 is disabled on host.
if (e.code() == EAI_ADDRFAMILY)
if (e.code() == EAI_FAMILY
#if defined(EAI_ADDRFAMILY)
|| e.code() == EAI_ADDRFAMILY
#endif
)
{
LOG_ERROR(log, "Cannot resolve listen_host (" << listen_host + "), error: " << e.message() << ". "
"If it is an IPv6 address and your host has disabled IPv6, then consider to specify IPv4 address to listen in <listen_host> element of configuration file. Example: <listen_host>0.0.0.0</listen_host>");

20
doc/build_freebsd.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/sh
# How to build ClickHouse under freebsd 11+
# [temporary solution before port created]
# install compiler and libs
pkg install -y git cmake gcc6 bash glib mysql57-client icu libltdl unixODBC
# install testing only stuff if you want:
pkg install -y python py27-lxml py27-termcolor
# Checkout ClickHouse sources
git clone https://github.com/yandex/ClickHouse.git
# Build!
mkdir -p ClickHouse/build
cd ClickHouse/build
cmake .. -DCMAKE_CXX_COMPILER=`which g++6` -DCMAKE_C_COMPILER=`which gcc6`
make -j $(nproc || sysctl -n hw.ncpu || echo 2)
cd ..

View File

@ -27,6 +27,7 @@ endif()
add_library (common
src/DateLUT.cpp
src/DateLUTImpl.cpp
src/exp10.cpp
src/ClickHouseRevision.cpp
src/JSON.cpp
@ -37,6 +38,7 @@ add_library (common
include/common/LocalDate.h
include/common/LocalDateTime.h
include/common/ErrorHandlers.h
include/common/exp10.h
include/common/likely.h
include/common/logger_useful.h
include/common/MultiVersion.h

View File

@ -0,0 +1,8 @@
#pragma once
double musl_exp10(double x);
#if defined(__FreeBSD__)
//const auto& exp10 = musl_exp10; // it must be the name of a function with external linkage
#define exp10 musl_exp10
#endif

View File

@ -5,6 +5,7 @@
#include <Poco/NumberParser.h>
#include <common/JSON.h>
#include <common/find_first_symbols.h>
#include <common/exp10.h>
#include <iostream>

View File

@ -0,0 +1,197 @@
/*
https://www.musl-libc.org/
http://git.musl-libc.org/cgit/musl/tree/src/math/exp10.c
musl as a whole is licensed under the following standard MIT license:
----------------------------------------------------------------------
Copyright © 2005-2014 Rich Felker, et al.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
----------------------------------------------------------------------
Authors/contributors include:
Alex Dowad
Alexander Monakov
Anthony G. Basile
Arvid Picciani
Bobby Bingham
Boris Brezillon
Brent Cook
Chris Spiegel
Clément Vasseur
Daniel Micay
Denys Vlasenko
Emil Renner Berthing
Felix Fietkau
Felix Janda
Gianluca Anzolin
Hauke Mehrtens
Hiltjo Posthuma
Isaac Dunham
Jaydeep Patil
Jens Gustedt
Jeremy Huntwork
Jo-Philipp Wich
Joakim Sindholt
John Spencer
Josiah Worcester
Justin Cormack
Khem Raj
Kylie McClain
Luca Barbato
Luka Perkov
M Farkas-Dyck (Strake)
Mahesh Bodapati
Michael Forney
Natanael Copa
Nicholas J. Kain
orc
Pascal Cuoq
Petr Hosek
Pierre Carrier
Rich Felker
Richard Pennington
Shiz
sin
Solar Designer
Stefan Kristiansson
Szabolcs Nagy
Timo Teräs
Trutz Behn
Valentin Ochs
William Haddon
Portions of this software are derived from third-party works licensed
under terms compatible with the above MIT license:
The TRE regular expression implementation (src/regex/reg* and
src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed
under a 2-clause BSD license (license text in the source files). The
included version has been heavily modified by Rich Felker in 2012, in
the interests of size, simplicity, and namespace cleanliness.
Much of the math library code (src/math/ * and src/complex/ *) is
Copyright © 1993,2004 Sun Microsystems or
Copyright © 2003-2011 David Schultz or
Copyright © 2003-2009 Steven G. Kargl or
Copyright © 2003-2009 Bruce D. Evans or
Copyright © 2008 Stephen L. Moshier
and labelled as such in comments in the individual source files. All
have been licensed under extremely permissive terms.
The ARM memcpy code (src/string/arm/memcpy_el.S) is Copyright © 2008
The Android Open Source Project and is licensed under a two-clause BSD
license. It was taken from Bionic libc, used on Android.
The implementation of DES for crypt (src/crypt/crypt_des.c) is
Copyright © 1994 David Burren. It is licensed under a BSD license.
The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was
originally written by Solar Designer and placed into the public
domain. The code also comes with a fallback permissive license for use
in jurisdictions that may not recognize the public domain.
The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011
Valentin Ochs and is licensed under an MIT-style license.
The BSD PRNG implementation (src/prng/random.c) and XSI search API
(src/search/ *.c) functions are Copyright © 2011 Szabolcs Nagy and
licensed under following terms: "Permission to use, copy, modify,
and/or distribute this code for any purpose with or without fee is
hereby granted. There is no warranty."
The x86_64 port was written by Nicholas J. Kain and is licensed under
the standard MIT terms.
The mips and microblaze ports were originally written by Richard
Pennington for use in the ellcc project. The original code was adapted
by Rich Felker for build system and code conventions during upstream
integration. It is licensed under the standard MIT terms.
The mips64 port was contributed by Imagination Technologies and is
licensed under the standard MIT terms.
The powerpc port was also originally written by Richard Pennington,
and later supplemented and integrated by John Spencer. It is licensed
under the standard MIT terms.
All other files which have no copyright comments are original works
produced specifically for use as part of this library, written either
by Rich Felker, the main author of the library, or by one or more
contibutors listed above. Details on authorship of individual files
can be found in the git version control history of the project. The
omission of copyright and license comments in each file is in the
interest of source tree size.
In addition, permission is hereby granted for all public header files
(include/ * and arch/ * /bits/ *) and crt files intended to be linked into
applications (crt/ *, ldso/dlstart.c, and arch/ * /crt_arch.h) to omit
the copyright notice and permission notice otherwise required by the
license, and to use these files without any requirement of
attribution. These files include substantial contributions from:
Bobby Bingham
John Spencer
Nicholas J. Kain
Rich Felker
Richard Pennington
Stefan Kristiansson
Szabolcs Nagy
all of whom have explicitly granted such permission.
This file previously contained text expressing a belief that most of
the files covered by the above exception were sufficiently trivial not
to be subject to copyright, resulting in confusion over whether it
negated the permissions granted in the license. In the spirit of
permissive licensing, and of not having licensing issues being an
obstacle to adoption, that text has been removed.
*/
//#define _GNU_SOURCE
#include <math.h>
#include <stdint.h>
//#include "libc.h"
double musl_exp10(double x)
{
static const double p10[] = {
1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10,
1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1,
1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
1e10, 1e11, 1e12, 1e13, 1e14, 1e15
};
double n, y = modf(x, &n);
union {double f; uint64_t i;} u = {n};
/* fabs(n) < 16 without raising invalid on nan */
if ((u.i>>52 & 0x7ff) < 0x3ff+4) {
if (!y) return p10[(int)n+15];
y = exp2(3.32192809488736234787031942948939 * y);
return y * p10[(int)n+15];
}
return pow(10.0, x);
}
//weak_alias(exp10, pow10);

View File

@ -8,10 +8,13 @@ add_executable (multi_version multi_version.cpp)
add_executable (json_test json_test.cpp)
add_executable (strong_typedef strong_typedef.cpp)
target_link_libraries (date_lut_init common ${ICU_LIBS} dl)
target_link_libraries (date_lut2 common ${ICU_LIBS} dl)
target_link_libraries (date_lut3 common ${ICU_LIBS} dl)
target_link_libraries (date_lut4 common ${ICU_LIBS} dl)
set(PLATFORM_LIBS ${CMAKE_DL_LIBS})
target_link_libraries (date_lut_init common ${ICU_LIBS} ${PLATFORM_LIBS})
target_link_libraries (date_lut2 common ${ICU_LIBS} ${PLATFORM_LIBS})
target_link_libraries (date_lut3 common ${ICU_LIBS} ${PLATFORM_LIBS})
target_link_libraries (date_lut4 common ${ICU_LIBS} ${PLATFORM_LIBS})
target_link_libraries (multi_version dbms ${Boost_SYSTEM_LIBRARY} ${RT_LIBRARIES})
target_link_libraries (json_test dbms ${Boost_SYSTEM_LIBRARY} ${RT_LIBRARIES})
target_link_libraries (strong_typedef common)

View File

@ -284,10 +284,12 @@ private:
#if defined(__x86_64__)
/// Get the address at the time the signal was raised from the RIP (x86-64)
#ifndef __APPLE__
caller_address = reinterpret_cast<void *>(context.uc_mcontext.gregs[REG_RIP]);
#else
#if defined(__FreeBSD__)
caller_address = reinterpret_cast<void *>(context.uc_mcontext.mc_rip);
#elif defined(__APPLE__)
caller_address = reinterpret_cast<void *>(context.uc_mcontext->__ss.__rip);
#else
caller_address = reinterpret_cast<void *>(context.uc_mcontext.gregs[REG_RIP]);
#endif
#elif defined(__aarch64__)
caller_address = reinterpret_cast<void *>(context.uc_mcontext.pc);

View File

@ -33,9 +33,11 @@ else ()
find_library (Z_LIB z HINTS ${Z_HINTS})
endif ()
set(PLATFORM_LIBS ${CMAKE_DL_LIBS})
if (USE_STATIC_LIBRARIES)
set (MYSQLCLIENT_LIB ${CMAKE_CURRENT_BINARY_DIR}/libmysqlclient.a)
target_link_libraries (mysqlxx common ${MYSQLCLIENT_LIB} ${OPENSSL_LIBRARIES} ${Z_LIB} dl)
target_link_libraries (mysqlxx common ${MYSQLCLIENT_LIB} ${OPENSSL_LIBRARIES} ${Z_LIB} ${PLATFORM_LIBS})
add_custom_command (
OUTPUT ${MYSQLCLIENT_LIB}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/patch.sh ${STATIC_MYSQLCLIENT_LIB} ${MYSQLCLIENT_LIB}
@ -45,7 +47,7 @@ if (USE_STATIC_LIBRARIES)
add_dependencies (mysqlxx our_mysql_client)
endif ()
target_link_libraries (mysqlxx common ${MYSQLCLIENT_LIB} ${OPENSSL_LIBRARIES} ${Z_LIB} dl)
target_link_libraries (mysqlxx common ${MYSQLCLIENT_LIB} ${OPENSSL_LIBRARIES} ${Z_LIB} ${PLATFORM_LIBS})
if (ENABLE_TESTS)
add_subdirectory (src/tests)

View File

@ -8,6 +8,7 @@
#include <string>
#include <limits>
#include <common/exp10.h>
#include <common/Common.h>
#include <common/DateLUT.h>

View File

@ -4,7 +4,7 @@ target_link_libraries (iotest dbms)
add_executable (iotest_nonblock iotest_nonblock.cpp ${SRCS})
target_link_libraries (iotest_nonblock dbms)
if (NOT APPLE)
if (NOT APPLE AND NOT CMAKE_SYSTEM MATCHES "FreeBSD")
add_executable (iotest_aio iotest_aio.cpp ${SRCS})
target_link_libraries (iotest_aio dbms)
endif()

View File

@ -17,14 +17,18 @@
#include <DB/Common/Stopwatch.h>
#include <stdlib.h>
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#include <malloc.h>
#endif
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#include <linux/aio_abi.h>
#endif
#include <sys/syscall.h>
using DB::throwFromErrno;

View File

@ -3,7 +3,7 @@
#include <stdlib.h>
#include <time.h>
#include <stdlib.h>
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#include <malloc.h>
#endif
#include <poll.h>