Index: 3rdParty/V8/CMakeLists.txt
--- 3rdParty/V8/CMakeLists.txt.orig	2018-04-11 17:16:11.000000000 +0200
+++ 3rdParty/V8/CMakeLists.txt	2018-04-12 07:38:43.021175000 +0200
@@ -226,7 +226,7 @@
   list(APPEND V8_GYP_ARGS --format ninja)
   list(APPEND V8_GYP_ARGS -S.${V8_TARGET_ARCH})
 
-  if (LINUX)
+  if (LINUX OR FREEBSD)
     set(V8_LIBRARY_DIR "${V8_LIBRARY_DIR}/obj.target/src")
     set(ICU_LIBRARY_DIR "${ICU_LIBRARY_DIR}/obj.target/third_party/icu")
   elseif (SOLARIS)
@@ -272,7 +272,7 @@
     "${PROJECT_NAME}: Libraries"
   )
 
-  list(APPEND LINK_DIRECTORIES "${NINJA_BUILD_DIR}/obj/third_party/icu")
+  list(INSERT LINK_DIRECTORIES 0 "${NINJA_BUILD_DIR}/obj/third_party/icu")
 
   set(ICU_LIBS
     "icui18n;icuuc"
@@ -510,7 +510,7 @@
   list(APPEND V8_GYP_ARGS --format make)
   list(APPEND V8_GYP_ARGS -S.${V8_TARGET_ARCH})
 
-  if (LINUX)
+  if (LINUX OR FREEBSD)
     set(V8_LIBRARY_DIR "${V8_LIBRARY_DIR}/obj.target/src")
     set(ICU_LIBRARY_DIR "${ICU_LIBRARY_DIR}/obj.target/third_party/icu")
   elseif (SOLARIS)
@@ -577,7 +577,7 @@
     "${PROJECT_NAME}: Libraries"
   )
 
