Skip to content

Commit

Permalink
Use CMake pkg-config .in files in the Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-grunder committed Jun 23, 2024
1 parent b9ea003 commit cd44982
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ OBJS = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SOURCES))
LIBNAME=libvalkey
PKGCONFNAME=$(LIB_DIR)/valkey.pc

PKGCONF_TEMPLATE = valkey.pc.in
SSL_PKGCONF_TEMPLATE = valkey_ssl.pc.in

LIBVALKEY_MAJOR=$(shell grep LIBVALKEY_MAJOR $(INCLUDE_DIR)/valkey.h | awk '{print $$3}')
LIBVALKEY_MINOR=$(shell grep LIBVALKEY_MINOR $(INCLUDE_DIR)/valkey.h | awk '{print $$3}')
LIBVALKEY_PATCH=$(shell grep LIBVALKEY_PATCH $(INCLUDE_DIR)/valkey.h | awk '{print $$3}')
Expand Down Expand Up @@ -223,34 +226,21 @@ clean:

INSTALL?= cp -pPR

$(PKGCONFNAME): include/valkey/valkey.h
$(PKGCONFNAME): $(PKGCONF_TEMPLATE)
@echo "Generating $@ for pkgconfig..."
@echo prefix=$(PREFIX) > $@
@echo exec_prefix=\$${prefix} >> $@
@echo libdir=$(PREFIX)/$(LIBRARY_PATH) >> $@
@echo includedir=$(PREFIX)/include >> $@
@echo pkgincludedir=$(PREFIX)/$(INCLUDE_PATH) >> $@
@echo >> $@
@echo Name: valkey >> $@
@echo Description: C client library for Valkey. >> $@
@echo Version: $(LIBVALKEY_MAJOR).$(LIBVALKEY_MINOR).$(LIBVALKEY_PATCH) >> $@
@echo Libs: -L\$${libdir} -lvalkey >> $@
@echo Cflags: -I\$${pkgincludedir} -I\$${includedir} -D_FILE_OFFSET_BITS=64 >> $@

$(SSL_PKGCONFNAME): include/valkey/valkey_ssl.h
sed \
-e 's|@CMAKE_INSTALL_PREFIX@|$(PREFIX)|g' \
-e 's|@CMAKE_INSTALL_LIBDIR@|$(INSTALL_LIBRARY_PATH)|g' \
-e 's|@PROJECT_VERSION@|$(LIBVALKEY_SONAME)|g' \
$< > $@

$(SSL_PKGCONFNAME): $(SSL_PKGCONF_TEMPLATE)
@echo "Generating $@ for pkgconfig..."
@echo prefix=$(PREFIX) > $@
@echo exec_prefix=\$${prefix} >> $@
@echo libdir=$(PREFIX)/$(LIBRARY_PATH) >> $@
@echo includedir=$(PREFIX)/include >> $@
@echo pkgincludedir=$(PREFIX)/$(INCLUDE_PATH) >> $@
@echo >> $@
@echo Name: valkey_ssl >> $@
@echo Description: SSL Support for valkey. >> $@
@echo Version: $(LIBVALKEY_MAJOR).$(LIBVALKEY_MINOR).$(LIBVALKEY_PATCH) >> $@
@echo Requires: valkey >> $@
@echo Libs: -L\$${libdir} -lvalkey_ssl >> $@
@echo Libs.private: -lssl -lcrypto >> $@
sed \
-e 's|@CMAKE_INSTALL_PREFIX@|$(PREFIX)|g' \
-e 's|@CMAKE_INSTALL_LIBDIR@|$(INSTALL_LIBRARY_PATH)|g' \
-e 's|@PROJECT_VERSION@|$(LIBVALKEY_SONAME)|g' \
$< > $@

install: $(DYLIBNAME) $(STLIBNAME) $(PKGCONFNAME) $(SSL_INSTALL)
mkdir -p $(INSTALL_INCLUDE_PATH)/adapters $(INSTALL_LIBRARY_PATH)
Expand Down

0 comments on commit cd44982

Please sign in to comment.