Index: /main/trunk/greenstone2/common-src/indexers/Makefile.in
===================================================================
--- /main/trunk/greenstone2/common-src/indexers/Makefile.in	(revision 21327)
+++ /main/trunk/greenstone2/common-src/indexers/Makefile.in	(revision 21328)
@@ -37,10 +37,34 @@
 endif
 
-INDEXERDIRS = $(UNAC) mg mgpp lucene-gs 
+ENABLE_MG=@ENABLE_MG@
+ifeq ($(ENABLE_MG), 1)
+MG=mg
+else
+MG=
+endif
+
+ENABLE_MGPP=@ENABLE_MGPP@
+ifeq ($(ENABLE_MGPP), 1)
+MGPP=mgpp
+else
+MGPP=
+endif
+
+ENABLE_LUCENE=@ENABLE_LUCENE@
+ifeq ($(ENABLE_LUCENE), 1)
+LUCENE=lucene-gs
+else
+LUCENE=
+endif
+
+INDEXERDIRS = $(UNAC) $(MG) $(MGPP) $(LUCENE)
+
 
 all install clean:
 	for odir in $(INDEXERDIRS); do \
-          echo making $@ in $$odir; \
-          (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
+	  if test -d $$odir; then \
+	    echo making $@ in $$odir; \
+	    (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
+	  fi; \
         done
 
@@ -50,5 +74,5 @@
           (cd $$odir && $(MAKE) $(MDEFINES) all) || exit 1; \
         done
-	for odir in mg mgpp; do \
+	for odir in $(MG) $(MGPP); do \
           echo making $@ in $$odir; \
           (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
@@ -60,5 +84,5 @@
           (cd $$odir && $(MAKE) $(MDEFINES) install) || exit 1; \
         done
-	for odir in mg mgpp; do \
+	for odir in $(MG) $(MGPP); do \
           echo making $@ in $$odir; \
           (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
@@ -66,9 +90,9 @@
 
 javaonly:
-	for odir in mg mgpp; do \
+	for odir in $(MG) $(MGPP); do \
           echo making $@ in $$odir; \
           (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
         done
-	for odir in lucene-gs; do \
+	for odir in $(LUCENE); do \
           echo making $@ in $$odir; \
           (cd $$odir && $(MAKE) $(MDEFINES) all) || exit 1; \
@@ -76,9 +100,9 @@
 
 install-javaonly:
-	for odir in mg mgpp; do \
+	for odir in $(MG) $(MGPP); do \
           echo making $@ in $$odir; \
           (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
         done
-	for odir in lucene-gs; do \
+	for odir in $(LUCENE); do \
           echo making $@ in $$odir; \
           (cd $$odir && $(MAKE) $(MDEFINES) install) || exit 1; \
@@ -87,9 +111,9 @@
 # make everything except jni stuff
 gs2:
-	for odir in $(UNAC) lucene-gs; do \
+	for odir in $(UNAC) $(LUCENE); do \
           echo making $@ in $$odir; \
           (cd $$odir && $(MAKE) $(MDEFINES) all) || exit 1; \
         done
-	for odir in mg mgpp; do \
+	for odir in $(MG) $(MGPP); do \
           echo making $@ in $$odir; \
           (cd $$odir && $(MAKE) $(MDEFINES) nojava) || exit 1; \
@@ -97,9 +121,9 @@
 
 install-gs2:
-	for odir in $(UNAC) lucene-gs; do \
+	for odir in $(UNAC) $(LUCENE); do \
           echo making $@ in $$odir; \
           (cd $$odir && $(MAKE) $(MDEFINES) install) || exit 1; \
         done
-	for odir in mg mgpp; do \
+	for odir in $(MG) $(MGPP); do \
           echo making $@ in $$odir; \
           (cd $$odir && $(MAKE) $(MDEFINES) install-nojava) || exit 1; \
@@ -108,6 +132,8 @@
 distclean:
 	for odir in $(INDEXERDIRS); do \
-          echo making $@ in $$odir; \
-          (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
+	  if test -d $$odir; then \
+	    echo making $@ in $$odir; \
+	    (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
+	  fi; \
         done
 	rm -f Makefile config.status config.log
Index: /main/trunk/greenstone2/common-src/indexers/configure
===================================================================
--- /main/trunk/greenstone2/common-src/indexers/configure	(revision 21327)
+++ /main/trunk/greenstone2/common-src/indexers/configure	(revision 21328)
@@ -272,8 +272,8 @@
 PACKAGE_BUGREPORT=
 
-ac_unique_file="mgpp/text/MGQuery.cpp"
 ac_subdirs_all="$ac_subdirs_all packages/unac"
-ac_subdirs_all="$ac_subdirs_all mg mgpp"
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS ENABLE_ACCENTFOLD COMPAT32BITFLAGS JAVAC JAVA uudecode subdirs LIBOBJS LTLIBOBJS'
+ac_subdirs_all="$ac_subdirs_all mg"
+ac_subdirs_all="$ac_subdirs_all mgpp"
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS ENABLE_ACCENTFOLD ENABLE_MG ENABLE_MGPP ENABLE_LUCENE COMPAT32BITFLAGS JAVAC JAVA uudecode subdirs LIBOBJS LTLIBOBJS'
 ac_subst_files=''
 
@@ -786,5 +786,8 @@
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
-  --disable-accentfold    Disable Accent Folding support
+  --disable-accentfolding    Disable Accent Folding support
+  --disable-mg        Disable MG compilation
+  --disable-mgpp        Disable MGPP compilation
+  --disable-lucene        Disable Lucene compilation
 
 Optional Packages:
@@ -1242,4 +1245,61 @@
 
 
+
+# Check whether --enable-mg or --disable-mg was given.
+if test "${enable_mg+set}" = set; then
+  enableval="$enable_mg"
+  ENABLE_MG=$enableval
+else
+  ENABLE_MG=yes
+fi;
+if test $ENABLE_MG = "yes" -o $ENABLE_MG = "1" ; then
+  ENABLE_MG=1
+  cat >>confdefs.h <<\_ACEOF
+#define ENABLE_MG
+_ACEOF
+
+else
+  ENABLE_MG=0
+fi
+
+
+
+# Check whether --enable-mgpp or --disable-mgpp was given.
+if test "${enable_mgpp+set}" = set; then
+  enableval="$enable_mgpp"
+  ENABLE_MGPP=$enableval
+else
+  ENABLE_MGPP=yes
+fi;
+if test $ENABLE_MGPP = "yes" -o $ENABLE_MGPP = "1" ; then
+  ENABLE_MGPP=1
+  cat >>confdefs.h <<\_ACEOF
+#define ENABLE_MGPP
+_ACEOF
+
+else
+  ENABLE_MGPP=0
+fi
+
+
+# Check whether --enable-lucene or --disable-lucene was given.
+if test "${enable_lucene+set}" = set; then
+  enableval="$enable_lucene"
+  ENABLE_LUCENE=$enableval
+else
+  ENABLE_LUCENE=yes
+fi;
+if test $ENABLE_LUCENE = "yes" -o $ENABLE_LUCENE = "1" ; then
+  ENABLE_LUCENE=1
+  cat >>confdefs.h <<\_ACEOF
+#define ENABLE_LUCENE
+_ACEOF
+
+else
+  ENABLE_LUCENE=0
+fi
+
+
+
 cat >>confdefs.h <<_ACEOF
 #define COMPAT32BITFLAGS $COMPAT32BITFLAGS
@@ -1348,5 +1408,5 @@
 CLASS_TEST=Test.class
 cat << \EOF > $JAVA_TEST
-/* #line 1350 "configure" */
+/* #line 1410 "configure" */
 public class Test {
 }
@@ -1518,5 +1578,5 @@
         ac_cv_prog_uudecode_base64=yes
 else
-        echo "configure: 1520: uudecode had trouble decoding base 64 file 'Test.uue'" >&5
+        echo "configure: 1580: uudecode had trouble decoding base 64 file 'Test.uue'" >&5
         echo "configure: failed file was:" >&5
         cat Test.uue >&5
@@ -1636,5 +1696,5 @@
 CLASS_TEST=Test.class
 cat << \EOF > $JAVA_TEST
-/* #line 1638 "configure" */
+/* #line 1698 "configure" */
 public class Test {
 }
@@ -1673,5 +1733,5 @@
 TEST=Test
 cat << \EOF > $JAVA_TEST
-/* [#]line 1675 "configure" */
+/* [#]line 1735 "configure" */
 public class Test {
 public static void main (String args[]) {
@@ -1765,7 +1825,32 @@
 
 
-
-subdirs="$subdirs mg mgpp"
-
+if test $ENABLE_MG = 1; then
+if test ! -d mg; then
+echo "***** Folder mg does not exist, cannot ENABLE_MG.";
+exit 1;
+fi
+
+
+subdirs="$subdirs mg"
+
+fi
+
+if test $ENABLE_MGPP = 1; then
+if test ! -d mgpp; then
+echo "***** Folder mgpp does not exist, cannot ENABLE_MGPP.";
+exit 1;
+fi
+
+
+subdirs="$subdirs mgpp"
+
+fi
+
+if test $ENABLE_LUCENE = 1; then
+if test ! -d lucene-gs; then
+echo "***** Folder lucene-gs does not exist, cannot ENABLE_LUCENE.";
+exit 1;
+fi
+fi
 
           ac_config_files="$ac_config_files Makefile"
@@ -2405,4 +2490,7 @@
 s,@LIBS@,$LIBS,;t t
 s,@ENABLE_ACCENTFOLD@,$ENABLE_ACCENTFOLD,;t t
+s,@ENABLE_MG@,$ENABLE_MG,;t t
+s,@ENABLE_MGPP@,$ENABLE_MGPP,;t t
+s,@ENABLE_LUCENE@,$ENABLE_LUCENE,;t t
 s,@COMPAT32BITFLAGS@,$COMPAT32BITFLAGS,;t t
 s,@JAVAC@,$JAVAC,;t t
Index: /main/trunk/greenstone2/common-src/indexers/configure.ac
===================================================================
--- /main/trunk/greenstone2/common-src/indexers/configure.ac	(revision 21327)
+++ /main/trunk/greenstone2/common-src/indexers/configure.ac	(revision 21328)
@@ -3,8 +3,49 @@
 dnl
 
-AC_INIT(mgpp/text/MGQuery.cpp)
-AC_ARG_ENABLE(accentfolding, [  --disable-accentfold    Disable Accent Folding support], ENABLE_ACCENTFOLD=0, ENABLE_ACCENTFOLD=1)
+dnl AC_INIT(mgpp/text/MGQuery.cpp)
+dnl http://www.gnu.org/software/hello/manual/autoconf/Initializing-configure.html
+AC_INIT()
+AC_ARG_ENABLE(accentfolding, [  --disable-accentfolding    Disable Accent Folding support], ENABLE_ACCENTFOLD=0, ENABLE_ACCENTFOLD=1)
 AC_DEFINE_UNQUOTED(ENABLE_ACCENTFOLD, $ENABLE_ACCENTFOLD)
 AC_SUBST(ENABLE_ACCENTFOLD)
+
+
+dnl
+dnl Set compilation of MG (enabled by default)
+dnl
+AC_ARG_ENABLE(mg, [  --disable-mg        Disable MG compilation], ENABLE_MG=$enableval, ENABLE_MG=yes)
+if test $ENABLE_MG = "yes" -o $ENABLE_MG = "1" ; then
+  ENABLE_MG=1
+  AC_DEFINE(ENABLE_MG,[])
+else
+  ENABLE_MG=0
+fi
+AC_SUBST(ENABLE_MG)
+
+
+dnl
+dnl Set compilation of MGPP (enabled by default)
+dnl
+AC_ARG_ENABLE(mgpp, [  --disable-mgpp        Disable MGPP compilation], ENABLE_MGPP=$enableval, ENABLE_MGPP=yes)
+if test $ENABLE_MGPP = "yes" -o $ENABLE_MGPP = "1" ; then
+  ENABLE_MGPP=1
+  AC_DEFINE(ENABLE_MGPP,[])
+else
+  ENABLE_MGPP=0
+fi
+AC_SUBST(ENABLE_MGPP)
+
+dnl
+dnl Set compilation of Lucene (enabled by default)
+dnl
+AC_ARG_ENABLE(lucene, [  --disable-lucene        Disable Lucene compilation], ENABLE_LUCENE=$enableval, ENABLE_LUCENE=yes)
+if test $ENABLE_LUCENE = "yes" -o $ENABLE_LUCENE = "1" ; then
+  ENABLE_LUCENE=1
+  AC_DEFINE(ENABLE_LUCENE,[])
+else
+  ENABLE_LUCENE=0
+fi
+AC_SUBST(ENABLE_LUCENE)
+
 
 AC_DEFINE_UNQUOTED(COMPAT32BITFLAGS, $COMPAT32BITFLAGS)
@@ -32,5 +73,28 @@
 fi
 
-AC_CONFIG_SUBDIRS(mg mgpp)
+dnl AC_CONFIG_SUBDIRS(mg mgpp)
+
+if test $ENABLE_MG = 1; then
+if test ! -d mg; then
+echo "***** Folder mg does not exist, cannot ENABLE_MG.";
+exit 1;
+fi
+AC_CONFIG_SUBDIRS(mg)
+fi
+
+if test $ENABLE_MGPP = 1; then
+if test ! -d mgpp; then
+echo "***** Folder mgpp does not exist, cannot ENABLE_MGPP.";
+exit 1;
+fi
+AC_CONFIG_SUBDIRS(mgpp)
+fi
+
+if test $ENABLE_LUCENE = 1; then
+if test ! -d lucene-gs; then
+echo "***** Folder lucene-gs does not exist, cannot ENABLE_LUCENE.";
+exit 1;
+fi
+fi
 
 AC_OUTPUT(Makefile)
Index: /main/trunk/greenstone2/common-src/indexers/winMake.bat
===================================================================
--- /main/trunk/greenstone2/common-src/indexers/winMake.bat	(revision 21327)
+++ /main/trunk/greenstone2/common-src/indexers/winMake.bat	(revision 21328)
@@ -10,4 +10,24 @@
 )
 
+:: ENABLE_MG/MGPP/LUCENE are guaranteed to be set to either 1 or 0 at this point
+set MAKE_VARS=%MAKE_VARS% ENABLE_MG=%ENABLE_MG%
+set MAKE_VARS=%MAKE_VARS% ENABLE_MGPP=%ENABLE_MGPP%
+set MAKE_VARS=%MAKE_VARS% ENABLE_LUCENE=%ENABLE_LUCENE%
+
+if "%ENABLE_MG%" == "1" if not exist mg (
+  echo ***** Folder mg does not exist, cannot ENABLE_MG.
+  goto failed
+)
+
+if "%ENABLE_MGPP%" == "1" if not exist mgpp (
+  echo ***** Folder mgpp does not exist, cannot ENABLE_MGPP.
+  goto failed
+)
+
+if "%ENABLE_LUCENE%" == "1" if not exist lucene-gs (
+  echo ***** Folder lucene-gs does not exist, cannot ENABLE_LUCENE.
+  goto failed
+)
+
 if ""%1"" == """" goto all
 if ""%1"" == ""all"" goto go
@@ -17,5 +37,5 @@
 :unknown
 	echo Error: Unrecognized argument %1.
-	goto done
+	goto failed
 
 :clean
@@ -41,15 +61,21 @@
 	cd ..\..
 
-	cd mg
-	call winMake.bat %1
-	cd ..
+	if "%ENABLE_MG%" == "1" (
+	  cd mg
+	  call winMake.bat %1
+	  cd ..
+	)
 
-	cd mgpp
-	call winMake.bat %1 
-	cd ..
-	
-	cd lucene-gs
-	call winMake.bat %1
-	cd ..
+	if "%ENABLE_MGPP%" == "1" (
+	  cd mgpp
+	  call winMake.bat %1 
+	  cd ..
+	)
+
+	if "%ENABLE_LUCENE%" == "1" (
+	  cd lucene-gs
+	  call winMake.bat %1
+	  cd ..
+	)
 
 	if ""%1"" == ""clean"" goto clean2 
@@ -63,15 +89,21 @@
 
 :java
-	cd mg
-	call winMake.bat %1 javaonly
-	cd ..
+	if "%ENABLE_MG%" == "1" (
+	  cd mg
+	  call winMake.bat %1 javaonly
+	  cd ..
+	)
 
-	cd mgpp
-	call winMake.bat %1 javaonly
-	cd ..
+	if "%ENABLE_MGPP%" == "1" (
+	  cd mgpp
+	  call winMake.bat %1 javaonly
+	  cd ..
+	)
 	
-	cd lucene-gs
-	call winMake.bat %1 
-	cd ..
+	if "%ENABLE_LUCENE%" == "1" (
+	  cd lucene-gs
+	  call winMake.bat %1 
+	  cd ..
+	)
 	goto done
 
@@ -86,11 +118,15 @@
 	cd ..\..
 
-	cd mg
-	call winMake.bat %1 nojava
-	cd ..
-
-	cd mgpp
-	call winMake.bat %1 nojava
-	cd ..
+	if "%ENABLE_MG%" == "1" (
+	  cd mg
+	  call winMake.bat %1 nojava
+	  cd ..
+	)
+	
+	if "%ENABLE_MGPP%" == "1" (
+	  cd mgpp
+	  call winMake.bat %1 nojava
+	  cd ..
+	)
 	goto done
 
@@ -107,16 +143,27 @@
 	cd ..\..
 
-	cd mg
-	call winMake.bat %1 nojava
-	cd ..
+	if "%ENABLE_MG%" == "1" (
+	  cd mg
+	  call winMake.bat %1 nojava
+	  cd ..
+	)
 
-	cd mgpp
-	call winMake.bat %1 nojava
-	cd ..
-	
-	cd lucene-gs
-	call winMake.bat %1
-	cd ..
+	if "%ENABLE_MGPP%" == "1" (
+	  cd mgpp
+	  call winMake.bat %1 nojava
+	  cd ..
+	)
+
+	if "%ENABLE_LUCENE%" == "1" (	
+	  cd lucene-gs
+	  call winMake.bat %1
+	  cd ..
+	)
 	goto done
 
+
+:failed
+echo ***** Compilation terminated with failure in %~dp0%0
+exit /b 1
+
 :done
