From a9b7237d09804d92cd259267ec617aae980db73b Mon Sep 17 00:00:00 2001 From: Lance Chen Date: Thu, 2 Jun 2016 17:29:40 +0800 Subject: [PATCH 1/3] Install/Uninstall the C static library Symbol stripping is done explicitly with strip command, since stripping with install command removes too many symbols, making the result library unusable. Signed-off-by: Lance Chen --- lib/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Makefile b/lib/Makefile index 598d1ddf..f49076f3 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -39,6 +39,8 @@ install : all $(INSTALL) -d ${DESTDIR}$(prefix)/lib${LIB_SUFFIX}/ $(INSTALL) -s --strip-program=${CROSS_COMPILE}${STRIP} libmosquitto.so.${SOVERSION} ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquitto.so.${SOVERSION} ln -sf libmosquitto.so.${SOVERSION} ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquitto.so + $(INSTALL) libmosquitto.a ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquitto.a + ${CROSS_COMPILE}${STRIP} -g --strip-unneeded ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquitto.a $(INSTALL) -d ${DESTDIR}${prefix}/include/ $(INSTALL) mosquitto.h ${DESTDIR}${prefix}/include/mosquitto.h $(MAKE) -C cpp install @@ -46,6 +48,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 From 4b4817c3f070738a2eaaf9ca4caaa55b7ace5037 Mon Sep 17 00:00:00 2001 From: Lance Chen Date: Thu, 2 Jun 2016 17:35:01 +0800 Subject: [PATCH 2/3] Build the CPP static library with bare Makefiles In order to make the CPP static library include all objects from the C static library, the list of objects (MOSQ_OBJS) is isolated into objects.mk to be used for building the C and CPP static libraries. Signed-off-by: Lance Chen --- lib/Makefile | 35 +++-------------------------------- lib/cpp/Makefile | 11 +++++++++-- lib/objects.mk | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 lib/objects.mk diff --git a/lib/Makefile b/lib/Makefile index f49076f3..d2d6643c 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,37 +1,8 @@ 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 : libmosquitto.so.${SOVERSION} libmosquitto.a $(MAKE) -C cpp @@ -57,10 +28,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 8b627d32..c8ce0050 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,32 @@ endif .PHONY : clean install -all : libmosquittopp.so.${SOVERSION} +all : libmosquittopp.so.${SOVERSION} libmosquittopp.a install : all $(INSTALL) -d ${DESTDIR}$(prefix)/lib${LIB_SUFFIX}/ $(INSTALL) -s --strip-program=${CROSS_COMPILE}${STRIP} libmosquittopp.so.${SOVERSION} ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquittopp.so.${SOVERSION} ln -sf libmosquittopp.so.${SOVERSION} ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquittopp.so + $(INSTALL) libmosquittopp.a ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquittopp.a + ${CROSS_COMPILE}${STRIP} -g --strip-unneeded ${DESTDIR}${prefix}/lib${LIB_SUFFIX}/libmosquittopp.a $(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)) From 5ccd0dbb80845acbb9025d0c4aef3952180e449c Mon Sep 17 00:00:00 2001 From: Lance Chen Date: Fri, 3 Jun 2016 01:45:43 +0800 Subject: [PATCH 3/3] Add an build option to control building static libraries or not The option WITH_STATIC_LIBRARIES is default to yes Signed-off-by: Lance Chen --- config.mk | 3 +++ lib/Makefile | 10 +++++++++- lib/cpp/Makefile | 10 +++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/config.mk b/config.mk index a1699050..7375c90d 100644 --- a/config.mk +++ b/config.mk @@ -80,6 +80,9 @@ WITH_DOCS:=yes # Build with client support for SOCK5 proxy. WITH_SOCKS:=yes +# Build static libraries +WITH_STATIC_LIBRARIES:=yes + # ============================================================================= # End of user configuration # ============================================================================= diff --git a/lib/Makefile b/lib/Makefile index d2d6643c..373a0b50 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -3,15 +3,23 @@ include objects.mk .PHONY : really clean install -all : libmosquitto.so.${SOVERSION} libmosquitto.a +ALL_DEPS=libmosquitto.so.${SOVERSION} + +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) -s --strip-program=${CROSS_COMPILE}${STRIP} 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 diff --git a/lib/cpp/Makefile b/lib/cpp/Makefile index c8ce0050..cf0df7a8 100644 --- a/lib/cpp/Makefile +++ b/lib/cpp/Makefile @@ -7,14 +7,22 @@ endif .PHONY : clean install -all : libmosquittopp.so.${SOVERSION} libmosquittopp.a +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) -s --strip-program=${CROSS_COMPILE}${STRIP} 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