Index: client/client_shared.h
--- client/client_shared.h.orig	2025-07-11 23:32:27.000000000 +0200
+++ client/client_shared.h	2025-07-12 13:19:22.876176000 +0200
@@ -20,6 +20,7 @@
 #define CLIENT_CONFIG_H
 
 #include <stdio.h>
+#include <sys/time.h>
 
 #ifdef WIN32
 #  include <winsock2.h>
Index: config.mk
--- config.mk.orig	2025-07-11 23:32:27.000000000 +0200
+++ config.mk	2025-07-12 13:19:22.876301000 +0200
@@ -343,15 +343,15 @@
 
 ifeq ($(WITH_WEBSOCKETS),yes)
 	BROKER_CPPFLAGS:=$(BROKER_CPPFLAGS) -DWITH_WEBSOCKETS
-	BROKER_LDADD:=$(BROKER_LDADD) -lwebsockets
+	BROKER_LDADD:=$(BROKER_LDADD) -lwebsockets -lssl -lcrypto -lz
 endif
 
 INSTALL?=install
-prefix?=/usr/local
+prefix?=${PREFIX}
 incdir?=${prefix}/include
-libdir?=${prefix}/lib${LIB_SUFFIX}
-localedir?=${prefix}/share/locale
-mandir?=${prefix}/share/man
+libdir?=${prefix}/lib
+localedir?=${PREFIX}/share/locale
+mandir?=${PREFIX}/man
 STRIP?=strip
 
 ifeq ($(WITH_STRIP),yes)
Index: lib/CMakeLists.txt
--- lib/CMakeLists.txt.orig	2025-07-11 23:32:27.000000000 +0200
+++ lib/CMakeLists.txt	2025-07-12 13:20:15.016775000 +0200
@@ -84,42 +84,6 @@
 	endif (ARES_HEADER)
 endif (WITH_SRV)
 
