Skip to content

Commit

Permalink
Generate static library that includes available static dependencies
Browse files Browse the repository at this point in the history
* Keep track of what dependencies are only available dynamically
* Rename xxhash file to avoid object collission with OpenSSL
  • Loading branch information
edenhill committed Mar 27, 2020
1 parent 71a9d85 commit 86461c0
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 23 deletions.
2 changes: 1 addition & 1 deletion LICENSE.lz4
@@ -1,4 +1,4 @@
src/xxhash.[ch] src/lz4*.[ch]: git@github.com:lz4/lz4.git e2827775ee80d2ef985858727575df31fc60f1f3
src/rdxxhash.[ch] src/lz4*.[ch]: git@github.com:lz4/lz4.git e2827775ee80d2ef985858727575df31fc60f1f3

LZ4 Library
Copyright (c) 2011-2016, Yann Collet
Expand Down
2 changes: 1 addition & 1 deletion LICENSES.txt
Expand Up @@ -114,7 +114,7 @@ THE SOFTWARE

LICENSE.lz4
--------------------------------------------------------------
src/xxhash.[ch] src/lz4*.[ch]: git@github.com:lz4/lz4.git e2827775ee80d2ef985858727575df31fc60f1f3
src/rdxxhash.[ch] src/lz4*.[ch]: git@github.com:lz4/lz4.git e2827775ee80d2ef985858727575df31fc60f1f3

LZ4 Library
Copyright (c) 2011-2016, Yann Collet
Expand Down
2 changes: 1 addition & 1 deletion debian/copyright
Expand Up @@ -79,7 +79,7 @@ License: BSD-3-clause
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Files: src/xxhash.h src/xxhash.c
Files: src/rdxxhash.h src/rdxxhash.c
Copyright: 2012-2014, Yann Collet
License: BSD-2-clause

Expand Down
51 changes: 41 additions & 10 deletions mklove/Makefile.base
Expand Up @@ -82,7 +82,7 @@ mklove-check:
$(CXX) -MD -MP $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@


lib: $(LIBFILENAME) $(LIBNAME).a $(LIBFILENAMELINK) lib-gen-pkg-config
lib: $(LIBFILENAME) $(LIBNAME).a $(LIBNAME)-static.a $(LIBFILENAMELINK) lib-gen-pkg-config

$(LIBNAME).lds: #overridable

Expand All @@ -94,6 +94,35 @@ $(LIBNAME).a: $(OBJS)
@printf "$(MKL_YELLOW)Creating static library $@$(MKL_CLR_RESET)\n"
$(AR) rcs$(ARFLAGS) $@ $(OBJS)

ifeq ($(MKL_NO_SELFCONTAINED_STATIC_LIB),y)
$(LIBNAME)-static.a:
else
$(LIBNAME)-static.a: $(LIBNAME).a
ifneq ($(MKL_STATIC_LIBS),)
@printf "$(MKL_YELLOW)Creating self-contained static library $@$(MKL_CLR_RESET)\n"
ifeq ($(HAS_LIBTOOL_STATIC),y)
$(LIBTOOL) -static -o $@ - $(LIBNAME).a $(MKL_STATIC_LIBS)
else
(_tmp=$$(mktemp arstaticXXXXXX) ; \
echo "CREATE $@" > $$_tmp ; \
for _f in $(LIBNAME).a $(MKL_STATIC_LIBS) ; do \
echo "ADDLIB $$_f" >> $$_tmp ; \
done ; \
echo "SAVE" >> $$_tmp ; \
echo "END" >> $$_tmp ; \
cat $$_tmp ; \
ar -M < $$_tmp || exit 1 ; \
rm $$_tmp)
endif
ifneq ($(MKL_DYNAMIC_LIBS),)
@printf "$(MKL_RED)WARNING:$(MKL_YELLOW) $@: The following libraries were not available as static libraries and need to be linked dynamically: $(MKL_DYNAMIC_LIBS)$(MKL_CLR_RESET)\n"
endif
else
@printf "$(MKL_RED)WARNING:$(MKL_YELLOW) $@: Not creating self-contained static library $@: no static libraries available/enabled$(MKL_CLR_RESET)\n"
endif
endif


$(LIBFILENAMELINK): $(LIBFILENAME)
@printf "$(MKL_YELLOW)Creating $@ symlink$(MKL_CLR_RESET)\n"
rm -f "$@" && ln -s "$^" "$@"
Expand Down Expand Up @@ -125,7 +154,7 @@ Name: $(LIBNAME)-static
Description: $(MKL_APP_DESC_ONELINE) (static)
Version: $(MKL_APP_VERSION)
Cflags: -I$${includedir}
Libs: -L$${libdir} $${libdir}/$(LIBNAME).a $(LIBS)
Libs: -L$${libdir} $${libdir}/$(LIBNAME)-static.a $(MKL_DYNAMIC_LIBS)
endef

