From 2224cc3a999db3e582cfc140ec176818d3a50c68 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 22 Feb 2022 11:55:42 -0500 Subject: Added soname to library --- Makefile | 28 +++++++++++++++------------- src/lib/Makefile | 23 +++++++++++++++++++++++ src/test/Makefile | 6 ++---- 3 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 src/lib/Makefile diff --git a/Makefile b/Makefile index b7eba21..b08ed50 100644 --- a/Makefile +++ b/Makefile @@ -1,32 +1,33 @@ -LIBS = sword minizip -override CXXFLAGS += -MMD -Wall -fPIC -std=c++20 `pkg-config $(LIBS) --cflags` -override LDFLAGS += -lstdc++fs `pkg-config $(LIBS) --libs` -SOURCES = $(wildcard src/*.cc) $(wildcard src/lib/*.cc) +export version = 1.0.1 +override CXXFLAGS += -MMD -Wall -std=c++20 +override LDFLAGS += -Lsrc/lib -lbible +SOURCES = $(wildcard src/*.cc) OBJECTS = $(SOURCES:.cc=.o) DEPS = $(OBJECTS:.o=.d) EXECUTABLE = bible -LIBRARY = libbible.so prefix ?= /usr exec_prefix ?= $(prefix) libdir ?= $(exec_prefix)/lib bindir ?= $(exec_prefix)/bin includedir ?= $(prefix)/include -$(EXECUTABLE): $(OBJECTS) +$(EXECUTABLE): $(OBJECTS) libbible $(CXX) $(OBJECTS) -o $@ $(LDFLAGS) -include $(DEPS) -$(LIBRARY): $(OBJECTS) - $(CXX) $(OBJECTS) -shared -o $@ $(LDFLAGS) +.PHONY: libbible +libbible: + $(MAKE) -C src/lib .PHONY: test -test: $(LIBRARY) +test: libbible $(MAKE) -C src/test/ test -install: $(LIBRARY) $(EXECUTABLE) +install: libbible $(EXECUTABLE) install -d $(DESTDIR)$(libdir) - install -m 644 $(LIBRARY) $(DESTDIR)$(libdir) + install -m 644 src/lib/libbible.so $(DESTDIR)$(libdir)/libbible.so.$(version) + install -m 644 src/lib/libbible.a $(DESTDIR)$(libdir) install -d $(DESTDIR)$(includedir) install -m 644 src/lib/libbible.h $(DESTDIR)$(includedir) install -d $(DESTDIR)$(bindir) @@ -36,5 +37,6 @@ install: $(LIBRARY) $(EXECUTABLE) .PHONY: clean clean: - $(RM) $(OBJECTS) $(DEPS) $(EXECUTABLE) $(LIBRARY) $(TEST) - $(MAKE) -C src/test/ clean + $(RM) $(OBJECTS) $(DEPS) $(EXECUTABLE) + $(MAKE) -C src/test clean + $(MAKE) -C src/lib clean diff --git a/src/lib/Makefile b/src/lib/Makefile new file mode 100644 index 0000000..6b3b506 --- /dev/null +++ b/src/lib/Makefile @@ -0,0 +1,23 @@ +LIBS = sword minizip +override CXXFLAGS += -MMD -Wall -fPIC -std=c++20 `pkg-config $(LIBS) --cflags` +override LDFLAGS += -lstdc++fs `pkg-config $(LIBS) --libs` +SOURCES = $(wildcard *.cc) +OBJECTS = $(SOURCES:.cc=.o) +DEPS = $(OBJECTS:.o=.d) +LIBRARY = libbible +SONAME = $(LIBRARY).so.$(word 1, $(subst ., , $(version))) +LIBRARY_STATIC = $(LIBRARY).a +LIBRARY_SHARED = $(LIBRARY).so + +.PHONY: all +all: $(LIBRARY_SHARED) $(LIBRARY_STATIC) + +$(LIBRARY_SHARED): $(OBJECTS) + $(CXX) $^ -shared -Wl,-soname,$(SONAME) -o $@ $(LDFLAGS) + +$(LIBRARY_STATIC): $(OBJECTS) + $(AR) rcs $@ $^ + +.PHONY: clean +clean: + $(RM) $(OBJECTS) $(DEPS) $(LIBRARY_SHARED) $(LIBRARY_STATIC) diff --git a/src/test/Makefile b/src/test/Makefile index 1f8bc8b..422cc03 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -1,13 +1,11 @@ -LIBS = sword minizip -override CXXFLAGS += -MMD -Wall -fPIC -std=c++20 `pkg-config $(LIBS) --cflags` -override LDFLAGS += -lstdc++fs `pkg-config $(LIBS) --libs` -lcppunit ../../libbible.so +override LDFLAGS += -lcppunit ../lib/libbible.so SOURCES = $(wildcard *.cc) OBJECTS = $(SOURCES:.cc=.o) DEPS = $(OBJECTS:.o=.d) TEST = testLibbible $(TEST): $(OBJECTS) - $(CXX) $(OBJECTS) -o $@ $(LDFLAGS) + $(CXX) $^ -o $@ $(LDFLAGS) -include $(DEPS) -- cgit v1.2.3