-add_library(libmosquitto SHARED ${C_SRC})
-set_target_properties(libmosquitto PROPERTIES
-	POSITION_INDEPENDENT_CODE 1
-)
-
-if (WITH_THREADING)
-	if(WIN32)
-		set (LIBRARIES ${LIBRARIES} PThreads4W::PThreads4W)
-	else()
-		set(THREADS_PREFER_PTHREAD_FLAG ON)
-		find_package(Threads REQUIRED)
-
-		set (LIBRARIES ${LIBRARIES} Threads::Threads)
-	endif()
-endif()
-
-target_link_libraries(libmosquitto ${LIBRARIES})
-
-set_target_properties(libmosquitto PROPERTIES
-	OUTPUT_NAME mosquitto
-	VERSION ${VERSION}
-	SOVERSION 1
-)
-
-if(UNIX AND NOT APPLE)
-	set_target_properties(libmosquitto PROPERTIES
-		LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linker.version
-		LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/linker.version"
-	)
-endif()
-
-install(TARGETS libmosquitto
-	RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
-	ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
-	LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
-
 if (WITH_STATIC_LIBRARIES)
 	add_library(libmosquitto_static STATIC ${C_SRC})
 	if (WITH_PIC)
Index: lib/cpp/CMakeLists.txt
--- lib/cpp/CMakeLists.txt.orig	2025-07-11 23:32:27.000000000 +0200
+++ lib/cpp/CMakeLists.txt	2025-07-12 13:19:24.900232000 +0200
@@ -5,20 +5,6 @@
 
 set(CPP_SRC mosquittopp.cpp mosquittopp.h)
 
-add_library(mosquittopp SHARED ${CPP_SRC})
-set_target_properties(mosquittopp PROPERTIES
-	POSITION_INDEPENDENT_CODE 1
-)
-target_link_libraries(mosquittopp libmosquitto)
-set_target_properties(mosquittopp PROPERTIES
-	VERSION ${VERSION}
-	SOVERSION 1
-)
-install(TARGETS mosquittopp
-	RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
-	ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
-	LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
-
 if (WITH_STATIC_LIBRARIES)
 	add_library(mosquittopp_static STATIC
 		${C_SRC}
Index: lib/mosquitto.c
--- lib/mosquitto.c.orig	2025-07-11 23:32:27.000000000 +0200
+++ lib/mosquitto.c	2025-07-12 13:19:24.900526000 +0200
@@ -18,6 +18,10 @@
 
 #include "config.h"
 
+#if defined(__FreeBSD__)
+#define __XSI_VISIBLE 1
+#endif
+
 #include <errno.h>
 #include <signal.h>
 #include <string.h>
Index: lib/tls_mosq.c
--- lib/tls_mosq.c.orig	2025-07-11 23:32:27.000000000 +0200
+++ lib/tls_mosq.c	2025-07-12 13:19:24.900764000 +0200
@@ -26,6 +26,7 @@
 #else
 #  include <arpa/inet.h>
 #  include <sys/socket.h>
+#  include <netinet/in.h>
 #  include <strings.h>
 #endif
 
Index: lib/tls_mosq.h
--- lib/tls_mosq.h.orig	2025-07-11 23:32:27.000000000 +0200
+++ lib/tls_mosq.h	2025-07-12 13:19:24.900940000 +0200
@@ -29,6 +29,7 @@
 
 #include <openssl/ssl.h>
 #include <openssl/engine.h>
+#include <sys/socket.h>
 
 int mosquitto__server_certificate_verify(int preverify_ok, X509_STORE_CTX *ctx);
 int mosquitto__verify_certificate_hostname(X509 *cert, const char *hostname);
Index: src/CMakeLists.txt
--- src/CMakeLists.txt.orig	2025-07-11 23:32:27.000000000 +0200
+++ src/CMakeLists.txt	2025-07-12 13:19:24.901192000 +0200
@@ -186,7 +186,11 @@
     elseif(QNX)
         set(MOSQ_LIBS ${MOSQ_LIBS} m socket)
     else(APPLE)
-        set (MOSQ_LIBS ${MOSQ_LIBS} dl m)
+		set (MOSQ_LIBS ${MOSQ_LIBS} m)
+		find_library(LIBDL dl)
+		if (LIBDL)
+			set (MOSQ_LIBS ${MOSQ_LIBS} dl)
+		endif (LIBDL)
         find_library(LIBRT rt)
         if (LIBRT)
             set (MOSQ_LIBS ${MOSQ_LIBS} rt)
@@ -200,13 +204,13 @@
 
 if (WITH_WEBSOCKETS)
 	if (STATIC_WEBSOCKETS)
-		set (MOSQ_LIBS ${MOSQ_LIBS} websockets_static)
+		set (MOSQ_LIBS ${MOSQ_LIBS} websockets ssl crypto z)
 		if (WIN32)
 			set (MOSQ_LIBS ${MOSQ_LIBS} iphlpapi)
 			link_directories(${mosquitto_SOURCE_DIR})
 		endif (WIN32)
 	else (STATIC_WEBSOCKETS)
-		set (MOSQ_LIBS ${MOSQ_LIBS} websockets_shared)
+		set (MOSQ_LIBS ${MOSQ_LIBS} websockets_shared ssl crypto z)
 	endif (STATIC_WEBSOCKETS)
 endif (WITH_WEBSOCKETS)
 
Index: src/conf.c
--- src/conf.c.orig	2025-07-11 23:32:27.000000000 +0200
+++ src/conf.c	2025-07-12 13:19:24.901982000 +0200
@@ -1336,7 +1336,7 @@
 				}else if(!strcmp(token, "include_dir")){
 					if(level == 0){
 						/* Only process include_dir from the main config file. */
-						token = strtok_r(NULL, "", &saveptr);
+						token = strtok_r(NULL, " ", &saveptr);
 						if(!token){
 							log__printf(NULL, MOSQ_LOG_ERR, "Error: Empty include_dir value in configuration.");
 							return 1;
Index: src/mosquitto.c
--- src/mosquitto.c.orig	2025-07-11 23:32:27.000000000 +0200
+++ src/mosquitto.c	2025-07-12 13:19:24.902323000 +0200
@@ -18,6 +18,11 @@
 
 #include "config.h"
 
+#if defined(__FreeBSD__)
+#define __XSI_VISIBLE 1
+#define __BSD_VISIBLE 1
+#endif
+
 #ifndef WIN32
 /* For initgroups() */
 #  include <unistd.h>
@@ -33,6 +38,7 @@
 #endif
 
 #ifndef WIN32
+#  include <time.h>
 #  include <sys/time.h>
 #endif
 
@@ -40,6 +46,8 @@
 #include <signal.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
 #ifdef WITH_SYSTEMD
 #  include <systemd/sd-daemon.h>
 #endif
Index: src/mosquitto_broker_internal.h
--- src/mosquitto_broker_internal.h.orig	2025-07-11 23:32:27.000000000 +0200
+++ src/mosquitto_broker_internal.h	2025-07-12 13:19:24.902654000 +0200
@@ -22,10 +22,12 @@
 
 #include "config.h"
 #include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
 
 #ifdef WITH_WEBSOCKETS
 #  include <libwebsockets.h>
-#  if LWS_LIBRARY_VERSION_NUMBER >= 3002000 && !defined(LWS_WITH_EXTERNAL_POLL)
+#  if LWS_LIBRARY_VERSION_NUMBER >= 3002000 && !defined(LWS_WITH_EXTERNAL_POLL) && !defined(__FreeBSD__)
 #    warning "libwebsockets is not compiled with LWS_WITH_EXTERNAL_POLL support. Websocket performance will be unusable."
 #  endif
 #endif
Index: src/signals.c
--- src/signals.c.orig	2025-07-11 23:32:27.000000000 +0200
+++ src/signals.c	2025-07-12 13:19:24.902839000 +0200
@@ -28,6 +28,8 @@
 #include <stdio.h>
 #include <stdbool.h>
 #include <signal.h>
+#include <sys/types.h>
+#include <sys/socket.h>
 
 #include "mosquitto_broker_internal.h"
 
Index: src/websockets.c
--- src/websockets.c.orig	2025-07-11 23:32:27.000000000 +0200
+++ src/websockets.c	2025-07-12 13:19:24.903134000 +0200
@@ -20,6 +20,8 @@
 
 #include "config.h"
 
+#include <sys/types.h>
+#include <sys/socket.h>
 #include <libwebsockets.h>
 #include "mosquitto_internal.h"
 #include "mosquitto_broker_internal.h"
