Skip to content

Commit

Permalink
Add SONAME, pkgconfig and fix makefile issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tezc committed Oct 29, 2023
1 parent 8d916c4 commit e4c5fb3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 21 deletions.
74 changes: 55 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@ INSTALL = /usr/bin/install -c
BINDIR=$(DESTDIR)$(PREFIX)/bin
LIBDIR=$(DESTDIR)$(PREFIX)/lib
INCDIR=$(DESTDIR)$(PREFIX)/include/librdb/
LIBRDB_INSTALL_SHARED:=yes
LIBRDB_INSTALL_STATIC:=yes

VERSION = $(shell grep -oP '(?<=LIBRDB_VERSION_STRING ")[0-9]+\.[0-9]+\.[0-9]+' ./src/lib/version.h)
UNAME := $(shell uname)

ifneq (,$(filter $(UNAME),OpenBSD FreeBSD NetBSD))
PKGCONFIGDIR = $(DESTDIR)$(PREFIX)/libdata/pkgconfig
else
PKGCONFIGDIR = $(LIBDIR)/pkgconfig
endif

LIBRDB_VERSION = $(shell grep -oP '(?<=LIBRDB_VERSION_STRING ")[0-9]+\.[0-9]+\.[0-9]+' ./src/lib/version.h)
export LIBRDB_VERSION

# ------------------------- ALL --------------------------------------

Expand All @@ -25,6 +36,8 @@ clean:
$(MAKE) -C src/cli -f Makefile clean
$(MAKE) -C examples -f Makefile clean
$(MAKE) -C test -f Makefile clean
rm -f librdb.pc
rm -f librdb-ext.pc

distclean: clean

Expand All @@ -48,41 +61,64 @@ valgrind: build_test
./runtests -v

# ------------------------- INSTALL --------------------------------------
install: all

librdb.pc: librdb.pc.in Makefile
sed -e 's|@PREFIX@|$(PREFIX)|' \
-e 's|@VERSION@|$(LIBRDB_VERSION)|' \
$< >$@

librdb-ext.pc: librdb-ext.pc.in Makefile
sed -e 's|@PREFIX@|$(PREFIX)|' \
-e 's|@VERSION@|$(LIBRDB_VERSION)|' \
$< >$@

install: all librdb.pc librdb-ext.pc
$(INSTALL) -d $(BINDIR)
$(INSTALL) -m 755 bin/rdb-cli $(BINDIR)/rdb-cli-$(VERSION)
ln -fsr $(BINDIR)/rdb-cli-$(VERSION) $(BINDIR)/rdb-cli
$(INSTALL) -m 755 bin/rdb-cli $(BINDIR)/rdb-cli-$(LIBRDB_VERSION)
ln -fsr $(BINDIR)/rdb-cli-$(LIBRDB_VERSION) $(BINDIR)/rdb-cli
$(INSTALL) -d $(LIBDIR)
$(INSTALL) -m 755 lib/librdb.so $(LIBDIR)/librdb.so.$(VERSION)
ln -fsr $(LIBDIR)/librdb.so.$(VERSION) $(LIBDIR)/librdb.so
$(INSTALL) -m 755 lib/librdb-ext.so $(LIBDIR)/librdb-ext.so.$(VERSION)
ln -fsr $(LIBDIR)/librdb-ext.so.$(VERSION) $(LIBDIR)/librdb-ext.so
$(INSTALL) -m 755 lib/librdb.a $(LIBDIR)/librdb.a.$(VERSION)
ln -fsr $(LIBDIR)/librdb.a.$(VERSION) $(LIBDIR)/librdb.a
$(INSTALL) -m 755 lib/librdb-ext.a $(LIBDIR)/librdb-ext.a.$(VERSION)
ln -fsr $(LIBDIR)/librdb-ext.a.$(VERSION) $(LIBDIR)/librdb-ext.a

ifeq ($(LIBRDB_INSTALL_SHARED),yes)
$(INSTALL) -m 755 lib/librdb.so $(LIBDIR)/librdb.so.$(LIBRDB_VERSION)
ln -fsr $(LIBDIR)/librdb.so.$(LIBRDB_VERSION) $(LIBDIR)/librdb.so
$(INSTALL) -m 755 lib/librdb-ext.so $(LIBDIR)/librdb-ext.so.$(LIBRDB_VERSION)
ln -fsr $(LIBDIR)/librdb-ext.so.$(LIBRDB_VERSION) $(LIBDIR)/librdb-ext.so
$(INSTALL) -d $(PKGCONFIGDIR)
$(INSTALL) -m 644 librdb.pc $(PKGCONFIGDIR)
$(INSTALL) -m 644 librdb-ext.pc $(PKGCONFIGDIR)
endif