export _PKG_CONFIG_STATIC_DEF
Expand All @@ -134,7 +163,7 @@ $(LIBNAME0).pc: $(TOPDIR)/Makefile.config
@printf "$(MKL_YELLOW)Generating pkg-config file $@$(MKL_CLR_RESET)\n"
@echo "$$_PKG_CONFIG_DEF" > $@

$(LIBNAME0)-static.pc: $(TOPDIR)/Makefile.config
$(LIBNAME0)-static.pc: $(TOPDIR)/Makefile.config $(LIBNAME)-static.a
@printf "$(MKL_YELLOW)Generating pkg-config file $@$(MKL_CLR_RESET)\n"
@echo "$$_PKG_CONFIG_STATIC_DEF" > $@

Expand Down Expand Up @@ -184,26 +213,28 @@ copyright-check:

lib-install:
@printf "$(MKL_YELLOW)Install $(LIBNAME) to $$DESTDIR$(prefix)$(MKL_CLR_RESET)\n"
$(INSTALL) -d $$DESTDIR$(includedir)/$(PKGNAME) && \
$(INSTALL) -d $$DESTDIR$(libdir) && \
$(INSTALL) $(HDRS) $$DESTDIR$(includedir)/$(PKGNAME) && \
$(INSTALL) $(LIBNAME).a $$DESTDIR$(libdir) && \
$(INSTALL) $(LIBFILENAME) $$DESTDIR$(libdir) && \
$(INSTALL) -d $$DESTDIR$(includedir)/$(PKGNAME)
$(INSTALL) -d $$DESTDIR$(libdir)
$(INSTALL) $(HDRS) $$DESTDIR$(includedir)/$(PKGNAME)
$(INSTALL) $(LIBNAME).a $$DESTDIR$(libdir)
[ ! -f $(LIBNAME)-static.a ] || $(INSTALL) $(LIBNAME)-static.a $$DESTDIR$(libdir)
$(INSTALL) $(LIBFILENAME) $$DESTDIR$(libdir)
[ -f "$(LIBNAME0).pc" ] && ( \
$(INSTALL) -d $$DESTDIR$(pkgconfigdir) && \
$(INSTALL) -m 0644 $(LIBNAME0).pc $$DESTDIR$(pkgconfigdir) \
) && \
)
[ -f "$(LIBNAME0)-static.pc" ] && ( \
$(INSTALL) -d $$DESTDIR$(pkgconfigdir) && \
$(INSTALL) -m 0644 $(LIBNAME0)-static.pc $$DESTDIR$(pkgconfigdir) \
) && \
)
(cd $$DESTDIR$(libdir) && ln -sf $(LIBFILENAME) $(LIBFILENAMELINK))