-  list(APPEND LINK_DIRECTORIES "${ICU_LIBRARY_DIR}")
+  list(INSERT LINK_DIRECTORIES 0 "${ICU_LIBRARY_DIR}")
 
   set(ICU_LIBS
     "icui18n;icuuc"
Index: 3rdParty/V8/v5.7.492.77/src/base/platform/platform-freebsd.cc
--- 3rdParty/V8/v5.7.492.77/src/base/platform/platform-freebsd.cc.orig	2018-04-11 17:16:11.000000000 +0200
+++ 3rdParty/V8/v5.7.492.77/src/base/platform/platform-freebsd.cc	2018-04-12 07:38:43.021354000 +0200
@@ -8,6 +8,7 @@
 #include <pthread.h>
 #include <semaphore.h>
 #include <signal.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <sys/resource.h>
 #include <sys/time.h>
Index: 3rdParty/V8/v5.7.492.77/src/base/platform/platform-posix.cc
--- 3rdParty/V8/v5.7.492.77/src/base/platform/platform-posix.cc.orig	2018-04-11 17:16:11.000000000 +0200
+++ 3rdParty/V8/v5.7.492.77/src/base/platform/platform-posix.cc	2018-04-12 07:38:43.021566000 +0200
@@ -26,6 +26,9 @@
     defined(__NetBSD__) || defined(__OpenBSD__)
 #include <sys/sysctl.h>  // NOLINT, for sysctl
 #endif
+#if defined(__FreeBSD__)
+#include <sys/thr.h>
+#endif
 
 #ifdef __linux__
 #include <syslog.h>
@@ -40,6 +43,7 @@
 
 #include <cmath>
 #include <cstdlib>
+#include <cstdio>
 
 #include "src/base/lazy-instance.h"
 #include "src/base/macros.h"
Index: 3rdParty/V8/v5.7.492.77/src/wasm/wasm-result.cc
--- 3rdParty/V8/v5.7.492.77/src/wasm/wasm-result.cc.orig	2018-04-11 17:16:11.000000000 +0200
+++ 3rdParty/V8/v5.7.492.77/src/wasm/wasm-result.cc	2018-04-12 07:38:43.021712000 +0200
@@ -11,6 +11,8 @@
 
 #include "src/base/platform/platform.h"
 
+#include <cstdarg>
+
 namespace v8 {
 namespace internal {
 namespace wasm {
Index: 3rdParty/V8/v5.7.492.77/src/wasm/wasm-result.h
--- 3rdParty/V8/v5.7.492.77/src/wasm/wasm-result.h.orig	2018-04-11 17:16:11.000000000 +0200
+++ 3rdParty/V8/v5.7.492.77/src/wasm/wasm-result.h	2018-04-12 07:38:43.021836000 +0200
@@ -6,6 +6,7 @@
 #define V8_WASM_RESULT_H_
 
 #include <memory>
+#include <cstdarg>
 
 #include "src/base/compiler-specific.h"
 
Index: 3rdParty/rocksdb/v5.6.X/Makefile
--- 3rdParty/rocksdb/v5.6.X/Makefile.orig	2018-04-11 17:16:11.000000000 +0200
+++ 3rdParty/rocksdb/v5.6.X/Makefile	2018-04-12 07:38:43.022213000 +0200
@@ -155,15 +155,8 @@
 $(foreach path, $(missing_make_config_paths), \
 	$(warning Warning: $(path) dont exist))
 
-ifeq ($(PLATFORM), OS_AIX)
-# no debug info
-else ifneq ($(PLATFORM), IOS)
-CFLAGS += -g
-CXXFLAGS += -g
-else
 # no debug info for IOS, that will make our library big
 OPT += -DNDEBUG
-endif
 
 ifeq ($(PLATFORM), OS_AIX)
 ARFLAGS = -X64 rs
@@ -567,7 +560,7 @@
 	analyze tools tools_lib
 
 
-all: $(LIBRARY) $(BENCHMARKS) tools tools_lib test_libs $(TESTS)
+all: $(LIBRARY)
 
 static_lib: $(LIBRARY)
 
Index: 3rdParty/rocksdb/v5.6.X/port/port_posix.h
--- 3rdParty/rocksdb/v5.6.X/port/port_posix.h.orig	2018-04-11 17:16:11.000000000 +0200
+++ 3rdParty/rocksdb/v5.6.X/port/port_posix.h	2018-04-12 07:38:43.022410000 +0200
@@ -30,7 +30,7 @@
     #define PLATFORM_IS_LITTLE_ENDIAN \
         (__DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN)
   #endif
-#elif defined(OS_SOLARIS)
+#elif defined(OS_SOLARIS) || defined(__sun)
   #include <sys/isa_defs.h>
   #ifdef _LITTLE_ENDIAN
     #define PLATFORM_IS_LITTLE_ENDIAN true
@@ -44,7 +44,7 @@
   #define PLATFORM_IS_LITTLE_ENDIAN (BYTE_ORDER == LITTLE_ENDIAN)
   #include <alloca.h>
 #elif defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_NETBSD) || \
-    defined(OS_DRAGONFLYBSD) || defined(OS_ANDROID)
+    defined(OS_DRAGONFLYBSD) || defined(OS_ANDROID) || defined(__FreeBSD__)
   #include <sys/endian.h>
   #include <sys/types.h>
   #define PLATFORM_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN)
Index: 3rdParty/rocksdb/v5.6.X/tools/ldb_cmd.cc
--- 3rdParty/rocksdb/v5.6.X/tools/ldb_cmd.cc.orig	2018-04-11 17:16:11.000000000 +0200
+++ 3rdParty/rocksdb/v5.6.X/tools/ldb_cmd.cc	2018-04-12 07:38:43.022867000 +0200
@@ -465,7 +465,7 @@
       option_map_.find(option);
   if (itr != option_map_.end()) {
     try {
-#if defined(CYGWIN)
+#if 1
       value = strtol(itr->second.c_str(), 0, 10);
 #else
       value = std::stoi(itr->second);
@@ -1317,7 +1317,7 @@
   itr = options.find(ARG_MAX_KEYS);
   if (itr != options.end()) {
     try {
-#if defined(CYGWIN)
+#if 1
       max_keys_ = strtol(itr->second.c_str(), 0, 10);
 #else
       max_keys_ = std::stoi(itr->second);
@@ -2231,7 +2231,7 @@
   itr = options.find(ARG_MAX_KEYS);
   if (itr != options.end()) {
     try {
-#if defined(CYGWIN)
+#if 1
       max_keys_scanned_ = strtol(itr->second.c_str(), 0, 10);
 #else
       max_keys_scanned_ = std::stoi(itr->second);
Index: CMakeLists.txt
--- CMakeLists.txt.orig	2018-04-11 17:16:11.000000000 +0200
+++ CMakeLists.txt	2018-04-12 07:38:43.023131000 +0200
@@ -377,7 +377,7 @@
 endif ()
 
 if (CMAKE_COMPILER_IS_CLANG)
-  if (APPLE)
+  if (APPLE OR FREEBSD)
     set(BASE_CXX_FLAGS "${BASE_CXX_FLAGS} -stdlib=libc++")
     add_definitions("-Wno-deprecated-declarations")
   else ()
@@ -594,9 +594,10 @@
 ################################################################################
 
 if (NOT WINDOWS)
-  set(SYS_LIBS ${SYS_LIBS} resolv)
-
-  if (NOT DARWIN)
+  if (NOT FREEBSD)
+    set(SYS_LIBS ${SYS_LIBS} resolv)
+  endif ()
+  if (NOT DARWIN AND NOT FREEBSD)
     set(SYS_LIBS ${SYS_LIBS} rt)
   endif ()
 endif ()
@@ -663,19 +664,17 @@
     message(STATUS "Compiler type GNU: ${CMAKE_CXX_COMPILER}")
   endif ()
 
-  set(BASE_FLAGS "-Wall -Wextra -Wno-unused-parameter ${BASE_FLAGS}")
-
-  set(CMAKE_C_FLAGS                "-g"                             CACHE INTERNAL "default C compiler flags")
+  set(CMAKE_C_FLAGS                ""                               CACHE INTERNAL "default C compiler flags")
   set(CMAKE_C_FLAGS_DEBUG          "-O0 -g -D_DEBUG=1"              CACHE INTERNAL "C debug flags")
   set(CMAKE_C_FLAGS_MINSIZEREL     "-Os"                            CACHE INTERNAL "C minimal size flags")
-  set(CMAKE_C_FLAGS_RELEASE        "-O3 -fomit-frame-pointer"       CACHE INTERNAL "C release flags")
-  set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -fno-omit-frame-pointer" CACHE INTERNAL "C release with debug info flags")
+  set(CMAKE_C_FLAGS_RELEASE        "-O2 -fomit-frame-pointer"       CACHE INTERNAL "C release flags")
+  set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -fno-omit-frame-pointer" CACHE INTERNAL "C release with debug info flags")
 
-  set(CMAKE_CXX_FLAGS                "-g -Wnon-virtual-dtor"          CACHE INTERNAL "default C++ compiler flags")
+  set(CMAKE_CXX_FLAGS                "-Wnon-virtual-dtor"             CACHE INTERNAL "default C++ compiler flags")
   set(CMAKE_CXX_FLAGS_DEBUG          "-O0 -g -D_DEBUG=1"              CACHE INTERNAL "C++ debug flags")
   set(CMAKE_CXX_FLAGS_MINSIZEREL     "-Os"                            CACHE INTERNAL "C++ minimal size flags")
-  set(CMAKE_CXX_FLAGS_RELEASE        "-O3 -fomit-frame-pointer"       CACHE INTERNAL "C++ release flags")
-  set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -fno-omit-frame-pointer" CACHE INTERNAL "C++ release with debug info flags")
+  set(CMAKE_CXX_FLAGS_RELEASE        "-O2 -fomit-frame-pointer"       CACHE INTERNAL "C++ release flags")
+  set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -fno-omit-frame-pointer" CACHE INTERNAL "C++ release with debug info flags")
 
 elseif (CMAKE_COMPILER_IS_CLANG)
   if (VERBOSE)
@@ -996,6 +995,11 @@
 ## SUB-PROJECTS
 ################################################################################
 
+set(SYS_LIBS ${SYS_LIBS} crypto)
+set(SYS_LIBS ${SYS_LIBS} ncurses)
+set(SYS_LIBS ${SYS_LIBS} execinfo)
+set(SYS_LIBS ${SYS_LIBS} m)
+
 list(INSERT SYSTEM_LIBRARIES 0
   ${BT_LIBS}
   ${ZLIB_LIBS}
Index: arangod/Agency/Store.cpp
--- arangod/Agency/Store.cpp.orig	2018-04-11 17:16:11.000000000 +0200
+++ arangod/Agency/Store.cpp	2018-04-12 07:38:43.023337000 +0200
@@ -603,7 +603,7 @@
       auto ts = std::chrono::duration_cast<std::chrono::seconds>(
                     i.first.time_since_epoch())
                     .count();
-      builder.add(i.second, VPackValue(ts));
+      builder.add(i.second, VPackValue((int64_t)ts));
     }
   }
   {
Index: arangod/Aql/Condition.cpp
--- arangod/Aql/Condition.cpp.orig	2018-04-11 17:16:11.000000000 +0200
+++ arangod/Aql/Condition.cpp	2018-04-12 07:38:43.023633000 +0200
@@ -34,6 +34,8 @@
 #include "Logger/Logger.h"
 #include "Transaction/Methods.h"
 
+#include <cmath>
+
 #ifdef _WIN32
 // turn off warnings about too long type name for debug symbols blabla in MSVC
 // only...
Index: arangod/Aql/Expression.cpp
--- arangod/Aql/Expression.cpp.orig	2018-04-11 17:16:11.000000000 +0200
+++ arangod/Aql/Expression.cpp	2018-04-12 07:38:43.023920000 +0200
@@ -635,7 +635,7 @@
 
       try {
         // stoll() might throw an exception if the string is not a number
-        int64_t position = static_cast<int64_t>(std::stoll(value));
+        int64_t position = static_cast<int64_t>(strtol(value.c_str(), NULL, 10));
         return result.at(trx, position, mustDestroy, true);
       } catch (...) {
         // no number found.
Index: arangod/Aql/Functions.cpp
--- arangod/Aql/Functions.cpp.orig	2018-04-11 17:16:11.000000000 +0200
+++ arangod/Aql/Functions.cpp	2018-04-12 07:38:43.024426000 +0200
@@ -193,10 +193,10 @@
         isValid = true;
         return 0.0;
       }
-      size_t behind = 0;
-      double value = std::stod(str, &behind);
-      while (behind < str.size()) {
-        char c = str[behind];
+      char *behind = NULL;
+      double value = strtod(str.c_str(), &behind);
+      while (behind < str.c_str() + str.size()) {
+        char c = *behind;
         if (c != ' ' && c != '\t' && c != '\r' && c != '\n' && c != '\f') {
           isValid = false;
           return 0.0;
@@ -2812,7 +2812,7 @@
   AqlValue value = ExtractFunctionParameterValue(trx, parameters, 0);
   
   double input = value.toDouble(trx);
-  return NumberValue(trx, std::log2(input), true);  
+  return NumberValue(trx, log2(input), true);  
 }
 
 /// @brief function LOG10
@@ -2848,7 +2848,7 @@
   AqlValue value = ExtractFunctionParameterValue(trx, parameters, 0);
   
   double input = value.toDouble(trx);
-  return NumberValue(trx, std::exp2(input), true);  
+  return NumberValue(trx, exp2(input), true);  
 }
 
 /// @brief function SIN
Index: arangod/Aql/SortNode.cpp
--- arangod/Aql/SortNode.cpp.orig	2018-04-11 17:16:11.000000000 +0200
+++ arangod/Aql/SortNode.cpp	2018-04-12 07:38:43.024549000 +0200
@@ -196,5 +196,5 @@
   if (nrItems <= 3.0) {
     return depCost + nrItems;
   }
-  return depCost + nrItems * std::log2(static_cast<double>(nrItems));
+  return depCost + nrItems * log2(static_cast<double>(nrItems));
 }
Index: arangod/Indexes/Index.cpp
--- arangod/Indexes/Index.cpp.orig	2018-04-11 17:16:11.000000000 +0200
+++ arangod/Indexes/Index.cpp	2018-04-12 07:38:43.024755000 +0200
@@ -574,7 +574,7 @@
   // by default, no sort conditions are supported
   coveredAttributes = 0;
   if (itemsInIndex > 0) {
-    estimatedCost = itemsInIndex * std::log2(itemsInIndex);
+    estimatedCost = itemsInIndex * log2(itemsInIndex);
   } else {
     estimatedCost = 0.0;
   }
Index: arangod/RestHandler/RestAuthHandler.cpp
--- arangod/RestHandler/RestAuthHandler.cpp.orig	2018-04-11 17:16:11.000000000 +0200
+++ arangod/RestHandler/RestAuthHandler.cpp	2018-04-12 07:38:43.024883000 +0200
@@ -54,7 +54,7 @@
     VPackObjectBuilder p(&bodyBuilder);
     bodyBuilder.add("preferred_username", VPackValue(username));
     bodyBuilder.add("iss", VPackValue("arangodb"));
-    bodyBuilder.add("exp", VPackValue(exp.count()));
+    bodyBuilder.add("exp", VPackValue((int64_t)exp.count()));
   }
   AuthenticationFeature* af = AuthenticationFeature::instance();
   TRI_ASSERT(af != nullptr);
Index: arangod/RocksDBEngine/RocksDBThrottle.cpp
--- arangod/RocksDBEngine/RocksDBThrottle.cpp.orig	2018-04-11 17:16:11.000000000 +0200
+++ arangod/RocksDBEngine/RocksDBThrottle.cpp	2018-04-12 07:38:43.025056000 +0200
@@ -509,7 +509,7 @@
 /// @brief Adjust the active thread's priority to match the work
 ///  it is performing.  The routine is called HEAVILY.
 void RocksDBThrottle::AdjustThreadPriority(int Adjustment) {
-#ifndef WIN32
+#if !defined(WIN32) && !defined(__FreeBSD__)
   // initialize thread infor if this the first time the thread has ever called
   if (!gThreadPriority._baseSet) {
     pid_t tid;
Index: arangod/Scheduler/ListenTask.cpp
--- arangod/Scheduler/ListenTask.cpp.orig	2018-04-11 17:16:11.000000000 +0200
+++ arangod/Scheduler/ListenTask.cpp	2018-04-12 07:38:43.025181000 +0200
@@ -22,6 +22,11 @@
 /// @author Achim Brandt
 ////////////////////////////////////////////////////////////////////////////////
 
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
 #include "ListenTask.h"
 
 #include "Basics/MutexLocker.h"
Index: etc/arangodb3/arango-dfdb.conf.in
--- etc/arangodb3/arango-dfdb.conf.in.orig	2018-04-11 17:16:11.000000000 +0200
+++ etc/arangodb3/arango-dfdb.conf.in	2018-04-12 07:38:43.025304000 +0200
@@ -3,7 +3,7 @@
 [database]
 auto-upgrade = false
 upgrade-check = false
-directory= @LOCALSTATEDIR@/lib/arangodb3
+directory= @LOCALSTATEDIR@/arangodb
 
 [server]
 rest-server = false
@@ -18,7 +18,7 @@
 
 [javascript]
 startup-directory = @PKGDATADIR@/js
-app-path = @LOCALSTATEDIR@/lib/arangodb3-apps
+app-path = @LOCALSTATEDIR@/arangodb/apps
 script = @PKGDATADIR@/js/server/arango-dfdb.js
 v8-contexts = 1
 
Index: etc/arangodb3/arangod.conf.in
--- etc/arangodb3/arangod.conf.in.orig	2018-04-11 17:16:11.000000000 +0200
+++ etc/arangodb3/arangod.conf.in	2018-04-12 07:38:43.025424000 +0200
@@ -5,7 +5,7 @@
 # 
 
 [database]
-directory = @LOCALSTATEDIR@/lib/arangodb3
+directory = @LOCALSTATEDIR@/arangodb
 
 # maximal-journal-size = 33554432
 
@@ -49,7 +49,7 @@
 
 [javascript]
 startup-directory = @PKGDATADIR@/js
-app-path = @LOCALSTATEDIR@/lib/arangodb3-apps
+app-path = @LOCALSTATEDIR@/arangodb/apps
 # app-path = @HOMEDRIVE@/@HOMEPATH@/arangodb3/apps
 
 # number of V8 contexts available for JavaScript execution. use 0 to 
@@ -65,7 +65,7 @@
 
 [log]
 level = info
-@COMMENT_LOGFILE@file = @LOCALSTATEDIR@/log/arangodb3/arangod.log
+@COMMENT_LOGFILE@file = @LOCALSTATEDIR@/arangodb/log/arangod.log
 
 [cluster]
 
Index: lib/Basics/ArangoGlobalContext.cpp
--- lib/Basics/ArangoGlobalContext.cpp.orig	2018-04-11 17:16:11.000000000 +0200
+++ lib/Basics/ArangoGlobalContext.cpp	2018-04-12 07:53:29.081762000 +0200
@@ -143,6 +143,7 @@
 #ifndef _WIN32
 #ifndef __APPLE__
 #ifndef __GLIBC__
+#ifndef __FreeBSD__
   // Increase default stack size for libmusl:
   pthread_attr_t a;
   memset(&a, 0, sizeof(pthread_attr_t));
@@ -152,6 +153,7 @@
 #endif
 #endif
 #endif
+#endif
 
 
   // allow failing memory allocations for the global context thread (i.e. main program thread)
Index: lib/Basics/Endian.h
--- lib/Basics/Endian.h.orig	2018-04-11 17:16:11.000000000 +0200
+++ lib/Basics/Endian.h	2018-04-12 07:38:43.025614000 +0200
@@ -33,6 +33,8 @@
 #elif _WIN32
 #elif __linux__
   #include <endian.h>
+#elif defined(__FreeBSD__)
+  #include <sys/endian.h>
 #else
   #pragma messsage("unsupported os or compiler")
 #endif
@@ -59,7 +61,7 @@
 inline uint16_t hostToLittle(uint16_t in){
 #ifdef __APPLE__
   return OSSwapHostToLittleInt16(in);
-#elif __linux__
+#elif defined(__linux__) || defined(__FreeBSD__)
   return htole16(in);
 #elif _WIN32
   if(!isLittleEndian()){
@@ -72,7 +74,7 @@
 inline uint32_t hostToLittle(uint32_t in){
 #ifdef __APPLE__
   return OSSwapHostToLittleInt32(in);
-#elif __linux__
+#elif defined(__linux__) || defined(__FreeBSD__)
   return htole32(in);
 #elif _WIN32
   if(!isLittleEndian()){
@@ -85,7 +87,7 @@
 inline uint64_t hostToLittle(uint64_t in){
 #ifdef __APPLE__
   return OSSwapHostToLittleInt64(in);
-#elif __linux__
+#elif defined(__linux__) || defined(__FreeBSD__)
   return htole64(in);
 #elif _WIN32
   if(!isLittleEndian()){
@@ -101,7 +103,7 @@
 
 #ifdef __APPLE__
   tmp = OSSwapHostToLittleInt16(tmp);
-#elif __linux__
+#elif defined(__linux__) || defined(__FreeBSD__)
   tmp =  htole16(tmp);
 #elif _WIN32
   if(!isLittleEndian()){
@@ -119,7 +121,7 @@
 
 #ifdef __APPLE__
   tmp = OSSwapHostToLittleInt32(tmp);
-#elif __linux__
+#elif defined(__linux__) || defined(__FreeBSD__)
   tmp =  htole32(tmp);
 #elif _WIN32
   if(!isLittleEndian()){
@@ -137,7 +139,7 @@
 
 #ifdef __APPLE__
   tmp = OSSwapHostToLittleInt64(tmp);
-#elif __linux__
+#elif defined(__linux__) || defined(__FreeBSD__)
   tmp =  htole64(tmp);
 #elif _WIN32
   if(!isLittleEndian()){
@@ -153,7 +155,7 @@
 inline uint16_t littleToHost(uint16_t in){
 #ifdef __APPLE__
   return OSSwapLittleToHostInt16(in);
-#elif __linux__
+#elif defined(__linux__) || defined(__FreeBSD__)
   return le16toh(in);
 #elif _WIN32
   if(!isLittleEndian()){
@@ -166,7 +168,7 @@
 inline uint32_t littleToHost(uint32_t in){
 #ifdef __APPLE__
   return OSSwapLittleToHostInt32(in);
-#elif __linux__
+#elif defined(__linux__) || defined(__FreeBSD__)
   return le32toh(in);
 #elif _WIN32
   if(!isLittleEndian()){
@@ -179,7 +181,7 @@
 inline uint64_t littleToHost(uint64_t in){
 #ifdef __APPLE__
   return OSSwapLittleToHostInt64(in);
-#elif __linux__
+#elif defined(__linux__) || defined(__FreeBSD__)
   return le64toh(in);
 #elif _WIN32
   if(!isLittleEndian()){
@@ -194,7 +196,7 @@
 std::memcpy(&tmp,&in,2);
 #ifdef __APPLE__
   tmp = OSSwapLittleToHostInt16(tmp);
-#elif __linux__
+#elif defined(__linux__) || defined(__FreeBSD__)
   tmp = le16toh(tmp);
 #elif _WIN32
   if(!isLittleEndian()){
@@ -210,7 +212,7 @@
 std::memcpy(&tmp,&in,4);
 #ifdef __APPLE__
   tmp = OSSwapLittleToHostInt32(tmp);
-#elif __linux__
+#elif defined(__linux__) || defined(__FreeBSD__)
   tmp = le32toh(tmp);
 #elif _WIN32
   if(!isLittleEndian()){
@@ -226,7 +228,7 @@
 std::memcpy(&tmp,&in,8);
 #ifdef __APPLE__
   tmp = OSSwapLittleToHostInt64(tmp);
-#elif __linux__
+#elif defined(__linux__) || defined(__FreeBSD__)
   tmp = le64toh(tmp);
 #elif _WIN32
   if(!isLittleEndian()){
Index: lib/Basics/asio-helper.h
--- lib/Basics/asio-helper.h.orig	2018-04-11 17:16:11.000000000 +0200
+++ lib/Basics/asio-helper.h	2018-04-12 07:38:43.025727000 +0200
@@ -42,6 +42,7 @@
   const boost::system::error_category& unused4
     = boost::asio::error::misc_category;
 
+#if 0
   const boost::system::error_category& unused5
     = boost::system::posix_category;
 
@@ -50,6 +51,7 @@
 
   const boost::system::error_category& unused7
     = boost::system::native_ecat;
+#endif
 };
 }
 #endif
Index: lib/Basics/operating-system.h
--- lib/Basics/operating-system.h.orig	2018-04-11 17:16:11.000000000 +0200
+++ lib/Basics/operating-system.h	2018-04-12 07:38:43.025894000 +0200
@@ -440,6 +440,7 @@
 
 #define TRI_GCC_THREAD_LOCAL_STORAGE 1
 
+#define TRI_HAVE_SC_PHYS_PAGES 1
 #define TRI_HAVE_LINUX_PROC 1
 #define ARANGODB_HAVE_DOMAIN_SOCKETS 1
 #define TRI_HAVE_POSIX_MMAP 1
Index: lib/Basics/process-utils.cpp
--- lib/Basics/process-utils.cpp.orig	2018-04-11 17:16:11.000000000 +0200
+++ lib/Basics/process-utils.cpp	2018-04-12 07:38:43.026138000 +0200
@@ -23,7 +23,7 @@
 
 #include "process-utils.h"
 
-#if defined(TRI_HAVE_MACOS_MEM_STATS)
+#if defined(TRI_HAVE_MACOS_MEM_STATS) || defined (__FreeBSD__)
 #include <sys/types.h>
 #include <sys/sysctl.h>
 #endif
@@ -557,6 +557,7 @@
 }
 
 #else
+#ifdef _WIN32
 /// --------------------------------------------
 /// transform a file time to timestamp
 /// Particularities:
@@ -648,6 +649,7 @@
   return result;
 }
 #endif
+#endif
 
 ////////////////////////////////////////////////////////////////////////////////
 /// @brief returns information about the process
@@ -1435,7 +1437,7 @@
 /// @brief gets the physical memory
 ////////////////////////////////////////////////////////////////////////////////
 
-#if defined(TRI_HAVE_MACOS_MEM_STATS)
+#if defined(TRI_HAVE_MACOS_MEM_STATS) || defined(__FreeBSD__)
 
 static uint64_t GetPhysicalMemory() {
   int mib[2];
Index: lib/Basics/socket-utils.h
--- lib/Basics/socket-utils.h.orig	2018-04-11 17:16:11.000000000 +0200
+++ lib/Basics/socket-utils.h	2018-04-12 07:38:43.026265000 +0200
@@ -26,6 +26,11 @@
 
 #include "Basics/Common.h"
 
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
 #ifdef TRI_HAVE_WINSOCK2_H
 #include <WinSock2.h>
 #include <WS2tcpip.h>
Index: lib/Endpoint/EndpointIp.cpp
--- lib/Endpoint/EndpointIp.cpp.orig	2018-04-11 17:16:11.000000000 +0200
+++ lib/Endpoint/EndpointIp.cpp	2018-04-12 07:38:43.026438000 +0200
@@ -29,6 +29,10 @@
 
 #include "Endpoint/Endpoint.h"
 
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/tcp.h>
+
 using namespace arangodb;
 using namespace arangodb::basics;
 
Index: lib/Logger/LogAppenderSyslog.cpp
--- lib/Logger/LogAppenderSyslog.cpp.orig	2018-04-11 17:16:11.000000000 +0200
+++ lib/Logger/LogAppenderSyslog.cpp	2018-04-12 07:38:43.026553000 +0200
@@ -62,7 +62,7 @@
   if ('0' <= facility[0] && facility[0] <= '9') {
     value = StringUtils::int32(facility);
   } else {
-    CODE* ptr = reinterpret_cast<CODE*>(facilitynames);
+    CODE* ptr = static_cast<CODE*>((CODE *)facilitynames);
 
     while (ptr->c_name != 0) {
       if (strcmp(ptr->c_name, facility.c_str()) == 0) {
Index: lib/SimpleHttpClient/SimpleHttpClient.cpp
--- lib/SimpleHttpClient/SimpleHttpClient.cpp.orig	2018-04-11 17:16:11.000000000 +0200
+++ lib/SimpleHttpClient/SimpleHttpClient.cpp	2018-04-12 07:38:43.026735000 +0200
@@ -818,7 +818,7 @@
   uint32_t contentLength;
 
   try {
-    contentLength = static_cast<uint32_t>(std::stol(line, nullptr, 16));
+    contentLength = static_cast<uint32_t>(strtol(line.c_str(), NULL, 16));
   } catch (...) {
     setErrorMessage("found invalid Content-Length", true);
     // reset connection