ifeq ($(LIBRDB_INSTALL_STATIC),yes)
$(INSTALL) -m 755 lib/librdb.a $(LIBDIR)/librdb.a.$(LIBRDB_VERSION)
ln -fsr $(LIBDIR)/librdb.a.$(LIBRDB_VERSION) $(LIBDIR)/librdb.a
$(INSTALL) -m 755 lib/librdb-ext.a $(LIBDIR)/librdb-ext.a.$(LIBRDB_VERSION)
ln -fsr $(LIBDIR)/librdb-ext.a.$(LIBRDB_VERSION) $(LIBDIR)/librdb-ext.a
endif

$(INSTALL) -d $(INCDIR)
$(INSTALL) -m 644 api/librdb-api.h $(INCDIR)
$(INSTALL) -m 644 api/librdb-ext-api.h $(INCDIR)

uninstall:
rm -f $(BINDIR)/rdb-cli || true
rm -f $(BINDIR)/rdb-cli-$(VERSION)
rm -f $(BINDIR)/rdb-cli-$(LIBRDB_VERSION)
rm -f $(LIBDIR)/librdb.so
rm -f $(LIBDIR)/librdb.so.$(VERSION)
rm -f $(LIBDIR)/librdb.so.$(LIBRDB_VERSION)
rm -f $(LIBDIR)/librdb-ext.so
rm -f $(LIBDIR)/librdb-ext.so.$(VERSION)
rm -f $(LIBDIR)/librdb-ext.so.$(LIBRDB_VERSION)
rm -f $(LIBDIR)/librdb.a
rm -f $(LIBDIR)/librdb.a.$(VERSION)
rm -f $(LIBDIR)/librdb.a.$(LIBRDB_VERSION)
rm -f $(LIBDIR)/librdb-ext.a
rm -f $(LIBDIR)/librdb-ext.a.$(VERSION)
rm -f $(LIBDIR)/librdb-ext.a.$(LIBRDB_VERSION)
rm -f $(INCDIR)/librdb-api.h
rm -f $(INCDIR)/librdb-ext-api.h
rm -f $(PKGCONFIGDIR)/librdb.pc
rm -f $(PKGCONFIGDIR)/librdb-ext.pc

# ------------------------- HELP --------------------------------------

help:
@echo "librdb (v$(VERSION)) target rules:"
@echo "librdb (v$(LIBRDB_VERSION)) target rules:"
@echo " all - Build parser libraries, tests, and run tests"
@echo " debug - Build without compiler optimization and with assert() enabled"
@echo " test - Run tests with shared lib"
Expand All @@ -96,4 +132,4 @@ help:
@echo " help - Prints this message"


.PHONY: all debug test valgrind example clean distclean install uninstall build_test help
.PHONY: all debug test valgrind example clean distclean install uninstall build_test help
11 changes: 11 additions & 0 deletions librdb-ext.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: librdb-ext
Description: Extension library for parsing Redis RDB to JSON and RESP protocols
Version: @VERSION@
Libs: -L${libdir} -lrdb-ext
Requires: librdb
Cflags: -I${includedir}
10 changes: 10 additions & 0 deletions librdb.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prefix=@PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: librdb
Description: Library for parsing Redis RDB files
Version: @VERSION@
Libs: -L${libdir} -lrdb
Cflags: -I${includedir}
3 changes: 2 additions & 1 deletion src/ext/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ default: all
LIB_NAME = rdb
LIB_NAME_EXT = $(LIB_NAME)-ext
LIB_DIR = ../../lib
LIBRDB_SONAME_EXT = lib$(LIB_NAME_EXT).so.${LIBRDB_VERSION}

TARGET_LIB_STATIC = $(LIB_DIR)/lib$(LIB_NAME).a
# Artifacts:
Expand Down Expand Up @@ -38,7 +39,7 @@ all: $(TARGET_LIB_EXT) $(TARGET_LIB_STATIC_EXT)
@echo "Done.";

$(TARGET_LIB_EXT): $(OBJECTS) $(REDIS_OBJECTS)
$(CC) -o $@ -shared ${LDFLAGS} $^ $(LIBS)
$(CC) -o $@ -shared -Wl,-soname,${LIBRDB_SONAME_EXT} ${LDFLAGS} $^ $(LIBS)

$(TARGET_LIB_STATIC_EXT): $(OBJECTS) $(REDIS_OBJECTS)
ar rcs $@ $^
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ default: all

LIB_NAME = rdb
LIB_DIR = ../../lib
LIBRDB_SONAME = lib$(LIB_NAME).so.${LIBRDB_VERSION}

# Artifacts:
TARGET_LIB = $(LIB_DIR)/lib$(LIB_NAME).so
Expand Down Expand Up @@ -38,7 +39,7 @@ all: $(TARGET_LIB) $(TARGET_LIB_STATIC)
@echo "Done.";

$(TARGET_LIB): $(OBJECTS) $(REDIS_OBJECTS)
$(CC) -o $@ -shared ${LDFLAGS} $^
$(CC) -o $@ -shared -Wl,-soname,${LIBRDB_SONAME} ${LDFLAGS} $^

$(TARGET_LIB_STATIC): $(OBJECTS) $(REDIS_OBJECTS)
ar rcs $@ $^
Expand Down

0 comments on commit e4c5fb3

Please sign in to comment.