lib-uninstall:
@printf "$(MKL_YELLOW)Uninstall $(LIBNAME) from $$DESTDIR$(prefix)$(MKL_CLR_RESET)\n"
for hdr in $(HDRS) ; do \
rm -f $$DESTDIR$(includedir)/$(PKGNAME)/$$hdr ; done
rm -f $$DESTDIR$(libdir)/$(LIBNAME).a
rm -f $$DESTDIR$(libdir)/$(LIBNAME)-static.a
rm -f $$DESTDIR$(libdir)/$(LIBFILENAME)
rm -f $$DESTDIR$(libdir)/$(LIBFILENAMELINK)
rmdir $$DESTDIR$(includedir)/$(PKGNAME) || true
Expand Down
15 changes: 14 additions & 1 deletion mklove/modules/configure.base
Expand Up @@ -796,6 +796,19 @@ function mkl_generate_late_vars {
# Generate output files.
# Must be called following a succesful configure run.
function mkl_generate {

# Generate MKL_STATIC_LIBS and MKL_DYNAMIC_LIBS from LIBS
local arg=
for arg in $LIBS ; do
if [[ $arg == -l* ]]; then
mkl_mkvar_append "" MKL_DYNAMIC_LIBS $arg
elif [[ $arg == *.a ]]; then
mkl_mkvar_append "" MKL_STATIC_LIBS $arg
else
mkl_dbg "Ignoring arg $arg from LIBS while building STATIC and DYNAMIC lists"
fi
done

local mf=
for mf in $MKL_GENERATORS ; do
MKL_MODULE=${mf%:*}
Expand Down Expand Up @@ -1366,7 +1379,7 @@ function mkl_link_check0 {
echo "#include <stdio.h>
int main () { FILE *fp = stderr; return fp ? 0 : 0; }" > ${srcfile}.c

local cmd="${CC} $(mkl_mkvar_get CFLAGS) $(mkl_mkvar_get LDFLAGS) -c ${srcfile}.c -o ${srcfile}_out $libs";
local cmd="${CC} $(mkl_mkvar_get CFLAGS) $(mkl_mkvar_get LDFLAGS) ${srcfile}.c -o ${srcfile}_out $libs";
mkl_dbg "Link check for $1: $cmd"

local output
Expand Down
4 changes: 3 additions & 1 deletion mklove/modules/configure.cc
Expand Up @@ -57,7 +57,7 @@ function checks {

# Provide prefix and checks for various other build tools.
local t=
for t in LD:ld NM:nm OBJDUMP:objdump STRIP:strip ; do
for t in LD:ld NM:nm OBJDUMP:objdump STRIP:strip LIBTOOL:libtool ; do
local tenv=${t%:*}
t=${t#*:}
local tval="${!tenv}"
Expand Down Expand Up @@ -154,6 +154,8 @@ function checks {
# OSX linker can't enable/disable static linking so we'll
# need to find the .a through STATIC_LIB_libname env var
mkl_mkvar_set staticlinking HAS_LDFLAGS_STATIC n
# libtool -static supported
mkl_mkvar_set staticlinking HAS_LIBTOOL_STATIC y
fi
fi
}
Expand Down
1 change: 1 addition & 0 deletions packaging/rpm/librdkafka.spec
Expand Up @@ -86,6 +86,7 @@ rm -rf %{buildroot}
%{_includedir}/librdkafka
%defattr(444,root,root)
%{_libdir}/librdkafka.a
%{_libdir}/librdkafka-static.a
%{_libdir}/librdkafka.so
%{_libdir}/librdkafka++.a
%{_libdir}/librdkafka++.so
Expand Down
2 changes: 1 addition & 1 deletion src-cpp/Makefile
Expand Up @@ -15,7 +15,7 @@ OBJS= $(CXXSRCS:%.cpp=%.o)

all: lib check


MKL_NO_SELFCONTAINED_STATIC_LIB=y
include ../mklove/Makefile.base

# No linker script/symbol hiding for C++ library
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Expand Up @@ -61,7 +61,7 @@ set(
snappy.c
tinycthread.c
tinycthread_extra.c
xxhash.c
rdxxhash.c
)

if(WITH_SSL)
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Expand Up @@ -18,7 +18,7 @@ SRCS_$(WITH_ZSTD) += rdkafka_zstd.c
SRCS_$(WITH_HDRHISTOGRAM) += rdhdrhistogram.c
SRCS_$(WITH_SSL) += rdkafka_ssl.c

SRCS_LZ4 = xxhash.c
SRCS_LZ4 = rdxxhash.c
ifneq ($(WITH_LZ4_EXT), y)
# Use built-in liblz4
SRCS_LZ4 += lz4.c lz4frame.c lz4hc.c
Expand Down
2 changes: 1 addition & 1 deletion src/lz4frame.c
Expand Up @@ -94,7 +94,7 @@
#define LZ4_HC_STATIC_LINKING_ONLY
#include "lz4hc.h"
#define XXH_STATIC_LINKING_ONLY
#include "xxhash.h"
#include "rdxxhash.h"


/*-************************************
Expand Down
2 changes: 1 addition & 1 deletion src/rdkafka_lz4.c
Expand Up @@ -33,7 +33,7 @@
#else
#include "lz4frame.h"
#endif
#include "xxhash.h"
#include "rdxxhash.h"

#include "rdbuf.h"

Expand Down
2 changes: 1 addition & 1 deletion src/xxhash.c → src/rdxxhash.c
Expand Up @@ -114,7 +114,7 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcp
#include <assert.h> /* assert */

#define XXH_STATIC_LINKING_ONLY
#include "xxhash.h"
#include "rdxxhash.h"


/* *************************************
Expand Down
2 changes: 1 addition & 1 deletion src/xxhash.h → src/rdxxhash.h
Expand Up @@ -315,7 +315,7 @@ struct XXH64_state_s {


#if defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API)
# include "xxhash.c" /* include xxhash function bodies as `static`, for inlining */
# include "rdxxhash.c" /* include xxhash function bodies as `static`, for inlining */
#endif

#endif /* XXH_STATIC_LINKING_ONLY */
Expand Down
2 changes: 1 addition & 1 deletion win32/librdkafka.vcxproj
Expand Up @@ -232,7 +232,7 @@
<ClCompile Include="..\src\regexp.c" />
<ClCompile Include="..\src\rdports.c" />
<ClCompile Include="..\src\rdavl.c" />
<ClCompile Include="..\src\xxhash.c" />
<ClCompile Include="..\src\rdxxhash.c" />
<ClCompile Include="..\src\lz4.c" />
<ClCompile Include="..\src\lz4frame.c" />
<ClCompile Include="..\src\lz4hc.c" />
Expand Down

0 comments on commit 86461c0

Please sign in to comment.