--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for rjags 3.
+# Generated by GNU Autoconf 2.69 for rjags 4.
 #
 #
 # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
@@ -577,8 +577,8 @@
 # Identity of this package.
 PACKAGE_NAME='rjags'
 PACKAGE_TARNAME='rjags'
-PACKAGE_VERSION='3'
-PACKAGE_STRING='rjags 3'
+PACKAGE_VERSION='4'
+PACKAGE_STRING='rjags 4'
 PACKAGE_BUGREPORT=''
 PACKAGE_URL=''
 
@@ -621,9 +621,9 @@
 ac_subst_vars='LTLIBOBJS
 LIBOBJS
 JAGS_RPATH
-JAGS_MODULES
-JAGS_LIB
-JAGS_INCLUDE
+JAGS_MODDIR
+JAGS_LIBDIR
+JAGS_PKGINCLUDEDIR
 ac_ct_CC
 CFLAGS
 CC
@@ -679,10 +679,10 @@
 ac_subst_files=''
 ac_user_opts='
 enable_option_checking
-with_jags_include
-with_jags_lib
+with_jags_prefix
+with_jags_includedir
+with_jags_libdir
 enable_rpath
-with_jags_modules
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1236,7 +1236,7 @@
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures rjags 3 to adapt to many kinds of systems.
+\`configure' configures rjags 4 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1297,7 +1297,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of rjags 3:";;
+     short | recursive ) echo "Configuration of rjags 4:";;
    esac
   cat <<\_ACEOF
 
@@ -1310,12 +1310,12 @@
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
-  --with-jags-include=INCLUDE_PATH
-                          the location of JAGS header files
-  --with-jags-lib=LIB_PATH
-                          the location of the JAGS library
-  --with-jags-modules=MOD_PATH
-                          the location of the JAGS modules
+  --with-jags-prefix=PREFIX_PATH
+                          the prefix used when JAGS was installed
+  --with-jags-includedir=INCLUDE_PATH
+                          the value of includedir used when JAGS was installed
+  --with-jags-libdir=LIB_PATH
+                          the value of libdir used when JAGS was installed
 
 Some influential environment variables:
   CXX         C++ compiler command
@@ -1395,7 +1395,7 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-rjags configure 3
+rjags configure 4
 generated by GNU Autoconf 2.69
 
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1731,7 +1731,7 @@
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by rjags $as_me 3, which was
+It was created by rjags $as_me 4, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
@@ -2089,6 +2089,8 @@
 CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXXFLAGS`
 CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS`
 
+# Guess the installation prefix from location of the jags executable
+
 if test "x$prefix" = xNONE; then
   $as_echo_n "checking for prefix by " >&6
   # Extract the first word of "jags", so it can be a program name with args.
@@ -2182,26 +2184,47 @@
 fi
 
 
-#Set optional include path with option --with-jags-include or
-#environment variable JAGS_INCLUDE
-
-
-# Check whether --with-jags-include was given.
-if test "${with_jags_include+set}" = set; then :
-  withval=$with_jags_include; jags_include_path=$withval
-fi
-
-if test  -n "$jags_include_path"  ; then
-   JAGS_INCLUDE=${jags_include_path}
-else
-   if test  -z "${JAGS_INCLUDE}"  ; then
+# For installations in a non-standard location, set the prefix
+# manually, using either option --with-jags-prefix or environment
+# variable JAGS_PREFIX. Otherwise we accept the guess from
+# AC_PREFIX_PROGRAM.
+
+
+# Check whether --with-jags-prefix was given.
+if test "${with_jags_prefix+set}" = set; then :
+  withval=$with_jags_prefix; jags_prefix_path=$withval
+fi
+
+if test  -n "$jags_prefix_path"  ; then
+   JAGS_PREFIX=${jags_prefix_path}
+else
+   if test  -z "${JAGS_PREFIX}"  ; then
       if test  "$prefix" = "NONE" ; then
-         as_fn_error $? "\"Location of JAGS headers not defined. Use configure arg '--with-jags-include' or environment variable 'JAGS_INCLUDE'\"" "$LINENO" 5
+         as_fn_error $? "\"Automatic detection of JAGS failed. Please supply the prefix for JAGS with the --with-jags-prefix option. See the README file for details.\"" "$LINENO" 5
       else
-         JAGS_INCLUDE=${prefix}/include/JAGS
+         JAGS_PREFIX=${prefix}
       fi
    fi
 fi
+
+# Set include path with option --with-jags-includedir or environment
+# variable JAGS_INCLUDEDIR. By default, this is determined from
+# JAGS_PREFIX.
+
+
+# Check whether --with-jags-includedir was given.
+if test "${with_jags_includedir+set}" = set; then :
+  withval=$with_jags_includedir; jags_include_path=$withval
+fi
+
+if test  -n "$jags_include_path"  ; then
+   JAGS_INCLUDEDIR=${jags_include_path}
+else
+   if test  -z "${JAGS_INCLUDEDIR}"  ; then
+      JAGS_INCLUDEDIR=${JAGS_PREFIX}/include
+   fi
+fi
+JAGS_PKGINCLUDEDIR=${JAGS_INCLUDEDIR}/JAGS
 
 ac_ext=cpp
 ac_cpp='$CXXCPP $CPPFLAGS'
@@ -2210,7 +2233,7 @@
 ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 
 OCPPFLAGS=${CPPFLAGS}
-CPPFLAGS=-I${JAGS_INCLUDE}
+CPPFLAGS=-I${JAGS_PKGINCLUDEDIR}
 ac_ext=cpp
 ac_cpp='$CXXCPP $CPPFLAGS'
 ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -3116,10 +3139,7 @@
 if test "x$ac_cv_header_Console_h" = xyes; then :
 
 else
-  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "\"Problem with header file ${JAGS_INCLUDE}/Console.h \"
-See \`config.log' for more details" "$LINENO" 5; }
+  as_fn_error $? "\"Cannot find header file ${JAGS_PKGINCLUDEDIR}/Console.h. See the README file for help.\"" "$LINENO" 5
 fi
 
 
@@ -3135,7 +3155,7 @@
 # There is no consensus on where 64- versus 32-bit libraries should be
 # installed.  We take a hint from R, assuming that if R is installed
 # in, say, /usr/LIBnn/R then we can find the jags library in
-# ${prefix}/LIBnn.
+# ${JAGS_PREFIX}/LIBnn.
 #
 # This is a reasonable assumption if both JAGS and R have been
 # properly packaged, but may not be true if either has been manually
@@ -3146,26 +3166,28 @@
    LIBnn=`"${R_HOME}/bin/R" CMD config LIBnn`
 fi
 
-#Set optional library path with option --with-jags-lib or
-#environment variable JAGS_LIBS
-
-
-# Check whether --with-jags-lib was given.
-if test "${with_jags_lib+set}" = set; then :
-  withval=$with_jags_lib; jags_lib_path=$withval
+# Set optional library path with option --with-jags-libdir or
+# environment variable JAGS_LIBDIR. By default this is determined by
+# JAGS_PREFIX and LIBnn.
+
+
+# Check whether --with-jags-libdir was given.
+if test "${with_jags_libdir+set}" = set; then :
+  withval=$with_jags_libdir; jags_lib_path=$withval
 fi
 
 if test  -n "$jags_lib_path"  ; then
-   JAGS_LIB=$jags_lib_path
-else
-   if test  -z "${JAGS_LIB}"  ; then
-      if test  "${prefix}" = "NONE"  ; then
-         as_fn_error $? "\"Location of JAGS library not defined. Use configure arg '--with-jags-lib' or environment variable 'JAGS_LIB'\"" "$LINENO" 5
-      else
-         JAGS_LIB=${prefix}/${LIBnn}
-      fi
+   JAGS_LIBDIR=$jags_lib_path
+else
+   if test  -z "${JAGS_LIBDIR}"  ; then
+      JAGS_LIBDIR=${JAGS_PREFIX}/${LIBnn}
    fi
 fi
+
+
+# Set location of modules
+
+JAGS_MODDIR=${JAGS_LIBDIR}/JAGS/modules-${PACKAGE_VERSION}
 
 # Support for private installations of JAGS. If the jags library is not
 # on the linker path then it helps to hard-code the location of JAGS into
@@ -3177,7 +3199,7 @@
 fi
 
 if test  "x$enable_rpath" = "xyes"; then
-   JAGS_RPATH="-Wl,-rpath ${JAGS_LIB}"
+   JAGS_RPATH="-Wl,-rpath ${JAGS_LIBDIR}"
 fi
 
 OLDFLAGS=${LDFLAGS}
@@ -3187,7 +3209,7 @@
 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
-LDFLAGS="-L${JAGS_LIB}"
+LDFLAGS="-L${JAGS_LIBDIR}"
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -3772,9 +3794,8 @@
   LIBS="-ljags $LIBS"
 
 else
-  as_fn_error $? "\"Cannot load JAGS library in ${JAGS_LIB}\"" "$LINENO" 5
-fi
-
+  as_fn_error $? "\"Cannot load JAGS library in ${JAGS_LIBDIR}. See the README file for help.\"" "$LINENO" 5
+fi
 
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
@@ -3783,26 +3804,6 @@
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 LDFLAGS=${OLDFLAGS}
-
-#Finally, set optional module directory using --with-jags-modules or
-#environment variable JAGS_MODULES
-
-
-# Check whether --with-jags-modules was given.
-if test "${with_jags_modules+set}" = set; then :
-  withval=$with_jags_modules; jags_mod_path=$withval
-fi
-
-if test  -n "$jags_mod_path"  ; then
-   JAGS_MODULES=$jags_mod_path
-else
-   if test  -z "${JAGS_MODULES}"  ; then
-      JAGS_MODULES=${JAGS_LIB}/JAGS/modules-${PACKAGE_VERSION}
-      if test ! -d ${JAGS_MODULES} ; then
-         as_fn_error $? "\"JAGS module directory ${JAGS_MODULES} does not exist.\"" "$LINENO" 5
-      fi
-   fi
-fi
 
 
 
@@ -4353,7 +4354,7 @@
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by rjags $as_me 3, which was
+This file was extended by rjags $as_me 4, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -4406,7 +4407,7 @@
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-rjags config.status 3
+rjags config.status 4
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 
@@ -5510,7 +5511,7 @@
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by rjags $as_me 3, which was
+This file was extended by rjags $as_me 4, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -5563,7 +5564,7 @@
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-rjags config.status 3
+rjags config.status 4
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"