Generate and install a pkg-config file (#7244)

Summary:
pkg-config files are quite useful for communicating to users of a
library how to compile against them. This commit generates and installs
a pkg-config file that can be used for both static and dynamic builds
against the RocksDB library. This should make life easier for developers
of client programs, language bindings, etc.

Example usage:

```
g++ `pkg-config --cflags rocksdb` -o simple_example simple_example.cc `pkg-config --libs rocksdb`

g++ `pkg-config --cflags --static rocksdb` -static \
   -o simple_example simple_example.cc `pkg-config --libs --static rocksdb`
```

The commit also adds the generated file to .gitignore, to the uninstall
target, and to clean.

No additional dependencies are added to RocksDB itself, and this does
not make RocksDB use pkg-config as part of its build process.

Resolves https://github.com/facebook/rocksdb/issues/4452

Pull Request resolved: https://github.com/facebook/rocksdb/pull/7244

Reviewed By: siying

Differential Revision: D23146153

Pulled By: ajkr

fbshipit-source-id: 3045aa650d68bd5ac42d40ed709570e9584ef004
This commit is contained in:
John Goerzen 2020-08-17 11:51:35 -07:00 committed by Facebook GitHub Bot
parent 69760b4d05
commit 59ebab654e
2 changed files with 22 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
make_config.mk make_config.mk
rocksdb.pc
*.a *.a
*.arc *.arc

View File

@ -265,7 +265,7 @@ dummy := $(shell (export ROCKSDB_ROOT="$(CURDIR)"; \
include make_config.mk include make_config.mk
export JAVAC_ARGS export JAVAC_ARGS
CLEAN_FILES += make_config.mk CLEAN_FILES += make_config.mk rocksdb.pc
ifeq ($(V), 1) ifeq ($(V), 1)
$(info $(shell uname -a)) $(info $(shell uname -a))
@ -725,7 +725,7 @@ endif # PLATFORM_SHARED_EXT
.PHONY: blackbox_crash_test check clean coverage crash_test ldb_tests package \ .PHONY: blackbox_crash_test check clean coverage crash_test ldb_tests package \
release tags tags0 valgrind_check whitebox_crash_test format static_lib shared_lib all \ release tags tags0 valgrind_check whitebox_crash_test format static_lib shared_lib all \
dbg rocksdbjavastatic rocksdbjava install install-static install-shared uninstall \ dbg rocksdbjavastatic rocksdbjava gen-pc install install-static install-shared uninstall \
analyze tools tools_lib \ analyze tools tools_lib \
blackbox_crash_test_with_atomic_flush whitebox_crash_test_with_atomic_flush \ blackbox_crash_test_with_atomic_flush whitebox_crash_test_with_atomic_flush \
blackbox_crash_test_with_txn whitebox_crash_test_with_txn \ blackbox_crash_test_with_txn whitebox_crash_test_with_txn \
@ -1827,16 +1827,19 @@ uninstall:
$(INSTALL_PATH)/lib/$(SHARED4) \ $(INSTALL_PATH)/lib/$(SHARED4) \
$(INSTALL_PATH)/lib/$(SHARED3) \ $(INSTALL_PATH)/lib/$(SHARED3) \
$(INSTALL_PATH)/lib/$(SHARED2) \ $(INSTALL_PATH)/lib/$(SHARED2) \
$(INSTALL_PATH)/lib/$(SHARED1) $(INSTALL_PATH)/lib/$(SHARED1) \
$(INSTALL_PATH)/lib/pkgconfig/rocksdb.pc
install-headers: install-headers: gen-pc
install -d $(INSTALL_PATH)/lib install -d $(INSTALL_PATH)/lib
install -d $(INSTALL_PATH)/lib/pkgconfig
for header_dir in `$(FIND) "include/rocksdb" -type d`; do \ for header_dir in `$(FIND) "include/rocksdb" -type d`; do \
install -d $(INSTALL_PATH)/$$header_dir; \ install -d $(INSTALL_PATH)/$$header_dir; \
done done
for header in `$(FIND) "include/rocksdb" -type f -name *.h`; do \ for header in `$(FIND) "include/rocksdb" -type f -name *.h`; do \
install -C -m 644 $$header $(INSTALL_PATH)/$$header; \ install -C -m 644 $$header $(INSTALL_PATH)/$$header; \
done done
install -C -m 644 rocksdb.pc $(INSTALL_PATH)/lib/pkgconfig/rocksdb.pc
install-static: install-headers $(LIBRARY) install-static: install-headers $(LIBRARY)
install -C -m 755 $(LIBRARY) $(INSTALL_PATH)/lib install -C -m 755 $(LIBRARY) $(INSTALL_PATH)/lib
@ -1851,6 +1854,20 @@ install-shared: install-headers $(SHARED4)
install: install-static install: install-static
[ -e $(SHARED4) ] && $(MAKE) install-shared || : [ -e $(SHARED4) ] && $(MAKE) install-shared || :
# Generate the pkg-config file
gen-pc:
-echo 'prefix=$(INSTALL_PATH)' > rocksdb.pc
-echo 'exec_prefix=$${prefix}' >> rocksdb.pc
-echo 'includedir=$${prefix}/include' >> rocksdb.pc
-echo 'libdir=$${exec_prefix}/lib' >> rocksdb.pc
-echo '' >> rocksdb.pc
-echo 'Name: rocksdb' >> rocksdb.pc
-echo 'Description: An embeddable persistent key-value store for fast storage' >> rocksdb.pc
-echo Version: $(shell ./build_tools/version.sh full) >> rocksdb.pc
-echo 'Libs: -L$${libdir} $(EXEC_LDFLAGS) -lrocksdb' >> rocksdb.pc
-echo 'Libs.private: $(PLATFORM_LDFLAGS)' >> rocksdb.pc
-echo 'Cflags: -I$${includedir} $(PLATFORM_CXXFLAGS)' >> rocksdb.pc
#------------------------------------------------- #-------------------------------------------------