diff --git a/ChangeLog.txt b/ChangeLog.txt index 84bd46e8..535e268f 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -51,6 +51,8 @@ Client: Build: - Add WITH_STRIP option (defaulting to "no") that when set to "yes" will strip executables and shared libraries when installing. +- Add WITH_STATIC_LIBRARIES (defaulting to "no") that when set to "yes" will + buld and install static versions of the client libraries. 1.4.7 - 20151221 ================ diff --git a/config.mk b/config.mk index 5ed1dbe7..88483a9e 100644 --- a/config.mk +++ b/config.mk @@ -83,6 +83,9 @@ WITH_SOCKS:=yes # Strip executables and shared libraries on install. WITH_STRIP:=no +# Build static libraries +WITH_STATIC_LIBRARIES:=no + # ============================================================================= # End of user configuration # ============================================================================= diff --git a/lib/Makefile b/lib/Makefile index eef87b95..22f4a6d1 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,44 +1,25 @@ include ../config.mk +include objects.mk .PHONY : really clean install -MOSQ_OBJS=mosquitto.o \ - handle_connack.o \ - handle_ping.o \ - handle_pubackcomp.o \ - handle_publish.o \ - handle_pubrec.o \ - handle_pubrel.o \ - handle_suback.o \ - handle_unsuback.o \ - helpers.o \ - logging_mosq.o \ - memory_mosq.o \ - messages_mosq.o \ - net_mosq.o \ - packet_mosq.o \ - read_handle.o \ - send_connect.o \ - send_disconnect.o \ - send_mosq.o \ - send_publish.o \ - send_subscribe.o \ - send_unsubscribe.o \ - socks_mosq.o \ - srv_mosq.o \ - thread_mosq.o \ - time_mosq.o \ - tls_mosq.o \ - util_mosq.o \ - will_mosq.o +ALL_DEPS=libmosquitto.so.${SOVERSION} -all : libmosquitto.so.${SOVERSION} libmosquitto.a +ifeq ($(WITH_STATIC_LIBRARIES),yes) + ALL_DEPS+=libmosquitto.a +endif + +all : ${ALL_DEPS} $(MAKE) -C cpp install : all $(INSTALL) -d ${DESTDIR}$(prefix)/lib${LIB_SUFFIX}/ $(INSTALL) ${STRIP_OPTS} libmosquitto.so.${SOVERSION} ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquitto.so.${SOVERSION} ln -sf libmosquitto.so.${SOVERSION} ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquitto.so +ifeq ($(WITH_STATIC_LIBRARIES),yes) + $(INSTALL) libmosquitto.a ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquitto.a + ${CROSS_COMPILE}${STRIP} -g --strip-unneeded ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquitto.a +endif $(INSTALL) -d ${DESTDIR}${prefix}/include/ $(INSTALL) mosquitto.h ${DESTDIR}${prefix}/include/mosquitto.h $(MAKE) -C cpp install @@ -46,6 +27,7 @@ install : all uninstall : -rm -f ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquitto.so.${SOVERSION} -rm -f ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquitto.so + -rm -f ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquitto.a -rm -f ${DESTDIR}${prefix}/include/mosquitto.h reallyclean : clean @@ -54,10 +36,10 @@ clean : -rm -f *.o libmosquitto.so.${SOVERSION} libmosquitto.so libmosquitto.a $(MAKE) -C cpp clean -libmosquitto.so.${SOVERSION} : ${MOSQ_OBJS} +libmosquitto.so.${SOVERSION} : ${MOSQ_C_OBJS} ${CROSS_COMPILE}$(CC) -shared $(LIB_LDFLAGS) $^ -o $@ ${LIB_LIBS} -libmosquitto.a : ${MOSQ_OBJS} +libmosquitto.a : ${MOSQ_C_OBJS} ${CROSS_COMPILE}$(AR) cr $@ $^ mosquitto.o : mosquitto.c mosquitto.h diff --git a/lib/cpp/Makefile b/lib/cpp/Makefile index 9f521358..28b0e5e5 100644 --- a/lib/cpp/Makefile +++ b/lib/cpp/Makefile @@ -1,4 +1,5 @@ include ../../config.mk +include ../objects.mk ifneq ($(UNAME),SunOS) LIB_LDFLAGS:=$(LDFLAGS) -Wl,-soname,libmosquittopp.so.${SOVERSION} @@ -6,26 +7,40 @@ endif .PHONY : clean install -all : libmosquittopp.so.${SOVERSION} +ALL_DEPS=libmosquittopp.so.${SOVERSION} + +ifeq ($(WITH_STATIC_LIBRARIES),yes) + ALL_DEPS+=libmosquittopp.a +endif + +all : ${ALL_DEPS} install : all $(INSTALL) -d ${DESTDIR}$(prefix)/lib${LIB_SUFFIX}/ $(INSTALL) ${STRIP_OPTS} libmosquittopp.so.${SOVERSION} ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquittopp.so.${SOVERSION} ln -sf libmosquittopp.so.${SOVERSION} ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquittopp.so +ifeq ($(WITH_STATIC_LIBRARIES),yes) + $(INSTALL) libmosquittopp.a ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquittopp.a + ${CROSS_COMPILE}${STRIP} -g --strip-unneeded ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquittopp.a +endif $(INSTALL) -d ${DESTDIR}${prefix}/include/ $(INSTALL) mosquittopp.h ${DESTDIR}${prefix}/include/mosquittopp.h uninstall : -rm -f ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquittopp.so.${SOVERSION} -rm -f ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquittopp.so + -rm -f ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquittopp.a -rm -f ${DESTDIR}${prefix}/include/mosquittopp.h clean : - -rm -f *.o libmosquittopp.so.${SOVERSION} + -rm -f *.o libmosquittopp.so.${SOVERSION} libmosquittopp.a libmosquittopp.so.${SOVERSION} : mosquittopp.o ${CROSS_COMPILE}$(CXX) -shared $(LIB_LDFLAGS) $< -o $@ ../libmosquitto.so.${SOVERSION} +libmosquittopp.a : mosquittopp.o ${MOSQ_C_OBJS} + ${CROSS_COMPILE}$(AR) cr $@ $^ + mosquittopp.o : mosquittopp.cpp mosquittopp.h ${CROSS_COMPILE}$(CXX) $(LIB_CXXFLAGS) -c $< -o $@ diff --git a/lib/objects.mk b/lib/objects.mk new file mode 100644 index 00000000..734865cc --- /dev/null +++ b/lib/objects.mk @@ -0,0 +1,32 @@ +MOSQ_C_OBJ_NAMES=mosquitto.o \ + handle_connack.o \ + handle_ping.o \ + handle_pubackcomp.o \ + handle_publish.o \ + handle_pubrec.o \ + handle_pubrel.o \ + handle_suback.o \ + handle_unsuback.o \ + helpers.o \ + logging_mosq.o \ + memory_mosq.o \ + messages_mosq.o \ + net_mosq.o \ + packet_mosq.o \ + read_handle.o \ + send_connect.o \ + send_disconnect.o \ + send_mosq.o \ + send_publish.o \ + send_subscribe.o \ + send_unsubscribe.o \ + socks_mosq.o \ + srv_mosq.o \ + thread_mosq.o \ + time_mosq.o \ + tls_mosq.o \ + util_mosq.o \ + will_mosq.o + +CURDIR=$(dir $(lastword $(MAKEFILE_LIST))) +MOSQ_C_OBJS=$(addprefix $(CURDIR), $(MOSQ_C_OBJ_NAMES))