From 1e59800718b29d4a762b8ac356767a701f968a4d Mon Sep 17 00:00:00 2001 From: Jonny Heggheim Date: Fri, 28 Aug 2020 14:46:04 -0700 Subject: [PATCH] Use standard variables for installing/uninstalling with make (#7187) Summary: Fixes https://github.com/facebook/rocksdb/issues/7185. Standard for GNU and FreeBSD. See https://www.freebsd.org/doc/en/books/porters-handbook/porting-prefix.html https://www.gnu.org/prep/standards/html_node/DESTDIR.html#DESTDIR https://www.gnu.org/prep/standards/html_node/Directory-Variables.html Pull Request resolved: https://github.com/facebook/rocksdb/pull/7187 Reviewed By: cheng-chang Differential Revision: D23333233 Pulled By: ajkr fbshipit-source-id: f704d23852c4516cf5fa00df73ff57687b2ddffb --- Makefile | 44 ++++++++++++++++++++----------------- build_tools/make_package.sh | 21 +++++++----------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index b4e9207e3..7c1cc8f05 100644 --- a/Makefile +++ b/Makefile @@ -1830,36 +1830,40 @@ prefetch_test: $(OBJ_DIR)/file/prefetch_test.o $(TEST_LIBRARY) $(LIBRARY) #------------------------------------------------- # make install related stuff -INSTALL_PATH ?= /usr/local +PREFIX ?= /usr/local +LIBDIR ?= $(PREFIX)/lib +INSTALL_LIBDIR = $(DESTDIR)$(LIBDIR) uninstall: - rm -rf $(INSTALL_PATH)/include/rocksdb \ - $(INSTALL_PATH)/lib/$(LIBRARY) \ - $(INSTALL_PATH)/lib/$(SHARED4) \ - $(INSTALL_PATH)/lib/$(SHARED3) \ - $(INSTALL_PATH)/lib/$(SHARED2) \ - $(INSTALL_PATH)/lib/$(SHARED1) \ - $(INSTALL_PATH)/lib/pkgconfig/rocksdb.pc + rm -rf $(DESTDIR)$(PREFIX)/include/rocksdb \ + $(INSTALL_LIBDIR)/$(LIBRARY) \ + $(INSTALL_LIBDIR)/$(SHARED4) \ + $(INSTALL_LIBDIR)/$(SHARED3) \ + $(INSTALL_LIBDIR)/$(SHARED2) \ + $(INSTALL_LIBDIR)/$(SHARED1) \ + $(INSTALL_LIBDIR)/pkgconfig/rocksdb.pc install-headers: gen-pc - install -d $(INSTALL_PATH)/lib - install -d $(INSTALL_PATH)/lib/pkgconfig + install -d $(INSTALL_LIBDIR) + install -d $(INSTALL_LIBDIR)/pkgconfig for header_dir in `$(FIND) "include/rocksdb" -type d`; do \ - install -d $(INSTALL_PATH)/$$header_dir; \ + install -d $(DESTDIR)/$(PREFIX)/$$header_dir; \ done for header in `$(FIND) "include/rocksdb" -type f -name *.h`; do \ - install -C -m 644 $$header $(INSTALL_PATH)/$$header; \ + install -C -m 644 $$header $(DESTDIR)/$(PREFIX)/$$header; \ done - install -C -m 644 rocksdb.pc $(INSTALL_PATH)/lib/pkgconfig/rocksdb.pc + install -C -m 644 rocksdb.pc $(INSTALL_LIBDIR)/pkgconfig/rocksdb.pc install-static: install-headers $(LIBRARY) - install -C -m 755 $(LIBRARY) $(INSTALL_PATH)/lib + install -d $(INSTALL_LIBDIR) + install -C -m 755 $(LIBRARY) $(INSTALL_LIBDIR) install-shared: install-headers $(SHARED4) - install -C -m 755 $(SHARED4) $(INSTALL_PATH)/lib && \ - ln -fs $(SHARED4) $(INSTALL_PATH)/lib/$(SHARED3) && \ - ln -fs $(SHARED4) $(INSTALL_PATH)/lib/$(SHARED2) && \ - ln -fs $(SHARED4) $(INSTALL_PATH)/lib/$(SHARED1) + install -d $(INSTALL_LIBDIR) + install -C -m 755 $(SHARED4) $(INSTALL_LIBDIR) + ln -fs $(SHARED4) $(INSTALL_LIBDIR)/$(SHARED3) + ln -fs $(SHARED4) $(INSTALL_LIBDIR)/$(SHARED2) + ln -fs $(SHARED4) $(INSTALL_LIBDIR)/$(SHARED1) # install static by default + install shared if it exists install: install-static @@ -1867,10 +1871,10 @@ install: install-static # Generate the pkg-config file gen-pc: - -echo 'prefix=$(INSTALL_PATH)' > rocksdb.pc + -echo 'prefix=$(PREFIX)' > rocksdb.pc -echo 'exec_prefix=$${prefix}' >> rocksdb.pc -echo 'includedir=$${prefix}/include' >> rocksdb.pc - -echo 'libdir=$${exec_prefix}/lib' >> rocksdb.pc + -echo 'libdir=$(LIBDIR)' >> rocksdb.pc -echo '' >> rocksdb.pc -echo 'Name: rocksdb' >> rocksdb.pc -echo 'Description: An embeddable persistent key-value store for fast storage' >> rocksdb.pc diff --git a/build_tools/make_package.sh b/build_tools/make_package.sh index 7b5c52cff..68a5d8a72 100755 --- a/build_tools/make_package.sh +++ b/build_tools/make_package.sh @@ -103,31 +103,26 @@ function main() { gem_install fpm make static_lib - make install INSTALL_PATH=package - - cd package - - LIB_DIR=lib - if [[ -z "$ARCH" ]]; then - ARCH=$(getconf LONG_BIT) - fi - if [[ ("$FPM_OUTPUT" = "rpm") && ($ARCH -eq 64) ]]; then - mv lib lib64 - LIB_DIR=lib64 + LIBDIR=/usr/lib + if [[ $FPM_OUTPUT = "rpm" ]]; then + LIBDIR=$(rpm --eval '%_libdir') fi + rm -rf package + make install DESTDIR=package PREFIX=/usr LIBDIR=$LIBDIR + fpm \ -s dir \ -t $FPM_OUTPUT \ + -C package \ -n rocksdb \ -v $1 \ - --prefix /usr \ --url http://rocksdb.org/ \ -m rocksdb@fb.com \ --license BSD \ --vendor Facebook \ --description "RocksDB is an embeddable persistent key-value store for fast storage." \ - include $LIB_DIR + usr } # shellcheck disable=SC2068