From 434b47a73faa56d15ab902423cb15efc56c79c07 Mon Sep 17 00:00:00 2001 From: Jeevan Ladhe Date: Fri, 10 Sep 2021 12:44:42 +0530 Subject: [PATCH] Allow mongo-c and json-c drivers installation at custom locations. autogen.sh helps in avoiding manual installation and automates the download and installation of the appropriate drivers and libraries including mongo-c and json-c driver. But, these drivers get installed at the default locations e.g. /usr/lib/, and user might not have permission to write in this directory. This results in autogen.sh failure. Use environment variables MONGOC_INSTALL_DIR and JSONC_INSTALL_DIR in autogen.sh to set CMAKE_INSTALL_PREFIX to allow custom directory installation for these drivers where the user might have permission. Reported on GitHub through issue #152 by user pgloader. FDW-406, Vaibhav Dalvi, reviewed by Jeevan Ladhe, tested by Rajkumar Raghuwanshi. --- README.md | 29 ++++++++++++++++++++++++++++- autogen.sh | 6 ++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9e58ca6..050a612 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,34 @@ different type of MongoDB drivers and supported libraries. If you want to avoid the manual steps, there is a shell script available which will download and install the appropriate drivers and libraries for you. -Here is how it works : +Here is how it works: + +To install mongo-c and json-c libraries at custom locations, you need to +export environment variables `MONGOC_INSTALL_DIR` and `JSONC_INSTALL_DIR` +respectively. If these variables are not set then these libraries will be +installed in the default location. Please note that you need to have the +required permission to install the directory whether it is custom or default. + +The `PKG_CONFIG_PATH` environment variable must be set to mongo-c-driver source +directory for successful compilation as shown below, + +```sh +export PKG_CONFIG_PATH=$YOUR_MONGO_FDW_SOURCE_DIR/mongo-c-driver/src/libmongoc/src:$YOUR_MONGO_FDW_SOURCE_DIR/mongo-c-driver/src/libbson/src +``` + +The `LD_LIBRARY_PATH` environment variable must include the path to the mongo-c +installation directory containing the libmongoc-1.0.so and libbson-1.0.so +files. For example, assuming the installation directory is /home/mongo-c and +the libraries were created under it in lib64 sub-directory, then we can define +the `LD_LIBRARY_PATH` as: + +```sh +export LD_LIBRARY_PATH=/home/mongo-c/lib64:$LD_LIBRARY_PATH +``` + +Note: This `LD_LIBRARY_PATH` environment variable setting must be in effect +when the `pg_ctl` utility is executed to start or restart PostgreSQL or +EDB Postgres Advanced Server. Build with [MongoDB][1]'s legacy branch driver * autogen.sh --with-legacy diff --git a/autogen.sh b/autogen.sh index 6ba463e..0124b06 100755 --- a/autogen.sh +++ b/autogen.sh @@ -16,6 +16,8 @@ MONGOC_VERSION=1.17.3 JSONC_VERSION=0.15-20200726 +MONGOC_INSTALL="${MONGOC_INSTALL_DIR}" +JSONC_INSTALL="${JSONC_INSTALL_DIR}" if [ "$#" -ne 1 ]; then echo "Usage: autogen.sh --[with-legacy | with-master]" @@ -71,7 +73,7 @@ function checkout_json_lib function install_json_lib { cd json-c && - $CMAKE_COMMAND $JSONC_CFLAGS . && + $CMAKE_COMMAND -DCMAKE_INSTALL_PREFIX=$JSONC_INSTALL $JSONC_CFLAGS . && make install && cd .. } @@ -82,7 +84,7 @@ function install_json_lib function install_mongoc_driver { cd mongo-c-driver && - $CMAKE_COMMAND -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DENABLE_SSL=AUTO . && + $CMAKE_COMMAND -DCMAKE_INSTALL_PREFIX=$MONGOC_INSTALL -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DENABLE_SSL=AUTO . && make install && cd .. }