From 28e3495012c21f1053cccd40efa2ced5abd4c76d Mon Sep 17 00:00:00 2001 From: Andreas Kempf Date: Mon, 16 May 2022 08:34:16 +0200 Subject: [PATCH 1/2] Enable building on AIX The AIX operating system by IBM does not provide the getifaddrs function and requires a custom linker script syntax. This commit allows for a basic GCC build on AIX 7.2. The build was tested using the command lines make CC=gcc WITH_CJSON=no WITH_DOCS=no WITH_STATIC_LIBRARIES=yes and CC=gcc cmake -DDOCUMENTATION=no At this point, the persistence test suite seems to fail. The library, as well as the mosquitto_sub and mosquitto_pub executables were tested and appear to be functional. Signed-off-by: Andreas Kempf --- config.h | 2 ++ config.mk | 12 +++++++++++- lib/cpp/Makefile | 4 +++- lib/socks_mosq.c | 2 +- man/mosquitto.conf.5.xml | 2 +- src/CMakeLists.txt | 1 + src/context.c | 2 +- src/linker-aix.syms | 34 ++++++++++++++++++++++++++++++++++ src/net.c | 6 ++++-- 9 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 src/linker-aix.syms diff --git a/config.h b/config.h index 83d4adb0..15601117 100644 --- a/config.h +++ b/config.h @@ -14,6 +14,8 @@ # define _XOPEN_SOURCE 600 # define __BSD_VISIBLE 1 # define HAVE_NETINET_IN_H +#elif defined(_AIX) +# define HAVE_NETINET_IN_H #else # define _XOPEN_SOURCE 700 # define _DEFAULT_SOURCE 1 diff --git a/config.mk b/config.mk index 345474ae..84a80197 100644 --- a/config.mk +++ b/config.mk @@ -210,6 +210,12 @@ ifeq ($(UNAME),Linux) LIB_LIBADD:=$(LIB_LIBADD) -lrt endif +ifeq ($(UNAME),AIX) + BROKER_LDFLAGS:=$(BROKER_LDFLAGS) -Wl,-bE:linker-aix.syms +# Allow library path override using LIBPATH environment variable + CLIENT_LDFLAGS:=$(CLIENT_LDFLAGS) -Wl,-bnoipath +endif + ifeq ($(WITH_SHARED_LIBRARIES),yes) CLIENT_LDADD:=${CLIENT_LDADD} ${R}/lib/libmosquitto.so.${SOVERSION} endif @@ -237,10 +243,14 @@ else LIB_CXXFLAGS:=$(LIB_CXXFLAGS) -fPIC endif -ifneq ($(UNAME),SunOS) +ifneq ($(and $(findstring $(UNAME),SunOS), $(findstring $(UNAME),AIX)),) LIB_LDFLAGS:=$(LIB_LDFLAGS) -Wl,--version-script=linker.version -Wl,-soname,libmosquitto.so.$(SOVERSION) endif +ifeq ($(UNAME),AIX) + PLUGIN_LDFLAGS:=$(PLUGIN_LDFLAGS) -Wl,-G +endif + ifeq ($(UNAME),QNX) BROKER_LDADD:=$(BROKER_LDADD) -lsocket LIB_LIBADD:=$(LIB_LIBADD) -lsocket diff --git a/lib/cpp/Makefile b/lib/cpp/Makefile index 162bc25b..0580019c 100644 --- a/lib/cpp/Makefile +++ b/lib/cpp/Makefile @@ -1,7 +1,7 @@ R=../.. include ${R}/config.mk -ifneq ($(UNAME),SunOS) +ifneq ($(and $(findstring $(UNAME),SunOS), $(findstring $(UNAME),AIX)),) LIB_LDFLAGS:=$(LDFLAGS) -Wl,-soname,libmosquittopp.so.${SOVERSION} endif @@ -21,7 +21,9 @@ install : all ln -sf libmosquittopp.so.${SOVERSION} "${DESTDIR}${libdir}/libmosquittopp.so" ifeq ($(WITH_STATIC_LIBRARIES),yes) $(INSTALL) libmosquittopp.a "${DESTDIR}${libdir}/libmosquittopp.a" +ifneq ($(UNAME),AIX) ${CROSS_COMPILE}${STRIP} -g --strip-unneeded "${DESTDIR}${libdir}/libmosquittopp.a" +endif endif $(INSTALL) -d "${DESTDIR}${incdir}/" $(INSTALL) ${R}/include/mosquittopp.h "${DESTDIR}${incdir}/mosquittopp.h" diff --git a/lib/socks_mosq.c b/lib/socks_mosq.c index b50c2d51..6f93ede4 100644 --- a/lib/socks_mosq.c +++ b/lib/socks_mosq.c @@ -30,7 +30,7 @@ Contributors: #else # include #endif -#if defined(__FreeBSD__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(_AIX) # include # include #endif diff --git a/man/mosquitto.conf.5.xml b/man/mosquitto.conf.5.xml index 9878e8a6..943413fc 100644 --- a/man/mosquitto.conf.5.xml +++ b/man/mosquitto.conf.5.xml @@ -1205,7 +1205,7 @@ accept_protocol_versions 3, 4 address/host part of the , then will take priority. - This option is not available on Windows. + This option is not available on Windows and AIX. Not reloaded on reload signal. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 250bcfd5..5d414e17 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -261,6 +261,7 @@ if(UNIX) set_target_properties(mosquitto PROPERTIES LINK_FLAGS "-Wl,-exported_symbols_list -Wl,${mosquitto_SOURCE_DIR}/src/linker-macosx.syms" ) + elseif (${CMAKE_SYSTEM_NAME} MATCHES "AIX") else() set_target_properties(mosquitto PROPERTIES LINK_FLAGS "-Wl,-dynamic-list=${mosquitto_SOURCE_DIR}/src/linker.syms" diff --git a/src/context.c b/src/context.c index 9d3a07ec..622e5711 100644 --- a/src/context.c +++ b/src/context.c @@ -20,7 +20,7 @@ Contributors: #include #include -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(_AIX) #include #endif diff --git a/src/linker-aix.syms b/src/linker-aix.syms new file mode 100644 index 00000000..f8a21537 --- /dev/null +++ b/src/linker-aix.syms @@ -0,0 +1,34 @@ +mosquitto_broker_publish +mosquitto_broker_publish_copy +mosquitto_callback_register +mosquitto_callback_unregister +mosquitto_calloc +mosquitto_client_address +mosquitto_client_certificate +mosquitto_client_clean_session +mosquitto_client_id +mosquitto_client_keepalive +mosquitto_client_protocol +mosquitto_client_protocol_version +mosquitto_client_sub_count +mosquitto_client_username +mosquitto_free +mosquitto_kick_client_by_clientid +mosquitto_kick_client_by_username +mosquitto_log_printf +mosquitto_malloc +mosquitto_property_add_binary +mosquitto_property_add_byte +mosquitto_property_add_int16 +mosquitto_property_add_int32 +mosquitto_property_add_string +mosquitto_property_add_string_pair +mosquitto_property_add_varint +mosquitto_property_free_all +mosquitto_pub_topic_check +mosquitto_realloc +mosquitto_set_username +mosquitto_strdup +mosquitto_sub_topic_check +mosquitto_topic_matches_sub +mosquitto_validate_utf8 diff --git a/src/net.c b/src/net.c index cb75ce9b..0c783a1d 100644 --- a/src/net.c +++ b/src/net.c @@ -24,7 +24,9 @@ Contributors: #include #include #include +#ifndef _AIX #include +#endif #else #include #include @@ -651,7 +653,7 @@ int net__tls_load_verify(struct mosquitto__listener *listener) } -#ifndef WIN32 +#if !defined(WIN32) && !defined(_AIX) static int net__bind_interface(struct mosquitto__listener *listener, struct addrinfo *rp) { /* @@ -791,7 +793,7 @@ static int net__socket_listen_tcp(struct mosquitto__listener *listener) return 1; } -#ifndef WIN32 +#if !defined(WIN32) && !defined(_AIX) if(listener->bind_interface){ /* It might be possible that an interface does not support all relevant sa_families. * We should successfully find at least one. */ From a6d1f7b4d008ff3e4df5d051d56aa88c2b2e4758 Mon Sep 17 00:00:00 2001 From: Andreas Kempf Date: Mon, 16 May 2022 11:23:56 +0200 Subject: [PATCH 2/2] Make plugin build dependent on WITH_CJSON Signed-off-by: Andreas Kempf --- plugins/persist-sqlite/Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/persist-sqlite/Makefile b/plugins/persist-sqlite/Makefile index 41ad7958..104574c6 100644 --- a/plugins/persist-sqlite/Makefile +++ b/plugins/persist-sqlite/Makefile @@ -23,6 +23,12 @@ else ALL_DEPS:= endif +ifeq ($(WITH_CJSON),yes) +ALL_DEPS:=$(ALL_DEPS) +else +ALL_DEPS:= +endif + all : ${ALL_DEPS} binary : ${PLUGIN_NAME}.so @@ -65,9 +71,11 @@ test: install: all ifeq ($(WITH_SQLITE),yes) +ifeq ($(WITH_CJSON),yes) $(INSTALL) -d "${DESTDIR}$(libdir)" $(INSTALL) ${STRIP_OPTS} ${PLUGIN_NAME}.so "${DESTDIR}${libdir}/${PLUGIN_NAME}.so" endif +endif uninstall : -rm -f "${DESTDIR}${libdir}/${PLUGIN_NAME}.so"