From 16351a7ebaf318d21632bbaabf0675a70bb67dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= Date: Tue, 3 Dec 2019 12:07:19 +0100 Subject: [PATCH 3/5] Generate both shared and static libraries --- c/Makefile | 14 ++++++++++---- cpp/Makefile | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/c/Makefile b/c/Makefile index bf79462..38eda2d 100644 --- a/c/Makefile +++ b/c/Makefile @@ -51,16 +51,19 @@ CFLAGS ?= -std=c99 -O # ---- Targets to build ---- LIB = qrcodegen -LIBFILE = lib$(LIB).a +ARFILE = lib$(LIB).a +LIBFILE = lib$(LIB).so +# Bump the soname number when the ABI changes and gets incompatible +SO_NAME = $(LIBFILE).1 LIBOBJ = qrcodegen.o MAINS = qrcodegen-demo qrcodegen-test qrcodegen-worker # Build all binaries -all: $(LIBFILE) $(MAINS) +all: $(LIBFILE) $(ARFILE) $(MAINS) # Delete build output clean: - rm -f -- $(LIBOBJ) $(LIBFILE) $(MAINS:=.o) $(MAINS) + rm -f -- $(LIBOBJ) $(LIBFILE) $(ARFILE) $(MAINS:=.o) $(MAINS) rm -rf .deps # Executable files @@ -72,9 +75,12 @@ qrcodegen-test: qrcodegen-test.c $(LIBOBJ:%.o=%.c) $(CC) $(CFLAGS) -DQRCODEGEN_TEST -o $@ $^ # The library -$(LIBFILE): $(LIBOBJ) +$(ARFILE): $(LIBOBJ) $(AR) -crs $@ -- $^ +$(LIBFILE): $(LIBOBJ) + $(CC) -shared -Wl,-soname,$(SO_NAME) $(LDFLAGS) -o $@ $^ + # Object files %.o: %.c .deps/timestamp $(CC) $(CFLAGS) -fPIC -c -o $@ -MMD -MF .deps/$*.d $< diff --git a/cpp/Makefile b/cpp/Makefile index deb8924..2f5b2af 100644 --- a/cpp/Makefile +++ b/cpp/Makefile @@ -51,16 +51,19 @@ CXXFLAGS ?= -std=c++11 -O # ---- Targets to build ---- LIB = qrcodegen -LIBFILE = lib$(LIB).a +ARFILE = lib$(LIB).a +LIBFILE = lib$(LIB).so +# Bump the soname number when the ABI changes and gets incompatible +SO_NAME = $(LIBFILE).1 LIBOBJ = BitBuffer.o QrCode.o QrSegment.o MAINS = QrCodeGeneratorDemo QrCodeGeneratorWorker # Build all binaries -all: $(LIBFILE) $(MAINS) +all: $(LIBFILE) $(ARFILE) $(MAINS) # Delete build output clean: - rm -f -- $(LIBOBJ) $(LIBFILE) $(MAINS:=.o) $(MAINS) + rm -f -- $(LIBOBJ) $(LIBFILE) $(ARFILE) $(MAINS:=.o) $(MAINS) rm -rf .deps # Executable files @@ -68,9 +71,12 @@ clean: $(CXX) $(CXXFLAGS) -o $@ $< -L . -l $(LIB) # The library -$(LIBFILE): $(LIBOBJ) +$(ARFILE): $(LIBOBJ) $(AR) -crs $@ -- $^ +$(LIBFILE): $(LIBOBJ) + $(CC) -shared -Wl,-soname,$(SO_NAME) $(LDFLAGS) -o $@ $^ + # Object files %.o: %.cpp .deps/timestamp $(CXX) $(CXXFLAGS) -fPIC -c -o $@ -MMD -MF .deps/$*.d $< -- 2.24.0