forked from EnterpriseDB/mongo_fdw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autogen.sh
executable file
·148 lines (132 loc) · 3.25 KB
/
autogen.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#! /bin/bash
#-------------------------------------------------------------------------
#
# autogen.sh
# Foreign-data wrapper for remote MongoDB servers
#
# Portions Copyright (c) 2012-2014, PostgreSQL Global Development Group
# Portions Copyright (c) 2004-2022, EnterpriseDB Corporation.
#
# IDENTIFICATION
# autogen.sh
#
#-------------------------------------------------------------------------
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]"
exit
fi
CMAKE_COMMAND='cmake3'
if ! [ -x "$(command -v cmake3)" ]; then
CMAKE_COMMAND='cmake'
fi
###
# Pull the latest version of Mongo C Driver's master branch
#
function checkout_mongo_driver
{
rm -rf mongo-c-driver &&
wget https://github.com/mongodb/mongo-c-driver/releases/download/$MONGOC_VERSION/mongo-c-driver-$MONGOC_VERSION.tar.gz &&
tar -zxf mongo-c-driver-$MONGOC_VERSION.tar.gz &&
mv mongo-c-driver-$MONGOC_VERSION mongo-c-driver &&
rm -rf mongo-c-driver-$MONGOC_VERSION.tar.gz
}
###
# Pull the legacy branch of the Mongo C Driver
#
function checkout_legacy_branch
{
rm -rf mongo-c-driver &&
wget https://github.com/mongodb/mongo-c-driver/archive/v0.8.tar.gz &&
tar -zxf v0.8.tar.gz &&
mv mongo-c-driver-0.8 mongo-c-driver &&
rm -rf v0.8.tar.gz
}
##
# Pull the json-c library
#
function checkout_json_lib
{
echo $PWD &&
rm -rf json-c &&
wget https://github.com/json-c/json-c/archive/json-c-$JSONC_VERSION.tar.gz &&
tar -zxf json-c-$JSONC_VERSION.tar.gz &&
mv json-c-json-c-$JSONC_VERSION json-c &&
rm -rf json-c-$JSONC_VERSION.tar.gz &&
echo $PWD
}
##
# Compile and install json-c library
#
function install_json_lib
{
cd json-c &&
$CMAKE_COMMAND -DCMAKE_INSTALL_PREFIX=$JSONC_INSTALL $JSONC_CFLAGS . &&
make install &&
cd ..
}
###
# Configure and install the Mongo C Driver and libbson
#
function install_mongoc_driver
{
cd mongo-c-driver &&
$CMAKE_COMMAND -DCMAKE_INSTALL_PREFIX=$MONGOC_INSTALL -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DENABLE_SSL=AUTO . &&
make install &&
cd ..
}
###
# Cleanup the system
#
function cleanup
{
rm -f config.h
touch config.h
}
###
# Create a config file and append #define META_DRIVER which will be
# used in case of Meta Driver (master branch) option.
#
function create_config
{
echo "#ifdef __CONFIG__" >> config.h &&
echo "#define META_DRIVER" >> config.h &&
echo "#endif" >> config.h
}
cleanup
if [ "--with-legacy" = $1 ]; then
echo "Warning: The legacy driver support has been deprecated in mongo_fdw 5.4.0 and is expected to be removed entirely in a future release."
checkout_json_lib &&
checkout_legacy_branch &&
install_json_lib &&
cp Makefile.legacy Makefile
ret=$?
if [ "$ret" -ne 0 ]; then
echo "Failed"
exit $ret
else
echo "Done"
exit 0
fi
elif [ "--with-master" == $1 ]; then
checkout_mongo_driver &&
checkout_json_lib &&
install_mongoc_driver &&
install_json_lib &&
create_config &&
export PKG_CONFIG_PATH=mongo-c-driver/src/libmongoc/src:mongo-c-driver/src/libbson/src &&
cp Makefile.meta Makefile
ret=$?
if [ "$ret" -ne 0 ]; then
echo "Failed"
exit $ret
else
echo "Done"
exit 0
fi
else
echo "Usage: autogen.sh --[with-legacy | with-master]"
fi