Merge branch 'enhance-bare-makefile-static-library-build' of https://github.com/Lance0312/mosquitto into Lance0312-enhance-bare-makefile-static-library-build

This commit is contained in:
Roger A. Light 2016-06-15 20:59:34 +01:00
commit 2286caaca2
5 changed files with 68 additions and 34 deletions

View File

@ -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
================

View File

@ -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
# =============================================================================

View File

@ -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

View File

@ -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 $@

32
lib/objects.mk Normal file
View File

@ -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))