summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2014-02-04 21:44:44 -0600
committerPaul J. Davis <paul.joseph.davis@gmail.com>2014-02-05 08:34:52 -0600
commita204d0a891281b0c2b9b9382312dc78b7f9f7a66 (patch)
treee85b34de5ef3ca3a3d0f6bed02a739edaa95ecd6
parent0052a9b26806d155c56ba539c118fb6cffd61b03 (diff)
downloadcouchdb-a204d0a891281b0c2b9b9382312dc78b7f9f7a66.tar.gz
Improved configure scripts
This provides a better help output and argument parsing for the './configure' script. It implements a method for pulling config values into rebar.config.script's so that we can control the build a bit more. As an example there's now a '-c' option to build couchjs with cURL bindings.
-rw-r--r--.gitignore1
-rw-r--r--Makefile8
-rwxr-xr-xconfigure117
-rw-r--r--rebar.config.script7
4 files changed, 91 insertions, 42 deletions
diff --git a/.gitignore b/.gitignore
index 7b37ceab1..902035ddf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+config.erl
install.mk
rel/*.config
rel/dev*
diff --git a/Makefile b/Makefile
index 8651369f6..812849d88 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,13 @@
all: compile
-compile:
+config.erl:
+ @echo "Apache CouchDB has not been configured."
+ @echo "Try \"./configure -h\" for help."
+ @echo
+ @false
+
+compile: config.erl
@echo "==> couchjs (compile)"
@rebar compile
diff --git a/configure b/configure
index c95a9889b..7036d7c1e 100755
--- a/configure
+++ b/configure
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/sh -e
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
@@ -13,42 +13,73 @@
PREFIX="/opt/couchdb"
COUCHDB_USER=`whoami`
-ABSPATH="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
-if test ! -n "$DIRPATH"; then DIRPATH=`dirname "$ABSPATH"`; fi
-
-while [ $# -gt 0 ]
-do
- case $1
- in
- -p)
- PREFIX=$2
- shift 2
- ;;
- -t)
- TEMPLATE=$2
- shift 2
- ;;
- -d)
- DATA=$2
- shift 2
- ;;
- -v)
- VIEW=$2
- shift 2
- ;;
- -u)
- COUCHDB_USER=$2
- shift 2
- ;;
- *)
- echo "usage: $0 [-p {prefix} -t {template} -d {data_dir} -v {view_dir} -u {user}]"
- exit
- ;;
- esac
-done
+WITH_CURL="false"
+
+rootdir="$(cd "${0%/*}" 2>/dev/null; echo "$PWD")"
+basename=`basename $0`
+
+
+display_help () {
+ cat << EOF
+Usage: $basename [OPTION]
+
+The $basename command is responsible for generating the build
+system for Apache CouchDB.
+
+Options:
+
+ -h display a short help message and exit
+ -u USER set the username to run as (defaults to $COUCHDB_USER)
+ -p DIRECTORY set the prefix for installation (defaults to $PREFIX)
+ -d DIRECTORY specify the data directory (defaults to $PREFIX/var/lib)
+ -v DIRECTORY specify the view directory (defaults to $PREFIX/var/lib)
+ -c request that couchjs is linked to cURL (default false)
+
+EOF
+}
+
+
+display_error () {
+ if test -n "$1"; then
+ echo $1 >&2
+ fi
+ echo >&2
+ echo "Try \"$basename -h\" for more information." >&2
+ false
+}
+
+
+parse_opts () {
+ set +e
+ options=`getopt hu:p:d:v:c $@`
+ if test ! $? -eq 0; then
+ display_error
+ fi
+ set -e
+ eval set -- $options
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ -h) shift; display_help; exit;;
+ -u) shift; COUCHDB_USER=$1; shift;;
+ -p) shift; PREFIX=$1; shift;;
+ -d) shift; DATA=$1; shift;;
+ -v) shift; VIEW=$1; shift;;
+ -c) shift; WITH_CURL="true";;
+ --) shift; break;;
+ *) display_error "Unknown option: $1" >&2;;
+ esac
+ done
+ if test ! -n "$DATA"; then
+ DATA="$PREFIX/var/lib";
+ fi
+ if test ! -n "$VIEW"; then
+ VIEW="$PREFIX/var/lib";
+ fi
+}
+
+
+parse_opts $@
-if test ! -n "$DATA"; then DATA="$PREFIX/var/lib"; fi
-if test ! -n "$VIEW"; then VIEW="$PREFIX/var/lib"; fi
echo "==> configuring couchdb in rel/couchdb.config"
cat > rel/couchdb.config << EOF
@@ -69,16 +100,22 @@ view_dir = $VIEW
user = $COUCHDB_USER
EOF
+cat > $rootdir/config.erl << EOF
+{with_curl, $WITH_CURL}.
+EOF
+
# finally, a few config files for local development nodes
for i in 1 2 3; do
cat > rel/dev$i.config << EOF
-{prefix, "$DIRPATH/rel/dev$i"}.
-{data_dir, "$DIRPATH/rel/tmpdata/dev$i"}.
-{view_dir, "$DIRPATH/rel/tmpdata/dev$i"}.
+{prefix, "$rootdir/rel/dev$i"}.
+{data_dir, "$rootdir/rel/tmpdata/dev$i"}.
+{view_dir, "$rootdir/rel/tmpdata/dev$i"}.
{node_name, "-name dev$i@127.0.0.1"}.
{cluster_port, `expr 10000 \* $i + 5984`}.
{backend_port, `expr 10000 \* $i + 5986`}.
EOF
done
-rebar get-deps && rebar update-deps && cat rel/couchdb.config
+
+echo "==> updating dependencies"
+rebar get-deps update-deps
diff --git a/rebar.config.script b/rebar.config.script
index b541d0299..e57249534 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -10,7 +10,11 @@
% License for the specific language governing permissions and limitations under
% the License.
-{require_otp_vsn, "R14B01|R14B03|R14B04|R15B02|R15B03|R16"}.
+% Set the path to the configuration environment generated
+% by `./configure`.
+ConfigureEnv = filename:join(filename:dirname(SCRIPT), "config.erl"),
+os:putenv("COUCHDB_CONFIG", ConfigureEnv).
+
DepDescs = [
{chttpd, "couchdb-chttpd", {branch, import}},
@@ -38,6 +42,7 @@ MakeDep = fun({AppName, RepoName, Version}) ->
end,
AddConfig = [
+ {require_otp_vsn, "R14B01|R14B03|R14B04|R15B02|R15B03|R16"},
{deps_dir, "src"},
{deps, lists:map(MakeDep, DepDescs)},
{sub_dirs, ["rel"]},