[med-svn] [ngs-sdk] 01/03: Imported Upstream version 1.0.1

Andreas Tille tille at debian.org
Mon Feb 2 10:44:26 UTC 2015


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to branch master
in repository ngs-sdk.

commit 3387fabec383ff729ad90d610483f66148dd8b67
Author: Andreas Tille <tille at debian.org>
Date:   Mon Feb 2 11:43:29 2015 +0100

    Imported Upstream version 1.0.1
---
 .gitignore                                         |    5 +-
 ngs-python/Makefile => Makefile                    |   39 +-
 configure                                          |   32 +-
 ngs-bam/.gitignore                                 |    2 +
 {ngs-python => ngs-bam}/Makefile                   |   24 +-
 ngs-bam/Makefile.libs                              |  112 ++
 {ngs-sdk => ngs-bam}/Makefile.rules                |    8 +-
 ngs-bam/bam.cpp                                    |  682 ++++++++++
 ngs-bam/bam.hpp                                    |  547 ++++++++
 {ngs-python => ngs-bam}/configure                  |    6 +-
 ngs-bam/ngs-bam.cpp                                |  632 ++++++++++
 ngs-bam/ngs-bam/ngs-bam.hpp                        |   45 +
 ngs-python/configure => ngs-bam/setup/install      |   10 +-
 ngs-bam/setup/install.perl                         | 1324 ++++++++++++++++++++
 ngs-bam/setup/install.prl                          |    6 +
 {ngs-java => ngs-bam/setup}/konfigure.perl         |  782 ++++++++----
 .../configure => ngs-bam/setup/ngs-bam/install     |   12 +-
 ngs-bam/setup/ngs-bam/linux/os.prl                 |    2 +
 ngs-bam/setup/ngs-bam/mac/os.prl                   |    2 +
 {ngs-java => ngs-bam/setup}/os-arch.perl           |    4 +-
 ngs-java/os-arch.pm => ngs-bam/setup/os-arch.prl   |    6 +-
 ngs-bam/setup/package.prl                          |   31 +
 ngs-java/.gitignore                                |    9 +-
 ngs-java/Makefile.java                             |   45 +-
 ngs-java/Makefile.rules                            |    4 +-
 ngs-java/configure                                 |    6 +-
 .../gov/nih/nlm/ncbi/ngs/HttpException.java        |   27 +-
 ngs-java/gov/nih/nlm/ncbi/ngs/HttpManager.java     |   94 +-
 ngs-java/gov/nih/nlm/ncbi/ngs/LibManager.java      |  122 +-
 ngs-java/gov/nih/nlm/ncbi/ngs/LibPathIterator.java |   95 +-
 ngs-java/gov/nih/nlm/ncbi/ngs/Makefile             |   37 +-
 ngs-java/gov/nih/nlm/ncbi/ngs/Manager.java         |   13 +-
 ngs-java/ngs/Alignment.java                        |    9 +
 ngs-java/ngs/Fragment.java                         |    4 +-
 ngs-java/ngs/Read.java                             |    4 +-
 ngs-java/ngs/ReadCollection.java                   |    5 +-
 ngs-java/ngs/Reference.java                        |    4 +-
 ngs-java/ngs/itf/AlignmentItf.java                 |   12 +
 ngs-java/package.pm                                |   29 -
 ngs-python/configure => ngs-java/setup/install     |   10 +-
 ngs-java/setup/install.perl                        | 1324 ++++++++++++++++++++
 ngs-java/setup/install.prl                         |    4 +
 {ngs-python => ngs-java/setup}/konfigure.perl      |  782 ++++++++----
 .../configure => ngs-java/setup/ngs-java/install   |   12 +-
 ngs-java/setup/ngs-java/linux/os.prl               |    2 +
 ngs-java/setup/ngs-java/mac/os.prl                 |    2 +
 {ngs-python => ngs-java/setup}/os-arch.perl        |    4 +-
 ngs-sdk/os-arch.pm => ngs-java/setup/os-arch.prl   |    6 +-
 ngs-java/setup/package.prl                         |   17 +
 ngs-java/win-configure.bat                         |    2 -
 ngs-python/.gitignore                              |    9 +-
 ngs-python/Makefile                                |    2 +-
 ngs-python/Makefile.python                         |   17 +-
 ngs-python/Makefile.rules                          |    4 +-
 ngs-python/configure                               |    6 +-
 ngs-python/examples/AlignSliceTest.py              |   67 +
 ngs-python/examples/AlignSliceTest26.py            |   67 +
 ngs-python/examples/AlignTest.py                   |   73 ++
 ngs-python/examples/AlignTest26.py                 |   73 ++
 ngs-python/examples/FragTest.py                    |   70 ++
 ngs-python/examples/FragTest26.py                  |   70 ++
 ngs-python/examples/RefTest.py                     |   62 +
 ngs-python/examples/RefTest26.py                   |   63 +
 ngs-python/ngs/Alignment.py                        |   47 +-
 ngs-python/ngs/AlignmentIterator.py                |    4 +-
 ngs-python/ngs/Fragment.py                         |   30 +-
 ngs-python/ngs/FragmentIterator.py                 |    4 +-
 ngs-python/ngs/LibManager.py                       |  187 ++-
 ngs-python/ngs/Pileup.py                           |    6 +-
 ngs-python/ngs/PileupEvent.py                      |    6 +-
 ngs-python/ngs/PileupEventIterator.py              |    4 +-
 ngs-python/ngs/PileupIterator.py                   |    4 +-
 ngs-python/ngs/Read.py                             |   31 +-
 ngs-python/ngs/ReadCollection.py                   |  107 +-
 ngs-python/ngs/ReadGroup.py                        |    6 +-
 ngs-python/ngs/ReadGroupIterator.py                |    4 +-
 ngs-python/ngs/ReadIterator.py                     |    4 +-
 ngs-python/ngs/Refcount.py                         |   12 +-
 ngs-python/ngs/Reference.py                        |   68 +-
 ngs-python/ngs/ReferenceIterator.py                |    4 +-
 ngs-python/ngs/Statistics.py                       |   50 +-
 ngs-python/ngs/String.py                           |   26 +-
 ngs-python/ngs/__init__.py                         |    2 +-
 ngs-python/setup.py                                |    8 +-
 ngs-python/{configure => setup/install}            |   10 +-
 ngs-python/setup/install.perl                      | 1324 ++++++++++++++++++++
 ngs-python/setup/install.prl                       |    4 +
 {ngs-sdk => ngs-python/setup}/konfigure.perl       |  782 ++++++++----
 ngs-python/{configure => setup/ngs-python/install} |   12 +-
 ngs-python/setup/ngs-python/linux/os.prl           |    2 +
 ngs-python/setup/ngs-python/mac/os.prl             |    2 +
 {ngs-sdk => ngs-python/setup}/os-arch.perl         |    4 +-
 ngs-python/{os-arch.pm => setup/os-arch.prl}       |    6 +-
 ngs-python/{package.pm => setup/package.prl}       |   26 +-
 ngs-python/win-configure.bat                       |    1 -
 ngs-sdk/.gitignore                                 |   13 +-
 ngs-sdk/Makefile.install                           |   18 +-
 ngs-sdk/Makefile.libs                              |   14 +-
 ngs-sdk/Makefile.rules                             |    4 +-
 ngs-sdk/adapter/AlignmentItf.cpp                   |   23 +-
 ngs-sdk/adapter/Makefile                           |    2 +-
 .../{ngs/defs.h => adapter/unix/fat86/atomic32.h}  |   20 +-
 ngs-sdk/configure                                  |    6 +-
 ngs-sdk/dispatch/AlignmentItf.cpp                  |   24 +
 ngs-sdk/language/java/jni_AlignmentItf.cpp         |   28 +
 ngs-sdk/language/java/jni_AlignmentItf.h           |    8 +
 ngs-sdk/language/python/py_AlignmentItf.cpp        |    1 +
 ngs-sdk/language/python/py_AlignmentItf.h          |    1 +
 ngs-sdk/ngs/Alignment.hpp                          |   10 +-
 ngs-sdk/ngs/AlignmentIterator.hpp                  |    2 +-
 ngs-sdk/ngs/Fragment.hpp                           |    2 +-
 ngs-sdk/ngs/FragmentIterator.hpp                   |    2 +-
 ngs-sdk/ngs/Pileup.hpp                             |    2 +-
 ngs-sdk/ngs/PileupEvent.hpp                        |   47 +-
 ngs-sdk/ngs/PileupEventIterator.hpp                |    2 +-
 ngs-sdk/ngs/PileupIterator.hpp                     |    2 +-
 ngs-sdk/ngs/Read.hpp                               |    2 +-
 ngs-sdk/ngs/ReadCollection.hpp                     |    2 +-
 ngs-sdk/ngs/ReadGroup.hpp                          |    2 +-
 ngs-sdk/ngs/ReadGroupIterator.hpp                  |    2 +-
 ngs-sdk/ngs/ReadIterator.hpp                       |    2 +-
 ngs-sdk/ngs/Reference.hpp                          |    2 +-
 ngs-sdk/ngs/ReferenceIterator.hpp                  |    2 +-
 ngs-sdk/ngs/Statistics.hpp                         |    2 +-
 ngs-sdk/ngs/StringRef.hpp                          |    8 +-
 ngs-sdk/ngs/adapter/AlignmentItf.hpp               |    2 +
 ngs-sdk/ngs/itf/AlignmentItf.h                     |    4 +
 ngs-sdk/ngs/itf/AlignmentItf.hpp                   |    4 +-
 ngs-sdk/ngs/itf/ErrBlock.hpp                       |    2 +-
 ngs-sdk/ngs/itf/ErrorMsg.hpp                       |    2 +-
 ngs-sdk/ngs/itf/FragmentItf.hpp                    |    2 +-
 ngs-sdk/ngs/itf/PileupEventItf.hpp                 |    2 +-
 ngs-sdk/ngs/itf/PileupItf.hpp                      |    2 +-
 ngs-sdk/ngs/itf/ReadCollectionItf.hpp              |    2 +-
 ngs-sdk/ngs/itf/ReadGroupItf.hpp                   |    2 +-
 ngs-sdk/ngs/itf/ReadItf.hpp                        |    2 +-
 ngs-sdk/ngs/itf/Refcount.hpp                       |    4 +-
 ngs-sdk/ngs/itf/ReferenceItf.hpp                   |    2 +-
 ngs-sdk/ngs/itf/StatisticsItf.hpp                  |    2 +-
 ngs-sdk/ngs/itf/StringItf.hpp                      |    2 +-
 ngs-sdk/ngs/itf/defs.h                             |   13 -
 ngs-python/configure => ngs-sdk/setup/install      |   10 +-
 ngs-sdk/setup/install.perl                         | 1324 ++++++++++++++++++++
 ngs-sdk/setup/install.prl                          |    6 +
 {ngs-java => ngs-sdk/setup}/konfigure.perl         |  782 ++++++++----
 .../configure => ngs-sdk/setup/ngs-c++/install     |   12 +-
 ngs-sdk/setup/ngs-c++/install.prl                  |    5 +
 ngs-sdk/setup/ngs-c++/linux/os.prl                 |    2 +
 ngs-sdk/setup/ngs-c++/mac/os.prl                   |    2 +
 .../setup/ngs-engine-dev/install                   |   12 +-
 ngs-sdk/setup/ngs-engine-dev/install.prl           |    5 +
 ngs-sdk/setup/ngs-engine-dev/linux/os.prl          |    2 +
 ngs-sdk/setup/ngs-engine-dev/mac/os.prl            |    2 +
 {ngs-java => ngs-sdk/setup}/os-arch.perl           |    4 +-
 ngs-java/os-arch.pm => ngs-sdk/setup/os-arch.prl   |    6 +-
 ngs-sdk/{package.pm => setup/package.prl}          |    3 +-
 ngs-sdk/test/test_engine/AlignmentItf.hpp          |    7 +-
 ngs-sdk/test/test_engine/PileupEventItf.hpp        |    2 +-
 ngs-sdk/test/test_engine/PileupItf.hpp             |    2 +-
 ngs-sdk/test/test_engine/ReadCollectionItf.hpp     |    2 +-
 ngs-sdk/test/test_engine/ReadGroupItf.hpp          |    2 +-
 ngs-sdk/test/test_engine/ReadItf.hpp               |    2 +-
 ngs-sdk/test/test_engine/ReferenceItf.hpp          |    2 +-
 ngs-sdk/test/test_engine/StatisticsItf.hpp         |    2 +-
 ngs-sdk/test/test_engine/test_engine.cpp           |   18 +-
 ngs-sdk/test/test_engine/test_engine.hpp           |    2 +-
 ngs-sdk/win-configure.bat                          |    2 -
 ngs-sdk/win/lib-project.props                      |   13 +
 ngs-sdk/win/libadapter.vcxproj                     |  211 +---
 ngs-sdk/win/libdispatch.vcxproj                    |  242 +---
 ngs-sdk/win/libngs-c++.vcxproj                     |  189 +--
 ngs-sdk/win/libngs.vcxproj                         |  187 ---
 ngs-sdk/win/libngs.vcxproj.filters                 |  123 --
 ngs-sdk/win/libtest_engine.vcxproj                 |  207 +--
 ngs-sdk/win/ngs-common.props                       |   73 +-
 ngs-sdk/win/ngs-sdk.vcxproj                        |  262 ++--
 ngs-sdk/win/ngs-test.vcxproj                       |  202 +--
 177 files changed, 11697 insertions(+), 2903 deletions(-)

diff --git a/.gitignore b/.gitignore
index 84ad061..397b4a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1 @@
-ngs-sdk/win/ngs-sdk.opensdf
-ngs-sdk/win/ngs-sdk.sdf
-ngs-sdk/win/ngs-sdk.suo
-ngs-sdk/win/ipch
+*.log
diff --git a/ngs-python/Makefile b/Makefile
similarity index 73%
copy from ngs-python/Makefile
copy to Makefile
index 0b8331a..3b91726 100644
--- a/ngs-python/Makefile
+++ b/Makefile
@@ -23,21 +23,34 @@
 # ===========================================================================
 
 # default response to "make"
-default: subtargs
+default: subdirs
 
-# the sub-targets
-SUBTARGS =  \
-	dummy
+# the sub-directories
+SUBDIRS =    \
+	ngs-sdk \
+	ngs-java \
+	ngs-python \
+	ngs-bam
 
-# standard rules and phony targets
-include $(CURDIR)/Makefile.rules
+SUBDIRS_CLN = \
+	$(addsuffix _cln,$(SUBDIRS))
 
-# rules for making python code
-install: Makefile.config
-	@ $(MAKE) -f Makefile.python install
+SUBDIRS_INST = \
+	$(addsuffix _inst,$(SUBDIRS))
 
-dummy:
-	@ echo "make complete"
+subdirs: $(SUBDIRS)
 
-dummy_cln dummy_inst:
-	@ true
+clean: $(SUBDIRS_CLN)
+
+install: $(SUBDIRS_INST)
+
+$(SUBDIRS):
+	@ $(MAKE) -C $@
+
+$(SUBDIRS_CLN):
+	@ $(MAKE) -C $(subst _cln,,$@) clean
+
+$(SUBDIRS_INST):
+	@ $(MAKE) -C $(subst _inst,,$@) install
+
+.PHONY: $(SUBDIRS) $(SUBDIRS_CLN) $(SUBDIRS_INST)
diff --git a/configure b/configure
index e0bcd21..727531b 100755
--- a/configure
+++ b/configure
@@ -26,11 +26,27 @@
 
 perl -v > /dev/null 2>&1 || { echo "checking for perl... no"; echo >&2 "configure: error: perl not found."; exit 1; }
 
-for D in ngs-sdk ngs-java ngs-python
-do
-  if [ -d $D ]
-    then echo "CONFIGURING $D"
-    $D/configure $@
-    echo
-  fi
-done 
+FILENAME="`basename $0`"
+CURDIR="`dirname $0`"
+
+if [ -z "$CURDIR" ]
+    then
+    echo configure: error: configure should be run as ./configure
+    exit 1
+fi
+
+
+if [ "$FILENAME" != configure -a ! -s configure ]
+    then
+    echo configure: error: configure should be run as ./configure
+else
+    cd $CURDIR
+    for D in ngs-sdk ngs-java ngs-python ngs-bam
+    do
+      if [ -d $D ]
+          then echo "CONFIGURING $D"
+          $D/configure "$@"
+          echo
+      fi
+    done
+fi
diff --git a/ngs-bam/.gitignore b/ngs-bam/.gitignore
new file mode 100644
index 0000000..df15e2d
--- /dev/null
+++ b/ngs-bam/.gitignore
@@ -0,0 +1,2 @@
+/Makefile.config*
+/reconfigure
diff --git a/ngs-python/Makefile b/ngs-bam/Makefile
similarity index 84%
copy from ngs-python/Makefile
copy to ngs-bam/Makefile
index 0b8331a..210fbbf 100644
--- a/ngs-python/Makefile
+++ b/ngs-bam/Makefile
@@ -23,21 +23,23 @@
 # ===========================================================================
 
 # default response to "make"
-default: subtargs
+default: std
 
 # the sub-targets
-SUBTARGS =  \
-	dummy
+SUBDIRS =    \
+
+SUBTARGS =     \
 
-# standard rules and phony targets
 include $(CURDIR)/Makefile.rules
 
-# rules for making python code
-install: Makefile.config
-	@ $(MAKE) -f Makefile.python install
+std: Makefile.config
+	@ $(MAKE) -f Makefile.libs std
 
-dummy:
-	@ echo "make complete"
+clean: Makefile.config
+	@ $(MAKE) -f Makefile.libs clean
+
+install: Makefile.config
+	@ $(MAKE) -f Makefile.libs
+	@ perl $(TOP)/setup/install
 
-dummy_cln dummy_inst:
-	@ true
+.PHONY: std clean install
diff --git a/ngs-bam/Makefile.libs b/ngs-bam/Makefile.libs
new file mode 100644
index 0000000..517a204
--- /dev/null
+++ b/ngs-bam/Makefile.libs
@@ -0,0 +1,112 @@
+# ===========================================================================
+#
+#                            PUBLIC DOMAIN NOTICE
+#               National Center for Biotechnology Information
+#
+#  This software/database is a "United States Government Work" under the
+#  terms of the United States Copyright Act.  It was written as part of
+#  the author's official duties as a United States Government employee and
+#  thus cannot be copyrighted.  This software/database is freely available
+#  to the public for use. The National Library of Medicine and the U.S.
+#  Government have not placed any restriction on its use or reproduction.
+#
+#  Although all reasonable efforts have been taken to ensure the accuracy
+#  and reliability of the software and data, the NLM and the U.S.
+#  Government do not and cannot warrant the performance or results that
+#  may be obtained by using this software or data. The NLM and the U.S.
+#  Government disclaim all warranties, express or implied, including
+#  warranties of performance, merchantability or fitness for any particular
+#  purpose.
+#
+#  Please cite the author in any work or product based on this material.
+#
+# ===========================================================================
+
+
+default: std
+
+TOP ?= $(CURDIR)
+MODPATH =
+
+include $(TOP)/Makefile.config
+
+INTLIBS = \
+
+EXTLIBS =   \
+	ngs-bam \
+	ngs-bam-c++
+
+TARGETS =      \
+	$(INTLIBS) \
+	$(EXTLIBS)
+
+all std: $(TARGETS)
+
+clean:
+	@ rm -rf $(OBJDIR)
+	@ rm -f $(addprefix $(ILIBDIR)/$(LPFX),$(addsuffix *,$(INTLIBS))) \
+			$(addprefix $(LIBDIR)/$(LPFX),$(addsuffix *,$(EXTLIBS)))
+
+.PHONY: default all std $(TARGETS)
+
+ngs-bam: $(LIBDIR) $(OBJDIR) $(LIBDIR)/$(LPFX)ngs-bam.$(SHLX)
+
+ngs-bam-c++: $(LIBDIR) $(OBJDIR) $(LIBDIR)/$(LPFX)ngs-bam-c++.$(LIBX)
+
+runtests: ngs-bam ngs-bam-c++
+
+ifdef NGS_INCDIR
+       INCDIRS += -I$(NGS_INCDIR)
+endif
+
+#-------------------------------------------------------------------------------
+# ngs-bam
+#
+NGS_BAM_SRC = \
+	bam		  \
+	ngs-bam
+
+NGS_BAM_OBJ = \
+	$(addprefix $(OBJDIR)/,$(addsuffix .$(LOBX),$(NGS_BAM_SRC)))
+
+NGS_BAM_DEPS = $(NGS_BAM_OBJ)
+
+NGS_BAM_LIB =
+
+ifdef NGS_LIBDIR
+	NGS_BAM_LIB += -L$(NGS_LIBDIR)
+	NGS_BAM_DEPS += $(NGS_LIBDIR)/$(LPFX)ngs-adapt-c++.$(LIBX)
+endif
+
+NGS_BAM_LIB +=      \
+	-lngs-adapt-c++ \
+	-lz
+
+$(LIBDIR)/$(LPFX)ngs-bam.$(VERSION_SHLX): $(NGS_BAM_DEPS)
+	$(LP) $(DBG) $(OPT) -shared -o $@ $(SONAME) $(NGS_BAM_OBJ) $(NGS_BAM_LIB)
+
+$(LIBDIR)/$(LPFX)ngs-bam.$(MAJVERS_SHLX): $(LIBDIR)/$(LPFX)ngs-bam.$(VERSION_SHLX)
+	@ rm -f $@
+	ln -s $(notdir $^) $@
+
+$(LIBDIR)/$(LPFX)ngs-bam.$(SHLX): $(LIBDIR)/$(LPFX)ngs-bam.$(MAJVERS_SHLX)
+	@ rm -f $@
+	ln -s $(notdir $^) $@
+
+$(LIBDIR)/$(LPFX)ngs-bam-c++.$(VERSION_LIBX): $(NGS_BAM_OBJ)
+	$(AR) $@ $^
+
+$(LIBDIR)/$(LPFX)ngs-bam-c++.$(MAJVERS_LIBX): $(LIBDIR)/$(LPFX)ngs-bam-c++.$(VERSION_LIBX)
+	@ rm -f $@
+	ln -s $(notdir $^) $@
+
+$(LIBDIR)/$(LPFX)ngs-bam-c++.$(LIBX): $(LIBDIR)/$(LPFX)ngs-bam-c++.$(MAJVERS_LIBX)
+	@ rm -f $@
+	ln -s $(notdir $^) $@
+
+REQUIRED_LIBS =                                \
+	$(NGS_LIBDIR)/$(LPFX)ngs-adapt-c++.$(LIBX)
+
+$(REQUIRED_LIBS):
+	@ echo missing $@
+	@ false
diff --git a/ngs-sdk/Makefile.rules b/ngs-bam/Makefile.rules
similarity index 90%
copy from ngs-sdk/Makefile.rules
copy to ngs-bam/Makefile.rules
index 1ac77d3..6af0a23 100644
--- a/ngs-sdk/Makefile.rules
+++ b/ngs-bam/Makefile.rules
@@ -34,13 +34,13 @@ subtargs: $(SUBTARGS)
 
 # rules for "make clean"
 SUBDIRS_CLN = \
-	$(addsuffix _cln,$(SUBDIRS) test)
+	$(addsuffix _cln,$(SUBDIRS))
 
 $(SUBDIRS_CLN): Makefile.config
 	@ $(MAKE) -s -C $(subst _cln,,$@) clean
 
 SUBTARGS_CLN = \
-	$(addsuffix _cln,$(SUBTARGS) test)
+	$(addsuffix _cln,$(SUBTARGS))
 
 clean: Makefile.config $(SUBTARGS_CLN)
 
@@ -61,9 +61,9 @@ test runtests: Makefile.config default
 	@ $(MAKE) -C test runtests
 
 # rule to run configuration
-Makefile.config: Makefile.config.$(shell perl $(TOP)/os-arch.perl) konfigure.perl
+Makefile.config: Makefile.config.$(shell perl $(TOP)/setup/os-arch.perl) setup/konfigure.perl
 
-Makefile.config.$(shell perl $(TOP)/os-arch.perl):
+Makefile.config.$(shell perl $(TOP)/setup/os-arch.perl):
 	@echo "*** File '$@' is missing. Please run ./configure"
 	@false
 
diff --git a/ngs-bam/bam.cpp b/ngs-bam/bam.cpp
new file mode 100644
index 0000000..18a4be0
--- /dev/null
+++ b/ngs-bam/bam.cpp
@@ -0,0 +1,682 @@
+/* ===========================================================================
+ *
+ *                            PUBLIC DOMAIN NOTICE
+ *               National Center for Biotechnology Information
+ *
+ *  This software/database is a "United States Government Work" under the
+ *  terms of the United States Copyright Act.  It was written as part of
+ *  the author's official duties as a United States Government employee and
+ *  thus cannot be copyrighted.  This software/database is freely available
+ *  to the public for use. The National Library of Medicine and the U.S.
+ *  Government have not placed any restriction on its use or reproduction.
+ *
+ *  Although all reasonable efforts have been taken to ensure the accuracy
+ *  and reliability of the software and data, the NLM and the U.S.
+ *  Government do not and cannot warrant the performance or results that
+ *  may be obtained by using this software or data. The NLM and the U.S.
+ *  Government disclaim all warranties, express or implied, including
+ *  warranties of performance, merchantability or fitness for any particular
+ *  purpose.
+ *
+ *  Please cite the author in any work or product based on this material.
+ *
+ * ===========================================================================
+ */
+
+#include <iostream>
+#include "bam.hpp"
+
+#define MAX_INDEX_SEQ_LEN ((1u << 29) - 1)
+#define MAX_BIN  (37449u)
+#define NUMINTV ((MAX_INDEX_SEQ_LEN + 1) >> 14)
+
+class RefIndex {
+public:
+    BAMFilePosType off_beg, off_end;
+    uint64_t n_mapped, n_unmapped;
+    BAMFilePosTypeList interval;
+    std::vector<BAMFilePosTypeList> bins;
+    
+private:
+    static void CopyWhereLess(BAMFilePosTypeList &dst,
+                              BAMFilePosTypeList const &src,
+                              BAMFilePosType const maxpos)
+    {
+        if (maxpos.hasValue()) {
+            for (unsigned i = 0; i < src.size(); ++i) {
+                BAMFilePosType const pos = src[i];
+                
+                if (pos < maxpos)
+                    dst.push_back(pos);
+            }
+        }
+        else {
+            for (unsigned i = 0; i < src.size(); ++i)
+                dst.push_back(src[i]);
+        }
+    }
+public:
+    char const *LoadIndexIntervals(char const *data, char const *const endp)
+    {
+        if (data + 4 > endp)
+            throw std::runtime_error("insufficient data to load index interval count");
+        int32_t const n = LE2Host<int32_t>(data); data += 4;
+
+        char const *const next = data + 8 * n;
+        if (next > endp)
+            throw std::runtime_error("insufficient data to load index intervals");
+
+        BAMFilePosType last(0);
+        
+        interval.resize(n);
+        for (unsigned i = 0; i < n; ++i) {
+            BAMFilePosType const intvl = LE2Host<BAMFilePosType>(data); data += 8;
+            
+            interval[i] = (intvl == last) ? BAMFilePosType(0) : intvl;
+            last = intvl;
+        }
+        while (interval.size() > 0 && !interval.back().hasValue())
+            interval.pop_back();
+        
+        return next;
+    }
+    char const *LoadIndexBins(char const *data, char const *const endp)
+    {
+        if (data + 4 > endp)
+            throw std::runtime_error("insufficient data to load index bin count");
+        int32_t const n_bin = LE2Host<int32_t>(data); data += 4;
+        
+        bins.resize(MAX_BIN);
+        for (int i = 0; i < n_bin; ++i) {
+            if (data + 8 > endp)
+                throw std::runtime_error("insufficient data to load index bin size");
+            
+            uint32_t const bin     = LE2Host<uint32_t>(data + 0);
+             int32_t const n_chunk = LE2Host< int32_t>(data + 4);
+
+            data += 8;
+            if (data + n_chunk * 16 > endp)
+                throw std::runtime_error("insufficient data to load index bin chunks");
+            
+            if (bin == MAX_BIN && n_chunk == 2) {
+                // special doodad
+                off_beg    = LE2Host<BAMFilePosType>(data); data += 8;
+                off_end    = LE2Host<BAMFilePosType>(data); data += 8;
+                n_mapped   = LE2Host<uint64_t>(data); data += 8;
+                n_unmapped = LE2Host<uint64_t>(data); data += 8;
+            }
+            else if (bin < MAX_BIN) {
+                BAMFilePosTypeList &this_bin = bins[bin];
+                
+                this_bin.resize(n_chunk);
+                
+                for (unsigned k = 0; k < n_chunk; ++k) {
+                    BAMFilePosType const beg = LE2Host<BAMFilePosType>(data); data += 8;
+                    BAMFilePosType const end = LE2Host<BAMFilePosType>(data); data += 8;
+                    
+                    (void)end;
+                    this_bin[k] = beg;
+                }
+            }
+            else
+                data += 16 * n_chunk;
+        }
+        return data;
+    }
+    RefIndex()
+    {}
+    BAMFilePosTypeList slice(unsigned const beg, unsigned const end) const
+    {
+        unsigned const first[] = { 1, 9, 73, 585, 4681 };
+        unsigned const cnt = end - 1 - beg;
+        unsigned const maxintvl = (end >> 14) + 1;
+        BAMFilePosType const maxpos = maxintvl < interval.size() ? interval[maxintvl] : off_end;
+        unsigned int_beg[5], int_cnt[5];
+        BAMFilePosTypeList rslt;
+        
+        for (unsigned i = 0; i < 5; ++i) {
+            unsigned const shift = 14 + 3 * (4 - i);
+            
+            int_beg[i] = (beg >> shift);
+        }
+        for (unsigned i = 0; i < 5; ++i) {
+            unsigned const shift = 14 + 3 * (4 - i);
+            
+            int_cnt[i] = (cnt >> shift) + 1;
+        }
+        CopyWhereLess(rslt, bins[0], maxpos);
+        for (unsigned i = 0; i < 5; ++i) {
+            unsigned const beg = int_beg[i] + first[i];
+            unsigned const N = int_cnt[i];
+            
+            for (unsigned j = 0; j < N; ++j) {
+                CopyWhereLess(rslt, bins[beg + j], maxpos);
+            }
+        }
+        std::sort(rslt.begin(), rslt.end());
+        return rslt;
+    }
+};
+
+size_t HeaderRefInfo::LoadIndex(char const data[], char const *const endp)
+{
+    RefIndex *i = new RefIndex();
+    try {
+        char const *const next1 = i->LoadIndexBins(data, endp);
+        char const *const next2 = i->LoadIndexIntervals(next1, endp);
+        
+        index = i;
+        
+        return next2 - data;
+    }
+    catch (...) {
+        delete i;
+        throw;
+    }
+}
+
+void HeaderRefInfo::DropIndex()
+{
+    if (index) {
+        delete index;
+        index = 0;
+    }
+}
+
+BAMFilePosTypeList HeaderRefInfo::slice(unsigned const beg, unsigned const end) const {
+    return index ? index->slice(beg, end) : BAMFilePosTypeList();
+}
+
+void BAMFile::DumpSAM(std::ostream &oss, BAMRecord const &rec) const
+{
+    unsigned const seqlen   = rec.l_seq();
+    std::string const RNAME = rec.isSelfMapped() ? getRefInfo(rec.refID()).getName() : "*";
+    std::string const RNEXT = rec.isMateMapped() ? getRefInfo(rec.next_refID()).getName() : "*";
+    int const POS   		= rec.isSelfMapped() ? (rec.pos() + 1) : 0;
+    int const PNEXT 		= rec.isMateMapped() ? (rec.next_pos() + 1) : 0;
+
+    oss	        << rec.readname()
+ 		<< '\t' << rec.flag()
+    	<< '\t' << RNAME
+    	<< '\t' << POS
+        << '\t' << int(rec.mq())
+    	<< '\t';
+    
+    if (rec.isSelfMapped()) {
+        unsigned const N = rec.nc();
+        
+        for (unsigned i = 0; i < N; ++i) {
+            uint32_t const cv = rec.cigar(i);
+            int const op = cv & 0x0F;
+            int len = cv >> 4;
+            char buf[16];
+            char *cur = buf + sizeof(buf);
+            
+            *--cur = '\0';
+            *--cur = "MIDNSHP=X???????"[op];
+            do {
+                int const digit = len % 10;
+                
+                *--cur = digit + '0';
+                len /= 10;
+            } while (len > 0);
+            oss << cur;
+        }
+    }
+    else
+        oss << '*';
+    
+	oss	<< '\t' << RNEXT
+    	<< '\t' << PNEXT
+        << '\t' << rec.tlen()
+    	<< '\t';
+    
+    if (seqlen > 0) {
+        for (int i = 0; i < seqlen; ++i)
+            oss << rec.seq(i);
+        oss << '\t';
+        
+        bool allFF = true;
+        uint8_t const *const q = rec.qual();
+        for (unsigned i = 0; i < seqlen; ++i) {
+            uint8_t const qv = q[i];
+            
+            if (qv != 0xFF) {
+                allFF = false;
+                break;
+            }
+        }
+        if (allFF)
+            oss << '*';
+        else {
+            for (unsigned i = 0; i < seqlen; ++i) {
+                uint8_t const qv = q[i];
+                int const offset = ((int)qv) + '!';
+                int const out = offset < '~' ? offset : '~';
+                
+                oss << char(out);
+            }
+        }
+    }
+    else
+        oss << "*\t*";
+    
+    for (BAMRecord::OptionalField::const_iterator i = rec.begin(); i != rec.end(); ++i) {
+        std::string const tag = std::string(i->getTag(), 2);
+        int const elems = i->getElementCount();
+        char const type = i->getValueType();
+        char const *raw = i->getRawValue();
+        
+        oss << '\t' << tag << ':' << (elems == 1 ? type : 'B') << ':';
+        if (type == 'Z' || type == 'H')
+            oss << raw;
+        else {
+            if (elems > 1)
+                oss << type;
+            for (int j = 0; j < elems; ++j) {
+                if (elems > 1)
+                    oss << ',';
+                switch (type) {
+                    case 'A':
+                        oss << *raw;
+                        ++raw;
+                        break;
+                    case 'C':
+                        oss << unsigned(*((uint8_t const *)raw));
+                        ++raw;
+                        break;
+                    case 'c':
+                        oss << int(*((int8_t const *)raw));
+                        ++raw;
+                        break;
+                    case 'S':
+                        oss << unsigned(LE2Host<uint16_t>(raw));
+                        raw += 2;
+                        break;
+                    case 's':
+                        oss << int(LE2Host<int16_t>(raw));
+                        raw += 2;
+                        break;
+                    case 'F':
+                        oss << float(LE2Host<float>(raw));
+                        raw += 4;
+                        break;
+                    case 'I':
+                        oss << unsigned(LE2Host<uint32_t>(raw));
+                        raw += 4;
+                        break;
+                    case 'i':
+                        oss << int(LE2Host<int32_t>(raw));
+                        raw += 4;
+                        break;
+                }
+            }
+        }
+    }
+}
+
+unsigned BAMFile::FillBuffer(int const n) {
+    char *const dst = (char *)(iobuffer + (n == 1 ? sizeof(iobuffer) / 2 : 0));
+    size_t const nwant = n == 1 ? sizeof(iobuffer) / 2 : sizeof(iobuffer);
+    size_t const nread = file.eof() ? 0 : file.read(dst, nwant).gcount();
+    
+    if (nread == 0 && !file.eof())
+        throw std::runtime_error("read failed");
+    
+    return (unsigned)nread;
+}
+
+void BAMFile::ReadZlib(void) {
+    zs.next_out  = bambuffer;
+    zs.avail_out = sizeof(bambuffer);
+    zs.total_out = 0;
+    bam_cur      = 0;
+    
+    if (zs.avail_in == 0) {
+    FILL_BUFFER:
+        cpos = file.tellg();
+        zs.avail_in = FillBuffer(2);
+        zs.next_in  = iobuffer;
+        if (zs.avail_in == 0) /* EOF */
+            return;
+    }
+    
+    bpos = cpos + (std::ifstream::pos_type)(zs.next_in - iobuffer);
+    int const zrc = inflate(&zs, Z_FINISH);
+    
+    if (zrc == Z_STREAM_END) {
+        /* inflateReset clobbers these value but we want them */
+        uLong const total_out = zs.total_out;
+        uLong const total_in  = zs.total_in;
+        
+        int const zrc = inflateReset(&zs);
+        if (zrc != Z_OK)
+            throw std::logic_error("inflateReset didn't return Z_OK");
+        
+        zs.total_out = total_out;
+        zs.total_in  = total_in;
+        
+        if (   zs.next_in >= &iobuffer[sizeof(iobuffer)/2]
+               && zs.next_in + zs.avail_in == &iobuffer[sizeof(iobuffer)])
+        {
+            memcpy(iobuffer, &iobuffer[sizeof(iobuffer)/2], sizeof(iobuffer)/2);
+            cpos += sizeof(iobuffer)/2;
+            zs.next_in  -= sizeof(iobuffer)/2;
+            zs.avail_in += FillBuffer(1);
+        }
+        
+        return;
+    }
+    if (zrc != Z_OK && zrc != Z_BUF_ERROR)
+        throw std::runtime_error("decompression failed");
+    
+    if (zs.avail_in == 0)
+        goto FILL_BUFFER;
+    
+    throw std::runtime_error("zs.avail_in != 0");
+}
+
+size_t BAMFile::ReadN(size_t N, void *Dst) {
+    uint8_t *const dst = reinterpret_cast<uint8_t *>(Dst);
+    size_t n = 0;
+    
+    while (n < N) {
+        size_t const avail_out = N - n;
+        size_t const avail_in = zs.total_out - bam_cur;
+        
+        if (avail_in) {
+            size_t const copy = avail_out < avail_in ? avail_out : avail_in;
+            
+            memcpy(dst + n, bambuffer + bam_cur, copy);
+            bam_cur += copy;
+            if (bam_cur == zs.total_out)
+                bam_cur = zs.total_out = 0;
+            
+            n += copy;
+            if (n == N)
+                break;
+        }
+        ReadZlib();
+        if (zs.total_out == 0)
+            break;
+    }
+    return n;
+}
+
+size_t BAMFile::SkipN(size_t N) {
+    size_t n = 0;
+    
+    while (n < N) {
+        size_t const avail_out = N - n;
+        size_t const avail_in = zs.total_out - bam_cur;
+        
+        if (avail_in) {
+            size_t const copy = avail_out < avail_in ? avail_out : avail_in;
+            
+            bam_cur += copy;
+            n += copy;
+            if (n == N)
+                break;
+        }
+        ReadZlib();
+        if (zs.total_out == 0)
+            break;
+    }
+    return n;
+}
+
+void BAMFile::Seek(std::ifstream::pos_type const &new_bpos, unsigned const new_bam_cur) {
+    unsigned const c_offset = new_bpos % IO_BLK_SIZE;
+    std::ifstream::pos_type const new_cpos = new_bpos - std::ifstream::pos_type(c_offset);
+
+    std::cerr << "seek to " << std::hex << new_bpos << "|" << new_bam_cur << std::endl;
+    
+    file.seekg(new_cpos);
+    cpos = file.tellg();
+    zs.avail_in = FillBuffer(2);
+    if (zs.avail_in > c_offset) {
+        zs.avail_in -= c_offset;
+        zs.next_in = iobuffer + c_offset;
+        ReadZlib();
+        if (zs.total_out > new_bam_cur) {
+            bam_cur = new_bam_cur;
+            return;
+        }
+    }
+    throw std::runtime_error("position is invalid");
+}
+
+template <typename T>
+bool BAMFile::Read(size_t count, T *dst) {
+    size_t const nwant = count * sizeof(T);
+    size_t const nread = ReadN(nwant, reinterpret_cast<void *>(dst));
+    
+    return nwant == nread;
+}
+
+int32_t BAMFile::ReadI32() {
+    int32_t value;
+    
+    if (Read(1, &value))
+        return LE2Host<int32_t>(&value);
+    throw std::runtime_error("insufficient data while reading bam file");
+}
+
+bool BAMFile::ReadI32(int32_t &rslt) {
+    int32_t value;
+    
+    if (Read(1, &value)) {
+        rslt = LE2Host<int32_t>(&value);
+        return true;
+    }
+    return false;
+}
+
+void BAMFile::InflateInit(void) {
+    memset(&zs, 0, sizeof(zs));
+    
+    int const zrc = inflateInit2(&zs, MAX_WBITS + 16);
+    switch (zrc) {
+        case Z_OK:
+            break;
+        case Z_MEM_ERROR:
+            throw std::bad_alloc();
+            break;
+        case Z_VERSION_ERROR:
+            throw std::runtime_error(std::string("zlib version is not compatible; need version " ZLIB_VERSION " but have ") + zlibVersion());
+            break;
+        case Z_STREAM_ERROR:
+        default:
+            throw std::invalid_argument(zs.msg ? zs.msg : "unknown");
+            break;
+    }
+}
+
+void BAMFile::CheckHeaderSignature(void) {
+    static char const sig[] = "BAM\1";
+    char actual[4];
+    
+    if (!Read(4, actual) || memcmp(actual, sig, 4) != 0)
+        throw std::runtime_error("Not a BAM file");
+}
+
+void BAMFile::ReadHeader(void) {
+    CheckHeaderSignature();
+    
+    {
+        int32_t const l_text = ReadI32();
+        if (l_text < 0)
+            throw std::runtime_error("header text length < 0");
+        
+        char *const text = new char[l_text];
+        if (!Read(l_text, text))
+            throw std::runtime_error("file is truncated");
+        
+        headerText = text;
+        delete [] text;
+    }
+    int32_t const n_ref = ReadI32();
+    if (n_ref < 0)
+        throw std::runtime_error("header reference count < 0");
+    
+    references.reserve(n_ref);
+    
+    for (int i = 0; i < n_ref; ++i) {
+        int32_t const l_name = ReadI32();
+        
+        if (l_name < 0)
+            throw std::runtime_error("header reference name length < 0");
+        
+        char *const name = new char[l_name];
+        if (!Read(l_name, name))
+            throw std::runtime_error("file is truncated");
+        
+        int32_t const l_ref = ReadI32();
+        if (l_ref < 0)
+            throw std::runtime_error("header reference length < 0");
+        
+        references.push_back(HeaderRefInfo(name, l_ref));
+        referencesByName[name] = i;
+        
+        delete [] name;
+    }
+}
+
+void BAMFile::LoadIndexData(size_t const fsize, char const data[]) {
+    char const *const endp = data + fsize;
+    
+    if (memcmp(data, "BAI\1", 4) != 0)
+        return;
+    
+    int32_t const n_ref = LE2Host<int32_t>(data + 4);
+    if (n_ref != references.size())
+        return;
+    
+    size_t offset = 8;
+    
+    for (int i = 0; i < n_ref; ++i) {
+        size_t const size = references[i].LoadIndex(data + offset, endp);
+        
+        offset += size;
+        if (size == 0) {
+            std::cerr << "failed to load index #" << (i + 1) << std::endl;
+            for (int j = 0; j < i; ++j)
+                references[j].DropIndex();
+            return;
+        }
+    }
+}
+
+void BAMFile::LoadIndex(std::string const &filepath) {
+    char *data;
+    size_t fsize;
+    {
+        std::string const idxpath(filepath+".bai");
+        std::ifstream ifile;
+        
+        ifile.open(idxpath.c_str(), std::ifstream::in | std::ifstream::binary);
+        if (!ifile.is_open())
+            return;
+        
+        std::filebuf *const buf = ifile.rdbuf();
+        fsize = buf->pubseekoff(0, ifile.end, ifile.in);
+        
+        if (fsize < 8)
+            return;
+        
+        buf->pubseekpos(0, ifile.in);
+        
+        data = new char[fsize];
+        buf->sgetn(data, fsize);
+    }
+    LoadIndexData(fsize, data);
+    delete [] data;
+}
+
+BAMFile::BAMFile(std::string const &filepath)
+{
+    InflateInit();
+    
+    file.open(filepath.c_str(), std::ifstream::in | std::ifstream::binary);
+    if (!file.is_open())
+        throw std::runtime_error(std::string("The file '")+filepath+"' could not be opened");
+    
+    ReadHeader();
+    first_bpos = cpos + (std::ifstream::pos_type)(zs.next_in - iobuffer);
+    first_bam_cur = bam_cur;
+    LoadIndex(filepath);
+}
+
+BAMRecord const *BAMFile::Read()
+{
+    union aligned_BAMRecord {
+        SizedRawData raw;
+        BAMRecord record;
+        struct {
+            uint8_t align[16];
+        } align;
+    };
+    int32_t datasize;
+    
+    if (!ReadI32(datasize)) // assumes cause is EOF
+        return 0;
+    
+    if (datasize < 0)
+        throw std::runtime_error("file is corrupt: record size < 0");
+
+    uint32_t const size = (uint32_t)datasize;
+    
+    union aligned_BAMRecord *data = new aligned_BAMRecord[(size + sizeof(uint32_t) + sizeof(aligned_BAMRecord) - 1)/sizeof(aligned_BAMRecord)];
+    data->raw.size = size;
+    if (Read(size, data->raw.data))
+        return &data->record;
+
+    delete [] data;
+    throw std::runtime_error("file is truncated");
+}
+
+bool BAMFile::isGoodRecord(BAMRecord const &rec)
+{
+    if (rec.isTooSmall())
+        return false;
+    
+    unsigned const refs = (unsigned)references.size();
+    unsigned const flag = rec.flag();
+    int const self_refID = rec.refID();
+    if ((flag & 0x40) != 0 && self_refID > 0 && self_refID >= refs)
+        return false;
+
+    int const mate_refID = rec.next_refID();
+    if ((flag & 0x80) != 0 && mate_refID > 0 && mate_refID >= refs)
+        return false;
+    
+    return true;
+}
+
+BAMRecordSource *BAMFile::Slice(const std::string &rname, unsigned start, unsigned last)
+{
+    int const refID = getReferenceIndexByName(rname);
+    
+    if (refID < 0)
+        return new BAMRecordSource();
+    
+    HeaderRefInfo const &ri = getRefInfo(refID);
+
+    if (start > 0)
+        --start;
+    if (last == 0)
+        last = ri.length;
+    
+    if (!ri.index || start >= ri.length)
+        return new BAMRecordSource();
+
+    if (last > start + ri.length)
+        last = start + ri.length;
+    
+    BAMFilePosTypeList const &index = ri.slice(start, last);
+    
+    if (index.size() == 0)
+        return new BAMRecordSource();
+    
+    return new BAMFileSlice(*this, refID, start, last, index);
+}
diff --git a/ngs-bam/bam.hpp b/ngs-bam/bam.hpp
new file mode 100644
index 0000000..e7148d7
--- /dev/null
+++ b/ngs-bam/bam.hpp
@@ -0,0 +1,547 @@
+/* ===========================================================================
+ *
+ *                            PUBLIC DOMAIN NOTICE
+ *               National Center for Biotechnology Information
+ *
+ *  This software/database is a "United States Government Work" under the
+ *  terms of the United States Copyright Act.  It was written as part of
+ *  the author's official duties as a United States Government employee and
+ *  thus cannot be copyrighted.  This software/database is freely available
+ *  to the public for use. The National Library of Medicine and the U.S.
+ *  Government have not placed any restriction on its use or reproduction.
+ *
+ *  Although all reasonable efforts have been taken to ensure the accuracy
+ *  and reliability of the software and data, the NLM and the U.S.
+ *  Government do not and cannot warrant the performance or results that
+ *  may be obtained by using this software or data. The NLM and the U.S.
+ *  Government disclaim all warranties, express or implied, including
+ *  warranties of performance, merchantability or fitness for any particular
+ *  purpose.
+ *
+ *  Please cite the author in any work or product based on this material.
+ *
+ * ===========================================================================
+ */
+
+#include <stdint.h>
+#include <string.h>
+
+#include <stdexcept>
+#include <vector>
+#include <map>
+#include <fstream>
+#include <algorithm>
+#include <iterator>
+
+#include <zlib.h>
+
+#define BAM_BLK_MAX (64u * 1024u)
+#define IO_BLK_SIZE (1024u * 1024u)
+
+template<typename T>
+static T LE2Host(void const *const src)
+{
+    union {
+        uint8_t ch[sizeof(T)];
+        T v; // ensures alignment if necessary
+    } u;
+    memcpy(reinterpret_cast<void *>(&u), src, sizeof(T));
+#if BYTE_ORDER == LITTLE_ENDIAN
+    return u.v;
+#else
+    T y = 0;
+    size_t j = sizeof(T);
+
+    for (size_t i = 0; i < sizeof(T); ++i)
+        y = (y << 8) | u.ch[--j];
+
+    return y;
+#endif
+}
+
+class BAMFilePosType {
+    uint64_t value;
+public:
+    BAMFilePosType(uint64_t const x = 0) : value(x) {}
+    bool hasValue() const { return value != 0; }
+    uint64_t fpos() const {
+        return value >> 16;
+    }
+    uint16_t bpos() const {
+        return (uint16_t)value;
+    }
+    friend bool operator <(BAMFilePosType const lhs, BAMFilePosType const rhs) {
+        return rhs.value < rhs.value;
+    }
+    friend bool operator ==(BAMFilePosType const lhs, BAMFilePosType const rhs) {
+        return rhs.value == rhs.value;
+    }
+};
+
+template <>
+BAMFilePosType LE2Host<BAMFilePosType>(void const *const src)
+{
+    return BAMFilePosType(LE2Host<uint64_t>(src));
+}
+
+
+typedef std::vector<BAMFilePosType> BAMFilePosTypeList;
+
+class BAMFile;
+class RefIndex;
+
+class HeaderRefInfo
+{
+    friend class BAMFile;
+
+    RefIndex const *index;
+    std::string name;
+    unsigned length;
+
+    HeaderRefInfo(std::string const &Name, int32_t const Length)
+    : name(Name), length(Length), index(0)
+    {}
+    size_t LoadIndex(char const data[], char const *const endp);
+    void DropIndex();
+public:
+    ~HeaderRefInfo() {
+        DropIndex();
+    }
+    BAMFilePosTypeList slice(unsigned const beg, unsigned const end) const;
+    std::string const &getName() const {
+        return name;
+    }
+    unsigned getLength() const {
+        return length;
+    }
+};
+
+struct SizedRawData
+{
+    uint32_t size;
+    uint8_t data[1];
+};
+
+struct BAMLayout : public SizedRawData {
+/* layout looks like:
+    uint8_t
+        m_refID[4],
+        m_pos[4],
+        m_bin_mq_nl[4],
+        m_flag_nc[4],
+        m_l_seq[4],
+        m_next_refID[4],
+        m_next_pos[4],
+        m_tlen[4],
+        m_readname[1];
+ */
+    enum layout {
+        start_refID = 0,
+        start_pos = 4,
+        start_bin_mq_nl = start_pos + 4,
+        start_flag_nc = start_bin_mq_nl + 4,
+        start_l_seq = start_flag_nc + 4,
+        start_next_refID = start_l_seq + 4,
+        start_next_pos = start_next_refID + 4,
+        start_tlen = start_next_pos + 4,
+        start_readname = start_tlen + 4,
+
+        length_fixed_part = start_readname,
+
+        start_nl = start_bin_mq_nl,
+        start_mq = start_nl + 1,
+        start_bin = start_mq + 1,
+        start_nc = start_flag_nc,
+        start_flag = start_nc + 2
+    };
+    uint8_t const *p_refID     () const { return data + start_refID     ; }
+    uint8_t const *p_pos       () const { return data + start_pos       ; }
+    uint8_t const *p_nl        () const { return data + start_nl        ; }
+    uint8_t const *p_mq        () const { return data + start_mq        ; }
+    uint8_t const *p_bin       () const { return data + start_bin       ; }
+    uint8_t const *p_nc        () const { return data + start_nc        ; }
+    uint8_t const *p_flag      () const { return data + start_flag      ; }
+    uint8_t const *p_l_seq     () const { return data + start_l_seq     ; }
+    uint8_t const *p_next_refID() const { return data + start_next_refID; }
+    uint8_t const *p_next_pos  () const { return data + start_next_pos  ; }
+    uint8_t const *p_tlen      () const { return data + start_tlen      ; }
+    uint8_t const *p_readname  () const { return data + start_readname  ; }
+    
+    size_t min_size() const {
+        if (size < length_fixed_part)
+            return length_fixed_part;
+        
+        uint16_t const nc = LE2Host<uint16_t>(p_nc());
+        uint32_t const lseq = LE2Host<int32_t>(p_l_seq());
+        return length_fixed_part + 4u * nc + ((lseq + 1) >> 1) + lseq;
+    }
+    void const *endp() const {
+        return (void const *)(data + size);
+    }
+};
+
+class BAMRecord : private BAMLayout {
+public:
+    bool isTooSmall() const {
+        return (size_t)size < min_size();
+    }
+
+    int32_t refID() const { return LE2Host<int32_t>(p_refID()); }
+    int32_t pos() const { return LE2Host<int32_t>(p_pos()); }
+    uint8_t mq() const { return *p_mq(); }
+    uint8_t l_read_name() const { return *p_nl(); }
+    uint16_t flag() const { return LE2Host<uint16_t>(p_flag()); }
+    uint16_t nc() const { return LE2Host<uint16_t>(p_nc()); }
+    int32_t l_seq() const { return LE2Host<int32_t>(p_l_seq()); }
+    int32_t next_refID() const { return LE2Host<int32_t>(p_next_refID()); }
+    int32_t next_pos() const { return LE2Host<int32_t>(p_next_pos()); }
+    int32_t tlen() const { return LE2Host<int32_t>(p_tlen()); }
+    char const *readname() const { return (char const *)p_readname(); }
+    uint32_t cigar(unsigned const i) const {
+        uint8_t const *const p_cigar = p_readname() + l_read_name();
+        return LE2Host<uint32_t>(p_cigar + 4u * i);
+    }
+    uint8_t const *seq() const { return p_readname() + l_read_name() + 4u * nc(); }
+    char seq(unsigned const i) const {
+        static char const tr[] = "=ACMGRSVTWYHKDBN";
+        uint8_t const b4na2 = seq()[i >> 1];
+        uint8_t const lo = b4na2 & 15;
+        uint8_t const hi = b4na2 >> 4;
+        return tr[(i & 1) ? lo : hi];
+    }
+    uint8_t const *qual() const { return seq() + ((l_seq() + 1) >> 1); }
+    void const *extra() const { return (void const *)(qual() + l_seq()); }
+
+    unsigned refLen() const {
+        unsigned const n = nc();
+        unsigned rslt = 0;
+
+        for (unsigned i = 0; i < n; ++i) {
+            uint32_t const op = cigar(i);
+            int const code = op & 0x0F;
+            int const len = op >> 4;
+            switch (code) {
+                case 0: /* M */
+                case 2: /* D */
+                case 3: /* N */
+                case 7: /* = */
+                case 8: /* X */
+                    rslt += len;
+            }
+        }
+        return rslt;
+    }
+    bool isSelfMapped() const {
+        return ((flag() & 0x0004) != 0 || refID() < 0 || pos() < 0 || nc() == 0) ? false : true;
+    }
+    bool isMateMapped() const {
+        int const FLAG = flag();
+
+        return ((FLAG & 0x0001) == 0 || (FLAG & 0x0008) != 0 || next_refID() < 0 || next_pos() < 0) ? false : true;
+    }
+
+    void cigarString(std::string &rslt, bool const clipped, char const OPCODE[]) const {
+        unsigned const n = nc();
+        int last_len = 0;
+        char last_code = 0;
+        unsigned last_size = 0;
+
+        rslt.resize(0);
+        rslt.reserve(11*n);
+
+        for (unsigned i = 0; i < n; ++i) {
+            char buf[12];
+            char *cur = buf + sizeof(buf);
+            uint32_t const op = cigar(i);
+            char const code = OPCODE[op & 0x0F];
+            int len = op >> 4;
+
+            if (last_code == code) {
+                len += last_len;
+                rslt.resize(last_size);
+            }
+            last_size = (unsigned)rslt.size();
+            last_len = len;
+            last_code = code;
+
+            *--cur = '\0';
+            *--cur = code;
+            for ( ; ; ) {
+                *--cur = len % 10 + '0';
+                if ((len /= 10) == 0)
+                    break;
+            }
+            if (!clipped || last_size != 0 || !(last_code == 'S' || last_code == 'H'))
+	            rslt.append(cur);
+        }
+        if (clipped && (last_code == 'S' || last_code == 'H'))
+            rslt.resize(last_size);
+    }
+    class OptionalField {
+        char tag[2];
+        char val_type;
+        union {
+            char scalar[1];
+            struct {
+                char type;
+                char count[4];
+                char value[1];
+            } array;
+        } value;
+
+        static int type_size(int const type) {
+            switch (type) {
+                case 'A':
+                case 'C':
+                case 'c':
+                    return 1;
+                case 'S':
+                case 's':
+                    return 2;
+                case 'F':
+                case 'I':
+                case 'i':
+                    return 4;
+                default:
+                    return -1;
+            }
+        }
+
+        int size(void const *const max) const {
+            if (val_type == 'B') {
+                int const elem_size = type_size(value.array.type);
+                if (elem_size < 0)
+                    return -1;
+                int const elem_count = LE2Host<int32_t>(value.array.count);
+                char const *end = &value.array.value[elem_size * elem_count];
+
+                if (end > max)
+                    return -1;
+                return (int)(end - tag);
+            }
+            else if (val_type == 'Z' || val_type == 'H') {
+                for (char const *cur = value.scalar; cur != max; ++cur) {
+                    if (*cur == '\0')
+                        return (int)((cur + 1) - tag);
+                }
+                return -1;
+            }
+            else {
+                int const ts = type_size(val_type);
+                return ts < 0 ? -1 : (int)(&value.scalar[type_size(val_type)] - tag);
+            }
+        }
+        void const *next(void const *const max) const {
+            int const bytes = size(max);
+            if (bytes <= 0)
+                return 0;
+            return (void const *)(((char const *)this) + bytes);
+        }
+        OptionalField() {}
+    public:
+        char const *getTag() const {
+            return tag;
+        }
+        char getValueType() const {
+            if (val_type != 'B')
+                return val_type;
+            else
+                return value.array.type;
+        }
+        int getElementCount() const {
+            if (val_type != 'B')
+                return 1;
+            else
+                return LE2Host<int32_t>(value.array.count);
+        }
+        int getElementSize() const {
+            if (val_type == 'B')
+                return type_size(value.array.type);
+            else if (val_type != 'Z' && val_type != 'H')
+                return type_size(val_type);
+            else
+                return (int)strlen(value.scalar);
+        }
+        char const *getRawValue() const {
+            if (val_type == 'B')
+                return value.array.value;
+            else
+                return value.scalar;
+        }
+
+        typedef OptionalField const constOptionalField;
+        class const_iterator : public std::iterator<std::forward_iterator_tag, constOptionalField>
+        {
+            friend class BAMRecord;
+            void const *cur;
+            void const *const endp;
+
+            const_iterator(void const *const init, void const *const last) : cur(init), endp(last) {}
+        public:
+            const_iterator &operator ++() {
+                if (cur < endp)
+                    cur = ((OptionalField const *)cur)->next(endp);
+                if (!cur)
+                    cur = endp;
+                return *this;
+            }
+            OptionalField const &operator *() {
+                return *((OptionalField const *)cur);
+            }
+            OptionalField const *operator ->() {
+                return (OptionalField const *)cur;
+            }
+            friend bool operator ==(const_iterator const &a, const_iterator const &b) {
+                return a.endp == b.endp && a.cur == b.cur;
+            }
+            friend bool operator !=(const_iterator const &a, const_iterator const &b) {
+                return !(a == b);
+            }
+        };
+    };
+    OptionalField::const_iterator begin() const {
+        return OptionalField::const_iterator(extra(), endp());
+    }
+    OptionalField::const_iterator end() const {
+        return OptionalField::const_iterator(endp(), endp());
+    }
+};
+
+class BAMRecordSource
+{
+public:
+    virtual bool isGoodRecord(BAMRecord const &rec) {
+        return false;
+    }
+    virtual BAMRecord const *Read() {
+        return 0;
+    }
+    virtual void DumpSAM(std::ostream &oss, BAMRecord const &rec) const {
+
+    }
+};
+
+class BAMFile : public BAMRecordSource {
+    std::ifstream file;
+    std::vector<HeaderRefInfo> references;
+    std::map<std::string, unsigned> referencesByName;
+    std::string headerText;
+
+    std::ifstream::pos_type first_bpos;
+    std::ifstream::pos_type bpos;   /* file position of bambuffer */
+    std::ifstream::pos_type cpos;   /* file position of iobuffer  */
+    z_stream zs;
+
+    unsigned first_bam_cur;
+    unsigned bam_cur;               /* current offset in bambuffer */
+
+    Bytef iobuffer[2*IO_BLK_SIZE];
+    Bytef bambuffer[BAM_BLK_MAX];
+
+    unsigned FillBuffer(int const n);
+    void ReadZlib(void);
+    size_t ReadN(size_t N, void *Dst);
+    size_t SkipN(size_t N);
+    template <typename T> bool Read(size_t count, T *dst);
+    int32_t ReadI32();
+    bool ReadI32(int32_t &rslt);
+    void InflateInit(void);
+    void CheckHeaderSignature(void);
+    void ReadHeader(void);
+    void LoadIndexData(size_t const fsize, char const data[]);
+    void LoadIndex(std::string const &filepath);
+
+public:
+    BAMFile(std::string const &filepath);
+
+    void Seek(std::ifstream::pos_type const &new_bpos, unsigned new_bam_cur);
+    void Rewind() {
+        Seek(first_bpos, first_bam_cur);
+    }
+    virtual bool isGoodRecord(BAMRecord const &rec);
+    virtual BAMRecord const *Read();
+
+    unsigned countOfReferences() const {
+        return (unsigned)references.size();
+    }
+
+    int getReferenceIndexByName(std::string const &name) const {
+        std::map<std::string, unsigned>::const_iterator i = referencesByName.find(name);
+        if (i != referencesByName.end())
+            return i->second;
+        else
+            return -1;
+    }
+
+    HeaderRefInfo const &getRefInfo(unsigned const i) const {
+        return references[i];
+    }
+
+    BAMRecordSource *Slice(std::string const &rname, unsigned start, unsigned last);
+
+    void DumpSAM(std::ostream &oss, BAMRecord const &rec) const;
+};
+
+class BAMFileSlice : public BAMRecordSource {
+    friend class BAMFile;
+
+    BAMFile *const parent;
+    BAMFilePosTypeList const index;
+    unsigned const refID;
+    unsigned const start;
+    unsigned const end;
+    BAMFilePosTypeList::const_iterator cur;
+
+    void Seek(void)
+    {
+        BAMFilePosType const pos = *cur++;
+        std::ifstream::pos_type const fpos = pos.fpos();
+        uint16_t const bpos = pos.bpos();
+
+        parent->Seek(fpos, bpos);
+    }
+    BAMFileSlice(BAMFile &p, unsigned const r, unsigned const s, unsigned const e, BAMFilePosTypeList const &i)
+    : parent(&p)
+    , refID(r)
+    , start(s)
+    , end(e)
+    , index(i)
+    {
+        cur = index.begin();
+        Seek();
+    }
+public:
+    virtual bool isGoodRecord(BAMRecord const &rec) {
+        return parent->isGoodRecord(rec);
+    }
+    virtual BAMRecord const *Read() {
+        for ( ; ; ) {
+            BAMRecord const *const current = parent->Read();
+
+            if (!current)
+                return 0;
+
+            if (!current->isSelfMapped()) {
+                delete current;
+                continue;
+            }
+            unsigned const REF = current->refID();
+            unsigned const POS = current->pos();
+
+            if (REF != refID || POS >= end) {
+                delete current;
+                return 0;
+            }
+            unsigned const LEN = current->refLen();
+
+            if (POS + LEN <= start) {
+                delete current;
+                continue;
+            }
+            return current;
+        }
+    }
+    void DumpSAM(std::ostream &oss, BAMRecord const &rec) const {
+        parent->DumpSAM(oss, rec);
+    }
+};
diff --git a/ngs-python/configure b/ngs-bam/configure
similarity index 93%
copy from ngs-python/configure
copy to ngs-bam/configure
index 3313aac..baa556f 100755
--- a/ngs-python/configure
+++ b/ngs-bam/configure
@@ -33,13 +33,13 @@ if [ -z "$CURDIR" ]
     exit 1
 fi
 
-if [ "$FILENAME" != configure -a ! -s konfigure.perl ]
+if [ "$FILENAME" != configure -a ! -s setup/konfigure.perl ]
     then
     echo configure: error: configure should be run as ./configure
 else
     perl -v > /dev/null 2>&1 || { echo "checking for perl... no"; \
         echo >&2 "configure: error: perl not found."; exit 1; }
 
-    cd $CURDIR
-    perl -w ./konfigure.perl $@
+    cd $CURDIR/setup
+    perl -w konfigure.perl "$@"
 fi
diff --git a/ngs-bam/ngs-bam.cpp b/ngs-bam/ngs-bam.cpp
new file mode 100644
index 0000000..30121b8
--- /dev/null
+++ b/ngs-bam/ngs-bam.cpp
@@ -0,0 +1,632 @@
+/* ===========================================================================
+ *
+ *                            PUBLIC DOMAIN NOTICE
+ *               National Center for Biotechnology Information
+ *
+ *  This software/database is a "United States Government Work" under the
+ *  terms of the United States Copyright Act.  It was written as part of
+ *  the author's official duties as a United States Government employee and
+ *  thus cannot be copyrighted.  This software/database is freely available
+ *  to the public for use. The National Library of Medicine and the U.S.
+ *  Government have not placed any restriction on its use or reproduction.
+ *
+ *  Although all reasonable efforts have been taken to ensure the accuracy
+ *  and reliability of the software and data, the NLM and the U.S.
+ *  Government do not and cannot warrant the performance or results that
+ *  may be obtained by using this software or data. The NLM and the U.S.
+ *  Government disclaim all warranties, express or implied, including
+ *  warranties of performance, merchantability or fitness for any particular
+ *  purpose.
+ *
+ *  Please cite the author in any work or product based on this material.
+ *
+ * ===========================================================================
+ */
+
+#include <ngs-bam/ngs-bam.hpp>
+#include "bam.hpp"
+
+#include <ngs/ReadCollection.hpp>
+#include <ngs/adapter/ReadCollectionItf.hpp>
+#include <ngs/adapter/AlignmentItf.hpp>
+#include <ngs/adapter/ReferenceItf.hpp>
+#include <ngs/adapter/StringItf.hpp>
+
+class ReadCollection : public ngs_adapt::ReadCollectionItf
+{
+    class Alignment;
+    class AlignmentNone;
+    class AlignmentSlice;
+    class Reference;
+
+    BAMFile file;
+    std::string const path;         /* path used to open the BAM file       */
+public:
+    ReadCollection(std::string const &filepath) : path(filepath), file(filepath) {};
+    
+    ngs_adapt::StringItf *getName() const;
+    ngs_adapt::ReadGroupItf *getReadGroups() const;
+    ngs_adapt::ReadGroupItf *getReadGroup(char const spec[]) const;
+    ngs_adapt::ReferenceItf *getReferences() const;
+    ngs_adapt::ReferenceItf *getReference(char const spec[]) const;
+    ngs_adapt::AlignmentItf *getAlignment(char const spec[]) const;
+    ngs_adapt::AlignmentItf *getAlignments(bool const want_primary,
+                                           bool const want_secondary) const;
+    uint64_t getAlignmentCount(bool const want_primary,
+                               bool const want_secondary) const;
+    ngs_adapt::AlignmentItf *getAlignmentRange(uint64_t const first,
+                                               uint64_t const count,
+                                               bool const want_primary,
+                                               bool const want_secondary ) const;
+    uint64_t getReadCount(bool const want_full,
+                          bool const want_partial,
+                          bool const want_unaligned) const;
+    ngs_adapt::ReadItf *getRead(char const spec[]) const;
+    ngs_adapt::ReadItf *getReads(bool const want_full,
+                                 bool const want_partial,
+                                 bool const want_unaligned) const;
+    ngs_adapt::ReadItf *getReadRange(uint64_t const first,
+                                     uint64_t const count,
+                                     bool const want_full,
+                                     bool const want_partial,
+                                     bool const want_unaligned) const;
+    
+    void Seek(BAMFilePosType const new_pos) {
+    	file.Seek(new_pos.fpos(), new_pos.bpos());
+    }
+    BAMRecord const *ReadBAMRecord() {
+        return file.Read();
+    }
+    HeaderRefInfo const &getRefInfo(unsigned const i) const {
+        return file.getRefInfo(i);
+    }
+};
+
+// base class for the Alignment types
+// defines the default behavior of the Alignment types
+// by design, this class doesn't actually do anything but throw errors
+// it is the type that is returned when there can't be any alignments
+// for example, if want_primary and want_secondary are both false
+class ReadCollection::AlignmentNone : public ngs_adapt::AlignmentItf
+{
+    virtual ngs_adapt::StringItf *getCigar(bool const clipped, char const OPCODE[]) const {
+        throw std::runtime_error("no rows");
+    }
+public:
+    ngs_adapt::StringItf *getFragmentId() const {
+        throw std::runtime_error("not available");
+    }
+    ngs_adapt::StringItf *getFragmentBases(uint64_t offset, uint64_t length) const {
+        throw std::runtime_error("no rows");
+    }
+    ngs_adapt::StringItf *getFragmentQualities(uint64_t offset, uint64_t length) const {
+        throw std::runtime_error("no rows");
+    }
+    ngs_adapt::StringItf *getAlignmentId() const {
+        throw std::runtime_error("not available");
+    }
+    ngs_adapt::StringItf *getReferenceSpec() const {
+        throw std::runtime_error("no rows");
+    }
+    int32_t getMappingQuality() const {
+        throw std::runtime_error("no rows");
+    }
+    ngs_adapt::StringItf *getReferenceBases() const {
+        throw std::runtime_error("not available");
+    }
+    ngs_adapt::StringItf *getReadGroup() const {
+        throw std::runtime_error("no rows");
+    }
+    ngs_adapt::StringItf *getReadId() const {
+        throw std::runtime_error("no rows");
+    }
+    ngs_adapt::StringItf *getClippedFragmentBases() const {
+        throw std::runtime_error("not available");
+    }
+    ngs_adapt::StringItf *getClippedFragmentQualities() const {
+        throw std::runtime_error("not available");
+    }
+    ngs_adapt::StringItf *getAlignedFragmentBases() const {
+        throw std::runtime_error("not available");
+    }
+    ngs_adapt::StringItf *getAlignedFragmentQualities() const {
+        throw std::runtime_error("not available");
+    }
+    bool isPrimary() const {
+        throw std::runtime_error("no rows");
+    }
+    int64_t getAlignmentPosition() const {
+        throw std::runtime_error("no rows");
+    }
+    uint64_t getAlignmentLength() const {
+        throw std::runtime_error("no rows");
+    }
+    ngs_adapt::StringItf *getShortCigar(bool clipped) const {
+        return getCigar(clipped, "MIDNSHPMM???????");
+    }
+    ngs_adapt::StringItf *getLongCigar(bool clipped) const {
+        return getCigar(clipped, "MIDNSHP=X???????");
+    }
+    char getRNAOrientation () const {
+        throw std::runtime_error("no rows");
+    }
+    bool getIsReversedOrientation() const {
+        throw std::runtime_error("no rows");
+    }
+    int32_t getSoftClip(uint32_t edge) const {
+        throw std::runtime_error("not available");
+    }
+    uint64_t getTemplateLength() const {
+        throw std::runtime_error("no rows");
+    }
+    bool hasMate() const {
+        throw std::runtime_error("no rows");
+    }
+    ngs_adapt::StringItf *getMateAlignmentId() const {
+        throw std::runtime_error("not available");
+    }
+    ngs_adapt::AlignmentItf *getMateAlignment() const {
+        throw std::runtime_error("not available");
+    }
+    ngs_adapt::StringItf *getMateReferenceSpec() const {
+        throw std::runtime_error("no rows");
+    }
+    bool getMateIsReversedOrientation() const {
+        throw std::runtime_error("no rows");
+    }
+    bool nextAlignment() {
+        return false;
+    }
+    bool nextFragment() {
+        throw std::runtime_error("not available");
+    }
+};
+
+class ReadCollection::Alignment : public ReadCollection::AlignmentNone
+{
+    mutable std::string seqBuffer;
+    mutable std::string qualBuffer;
+    mutable std::string cigarBuffer;
+protected:
+    ReadCollection *parent;
+    BAMRecord const *current;
+    bool want_primary;
+    bool want_secondary;
+
+    ngs_adapt::StringItf *getCigar(bool const clipped, char const OPCODE[]) const;
+    
+    bool shouldSkip() const {
+        int const flag = current->flag();
+
+        if ((flag & 0x0004) != 0)
+            return true;
+        
+        if ((flag & 0x0900) == 0 && !want_primary)
+            return true;
+        
+        if ((flag & 0x0900) != 0 && !want_secondary)
+            return true;
+        
+        return false;
+    }
+
+public:
+    Alignment(ReadCollection const *Parent, bool WantPrimary, bool WantSecondary) {
+        parent = static_cast<ReadCollection *>(Parent->Duplicate());
+        want_primary = WantPrimary;
+        want_secondary = WantSecondary;
+        current = 0;
+    }
+    virtual ~Alignment() {
+        if (current)
+            delete current;
+        parent->Release();
+    }
+    
+    ngs_adapt::StringItf *getFragmentBases(uint64_t offset, uint64_t length) const;
+    ngs_adapt::StringItf *getFragmentQualities(uint64_t offset, uint64_t length) const;
+    ngs_adapt::StringItf *getReferenceSpec() const;
+    int32_t getMappingQuality() const;
+    ngs_adapt::StringItf *getReadGroup() const;
+    ngs_adapt::StringItf *getReadId() const;
+    bool isPrimary() const;
+    int64_t getAlignmentPosition() const;
+    uint64_t getAlignmentLength() const;
+    bool getIsReversedOrientation() const;
+    uint64_t getTemplateLength() const;
+    bool hasMate() const;
+    ngs_adapt::StringItf *getMateReferenceSpec() const;
+    bool getMateIsReversedOrientation() const;
+    bool nextAlignment();
+};
+
+class ReadCollection::AlignmentSlice : public ReadCollection::Alignment
+{
+    unsigned refID;
+    unsigned beg;
+    unsigned end;
+    BAMFilePosTypeList const slice;
+    BAMFilePosTypeList::const_iterator cur;
+public:
+    AlignmentSlice(ReadCollection const *Parent,
+                   bool const WantPrimary,
+                   bool const WantSecondary,
+                   BAMFilePosTypeList const &Slice,
+                   unsigned const Beg,
+                   unsigned const End)
+    : Alignment(Parent, WantPrimary, WantSecondary)
+    , slice(Slice)
+    , beg(Beg)
+    , end(End)
+    , cur(Slice.begin())
+    {
+        parent->Seek(*cur++);
+    }
+    
+    bool nextAlignment() {
+        for ( ; ; ) {
+            if (!Alignment::nextAlignment())
+                return false;
+            if (current->isSelfMapped()) {
+                unsigned const POS   = current->pos();
+                unsigned const REFID = current->refID();
+                
+                if (REFID != refID || POS >= end)
+                    return false;
+                
+                unsigned const REFLEN = current->refLen();
+                if (POS + REFLEN > beg)
+                    return true;
+            }
+        }
+    }
+};
+
+class ReadCollection::Reference : public ngs_adapt::ReferenceItf
+{
+    ReadCollection *parent;
+    unsigned cur;
+    unsigned max;
+    int state;
+    
+public:
+    Reference(ReadCollection const *const Parent,
+              unsigned const current,
+              unsigned const references,
+              int const initState)
+    : parent(static_cast<ReadCollection *>(Parent->Duplicate()))
+    , cur(current)
+    , max(references)
+    , state(initState)
+    {}
+    
+    ~Reference() {
+        parent->Release();
+    }
+    
+    ngs_adapt::StringItf *getCommonName() const {
+        if (state == 2)
+            throw std::runtime_error("no current row");
+        
+        HeaderRefInfo const &ri = parent->getRefInfo(cur);
+        std::string const &RNAME = ri.getName();
+        
+        return new ngs_adapt::StringItf(RNAME.data(), RNAME.size());
+    }
+    ngs_adapt::StringItf *getCanonicalName() const {
+        throw std::runtime_error("not available");
+    }
+    // TODO: rename to isCircular
+    bool getIsCircular() const {
+        throw std::runtime_error("not available");
+    }
+    uint64_t getLength() const {
+        if (state == 2)
+            throw std::runtime_error("no current row");
+        
+        HeaderRefInfo const &ri = parent->getRefInfo(cur);
+        
+        return ri.getLength();
+    }
+    ngs_adapt::StringItf *getReferenceBases(uint64_t const offset, uint64_t const length) const {
+        throw std::runtime_error("not available");
+    }
+    ngs_adapt::StringItf *getReferenceChunk(uint64_t const offset, uint64_t const length) const {
+        throw std::runtime_error("not available");
+    }
+    ngs_adapt::AlignmentItf *getAlignment(char const id[]) const {
+        throw std::runtime_error("not available");
+    }
+    ngs_adapt::AlignmentItf *getAlignments(bool const want_primary, bool const want_secondary) const {
+        return getAlignmentSlice(0, getLength(), want_primary, want_secondary);
+    }
+    ngs_adapt::AlignmentItf *getAlignmentSlice(int64_t const Start, uint64_t const length, bool const want_primary, bool const want_secondary) const {
+        if (state == 2)
+            throw std::runtime_error("no current row");
+        
+        HeaderRefInfo const &ri = parent->getRefInfo(cur);
+        unsigned const len = ri.getLength();
+        if (Start >= len)
+            return new ReadCollection::AlignmentNone();
+        
+        unsigned const start = Start < 0 ? 0 : Start;
+        uint64_t const End = (Start < 0 ? 0 : Start) + length;
+        unsigned const end = End > len ? len : End;
+        BAMFilePosTypeList const &slice = ri.slice(start, end);
+        
+        if (slice.size() == 0)
+            return new ReadCollection::AlignmentNone();
+
+        return new ReadCollection::AlignmentSlice(parent, want_primary, want_secondary,
+                                                  slice, start, end);
+    }
+    ngs_adapt::PileupItf *getPileups(bool const want_primary, bool const want_secondary) const {
+        throw std::runtime_error("not available");
+    }
+    ngs_adapt::PileupItf *getPileupSlice(int64_t const start, uint64_t const length, bool const want_primary, bool const want_secondary) const {
+        throw std::runtime_error("not available");
+    }
+    bool nextReference() {
+        switch (state) {
+            case 0:
+                if (cur < max) {
+                    state = 1;
+                    return true;
+                }
+                else {
+                    state = 2;
+                    return false;
+                }
+            case 1:
+                ++cur;
+                if (cur < max)
+                    return true;
+                state = 2;
+            case 2:
+                return false;
+            default:
+                throw std::runtime_error("no more rows available");
+        }
+    }
+};
+
+ngs_adapt::StringItf *ReadCollection::getName() const
+{
+    unsigned const sep = path.rfind('/');
+    
+    if (sep == path.npos)
+        return new ngs_adapt::StringItf(path.data(), path.size());
+    else {
+        char const *name = path.data() + sep + 1;
+        unsigned const len = path.size() - sep - 1;
+        return new ngs_adapt::StringItf(name, len);
+    }
+}
+
+ngs_adapt::ReadGroupItf *ReadCollection::getReadGroups() const
+{
+    throw std::logic_error("unimplemented");
+}
+
+ngs_adapt::ReadGroupItf *ReadCollection::getReadGroup(char const spec[]) const
+{
+    throw std::logic_error("unimplemented");
+}
+
+ngs_adapt::ReferenceItf *ReadCollection::getReferences() const
+{
+    return new Reference(this, 0, file.countOfReferences(), 0);
+}
+
+ngs_adapt::ReferenceItf *ReadCollection::getReference(char const spec[]) const
+{
+    int const i = file.getReferenceIndexByName(spec);
+    
+    if (i < 0)
+        return NULL;
+    else
+        return new Reference(this, i, 0, 3);
+}
+
+ngs_adapt::AlignmentItf *ReadCollection::getAlignment(char const spec[]) const
+{
+    throw std::logic_error("unimplemented");
+}
+
+ngs_adapt::AlignmentItf *ReadCollection::getAlignments(bool const want_primary,
+                                                       bool const want_secondary) const
+{
+    if (!want_secondary && !want_primary)
+        return new AlignmentNone();
+    const_cast<BAMFile *>(&file)->Rewind();
+    return new Alignment(this, want_primary, want_secondary);
+}
+
+uint64_t ReadCollection::getAlignmentCount(bool const want_primary,
+                                           bool const want_secondary) const
+{
+    throw std::logic_error("unimplemented");
+}
+
+ngs_adapt::AlignmentItf *ReadCollection::getAlignmentRange(uint64_t const first,
+                                                           uint64_t const count,
+                                                           bool const want_primary,
+                                                           bool const want_secondary ) const
+{
+    throw std::logic_error("unimplemented");
+}
+
+uint64_t ReadCollection::getReadCount(bool const want_full,
+                                      bool const want_partial,
+                                      bool const want_unaligned) const
+{
+    throw std::logic_error("unimplemented");
+}
+
+ngs_adapt::ReadItf *ReadCollection::getRead(char const spec[]) const
+{
+    throw std::logic_error("unimplemented");
+}
+
+ngs_adapt::ReadItf *ReadCollection::getReads(bool const want_full,
+                                             bool const want_partial,
+                                             bool const want_unaligned) const
+{
+    throw std::logic_error("unimplemented");
+}
+
+ngs_adapt::ReadItf *ReadCollection::getReadRange(uint64_t const first,
+                                                 uint64_t const count,
+                                                 bool const want_full,
+                                                 bool const want_partial,
+                                                 bool const want_unaligned) const
+{
+    throw std::logic_error("unimplemented");
+}
+
+ngs_adapt::StringItf *ReadCollection::Alignment::getFragmentBases(uint64_t const Offset, uint64_t const Length) const
+{
+    uint64_t const End = Offset + Length;
+    unsigned const seqLen = current->l_seq();
+    unsigned const offset = Offset < seqLen ? Offset : seqLen;
+    unsigned const seqEnd = End < seqLen ? End : seqLen;
+    
+    seqBuffer.resize(0);
+    seqBuffer.reserve(seqLen);
+    
+    for (unsigned i = offset; i < seqEnd; ++i)
+        seqBuffer.append(1, current->seq(i));
+    
+    return new ngs_adapt::StringItf(seqBuffer.data(), seqBuffer.size());
+}
+
+ngs_adapt::StringItf *ReadCollection::Alignment::getFragmentQualities(uint64_t const Offset, uint64_t const Length) const
+{
+    uint64_t const End = Offset + Length;
+    unsigned const seqLen = current->l_seq();
+    unsigned const offset = Offset < seqLen ? Offset : seqLen;
+    unsigned const seqEnd = End < seqLen ? End : seqLen;
+    bool notFF = false;
+    uint8_t const *qual = current->qual();
+    
+    qualBuffer.resize(0);
+    qualBuffer.reserve(seqLen);
+    
+    for (unsigned i = offset; i < seqEnd; ++i) {
+        int const qv = qual[i];
+        
+        notFF |= (qv != 0xFF);
+        qualBuffer.append(1, (char)((qv > 63 ? 63 : qv) + 33));
+    }
+    return new ngs_adapt::StringItf(qualBuffer.data(), notFF ? qualBuffer.size() : 0);
+}
+
+ngs_adapt::StringItf *ReadCollection::Alignment::getReferenceSpec() const
+{
+    int const refID = current->refID();
+    HeaderRefInfo const &ri = parent->getRefInfo(refID);
+    std::string const &RNAME = ri.getName();
+    return new ngs_adapt::StringItf(RNAME.data(), RNAME.size());
+}
+
+int32_t ReadCollection::Alignment::getMappingQuality() const
+{
+    return current->mq();
+}
+
+ngs_adapt::StringItf *ReadCollection::Alignment::getReadGroup() const
+{
+    for (BAMRecord::OptionalField::const_iterator i = current->begin(); i != current->end(); ++i) {
+        char const *tag = i->getTag();
+        if (tag[0] == 'R' && tag[1] == 'G' && i->getValueType() == 'Z') {
+            return new ngs_adapt::StringItf(i->getRawValue(), i->getElementSize());
+        }
+    }
+    return NULL;
+}
+
+ngs_adapt::StringItf *ReadCollection::Alignment::getReadId() const
+{
+    char const *const QNAME = current->readname();
+    size_t const len = strnlen(QNAME, current->l_read_name());
+    return new ngs_adapt::StringItf(QNAME, len);
+}
+
+bool ReadCollection::Alignment::isPrimary() const
+{
+    return (current->flag() & 0x0900) == 0;
+}
+
+int64_t ReadCollection::Alignment::getAlignmentPosition() const
+{
+    return current->pos();
+}
+
+uint64_t ReadCollection::Alignment::getAlignmentLength() const {
+    return current->refLen();
+}
+
+ngs_adapt::StringItf *ReadCollection::Alignment::getCigar(bool const clipped, char const OPCODE[]) const
+{
+    current->cigarString(cigarBuffer, clipped, OPCODE);
+    return new ngs_adapt::StringItf(cigarBuffer.data(), cigarBuffer.size());
+}
+
+bool ReadCollection::Alignment::getIsReversedOrientation() const
+{
+    return (current->flag() & 0x0010) != 0;
+}
+
+// TODO: return type should be int64_t
+uint64_t ReadCollection::Alignment::getTemplateLength() const
+{
+    return current->tlen();
+}
+
+bool ReadCollection::Alignment::hasMate() const
+{
+    int const FLAG = current->flag();
+
+    return (FLAG & 0x0001) != 0 && (FLAG & 0x00C0) != 0 && (FLAG & 0x00C0) != 0x00C0;
+}
+
+ngs_adapt::StringItf *ReadCollection::Alignment::getMateReferenceSpec() const
+{
+    int const refID = current->next_refID();
+    
+    if (refID < 0)
+        return new ngs_adapt::StringItf("", 0);
+
+    HeaderRefInfo const &ri = parent->getRefInfo(refID);
+    std::string const &RNEXT = ri.getName();
+    return new ngs_adapt::StringItf(RNEXT.data(), RNEXT.size());
+}
+
+// TODO: rename to isMateReversedOrientation
+bool ReadCollection::Alignment::getMateIsReversedOrientation() const
+{
+    return (current->flag() & 0x0020) != 0;
+}
+
+bool ReadCollection::Alignment::nextAlignment()
+{
+    do {
+        if (current) {
+            delete current;
+            current = 0;
+        }
+        current = parent->ReadBAMRecord();
+        if (!current)
+            return false;
+    } while (shouldSkip());
+    return true;
+}
+
+ngs::ReadCollection NGS_BAM::openReadCollection(std::string const &path)
+{
+    ngs_adapt::ReadCollectionItf *const self = new ReadCollection(path);
+    NGS_ReadCollection_v1 *const c_obj = self->Cast();
+    ngs::ReadCollectionItf *const ngs_itf = ngs::ReadCollectionItf::Cast(c_obj);
+    
+    return ngs::ReadCollection(ngs_itf);
+}
diff --git a/ngs-bam/ngs-bam/ngs-bam.hpp b/ngs-bam/ngs-bam/ngs-bam.hpp
new file mode 100644
index 0000000..f0f85b5
--- /dev/null
+++ b/ngs-bam/ngs-bam/ngs-bam.hpp
@@ -0,0 +1,45 @@
+/* ===========================================================================
+ *
+ *                            PUBLIC DOMAIN NOTICE
+ *               National Center for Biotechnology Information
+ *
+ *  This software/database is a "United States Government Work" under the
+ *  terms of the United States Copyright Act.  It was written as part of
+ *  the author's official duties as a United States Government employee and
+ *  thus cannot be copyrighted.  This software/database is freely available
+ *  to the public for use. The National Library of Medicine and the U.S.
+ *  Government have not placed any restriction on its use or reproduction.
+ *
+ *  Although all reasonable efforts have been taken to ensure the accuracy
+ *  and reliability of the software and data, the NLM and the U.S.
+ *  Government do not and cannot warrant the performance or results that
+ *  may be obtained by using this software or data. The NLM and the U.S.
+ *  Government disclaim all warranties, express or implied, including
+ *  warranties of performance, merchantability or fitness for any particular
+ *  purpose.
+ *
+ *  Please cite the author in any work or product based on this material.
+ *
+ * ===========================================================================
+ */
+
+#ifndef _hpp_ngs_bam_
+#define _hpp_ngs_bam_
+
+#ifndef _hpp_ngs_read_collection_
+#include <ngs/ReadCollection.hpp>
+#endif
+
+#include <string>
+
+namespace NGS_BAM
+{
+
+    /* openReadCollection
+     *  create an object representing a named collection of reads
+     *  "path" is a file-system path to a BAM file
+     */
+    ngs :: ReadCollection openReadCollection ( const std :: string & path );
+}
+
+#endif // _hpp_ngs_bam_
diff --git a/ngs-python/configure b/ngs-bam/setup/install
similarity index 83%
copy from ngs-python/configure
copy to ngs-bam/setup/install
index 3313aac..4dcf8cf 100755
--- a/ngs-python/configure
+++ b/ngs-bam/setup/install
@@ -29,17 +29,17 @@ CURDIR="`dirname $0`"
 
 if [ -z "$CURDIR" ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
     exit 1
 fi
 
-if [ "$FILENAME" != configure -a ! -s konfigure.perl ]
+if [ "$FILENAME" != install -a ! -s install.perl ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
 else
     perl -v > /dev/null 2>&1 || { echo "checking for perl... no"; \
-        echo >&2 "configure: error: perl not found."; exit 1; }
+        echo >&2 "error: perl not found."; exit 1; }
 
     cd $CURDIR
-    perl -w ./konfigure.perl $@
+    perl -w ./install.perl "$@"
 fi
diff --git a/ngs-bam/setup/install.perl b/ngs-bam/setup/install.perl
new file mode 100644
index 0000000..5e5f33e
--- /dev/null
+++ b/ngs-bam/setup/install.perl
@@ -0,0 +1,1324 @@
+################################################################################
+
+use strict;
+
+require 'install.prl';
+
+use Config;
+use Cwd        "abs_path";
+use File::Copy "copy";
+use File::Copy::Recursive qw(dircopy);
+use File::Path   "make_path";
+use FindBin    qw($Bin);
+use Getopt::Long "GetOptions";
+
+my ($OS, $MAKING, %INSTALLED_LIBS);
+{
+    my $file = 'os.prl';
+    if (-e $file) {
+        require $file;
+        $OS = OS();
+    } else {
+        ++$MAKING;
+    }
+}
+
+my %HAVE = HAVE();
+BINS() if ($HAVE{BINS});
+if ($HAVE{LIBS}) {
+    ++$HAVE{INCLUDES};
+    LIBS();
+}
+if ($HAVE{INCLUDES} || $HAVE{USR_INCLUDES}) {
+    die "no INCLUDES" unless INCLUDES();
+}
+die "no CONFIG_OUT" unless CONFIG_OUT();
+
+my @bits;
+my @options = ( 'debug', 'examplesdir=s', 'force', 'help',
+                'includedir=s', 'no-create', 'prefix=s', 'root=s', );
+push @options, 'oldincludedir=s' if ($HAVE{USR_INCLUDES});
+if ($HAVE{JAR}) {
+    push @options, 'jardir=s';
+    if (-e "$Bin/../jar") {
+        ++$HAVE{LIBS};
+        $_{JARDIR} = expand_path("$Bin/../jar");
+    }
+} elsif ($HAVE{PYTHON} && ! $MAKING) {
+    ++$HAVE{LIBS};
+}
+if (! $MAKING && ($HAVE{JAR} || $HAVE{PYTHON})) {
+    ++$HAVE{TWO_LIBS};
+    push @options, 'ngslibdir=s', 'vdblibdir=s';
+}
+push @options, 'bindir=s'                     if ($HAVE{BINS});
+push @options, 'bits=s' => \@bits, 'libdir=s' if ($HAVE{LIBS});
+
+my %OPT;
+unless (GetOptions(\%OPT, @options)) {
+    print "install: error\n";
+    exit 1;
+}
+ at bits = split(/,/,join(',', at bits));
+foreach (@bits) {
+    unless (/^32$/ || /^64$/) {
+        print "install: error: bad bits option argument value\n";
+        exit 1;
+    }
+}
+if ($#bits > 0) {
+    foreach (qw(bindir libdir ngslibdir vdblibdir)) {
+        if ($OPT{$_}) {
+            print "install: error: cannot supply multiple bits arguments "
+                . "when $_ argument is provided\n";
+            exit 1;
+        }
+    }
+}
+
+$OPT{root} = expand_path($OPT{root}) if ($OPT{root});
+
+prepare();
+
+my $LINUX_ROOT;
+++$LINUX_ROOT if (linux_root());
+my $ROOT = '';
+if ($OPT{root}) {
+    $ROOT = "$OPT{root}/root";
+    ++$LINUX_ROOT;
+    foreach ("$ROOT/usr/include", "$ROOT/etc/profile.d") {
+        unless (-e $_) {
+            print "mkdir -p $_... ";
+            eval { make_path($_) };
+            if ($@) {
+                print "failure: $@\n";
+                exit 1;
+            }
+            print "ok\n";
+        }
+    }
+}
+
+my $oldincludedir = "$ROOT/usr/include";
+
+my $EXAMPLES_DIR = "$Bin/../examples";
+
+ at _ = CONFIGURE();
+
+if ($OPT{help}) {
+    help();
+    exit 0;
+}
+
+foreach (qw(BITS INCDIR
+ INST_INCDIR INST_JARDIR INST_LIBDIR INST_NGSLIBDIR INST_SHAREDIR INST_VDBLIBDIR
+ LIBX LPFX MAJVERS MAJVERS_SHLX OS OTHER_PREFIX
+ PACKAGE_NAME PREFIX SHLX VERSION VERSION_LIBX VERSION_SHLX))
+{
+    unless ($_{$_}) {
+        next if (/^INST_JARDIR$/    && ! $HAVE{JAR});
+        next if (/^INST_NGSLIBDIR$/ && ! $HAVE{TWO_LIBS});
+        next if (/^INST_SHAREDIR$/  && ! $HAVE{EXAMPLES});
+        next if (/^INST_VDBLIBDIR$/ && ! $HAVE{TWO_LIBS});
+        fatal_config("$_ not found");
+    }
+}
+unless ($_{LIBDIR32} || $_{LIBDIR64} || ($HAVE{PYTHON} && $MAKING)) {
+    fatal_config('LIBDIR not found');
+}
+ 
+if ($OPT{prefix}) {
+    $OPT{prefix} = expand_path($OPT{prefix});
+    $_{INST_BINDIR  } = "$OPT{prefix}/bin";
+    $_{INST_LIBDIR  } = "$OPT{prefix}/lib";
+    $_{INST_NGSLIBDIR} = $_{INST_VDBLIBDIR} = $_{INST_LIBDIR};
+    $_{INST_INCDIR  } = "$OPT{prefix}/include";
+    $_{INST_JARDIR  } = "$OPT{prefix}/jar";
+    $_{INST_SHAREDIR} = "$OPT{prefix}/share";
+}
+$_{INST_SHAREDIR} = expand_path($OPT{examplesdir  }) if ($OPT{examplesdir  });
+$_{INST_INCDIR  } = expand_path($OPT{includedir   }) if ($OPT{includedir   });
+$_{INST_JARDIR  } = expand_path($OPT{jardir       }) if ($OPT{jardir       });
+$_{BIN_TARGET   } = expand_path($OPT{bindir       }) if ($OPT{bindir       });
+$oldincludedir    = expand_path($OPT{oldincludedir}) if ($OPT{oldincludedir});
+if ($OPT{libdir}) {
+    $_{INST_NGSLIBDIR} = $_{LIB_TARGET} = expand_path($OPT{libdir}) ;
+    $_{INST_VDBLIBDIR} = $_{LIB_TARGET};
+}
+$_{INST_NGSLIBDIR}= expand_path($OPT{ngslibdir}) if ($OPT{ngslibdir});
+$_{INST_VDBLIBDIR}= expand_path($OPT{vdblibdir}) if ($OPT{vdblibdir});
+
+if ($OPT{'no-create'} && $_{OS} eq 'linux') {
+    if ($LINUX_ROOT) {
+        print "root user\n\n";
+    } else {
+        print "non root user\n\n";
+    }
+}
+
+my $failures = 0;
+my $bFailure = 1;
+
+push @bits, $_{BITS} unless (@bits);
+foreach (@bits) {
+    $_{BITS} = $_;
+
+    print "installing $_{PACKAGE_NAME} ($_{VERSION}) package";
+    print " for $_{OS}-$_{BITS}" if ($HAVE{BINS} || $HAVE{LIBS});
+    print "...\n";
+
+    if ($HAVE{BINS}) {
+        $_{BINDIR} = $_{"BINDIR$_{BITS}"};
+        unless ($_{BINDIR}) {
+            print "install: error: $_{BITS}-bit version is not available\n\n";
+            next;
+        }
+    }
+    if ($HAVE{LIBS} || $HAVE{PYTHON}) {
+# ($_{LIBDIR} for python points where ngs-sdk and ncbi-vdb dynamic libraries
+# can be found to correctly set up LD_LIBRARY_PATH
+        $_{LIBDIR} = $_{"LIBDIR$_{BITS}"};
+        unless ($_{LIBDIR}) {
+            print "install: error: $_{BITS}-bit version is not available\n\n";
+            next;
+        }
+    }
+    if ($HAVE{JAR} && ! $_{JARDIR}) {
+        $_{JARDIR} = $_{"LIBDIR$_{BITS}"};
+        unless ($_{JARDIR}) {
+            if ($_{BITS} == 64) {
+                $_{JARDIR} = $_{LIBDIR32};
+            } else {
+                $_{JARDIR} = $_{LIBDIR64};
+            }
+            unless ($_{JARDIR}) {
+                print "install: error: jar file was not cannot found\n";
+                exit 1;
+            }
+        }
+    }
+    $bFailure = 0;
+
+    if ($OPT{'no-create'}) {
+        print     "includedir : '$_{INST_INCDIR  }'\n" if ($HAVE{INCLUDES  });
+        print     "libdir     : '$_{INST_LIBDIR}$_{BITS}'\n" if ($HAVE{LIBS});
+        print     "jardir     : '$_{INST_JARDIR  }'\n" if ($HAVE{JAR       });
+        print     "examplesdir: '$_{INST_SHAREDIR}'\n" if ($HAVE{EXAMPLES  });;
+        if ($LINUX_ROOT) {
+            print "oldincludedir: '$oldincludedir'\n"  if ($HAVE{USR_INCLUDES});
+        }
+        print "\n";
+        next;
+    }
+
+    $_{BIN_TARGET} = "$_{INST_BINDIR}$_{BITS}" unless ($OPT{bindir});
+    $_{LIB_TARGET} = "$_{INST_LIBDIR}$_{BITS}" unless ($OPT{libdir});
+
+    $File::Copy::Recursive::CPRFComp = 1;
+
+    $failures += copybins    () if ($HAVE{BINS});
+    $failures += copylibs    () if ($HAVE{LIBS});
+    $failures += copyincludes() if ($HAVE{INCLUDES});
+    $failures += copyjars    () if ($HAVE{JAR});
+    $failures += copyconfig  () if ($HAVE{CONFIG});
+
+    if ($HAVE{JAR}) {
+        $File::Copy::Recursive::CPRFComp = 0;
+        $failures += copydocs() ;
+        $File::Copy::Recursive::CPRFComp = 1;
+    }
+
+    $failures += copyexamples();
+    $failures += finishinstall() unless ($failures);
+
+    unless ($failures) {
+        print "\nsuccessfully installed $_{PACKAGE_NAME} ($_{VERSION}) package";
+    } else {
+        print "\nfailed to install $_{PACKAGE_NAME} ($_{VERSION}) package";
+    }
+    print " for $_{OS}-$_{BITS}" if ($HAVE{BINS} || $HAVE{LIBS});
+    print ".\n\n";
+}
+
+$failures = 1 if (!$failures && $bFailure);
+
+exit $failures;
+
+################################################################################
+
+sub copybins {
+    unless ($_{BIN_TARGET}) {
+        print "error: cannot install executables: no BIN_TARGET\n";
+        return 1;
+    }
+    my $s = $_{BINDIR};
+    my $d = $_{BIN_TARGET};
+    print "installing executables to $d...";
+    unless (-e $s) {
+        print " failure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+    print "\t\tcd $d\n" if ($OPT{debug});
+    chdir $d or die "cannot cd $d";
+    my $failures = 0;
+    foreach (BINS()) {
+        print "installing '$_'..." if ($OPT{debug});
+        my $df = "$_$_{VERSION_EXEX}";
+        my $sf = "$s/$df";
+        print "\n\t\t$sf -> $df\n\t" if ($OPT{debug});
+        unless (-e $sf) {
+            print " skipped\n" if ($OPT{debug});
+            next;
+        }
+        if ((! $OPT{force}) && (-e $df) && (-M $df < -M $sf)) {
+            print " found\n" if ($OPT{debug});
+        } else {
+            unless (copy($sf, $df)) {
+                print "failure\n";
+                print "install: error: cannot copy '$sf' '$df'.\n";
+                ++$failures;
+                next;
+            }
+            my $mode = 0755;
+            printf "\tchmod %o $df\n\t", $mode if ($OPT{debug});
+            unless (chmod($mode, $df)) {
+                print " failure\n" if ($OPT{debug});
+                print "install: error: cannot chmod '$df': $!\n";
+                ++$failures;
+                next;
+            }
+            unless (symlinks($_, $df, 'bin')) {
+                print " success\n" if ($OPT{debug});
+            } else {
+                print " failure\n" if ($OPT{debug});
+                ++$failures;
+            }
+        }
+    }
+    return $failures;
+}
+
+sub copyconfig {
+    my $d;
+    if ($LINUX_ROOT) {
+        $d = "$ROOT/etc";
+    }
+    elsif ($HAVE{BINS}) {
+        $d = $_{BIN_TARGET};
+        unless ($d) {
+            print
+               "error: cannot install configuration files: no BIN_TARGET\n";
+            return 1;
+        }
+    } else {
+        $d = $_{LIB_TARGET};
+        unless ($d) {
+            print
+               "error: cannot install configuration files: no LIB_TARGET\n";
+            return 1;
+        }
+    }
+    $d = File::Spec->catdir($d, 'ncbi');
+    my $kfg = File::Spec->catdir($Bin, '..', 'libs/kfg/default.kfg');
+    unless (-e $kfg) {
+        $kfg = File::Spec->catdir($Bin, '..', 'tools/vdb-copy/vdb-copy.kfg');
+    }
+    unless (-e $kfg) {
+        if ($_{BINDIR}) {
+            $kfg = File::Spec->catdir($_{BINDIR}, 'ncbi', 'vdb-copy.kfg');
+        } elsif ($_{LIBDIR}) {
+            $kfg = File::Spec->catdir($_{LIBDIR}, 'ncbi', 'default.kfg');
+            unless (-e $kfg) {
+                print
+                  "error: cannot install configuration files: no default.kfg\n";
+                return 1;
+            }
+        }
+    }
+    print "installing configuration files to $d... ";
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+    my $df = File::Spec->catdir($d, 'ncbi-vdb.kfg');
+    print "\t\t$kfg -> $df\n" if ($OPT{debug});
+    unless (copy($kfg, $df)) {
+        print "install: error: cannot copy '$kfg' '$df'.\n";
+        return 1;
+    } else {
+        print "success\n";
+        return 0;
+    }
+}
+
+sub copylibs {
+    die unless ($HAVE{LIBS});
+
+    my $s = $_{LIBDIR};
+    my $d = $_{LIB_TARGET};
+
+    print "installing libraries to $d... ";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    if ($HAVE{TWO_LIBS}) {
+        my $ngs = $_{INST_NGSLIBDIR};
+        if ($ngs && ! ($OPT{prefix} && $OPT{libdir} && $OPT{ngslibdir})) {
+            $ngs .= $_{BITS};
+        }
+        my $vdb = $_{INST_VDBLIBDIR};
+        if ($vdb && ! ($OPT{prefix} && $OPT{libdir} && $OPT{vdblibdir})) {
+            $vdb .= $_{BITS};
+        }
+        if ($ngs || $vdb) {
+            unless ($ngs && $vdb) {
+                $ngs = $d unless ($ngs);
+                $vdb = $d unless ($vdb);
+            }
+            $INSTALLED_LIBS{'ngs-sdk' } = $ngs;
+            $INSTALLED_LIBS{'ncbi-vdb'} = $vdb;
+        }
+    }
+    $INSTALLED_LIBS{0} = $d unless (%INSTALLED_LIBS);
+
+    foreach (keys %INSTALLED_LIBS) {
+        my $d = $INSTALLED_LIBS{$_};
+        print "\nchecking $d... ";
+        unless (-e $d) {
+            print "not found\n";
+            print "mkdir -p $d... ";
+            eval { make_path($d) };
+            if ($@) {
+                print "failure\ninstall: error: cannot mkdir $d\n";
+                return 1;
+            } else {
+                print "success\n";
+            }
+        } else {
+            print "exists\n";
+        }
+    }
+
+    return $MAKING ? copybldlibs($s, $d) : copydir($s, %INSTALLED_LIBS);
+}
+
+sub copybldlibs {
+    my ($s, $d) = @_;
+
+    print "\t\tcd $d\n" if ($OPT{debug});
+    chdir $d or die "cannot cd $d";
+
+    my $failures = 0;
+
+    my %LIBRARIES_TO_INSTALL = LIBS();
+    foreach (keys %LIBRARIES_TO_INSTALL) {
+        print "installing '$_'... ";
+
+        my $nb = "$_{LPFX}$_";
+        my $nv = "$nb.";
+        my $lib = 'dll';
+        if ($LIBRARIES_TO_INSTALL{$_} eq 'SHL') {
+            $nv .= $_{VERSION_SHLX};
+        } elsif ($LIBRARIES_TO_INSTALL{$_} eq 'LIB') {
+            $nv .= $_{VERSION_LIBX};
+            $lib = 'lib';
+        } else {
+            die "bad library type";
+        }
+
+        my $sf = "$s/$nv";
+        my $df = "$d/$nv";
+
+        print "\n\t\t$sf -> $df\n\t" if ($OPT{debug});
+
+        unless (-e $sf) {
+            print "failure\n";
+            print "install: error: '$sf' is not found.\n";
+            ++$failures;
+            next;
+        }
+
+        if ((! $OPT{force}) && (-e $df) && (-M $df < -M $sf)) {
+            print "found\n";
+        } else {
+            unless (copy($sf, $df)) {
+                print "failure\n";
+                print "install: error: cannot copy '$sf' '$df'.\n";
+                ++$failures;
+                next;
+            }
+            my $mode = 0644;
+            $mode = 0755 if ($lib eq 'dll');
+            printf "\tchmod %o $df\n\t", $mode if ($OPT{debug});
+            unless (chmod($mode, $df)) {
+                print "failure\n";
+                print "install: error: cannot chmod '$df': $!\n";
+                ++$failures;
+                next;
+            }
+            unless (symlinks($nb, $nv, $lib)) {
+                print "success\n";
+            } else {
+                print "failure\n";
+                ++$failures;
+            }
+        }
+    }
+
+    return $failures;
+}
+
+sub symlinks {
+    my ($nb, $nv, $type) = @_;
+
+    my @l;
+    if ($type eq 'lib') {
+        push @l, "$nb-static.$_{LIBX}";
+        push @l, "$nb.$_{LIBX}";
+        push @l, "$nb.$_{MAJVERS_LIBX}";
+    } elsif ($type eq 'dll') {
+        push @l, "$nb.$_{SHLX}";
+        push @l, "$nb.$_{MAJVERS_SHLX}";
+    } elsif ($type eq 'bin' || $type eq 'jar') {
+        push @l, $nb;
+        push @l, "$nb.$_{MAJVERS}";
+    } else {
+        print "failure\n";
+        print "install: error: unknown symlink type '$type'\n";
+        return 1;
+    }
+
+    my $failures = 0;
+
+    for (my $i = 0; $i <= $#l; ++$i) {
+        my $file = $l[$i];
+        if (-e $file) {
+            print "\trm $file\n\t" if ($OPT{debug});
+            unless (unlink $file) {
+                print "failure\n";
+                print "install: error: cannot rm '$file': $!\n";
+                ++$failures;
+                next;
+            }
+        }
+
+        my $o = $nv;
+        $o = $l[$i + 1] if ($i < $#l);
+
+        print "\tln -s $o $file\n\t" if ($OPT{debug});
+        unless (symlink $o, $file) {
+            print "failure\n";
+            print "install: error: cannot symlink '$o' '$file': $!\n";
+            ++$failures;
+            next;
+        }
+    }
+
+    return $failures;
+}
+
+sub copydir {
+    my ($s, %d) = @_;
+
+    my $failures = 0;
+
+    foreach my $pattern(keys %d) {
+        my $d = $d{$pattern};
+        print "\t\tcd $d\n" if ($OPT{debug});
+        chdir $d or die "cannot cd $d";
+
+        opendir(D, $s) or die "cannot opendir $s: $!";
+
+        while (readdir D) {
+            next if (/^\.{1,2}$/);
+            next if ($pattern && ! /$pattern/);
+
+            my $n = "$s/$_";
+
+            if (-l $n) {
+                print "\t\t$_ (symlink)... " if ($OPT{debug});
+                my $l = readlink $n;
+                if ((-e $_) && (!unlink $_)) {
+                    print "error: cannot remove $l: $!\n";
+                    ++$failures;
+                    next;
+                }
+                unless (symlink($l, $_)) {
+                    print "error: cannot create symlink from $_ to $l: $!\n";
+                    ++$failures;
+                    next;
+                }
+                print "success\n" if ($OPT{debug});
+            } else {
+                print "\t\t$_... " if ($OPT{debug});
+                if ((-e $_) && (!unlink $_)) {
+                    print "error: cannot remove $_: $!\n";
+                    ++$failures;
+                    next;
+                }
+                unless (copy($n, $_)) {
+                    print "error: cannot copy '$n' to '$_': $!\n";
+                    ++$failures;
+                    next;
+                }
+                print "success\n" if ($OPT{debug});
+            }
+        }
+
+        closedir D;
+    }
+
+    return $failures;
+}
+
+sub includes_out {
+    my $out = '';
+    eval { $out = INCLUDES_OUT(); };
+    $out = File::Spec->catdir($_{INST_INCDIR}, $out);
+    $out;
+}
+
+sub copyincludes {
+    print "installing includes to $_{INST_INCDIR}... ";
+
+    my $s = "$_{INCDIR}/" . INCLUDES();
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    my $out = includes_out();
+    my $d = $out;
+    $d = $_{INST_INCDIR} unless ($d);
+
+    unless (-e $d) {
+        print "\n\t\tmkdir -p $d" if ($OPT{debug});
+        eval { make_path($d) };
+        if ($@) {
+            print "\tfailure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        }
+    }
+
+    if ($out && -f $s) {
+        print "\n\t\tcp $s $d\n\t" if ($OPT{debug});
+        unless (copy($s, $d)) {
+            print "failure\n";
+            return 1;
+        }
+    } else {
+        print "\n\t\tcp -r $s $d\n\t" if ($OPT{debug});
+        unless (dircopy($s, $d)) {
+            print "\tfailure\ninstall: error: cannot copy '$s' 'd'";
+            return 1;
+        }
+    }
+
+    print "success\n";
+    return 0;
+}
+
+sub copyjars {
+    my $s = $_{JARDIR};
+    my $d = $_{INST_JARDIR};
+
+    print "installing jar files to $d... ";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+
+    return $MAKING ? copybldjars($s, $d) : copydir($s, 0 => $d);
+}
+
+sub copybldjars {
+    my ($s, $d) = @_;
+    my $n = 'ngs-java.jar';
+    $s .= "/$n";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    my $nd = "$n.$_{VERSION}";
+    print "installing '$n'... ";
+
+    print "\t\tcd $d\n" if ($OPT{debug});
+    chdir $d or die "cannot cd $d";
+
+    $d .= "/$nd";
+
+    print "\n\t\t$s -> $d\n\t" if ($OPT{debug});
+
+    if ((! $OPT{force}) && (-e $d) && (-M $d < -M $s)) {
+        print "found\n";
+    } else {
+        unless (copy($s, $d)) {
+            print "failure\n";
+            print "install: error: cannot copy '$s' '$d'.\n";
+            return 1;
+        }
+        my $mode = 0644;
+        printf "\tchmod %o $d\n\t", $mode if ($OPT{debug});
+        unless (chmod($mode, $d)) {
+            print "failure\n";
+            print "install: error: cannot chmod '$d': $!\n";
+            return 1;
+        }
+        unless (symlinks($n, $nd, 'jar')) {
+            print "success\n";
+        } else {
+            print "failure\n";
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+sub copydocs {
+    my $s = "$_{JARDIR}/javadoc";
+    $s = expand_path("$Bin/../doc") unless ($MAKING);
+    my $d = "$_{INST_SHAREDIR}/doc";
+
+    print "installing html documents to $d... ";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+
+    print "\t\t$s -> $d\n\t" if ($OPT{debug});
+    unless (dircopy($s, $d)) {
+        print "\tfailure\ninstall: error: cannot copy '$s' to '$d'";
+        return 1;
+    }
+
+    print "success\n";
+    return 0;
+}
+
+sub copyexamples {
+    my $failures = 0;
+    my $CPRFComp = $File::Copy::Recursive::CPRFComp;
+    my $sd = $EXAMPLES_DIR;
+    return 0 unless (-e $sd);
+
+    my $d = $_{INST_SHAREDIR};
+    if ($HAVE{JAR}) {
+        $d .= '/examples-java';
+    } elsif ($HAVE{PYTHON}) {
+        $File::Copy::Recursive::CPRFComp = 0;
+        $d .= '/examples-python';
+    }
+
+    print "installing examples to $d... ";
+
+    my $s = $sd;
+    $s = "$sd/examples" if ($HAVE{JAR} && $MAKING);
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        ++$failures;
+    }
+
+    unless ($failures) {
+        print "\nchecking $d... ";
+        unless (-e $d) {
+            print "not found\n";
+            print "mkdir -p $d... ";
+            eval { make_path($d) };
+            if ($@) {
+                print "failure\ninstall: error: cannot mkdir $d\n";
+                ++$failures;
+            } else {
+                print "success\n";
+            }
+        } else {
+            print "exists\n";
+        }
+    }
+
+    unless ($failures) {
+        print "\t\t$s -> $d\n\t" if ($OPT{debug});
+        if ($HAVE{JAR} && ! $MAKING) {
+            if (copydir($s, 0 => $d)) {
+                ++$failures;
+            }
+        } else {
+            unless (dircopy($s, $d)) {
+                print "\tfailure\ninstall: error: cannot copy '$s' to '$d'";
+                ++$failures;
+            }
+        }
+    }
+
+    unless ($failures) {
+        if ($HAVE{JAR} && $MAKING) {
+            $sd = "$sd/Makefile";
+            $d = "$d/Makefile";
+            print "\t$sd -> $d\n\t" if ($OPT{debug});
+            unless (-e $sd) {
+                print "\tfailure\n";
+                print "install: error: '$sd' is not found.\n";
+                ++$failures;
+            }
+            unless ($failures) {
+                if (-e $d) {
+                unless (unlink $d) {
+                    print "failure\n";
+                    print "install: error: cannot rm '$d': $!\n";
+                    ++$failures;
+                }
+            }
+            unless ($failures) {
+                unless (copy($sd, $d)) {
+                    print "error: cannot copy '$sd' to '$d': $!\n";
+                    ++$failures;
+                }
+            }
+        }
+      }
+    }
+
+    print "success\n" unless ($failures);
+
+    $File::Copy::Recursive::CPRFComp = $CPRFComp;
+
+    return $failures;
+}
+
+sub finishinstall {
+    my $failures = 0;
+
+    $_{JAR_TARGET} = "$_{INST_JARDIR}/ngs-java.jar";
+
+    my @libs;
+    if (%INSTALLED_LIBS) {
+        my %libs;
+        ++$libs{$INSTALLED_LIBS{$_}} foreach (keys %INSTALLED_LIBS);
+        push @libs, $_ foreach (keys %libs);
+    } else {
+        push @libs, $_{LIB_TARGET};
+    }
+    my $libs;
+    foreach (@libs) {
+        $libs .= ":" if ($libs);
+        $libs .= $_;
+    }
+
+    if ($HAVE{PYTHON}) {
+        chdir "$Bin/.." or die "cannot cd '$Bin/..'";
+        my $cmd = "python setup.py install";
+        $cmd .= ' --user' unless (linux_root());
+        print `$cmd`;
+        if ($?) {
+            ++$failures;
+        } else {
+            unless ($libs) {
+                print "internal python failure\n";
+                ++$failures;
+            } elsif ($HAVE{LIBS}) {
+                print <<EndText;
+Please add $libs to your LD_LIBRARY_PATH, e.g.:
+      export LD_LIBRARY_PATH=$libs:\$LD_LIBRARY_PATH
+EndText
+            }
+        }
+    } elsif ($LINUX_ROOT) {
+        print "\t\tlinux root\n" if ($OPT{debug});
+
+        if ($HAVE{USR_INCLUDES}) {
+            unless (-e $oldincludedir) {
+                print "install: error: '$oldincludedir' does not exist\n";
+                ++$failures;
+            } else {
+                my $o = includes_out();
+                if ($o) {
+                    eval { INCLUDES_OUT(); };
+                    if (@_) {
+                        print "install: cannot find INCLUDES_OUT\n";
+                        ++$failures;
+                    } else {
+                        my $INCLUDE_SYMLINK
+                            = "$oldincludedir/" . INCLUDES_OUT();
+                        print "updating $INCLUDE_SYMLINK... ";
+                        unlink $INCLUDE_SYMLINK;
+                        if ($OPT{debug}) {
+                            print "\n\t\tln -s $o $INCLUDE_SYMLINK... ";
+                        }
+                        unless (symlink $o, $INCLUDE_SYMLINK) {
+                            print "failure\n";
+                            print "install: error: " .
+                                "cannot symlink '$o' '$INCLUDE_SYMLINK': $!\n";
+                            ++$failures;
+                        } else {
+                            print "success\n";
+                        }
+                    }
+                } else {
+                    my $INCLUDE_SYMLINK = "$oldincludedir/" . INCLUDES();
+                    print "updating $INCLUDE_SYMLINK... ";
+                    unlink $INCLUDE_SYMLINK;
+                    my $o = "$_{INST_INCDIR}/" . INCLUDES();
+                    unless (symlink $o, $INCLUDE_SYMLINK) {
+                        print "failure\n";
+                        print "install: error: "
+                            . "cannot symlink '$o' '$INCLUDE_SYMLINK': $!\n";
+                        ++$failures;
+                    } else {
+                        print "success\n";
+                    }
+                }
+            }
+        }
+
+        my $NAME = PACKAGE_NAME();
+        if ($HAVE{BINS} || $HAVE{JAR}
+            || ($HAVE{LIBS}
+                && ($HAVE{DLLS} || $NAME eq 'NGS-SDK' || $NAME eq 'NGS-BAM')
+               )
+            )
+        {
+            my $profile = "$ROOT/etc/profile.d";
+            my $PROFILE_FILE = "$profile/" . lc(PACKAGE_NAME());
+            unless (-e $profile) {
+                print "install: error: '$profile' does not exist\n";
+                ++$failures;
+            } else {
+                print "updating $PROFILE_FILE.[c]sh... ";
+
+                my $f = "$PROFILE_FILE.sh";
+                if (!open F, ">$f") {
+                    print "failure\n";
+                    print "install: error: cannot open '$f': $!\n";
+                    ++$failures;
+                } else {
+                    print F "#version $_{VERSION}\n\n";
+
+                    if ($HAVE{LIBS}) {
+                        unless (@libs) {
+                            print "internal root libraries failure\n";
+                            ++$failures;
+                        } else {
+                            if ($HAVE{DLLS}) {
+                                foreach (@libs) {
+                                    print F <<EndText;
+if ! echo \$LD_LIBRARY_PATH | /bin/grep -q $_
+then export LD_LIBRARY_PATH=$_:\$LD_LIBRARY_PATH
+fi
+
+EndText
+                                }
+                            }
+                            if ($NAME eq 'NGS-SDK') {
+                                print F "export NGS_LIBDIR=$_{LIB_TARGET}\n";
+                            } elsif ($NAME eq 'NGS-BAM') {
+                                print F
+                                      "\nexport NGS_BAM_LIBDIR=$_{LIB_TARGET}\n"
+                            }
+                        }
+                    }
+                    if ($HAVE{JAR}) {
+                        print F <<EndText;
+if ! echo \$CLASSPATH | /bin/grep -q $_{JAR_TARGET}
+then export CLASSPATH=$_{JAR_TARGET}:\$CLASSPATH
+fi
+EndText
+                    }
+                    if ($HAVE{BINS}) {
+                        print F <<EndText;
+if ! echo \$PATH | /bin/grep -q $_{INST_BINDIR}
+then export PATH=$_{INST_BINDIR}:\$PATH
+fi
+EndText
+                    }
+                    close F;
+                    unless (chmod(0644, $f)) {
+                        print "failure\n";
+                        print "install: error: cannot chmod '$f': $!\n";
+                        ++$failures;
+                    }
+                }
+            }
+
+            my $f = "$PROFILE_FILE.csh";
+            if (!open F, ">$f") {
+                print "failure\n";
+                print "install: error: cannot open '$f': $!\n";
+                ++$failures;
+            } else {
+                print F "#version $_{VERSION}\n\n";
+
+                if ($HAVE{LIBS}) {
+                    unless (@libs) {
+                        print "internal libraries failure\n";
+                        ++$failures;
+                    } else {
+                        if ($HAVE{DLLS}) {
+                            foreach (@libs) {
+                                print F <<EndText;
+echo \$LD_LIBRARY_PATH | /bin/grep -q $_
+if ( \$status ) setenv LD_LIBRARY_PATH $_:\$LD_LIBRARY_PATH
+
+EndText
+                            }
+                        }
+                    }
+                    if (PACKAGE_NAME() eq 'NGS-BAM') {
+                        print F "setenv NGS_BAM_LIBDIR $_{LIB_TARGET}\n";
+                    } elsif (PACKAGE_NAME() eq 'NGS-SDK') {
+                        print F "setenv NGS_LIBDIR $_{LIB_TARGET}\n";
+                    } elsif (PACKAGE_NAME() eq 'NCBI-VDB') {
+                        print F "setenv NCBI_VDB_LIBDIR $_{LIB_TARGET}\n";
+                    }
+                }
+                if ($HAVE{JAR}) {
+                    print F <<EndText;
+echo \$CLASSPATH | /bin/grep -q $_{JAR_TARGET}
+if ( \$status ) setenv CLASSPATH $_{JAR_TARGET}:\$CLASSPATH
+EndText
+                }
+                if ($HAVE{BINS}) {
+                    print F <<EndText;
+echo \$PATH | /bin/grep -q $_{INST_BINDIR}
+if ( \$status ) setenv PATH $_{INST_BINDIR}:\$PATH
+EndText
+                }
+                close F;
+                unless (chmod(0644, $f)) {
+                    print "failure\n";
+                    print "install: error: cannot chmod '$f': $!\n";
+                    ++$failures;
+                }
+            }
+#	@ #TODO: check version of the files above
+            print "success\n" unless ($failures);
+        }
+
+        unless ($failures) {
+            if ($HAVE{LIBS}) {
+                if (PACKAGE_NAME() eq 'NGS-BAM') {
+                    print "\n";
+                    print "Use \$NGS_BAM_LIBDIR in your link commands, e.g.:\n";
+                    print "      ld -L\$NGS_BAM_LIBDIR -lngs-bam ...\n";
+                } elsif (PACKAGE_NAME() eq 'NGS-SDK') {
+                    print "\nUse \$NGS_LIBDIR in your link commands, e.g.:\n";
+                    print "      ld -L\$NGS_LIBDIR -lngs-sdk ...\n";
+                } elsif (PACKAGE_NAME() eq 'NCBI-VDB') {
+                    print "\n"
+                       . "Use \$NCBI_VDB_LIBDIR in your link commands, e.g.:\n";
+                    print "      ld -L\$NCBI_VDB_LIBDIR -lncbi-vdb ...\n";
+                }
+            }
+        }
+    } else {
+        print "\t\tnot linux root\n" if ($OPT{debug});
+        if ($HAVE{LIBS}) {
+            unless ($libs) {
+                print "internal libraries failure\n";
+                ++$failures;
+            } else {
+                print "\n";
+                print <<EndText if ($HAVE{DLLS});
+Please add $libs to your LD_LIBRARY_PATH, e.g.:
+      export LD_LIBRARY_PATH=$libs:\$LD_LIBRARY_PATH
+EndText
+                if (PACKAGE_NAME() eq 'NGS-SDK') {
+                    print "Use $libs in your link commands, e.g.:\n"
+                        . "export NGS_LIBDIR=$libs\n"
+                        . "ld -L\$NGS_LIBDIR -lngs-sdk ...\n";
+                } elsif (PACKAGE_NAME() eq 'NGS-BAM') {
+                    print "Use $libs in your link commands, e.g.:\n"
+                        . "export NGS_BAM_LIBDIR=$libs\n"
+                        . "ld -L\$NGS_BAM_LIBDIR -lngs-bam ...\n";
+                }
+            }
+        }
+        if ($HAVE{JAR}) {
+            print <<EndText;
+
+Please add $_{JAR_TARGET} to your CLASSPATH, i.e.:
+      export CLASSPATH=$_{JAR_TARGET}:\$CLASSPATH
+EndText
+        }
+    }
+
+    return $failures;
+}
+
+sub expand_path {
+    my ($filename) = @_;
+    return unless ($filename);
+
+    if ($filename =~ /^~/) {
+        if ($filename =~ m|^~([^/]*)|) {
+            if ($1 && ! getpwnam($1)) {
+                print "install: error: bad path: '$filename'\n";
+                exit 1;
+            }
+        }
+
+        $filename =~ s{ ^ ~ ( [^/]* ) }
+                      { $1
+                            ? (getpwnam($1))[7]
+                            : ( $ENV{HOME} || $ENV{USERPROFILE} || $ENV{LOGDIR}
+                                || (getpwuid($<))[7]
+                              )
+                      }ex;
+    }
+
+    my $a = abs_path($filename);
+    $filename = $a if ($a);
+
+    $filename;
+}
+
+sub help {
+    $_{LIB_TARGET} = "$_{INST_LIBDIR}$_{BITS}";
+
+    print <<EndText;
+'install' installs $_{PACKAGE_NAME} $_{VERSION} package.
+
+Usage: ./install [OPTION]...
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+  -n, --no-create         do not run installation
+
+EndText
+
+    if ($HAVE{TWO_LIBS}) {
+        my $p = lc(PACKAGE_NAME());
+        print "By default, `./install' will install all the files in\n";
+        print "`/usr/local/ngs/$p/jar', " if ($HAVE{JAR});
+        print <<EndText;
+`/usr/local/ngs/$p/share',
+`/usr/local/ngs/ngs-sdk/lib$_{BITS}', `/usr/local/ncbi/ncbi-vdb/lib$_{BITS}'.
+You can spefify other installation directories using the options below.
+
+Fine tuning of the installation directories:
+EndText
+        if ($HAVE{JAR}) {
+            print
+                "  --jardir=DIR         jar files [/usr/local/ngs/$p/jar]\n"
+        }
+        print <<EndText;
+  --ngslibdir=DIR      ngs-sdk libraries [/usr/local/ngs/ngs-sdk/lib$_{BITS}]
+  --vdblibdir=DIR      ncbi-vdb libraries [/usr/local/ncbi/ncbi-vdb/lib$_{BITS}]
+  --examplesdir=DIR    example files [/usr/local/ngs/$p/share]
+
+  --libdir=DIR         install all libraries in the same directory
+  --prefix=DIR         install files in PREFIX/lib$_{BITS}, PREFIX/share etc.
+EndText
+    } else {
+        print <<EndText;
+Installation directories:
+  --prefix=PREFIX         install all files in PREFIX
+                          [$_{PREFIX}]
+
+By default, `./install' will install all the files in
+EndText
+
+        if ($HAVE{INCLUDES}) {
+            print
+"`$_{PREFIX}/include', `$_{PREFIX}/lib$_{BITS}' etc.  You can specify\n"
+        } elsif ($HAVE{JAR}) {
+            print "`$_{PREFIX}/jar', `$_{PREFIX}/share' etc.  You can specify\n"
+        } elsif ($MAKING) {
+            print "`$_{PREFIX}/share' etc.  You can specify\n"
+        } else {
+            print
+"`$_{PREFIX}/lib$_{BITS}' `$_{PREFIX}/share' etc.  You can specify\n"
+        }
+
+        print <<EndText;
+an installation prefix other than `$_{PREFIX}' using `--prefix',
+for instance `--prefix=$_{OTHER_PREFIX}'.
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+EndText
+
+        if ($HAVE{BINS}) {
+            print "  --bindir=DIR            executables [PREFIX/bin]\n";
+        }
+        if ($HAVE{JAR}) {
+            print "  --jardir=DIR            jar files [PREFIX/jar]\n";
+        }
+        if ($HAVE{LIBS}) {
+            print
+"  --libdir=DIR            object code libraries [PREFIX/lib$_{BITS}]\n"
+        }
+        if ($HAVE{INCLUDES}) {
+            print "  --includedir=DIR        C header files [PREFIX/include]\n";
+        }
+        if ($HAVE{USR_INCLUDES}) {
+            print
+"  --oldincludedir=DIR     C header files for non-gcc [$oldincludedir]\n"
+        }
+
+        if (-e $EXAMPLES_DIR) {
+            print "  --examplesdir=DIR       example files [PREFIX/share]\n";
+        }
+    }
+
+    if ($HAVE{LIBS}) {
+        print <<EndText;
+
+System types:
+  --bits=[32|64]          use a 32- or 64-bit data model
+EndText
+    }
+
+    print "\nReport bugs to sra-tools\@ncbi.nlm.nih.gov\n";
+}
+
+sub prepare {
+    if ($MAKING) {
+        my $os_arch = `perl -w $Bin/os-arch.perl`;
+        unless ($os_arch) {
+            print "install: error\n";
+            exit 1;
+        }
+        chomp $os_arch;
+        my $config =
+            "$Bin/../" . CONFIG_OUT() . "/Makefile.config.install.$os_arch.prl";
+        fatal_config("$config not found") unless (-e "$config");
+
+        eval { require $config; };
+        fatal_config($@) if ($@);
+    } else {
+        my $a = $Config{archname64};
+        $_ = lc PACKAGE_NAME();
+        my $root = '';
+        $root = $OPT{root} if ($OPT{root});
+        my $code = 
+            'sub CONFIGURE { ' .
+            '   $_{OS           } = $OS; ' .
+            '   $_{VERSION      } = "1.0.0"; ' .
+            '   $_{MAJVERS      } = "1"; ' .
+            '   $_{LPFX         } = "lib"; ' .
+            '   $_{LIBX         } = "a"; ' .
+            '   $_{MAJVERS_LIBX } = "a.1"; ' .
+            '   $_{VERSION_LIBX } = "a.1.0.0"; ' .
+            '   $_{SHLX         } = "so"; ' .
+            '   $_{OTHER_PREFIX } = \'$HOME/ngs/' . $_ . '\'; ' .
+            '   $_{PREFIX       } = "' . "$root/usr/local/ngs/$_" . '"; ' .
+            '   $_{INST_INCDIR  } = "$_{PREFIX}/include"; ' .
+            '   $_{INST_LIBDIR  } = "$_{PREFIX}/lib"; ' .
+            '   $_{INST_JARDIR  } = "$_{PREFIX}/jar"; ' .
+            '   $_{INST_SHAREDIR} = "$_{PREFIX}/share"; ' .
+            '   $_{INCDIR       } = "$Bin/../include"; ' .
+            '   $_{LIBDIR64     } = "$Bin/../lib64"; ' .
+            '   $_{LIBDIR32     } = "$Bin/../lib32"; ';
+        if ($HAVE{TWO_LIBS}) {
+            $code .=
+               '$_{INST_NGSLIBDIR} = "' . "$root/usr/local/ngs/ngs-sdk/lib\";"
+             . '$_{INST_VDBLIBDIR} = "' . "$root/usr/local/ncbi/ncbi-vdb/lib\";"
+        }
+        $code .= ' $_{PACKAGE_NAME} = "' . PACKAGE_NAME() . '"; ';
+
+        if (defined $Config{archname64}) {
+            $code .= ' $_{BITS} = 64; ';
+        } else {
+            $code .= ' $_{BITS} = 32; ';
+        }
+
+        $code .= 
+            '   $_{MAJVERS_SHLX } = "so.1"; ' .
+            '   $_{VERSION_SHLX } = "so.1.0.0"; ' ;
+
+        $code .= 
+            '   @_ ' .
+            '}';
+
+        eval $code;
+
+        die $@ if ($@);
+    }
+}
+
+sub linux_root { $^O eq 'linux' && `id -u` == 0 }
+
+sub fatal_config {
+    if ($OPT{debug}) {
+        print "\t\t";
+        print "@_";
+        print "\n";
+    }
+
+    print "install: error: run ./configure [OPTIONS] first.\n";
+
+    exit 1;
+}
+
+################################################################################
diff --git a/ngs-bam/setup/install.prl b/ngs-bam/setup/install.prl
new file mode 100644
index 0000000..b4cd6da
--- /dev/null
+++ b/ngs-bam/setup/install.prl
@@ -0,0 +1,6 @@
+sub PACKAGE_NAME { 'NGS-BAM' }
+sub HAVE       { (  LIBS => 1, USR_INCLUDES => 1, ) }
+sub CONFIG_OUT {   '.' }
+sub INCLUDES   {   'ngs-bam' }
+sub LIBS       { ( 'ngs-bam' => 'SHL', 'ngs-bam-c++' => 'LIB', ) }
+1
diff --git a/ngs-java/konfigure.perl b/ngs-bam/setup/konfigure.perl
similarity index 60%
copy from ngs-java/konfigure.perl
copy to ngs-bam/setup/konfigure.perl
index 2a7fde7..7b7780e 100644
--- a/ngs-java/konfigure.perl
+++ b/ngs-bam/setup/konfigure.perl
@@ -32,65 +32,117 @@ if ($directories ne "./") {
     exit 1;
 }
 
-require 'package.pm';
-require 'os-arch.pm';
+require 'package.prl';
+require 'os-arch.prl';
 
-use Cwd qw (abs_path getcwd);
+use Cwd qw(abs_path getcwd);
 use File::Basename 'fileparse';
 use File::Spec 'catdir';
 use FindBin qw($Bin);
-use Getopt::Long 'GetOptions';
+use Getopt::Long "GetOptions";
+
+chdir '..' or die "cannot cd to package root";
 
 check();
 
+my $LOCAL_BUILD_OUT
+    = -e File::Spec->catdir($ENV{HOME}, 'tmp', 'local-build-out');
+
+my ($CONFIGURED, $RECONFIGURE) = ('');
+if (@ARGV) {
+    foreach (@ARGV) {
+        $CONFIGURED .= "\t" if ($CONFIGURED);
+        $CONFIGURED .= "'$_'";
+    }
+} elsif (-f 'reconfigure') {
+    ++$RECONFIGURE unless ($LOCAL_BUILD_OUT);
+}
+
 my %PKG = PKG();
 
 my $PACKAGE_NAME = PACKAGE_NAME();
 my $OUT_MAKEFILE = 'Makefile.config';
+my $INS_MAKEFILE = 'Makefile.config.install';
 
 my $PACKAGE = PACKAGE();
 
 my $HOME = $ENV{HOME} || $ENV{USERPROFILE}
     || $ENV{LOGDIR} || getcwd || (getpwuid($<))[7] || abs_path('.');
 
-$PKG{UPATH} =~ s/(\$\w+)/$1/eeg;
-
-my $OUTDIR = File::Spec->catdir($HOME, $PKG{OUT});
+$PKG{UPATH} = expand($PKG{UPATH});
 
 my $package_default_prefix = $PKG{PATH};
 my $schema_default_dir = $PKG{SCHEMA_PATH} if ($PKG{SCHEMA_PATH});
 
 my @REQ = REQ();
 
-my @options = ( "arch=s",
-                "build=s",
-                "clean",
-                "debug",
-                "help",
-#               "output-makefile=s",
-                "prefix=s",
-                "status",
-                "with-debug",
-                "without-debug" );
+my @options = ( 'build-prefix=s',
+                'clean',
+                'debug',
+                'help',
+                'prefix=s',
+                'reconfigure',
+                'status',
+                'with-debug',
+                'without-debug', );
+{
+    my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
+    push @options, 'arch=s'    if (@ARCHITECTURES);
+}
+push @options, 'enable-static' if (PACKAGE_TYPE() eq 'B');
 foreach my $href (@REQ) {
     my %a = %$href;
     push @options, "$a{option}=s";
     push @options, "$a{boption}=s" if ($a{boption});
-    $href->{usrpath} =~ s/(\$\w+)/$1/eeg;
+    $href->{usrpath} = '' unless ($href->{usrpath});
+    $href->{usrpath} = expand($href->{usrpath});
 }
 push @options, "shemadir" if ($PKG{SCHEMA_PATH});
 
 my %OPT;
 die "configure: error" unless (GetOptions(\%OPT, @options));
+++$OPT{'reconfigure'} if ($RECONFIGURE);
+
+if ($OPT{'reconfigure'}) {
+    unless (eval 'use Getopt::Long qw(GetOptionsFromString); 1') {
+        print <<EndText;
+configure: error: your perl does not support Getopt::Long::GetOptionsFromString
+                  reconfigure option is not avaliable.
+Run "sh ./reconfigure" instead.
+EndText
+        exit 1;
+    }
+    println "reconfiguring...";
+    open F, 'reconfigure' or die 'cannot open reconfigure';
+    $_ = <F>;
+    chomp;
+    unless (m|^\./configure\s*(.*)$|) {
+        println 'configure: error: cannot reconfigure';
+        println 'run "./configure --clean" then run "./configure [OPTIONS]"';
+        exit 1;
+    }
+
+    println "running \"./configure $1\"...";
+    undef %OPT;
+    die "configure: error" unless (GetOptionsFromString($1, \%OPT, @options));
+    ++$OPT{reconfigure};
+}
+
+$OPT{'local-build-out'} = $LOCAL_BUILD_OUT;
+my $OUTDIR = File::Spec->catdir($HOME, $PKG{OUT});
+if ($OPT{'local-build-out'}) {
+    my $o = expand_path(File::Spec->catdir($Bin, $PKG{LOCOUT}));
+    $OUTDIR = $o if ($o);
+}
 
 if ($OPT{'help'}) {
     help();
-    exit(0);
+    exit 0;
 } elsif ($OPT{'clean'}) {
     {
-        foreach (glob(CONFIG_OUT() . '/Makefile.config*'),
-            File::Spec->catdir(CONFIG_OUT(), 'user.status'),
-            File::Spec->catdir(CONFIG_OUT(), 'Makefile.userconfig'))
+        foreach ('reconfigure', glob(CONFIG_OUT() . '/Makefile.config*'),
+            File::Spec->catdir(CONFIG_OUT(), 'Makefile.userconfig'),
+            File::Spec->catdir(CONFIG_OUT(), 'user.status'))
         {
             my $f = $_;
             print "removing $f... ";
@@ -122,11 +174,14 @@ if ($OPT{'help'}) {
             }
         }
     }
-    exit(0);
+    exit 0;
 } elsif ($OPT{'status'}) {
     status(1);
-    exit(0);
+    exit 0;
 }
+
+println "Configuring $PACKAGE_NAME package";
+
 $OPT{'prefix'} = $package_default_prefix unless ($OPT{'prefix'});
 
 my $AUTORUN = $OPT{status};
@@ -134,34 +189,52 @@ print "checking system type... " unless ($AUTORUN);
 my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
 println $OSTYPE unless ($AUTORUN);
 
+unless ($OSTYPE =~ /linux/i || $OSTYPE =~ /darwin/i || $OSTYPE eq 'win') {
+    println "configure: error: unsupported system '$OSTYPE'";
+    exit 1;
+}
+
+print "checking machine architecture... " unless ($AUTORUN);
+println $MARCH unless ($AUTORUN);
+unless ($MARCH =~ /x86_64/i || $MARCH =~ /i?86/i) {
+    println "configure: error: unsupported architecture '$OSTYPE'";
+    exit 1;
+}
+
 {
-    $OPT{'prefix'} = expand($OPT{'prefix'});
+    $OPT{'prefix'} = expand_path($OPT{'prefix'});
     my $prefix = $OPT{'prefix'};
-    $OPT{eprefix} = $prefix unless ($OPT{eprefix} || $OS eq 'win');
-    my $eprefix = $OPT{eprefix};
-    unless ($OPT{bindir} || $OS eq 'win') {
-        $OPT{bindir} = File::Spec->catdir($eprefix, 'bin') ;
+    $OPT{'eprefix'} = $prefix unless ($OPT{'eprefix'} || $OS eq 'win');
+    my $eprefix = $OPT{'eprefix'};
+    unless ($OPT{'bindir'} || $OS eq 'win') {
+        $OPT{'bindir'} = File::Spec->catdir($eprefix, 'bin') ;
     }
-    unless ($OPT{libdir} || $OS eq 'win') {
-        $OPT{libdir} = File::Spec->catdir($eprefix, 'lib');
+    unless ($OPT{'libdir'} || $OS eq 'win') {
+        $OPT{'libdir'} = File::Spec->catdir($eprefix, 'lib');
     }
-    unless ($OPT{includedir} || $OS eq 'win') {
-        $OPT{includedir} = File::Spec->catdir($eprefix, 'include');
+    unless ($OPT{'includedir'} || $OS eq 'win') {
+        $OPT{'includedir'} = File::Spec->catdir($eprefix, 'include');
     }
-    if ($PKG{LNG} eq 'PYTHON' && ! $OPT{pythondir} && $OS ne 'win') {
-        $OPT{pythondir} = $eprefix;
+    if ($PKG{LNG} eq 'PYTHON' && ! $OPT{'pythondir'} && $OS ne 'win') {
+        $OPT{'pythondir'} = $eprefix;
     }
-    if ($PKG{LNG} eq 'JAVA' && ! $OPT{javadir} && $OS ne 'win') {
-        $OPT{javadir} = File::Spec->catdir($eprefix, 'jar');
+    if ($PKG{LNG} eq 'JAVA' && ! $OPT{'javadir'} && $OS ne 'win') {
+        $OPT{'javadir'} = File::Spec->catdir($eprefix, 'jar');
     }
-    if ($PKG{EXAMP} && ! $OPT{sharedir} && $OS ne 'win') {
-        $OPT{sharedir} = File::Spec->catdir($eprefix, 'share');
+    if ($PKG{EXAMP} && ! $OPT{'sharedir'} && $OS ne 'win') {
+        $OPT{'sharedir'} = File::Spec->catdir($eprefix, 'share');
     }
 }
 
 # initial values
 my $TARGDIR = File::Spec->catdir($OUTDIR, $PACKAGE);
-$TARGDIR = expand($OPT{'build'}) if ($OPT{'build'});
+if ($OPT{'build-prefix'}) {
+    $TARGDIR = $OPT{'build-prefix'} = expand_path($OPT{'build-prefix'});
+    unless ($TARGDIR =~ /$PACKAGE$/) {
+        $TARGDIR = File::Spec->catdir($TARGDIR, $PACKAGE);
+    }
+}
+my $BUILD_PREFIX = $TARGDIR;
 
 my $BUILD = 'rel';
 
@@ -195,14 +268,8 @@ if ($OPT{arch}) {
     }
 }
 
-$OUT_MAKEFILE .= ".$OS.$ARCH";
-$OUT_MAKEFILE = File::Spec->catdir(CONFIG_OUT(), $OUT_MAKEFILE);
-
-#my $OSTYPE = `uname -s`; chomp $OSTYPE;
-
-print "checking machine architecture... " unless ($AUTORUN);
-#my $MARCH = `uname -m`; chomp $MARCH;
-println $MARCH unless ($AUTORUN);
+$OUT_MAKEFILE = File::Spec->catdir(CONFIG_OUT(), "$OUT_MAKEFILE.$OS.$ARCH");
+$INS_MAKEFILE = File::Spec->catdir(CONFIG_OUT(), "$INS_MAKEFILE.$OS.$ARCH.prl");
 
 my $TOOLS = "";
 $TOOLS = "jdk" if ($PKG{LNG} eq 'JAVA');
@@ -217,17 +284,12 @@ print "checking for supported architecture... " unless ($AUTORUN);
 
 my $BITS;
 
-if ( $MARCH =~ m/x86_64/i )
-{
+if ($MARCH =~ /x86_64/i) {
     $BITS = 64;
-}
-elsif ( $MARCH =~ m/i?86/i )
-{
+} elsif ($MARCH =~ /i?86/i) {
     $BITS = 32;
-}
-else
-{
-    die "unrecognized Architecture - " . $ARCH;
+} else {
+    die "unrecognized Architecture '$ARCH'";
 }
 println "$MARCH ($BITS bits) is supported" unless ($AUTORUN);
 
@@ -235,105 +297,111 @@ println "$MARCH ($BITS bits) is supported" unless ($AUTORUN);
 my ($LPFX, $OBJX, $LOBX, $LIBX, $SHLX, $EXEX, $OSINC);
 
 print "checking for supported OS... " unless ($AUTORUN);
-if ( $OSTYPE =~ m/linux/i )
-{
-    $LPFX = "lib";
-    $OBJX = "o";
-    $LOBX = "pic.o";
-    $LIBX = "a";
-    $SHLX = "so";
-    $EXEX = "";
-    $OSINC = "unix";
-    if ( $TOOLS eq "" )
-    {
-        $TOOLS = "gcc";
-    }
-}
-elsif ( $OSTYPE =~ m/darwin/i )
-{
-    $LPFX = "lib";
-    $OBJX = "o";
-    $LOBX = "pic.o";
-    $LIBX = "a";
-    $SHLX = "dylib";
-    $EXEX = "";
-    $OSINC = "unix";
-    if ( $TOOLS eq "" )
-    {
-        $TOOLS = "clang";
-    }
+if ($OSTYPE =~ /linux/i) {
+    $LPFX = 'lib';
+    $OBJX = 'o';
+    $LOBX = 'pic.o';
+    $LIBX = 'a';
+    $SHLX = 'so';
+    $EXEX = '';
+    $OSINC = 'unix';
+    $TOOLS = 'gcc' unless ($TOOLS);
+} elsif ($OSTYPE =~ /darwin/i) {
+    $LPFX = 'lib';
+    $OBJX = 'o';
+    $LOBX = 'pic.o';
+    $LIBX = 'a';
+    $SHLX = 'dylib';
+    $EXEX = '';
+    $OSINC = 'unix';
+    $TOOLS = 'clang' unless ($TOOLS);
 } elsif ($OSTYPE eq 'win') {
-    $TOOLS = "vc++";
-} else
-{
-    die "unrecognized OS - " . $OSTYPE;
+    $TOOLS = 'vc++';
+} else {
+    die "unrecognized OS '$OSTYPE'";
 }
 println "$OSTYPE ($OS) is supported" unless ($AUTORUN);
 
 # tool chain
-my ($CC, $CP, $AR, $ARX, $ARLS, $LD, $LP);
+my ($CPP, $CC, $CP, $AR, $ARX, $ARLS, $LD, $LP);
 my ($JAVAC, $JAVAH, $JAR);
 my ($DBG, $OPT, $PIC, $INC, $MD);
 
 print "checking for supported tool chain... " unless ($AUTORUN);
-if ( $TOOLS =~ m/gcc/i )
-{
-    $CC = "gcc -c";
-    $CP = "g++ -c";
-    $AR = "ar rc";
-    $ARX = "ar x";
-    $ARLS = "ar t";
-    $LD = "gcc";
-    $LP = "g++";
-
-    $DBG = "-g -DDEBUG";
-    $OPT = "-O3";
-    $PIC = "-fPIC";
-    $INC = "-I";
-    $MD  = "-MD";
-}
-elsif ( $TOOLS =~ m/clang/i )
-{
-    $CC = "clang -c";
-    $CP = "clang++ -c";
-    $AR = "ar rc";
-    $ARX = "ar x";
-    $ARLS = "ar t";
-    $LD = "clang";
-    $LP = "clang++";
-
-    $DBG = "-g -DDEBUG";
-    $OPT = "-O3";
-    $PIC = "-fPIC";
-    $INC = "-I";
-    $MD  = "-MD";
-}
-elsif ( $TOOLS =~ m/jdk/i )
-{
-    $JAVAC = "javac";
-    $JAVAH = "javah";
-    $JAR   = "jar cf";
-
-    $DBG = "-g";
+if ($TOOLS eq 'gcc') {
+    $CPP  = 'g++';
+    $CC   = 'gcc -c';
+    $CP   = "$CPP -c";
+    $AR   = 'ar rc';
+    $ARX  = 'ar x';
+    $ARLS = 'ar t';
+    $LD   = 'gcc';
+    $LP   = $CPP;
+
+    $DBG = '-g -DDEBUG';
+    $OPT = '-O3';
+    $PIC = '-fPIC';
+    $INC = '-I';
+    $MD  = '-MD';
+} elsif ($TOOLS eq 'clang') {
+    $CPP  = 'clang++';
+    $CC   = 'clang -c';
+    $CP   = "$CPP -c -mmacosx-version-min=10.6";
+    $AR   = 'ar rc';
+    $ARX  = 'ar x';
+    $ARLS = 'ar t';
+    $LD   = 'clang';
+    $LP   = "$CPP -mmacosx-version-min=10.6";
+
+    $DBG = '-g -DDEBUG';
+    $OPT = '-O3';
+    $PIC = '-fPIC';
+    $INC = '-I';
+    $MD  = '-MD';
+} elsif ($TOOLS eq 'jdk') {
+    $JAVAC = 'javac';
+    $JAVAH = 'javah';
+    $JAR   = 'jar cf';
+
+    $DBG = '-g';
 } elsif ($TOOLS eq 'vc++') {
-} else
-{
-    die "unrecognized tool chain - " . $TOOLS;
+} else {
+    die "unrecognized tool chain '$TOOLS'";
 }
 println "$TOOLS tool chain is supported" unless ($AUTORUN);
 
-if ($OS ne 'win') {
+if ($OS ne 'win' && $PKG{LNG} ne 'JAVA') {
     $TARGDIR = File::Spec->catdir($TARGDIR, $OS, $TOOLS, $ARCH, $BUILD);
 }
 
+if ($CPP) {
+    unless (check_tool($CPP)) {
+        println "configure: error: '$CPP' cannot be found";
+        exit 1;
+    }
+}
+
+my $NO_ARRAY_BOUNDS_WARNING = '';
+if ($TOOLS eq 'gcc' && check_no_array_bounds()) {
+    $NO_ARRAY_BOUNDS_WARNING = '-Wno-array-bounds';
+}
+
 my @dependencies;
 
+my %DEPEND_OPTIONS;
 foreach my $href (DEPENDS()) {
     $_ = $href->{name};
     my ($I, $L) = ($href->{Include});
-    if ($OPT{"with-$_-prefix"}) {
-        $I = File::Spec->catdir($OPT{"with-$_-prefix"}, 'include'); 
-        $L = File::Spec->catdir($OPT{"with-$_-prefix"}, 'lib'); 
+    my $o = "with-$_-prefix";
+    ++$DEPEND_OPTIONS{$o};
+    if ($OPT{$o}) {
+        $OPT{$o} = expand_path($OPT{$o});
+        $I = File::Spec->catdir($OPT{$o}, 'include');
+        if (/^xml2$/) {
+            my $t = File::Spec->catdir($I, 'libxml2');
+            $I = $t if (-e $t);
+        }
+        $L = File::Spec->catdir($OPT{$o}, 'lib');
     }
     my ($i, $l) = find_lib($_, $I, $L);
     if (defined $i || $l) {
@@ -354,16 +422,21 @@ foreach my $href (DEPENDS()) {
 }
 
 foreach my $href (@REQ) {
-    $href->{bldpath} =~ s/(\$\w+)/$1/eeg if ($href->{bldpath});
+    $href->{   bldpath} = expand($href->{   bldpath}) if ($href->{   bldpath});
+    $href->{locbldpath} = expand($href->{locbldpath}) if ($href->{locbldpath});
     my ($found_itf, $found_lib, $found_ilib);        # found directories
     my %a = %$href;
+    next if ($a{option} && $DEPEND_OPTIONS{$a{option}});
     my $is_optional = optional($a{type});
+    my $quasi_optional = $a{type} =~ /Q/;
     my $need_source = $a{type} =~ /S/;
     my $need_build = $a{type} =~ /B/;
-    my $need_lib = $a{type} =~ /L/;
+    my $need_lib = $a{type} =~ /L|D/;
+    my $need_itf = ! ($a{type} =~ /D/);
     
     my ($inc, $lib, $ilib) = ($a{include}, $a{lib}); # file names to check
-    $lib =~ s/(\$\w+)/$1/eeg;
+    $lib = '' unless ($lib);
+    $lib = expand($lib);
 
     if ($need_build) {
         $ilib = $a{ilib};
@@ -383,7 +456,7 @@ foreach my $href (@REQ) {
     foreach my $option ($a{option}, $a{boption}) {
         next unless ($option);
         if ($OPT{$option}) {
-            my $try = expand($OPT{$option});
+            my $try = expand_path($OPT{$option});
             my ($i, $l, $il) = ($inc, $lib, $ilib);
             if ($option =~ /-build$/) {
                 undef $i;
@@ -397,9 +470,18 @@ foreach my $href (@REQ) {
                 ++$has_option{sources};
             }
             my ($fi, $fl, $fil) = find_in_dir($try, $i, $l, $il);
-            $found_itf  = $fi  if (! $found_itf  && $fi);
-            $found_lib  = $fl  if (! $found_lib  && $fl);
-            $found_ilib = $fil if (! $found_ilib && $fil);
+            if ($fi || $fl || $fil) {
+                $found_itf  = $fi  if (! $found_itf  && $fi);
+                $found_lib  = $fl  if (! $found_lib  && $fl);
+                $found_ilib = $fil if (! $found_ilib && $fil);
+            }
+            elsif (! ($try =~ /$a{name}$/)) {
+                $try = File::Spec->catdir($try, $a{name});
+                ($fi, $fl, $fil) = find_in_dir($try, $i, $l, $il);
+                $found_itf  = $fi  if (! $found_itf  && $fi);
+                $found_lib  = $fl  if (! $found_lib  && $fl);
+                $found_ilib = $fil if (! $found_ilib && $fil);
+            }
         }
     }
     if (! $found_itf && ! $has_option{sources} && $a{srcpath}) {
@@ -423,16 +505,39 @@ foreach my $href (@REQ) {
     }
     if (! $has_option{build}) {
         if (($need_build || ($need_lib && ! $found_lib)) && $a{bldpath}) {
-            my $try = $a{bldpath};
-            my (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
-            $found_lib  = $fl  if (! $found_lib  && $fl);
-            $found_ilib = $fil if (! $found_ilib && $fil);
+            my ($fl, $fil);
+            if ($OPT{'build-prefix'}) {
+                my $try = $OPT{'build-prefix'};
+                (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
+                if ($fl || $fil) {
+                    $found_lib  = $fl  if (! $found_lib  && $fl);
+                    $found_ilib = $fil if (! $found_ilib && $fil);
+                } elsif (! ($try =~ /$a{name}$/)) {
+                    $try = File::Spec->catdir($try, $a{name});
+                    (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
+                    if ($fl || $fil) {
+                        $found_lib  = $fl  if (! $found_lib  && $fl);
+                        $found_ilib = $fil if (! $found_ilib && $fil);
+                    }
+                }
+            }
+            unless ($fl || $fil) {
+                my $try = $a{bldpath};
+                $try = $a{locbldpath} if ($OPT{'local-build-out'});
+                (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
+                $found_lib  = $fl  if (! $found_lib  && $fl);
+                $found_ilib = $fil if (! $found_ilib && $fil);
+            }
         }
     }
-    if (! $found_itf || ($need_lib && ! $found_lib) || ($ilib && ! $found_ilib))
+    if (($need_itf && ! $found_itf) ||
+        ($need_lib && ! $found_lib) || ($ilib && ! $found_ilib))
     {
         if ($is_optional) {
             println "configure: optional $a{name} package not found: skipped.";
+        } elsif ($quasi_optional && $found_itf && ($need_lib && ! $found_lib)) {
+            println "configure: $a{name} package: "
+                . "found interface files but not libraries.";
         } else {
             if ($OPT{'debug'}) {
                 $_ = "$a{name}: includes: ";
@@ -456,20 +561,42 @@ foreach my $href (@REQ) {
             exit 1;
         }
     } else {
-        $found_itf = abs_path($found_itf);
-        push(@dependencies, "$a{namew}_INCDIR = $found_itf");
+        if ($found_itf) {
+            $found_itf = abs_path($found_itf);
+            push(@dependencies, "$a{aname}_INCDIR = $found_itf");
+        }
         if ($found_lib) {
             $found_lib = abs_path($found_lib);
-            push(@dependencies, "$a{namew}_LIBDIR = $found_lib");
+            if ($a{aname} eq 'NGS' || $a{aname} eq 'VDB') {
+                if ($OPT{PYTHON_LIB_PATH}) {
+                    $OPT{PYTHON_LIB_PATH} .= ':';
+                } else {
+                    $OPT{PYTHON_LIB_PATH} = '';
+                }
+                $OPT{PYTHON_LIB_PATH} .= $found_lib;
+            }
+            push(@dependencies, "$a{aname}_LIBDIR = $found_lib");
         }
         if ($ilib && $found_ilib) {
             $found_ilib = abs_path($found_ilib);
-            push(@dependencies, "$a{namew}_ILIBDIR = $found_ilib");
+            push(@dependencies, "$a{aname}_ILIBDIR = $found_ilib");
         }
     }
 }
 
+my ($E_BINDIR, $E_LIBDIR, $VERSION, $MAJVERS, $E_VERSION_LIBX, $E_MAJVERS_LIBX,
+                                              $E_VERSION_EXEX, $E_MAJVERS_EXEX)
+    = (''    , '');
+
 if ($OS ne 'win' && ! $OPT{'status'}) {
+    if ($OSTYPE =~ /darwin/i && CONFIG_OUT() ne '.') {
+        my $COMP = File::Spec->catdir(CONFIG_OUT(), 'COMP.mac');
+        println "configure: creating '$COMP' ($TOOLS)" unless ($AUTORUN);
+        open F, ">$COMP" or die "cannot open $COMP to write";
+        print F "$TOOLS\n";
+        close F;
+    }
+
     # create Makefile.config
     println "configure: creating '$OUT_MAKEFILE'" unless ($AUTORUN);
     open my $F, ">$OUT_MAKEFILE" or die "cannot open $OUT_MAKEFILE to write";
@@ -477,34 +604,53 @@ if ($OS ne 'win' && ! $OPT{'status'}) {
     print $F <<EndText;
 ### AUTO-GENERATED FILE ###
 
-OS_ARCH = \$(shell perl \$(TOP)/os-arch.perl)
+# configuration command
+
+CONFIGURED = $CONFIGURED
+
+OS_ARCH = \$(shell perl \$(TOP)/setup/os-arch.perl)
 
 # install paths
 EndText
 
-    L($F, "INST_BINDIR = $OPT{bindir}"        ) if ($OPT{bindir});
-    L($F, "INST_LIBDIR = $OPT{libdir}"        ) if ($OPT{libdir});
-    L($F, "INST_INCDIR = $OPT{includedir}"    ) if ($OPT{includedir});
+    L($F, "INST_BINDIR = $OPT{'bindir'}"      ) if ($OPT{'bindir'});
+    L($F, "INST_LIBDIR = $OPT{'libdir'}"      ) if ($OPT{'libdir'});
+    L($F, "INST_INCDIR = $OPT{'includedir'}"  ) if ($OPT{'includedir'});
     L($F, "INST_SCHEMADIR = $OPT{'shemadir'}" ) if ($OPT{'shemadir'});
     L($F, "INST_SHAREDIR = $OPT{'sharedir'}"  ) if ($OPT{'sharedir'});
     L($F, "INST_JARDIR = $OPT{'javadir'}"     ) if ($OPT{'javadir'});
     L($F, "INST_PYTHONDIR = $OPT{'pythondir'}") if ($OPT{'pythondir'});
 
-    my ($VERSION_SHLX, $MAJMIN_SHLX, $MAJVERS_SHLX);
+    my ($E_VERSION_SHLX, $VERSION_SHLX,
+        $E_MAJVERS_SHLX , $MAJMIN_SHLX, $MAJVERS_SHLX);
     if ($OSTYPE =~ /darwin/i) {
+        $E_VERSION_SHLX =  '$VERSION.$SHLX';
         $VERSION_SHLX = '$(VERSION).$(SHLX)';
         $MAJMIN_SHLX  = '$(MAJMIN).$(SHLX)';
+        $E_MAJVERS_SHLX = '$MAJVERS.$SHLX';
         $MAJVERS_SHLX = '$(MAJVERS).$(SHLX)';
     } else {
+        $E_VERSION_SHLX =  '$SHLX.$VERSION';
         $VERSION_SHLX = '$(SHLX).$(VERSION)';
         $MAJMIN_SHLX  = '$(SHLX).$(MAJMIN)';
+        $E_MAJVERS_SHLX =  '$SHLX.$MAJVERS';
         $MAJVERS_SHLX = '$(SHLX).$(MAJVERS)';
     }
 
+    $E_VERSION_LIBX = '$LIBX.$VERSION';
+    $E_MAJVERS_LIBX = '$LIBX.$MAJVERS';
 
-    print $F <<EndText;
+    L($F);
+    L($F, "# build type");
+
+    if ($OPT{'enable-static'}) {
+        L($F, "WANTS_STATIC = 1");
+    }
 
-# build type
+    $E_VERSION_EXEX = '$EXEX.$VERSION';
+    $E_MAJVERS_EXEX = '$LIBX.$MAJVERS';
+
+    print $F <<EndText;
 BUILD = $BUILD
 
 # target OS
@@ -587,11 +733,12 @@ EndText
     }
 
     L($F, 'CLSPATH = -classpath $(CLSDIR)');
+    L($F, "NO_ARRAY_BOUNDS_WARNING = $NO_ARRAY_BOUNDS_WARNING");
     L($F);
 
     # version information
 
-    my ($VERSION, $MAJMIN, $MAJVERS);
+    my $MAJMIN;
 
     if ($FULL_VERSION =~ /(\d+)\.(\d+)\.(\d+)-?\w*\d*/) {
         $VERSION = "$1.$2.$3";
@@ -608,6 +755,7 @@ MAJMIN  = $MAJMIN
 MAJVERS = $MAJVERS
 
 # output path
+BUILD_PREFIX = $BUILD_PREFIX
 TARGDIR = $TARGDIR
 
 # derived paths
@@ -618,16 +766,21 @@ BINDIR    = \$(TARGDIR)/bin
 EndText
 
     if ($PKG{LNG} eq 'C') {
+        $E_BINDIR        = '$TARGDIR/bin';
+        $E_LIBDIR        = '$TARGDIR/lib';
         L($F, 'LIBDIR    = $(TARGDIR)/lib');
     } elsif ($PKG{LNG} eq 'JAVA') {
+        $E_LIBDIR        = '$TARGDIR/jar';
         L($F, 'LIBDIR    = $(TARGDIR)/jar');
     }
 
-    print $F <<EndText;
-ILIBDIR   = \$(TARGDIR)/ilib
-OBJDIR    = \$(TARGDIR)/obj/\$(MODPATH)
-CLSDIR    = \$(TARGDIR)/cls
-EndText
+    L($F, 'ILIBDIR   = $(TARGDIR)/ilib');
+    if ($PKG{NOMODPATH}) {
+        L($F, 'OBJDIR    = $(TARGDIR)/obj');
+    } else {
+        L($F, 'OBJDIR    = $(TARGDIR)/obj/$(MODPATH)');
+    }
+    L($F, 'CLSDIR    = $(TARGDIR)/cls');
 
     if ($PKG{LNG} eq 'JAVA') {
         L($F,
@@ -747,6 +900,51 @@ EndText
         T($F, '  fi');
     }
     close $F;
+
+    # create Makefile.config.install
+    println "configure: creating '$INS_MAKEFILE'" unless ($AUTORUN);
+    open $F, ">$INS_MAKEFILE" or die "cannot open $INS_MAKEFILE to write";
+
+    $OPT{'javadir' } = '' unless ($OPT{'javadir' });
+    $OPT{'sharedir'} = '' unless ($OPT{'sharedir'});
+
+    print $F "sub CONFIGURE {\n";
+    print $F "    \$_{PACKAGE_NAME } = '$PACKAGE_NAME';\n";
+    print $F "    \$_{VERSION      } = '$VERSION';\n";
+    print $F "    \$_{LNG          } = '$PKG{LNG}';\n";
+    print $F "    \$_{OS           } = '$OS';\n";
+    print $F "    \$_{BITS         } =  $BITS;\n";
+    print $F "    \$_{MAJVERS      } =  $MAJVERS;\n";
+    print $F "    \$_{LPFX         } = '$LPFX';\n";
+    print $F "    \$_{LIBX         } = '$LIBX';\n";
+    print $F "    \$_{MAJVERS_LIBX } = '" . expand($E_MAJVERS_LIBX) . "';\n";
+    print $F "    \$_{VERSION_LIBX } = '" . expand($E_VERSION_LIBX) . "';\n";
+    print $F "    \$_{SHLX         } = '$SHLX';\n";
+    print $F "    \$_{MAJVERS_SHLX } = '" . expand($E_MAJVERS_SHLX) . "';\n";
+    print $F "    \$_{VERSION_SHLX } = '" . expand($E_VERSION_SHLX) . "';\n";
+    print $F "    \$_{VERSION_EXEX } = '" . expand($E_VERSION_EXEX) . "';\n";
+    print $F "    \$_{MAJVERS_EXEX } = '" . expand($E_MAJVERS_EXEX) . "';\n";
+    print $F "    \$_{INCDIR       } = '" . expand("$Bin/.."      ) . "';\n";
+    if ($PKG{LNG} ne 'PYTHON') {
+        print $F "  \$_{BINDIR$BITS} = '" . expand($E_BINDIR      ) . "';\n";
+        print $F "  \$_{LIBDIR$BITS} = '" . expand($E_LIBDIR      ) . "';\n";
+    } elsif ($OPT{PYTHON_LIB_PATH}) {
+        print $F "  \$_{LIBDIR$BITS} = '$OPT{PYTHON_LIB_PATH}';\n";
+    }
+    print $F "    \$_{OTHER_PREFIX } = '$PKG{UPATH}';\n";
+    print $F "    \$_{PREFIX       } = '$OPT{'prefix'}';\n";
+    print $F "    \$_{INST_INCDIR  } = '$OPT{'includedir'}';\n";
+    print $F "    \$_{INST_BINDIR  } = '$OPT{'bindir'}';\n";
+    print $F "    \$_{INST_LIBDIR  } = '$OPT{'libdir'}';\n";
+    print $F "    \$_{INST_JARDIR  } = '$OPT{'javadir'}';\n";
+    print $F "    \$_{INST_SHAREDIR} = '$OPT{'sharedir'}';\n";
+    print $F "\n";
+    print $F "    \@_\n";
+    print $F "}\n";
+    print $F "\n";
+    print $F "1\n";
+
+    close $F;
 }
 
 if (! $OPT{'status'} ) {
@@ -768,7 +966,7 @@ EndText
             my $NGS_SDK_PREFIX = '';
             $NGS_SDK_PREFIX = $a{found_itf} if ($a{found_itf});
             if ($a{name} eq 'ngs-sdk') {
-                my $root = "$a{namew}_ROOT";
+                my $root = "$a{aname}_ROOT";
                 print OUT "    <$root>$NGS_SDK_PREFIX\/</$root>\n";
                 last;
             }
@@ -786,12 +984,20 @@ EndText
         open COUT, ">$out" or die "cannot open $out to write";
         print COUT "### AUTO-GENERATED FILE ###\n";
         print COUT "\n";
-        print COUT "OS_ARCH = \$(shell perl \$(TOP)/os-arch.perl)\n";
+        print COUT "OS_ARCH = \$(shell perl \$(TOP)/setup/os-arch.perl)\n";
         print COUT "include \$(TOP)/$CONFIG_OUT/Makefile.config.\$(OS_ARCH)\n";
         close COUT;
     }
 }
 
+unless ($OPT{'reconfigure'}) {
+    println "configure: creating 'reconfigure'" unless ($AUTORUN);
+    $CONFIGURED =~ s/\t/ /g;
+    open my $F, '>reconfigure' or die 'cannot open reconfigure to write';
+    print $F "./configure $CONFIGURED\n";
+    close $F;
+}
+
 status() if ($OS ne 'win');
 
 unlink 'a.out';
@@ -817,8 +1023,11 @@ sub status {
                 $BUILD_TYPE = $1;
             } elsif (/BUILD \?= /) {
                 $BUILD_TYPE = $_ unless ($BUILD_TYPE);
-            }
-            elsif (/TARGDIR = /) {
+            } elsif (/BUILD_PREFIX = /) {
+                $BUILD_PREFIX = $_;
+            } elsif (/CONFIGURED = (.*)/) {
+                $CONFIGURED = $1;
+            } elsif (/TARGDIR = /) {
                 $TARGDIR = $_;
                 println "\t\tgot $_" if ($OPT{'debug'});
             } elsif (/TARGDIR \?= (.+)/) {
@@ -826,18 +1035,19 @@ sub status {
                 println "\t\tgot $_" if ($OPT{'debug'});
             }
             elsif (/INST_INCDIR = (.+)/) {
-                $OPT{includedir} = $1;
+                $OPT{'includedir'} = $1;
             }
             elsif (/INST_BINDIR = (.+)/) {
-                $OPT{bindir} = $1;
+                $OPT{'bindir'} = $1;
             }
             elsif (/INST_LIBDIR = (.+)/) {
-                $OPT{libdir} = $1;
+                $OPT{'libdir'} = $1;
             }
         }
     }
 
     println "build type: $BUILD_TYPE";
+    println "build prefix: $BUILD_PREFIX" if ($OS ne 'win');
     println "build output path: $TARGDIR" if ($OS ne 'win');
 
 #   print "prefix: ";    print $OPT{'prefix'} if ($OS ne 'win');    println;
@@ -860,13 +1070,24 @@ sub status {
     println "javadir: $OPT{'javadir'}" if ($OPT{'javadir'});
     println "pythondir: $OPT{'pythondir'}" if ($OPT{'pythondir'});
 
-    println;
+    $CONFIGURED =~ s/\t/ /g;
+    println "configured with: \"$CONFIGURED\"";
 }
 
-sub expand {
+sub expand { $_[0] =~ s/(\$\w+)/$1/eeg; $_[0]; }
+
+sub expand_path {
     my ($filename) = @_;
     return unless ($filename);
+
     if ($filename =~ /^~/) {
+        if ($filename =~ m|^~([^/]*)|) {
+            if ($1 && ! getpwnam($1)) {
+                print "configure: error: bad path: '$filename'\n";
+                exit 1;
+            }
+        }
+
         $filename =~ s{ ^ ~ ( [^/]* ) }
                       { $1
                             ? (getpwnam($1))[7]
@@ -875,6 +1096,7 @@ sub expand {
                               )
                       }ex;
     }
+
     my $a = abs_path($filename);
     $filename = $a if ($a);
     $filename;
@@ -882,34 +1104,33 @@ sub expand {
 
 sub find_in_dir {
     my ($dir, $include, $lib, $ilib) = @_;
-    print "\t$dir... " unless ($AUTORUN);
     unless (-d $dir) {
-        println "no" unless ($AUTORUN);
+#       println "no" unless ($AUTORUN);
         println "\t\tnot found $dir" if ($OPT{'debug'});
         return;
     }
-    print "[found] " if ($OPT{'debug'});
+#   print "\t$dir... " unless ($AUTORUN);
+#   print "[found] " if ($OPT{'debug'});
     my ($found_inc, $found_lib, $found_ilib);
-    my $nl = 1;
     if ($include) {
-        print "includes... " unless ($AUTORUN);
+        print "\tincludes... " unless ($AUTORUN);
         if (-e "$dir/$include") {
-            println 'yes' unless ($AUTORUN);
+            println $dir unless ($AUTORUN);
             $found_inc = $dir;
         } elsif (-e "$dir/include/$include") {
-            println 'yes' unless ($AUTORUN);
+            println $dir unless ($AUTORUN);
             $found_inc = "$dir/include";
         } elsif (-e "$dir/interfaces/$include") {
-            println 'yes' unless ($AUTORUN);
+            println $dir unless ($AUTORUN);
             $found_inc = "$dir/interfaces";
         } else {
+            print "$dir: " if ($OPT{'debug'});
             println 'no' unless ($AUTORUN);
         }
-        $nl = 0;
     }
     if ($lib || $ilib) {
-        print "\n\t" if ($nl && !$AUTORUN);
-        print "libraries... " unless ($AUTORUN);
+#       print "\n\t" if ($nl && !$AUTORUN);
+        print "\tlibraries... " unless ($AUTORUN);
         if ($lib) {
             my $builddir = File::Spec->catdir($dir, $OS, $TOOLS, $ARCH, $BUILD);
             my $libdir  = File::Spec->catdir($builddir, 'lib');
@@ -923,14 +1144,14 @@ sub find_in_dir {
                     my $f = File::Spec->catdir($ilibdir, $ilib);
                     print "\tchecking $f\n\t" if ($OPT{'debug'});
                     if (-e $f) {
-                        println 'yes';
+                        println $ilibdir;
                         $found_ilib = $ilibdir;
                     } else {
                         println 'no' unless ($AUTORUN);
                         return;
                     }
                 } else {
-                    println 'yes';
+                    println $libdir;
                 }
                 ++$found;
             }
@@ -939,7 +1160,7 @@ sub find_in_dir {
                 my $f = File::Spec->catdir($libdir, $lib);
                 print "\tchecking $f\n\t" if ($OPT{'debug'});
                 if (-e $f) {
-                    println 'yes';
+                    println $libdir;
                     $found_lib = $libdir;
                     ++$found;
                 }
@@ -957,16 +1178,18 @@ sub find_in_dir {
                         my $f = File::Spec->catdir($ilibdir, $ilib);
                         print "\tchecking $f\n\t" if ($OPT{'debug'});
                         if (-e $f) {
-                            println 'yes';
+                            println $ilibdir;
                             $found_ilib = $ilibdir;
                         } else {
                             println 'no' unless ($AUTORUN);
                             return;
                         }
                     } else {
-                        println 'yes';
+                        println $libdir;
                     }
                     ++$found;
+                } else {
+                    println 'no' unless ($AUTORUN);
                 }
             }
         }
@@ -976,7 +1199,6 @@ sub find_in_dir {
             println 'no' unless ($AUTORUN);
             undef $found_lib;
         }
-        ++$nl;
     }
     return ($found_inc, $found_lib, $found_ilib);
 }
@@ -994,38 +1216,90 @@ sub reverse_build {
 
 ################################################################################
 
+sub check_tool {
+    my ($tool) = @_;
+    print "checking for $tool... ";
+    my $cmd = "$tool --help";
+    print "\n\t\trunning $cmd\n\t" if ($OPT{'debug'});
+    my $out = `$cmd 2>&1`;
+    if ($? == 0) {
+        println "yes";
+        return 1;
+    } else {
+        println "no";
+        return 0;
+    }
+}
+
+sub check_no_array_bounds {
+    check_compiler('O', '-Wno-array-bounds');
+}
+
 sub find_lib {
-    my ($n, $i, $l) = @_;
+    check_compiler('L', @_);
+}
 
-    print "checking for $n library... ";
+sub check_compiler {
+    my ($t, $n, $i, $l) = @_;
+    my $tool = $TOOLS;
+
+    if ($t eq 'L') {
+        print "checking for $n library... ";
+    } elsif ($t eq 'O') {
+        if ($tool && $tool eq 'gcc') {
+            print "checking whether gcc accepts $n... ";
+        } else {
+            return;
+        }
+    } else {
+        die "Unknown check_compiler option: '$t'";
+    }
+
+    unless ($tool) {
+        println "warning: unknown tool";
+        return;
+    }
 
     while (1) {
-        my ($library, $log);
+        my ($flags, $library, $log) = ('', '');
 
-        if ($n eq 'hdf5') {
+        if ($t eq 'O') {
+            $flags = $n;
+            $log = '                      int main() {                     }\n'
+        } elsif ($n eq 'hdf5') {
             $library = '-lhdf5';
-            $log = '#include <hdf5.h>            \n main() { H5close     (); }';
-        } elsif ($n eq 'xml2') {
-            $library = '-lxml2';
-            $log = '#include <libxml/xmlreader.h>\n main() { xmlInitParser();}';
+            $log = '#include <hdf5.h>  \n int main() { H5close         (); }\n'
+        } elsif ($n eq 'fuse') {
+            $flags = '-D_FILE_OFFSET_BITS=64';
+            $library = '-lfuse';
+            $log = '#include <fuse.h>  \n int main() { fuse_get_context(); }\n'
         } elsif ($n eq 'magic') {
             $library = '-lmagic';
-            $log = '#include <magic.h>           \n main() { magic_open (0); }';
+            $log = '#include <magic.h> \n int main() { magic_open     (0); }\n'
+        } elsif ($n eq 'xml2') {
+            $library = '-lxml2';
+            $log = '#include <libxml/xmlreader.h>\n' .
+                                         'int main() { xmlInitParser  ( ); }\n'
         } else {
             println 'unknown: skipped';
             return;
         }
 
-        if (($i && ! -d $i) || ($l && ! -d $l)) {
+        if ($i && ! -d $i) {
+            print "'$i': " if ($OPT{'debug'});
             println 'no';
             return;
         }
+        if ($l && ! -d $l) {
+            print "'$l': " if ($OPT{'debug'});            println 'no';
+            return;
+        }
 
         my $cmd = $log;
         $cmd =~ s/\\n/\n/g;
 
-        my $gcc = "| gcc -xc " . ($i ? "-I$i " : ' ')
-                               . ($l ? "-L$l " : ' ') . "- $library";
+        my $gcc = "| $tool -xc $flags " . ($i ? "-I$i " : ' ')
+                                      . ($l ? "-L$l " : ' ') . "- $library";
         $gcc .= ' 2> /dev/null' unless ($OPT{'debug'});
 
         open GCC, $gcc or last;
@@ -1039,6 +1313,8 @@ sub find_lib {
 
         return if (!$ok);
 
+        return 1 if ($t eq 'O');
+
         return ($i, $l);
     }
 
@@ -1057,36 +1333,47 @@ sub check {
 
     my %PKG = PKG();
 
-    die "No LNG"   unless $PKG{LNG};
-    die "No OUT"   unless $PKG{OUT};
-    die "No PATH"  unless $PKG{PATH};
-    die "No UPATH" unless $PKG{UPATH};
+    die "No LNG"    unless $PKG{LNG};
+    die "No LOCOUT" unless $PKG{LOCOUT};
+    die "No OUT"    unless $PKG{OUT};
+    die "No PATH"   unless $PKG{PATH};
+    die "No UPATH"  unless $PKG{UPATH};
 
     foreach my $href (DEPENDS()) { die "No DEPENDS::name" unless $href->{name} }
 
     foreach my $href (REQ()) {
-        die "No REQ::name" unless $href->{name};
-
-        my $origin = $href->{origin};
-        die  "No $href->{name}:origin"  unless $origin;
-        die  "No $href->{name}:include" unless $href->{include};
-        die  "No $href->{name}:lib"     unless $href->{lib};
-        die  "No $href->{name}:option"  unless $href->{option};
-        die  "No $href->{name}:pkgpath" unless $href->{pkgpath};
-        die  "No $href->{name}:type"    unless $href->{type};
-        die  "No $href->{name}:usrpath" unless $href->{usrpath};
-        if ($origin eq 'I') {
-         die "No $href->{name}:bldpath" unless $href->{bldpath};
-         die "No $href->{name}:ilib"    unless $href->{ilib};
-         die "No $href->{name}:namew"   unless $href->{namew};
-         die "No $href->{name}:srcpath" unless $href->{srcpath};
+        die         "No REQ::name" unless $href->{name};
+
+        die         "No $href->{name}:option"  unless $href->{option};
+
+        die         "No $href->{name}:type"    unless $href->{type};
+        unless ($href->{type} =~ /I/) {
+            die     "No $href->{name}:lib"     unless $href->{lib};
+            die     "No $href->{name}:pkgpath" unless $href->{pkgpath};
+            die     "No $href->{name}:usrpath" unless $href->{usrpath};
+        }
+
+        die         "No $href->{name}:origin"  unless $href->{origin};
+        if ($href->{origin} eq 'I') {
+            die     "No $href->{name}:aname"   unless $href->{aname};
+            unless ($href->{type} =~ /D/) {
+                die "No $href->{name}:include" unless $href->{include};
+                die "No $href->{name}:srcpath" unless $href->{srcpath};
+            }
+            unless ($href->{type} =~ /I/) {
+                die "No $href->{name}:bldpath"    unless $href->{bldpath   };
+                die "No $href->{name}:locbldpath" unless $href->{locbldpath};
+            }
+            if ($href->{type} =~ /B/) {
+                die "No $href->{name}:ilib"    unless $href->{ilib};
+            }
         }
     }
 }
 
 ################################################################################
 
-sub optional { $_[0] =~ /^[LS]I$/ }
+sub optional { $_[0] =~ /O/ }
 
 sub help {
 #  --prefix=PREFIX         install architecture-independent files in PREFIX
@@ -1123,10 +1410,14 @@ EndText
     
         if (PACKAGE_TYPE() eq 'B') {
             print "\`$package_default_prefix/bin', ";
-        } else {
+        } elsif (PACKAGE_TYPE() eq 'L') {
             print "\`$package_default_prefix/include', ";
         }
-        println "\`$package_default_prefix/lib' etc.";
+        if (PACKAGE_TYPE() eq 'P') {
+            println "\`$package_default_prefix/share' etc.";
+        } else {
+            println "\`$package_default_prefix/lib' etc.";
+        }
 
         print <<EndText;
 You can specify an installation prefix other than \`$package_default_prefix'
@@ -1184,27 +1475,50 @@ EndText
         println;
     }
 
-    print <<EndText if ($^O ne 'MSWin32');
+    print <<EndText if (PACKAGE_TYPE() eq 'B');
+Optional Features:
+  --enable-static         build static executable [default=no]
+
+EndText
+
+    my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
+
+    if ($^O ne 'MSWin32') {
+        print <<EndText;
 Build tuning:
   --with-debug
   --without-debug
-  --arch=name             specify the name of the target architecture
+EndText
 
-  --build=DIR             generate build output into DIR directory
+        if (@ARCHITECTURES) {
+            print
+"  --arch=name             specify the name of the target architecture\n";
+        }
+
+        print <<EndText;
+
+  --build-prefix=DIR      generate build output into DIR directory
                           [$OUTDIR]
 
 EndText
+    }
 
-    println "Miscellaneous:";
+    println 'Miscellaneous:';
+    println '  --reconfigure           rerun `configure\'';
+    println '                          using the same command-line arguments';
     if ($^O ne 'MSWin32') {
         println
-            "  --status                print current configuration information"
+            '  --status                print current configuration information'
     }
-    println "  --clean                 remove all configuration results";
-    println "  --debug                 print lots of debugging information";
-    println;
+    print <<EndText;
+  --clean                 remove all configuration results
+  --debug                 print lots of debugging information
+
+If `configure' was arleady run running `configure' without options
+will rerun `configure' using the same command-line arguments.
+
+Report bugs to sra-tools\@ncbi.nlm.nih.gov
+EndText
 }
 
-=pod
 ################################################################################
-=cut
diff --git a/ngs-python/configure b/ngs-bam/setup/ngs-bam/install
similarity index 82%
copy from ngs-python/configure
copy to ngs-bam/setup/ngs-bam/install
index 3313aac..b1e201d 100755
--- a/ngs-python/configure
+++ b/ngs-bam/setup/ngs-bam/install
@@ -29,17 +29,17 @@ CURDIR="`dirname $0`"
 
 if [ -z "$CURDIR" ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
     exit 1
 fi
 
-if [ "$FILENAME" != configure -a ! -s konfigure.perl ]
+if [ "$FILENAME" != install -a ! -s setup/install.perl ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
 else
     perl -v > /dev/null 2>&1 || { echo "checking for perl... no"; \
-        echo >&2 "configure: error: perl not found."; exit 1; }
+        echo >&2 "error: perl not found."; exit 1; }
 
-    cd $CURDIR
-    perl -w ./konfigure.perl $@
+    cd $CURDIR/setup
+    perl -w ./install.perl "$@"
 fi
diff --git a/ngs-bam/setup/ngs-bam/linux/os.prl b/ngs-bam/setup/ngs-bam/linux/os.prl
new file mode 100644
index 0000000..5f75471
--- /dev/null
+++ b/ngs-bam/setup/ngs-bam/linux/os.prl
@@ -0,0 +1,2 @@
+sub OS { 'linux' }
+1
diff --git a/ngs-bam/setup/ngs-bam/mac/os.prl b/ngs-bam/setup/ngs-bam/mac/os.prl
new file mode 100644
index 0000000..b962c57
--- /dev/null
+++ b/ngs-bam/setup/ngs-bam/mac/os.prl
@@ -0,0 +1,2 @@
+sub OS { 'mac' }
+1
diff --git a/ngs-java/os-arch.perl b/ngs-bam/setup/os-arch.perl
similarity index 80%
copy from ngs-java/os-arch.perl
copy to ngs-bam/setup/os-arch.perl
index a7b4990..5f3f87a 100644
--- a/ngs-java/os-arch.perl
+++ b/ngs-bam/setup/os-arch.perl
@@ -1,14 +1,14 @@
 use strict;
 
 use FindBin qw($Bin);
-require "$Bin/os-arch.pm";
+require "$Bin/os-arch.prl";
 
 my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
 
 my $res = "$OS.$ARCH";
 
 if (@ARCHITECTURES) {
-    my $name = "$Bin/Makefile.config.$OS.arch";
+    my $name = "$Bin/../Makefile.config.$OS.arch";
     if (-e $name) {
         while (1) {
             open F, $name or last;
diff --git a/ngs-java/os-arch.pm b/ngs-bam/setup/os-arch.prl
similarity index 95%
copy from ngs-java/os-arch.pm
copy to ngs-bam/setup/os-arch.prl
index 6fbd606..791b556 100644
--- a/ngs-java/os-arch.pm
+++ b/ngs-bam/setup/os-arch.prl
@@ -18,6 +18,8 @@ sub OsArch {
             $HOST_OS = 'win';
         } elsif ($UNAME =~ /xMINGW/) {
             $HOST_OS = 'win';
+        } else {
+            $HOST_OS = $UNAME;
         }
         if ($HOST_OS eq 'mac') {
             $MARCH = $HOST_ARCH = MacArch();
@@ -50,7 +52,9 @@ sub OsArch {
                 @ARCHITECTURES = qw(x86_64 i386);
             } elsif ($MARCH =~ /sun4v/) {
                 $HOST_ARCH = 'sparc64';
-		        @ARCHITECTURES = qw(sparc64 sparc32);
+                @ARCHITECTURES = qw(sparc64 sparc32);
+            } else {
+                $HOST_ARCH = $MARCH;
             }
         }
     }
diff --git a/ngs-bam/setup/package.prl b/ngs-bam/setup/package.prl
new file mode 100644
index 0000000..4ebc3f1
--- /dev/null
+++ b/ngs-bam/setup/package.prl
@@ -0,0 +1,31 @@
+################################################################################
+sub PACKAGE      { 'ngs-bam' }
+sub VERSION      { '1.0.1' }
+sub PACKAGE_TYPE { 'L' }
+sub PACKAGE_NAME { 'NGS-BAM' }
+sub PACKAGE_NAMW { 'NGS' }
+sub DEPENDS      {}
+sub CONFIG_OUT   { '.' }
+sub PKG { ( LNG   => 'C',
+            OUT   => 'ncbi-outdir',
+            LOCOUT=> '../../../OUTDIR',
+            PATH  => '/usr/local/ngs/ngs-bam',
+            UPATH =>      '$HOME/ngs/ngs-bam',
+            NOMODPATH => 1,
+      ) }
+sub REQ { (
+           { name       => 'ngs-sdk',
+             aname      => 'NGS',
+             option     => 'with-ngs-sdk-prefix',
+             origin     => 'I',
+             type       => 'L',
+             srcpath    => '../ngs-sdk',
+             pkgpath    => '/usr/local/ngs/ngs-sdk',
+             usrpath    =>      '$HOME/ngs/ngs-sdk',
+             bldpath    => '$HOME/ncbi-outdir/ngs-sdk',
+             locbldpath => '$Bin/../../../OUTDIR/ngs-sdk',
+             include    => 'ngs/adapter/StringItf.hpp',
+             lib        => 'libngs-adapt-c++.a',
+            }
+        ) }
+1
diff --git a/ngs-java/.gitignore b/ngs-java/.gitignore
index 3259482..e339d6d 100644
--- a/ngs-java/.gitignore
+++ b/ngs-java/.gitignore
@@ -1,7 +1,8 @@
-Makefile.userconfig
-Makefile.config*
-user.status
-*.o
 *.class
 *.jar
+*.o
 core.*
+/Makefile.config*
+/Makefile.userconfig
+/reconfigure
+/user.status
diff --git a/ngs-java/Makefile.java b/ngs-java/Makefile.java
index 12f066f..9425d39 100644
--- a/ngs-java/Makefile.java
+++ b/ngs-java/Makefile.java
@@ -40,12 +40,6 @@ TARGETS =      \
 	$(INTLIBS) \
 	$(EXTLIBS)
 
-copyexamples:
-	@ echo "Installing examples to $(INST_SHAREDIR)/examples-java"
-	@ mkdir -p $(INST_SHAREDIR)/examples-java
-	@ cp $(TOP)/examples/Makefile $(INST_SHAREDIR)/examples-java
-	@ cp -r $(TOP)/examples/examples $(INST_SHAREDIR)/examples-java
-    
 # if configure was able to locate where the JNI headers go
 ifdef JNIPATH
 TARGETS += ngs-jni
@@ -56,7 +50,6 @@ all std: $(TARGETS)
 #-------------------------------------------------------------------------------
 # install
 # 
-ifeq (linux, $(OS))
 
 #fake root for debugging
 #uncomment this line and change the test for root ( see under install: ) to succeed:
@@ -64,9 +57,17 @@ ifeq (linux, $(OS))
 
 PROFILE_FILE = $(ROOT)/etc/profile.d/ngs-java
 JAR_TARGET = $(INST_JARDIR)/ngs-java.jar
+DOC_TARGET = $(INST_SHAREDIR)/doc/
+
+ifeq (linux, $(OS))
+    ifeq (0, $(shell id -u))
+        LINUX_ROOT = true
+        DOC_TARGET = $(ROOT)/usr/local/share/doc/ngs/
+    endif
+endif
 
-install: $(TARGETS) $(INST_JARDIR) $(INST_JARDIR)/ngs-java.jar.$(VERSION) copyexamples
-ifeq (0, $(shell id -u))
+install: $(TARGETS) javadoc $(INST_JARDIR) $(INST_JARDIR)/ngs-java.jar.$(VERSION) copydocs copyexamples 
+ifeq (true, $(LINUX_ROOT))
 	@ echo "Updating $(PROFILE_FILE).[c]sh"
 	@ echo -e \
 "#version $(VERSION)\n"\
@@ -100,15 +101,21 @@ $(INST_JARDIR)/ngs-java.jar.$(VERSION): $(LIBDIR)/ngs-java.jar
 	      false;                                                                      \
 	  fi
 
-clean:
-	rm -rf $(LIBDIR)/ngs-java* $(CLSDIR)
+copyexamples:
+	@ echo "Installing examples to $(INST_SHAREDIR)/examples-java"
+	@ mkdir -p $(INST_SHAREDIR)/examples-java
+	@ cp $(TOP)/examples/Makefile $(INST_SHAREDIR)/examples-java
+	@ cp -r $(TOP)/examples/examples $(INST_SHAREDIR)/examples-java
 
-else
-install:
+copydocs:
+	@ echo "Copying html docs to $(DOC_TARGET)..."
+	@ mkdir -p $(DOC_TARGET)
+	@ cp -r $(LIBDIR)/javadoc/* $(DOC_TARGET)
 
-endif
+clean:
+	rm -rf $(LIBDIR)/ngs-* $(CLSDIR)
 
-.PHONY: default all std install $(TARGETS)
+.PHONY: default all std clean install copyexamples copydocs $(TARGETS)
 
 #-------------------------------------------------------------------------------
 # JAVA NGS
@@ -244,3 +251,11 @@ $(JNIPATH)/headers-generated: $(MAKEFILE) $(LIBDIR)/ngs-java.jar
 	@ touch $@
 
 endif
+
+#-------------------------------------------------------------------------------
+# javadoc
+#
+javadoc:
+	javadoc -quiet -notimestamp $(CLSPATH) -sourcepath . gov.nih.nlm.ncbi.ngs ngs -d $(LIBDIR)/javadoc
+
+.PHONY: javadoc
diff --git a/ngs-java/Makefile.rules b/ngs-java/Makefile.rules
index 3ecb6ac..1a4989a 100644
--- a/ngs-java/Makefile.rules
+++ b/ngs-java/Makefile.rules
@@ -61,9 +61,9 @@ test runtests: Makefile.config
 #	@ $(MAKE) -C test runtests
 
 # rule to run configuration
-Makefile.config: Makefile.config.$(shell perl $(TOP)/os-arch.perl) konfigure.perl
+Makefile.config: Makefile.config.$(shell perl $(TOP)/setup/os-arch.perl) setup/konfigure.perl
 
-Makefile.config.$(shell perl $(TOP)/os-arch.perl):
+Makefile.config.$(shell perl $(TOP)/setup/os-arch.perl):
 	@echo "*** File '$@' is missing. Please run ./configure"
 	@false
 
diff --git a/ngs-java/configure b/ngs-java/configure
index 3313aac..baa556f 100755
--- a/ngs-java/configure
+++ b/ngs-java/configure
@@ -33,13 +33,13 @@ if [ -z "$CURDIR" ]
     exit 1
 fi
 
-if [ "$FILENAME" != configure -a ! -s konfigure.perl ]
+if [ "$FILENAME" != configure -a ! -s setup/konfigure.perl ]
     then
     echo configure: error: configure should be run as ./configure
 else
     perl -v > /dev/null 2>&1 || { echo "checking for perl... no"; \
         echo >&2 "configure: error: perl not found."; exit 1; }
 
-    cd $CURDIR
-    perl -w ./konfigure.perl $@
+    cd $CURDIR/setup
+    perl -w konfigure.perl "$@"
 fi
diff --git a/ngs-sdk/ngs/defs.h b/ngs-java/gov/nih/nlm/ncbi/ngs/HttpException.java
similarity index 77%
copy from ngs-sdk/ngs/defs.h
copy to ngs-java/gov/nih/nlm/ncbi/ngs/HttpException.java
index 5661ede..d9749b9 100644
--- a/ngs-sdk/ngs/defs.h
+++ b/ngs-java/gov/nih/nlm/ncbi/ngs/HttpException.java
@@ -24,20 +24,17 @@
 *
 */
 
-#ifndef _h_ngs_defs_
-#define _h_ngs_defs_
+package gov.nih.nlm.ncbi.ngs;
 
-/*--------------------------------------------------------------------------
- * DLL interface
- */
-#if defined _MSC_VER
- #if defined _LIBRARY
-  #define NGS_EXTERN   __declspec( dllexport ) 
- #else
-  #define NGS_EXTERN   __declspec( dllimport ) 
- #endif
-#else
- #define NGS_EXTERN   
-#endif
+////////////////////////////////////////////////////////////////////////////////
 
-#endif /* _h_ngs_defs_ */
+class HttpException extends Throwable {
+    HttpException(int responseCode)
+    {
+        this.responseCode = responseCode;
+    }
+
+    int getResponseCode() { return responseCode; }
+
+    private int responseCode;
+}
diff --git a/ngs-java/gov/nih/nlm/ncbi/ngs/HttpManager.java b/ngs-java/gov/nih/nlm/ncbi/ngs/HttpManager.java
index 187fdf9..dbd1d81 100644
--- a/ngs-java/gov/nih/nlm/ncbi/ngs/HttpManager.java
+++ b/ngs-java/gov/nih/nlm/ncbi/ngs/HttpManager.java
@@ -27,26 +27,83 @@
 package gov.nih.nlm.ncbi.ngs;
 
 import java.io.BufferedInputStream;
+import java.io.BufferedReader;
 import java.io.DataOutputStream;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URL;
 
+
 /** Helper class responsible for HTTP-related activities:
     download files using GET/POST */
 class HttpManager
 {
+    /** POST implementation. Returns response text */
+    static String post(String spec,
+            String request)
+        throws HttpException
+    {
+        String result = "";
+
+        Logger.fine(spec + "?" + request + "...");
+        
+        InputStream is = getPostInputStream(spec, request);
+
+        InputStreamReader isr = new java.io.InputStreamReader(is);
+
+        BufferedReader in = new BufferedReader(isr);
+
+        try {
+            String inputLine;
+            while ((inputLine = in.readLine()) != null)  {
+                result += inputLine;
+            }
+
+            in.close();
+        } catch (IOException e) {
+            throw new HttpException(-3);
+        }
+
+        return result;
+    }
+
+
+    /** POST implementation. Calls download() to process the response. */
+    static int post(String spec,
+        String request,
+        FileCreator creator,
+        String libname)
+    {
+        Logger.fine(spec + "?" + request + " -> " + libname + "...");
+
+        try {
+            InputStream in = getPostInputStream(spec, request);
+
+            if (download(in, creator, libname)) {
+                return 200;
+            } else {
+                return -3;
+            }
+        } catch (HttpException e) {
+            return e.getResponseCode();
+        }
+    }
+
+
     /** GET implementation. Calls download() to process the response. */
-    private static boolean get(String from, FileCreator creator, String libname)
+    private static boolean get(String spec,
+        FileCreator creator,
+        String libname)
     {
-        System.err.println(from + " ->" + libname + "...");
+        System.err.println(spec + " ->" + libname + "...");
 
         URL url = null;
         try {
-            url = new URL(from);
+            url = new URL(spec);
         } catch (java.net.MalformedURLException e) {
-            System.err.println("Bad URL: " + from + ": " + e);
+            System.err.println("Bad URL: " + spec + ": " + e);
             return false;
         }
 
@@ -54,28 +111,26 @@ class HttpManager
         try {
             in = url.openStream();
         } catch (IOException e) {
-            System.err.println("Cannot download " + from + ": " + e);
+            System.err.println("Cannot download " + spec + ": " + e);
             return false;
         }
 
         return download(in, creator, libname);
     }
 
-    /** POST implementation. Calls download() to process the response. */
-    static int post(String spec,
-        String request,
-        FileCreator creator,
-        String libname)
-    {
-        Logger.fine(spec + "?" + request + " -> " + libname + "...");
 
+    private static InputStream getPostInputStream(String spec,
+            String request)
+        throws HttpException
+    {
         URL url = null;
         try {
             url = new URL(spec);
         } catch (java.net.MalformedURLException e) {
             System.err.println("Bad URL: " + spec + ": " + e);
-            return -1;
+            throw new HttpException(-1);
         }
+
         InputStream in = null;
         try {
             java.net.URLConnection urlConn = url.openConnection();
@@ -93,24 +148,20 @@ class HttpManager
 
             in = urlConn.getInputStream();
 
-            // What if CGI returns non-200 status?
             HttpURLConnection httpConnection = (HttpURLConnection) urlConn;
             int status = httpConnection.getResponseCode();
             if (status != 200) {
-                return status;
+                throw new HttpException(status);
             }
         } catch (IOException e) {
             System.err.println(e);
-            return -2;
+            throw new HttpException(-2);
         }
 
-        if (download(in, creator, libname)) {
-            return 200;
-        } else {
-            return -3;
-        }
+        return in;
     }
 
+
     /** Download InputStream, use FileCreator to create output file */
     private static boolean download(InputStream in,
          FileCreator creator, String libname)
@@ -154,6 +205,7 @@ class HttpManager
         return true;
     }
 
+
     /** Size of buffer for HTTP-related buffered IO operations */
     static final int BUF_SZ = 128 * 1024;
 }
diff --git a/ngs-java/gov/nih/nlm/ncbi/ngs/LibManager.java b/ngs-java/gov/nih/nlm/ncbi/ngs/LibManager.java
index 7190ad7..2f4a7d6 100644
--- a/ngs-java/gov/nih/nlm/ncbi/ngs/LibManager.java
+++ b/ngs-java/gov/nih/nlm/ncbi/ngs/LibManager.java
@@ -57,10 +57,10 @@ class LibManager implements FileCreator
    Otherwise the manager will try to the search previous location entries first.
    May be you want it to test something (e.g. a bad library file). */
         KNOWN_PATH,    // from config or file downloaded from NCBI
+        NCBI_HOME,     // ~/.ncbi/lib64|32
         LIBPATH,       // iterate "java.library.path" - extended LD_LIBRARY_PATH
         NCBI_NGS_JAR_DIR, // directory where ncbi-ngs.jar is
         CLASSPATH,     // iterate "java.class.path" - where java classes are
-        NCBI_HOME,     // ~/.ncbi/ TODO: mkdir NCBI_HOME if does not exist
         CWD,           // "."
         TMP            // Temporary folder
     }
@@ -97,63 +97,83 @@ class LibManager implements FileCreator
         }
     }
 
+////////////////////////////////////////////////////////////////////////////////
+
+    private void updateKnownLibPath(String pathname) {
+        int l = 9;
+        if (knownLibPath == null) {
+            knownLibPath = new String[l];
+        } else {
+            l = knownLibPath.length;
+        }
+        int i = 0;
+        for (i = 0; i < l; ++i) {
+            if (knownLibPath[i] == null) {
+                break;
+            }
+        }
+        if (i >= l) {
+            String tmp[] = knownLibPath;
+            l *= 2;
+            knownLibPath = new String[l];
+            for (i = 0; i < tmp.length; ++i) {
+                knownLibPath[i] = tmp[i];
+            }
+        }
+        knownLibPath[i] = pathname;
+    }
+
 
     /** Creates a file by finding directory by iterating the location array
         and using libname to generate the file name */
     public BufferedOutputStream create ( String libname )
     {
-        LibPathIterator it
-            = new LibPathIterator(this, mapLibraryName(libname), true);
-
-        while (true) {
-            String pathname = it.nextName();
-            if (pathname == null) {
-                return null;
+        for (int i = 0; i < 2; ++i) {
+            Location location = null;
+            boolean model = true;
+            switch (i) {
+                case 0:
+                    location = Location.NCBI_HOME;
+                    model = false;
+                    break;
+                case 1:
+                    break;
             }
+            LibPathIterator it = new LibPathIterator
+                (this, location, mapLibraryName(libname, model), true);
 
-            Logger.fine("Trying to create " + pathname + "...");
-            File file = new File(pathname);
-            try {
-                pathname = file.getAbsolutePath();
-            } catch (SecurityException e) {
-                System.err.println(pathname + " : cannot getAbsolutePath " + e);
-            }
-            FileOutputStream s = null;
-            try {
-                s = new FileOutputStream(pathname);
-            } catch (java.io.FileNotFoundException e) {
+            while (true) {
+                String pathname = it.nextName();
+                if (pathname == null) {
+                    return null;
+                }
+
+                Logger.fine("Trying to create " + pathname + "...");
+                File file = new File(pathname);
+                try {
+                    pathname = file.getAbsolutePath();
+                } catch (SecurityException e) {
+                    System.err.println
+                        (pathname + " : cannot getAbsolutePath " + e);
+                }
+                FileOutputStream s = null;
+                try {
+                    s = new FileOutputStream(pathname);
+                } catch (java.io.FileNotFoundException e) {
 /* e.message = pathname (Permission denied):
 could be because pathname is not writable
 or pathname not found and its directory is not writable */
-                System.err.println("Cannot open " + pathname);
-                continue;
-            }
-
-            int l = 9;
-            if (knownLibPath == null) {
-                knownLibPath = new String[l];
-            } else {
-                l = knownLibPath.length;
-            }
-            int i = 0;
-            for (i = 0; i < l; ++i) {
-                if (knownLibPath[i] == null) {
-                    break;
-                }
-            }
-            if (i >= l) {
-                String tmp[] = knownLibPath;
-                l *= 2;
-                knownLibPath = new String[l];
-                for (i = 0; i < tmp.length; ++i) {
-                    knownLibPath[i] = tmp[i];
+                    System.err.println("Cannot open " + pathname);
+                    continue;
                 }
-            }
-            knownLibPath[i] = pathname;
 
-            Logger.fine("Opened " + pathname);
-            return new BufferedOutputStream(s, HttpManager.BUF_SZ);
+                updateKnownLibPath(pathname);
+
+                Logger.fine("Opened " + pathname);
+                return new BufferedOutputStream(s, HttpManager.BUF_SZ);
+            }
         }
+        return null;
     }
 
 
@@ -199,7 +219,15 @@ or pathname not found and its directory is not writable */
 
     static String[] mapLibraryName(String libname)
     {
-        String m = libnameWithModel(libname);
+        return mapLibraryName(libname, true);
+    }
+
+    static String[] mapLibraryName(String libname, boolean model)
+    {
+        String m = libname;
+        if (model) {
+            m = libnameWithModel(libname);
+        }
         String name = System.getProperty("os.name");
         int dup = 1;
         if (name != null  && name.equals("Mac OS X")) {
@@ -292,7 +320,7 @@ or pathname not found and its directory is not writable */
         return m;
     }
 
-    private enum Bit {
+    enum Bit {
         b32,
         b64,
         bUNKNOWN,
diff --git a/ngs-java/gov/nih/nlm/ncbi/ngs/LibPathIterator.java b/ngs-java/gov/nih/nlm/ncbi/ngs/LibPathIterator.java
index a5a7c86..59e0522 100644
--- a/ngs-java/gov/nih/nlm/ncbi/ngs/LibPathIterator.java
+++ b/ngs-java/gov/nih/nlm/ncbi/ngs/LibPathIterator.java
@@ -62,7 +62,7 @@ class LibPathIterator {
     }
 
 
-    private LibPathIterator(LibManager mgr,
+    LibPathIterator(LibManager mgr,
         LibManager.Location location,
         String filename[],
         boolean parents)
@@ -417,25 +417,19 @@ Here we use it just to find where to write the downoaded file. */
         return true;
     }
 
-    /** NCBI_HOME (~/.ncbi). Create it if required. */
-    private String ncbiHome()
+    private boolean mkdir(String path, boolean closed)
     {
-        String path = System.getProperty("user.home");
-        if (path == null) {
-            return null;
-        }
-
-        path += fileSeparator() + ".ncbi";
+        File f = new File(path);
+
+        if (!f.exists()) {
+            try {
+                f.mkdirs();
+            } catch (SecurityException e) {
+                Logger.fine(e.toString());
+                return false;
+            }
 
-        if (parents) {
-            File f = new File(path);
-            if (!f.exists()) {
-                try {
-                    f.mkdirs();
-                } catch (SecurityException e) {
-                    Logger.fine(e.toString());
-                    return null;
-                }
+            if (closed) {
                 try {
                     f.setExecutable(false, false);
                 } catch (SecurityException e) {
@@ -451,21 +445,56 @@ Here we use it just to find where to write the downoaded file. */
                 } catch (SecurityException e) {
                     Logger.fine(e.toString());
                 }
-                try {
-                    f.setExecutable(true, true);
-                } catch (SecurityException e) {
-                    Logger.fine(e.toString());
-                }
-                try {
-                    f.setReadable(true, true);
-                } catch (SecurityException e) {
-                    Logger.fine(e.toString());
-                }
-                try {
-                    f.setWritable(true, true);
-                } catch (SecurityException e) {
-                    Logger.fine(e.toString());
-                }
+            }
+
+            try {
+                f.setExecutable(true, true);
+            } catch (SecurityException e) {
+                Logger.fine(e.toString());
+            }
+            try {
+                f.setReadable(true, true);
+            } catch (SecurityException e) {
+                Logger.fine(e.toString());
+            }
+            try {
+                f.setWritable(true, true);
+            } catch (SecurityException e) {
+                Logger.fine(e.toString());
+            }
+        }
+
+        return true;
+    }
+
+    /** NCBI_HOME (~/.ncbi). Create it if required. */
+    private String ncbiHome()
+    {
+        String path = System.getProperty("user.home");
+        if (path == null) {
+            return null;
+        }
+
+        path += fileSeparator() + ".ncbi";
+        if (parents) {
+            if (!mkdir(path, true)) {
+                return null;
+            }
+        }
+
+        path += fileSeparator() + "lib";
+        switch (LibManager.DetectJVM()) {
+            case b64:
+                path += "64";
+                break;
+            case b32:
+                path += "32";
+                break;
+        }
+
+        if (parents) {
+            if (!mkdir(path, false)) {
+                return null;
             }
         }
 
diff --git a/ngs-java/gov/nih/nlm/ncbi/ngs/Makefile b/ngs-java/gov/nih/nlm/ncbi/ngs/Makefile
index e8d4b44..c191c7b 100644
--- a/ngs-java/gov/nih/nlm/ncbi/ngs/Makefile
+++ b/ngs-java/gov/nih/nlm/ncbi/ngs/Makefile
@@ -61,27 +61,28 @@ clean: stdjclean
 # classes for ngs-ncbi
 #
 
-LIB_SRC =                      \
+LIB_SRC =                          \
+	HttpException              \
 	HttpManager                \
-	LibManager      	       \
-	LibPathIterator   	       \
+	LibManager                 \
+	LibPathIterator	           \
 	Logger      	           \
 	Manager      	           \
-    ReadCollectionItf          \
-    Refcount                   \
-    ReadGroupIteratorItf       \
-    ReadGroupItf               \
-    ReferenceIteratorItf       \
-    ReferenceItf               \
-    AlignmentItf               \
-    AlignmentIteratorItf       \
-    ReadItf                    \
-    ReadIteratorItf            \
-    PileupIteratorItf          \
-    PileupItf                  \
-    FragmentItf                \
-    PileupEventIteratorItf     \
-    PileupEventItf             \
+	ReadCollectionItf          \
+	Refcount                   \
+	ReadGroupIteratorItf       \
+	ReadGroupItf               \
+	ReferenceIteratorItf       \
+	ReferenceItf               \
+	AlignmentItf               \
+	AlignmentIteratorItf       \
+	ReadItf                    \
+	ReadIteratorItf            \
+	PileupIteratorItf          \
+	PileupItf                  \
+	FragmentItf                \
+	PileupEventIteratorItf     \
+	PileupEventItf             \
 	TestyTheBear               \
 
 NGS_SRC =                      \
diff --git a/ngs-java/gov/nih/nlm/ncbi/ngs/Manager.java b/ngs-java/gov/nih/nlm/ncbi/ngs/Manager.java
index 702a97f..2cd771a 100644
--- a/ngs-java/gov/nih/nlm/ncbi/ngs/Manager.java
+++ b/ngs-java/gov/nih/nlm/ncbi/ngs/Manager.java
@@ -97,12 +97,15 @@ class Manager
         }
     }
 
-
-    // This jar's version : should match to JNI DLL's version
-    static int version ()
-    {
-        return 0x01000000;
+    /** ncbi-vdb version */
+    static String version() {
+        try {
+            return Version();
+        } catch (Throwable e) {
+            return "";
+        }
     }
+    private native static String Version ();
 
     private native static String Initialize ();
     private native static void Shutdown ();
diff --git a/ngs-java/ngs/Alignment.java b/ngs-java/ngs/Alignment.java
index e6cb7d3..af24486 100644
--- a/ngs-java/ngs/Alignment.java
+++ b/ngs-java/ngs/Alignment.java
@@ -181,6 +181,15 @@ public interface Alignment
     String getLongCigar ( boolean clipped )
         throws ErrorMsg;
 
+    /**
+     * getRNAOrientation
+     * @return '+' if positive strand is transcribed
+     * @return '-' if negative strand is transcribed
+     * @return '?' if unknown
+     */
+    char getRNAOrientation ()
+        throws ErrorMsg;
+
 
     /*------------------------------------------------------------------
      * details of mate alignment
diff --git a/ngs-java/ngs/Fragment.java b/ngs-java/ngs/Fragment.java
index cc80f64..133e4a1 100644
--- a/ngs-java/ngs/Fragment.java
+++ b/ngs-java/ngs/Fragment.java
@@ -61,7 +61,7 @@ public interface Fragment
     /** 
      * getFragmentBases
      * @param offset is zero-based and non-negative
-     * @param length must be >= 0
+     * @param length must be ≥ 0
      * @return sequence bases
      */
     String getFragmentBases ( long offset, long length )
@@ -86,7 +86,7 @@ public interface Fragment
     /** 
      * getFragmentQualities using ASCII offset of 33
      * @param offset is zero-based and non-negative
-     * @param length must be >= 0
+     * @param length must be ≥ 0
      * @return phred quality values
      */
     String getFragmentQualities ( long offset, long length )
diff --git a/ngs-java/ngs/Read.java b/ngs-java/ngs/Read.java
index 373026c..aef6a1d 100644
--- a/ngs-java/ngs/Read.java
+++ b/ngs-java/ngs/Read.java
@@ -105,7 +105,7 @@ public interface Read
     /** 
      * getReadBases
      * @param offset is zero-based and non-negative
-     * @param length must be >= 0
+     * @param length must be ≥ 0
      * @return sequence bases
      */
     String getReadBases ( long offset, long length )
@@ -130,7 +130,7 @@ public interface Read
     /**
      * getReadQualities
      * @param offset is zero-based and non-negative
-     * @param length must be >= 0
+     * @param length must be ≥ 0
      * @return phred quality values using ASCII offset of 33
      */
     String getReadQualities ( long offset, long length )
diff --git a/ngs-java/ngs/ReadCollection.java b/ngs-java/ngs/ReadCollection.java
index 4374d7e..a62b005 100644
--- a/ngs-java/ngs/ReadCollection.java
+++ b/ngs-java/ngs/ReadCollection.java
@@ -132,10 +132,11 @@ public interface ReadCollection
      * The object id is unique within any given ReadCollection,
      * and may designate an Alignment of any category.
      *
+     * Note Excessive usage may create pressure on JVM and System memory.
+     *
      * @return an individual Alignment instance
      * @throws ErrorMsg if Alignment is not found
      * @throws ErrorMsg upon an error accessing data
-     * @.note Excessive usage may create pressure on JVM and System memory.
      */
     Alignment getAlignment ( String alignmentId )
         throws ErrorMsg;
@@ -149,7 +150,7 @@ public interface ReadCollection
 
     /** 
      * Count all Alignments within the ReadCollection
-     * @return 0 if there are no aligned Reads, > 0 otherwise
+     * @return 0 if there are no aligned Reads, > 0 otherwise
      * @throws ErrorMsg upon an error accessing data
      */
     long getAlignmentCount ()
diff --git a/ngs-java/ngs/Reference.java b/ngs-java/ngs/Reference.java
index d253215..8f56c53 100644
--- a/ngs-java/ngs/Reference.java
+++ b/ngs-java/ngs/Reference.java
@@ -75,7 +75,7 @@ public interface Reference
     /** 
      * getReferenceBases
      * @param offset is zero-based and non-negative
-     * @param length must be >= 0
+     * @param length must be ≥ 0
      * @return sub-sequence bases for Reference
      */
     String getReferenceBases ( long offset, long length )
@@ -97,7 +97,7 @@ public interface Reference
     /** 
      * getReferenceChunk
      * @param offset is zero-based and non-negative
-     * @param length must be >= 0
+     * @param length must be > 0
      * @return largest contiguous chunk available of sub-sequence bases for Reference
      * <p>
      *  NB - actual returned sequence may be shorter
diff --git a/ngs-java/ngs/itf/AlignmentItf.java b/ngs-java/ngs/itf/AlignmentItf.java
index 709703c..f8d68b2 100644
--- a/ngs-java/ngs/itf/AlignmentItf.java
+++ b/ngs-java/ngs/itf/AlignmentItf.java
@@ -285,6 +285,16 @@ class AlignmentItf
     }
 
 
+    /* getRNAOrientation
+     */
+    public char getRNAOrientation ()
+        throws ErrorMsg
+    {
+        return this . GetRNAOrientation ( self );
+    }
+
+
+
     /*------------------------------------------------------------------
      * details of mate alignment
      */
@@ -405,6 +415,8 @@ class AlignmentItf
         throws ErrorMsg;
     private native String GetLongCigar ( long self, boolean clipped )
         throws ErrorMsg;
+    private native char GetRNAOrientation ( long self )
+        throws ErrorMsg;
     private native boolean HasMate ( long self );
     private native String GetMateAlignmentId ( long self )
         throws ErrorMsg;
diff --git a/ngs-java/package.pm b/ngs-java/package.pm
deleted file mode 100644
index c953e0c..0000000
--- a/ngs-java/package.pm
+++ /dev/null
@@ -1,29 +0,0 @@
-################################################################################
-sub PACKAGE      { "ngs-java" }
-sub VERSION      { "1.0.0" }
-sub PACKAGE_TYPE { 'B' }
-sub PACKAGE_NAME { "NGS-JAVA" }
-sub PACKAGE_NAMW { "NGS_JAVA" }
-sub DEPENDS      {}
-sub CONFIG_OUT   { '.' }
-sub PKG { ( LNG  => 'JAVA',
-            OUT  => 'ncbi-outdir',
-            PATH  => '/usr/local/ngs/ngs-java',
-            UPATH =>      '$HOME/ngs/ngs-java',
-            NGS_SDK_SRC => 1,
-            EXAMP => '1',  ) }
-sub REQ { ( { name    => 'ngs-sdk',
-              namew   => 'NGS',
-              option  => 'with-ngs-sdk-sources',
-              origin  => 'I',
-              type    => 'SI',
-              srcpath => '../ngs-sdk',
-              pkgpath => '/usr/local/ngs/ngs-sdk',
-              usrpath =>      '$HOME/ngs/ngs-sdk',
-              bldpath => '$HOME/ncbi-outdir/ngs-sdk/$OS',
-              include => 'ngs/itf/Refcount.h',
-              lib     => 'libngs-sdk.so',
-              ilib    => 'libngs-bind-c++.a',
-        } ) }
-
-1
diff --git a/ngs-python/configure b/ngs-java/setup/install
similarity index 83%
copy from ngs-python/configure
copy to ngs-java/setup/install
index 3313aac..4dcf8cf 100755
--- a/ngs-python/configure
+++ b/ngs-java/setup/install
@@ -29,17 +29,17 @@ CURDIR="`dirname $0`"
 
 if [ -z "$CURDIR" ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
     exit 1
 fi
 
-if [ "$FILENAME" != configure -a ! -s konfigure.perl ]
+if [ "$FILENAME" != install -a ! -s install.perl ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
 else
     perl -v > /dev/null 2>&1 || { echo "checking for perl... no"; \
-        echo >&2 "configure: error: perl not found."; exit 1; }
+        echo >&2 "error: perl not found."; exit 1; }
 
     cd $CURDIR
-    perl -w ./konfigure.perl $@
+    perl -w ./install.perl "$@"
 fi
diff --git a/ngs-java/setup/install.perl b/ngs-java/setup/install.perl
new file mode 100644
index 0000000..5e5f33e
--- /dev/null
+++ b/ngs-java/setup/install.perl
@@ -0,0 +1,1324 @@
+################################################################################
+
+use strict;
+
+require 'install.prl';
+
+use Config;
+use Cwd        "abs_path";
+use File::Copy "copy";
+use File::Copy::Recursive qw(dircopy);
+use File::Path   "make_path";
+use FindBin    qw($Bin);
+use Getopt::Long "GetOptions";
+
+my ($OS, $MAKING, %INSTALLED_LIBS);
+{
+    my $file = 'os.prl';
+    if (-e $file) {
+        require $file;
+        $OS = OS();
+    } else {
+        ++$MAKING;
+    }
+}
+
+my %HAVE = HAVE();
+BINS() if ($HAVE{BINS});
+if ($HAVE{LIBS}) {
+    ++$HAVE{INCLUDES};
+    LIBS();
+}
+if ($HAVE{INCLUDES} || $HAVE{USR_INCLUDES}) {
+    die "no INCLUDES" unless INCLUDES();
+}
+die "no CONFIG_OUT" unless CONFIG_OUT();
+
+my @bits;
+my @options = ( 'debug', 'examplesdir=s', 'force', 'help',
+                'includedir=s', 'no-create', 'prefix=s', 'root=s', );
+push @options, 'oldincludedir=s' if ($HAVE{USR_INCLUDES});
+if ($HAVE{JAR}) {
+    push @options, 'jardir=s';
+    if (-e "$Bin/../jar") {
+        ++$HAVE{LIBS};
+        $_{JARDIR} = expand_path("$Bin/../jar");
+    }
+} elsif ($HAVE{PYTHON} && ! $MAKING) {
+    ++$HAVE{LIBS};
+}
+if (! $MAKING && ($HAVE{JAR} || $HAVE{PYTHON})) {
+    ++$HAVE{TWO_LIBS};
+    push @options, 'ngslibdir=s', 'vdblibdir=s';
+}
+push @options, 'bindir=s'                     if ($HAVE{BINS});
+push @options, 'bits=s' => \@bits, 'libdir=s' if ($HAVE{LIBS});
+
+my %OPT;
+unless (GetOptions(\%OPT, @options)) {
+    print "install: error\n";
+    exit 1;
+}
+ at bits = split(/,/,join(',', at bits));
+foreach (@bits) {
+    unless (/^32$/ || /^64$/) {
+        print "install: error: bad bits option argument value\n";
+        exit 1;
+    }
+}
+if ($#bits > 0) {
+    foreach (qw(bindir libdir ngslibdir vdblibdir)) {
+        if ($OPT{$_}) {
+            print "install: error: cannot supply multiple bits arguments "
+                . "when $_ argument is provided\n";
+            exit 1;
+        }
+    }
+}
+
+$OPT{root} = expand_path($OPT{root}) if ($OPT{root});
+
+prepare();
+
+my $LINUX_ROOT;
+++$LINUX_ROOT if (linux_root());
+my $ROOT = '';
+if ($OPT{root}) {
+    $ROOT = "$OPT{root}/root";
+    ++$LINUX_ROOT;
+    foreach ("$ROOT/usr/include", "$ROOT/etc/profile.d") {
+        unless (-e $_) {
+            print "mkdir -p $_... ";
+            eval { make_path($_) };
+            if ($@) {
+                print "failure: $@\n";
+                exit 1;
+            }
+            print "ok\n";
+        }
+    }
+}
+
+my $oldincludedir = "$ROOT/usr/include";
+
+my $EXAMPLES_DIR = "$Bin/../examples";
+
+ at _ = CONFIGURE();
+
+if ($OPT{help}) {
+    help();
+    exit 0;
+}
+
+foreach (qw(BITS INCDIR
+ INST_INCDIR INST_JARDIR INST_LIBDIR INST_NGSLIBDIR INST_SHAREDIR INST_VDBLIBDIR
+ LIBX LPFX MAJVERS MAJVERS_SHLX OS OTHER_PREFIX
+ PACKAGE_NAME PREFIX SHLX VERSION VERSION_LIBX VERSION_SHLX))
+{
+    unless ($_{$_}) {
+        next if (/^INST_JARDIR$/    && ! $HAVE{JAR});
+        next if (/^INST_NGSLIBDIR$/ && ! $HAVE{TWO_LIBS});
+        next if (/^INST_SHAREDIR$/  && ! $HAVE{EXAMPLES});
+        next if (/^INST_VDBLIBDIR$/ && ! $HAVE{TWO_LIBS});
+        fatal_config("$_ not found");
+    }
+}
+unless ($_{LIBDIR32} || $_{LIBDIR64} || ($HAVE{PYTHON} && $MAKING)) {
+    fatal_config('LIBDIR not found');
+}
+ 
+if ($OPT{prefix}) {
+    $OPT{prefix} = expand_path($OPT{prefix});
+    $_{INST_BINDIR  } = "$OPT{prefix}/bin";
+    $_{INST_LIBDIR  } = "$OPT{prefix}/lib";
+    $_{INST_NGSLIBDIR} = $_{INST_VDBLIBDIR} = $_{INST_LIBDIR};
+    $_{INST_INCDIR  } = "$OPT{prefix}/include";
+    $_{INST_JARDIR  } = "$OPT{prefix}/jar";
+    $_{INST_SHAREDIR} = "$OPT{prefix}/share";
+}
+$_{INST_SHAREDIR} = expand_path($OPT{examplesdir  }) if ($OPT{examplesdir  });
+$_{INST_INCDIR  } = expand_path($OPT{includedir   }) if ($OPT{includedir   });
+$_{INST_JARDIR  } = expand_path($OPT{jardir       }) if ($OPT{jardir       });
+$_{BIN_TARGET   } = expand_path($OPT{bindir       }) if ($OPT{bindir       });
+$oldincludedir    = expand_path($OPT{oldincludedir}) if ($OPT{oldincludedir});
+if ($OPT{libdir}) {
+    $_{INST_NGSLIBDIR} = $_{LIB_TARGET} = expand_path($OPT{libdir}) ;
+    $_{INST_VDBLIBDIR} = $_{LIB_TARGET};
+}
+$_{INST_NGSLIBDIR}= expand_path($OPT{ngslibdir}) if ($OPT{ngslibdir});
+$_{INST_VDBLIBDIR}= expand_path($OPT{vdblibdir}) if ($OPT{vdblibdir});
+
+if ($OPT{'no-create'} && $_{OS} eq 'linux') {
+    if ($LINUX_ROOT) {
+        print "root user\n\n";
+    } else {
+        print "non root user\n\n";
+    }
+}
+
+my $failures = 0;
+my $bFailure = 1;
+
+push @bits, $_{BITS} unless (@bits);
+foreach (@bits) {
+    $_{BITS} = $_;
+
+    print "installing $_{PACKAGE_NAME} ($_{VERSION}) package";
+    print " for $_{OS}-$_{BITS}" if ($HAVE{BINS} || $HAVE{LIBS});
+    print "...\n";
+
+    if ($HAVE{BINS}) {
+        $_{BINDIR} = $_{"BINDIR$_{BITS}"};
+        unless ($_{BINDIR}) {
+            print "install: error: $_{BITS}-bit version is not available\n\n";
+            next;
+        }
+    }
+    if ($HAVE{LIBS} || $HAVE{PYTHON}) {
+# ($_{LIBDIR} for python points where ngs-sdk and ncbi-vdb dynamic libraries
+# can be found to correctly set up LD_LIBRARY_PATH
+        $_{LIBDIR} = $_{"LIBDIR$_{BITS}"};
+        unless ($_{LIBDIR}) {
+            print "install: error: $_{BITS}-bit version is not available\n\n";
+            next;
+        }
+    }
+    if ($HAVE{JAR} && ! $_{JARDIR}) {
+        $_{JARDIR} = $_{"LIBDIR$_{BITS}"};
+        unless ($_{JARDIR}) {
+            if ($_{BITS} == 64) {
+                $_{JARDIR} = $_{LIBDIR32};
+            } else {
+                $_{JARDIR} = $_{LIBDIR64};
+            }
+            unless ($_{JARDIR}) {
+                print "install: error: jar file was not cannot found\n";
+                exit 1;
+            }
+        }
+    }
+    $bFailure = 0;
+
+    if ($OPT{'no-create'}) {
+        print     "includedir : '$_{INST_INCDIR  }'\n" if ($HAVE{INCLUDES  });
+        print     "libdir     : '$_{INST_LIBDIR}$_{BITS}'\n" if ($HAVE{LIBS});
+        print     "jardir     : '$_{INST_JARDIR  }'\n" if ($HAVE{JAR       });
+        print     "examplesdir: '$_{INST_SHAREDIR}'\n" if ($HAVE{EXAMPLES  });;
+        if ($LINUX_ROOT) {
+            print "oldincludedir: '$oldincludedir'\n"  if ($HAVE{USR_INCLUDES});
+        }
+        print "\n";
+        next;
+    }
+
+    $_{BIN_TARGET} = "$_{INST_BINDIR}$_{BITS}" unless ($OPT{bindir});
+    $_{LIB_TARGET} = "$_{INST_LIBDIR}$_{BITS}" unless ($OPT{libdir});
+
+    $File::Copy::Recursive::CPRFComp = 1;
+
+    $failures += copybins    () if ($HAVE{BINS});
+    $failures += copylibs    () if ($HAVE{LIBS});
+    $failures += copyincludes() if ($HAVE{INCLUDES});
+    $failures += copyjars    () if ($HAVE{JAR});
+    $failures += copyconfig  () if ($HAVE{CONFIG});
+
+    if ($HAVE{JAR}) {
+        $File::Copy::Recursive::CPRFComp = 0;
+        $failures += copydocs() ;
+        $File::Copy::Recursive::CPRFComp = 1;
+    }
+
+    $failures += copyexamples();
+    $failures += finishinstall() unless ($failures);
+
+    unless ($failures) {
+        print "\nsuccessfully installed $_{PACKAGE_NAME} ($_{VERSION}) package";
+    } else {
+        print "\nfailed to install $_{PACKAGE_NAME} ($_{VERSION}) package";
+    }
+    print " for $_{OS}-$_{BITS}" if ($HAVE{BINS} || $HAVE{LIBS});
+    print ".\n\n";
+}
+
+$failures = 1 if (!$failures && $bFailure);
+
+exit $failures;
+
+################################################################################
+
+sub copybins {
+    unless ($_{BIN_TARGET}) {
+        print "error: cannot install executables: no BIN_TARGET\n";
+        return 1;
+    }
+    my $s = $_{BINDIR};
+    my $d = $_{BIN_TARGET};
+    print "installing executables to $d...";
+    unless (-e $s) {
+        print " failure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+    print "\t\tcd $d\n" if ($OPT{debug});
+    chdir $d or die "cannot cd $d";
+    my $failures = 0;
+    foreach (BINS()) {
+        print "installing '$_'..." if ($OPT{debug});
+        my $df = "$_$_{VERSION_EXEX}";
+        my $sf = "$s/$df";
+        print "\n\t\t$sf -> $df\n\t" if ($OPT{debug});
+        unless (-e $sf) {
+            print " skipped\n" if ($OPT{debug});
+            next;
+        }
+        if ((! $OPT{force}) && (-e $df) && (-M $df < -M $sf)) {
+            print " found\n" if ($OPT{debug});
+        } else {
+            unless (copy($sf, $df)) {
+                print "failure\n";
+                print "install: error: cannot copy '$sf' '$df'.\n";
+                ++$failures;
+                next;
+            }
+            my $mode = 0755;
+            printf "\tchmod %o $df\n\t", $mode if ($OPT{debug});
+            unless (chmod($mode, $df)) {
+                print " failure\n" if ($OPT{debug});
+                print "install: error: cannot chmod '$df': $!\n";
+                ++$failures;
+                next;
+            }
+            unless (symlinks($_, $df, 'bin')) {
+                print " success\n" if ($OPT{debug});
+            } else {
+                print " failure\n" if ($OPT{debug});
+                ++$failures;
+            }
+        }
+    }
+    return $failures;
+}
+
+sub copyconfig {
+    my $d;
+    if ($LINUX_ROOT) {
+        $d = "$ROOT/etc";
+    }
+    elsif ($HAVE{BINS}) {
+        $d = $_{BIN_TARGET};
+        unless ($d) {
+            print
+               "error: cannot install configuration files: no BIN_TARGET\n";
+            return 1;
+        }
+    } else {
+        $d = $_{LIB_TARGET};
+        unless ($d) {
+            print
+               "error: cannot install configuration files: no LIB_TARGET\n";
+            return 1;
+        }
+    }
+    $d = File::Spec->catdir($d, 'ncbi');
+    my $kfg = File::Spec->catdir($Bin, '..', 'libs/kfg/default.kfg');
+    unless (-e $kfg) {
+        $kfg = File::Spec->catdir($Bin, '..', 'tools/vdb-copy/vdb-copy.kfg');
+    }
+    unless (-e $kfg) {
+        if ($_{BINDIR}) {
+            $kfg = File::Spec->catdir($_{BINDIR}, 'ncbi', 'vdb-copy.kfg');
+        } elsif ($_{LIBDIR}) {
+            $kfg = File::Spec->catdir($_{LIBDIR}, 'ncbi', 'default.kfg');
+            unless (-e $kfg) {
+                print
+                  "error: cannot install configuration files: no default.kfg\n";
+                return 1;
+            }
+        }
+    }
+    print "installing configuration files to $d... ";
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+    my $df = File::Spec->catdir($d, 'ncbi-vdb.kfg');
+    print "\t\t$kfg -> $df\n" if ($OPT{debug});
+    unless (copy($kfg, $df)) {
+        print "install: error: cannot copy '$kfg' '$df'.\n";
+        return 1;
+    } else {
+        print "success\n";
+        return 0;
+    }
+}
+
+sub copylibs {
+    die unless ($HAVE{LIBS});
+
+    my $s = $_{LIBDIR};
+    my $d = $_{LIB_TARGET};
+
+    print "installing libraries to $d... ";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    if ($HAVE{TWO_LIBS}) {
+        my $ngs = $_{INST_NGSLIBDIR};
+        if ($ngs && ! ($OPT{prefix} && $OPT{libdir} && $OPT{ngslibdir})) {
+            $ngs .= $_{BITS};
+        }
+        my $vdb = $_{INST_VDBLIBDIR};
+        if ($vdb && ! ($OPT{prefix} && $OPT{libdir} && $OPT{vdblibdir})) {
+            $vdb .= $_{BITS};
+        }
+        if ($ngs || $vdb) {
+            unless ($ngs && $vdb) {
+                $ngs = $d unless ($ngs);
+                $vdb = $d unless ($vdb);
+            }
+            $INSTALLED_LIBS{'ngs-sdk' } = $ngs;
+            $INSTALLED_LIBS{'ncbi-vdb'} = $vdb;
+        }
+    }
+    $INSTALLED_LIBS{0} = $d unless (%INSTALLED_LIBS);
+
+    foreach (keys %INSTALLED_LIBS) {
+        my $d = $INSTALLED_LIBS{$_};
+        print "\nchecking $d... ";
+        unless (-e $d) {
+            print "not found\n";
+            print "mkdir -p $d... ";
+            eval { make_path($d) };
+            if ($@) {
+                print "failure\ninstall: error: cannot mkdir $d\n";
+                return 1;
+            } else {
+                print "success\n";
+            }
+        } else {
+            print "exists\n";
+        }
+    }
+
+    return $MAKING ? copybldlibs($s, $d) : copydir($s, %INSTALLED_LIBS);
+}
+
+sub copybldlibs {
+    my ($s, $d) = @_;
+
+    print "\t\tcd $d\n" if ($OPT{debug});
+    chdir $d or die "cannot cd $d";
+
+    my $failures = 0;
+
+    my %LIBRARIES_TO_INSTALL = LIBS();
+    foreach (keys %LIBRARIES_TO_INSTALL) {
+        print "installing '$_'... ";
+
+        my $nb = "$_{LPFX}$_";
+        my $nv = "$nb.";
+        my $lib = 'dll';
+        if ($LIBRARIES_TO_INSTALL{$_} eq 'SHL') {
+            $nv .= $_{VERSION_SHLX};
+        } elsif ($LIBRARIES_TO_INSTALL{$_} eq 'LIB') {
+            $nv .= $_{VERSION_LIBX};
+            $lib = 'lib';
+        } else {
+            die "bad library type";
+        }
+
+        my $sf = "$s/$nv";
+        my $df = "$d/$nv";
+
+        print "\n\t\t$sf -> $df\n\t" if ($OPT{debug});
+
+        unless (-e $sf) {
+            print "failure\n";
+            print "install: error: '$sf' is not found.\n";
+            ++$failures;
+            next;
+        }
+
+        if ((! $OPT{force}) && (-e $df) && (-M $df < -M $sf)) {
+            print "found\n";
+        } else {
+            unless (copy($sf, $df)) {
+                print "failure\n";
+                print "install: error: cannot copy '$sf' '$df'.\n";
+                ++$failures;
+                next;
+            }
+            my $mode = 0644;
+            $mode = 0755 if ($lib eq 'dll');
+            printf "\tchmod %o $df\n\t", $mode if ($OPT{debug});
+            unless (chmod($mode, $df)) {
+                print "failure\n";
+                print "install: error: cannot chmod '$df': $!\n";
+                ++$failures;
+                next;
+            }
+            unless (symlinks($nb, $nv, $lib)) {
+                print "success\n";
+            } else {
+                print "failure\n";
+                ++$failures;
+            }
+        }
+    }
+
+    return $failures;
+}
+
+sub symlinks {
+    my ($nb, $nv, $type) = @_;
+
+    my @l;
+    if ($type eq 'lib') {
+        push @l, "$nb-static.$_{LIBX}";
+        push @l, "$nb.$_{LIBX}";
+        push @l, "$nb.$_{MAJVERS_LIBX}";
+    } elsif ($type eq 'dll') {
+        push @l, "$nb.$_{SHLX}";
+        push @l, "$nb.$_{MAJVERS_SHLX}";
+    } elsif ($type eq 'bin' || $type eq 'jar') {
+        push @l, $nb;
+        push @l, "$nb.$_{MAJVERS}";
+    } else {
+        print "failure\n";
+        print "install: error: unknown symlink type '$type'\n";
+        return 1;
+    }
+
+    my $failures = 0;
+
+    for (my $i = 0; $i <= $#l; ++$i) {
+        my $file = $l[$i];
+        if (-e $file) {
+            print "\trm $file\n\t" if ($OPT{debug});
+            unless (unlink $file) {
+                print "failure\n";
+                print "install: error: cannot rm '$file': $!\n";
+                ++$failures;
+                next;
+            }
+        }
+
+        my $o = $nv;
+        $o = $l[$i + 1] if ($i < $#l);
+
+        print "\tln -s $o $file\n\t" if ($OPT{debug});
+        unless (symlink $o, $file) {
+            print "failure\n";
+            print "install: error: cannot symlink '$o' '$file': $!\n";
+            ++$failures;
+            next;
+        }
+    }
+
+    return $failures;
+}
+
+sub copydir {
+    my ($s, %d) = @_;
+
+    my $failures = 0;
+
+    foreach my $pattern(keys %d) {
+        my $d = $d{$pattern};
+        print "\t\tcd $d\n" if ($OPT{debug});
+        chdir $d or die "cannot cd $d";
+
+        opendir(D, $s) or die "cannot opendir $s: $!";
+
+        while (readdir D) {
+            next if (/^\.{1,2}$/);
+            next if ($pattern && ! /$pattern/);
+
+            my $n = "$s/$_";
+
+            if (-l $n) {
+                print "\t\t$_ (symlink)... " if ($OPT{debug});
+                my $l = readlink $n;
+                if ((-e $_) && (!unlink $_)) {
+                    print "error: cannot remove $l: $!\n";
+                    ++$failures;
+                    next;
+                }
+                unless (symlink($l, $_)) {
+                    print "error: cannot create symlink from $_ to $l: $!\n";
+                    ++$failures;
+                    next;
+                }
+                print "success\n" if ($OPT{debug});
+            } else {
+                print "\t\t$_... " if ($OPT{debug});
+                if ((-e $_) && (!unlink $_)) {
+                    print "error: cannot remove $_: $!\n";
+                    ++$failures;
+                    next;
+                }
+                unless (copy($n, $_)) {
+                    print "error: cannot copy '$n' to '$_': $!\n";
+                    ++$failures;
+                    next;
+                }
+                print "success\n" if ($OPT{debug});
+            }
+        }
+
+        closedir D;
+    }
+
+    return $failures;
+}
+
+sub includes_out {
+    my $out = '';
+    eval { $out = INCLUDES_OUT(); };
+    $out = File::Spec->catdir($_{INST_INCDIR}, $out);
+    $out;
+}
+
+sub copyincludes {
+    print "installing includes to $_{INST_INCDIR}... ";
+
+    my $s = "$_{INCDIR}/" . INCLUDES();
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    my $out = includes_out();
+    my $d = $out;
+    $d = $_{INST_INCDIR} unless ($d);
+
+    unless (-e $d) {
+        print "\n\t\tmkdir -p $d" if ($OPT{debug});
+        eval { make_path($d) };
+        if ($@) {
+            print "\tfailure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        }
+    }
+
+    if ($out && -f $s) {
+        print "\n\t\tcp $s $d\n\t" if ($OPT{debug});
+        unless (copy($s, $d)) {
+            print "failure\n";
+            return 1;
+        }
+    } else {
+        print "\n\t\tcp -r $s $d\n\t" if ($OPT{debug});
+        unless (dircopy($s, $d)) {
+            print "\tfailure\ninstall: error: cannot copy '$s' 'd'";
+            return 1;
+        }
+    }
+
+    print "success\n";
+    return 0;
+}
+
+sub copyjars {
+    my $s = $_{JARDIR};
+    my $d = $_{INST_JARDIR};
+
+    print "installing jar files to $d... ";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+
+    return $MAKING ? copybldjars($s, $d) : copydir($s, 0 => $d);
+}
+
+sub copybldjars {
+    my ($s, $d) = @_;
+    my $n = 'ngs-java.jar';
+    $s .= "/$n";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    my $nd = "$n.$_{VERSION}";
+    print "installing '$n'... ";
+
+    print "\t\tcd $d\n" if ($OPT{debug});
+    chdir $d or die "cannot cd $d";
+
+    $d .= "/$nd";
+
+    print "\n\t\t$s -> $d\n\t" if ($OPT{debug});
+
+    if ((! $OPT{force}) && (-e $d) && (-M $d < -M $s)) {
+        print "found\n";
+    } else {
+        unless (copy($s, $d)) {
+            print "failure\n";
+            print "install: error: cannot copy '$s' '$d'.\n";
+            return 1;
+        }
+        my $mode = 0644;
+        printf "\tchmod %o $d\n\t", $mode if ($OPT{debug});
+        unless (chmod($mode, $d)) {
+            print "failure\n";
+            print "install: error: cannot chmod '$d': $!\n";
+            return 1;
+        }
+        unless (symlinks($n, $nd, 'jar')) {
+            print "success\n";
+        } else {
+            print "failure\n";
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+sub copydocs {
+    my $s = "$_{JARDIR}/javadoc";
+    $s = expand_path("$Bin/../doc") unless ($MAKING);
+    my $d = "$_{INST_SHAREDIR}/doc";
+
+    print "installing html documents to $d... ";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+
+    print "\t\t$s -> $d\n\t" if ($OPT{debug});
+    unless (dircopy($s, $d)) {
+        print "\tfailure\ninstall: error: cannot copy '$s' to '$d'";
+        return 1;
+    }
+
+    print "success\n";
+    return 0;
+}
+
+sub copyexamples {
+    my $failures = 0;
+    my $CPRFComp = $File::Copy::Recursive::CPRFComp;
+    my $sd = $EXAMPLES_DIR;
+    return 0 unless (-e $sd);
+
+    my $d = $_{INST_SHAREDIR};
+    if ($HAVE{JAR}) {
+        $d .= '/examples-java';
+    } elsif ($HAVE{PYTHON}) {
+        $File::Copy::Recursive::CPRFComp = 0;
+        $d .= '/examples-python';
+    }
+
+    print "installing examples to $d... ";
+
+    my $s = $sd;
+    $s = "$sd/examples" if ($HAVE{JAR} && $MAKING);
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        ++$failures;
+    }
+
+    unless ($failures) {
+        print "\nchecking $d... ";
+        unless (-e $d) {
+            print "not found\n";
+            print "mkdir -p $d... ";
+            eval { make_path($d) };
+            if ($@) {
+                print "failure\ninstall: error: cannot mkdir $d\n";
+                ++$failures;
+            } else {
+                print "success\n";
+            }
+        } else {
+            print "exists\n";
+        }
+    }
+
+    unless ($failures) {
+        print "\t\t$s -> $d\n\t" if ($OPT{debug});
+        if ($HAVE{JAR} && ! $MAKING) {
+            if (copydir($s, 0 => $d)) {
+                ++$failures;
+            }
+        } else {
+            unless (dircopy($s, $d)) {
+                print "\tfailure\ninstall: error: cannot copy '$s' to '$d'";
+                ++$failures;
+            }
+        }
+    }
+
+    unless ($failures) {
+        if ($HAVE{JAR} && $MAKING) {
+            $sd = "$sd/Makefile";
+            $d = "$d/Makefile";
+            print "\t$sd -> $d\n\t" if ($OPT{debug});
+            unless (-e $sd) {
+                print "\tfailure\n";
+                print "install: error: '$sd' is not found.\n";
+                ++$failures;
+            }
+            unless ($failures) {
+                if (-e $d) {
+                unless (unlink $d) {
+                    print "failure\n";
+                    print "install: error: cannot rm '$d': $!\n";
+                    ++$failures;
+                }
+            }
+            unless ($failures) {
+                unless (copy($sd, $d)) {
+                    print "error: cannot copy '$sd' to '$d': $!\n";
+                    ++$failures;
+                }
+            }
+        }
+      }
+    }
+
+    print "success\n" unless ($failures);
+
+    $File::Copy::Recursive::CPRFComp = $CPRFComp;
+
+    return $failures;
+}
+
+sub finishinstall {
+    my $failures = 0;
+
+    $_{JAR_TARGET} = "$_{INST_JARDIR}/ngs-java.jar";
+
+    my @libs;
+    if (%INSTALLED_LIBS) {
+        my %libs;
+        ++$libs{$INSTALLED_LIBS{$_}} foreach (keys %INSTALLED_LIBS);
+        push @libs, $_ foreach (keys %libs);
+    } else {
+        push @libs, $_{LIB_TARGET};
+    }
+    my $libs;
+    foreach (@libs) {
+        $libs .= ":" if ($libs);
+        $libs .= $_;
+    }
+
+    if ($HAVE{PYTHON}) {
+        chdir "$Bin/.." or die "cannot cd '$Bin/..'";
+        my $cmd = "python setup.py install";
+        $cmd .= ' --user' unless (linux_root());
+        print `$cmd`;
+        if ($?) {
+            ++$failures;
+        } else {
+            unless ($libs) {
+                print "internal python failure\n";
+                ++$failures;
+            } elsif ($HAVE{LIBS}) {
+                print <<EndText;
+Please add $libs to your LD_LIBRARY_PATH, e.g.:
+      export LD_LIBRARY_PATH=$libs:\$LD_LIBRARY_PATH
+EndText
+            }
+        }
+    } elsif ($LINUX_ROOT) {
+        print "\t\tlinux root\n" if ($OPT{debug});
+
+        if ($HAVE{USR_INCLUDES}) {
+            unless (-e $oldincludedir) {
+                print "install: error: '$oldincludedir' does not exist\n";
+                ++$failures;
+            } else {
+                my $o = includes_out();
+                if ($o) {
+                    eval { INCLUDES_OUT(); };
+                    if (@_) {
+                        print "install: cannot find INCLUDES_OUT\n";
+                        ++$failures;
+                    } else {
+                        my $INCLUDE_SYMLINK
+                            = "$oldincludedir/" . INCLUDES_OUT();
+                        print "updating $INCLUDE_SYMLINK... ";
+                        unlink $INCLUDE_SYMLINK;
+                        if ($OPT{debug}) {
+                            print "\n\t\tln -s $o $INCLUDE_SYMLINK... ";
+                        }
+                        unless (symlink $o, $INCLUDE_SYMLINK) {
+                            print "failure\n";
+                            print "install: error: " .
+                                "cannot symlink '$o' '$INCLUDE_SYMLINK': $!\n";
+                            ++$failures;
+                        } else {
+                            print "success\n";
+                        }
+                    }
+                } else {
+                    my $INCLUDE_SYMLINK = "$oldincludedir/" . INCLUDES();
+                    print "updating $INCLUDE_SYMLINK... ";
+                    unlink $INCLUDE_SYMLINK;
+                    my $o = "$_{INST_INCDIR}/" . INCLUDES();
+                    unless (symlink $o, $INCLUDE_SYMLINK) {
+                        print "failure\n";
+                        print "install: error: "
+                            . "cannot symlink '$o' '$INCLUDE_SYMLINK': $!\n";
+                        ++$failures;
+                    } else {
+                        print "success\n";
+                    }
+                }
+            }
+        }
+
+        my $NAME = PACKAGE_NAME();
+        if ($HAVE{BINS} || $HAVE{JAR}
+            || ($HAVE{LIBS}
+                && ($HAVE{DLLS} || $NAME eq 'NGS-SDK' || $NAME eq 'NGS-BAM')
+               )
+            )
+        {
+            my $profile = "$ROOT/etc/profile.d";
+            my $PROFILE_FILE = "$profile/" . lc(PACKAGE_NAME());
+            unless (-e $profile) {
+                print "install: error: '$profile' does not exist\n";
+                ++$failures;
+            } else {
+                print "updating $PROFILE_FILE.[c]sh... ";
+
+                my $f = "$PROFILE_FILE.sh";
+                if (!open F, ">$f") {
+                    print "failure\n";
+                    print "install: error: cannot open '$f': $!\n";
+                    ++$failures;
+                } else {
+                    print F "#version $_{VERSION}\n\n";
+
+                    if ($HAVE{LIBS}) {
+                        unless (@libs) {
+                            print "internal root libraries failure\n";
+                            ++$failures;
+                        } else {
+                            if ($HAVE{DLLS}) {
+                                foreach (@libs) {
+                                    print F <<EndText;
+if ! echo \$LD_LIBRARY_PATH | /bin/grep -q $_
+then export LD_LIBRARY_PATH=$_:\$LD_LIBRARY_PATH
+fi
+
+EndText
+                                }
+                            }
+                            if ($NAME eq 'NGS-SDK') {
+                                print F "export NGS_LIBDIR=$_{LIB_TARGET}\n";
+                            } elsif ($NAME eq 'NGS-BAM') {
+                                print F
+                                      "\nexport NGS_BAM_LIBDIR=$_{LIB_TARGET}\n"
+                            }
+                        }
+                    }
+                    if ($HAVE{JAR}) {
+                        print F <<EndText;
+if ! echo \$CLASSPATH | /bin/grep -q $_{JAR_TARGET}
+then export CLASSPATH=$_{JAR_TARGET}:\$CLASSPATH
+fi
+EndText
+                    }
+                    if ($HAVE{BINS}) {
+                        print F <<EndText;
+if ! echo \$PATH | /bin/grep -q $_{INST_BINDIR}
+then export PATH=$_{INST_BINDIR}:\$PATH
+fi
+EndText
+                    }
+                    close F;
+                    unless (chmod(0644, $f)) {
+                        print "failure\n";
+                        print "install: error: cannot chmod '$f': $!\n";
+                        ++$failures;
+                    }
+                }
+            }
+
+            my $f = "$PROFILE_FILE.csh";
+            if (!open F, ">$f") {
+                print "failure\n";
+                print "install: error: cannot open '$f': $!\n";
+                ++$failures;
+            } else {
+                print F "#version $_{VERSION}\n\n";
+
+                if ($HAVE{LIBS}) {
+                    unless (@libs) {
+                        print "internal libraries failure\n";
+                        ++$failures;
+                    } else {
+                        if ($HAVE{DLLS}) {
+                            foreach (@libs) {
+                                print F <<EndText;
+echo \$LD_LIBRARY_PATH | /bin/grep -q $_
+if ( \$status ) setenv LD_LIBRARY_PATH $_:\$LD_LIBRARY_PATH
+
+EndText
+                            }
+                        }
+                    }
+                    if (PACKAGE_NAME() eq 'NGS-BAM') {
+                        print F "setenv NGS_BAM_LIBDIR $_{LIB_TARGET}\n";
+                    } elsif (PACKAGE_NAME() eq 'NGS-SDK') {
+                        print F "setenv NGS_LIBDIR $_{LIB_TARGET}\n";
+                    } elsif (PACKAGE_NAME() eq 'NCBI-VDB') {
+                        print F "setenv NCBI_VDB_LIBDIR $_{LIB_TARGET}\n";
+                    }
+                }
+                if ($HAVE{JAR}) {
+                    print F <<EndText;
+echo \$CLASSPATH | /bin/grep -q $_{JAR_TARGET}
+if ( \$status ) setenv CLASSPATH $_{JAR_TARGET}:\$CLASSPATH
+EndText
+                }
+                if ($HAVE{BINS}) {
+                    print F <<EndText;
+echo \$PATH | /bin/grep -q $_{INST_BINDIR}
+if ( \$status ) setenv PATH $_{INST_BINDIR}:\$PATH
+EndText
+                }
+                close F;
+                unless (chmod(0644, $f)) {
+                    print "failure\n";
+                    print "install: error: cannot chmod '$f': $!\n";
+                    ++$failures;
+                }
+            }
+#	@ #TODO: check version of the files above
+            print "success\n" unless ($failures);
+        }
+
+        unless ($failures) {
+            if ($HAVE{LIBS}) {
+                if (PACKAGE_NAME() eq 'NGS-BAM') {
+                    print "\n";
+                    print "Use \$NGS_BAM_LIBDIR in your link commands, e.g.:\n";
+                    print "      ld -L\$NGS_BAM_LIBDIR -lngs-bam ...\n";
+                } elsif (PACKAGE_NAME() eq 'NGS-SDK') {
+                    print "\nUse \$NGS_LIBDIR in your link commands, e.g.:\n";
+                    print "      ld -L\$NGS_LIBDIR -lngs-sdk ...\n";
+                } elsif (PACKAGE_NAME() eq 'NCBI-VDB') {
+                    print "\n"
+                       . "Use \$NCBI_VDB_LIBDIR in your link commands, e.g.:\n";
+                    print "      ld -L\$NCBI_VDB_LIBDIR -lncbi-vdb ...\n";
+                }
+            }
+        }
+    } else {
+        print "\t\tnot linux root\n" if ($OPT{debug});
+        if ($HAVE{LIBS}) {
+            unless ($libs) {
+                print "internal libraries failure\n";
+                ++$failures;
+            } else {
+                print "\n";
+                print <<EndText if ($HAVE{DLLS});
+Please add $libs to your LD_LIBRARY_PATH, e.g.:
+      export LD_LIBRARY_PATH=$libs:\$LD_LIBRARY_PATH
+EndText
+                if (PACKAGE_NAME() eq 'NGS-SDK') {
+                    print "Use $libs in your link commands, e.g.:\n"
+                        . "export NGS_LIBDIR=$libs\n"
+                        . "ld -L\$NGS_LIBDIR -lngs-sdk ...\n";
+                } elsif (PACKAGE_NAME() eq 'NGS-BAM') {
+                    print "Use $libs in your link commands, e.g.:\n"
+                        . "export NGS_BAM_LIBDIR=$libs\n"
+                        . "ld -L\$NGS_BAM_LIBDIR -lngs-bam ...\n";
+                }
+            }
+        }
+        if ($HAVE{JAR}) {
+            print <<EndText;
+
+Please add $_{JAR_TARGET} to your CLASSPATH, i.e.:
+      export CLASSPATH=$_{JAR_TARGET}:\$CLASSPATH
+EndText
+        }
+    }
+
+    return $failures;
+}
+
+sub expand_path {
+    my ($filename) = @_;
+    return unless ($filename);
+
+    if ($filename =~ /^~/) {
+        if ($filename =~ m|^~([^/]*)|) {
+            if ($1 && ! getpwnam($1)) {
+                print "install: error: bad path: '$filename'\n";
+                exit 1;
+            }
+        }
+
+        $filename =~ s{ ^ ~ ( [^/]* ) }
+                      { $1
+                            ? (getpwnam($1))[7]
+                            : ( $ENV{HOME} || $ENV{USERPROFILE} || $ENV{LOGDIR}
+                                || (getpwuid($<))[7]
+                              )
+                      }ex;
+    }
+
+    my $a = abs_path($filename);
+    $filename = $a if ($a);
+
+    $filename;
+}
+
+sub help {
+    $_{LIB_TARGET} = "$_{INST_LIBDIR}$_{BITS}";
+
+    print <<EndText;
+'install' installs $_{PACKAGE_NAME} $_{VERSION} package.
+
+Usage: ./install [OPTION]...
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+  -n, --no-create         do not run installation
+
+EndText
+
+    if ($HAVE{TWO_LIBS}) {
+        my $p = lc(PACKAGE_NAME());
+        print "By default, `./install' will install all the files in\n";
+        print "`/usr/local/ngs/$p/jar', " if ($HAVE{JAR});
+        print <<EndText;
+`/usr/local/ngs/$p/share',
+`/usr/local/ngs/ngs-sdk/lib$_{BITS}', `/usr/local/ncbi/ncbi-vdb/lib$_{BITS}'.
+You can spefify other installation directories using the options below.
+
+Fine tuning of the installation directories:
+EndText
+        if ($HAVE{JAR}) {
+            print
+                "  --jardir=DIR         jar files [/usr/local/ngs/$p/jar]\n"
+        }
+        print <<EndText;
+  --ngslibdir=DIR      ngs-sdk libraries [/usr/local/ngs/ngs-sdk/lib$_{BITS}]
+  --vdblibdir=DIR      ncbi-vdb libraries [/usr/local/ncbi/ncbi-vdb/lib$_{BITS}]
+  --examplesdir=DIR    example files [/usr/local/ngs/$p/share]
+
+  --libdir=DIR         install all libraries in the same directory
+  --prefix=DIR         install files in PREFIX/lib$_{BITS}, PREFIX/share etc.
+EndText
+    } else {
+        print <<EndText;
+Installation directories:
+  --prefix=PREFIX         install all files in PREFIX
+                          [$_{PREFIX}]
+
+By default, `./install' will install all the files in
+EndText
+
+        if ($HAVE{INCLUDES}) {
+            print
+"`$_{PREFIX}/include', `$_{PREFIX}/lib$_{BITS}' etc.  You can specify\n"
+        } elsif ($HAVE{JAR}) {
+            print "`$_{PREFIX}/jar', `$_{PREFIX}/share' etc.  You can specify\n"
+        } elsif ($MAKING) {
+            print "`$_{PREFIX}/share' etc.  You can specify\n"
+        } else {
+            print
+"`$_{PREFIX}/lib$_{BITS}' `$_{PREFIX}/share' etc.  You can specify\n"
+        }
+
+        print <<EndText;
+an installation prefix other than `$_{PREFIX}' using `--prefix',
+for instance `--prefix=$_{OTHER_PREFIX}'.
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+EndText
+
+        if ($HAVE{BINS}) {
+            print "  --bindir=DIR            executables [PREFIX/bin]\n";
+        }
+        if ($HAVE{JAR}) {
+            print "  --jardir=DIR            jar files [PREFIX/jar]\n";
+        }
+        if ($HAVE{LIBS}) {
+            print
+"  --libdir=DIR            object code libraries [PREFIX/lib$_{BITS}]\n"
+        }
+        if ($HAVE{INCLUDES}) {
+            print "  --includedir=DIR        C header files [PREFIX/include]\n";
+        }
+        if ($HAVE{USR_INCLUDES}) {
+            print
+"  --oldincludedir=DIR     C header files for non-gcc [$oldincludedir]\n"
+        }
+
+        if (-e $EXAMPLES_DIR) {
+            print "  --examplesdir=DIR       example files [PREFIX/share]\n";
+        }
+    }
+
+    if ($HAVE{LIBS}) {
+        print <<EndText;
+
+System types:
+  --bits=[32|64]          use a 32- or 64-bit data model
+EndText
+    }
+
+    print "\nReport bugs to sra-tools\@ncbi.nlm.nih.gov\n";
+}
+
+sub prepare {
+    if ($MAKING) {
+        my $os_arch = `perl -w $Bin/os-arch.perl`;
+        unless ($os_arch) {
+            print "install: error\n";
+            exit 1;
+        }
+        chomp $os_arch;
+        my $config =
+            "$Bin/../" . CONFIG_OUT() . "/Makefile.config.install.$os_arch.prl";
+        fatal_config("$config not found") unless (-e "$config");
+
+        eval { require $config; };
+        fatal_config($@) if ($@);
+    } else {
+        my $a = $Config{archname64};
+        $_ = lc PACKAGE_NAME();
+        my $root = '';
+        $root = $OPT{root} if ($OPT{root});
+        my $code = 
+            'sub CONFIGURE { ' .
+            '   $_{OS           } = $OS; ' .
+            '   $_{VERSION      } = "1.0.0"; ' .
+            '   $_{MAJVERS      } = "1"; ' .
+            '   $_{LPFX         } = "lib"; ' .
+            '   $_{LIBX         } = "a"; ' .
+            '   $_{MAJVERS_LIBX } = "a.1"; ' .
+            '   $_{VERSION_LIBX } = "a.1.0.0"; ' .
+            '   $_{SHLX         } = "so"; ' .
+            '   $_{OTHER_PREFIX } = \'$HOME/ngs/' . $_ . '\'; ' .
+            '   $_{PREFIX       } = "' . "$root/usr/local/ngs/$_" . '"; ' .
+            '   $_{INST_INCDIR  } = "$_{PREFIX}/include"; ' .
+            '   $_{INST_LIBDIR  } = "$_{PREFIX}/lib"; ' .
+            '   $_{INST_JARDIR  } = "$_{PREFIX}/jar"; ' .
+            '   $_{INST_SHAREDIR} = "$_{PREFIX}/share"; ' .
+            '   $_{INCDIR       } = "$Bin/../include"; ' .
+            '   $_{LIBDIR64     } = "$Bin/../lib64"; ' .
+            '   $_{LIBDIR32     } = "$Bin/../lib32"; ';
+        if ($HAVE{TWO_LIBS}) {
+            $code .=
+               '$_{INST_NGSLIBDIR} = "' . "$root/usr/local/ngs/ngs-sdk/lib\";"
+             . '$_{INST_VDBLIBDIR} = "' . "$root/usr/local/ncbi/ncbi-vdb/lib\";"
+        }
+        $code .= ' $_{PACKAGE_NAME} = "' . PACKAGE_NAME() . '"; ';
+
+        if (defined $Config{archname64}) {
+            $code .= ' $_{BITS} = 64; ';
+        } else {
+            $code .= ' $_{BITS} = 32; ';
+        }
+
+        $code .= 
+            '   $_{MAJVERS_SHLX } = "so.1"; ' .
+            '   $_{VERSION_SHLX } = "so.1.0.0"; ' ;
+
+        $code .= 
+            '   @_ ' .
+            '}';
+
+        eval $code;
+
+        die $@ if ($@);
+    }
+}
+
+sub linux_root { $^O eq 'linux' && `id -u` == 0 }
+
+sub fatal_config {
+    if ($OPT{debug}) {
+        print "\t\t";
+        print "@_";
+        print "\n";
+    }
+
+    print "install: error: run ./configure [OPTIONS] first.\n";
+
+    exit 1;
+}
+
+################################################################################
diff --git a/ngs-java/setup/install.prl b/ngs-java/setup/install.prl
new file mode 100644
index 0000000..4bd227e
--- /dev/null
+++ b/ngs-java/setup/install.prl
@@ -0,0 +1,4 @@
+sub PACKAGE_NAME { 'NGS-JAVA' }
+sub HAVE        { ( DLLS => 1, EXAMPLES => 1, JAR => 1, ) }
+sub CONFIG_OUT  {  '.' }
+1
diff --git a/ngs-python/konfigure.perl b/ngs-java/setup/konfigure.perl
similarity index 60%
rename from ngs-python/konfigure.perl
rename to ngs-java/setup/konfigure.perl
index 2a7fde7..7b7780e 100644
--- a/ngs-python/konfigure.perl
+++ b/ngs-java/setup/konfigure.perl
@@ -32,65 +32,117 @@ if ($directories ne "./") {
     exit 1;
 }
 
-require 'package.pm';
-require 'os-arch.pm';
+require 'package.prl';
+require 'os-arch.prl';
 
-use Cwd qw (abs_path getcwd);
+use Cwd qw(abs_path getcwd);
 use File::Basename 'fileparse';
 use File::Spec 'catdir';
 use FindBin qw($Bin);
-use Getopt::Long 'GetOptions';
+use Getopt::Long "GetOptions";
+
+chdir '..' or die "cannot cd to package root";
 
 check();
 
+my $LOCAL_BUILD_OUT
+    = -e File::Spec->catdir($ENV{HOME}, 'tmp', 'local-build-out');
+
+my ($CONFIGURED, $RECONFIGURE) = ('');
+if (@ARGV) {
+    foreach (@ARGV) {
+        $CONFIGURED .= "\t" if ($CONFIGURED);
+        $CONFIGURED .= "'$_'";
+    }
+} elsif (-f 'reconfigure') {
+    ++$RECONFIGURE unless ($LOCAL_BUILD_OUT);
+}
+
 my %PKG = PKG();
 
 my $PACKAGE_NAME = PACKAGE_NAME();
 my $OUT_MAKEFILE = 'Makefile.config';
+my $INS_MAKEFILE = 'Makefile.config.install';
 
 my $PACKAGE = PACKAGE();
 
 my $HOME = $ENV{HOME} || $ENV{USERPROFILE}
     || $ENV{LOGDIR} || getcwd || (getpwuid($<))[7] || abs_path('.');
 
-$PKG{UPATH} =~ s/(\$\w+)/$1/eeg;
-
-my $OUTDIR = File::Spec->catdir($HOME, $PKG{OUT});
+$PKG{UPATH} = expand($PKG{UPATH});
 
 my $package_default_prefix = $PKG{PATH};
 my $schema_default_dir = $PKG{SCHEMA_PATH} if ($PKG{SCHEMA_PATH});
 
 my @REQ = REQ();
 
-my @options = ( "arch=s",
-                "build=s",
-                "clean",
-                "debug",
-                "help",
-#               "output-makefile=s",
-                "prefix=s",
-                "status",
-                "with-debug",
-                "without-debug" );
+my @options = ( 'build-prefix=s',
+                'clean',
+                'debug',
+                'help',
+                'prefix=s',
+                'reconfigure',
+                'status',
+                'with-debug',
+                'without-debug', );
+{
+    my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
+    push @options, 'arch=s'    if (@ARCHITECTURES);
+}
+push @options, 'enable-static' if (PACKAGE_TYPE() eq 'B');
 foreach my $href (@REQ) {
     my %a = %$href;
     push @options, "$a{option}=s";
     push @options, "$a{boption}=s" if ($a{boption});
-    $href->{usrpath} =~ s/(\$\w+)/$1/eeg;
+    $href->{usrpath} = '' unless ($href->{usrpath});
+    $href->{usrpath} = expand($href->{usrpath});
 }
 push @options, "shemadir" if ($PKG{SCHEMA_PATH});
 
 my %OPT;
 die "configure: error" unless (GetOptions(\%OPT, @options));
+++$OPT{'reconfigure'} if ($RECONFIGURE);
+
+if ($OPT{'reconfigure'}) {
+    unless (eval 'use Getopt::Long qw(GetOptionsFromString); 1') {
+        print <<EndText;
+configure: error: your perl does not support Getopt::Long::GetOptionsFromString
+                  reconfigure option is not avaliable.
+Run "sh ./reconfigure" instead.
+EndText
+        exit 1;
+    }
+    println "reconfiguring...";
+    open F, 'reconfigure' or die 'cannot open reconfigure';
+    $_ = <F>;
+    chomp;
+    unless (m|^\./configure\s*(.*)$|) {
+        println 'configure: error: cannot reconfigure';
+        println 'run "./configure --clean" then run "./configure [OPTIONS]"';
+        exit 1;
+    }
+
+    println "running \"./configure $1\"...";
+    undef %OPT;
+    die "configure: error" unless (GetOptionsFromString($1, \%OPT, @options));
+    ++$OPT{reconfigure};
+}
+
+$OPT{'local-build-out'} = $LOCAL_BUILD_OUT;
+my $OUTDIR = File::Spec->catdir($HOME, $PKG{OUT});
+if ($OPT{'local-build-out'}) {
+    my $o = expand_path(File::Spec->catdir($Bin, $PKG{LOCOUT}));
+    $OUTDIR = $o if ($o);
+}
 
 if ($OPT{'help'}) {
     help();
-    exit(0);
+    exit 0;
 } elsif ($OPT{'clean'}) {
     {
-        foreach (glob(CONFIG_OUT() . '/Makefile.config*'),
-            File::Spec->catdir(CONFIG_OUT(), 'user.status'),
-            File::Spec->catdir(CONFIG_OUT(), 'Makefile.userconfig'))
+        foreach ('reconfigure', glob(CONFIG_OUT() . '/Makefile.config*'),
+            File::Spec->catdir(CONFIG_OUT(), 'Makefile.userconfig'),
+            File::Spec->catdir(CONFIG_OUT(), 'user.status'))
         {
             my $f = $_;
             print "removing $f... ";
@@ -122,11 +174,14 @@ if ($OPT{'help'}) {
             }
         }
     }
-    exit(0);
+    exit 0;
 } elsif ($OPT{'status'}) {
     status(1);
-    exit(0);
+    exit 0;
 }
+
+println "Configuring $PACKAGE_NAME package";
+
 $OPT{'prefix'} = $package_default_prefix unless ($OPT{'prefix'});
 
 my $AUTORUN = $OPT{status};
@@ -134,34 +189,52 @@ print "checking system type... " unless ($AUTORUN);
 my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
 println $OSTYPE unless ($AUTORUN);
 
+unless ($OSTYPE =~ /linux/i || $OSTYPE =~ /darwin/i || $OSTYPE eq 'win') {
+    println "configure: error: unsupported system '$OSTYPE'";
+    exit 1;
+}
+
+print "checking machine architecture... " unless ($AUTORUN);
+println $MARCH unless ($AUTORUN);
+unless ($MARCH =~ /x86_64/i || $MARCH =~ /i?86/i) {
+    println "configure: error: unsupported architecture '$OSTYPE'";
+    exit 1;
+}
+
 {
-    $OPT{'prefix'} = expand($OPT{'prefix'});
+    $OPT{'prefix'} = expand_path($OPT{'prefix'});
     my $prefix = $OPT{'prefix'};
-    $OPT{eprefix} = $prefix unless ($OPT{eprefix} || $OS eq 'win');
-    my $eprefix = $OPT{eprefix};
-    unless ($OPT{bindir} || $OS eq 'win') {
-        $OPT{bindir} = File::Spec->catdir($eprefix, 'bin') ;
+    $OPT{'eprefix'} = $prefix unless ($OPT{'eprefix'} || $OS eq 'win');
+    my $eprefix = $OPT{'eprefix'};
+    unless ($OPT{'bindir'} || $OS eq 'win') {
+        $OPT{'bindir'} = File::Spec->catdir($eprefix, 'bin') ;
     }
-    unless ($OPT{libdir} || $OS eq 'win') {
-        $OPT{libdir} = File::Spec->catdir($eprefix, 'lib');
+    unless ($OPT{'libdir'} || $OS eq 'win') {
+        $OPT{'libdir'} = File::Spec->catdir($eprefix, 'lib');
     }
-    unless ($OPT{includedir} || $OS eq 'win') {
-        $OPT{includedir} = File::Spec->catdir($eprefix, 'include');
+    unless ($OPT{'includedir'} || $OS eq 'win') {
+        $OPT{'includedir'} = File::Spec->catdir($eprefix, 'include');
     }
-    if ($PKG{LNG} eq 'PYTHON' && ! $OPT{pythondir} && $OS ne 'win') {
-        $OPT{pythondir} = $eprefix;
+    if ($PKG{LNG} eq 'PYTHON' && ! $OPT{'pythondir'} && $OS ne 'win') {
+        $OPT{'pythondir'} = $eprefix;
     }
-    if ($PKG{LNG} eq 'JAVA' && ! $OPT{javadir} && $OS ne 'win') {
-        $OPT{javadir} = File::Spec->catdir($eprefix, 'jar');
+    if ($PKG{LNG} eq 'JAVA' && ! $OPT{'javadir'} && $OS ne 'win') {
+        $OPT{'javadir'} = File::Spec->catdir($eprefix, 'jar');
     }
-    if ($PKG{EXAMP} && ! $OPT{sharedir} && $OS ne 'win') {
-        $OPT{sharedir} = File::Spec->catdir($eprefix, 'share');
+    if ($PKG{EXAMP} && ! $OPT{'sharedir'} && $OS ne 'win') {
+        $OPT{'sharedir'} = File::Spec->catdir($eprefix, 'share');
     }
 }
 
 # initial values
 my $TARGDIR = File::Spec->catdir($OUTDIR, $PACKAGE);
-$TARGDIR = expand($OPT{'build'}) if ($OPT{'build'});
+if ($OPT{'build-prefix'}) {
+    $TARGDIR = $OPT{'build-prefix'} = expand_path($OPT{'build-prefix'});
+    unless ($TARGDIR =~ /$PACKAGE$/) {
+        $TARGDIR = File::Spec->catdir($TARGDIR, $PACKAGE);
+    }
+}
+my $BUILD_PREFIX = $TARGDIR;
 
 my $BUILD = 'rel';
 
@@ -195,14 +268,8 @@ if ($OPT{arch}) {
     }
 }
 
-$OUT_MAKEFILE .= ".$OS.$ARCH";
-$OUT_MAKEFILE = File::Spec->catdir(CONFIG_OUT(), $OUT_MAKEFILE);
-
-#my $OSTYPE = `uname -s`; chomp $OSTYPE;
-
-print "checking machine architecture... " unless ($AUTORUN);
-#my $MARCH = `uname -m`; chomp $MARCH;
-println $MARCH unless ($AUTORUN);
+$OUT_MAKEFILE = File::Spec->catdir(CONFIG_OUT(), "$OUT_MAKEFILE.$OS.$ARCH");
+$INS_MAKEFILE = File::Spec->catdir(CONFIG_OUT(), "$INS_MAKEFILE.$OS.$ARCH.prl");
 
 my $TOOLS = "";
 $TOOLS = "jdk" if ($PKG{LNG} eq 'JAVA');
@@ -217,17 +284,12 @@ print "checking for supported architecture... " unless ($AUTORUN);
 
 my $BITS;
 
-if ( $MARCH =~ m/x86_64/i )
-{
+if ($MARCH =~ /x86_64/i) {
     $BITS = 64;
-}
-elsif ( $MARCH =~ m/i?86/i )
-{
+} elsif ($MARCH =~ /i?86/i) {
     $BITS = 32;
-}
-else
-{
-    die "unrecognized Architecture - " . $ARCH;
+} else {
+    die "unrecognized Architecture '$ARCH'";
 }
 println "$MARCH ($BITS bits) is supported" unless ($AUTORUN);
 
@@ -235,105 +297,111 @@ println "$MARCH ($BITS bits) is supported" unless ($AUTORUN);
 my ($LPFX, $OBJX, $LOBX, $LIBX, $SHLX, $EXEX, $OSINC);
 
 print "checking for supported OS... " unless ($AUTORUN);
-if ( $OSTYPE =~ m/linux/i )
-{
-    $LPFX = "lib";
-    $OBJX = "o";
-    $LOBX = "pic.o";
-    $LIBX = "a";
-    $SHLX = "so";
-    $EXEX = "";
-    $OSINC = "unix";
-    if ( $TOOLS eq "" )
-    {
-        $TOOLS = "gcc";
-    }
-}
-elsif ( $OSTYPE =~ m/darwin/i )
-{
-    $LPFX = "lib";
-    $OBJX = "o";
-    $LOBX = "pic.o";
-    $LIBX = "a";
-    $SHLX = "dylib";
-    $EXEX = "";
-    $OSINC = "unix";
-    if ( $TOOLS eq "" )
-    {
-        $TOOLS = "clang";
-    }
+if ($OSTYPE =~ /linux/i) {
+    $LPFX = 'lib';
+    $OBJX = 'o';
+    $LOBX = 'pic.o';
+    $LIBX = 'a';
+    $SHLX = 'so';
+    $EXEX = '';
+    $OSINC = 'unix';
+    $TOOLS = 'gcc' unless ($TOOLS);
+} elsif ($OSTYPE =~ /darwin/i) {
+    $LPFX = 'lib';
+    $OBJX = 'o';
+    $LOBX = 'pic.o';
+    $LIBX = 'a';
+    $SHLX = 'dylib';
+    $EXEX = '';
+    $OSINC = 'unix';
+    $TOOLS = 'clang' unless ($TOOLS);
 } elsif ($OSTYPE eq 'win') {
-    $TOOLS = "vc++";
-} else
-{
-    die "unrecognized OS - " . $OSTYPE;
+    $TOOLS = 'vc++';
+} else {
+    die "unrecognized OS '$OSTYPE'";
 }
 println "$OSTYPE ($OS) is supported" unless ($AUTORUN);
 
 # tool chain
-my ($CC, $CP, $AR, $ARX, $ARLS, $LD, $LP);
+my ($CPP, $CC, $CP, $AR, $ARX, $ARLS, $LD, $LP);
 my ($JAVAC, $JAVAH, $JAR);
 my ($DBG, $OPT, $PIC, $INC, $MD);
 
 print "checking for supported tool chain... " unless ($AUTORUN);
-if ( $TOOLS =~ m/gcc/i )
-{
-    $CC = "gcc -c";
-    $CP = "g++ -c";
-    $AR = "ar rc";
-    $ARX = "ar x";
-    $ARLS = "ar t";
-    $LD = "gcc";
-    $LP = "g++";
-
-    $DBG = "-g -DDEBUG";
-    $OPT = "-O3";
-    $PIC = "-fPIC";
-    $INC = "-I";
-    $MD  = "-MD";
-}
-elsif ( $TOOLS =~ m/clang/i )
-{
-    $CC = "clang -c";
-    $CP = "clang++ -c";
-    $AR = "ar rc";
-    $ARX = "ar x";
-    $ARLS = "ar t";
-    $LD = "clang";
-    $LP = "clang++";
-
-    $DBG = "-g -DDEBUG";
-    $OPT = "-O3";
-    $PIC = "-fPIC";
-    $INC = "-I";
-    $MD  = "-MD";
-}
-elsif ( $TOOLS =~ m/jdk/i )
-{
-    $JAVAC = "javac";
-    $JAVAH = "javah";
-    $JAR   = "jar cf";
-
-    $DBG = "-g";
+if ($TOOLS eq 'gcc') {
+    $CPP  = 'g++';
+    $CC   = 'gcc -c';
+    $CP   = "$CPP -c";
+    $AR   = 'ar rc';
+    $ARX  = 'ar x';
+    $ARLS = 'ar t';
+    $LD   = 'gcc';
+    $LP   = $CPP;
+
+    $DBG = '-g -DDEBUG';
+    $OPT = '-O3';
+    $PIC = '-fPIC';
+    $INC = '-I';
+    $MD  = '-MD';
+} elsif ($TOOLS eq 'clang') {
+    $CPP  = 'clang++';
+    $CC   = 'clang -c';
+    $CP   = "$CPP -c -mmacosx-version-min=10.6";
+    $AR   = 'ar rc';
+    $ARX  = 'ar x';
+    $ARLS = 'ar t';
+    $LD   = 'clang';
+    $LP   = "$CPP -mmacosx-version-min=10.6";
+
+    $DBG = '-g -DDEBUG';
+    $OPT = '-O3';
+    $PIC = '-fPIC';
+    $INC = '-I';
+    $MD  = '-MD';
+} elsif ($TOOLS eq 'jdk') {
+    $JAVAC = 'javac';
+    $JAVAH = 'javah';
+    $JAR   = 'jar cf';
+
+    $DBG = '-g';
 } elsif ($TOOLS eq 'vc++') {
-} else
-{
-    die "unrecognized tool chain - " . $TOOLS;
+} else {
+    die "unrecognized tool chain '$TOOLS'";
 }
 println "$TOOLS tool chain is supported" unless ($AUTORUN);
 
-if ($OS ne 'win') {
+if ($OS ne 'win' && $PKG{LNG} ne 'JAVA') {
     $TARGDIR = File::Spec->catdir($TARGDIR, $OS, $TOOLS, $ARCH, $BUILD);
 }
 
+if ($CPP) {
+    unless (check_tool($CPP)) {
+        println "configure: error: '$CPP' cannot be found";
+        exit 1;
+    }
+}
+
+my $NO_ARRAY_BOUNDS_WARNING = '';
+if ($TOOLS eq 'gcc' && check_no_array_bounds()) {
+    $NO_ARRAY_BOUNDS_WARNING = '-Wno-array-bounds';
+}
+
 my @dependencies;
 
+my %DEPEND_OPTIONS;
 foreach my $href (DEPENDS()) {
     $_ = $href->{name};
     my ($I, $L) = ($href->{Include});
-    if ($OPT{"with-$_-prefix"}) {
-        $I = File::Spec->catdir($OPT{"with-$_-prefix"}, 'include'); 
-        $L = File::Spec->catdir($OPT{"with-$_-prefix"}, 'lib'); 
+    my $o = "with-$_-prefix";
+    ++$DEPEND_OPTIONS{$o};
+    if ($OPT{$o}) {
+        $OPT{$o} = expand_path($OPT{$o});
+        $I = File::Spec->catdir($OPT{$o}, 'include');
+        if (/^xml2$/) {
+            my $t = File::Spec->catdir($I, 'libxml2');
+            $I = $t if (-e $t);
+        }
+        $L = File::Spec->catdir($OPT{$o}, 'lib');
     }
     my ($i, $l) = find_lib($_, $I, $L);
     if (defined $i || $l) {
@@ -354,16 +422,21 @@ foreach my $href (DEPENDS()) {
 }
 
 foreach my $href (@REQ) {
-    $href->{bldpath} =~ s/(\$\w+)/$1/eeg if ($href->{bldpath});
+    $href->{   bldpath} = expand($href->{   bldpath}) if ($href->{   bldpath});
+    $href->{locbldpath} = expand($href->{locbldpath}) if ($href->{locbldpath});
     my ($found_itf, $found_lib, $found_ilib);        # found directories
     my %a = %$href;
+    next if ($a{option} && $DEPEND_OPTIONS{$a{option}});
     my $is_optional = optional($a{type});
+    my $quasi_optional = $a{type} =~ /Q/;
     my $need_source = $a{type} =~ /S/;
     my $need_build = $a{type} =~ /B/;
-    my $need_lib = $a{type} =~ /L/;
+    my $need_lib = $a{type} =~ /L|D/;
+    my $need_itf = ! ($a{type} =~ /D/);
     
     my ($inc, $lib, $ilib) = ($a{include}, $a{lib}); # file names to check
-    $lib =~ s/(\$\w+)/$1/eeg;
+    $lib = '' unless ($lib);
+    $lib = expand($lib);
 
     if ($need_build) {
         $ilib = $a{ilib};
@@ -383,7 +456,7 @@ foreach my $href (@REQ) {
     foreach my $option ($a{option}, $a{boption}) {
         next unless ($option);
         if ($OPT{$option}) {
-            my $try = expand($OPT{$option});
+            my $try = expand_path($OPT{$option});
             my ($i, $l, $il) = ($inc, $lib, $ilib);
             if ($option =~ /-build$/) {
                 undef $i;
@@ -397,9 +470,18 @@ foreach my $href (@REQ) {
                 ++$has_option{sources};
             }
             my ($fi, $fl, $fil) = find_in_dir($try, $i, $l, $il);
-            $found_itf  = $fi  if (! $found_itf  && $fi);
-            $found_lib  = $fl  if (! $found_lib  && $fl);
-            $found_ilib = $fil if (! $found_ilib && $fil);
+            if ($fi || $fl || $fil) {
+                $found_itf  = $fi  if (! $found_itf  && $fi);
+                $found_lib  = $fl  if (! $found_lib  && $fl);
+                $found_ilib = $fil if (! $found_ilib && $fil);
+            }
+            elsif (! ($try =~ /$a{name}$/)) {
+                $try = File::Spec->catdir($try, $a{name});
+                ($fi, $fl, $fil) = find_in_dir($try, $i, $l, $il);
+                $found_itf  = $fi  if (! $found_itf  && $fi);
+                $found_lib  = $fl  if (! $found_lib  && $fl);
+                $found_ilib = $fil if (! $found_ilib && $fil);
+            }
         }
     }
     if (! $found_itf && ! $has_option{sources} && $a{srcpath}) {
@@ -423,16 +505,39 @@ foreach my $href (@REQ) {
     }
     if (! $has_option{build}) {
         if (($need_build || ($need_lib && ! $found_lib)) && $a{bldpath}) {
-            my $try = $a{bldpath};
-            my (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
-            $found_lib  = $fl  if (! $found_lib  && $fl);
-            $found_ilib = $fil if (! $found_ilib && $fil);
+            my ($fl, $fil);
+            if ($OPT{'build-prefix'}) {
+                my $try = $OPT{'build-prefix'};
+                (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
+                if ($fl || $fil) {
+                    $found_lib  = $fl  if (! $found_lib  && $fl);
+                    $found_ilib = $fil if (! $found_ilib && $fil);
+                } elsif (! ($try =~ /$a{name}$/)) {
+                    $try = File::Spec->catdir($try, $a{name});
+                    (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
+                    if ($fl || $fil) {
+                        $found_lib  = $fl  if (! $found_lib  && $fl);
+                        $found_ilib = $fil if (! $found_ilib && $fil);
+                    }
+                }
+            }
+            unless ($fl || $fil) {
+                my $try = $a{bldpath};
+                $try = $a{locbldpath} if ($OPT{'local-build-out'});
+                (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
+                $found_lib  = $fl  if (! $found_lib  && $fl);
+                $found_ilib = $fil if (! $found_ilib && $fil);
+            }
         }
     }
-    if (! $found_itf || ($need_lib && ! $found_lib) || ($ilib && ! $found_ilib))
+    if (($need_itf && ! $found_itf) ||
+        ($need_lib && ! $found_lib) || ($ilib && ! $found_ilib))
     {
         if ($is_optional) {
             println "configure: optional $a{name} package not found: skipped.";
+        } elsif ($quasi_optional && $found_itf && ($need_lib && ! $found_lib)) {
+            println "configure: $a{name} package: "
+                . "found interface files but not libraries.";
         } else {
             if ($OPT{'debug'}) {
                 $_ = "$a{name}: includes: ";
@@ -456,20 +561,42 @@ foreach my $href (@REQ) {
             exit 1;
         }
     } else {
-        $found_itf = abs_path($found_itf);
-        push(@dependencies, "$a{namew}_INCDIR = $found_itf");
+        if ($found_itf) {
+            $found_itf = abs_path($found_itf);
+            push(@dependencies, "$a{aname}_INCDIR = $found_itf");
+        }
         if ($found_lib) {
             $found_lib = abs_path($found_lib);
-            push(@dependencies, "$a{namew}_LIBDIR = $found_lib");
+            if ($a{aname} eq 'NGS' || $a{aname} eq 'VDB') {
+                if ($OPT{PYTHON_LIB_PATH}) {
+                    $OPT{PYTHON_LIB_PATH} .= ':';
+                } else {
+                    $OPT{PYTHON_LIB_PATH} = '';
+                }
+                $OPT{PYTHON_LIB_PATH} .= $found_lib;
+            }
+            push(@dependencies, "$a{aname}_LIBDIR = $found_lib");
         }
         if ($ilib && $found_ilib) {
             $found_ilib = abs_path($found_ilib);
-            push(@dependencies, "$a{namew}_ILIBDIR = $found_ilib");
+            push(@dependencies, "$a{aname}_ILIBDIR = $found_ilib");
         }
     }
 }
 
+my ($E_BINDIR, $E_LIBDIR, $VERSION, $MAJVERS, $E_VERSION_LIBX, $E_MAJVERS_LIBX,
+                                              $E_VERSION_EXEX, $E_MAJVERS_EXEX)
+    = (''    , '');
+
 if ($OS ne 'win' && ! $OPT{'status'}) {
+    if ($OSTYPE =~ /darwin/i && CONFIG_OUT() ne '.') {
+        my $COMP = File::Spec->catdir(CONFIG_OUT(), 'COMP.mac');
+        println "configure: creating '$COMP' ($TOOLS)" unless ($AUTORUN);
+        open F, ">$COMP" or die "cannot open $COMP to write";
+        print F "$TOOLS\n";
+        close F;
+    }
+
     # create Makefile.config
     println "configure: creating '$OUT_MAKEFILE'" unless ($AUTORUN);
     open my $F, ">$OUT_MAKEFILE" or die "cannot open $OUT_MAKEFILE to write";
@@ -477,34 +604,53 @@ if ($OS ne 'win' && ! $OPT{'status'}) {
     print $F <<EndText;
 ### AUTO-GENERATED FILE ###
 
-OS_ARCH = \$(shell perl \$(TOP)/os-arch.perl)
+# configuration command
+
+CONFIGURED = $CONFIGURED
+
+OS_ARCH = \$(shell perl \$(TOP)/setup/os-arch.perl)
 
 # install paths
 EndText
 
-    L($F, "INST_BINDIR = $OPT{bindir}"        ) if ($OPT{bindir});
-    L($F, "INST_LIBDIR = $OPT{libdir}"        ) if ($OPT{libdir});
-    L($F, "INST_INCDIR = $OPT{includedir}"    ) if ($OPT{includedir});
+    L($F, "INST_BINDIR = $OPT{'bindir'}"      ) if ($OPT{'bindir'});
+    L($F, "INST_LIBDIR = $OPT{'libdir'}"      ) if ($OPT{'libdir'});
+    L($F, "INST_INCDIR = $OPT{'includedir'}"  ) if ($OPT{'includedir'});
     L($F, "INST_SCHEMADIR = $OPT{'shemadir'}" ) if ($OPT{'shemadir'});
     L($F, "INST_SHAREDIR = $OPT{'sharedir'}"  ) if ($OPT{'sharedir'});
     L($F, "INST_JARDIR = $OPT{'javadir'}"     ) if ($OPT{'javadir'});
     L($F, "INST_PYTHONDIR = $OPT{'pythondir'}") if ($OPT{'pythondir'});
 
-    my ($VERSION_SHLX, $MAJMIN_SHLX, $MAJVERS_SHLX);
+    my ($E_VERSION_SHLX, $VERSION_SHLX,
+        $E_MAJVERS_SHLX , $MAJMIN_SHLX, $MAJVERS_SHLX);
     if ($OSTYPE =~ /darwin/i) {
+        $E_VERSION_SHLX =  '$VERSION.$SHLX';
         $VERSION_SHLX = '$(VERSION).$(SHLX)';
         $MAJMIN_SHLX  = '$(MAJMIN).$(SHLX)';
+        $E_MAJVERS_SHLX = '$MAJVERS.$SHLX';
         $MAJVERS_SHLX = '$(MAJVERS).$(SHLX)';
     } else {
+        $E_VERSION_SHLX =  '$SHLX.$VERSION';
         $VERSION_SHLX = '$(SHLX).$(VERSION)';
         $MAJMIN_SHLX  = '$(SHLX).$(MAJMIN)';
+        $E_MAJVERS_SHLX =  '$SHLX.$MAJVERS';
         $MAJVERS_SHLX = '$(SHLX).$(MAJVERS)';
     }
 
+    $E_VERSION_LIBX = '$LIBX.$VERSION';
+    $E_MAJVERS_LIBX = '$LIBX.$MAJVERS';
 
-    print $F <<EndText;
+    L($F);
+    L($F, "# build type");
+
+    if ($OPT{'enable-static'}) {
+        L($F, "WANTS_STATIC = 1");
+    }
 
-# build type
+    $E_VERSION_EXEX = '$EXEX.$VERSION';
+    $E_MAJVERS_EXEX = '$LIBX.$MAJVERS';
+
+    print $F <<EndText;
 BUILD = $BUILD
 
 # target OS
@@ -587,11 +733,12 @@ EndText
     }
 
     L($F, 'CLSPATH = -classpath $(CLSDIR)');
+    L($F, "NO_ARRAY_BOUNDS_WARNING = $NO_ARRAY_BOUNDS_WARNING");
     L($F);
 
     # version information
 
-    my ($VERSION, $MAJMIN, $MAJVERS);
+    my $MAJMIN;
 
     if ($FULL_VERSION =~ /(\d+)\.(\d+)\.(\d+)-?\w*\d*/) {
         $VERSION = "$1.$2.$3";
@@ -608,6 +755,7 @@ MAJMIN  = $MAJMIN
 MAJVERS = $MAJVERS
 
 # output path
+BUILD_PREFIX = $BUILD_PREFIX
 TARGDIR = $TARGDIR
 
 # derived paths
@@ -618,16 +766,21 @@ BINDIR    = \$(TARGDIR)/bin
 EndText
 
     if ($PKG{LNG} eq 'C') {
+        $E_BINDIR        = '$TARGDIR/bin';
+        $E_LIBDIR        = '$TARGDIR/lib';
         L($F, 'LIBDIR    = $(TARGDIR)/lib');
     } elsif ($PKG{LNG} eq 'JAVA') {
+        $E_LIBDIR        = '$TARGDIR/jar';
         L($F, 'LIBDIR    = $(TARGDIR)/jar');
     }
 
-    print $F <<EndText;
-ILIBDIR   = \$(TARGDIR)/ilib
-OBJDIR    = \$(TARGDIR)/obj/\$(MODPATH)
-CLSDIR    = \$(TARGDIR)/cls
-EndText
+    L($F, 'ILIBDIR   = $(TARGDIR)/ilib');
+    if ($PKG{NOMODPATH}) {
+        L($F, 'OBJDIR    = $(TARGDIR)/obj');
+    } else {
+        L($F, 'OBJDIR    = $(TARGDIR)/obj/$(MODPATH)');
+    }
+    L($F, 'CLSDIR    = $(TARGDIR)/cls');
 
     if ($PKG{LNG} eq 'JAVA') {
         L($F,
@@ -747,6 +900,51 @@ EndText
         T($F, '  fi');
     }
     close $F;
+
+    # create Makefile.config.install
+    println "configure: creating '$INS_MAKEFILE'" unless ($AUTORUN);
+    open $F, ">$INS_MAKEFILE" or die "cannot open $INS_MAKEFILE to write";
+
+    $OPT{'javadir' } = '' unless ($OPT{'javadir' });
+    $OPT{'sharedir'} = '' unless ($OPT{'sharedir'});
+
+    print $F "sub CONFIGURE {\n";
+    print $F "    \$_{PACKAGE_NAME } = '$PACKAGE_NAME';\n";
+    print $F "    \$_{VERSION      } = '$VERSION';\n";
+    print $F "    \$_{LNG          } = '$PKG{LNG}';\n";
+    print $F "    \$_{OS           } = '$OS';\n";
+    print $F "    \$_{BITS         } =  $BITS;\n";
+    print $F "    \$_{MAJVERS      } =  $MAJVERS;\n";
+    print $F "    \$_{LPFX         } = '$LPFX';\n";
+    print $F "    \$_{LIBX         } = '$LIBX';\n";
+    print $F "    \$_{MAJVERS_LIBX } = '" . expand($E_MAJVERS_LIBX) . "';\n";
+    print $F "    \$_{VERSION_LIBX } = '" . expand($E_VERSION_LIBX) . "';\n";
+    print $F "    \$_{SHLX         } = '$SHLX';\n";
+    print $F "    \$_{MAJVERS_SHLX } = '" . expand($E_MAJVERS_SHLX) . "';\n";
+    print $F "    \$_{VERSION_SHLX } = '" . expand($E_VERSION_SHLX) . "';\n";
+    print $F "    \$_{VERSION_EXEX } = '" . expand($E_VERSION_EXEX) . "';\n";
+    print $F "    \$_{MAJVERS_EXEX } = '" . expand($E_MAJVERS_EXEX) . "';\n";
+    print $F "    \$_{INCDIR       } = '" . expand("$Bin/.."      ) . "';\n";
+    if ($PKG{LNG} ne 'PYTHON') {
+        print $F "  \$_{BINDIR$BITS} = '" . expand($E_BINDIR      ) . "';\n";
+        print $F "  \$_{LIBDIR$BITS} = '" . expand($E_LIBDIR      ) . "';\n";
+    } elsif ($OPT{PYTHON_LIB_PATH}) {
+        print $F "  \$_{LIBDIR$BITS} = '$OPT{PYTHON_LIB_PATH}';\n";
+    }
+    print $F "    \$_{OTHER_PREFIX } = '$PKG{UPATH}';\n";
+    print $F "    \$_{PREFIX       } = '$OPT{'prefix'}';\n";
+    print $F "    \$_{INST_INCDIR  } = '$OPT{'includedir'}';\n";
+    print $F "    \$_{INST_BINDIR  } = '$OPT{'bindir'}';\n";
+    print $F "    \$_{INST_LIBDIR  } = '$OPT{'libdir'}';\n";
+    print $F "    \$_{INST_JARDIR  } = '$OPT{'javadir'}';\n";
+    print $F "    \$_{INST_SHAREDIR} = '$OPT{'sharedir'}';\n";
+    print $F "\n";
+    print $F "    \@_\n";
+    print $F "}\n";
+    print $F "\n";
+    print $F "1\n";
+
+    close $F;
 }
 
 if (! $OPT{'status'} ) {
@@ -768,7 +966,7 @@ EndText
             my $NGS_SDK_PREFIX = '';
             $NGS_SDK_PREFIX = $a{found_itf} if ($a{found_itf});
             if ($a{name} eq 'ngs-sdk') {
-                my $root = "$a{namew}_ROOT";
+                my $root = "$a{aname}_ROOT";
                 print OUT "    <$root>$NGS_SDK_PREFIX\/</$root>\n";
                 last;
             }
@@ -786,12 +984,20 @@ EndText
         open COUT, ">$out" or die "cannot open $out to write";
         print COUT "### AUTO-GENERATED FILE ###\n";
         print COUT "\n";
-        print COUT "OS_ARCH = \$(shell perl \$(TOP)/os-arch.perl)\n";
+        print COUT "OS_ARCH = \$(shell perl \$(TOP)/setup/os-arch.perl)\n";
         print COUT "include \$(TOP)/$CONFIG_OUT/Makefile.config.\$(OS_ARCH)\n";
         close COUT;
     }
 }
 
+unless ($OPT{'reconfigure'}) {
+    println "configure: creating 'reconfigure'" unless ($AUTORUN);
+    $CONFIGURED =~ s/\t/ /g;
+    open my $F, '>reconfigure' or die 'cannot open reconfigure to write';
+    print $F "./configure $CONFIGURED\n";
+    close $F;
+}
+
 status() if ($OS ne 'win');
 
 unlink 'a.out';
@@ -817,8 +1023,11 @@ sub status {
                 $BUILD_TYPE = $1;
             } elsif (/BUILD \?= /) {
                 $BUILD_TYPE = $_ unless ($BUILD_TYPE);
-            }
-            elsif (/TARGDIR = /) {
+            } elsif (/BUILD_PREFIX = /) {
+                $BUILD_PREFIX = $_;
+            } elsif (/CONFIGURED = (.*)/) {
+                $CONFIGURED = $1;
+            } elsif (/TARGDIR = /) {
                 $TARGDIR = $_;
                 println "\t\tgot $_" if ($OPT{'debug'});
             } elsif (/TARGDIR \?= (.+)/) {
@@ -826,18 +1035,19 @@ sub status {
                 println "\t\tgot $_" if ($OPT{'debug'});
             }
             elsif (/INST_INCDIR = (.+)/) {
-                $OPT{includedir} = $1;
+                $OPT{'includedir'} = $1;
             }
             elsif (/INST_BINDIR = (.+)/) {
-                $OPT{bindir} = $1;
+                $OPT{'bindir'} = $1;
             }
             elsif (/INST_LIBDIR = (.+)/) {
-                $OPT{libdir} = $1;
+                $OPT{'libdir'} = $1;
             }
         }
     }
 
     println "build type: $BUILD_TYPE";
+    println "build prefix: $BUILD_PREFIX" if ($OS ne 'win');
     println "build output path: $TARGDIR" if ($OS ne 'win');
 
 #   print "prefix: ";    print $OPT{'prefix'} if ($OS ne 'win');    println;
@@ -860,13 +1070,24 @@ sub status {
     println "javadir: $OPT{'javadir'}" if ($OPT{'javadir'});
     println "pythondir: $OPT{'pythondir'}" if ($OPT{'pythondir'});
 
-    println;
+    $CONFIGURED =~ s/\t/ /g;
+    println "configured with: \"$CONFIGURED\"";
 }
 
-sub expand {
+sub expand { $_[0] =~ s/(\$\w+)/$1/eeg; $_[0]; }
+
+sub expand_path {
     my ($filename) = @_;
     return unless ($filename);
+
     if ($filename =~ /^~/) {
+        if ($filename =~ m|^~([^/]*)|) {
+            if ($1 && ! getpwnam($1)) {
+                print "configure: error: bad path: '$filename'\n";
+                exit 1;
+            }
+        }
+
         $filename =~ s{ ^ ~ ( [^/]* ) }
                       { $1
                             ? (getpwnam($1))[7]
@@ -875,6 +1096,7 @@ sub expand {
                               )
                       }ex;
     }
+
     my $a = abs_path($filename);
     $filename = $a if ($a);
     $filename;
@@ -882,34 +1104,33 @@ sub expand {
 
 sub find_in_dir {
     my ($dir, $include, $lib, $ilib) = @_;
-    print "\t$dir... " unless ($AUTORUN);
     unless (-d $dir) {
-        println "no" unless ($AUTORUN);
+#       println "no" unless ($AUTORUN);
         println "\t\tnot found $dir" if ($OPT{'debug'});
         return;
     }
-    print "[found] " if ($OPT{'debug'});
+#   print "\t$dir... " unless ($AUTORUN);
+#   print "[found] " if ($OPT{'debug'});
     my ($found_inc, $found_lib, $found_ilib);
-    my $nl = 1;
     if ($include) {
-        print "includes... " unless ($AUTORUN);
+        print "\tincludes... " unless ($AUTORUN);
         if (-e "$dir/$include") {
-            println 'yes' unless ($AUTORUN);
+            println $dir unless ($AUTORUN);
             $found_inc = $dir;
         } elsif (-e "$dir/include/$include") {
-            println 'yes' unless ($AUTORUN);
+            println $dir unless ($AUTORUN);
             $found_inc = "$dir/include";
         } elsif (-e "$dir/interfaces/$include") {
-            println 'yes' unless ($AUTORUN);
+            println $dir unless ($AUTORUN);
             $found_inc = "$dir/interfaces";
         } else {
+            print "$dir: " if ($OPT{'debug'});
             println 'no' unless ($AUTORUN);
         }
-        $nl = 0;
     }
     if ($lib || $ilib) {
-        print "\n\t" if ($nl && !$AUTORUN);
-        print "libraries... " unless ($AUTORUN);
+#       print "\n\t" if ($nl && !$AUTORUN);
+        print "\tlibraries... " unless ($AUTORUN);
         if ($lib) {
             my $builddir = File::Spec->catdir($dir, $OS, $TOOLS, $ARCH, $BUILD);
             my $libdir  = File::Spec->catdir($builddir, 'lib');
@@ -923,14 +1144,14 @@ sub find_in_dir {
                     my $f = File::Spec->catdir($ilibdir, $ilib);
                     print "\tchecking $f\n\t" if ($OPT{'debug'});
                     if (-e $f) {
-                        println 'yes';
+                        println $ilibdir;
                         $found_ilib = $ilibdir;
                     } else {
                         println 'no' unless ($AUTORUN);
                         return;
                     }
                 } else {
-                    println 'yes';
+                    println $libdir;
                 }
                 ++$found;
             }
@@ -939,7 +1160,7 @@ sub find_in_dir {
                 my $f = File::Spec->catdir($libdir, $lib);
                 print "\tchecking $f\n\t" if ($OPT{'debug'});
                 if (-e $f) {
-                    println 'yes';
+                    println $libdir;
                     $found_lib = $libdir;
                     ++$found;
                 }
@@ -957,16 +1178,18 @@ sub find_in_dir {
                         my $f = File::Spec->catdir($ilibdir, $ilib);
                         print "\tchecking $f\n\t" if ($OPT{'debug'});
                         if (-e $f) {
-                            println 'yes';
+                            println $ilibdir;
                             $found_ilib = $ilibdir;
                         } else {
                             println 'no' unless ($AUTORUN);
                             return;
                         }
                     } else {
-                        println 'yes';
+                        println $libdir;
                     }
                     ++$found;
+                } else {
+                    println 'no' unless ($AUTORUN);
                 }
             }
         }
@@ -976,7 +1199,6 @@ sub find_in_dir {
             println 'no' unless ($AUTORUN);
             undef $found_lib;
         }
-        ++$nl;
     }
     return ($found_inc, $found_lib, $found_ilib);
 }
@@ -994,38 +1216,90 @@ sub reverse_build {
 
 ################################################################################
 
+sub check_tool {
+    my ($tool) = @_;
+    print "checking for $tool... ";
+    my $cmd = "$tool --help";
+    print "\n\t\trunning $cmd\n\t" if ($OPT{'debug'});
+    my $out = `$cmd 2>&1`;
+    if ($? == 0) {
+        println "yes";
+        return 1;
+    } else {
+        println "no";
+        return 0;
+    }
+}
+
+sub check_no_array_bounds {
+    check_compiler('O', '-Wno-array-bounds');
+}
+
 sub find_lib {
-    my ($n, $i, $l) = @_;
+    check_compiler('L', @_);
+}
 
-    print "checking for $n library... ";
+sub check_compiler {
+    my ($t, $n, $i, $l) = @_;
+    my $tool = $TOOLS;
+
+    if ($t eq 'L') {
+        print "checking for $n library... ";
+    } elsif ($t eq 'O') {
+        if ($tool && $tool eq 'gcc') {
+            print "checking whether gcc accepts $n... ";
+        } else {
+            return;
+        }
+    } else {
+        die "Unknown check_compiler option: '$t'";
+    }
+
+    unless ($tool) {
+        println "warning: unknown tool";
+        return;
+    }
 
     while (1) {
-        my ($library, $log);
+        my ($flags, $library, $log) = ('', '');
 
-        if ($n eq 'hdf5') {
+        if ($t eq 'O') {
+            $flags = $n;
+            $log = '                      int main() {                     }\n'
+        } elsif ($n eq 'hdf5') {
             $library = '-lhdf5';
-            $log = '#include <hdf5.h>            \n main() { H5close     (); }';
-        } elsif ($n eq 'xml2') {
-            $library = '-lxml2';
-            $log = '#include <libxml/xmlreader.h>\n main() { xmlInitParser();}';
+            $log = '#include <hdf5.h>  \n int main() { H5close         (); }\n'
+        } elsif ($n eq 'fuse') {
+            $flags = '-D_FILE_OFFSET_BITS=64';
+            $library = '-lfuse';
+            $log = '#include <fuse.h>  \n int main() { fuse_get_context(); }\n'
         } elsif ($n eq 'magic') {
             $library = '-lmagic';
-            $log = '#include <magic.h>           \n main() { magic_open (0); }';
+            $log = '#include <magic.h> \n int main() { magic_open     (0); }\n'
+        } elsif ($n eq 'xml2') {
+            $library = '-lxml2';
+            $log = '#include <libxml/xmlreader.h>\n' .
+                                         'int main() { xmlInitParser  ( ); }\n'
         } else {
             println 'unknown: skipped';
             return;
         }
 
-        if (($i && ! -d $i) || ($l && ! -d $l)) {
+        if ($i && ! -d $i) {
+            print "'$i': " if ($OPT{'debug'});
             println 'no';
             return;
         }
+        if ($l && ! -d $l) {
+            print "'$l': " if ($OPT{'debug'});            println 'no';
+            return;
+        }
 
         my $cmd = $log;
         $cmd =~ s/\\n/\n/g;
 
-        my $gcc = "| gcc -xc " . ($i ? "-I$i " : ' ')
-                               . ($l ? "-L$l " : ' ') . "- $library";
+        my $gcc = "| $tool -xc $flags " . ($i ? "-I$i " : ' ')
+                                      . ($l ? "-L$l " : ' ') . "- $library";
         $gcc .= ' 2> /dev/null' unless ($OPT{'debug'});
 
         open GCC, $gcc or last;
@@ -1039,6 +1313,8 @@ sub find_lib {
 
         return if (!$ok);
 
+        return 1 if ($t eq 'O');
+
         return ($i, $l);
     }
 
@@ -1057,36 +1333,47 @@ sub check {
 
     my %PKG = PKG();
 
-    die "No LNG"   unless $PKG{LNG};
-    die "No OUT"   unless $PKG{OUT};
-    die "No PATH"  unless $PKG{PATH};
-    die "No UPATH" unless $PKG{UPATH};
+    die "No LNG"    unless $PKG{LNG};
+    die "No LOCOUT" unless $PKG{LOCOUT};
+    die "No OUT"    unless $PKG{OUT};
+    die "No PATH"   unless $PKG{PATH};
+    die "No UPATH"  unless $PKG{UPATH};
 
     foreach my $href (DEPENDS()) { die "No DEPENDS::name" unless $href->{name} }
 
     foreach my $href (REQ()) {
-        die "No REQ::name" unless $href->{name};
-
-        my $origin = $href->{origin};
-        die  "No $href->{name}:origin"  unless $origin;
-        die  "No $href->{name}:include" unless $href->{include};
-        die  "No $href->{name}:lib"     unless $href->{lib};
-        die  "No $href->{name}:option"  unless $href->{option};
-        die  "No $href->{name}:pkgpath" unless $href->{pkgpath};
-        die  "No $href->{name}:type"    unless $href->{type};
-        die  "No $href->{name}:usrpath" unless $href->{usrpath};
-        if ($origin eq 'I') {
-         die "No $href->{name}:bldpath" unless $href->{bldpath};
-         die "No $href->{name}:ilib"    unless $href->{ilib};
-         die "No $href->{name}:namew"   unless $href->{namew};
-         die "No $href->{name}:srcpath" unless $href->{srcpath};
+        die         "No REQ::name" unless $href->{name};
+
+        die         "No $href->{name}:option"  unless $href->{option};
+
+        die         "No $href->{name}:type"    unless $href->{type};
+        unless ($href->{type} =~ /I/) {
+            die     "No $href->{name}:lib"     unless $href->{lib};
+            die     "No $href->{name}:pkgpath" unless $href->{pkgpath};
+            die     "No $href->{name}:usrpath" unless $href->{usrpath};
+        }
+
+        die         "No $href->{name}:origin"  unless $href->{origin};
+        if ($href->{origin} eq 'I') {
+            die     "No $href->{name}:aname"   unless $href->{aname};
+            unless ($href->{type} =~ /D/) {
+                die "No $href->{name}:include" unless $href->{include};
+                die "No $href->{name}:srcpath" unless $href->{srcpath};
+            }
+            unless ($href->{type} =~ /I/) {
+                die "No $href->{name}:bldpath"    unless $href->{bldpath   };
+                die "No $href->{name}:locbldpath" unless $href->{locbldpath};
+            }
+            if ($href->{type} =~ /B/) {
+                die "No $href->{name}:ilib"    unless $href->{ilib};
+            }
         }
     }
 }
 
 ################################################################################
 
-sub optional { $_[0] =~ /^[LS]I$/ }
+sub optional { $_[0] =~ /O/ }
 
 sub help {
 #  --prefix=PREFIX         install architecture-independent files in PREFIX
@@ -1123,10 +1410,14 @@ EndText
     
         if (PACKAGE_TYPE() eq 'B') {
             print "\`$package_default_prefix/bin', ";
-        } else {
+        } elsif (PACKAGE_TYPE() eq 'L') {
             print "\`$package_default_prefix/include', ";
         }
-        println "\`$package_default_prefix/lib' etc.";
+        if (PACKAGE_TYPE() eq 'P') {
+            println "\`$package_default_prefix/share' etc.";
+        } else {
+            println "\`$package_default_prefix/lib' etc.";
+        }
 
         print <<EndText;
 You can specify an installation prefix other than \`$package_default_prefix'
@@ -1184,27 +1475,50 @@ EndText
         println;
     }
 
-    print <<EndText if ($^O ne 'MSWin32');
+    print <<EndText if (PACKAGE_TYPE() eq 'B');
+Optional Features:
+  --enable-static         build static executable [default=no]
+
+EndText
+
+    my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
+
+    if ($^O ne 'MSWin32') {
+        print <<EndText;
 Build tuning:
   --with-debug
   --without-debug
-  --arch=name             specify the name of the target architecture
+EndText
 
-  --build=DIR             generate build output into DIR directory
+        if (@ARCHITECTURES) {
+            print
+"  --arch=name             specify the name of the target architecture\n";
+        }
+
+        print <<EndText;
+
+  --build-prefix=DIR      generate build output into DIR directory
                           [$OUTDIR]
 
 EndText
+    }
 
-    println "Miscellaneous:";
+    println 'Miscellaneous:';
+    println '  --reconfigure           rerun `configure\'';
+    println '                          using the same command-line arguments';
     if ($^O ne 'MSWin32') {
         println
-            "  --status                print current configuration information"
+            '  --status                print current configuration information'
     }
-    println "  --clean                 remove all configuration results";
-    println "  --debug                 print lots of debugging information";
-    println;
+    print <<EndText;
+  --clean                 remove all configuration results
+  --debug                 print lots of debugging information
+
+If `configure' was arleady run running `configure' without options
+will rerun `configure' using the same command-line arguments.
+
+Report bugs to sra-tools\@ncbi.nlm.nih.gov
+EndText
 }
 
-=pod
 ################################################################################
-=cut
diff --git a/ngs-python/configure b/ngs-java/setup/ngs-java/install
similarity index 82%
copy from ngs-python/configure
copy to ngs-java/setup/ngs-java/install
index 3313aac..b1e201d 100755
--- a/ngs-python/configure
+++ b/ngs-java/setup/ngs-java/install
@@ -29,17 +29,17 @@ CURDIR="`dirname $0`"
 
 if [ -z "$CURDIR" ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
     exit 1
 fi
 
-if [ "$FILENAME" != configure -a ! -s konfigure.perl ]
+if [ "$FILENAME" != install -a ! -s setup/install.perl ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
 else
     perl -v > /dev/null 2>&1 || { echo "checking for perl... no"; \
-        echo >&2 "configure: error: perl not found."; exit 1; }
+        echo >&2 "error: perl not found."; exit 1; }
 
-    cd $CURDIR
-    perl -w ./konfigure.perl $@
+    cd $CURDIR/setup
+    perl -w ./install.perl "$@"
 fi
diff --git a/ngs-java/setup/ngs-java/linux/os.prl b/ngs-java/setup/ngs-java/linux/os.prl
new file mode 100644
index 0000000..5f75471
--- /dev/null
+++ b/ngs-java/setup/ngs-java/linux/os.prl
@@ -0,0 +1,2 @@
+sub OS { 'linux' }
+1
diff --git a/ngs-java/setup/ngs-java/mac/os.prl b/ngs-java/setup/ngs-java/mac/os.prl
new file mode 100644
index 0000000..b962c57
--- /dev/null
+++ b/ngs-java/setup/ngs-java/mac/os.prl
@@ -0,0 +1,2 @@
+sub OS { 'mac' }
+1
diff --git a/ngs-python/os-arch.perl b/ngs-java/setup/os-arch.perl
similarity index 80%
rename from ngs-python/os-arch.perl
rename to ngs-java/setup/os-arch.perl
index a7b4990..5f3f87a 100644
--- a/ngs-python/os-arch.perl
+++ b/ngs-java/setup/os-arch.perl
@@ -1,14 +1,14 @@
 use strict;
 
 use FindBin qw($Bin);
-require "$Bin/os-arch.pm";
+require "$Bin/os-arch.prl";
 
 my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
 
 my $res = "$OS.$ARCH";
 
 if (@ARCHITECTURES) {
-    my $name = "$Bin/Makefile.config.$OS.arch";
+    my $name = "$Bin/../Makefile.config.$OS.arch";
     if (-e $name) {
         while (1) {
             open F, $name or last;
diff --git a/ngs-sdk/os-arch.pm b/ngs-java/setup/os-arch.prl
similarity index 95%
rename from ngs-sdk/os-arch.pm
rename to ngs-java/setup/os-arch.prl
index 6fbd606..791b556 100644
--- a/ngs-sdk/os-arch.pm
+++ b/ngs-java/setup/os-arch.prl
@@ -18,6 +18,8 @@ sub OsArch {
             $HOST_OS = 'win';
         } elsif ($UNAME =~ /xMINGW/) {
             $HOST_OS = 'win';
+        } else {
+            $HOST_OS = $UNAME;
         }
         if ($HOST_OS eq 'mac') {
             $MARCH = $HOST_ARCH = MacArch();
@@ -50,7 +52,9 @@ sub OsArch {
                 @ARCHITECTURES = qw(x86_64 i386);
             } elsif ($MARCH =~ /sun4v/) {
                 $HOST_ARCH = 'sparc64';
-		        @ARCHITECTURES = qw(sparc64 sparc32);
+                @ARCHITECTURES = qw(sparc64 sparc32);
+            } else {
+                $HOST_ARCH = $MARCH;
             }
         }
     }
diff --git a/ngs-java/setup/package.prl b/ngs-java/setup/package.prl
new file mode 100644
index 0000000..96914a4
--- /dev/null
+++ b/ngs-java/setup/package.prl
@@ -0,0 +1,17 @@
+################################################################################
+sub PACKAGE      { "ngs-java" }
+sub VERSION      { "1.0.1" }
+sub PACKAGE_TYPE { 'J' }
+sub PACKAGE_NAME { "NGS-JAVA" }
+sub PACKAGE_NAMW { "NGS_JAVA" }
+sub DEPENDS      {}
+sub CONFIG_OUT   { '.' }
+sub PKG { ( LNG   => 'JAVA',
+            OUT   => 'ncbi-outdir',
+            LOCOUT=> '../../../OUTDIR',
+            PATH  => '/usr/local/ngs/ngs-java',
+            UPATH =>      '$HOME/ngs/ngs-java',
+            EXAMP => '1'
+        ) }
+sub REQ {}
+1
diff --git a/ngs-java/win-configure.bat b/ngs-java/win-configure.bat
deleted file mode 100644
index 7b35820..0000000
--- a/ngs-java/win-configure.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-perl -w ./konfigure.perl %*
-
diff --git a/ngs-python/.gitignore b/ngs-python/.gitignore
index cfe3d89..70d522b 100644
--- a/ngs-python/.gitignore
+++ b/ngs-python/.gitignore
@@ -1,3 +1,6 @@
-Makefile.userconfig
-Makefile.config*
-user.status
\ No newline at end of file
+*.pyc
+/build
+/Makefile.userconfig
+/Makefile.config*
+/reconfigure
+/user.status
diff --git a/ngs-python/Makefile b/ngs-python/Makefile
index 0b8331a..0e718c4 100644
--- a/ngs-python/Makefile
+++ b/ngs-python/Makefile
@@ -37,7 +37,7 @@ install: Makefile.config
 	@ $(MAKE) -f Makefile.python install
 
 dummy:
-	@ echo "make complete"
+	@ echo "make complete for python"
 
 dummy_cln dummy_inst:
 	@ true
diff --git a/ngs-python/Makefile.python b/ngs-python/Makefile.python
index f6893b8..2669f69 100644
--- a/ngs-python/Makefile.python
+++ b/ngs-python/Makefile.python
@@ -57,19 +57,32 @@ ifeq (linux, $(OS))
 
 PROFILE_FILE = $(ROOT)/etc/profile.d/ngs-python
 
+$(INST_PYTHONDIR):
+	@ mkdir -p $@
+
 install: $(TARGETS) $(INST_PYTHONDIR) copyexamples
 ifeq (0, $(shell id -u))
 	@ echo "Installing ngs package..."
 	@ python setup.py install
-	@ echo "Please add $(NGS_LIBDIR):$(VDB_LIBDIR) to your LD_LIBRARY_PATH, e.g.:"
-	@ echo "      export LD_LIBRARY_PATH=$(NGS_LIBDIR):$(VDB_LIBDIR):\$$LD_LIBRARY_PATH"
    
 else
 	@ echo "Installing ngs package..."
 	@ python setup.py install --user
+endif
+
+ifneq (, $(NGS_LIBDIR))
+ifneq (, $(VDB_LIBDIR))
 	@ echo "Please add $(NGS_LIBDIR):$(VDB_LIBDIR) to your LD_LIBRARY_PATH, e.g.:"
 	@ echo "      export LD_LIBRARY_PATH=$(NGS_LIBDIR):$(VDB_LIBDIR):\$$LD_LIBRARY_PATH"
 endif
+endif
+
+ifeq (, $(NGS_LIBDIR))
+	@ echo "You will need to install ngs-sdk library in order to run ngs-python."
+endif
+ifeq (, $(VDB_LIBDIR))
+	@ echo "You will need to install ncbi-vdb library in order to run ngs-python."
+endif
 
 else
 install:
diff --git a/ngs-python/Makefile.rules b/ngs-python/Makefile.rules
index 3ecb6ac..1a4989a 100644
--- a/ngs-python/Makefile.rules
+++ b/ngs-python/Makefile.rules
@@ -61,9 +61,9 @@ test runtests: Makefile.config
 #	@ $(MAKE) -C test runtests
 
 # rule to run configuration
-Makefile.config: Makefile.config.$(shell perl $(TOP)/os-arch.perl) konfigure.perl
+Makefile.config: Makefile.config.$(shell perl $(TOP)/setup/os-arch.perl) setup/konfigure.perl
 
-Makefile.config.$(shell perl $(TOP)/os-arch.perl):
+Makefile.config.$(shell perl $(TOP)/setup/os-arch.perl):
 	@echo "*** File '$@' is missing. Please run ./configure"
 	@false
 
diff --git a/ngs-python/configure b/ngs-python/configure
index 3313aac..baa556f 100755
--- a/ngs-python/configure
+++ b/ngs-python/configure
@@ -33,13 +33,13 @@ if [ -z "$CURDIR" ]
     exit 1
 fi
 
-if [ "$FILENAME" != configure -a ! -s konfigure.perl ]
+if [ "$FILENAME" != configure -a ! -s setup/konfigure.perl ]
     then
     echo configure: error: configure should be run as ./configure
 else
     perl -v > /dev/null 2>&1 || { echo "checking for perl... no"; \
         echo >&2 "configure: error: perl not found."; exit 1; }
 
-    cd $CURDIR
-    perl -w ./konfigure.perl $@
+    cd $CURDIR/setup
+    perl -w konfigure.perl "$@"
 fi
diff --git a/ngs-python/examples/AlignSliceTest.py b/ngs-python/examples/AlignSliceTest.py
new file mode 100644
index 0000000..470c30c
--- /dev/null
+++ b/ngs-python/examples/AlignSliceTest.py
@@ -0,0 +1,67 @@
+#===========================================================================
+#
+#                           PUBLIC DOMAIN NOTICE
+#              National Center for Biotechnology Information
+#
+# This software/database is a "United States Government Work" under the
+# terms of the United States Copyright Act.  It was written as part of
+# the author's official duties as a United States Government employee and
+# thus cannot be copyrighted.  This software/database is freely available
+# to the public for use. The National Library of Medicine and the U.S.
+# Government have not placed any restriction on its use or reproduction.
+#
+# Although all reasonable efforts have been taken to ensure the accuracy
+# and reliability of the software and data, the NLM and the U.S.
+# Government do not and cannot warrant the performance or results that
+# may be obtained by using this software or data. The NLM and the U.S.
+# Government disclaim all warranties, express or implied, including
+# warranties of performance, merchantability or fitness for any particular
+# purpose.
+#
+# Please cite the author in any work or product based on this material.
+#
+#===========================================================================
+#
+import sys
+import traceback
+
+from ngs import NGS
+from ngs.ErrorMsg import ErrorMsg
+from ngs.ReadCollection import ReadCollection
+from ngs.Alignment import Alignment
+from ngs.AlignmentIterator import AlignmentIterator
+from ngs.Reference import Reference
+
+def run(acc, refName, start, stop):
+    # open requested accession using SRA implementation of the API
+    with NGS.openReadCollection(acc) as run:
+        run_name = run.getName()
+    
+        # get requested reference
+        with run.getReference(refName) as ref:
+            # start iterator on requested range
+            with ref.getAlignmentSlice(start, stop-start+1, Alignment.primaryAlignment) as it:
+                i = 0
+                while it.nextAlignment():
+                    print ("{}\t{}\t{}\t{}\t{}".format(
+                        it.getReadId(),
+                        it.getReferenceSpec(),
+                        it.getAlignmentPosition(),
+                        it.getLongCigar(False),
+                        it.getAlignedFragmentBases(),
+                        ))
+                    i += 1
+                print ("Read {} alignments for {}".format(i, run_name))
+
+
+if len(sys.argv) != 5:
+    print ("Usage: AlignSliceTest accession reference start stop\n")
+else:
+    try:
+        run(sys.argv[1], sys.argv[2], int(sys.argv[3]), int(sys.argv[4]))
+    except ErrorMsg as x:
+        print (x)
+        traceback.print_exc()
+        # x.printStackTrace - not implemented
+    except BaseException as x:
+        traceback.print_exc()
diff --git a/ngs-python/examples/AlignSliceTest26.py b/ngs-python/examples/AlignSliceTest26.py
new file mode 100644
index 0000000..12fa81b
--- /dev/null
+++ b/ngs-python/examples/AlignSliceTest26.py
@@ -0,0 +1,67 @@
+#===========================================================================
+#
+#                           PUBLIC DOMAIN NOTICE
+#              National Center for Biotechnology Information
+#
+# This software/database is a "United States Government Work" under the
+# terms of the United States Copyright Act.  It was written as part of
+# the author's official duties as a United States Government employee and
+# thus cannot be copyrighted.  This software/database is freely available
+# to the public for use. The National Library of Medicine and the U.S.
+# Government have not placed any restriction on its use or reproduction.
+#
+# Although all reasonable efforts have been taken to ensure the accuracy
+# and reliability of the software and data, the NLM and the U.S.
+# Government do not and cannot warrant the performance or results that
+# may be obtained by using this software or data. The NLM and the U.S.
+# Government disclaim all warranties, express or implied, including
+# warranties of performance, merchantability or fitness for any particular
+# purpose.
+#
+# Please cite the author in any work or product based on this material.
+#
+#===========================================================================
+#
+import sys
+import traceback
+
+from ngs import NGS
+from ngs.ErrorMsg import ErrorMsg
+from ngs.ReadCollection import ReadCollection
+from ngs.Alignment import Alignment
+from ngs.AlignmentIterator import AlignmentIterator
+from ngs.Reference import Reference
+
+def run(acc, refName, start, stop): # this function doesn't release NGS objects however it might
+    # open requested accession using SRA implementation of the API
+    run = NGS.openReadCollection(acc)
+    run_name = run.getName()
+    
+    # get requested reference
+    ref = run.getReference(refName)
+
+    # start iterator on requested range
+    it = ref.getAlignmentSlice(start, stop-start+1, Alignment.primaryAlignment)
+    i = 0
+    while it.nextAlignment():
+        print ("%s\t%s\t%d\t%s\t%s" % (
+            it.getReadId(),
+            it.getReferenceSpec(),
+            it.getAlignmentPosition(),
+            it.getLongCigar(False),
+            it.getAlignedFragmentBases(),
+            ))
+        i += 1
+    print ("Read %d alignments for %s" % (i, run_name))
+
+if len(sys.argv) != 5:
+    print ("Usage: AlignSliceTest accession reference start stop\n")
+else:
+    try:
+        run(sys.argv[1], sys.argv[2], int(sys.argv[3]), int(sys.argv[4]))
+    except ErrorMsg, x:
+        print (x)
+        traceback.print_exc()
+        # x.printStackTrace - not implemented
+    except BaseException, x:
+        traceback.print_exc()
diff --git a/ngs-python/examples/AlignTest.py b/ngs-python/examples/AlignTest.py
new file mode 100644
index 0000000..f078ebf
--- /dev/null
+++ b/ngs-python/examples/AlignTest.py
@@ -0,0 +1,73 @@
+#===========================================================================
+#
+#                           PUBLIC DOMAIN NOTICE
+#              National Center for Biotechnology Information
+#
+# This software/database is a "United States Government Work" under the
+# terms of the United States Copyright Act.  It was written as part of
+# the author's official duties as a United States Government employee and
+# thus cannot be copyrighted.  This software/database is freely available
+# to the public for use. The National Library of Medicine and the U.S.
+# Government have not placed any restriction on its use or reproduction.
+#
+# Although all reasonable efforts have been taken to ensure the accuracy
+# and reliability of the software and data, the NLM and the U.S.
+# Government do not and cannot warrant the performance or results that
+# may be obtained by using this software or data. The NLM and the U.S.
+# Government disclaim all warranties, express or implied, including
+# warranties of performance, merchantability or fitness for any particular
+# purpose.
+#
+# Please cite the author in any work or product based on this material.
+#
+#===========================================================================
+#
+import sys
+import traceback
+
+from ngs import NGS
+from ngs.ErrorMsg import ErrorMsg
+from ngs.ReadCollection import ReadCollection
+from ngs.Alignment import Alignment
+from ngs.AlignmentIterator import AlignmentIterator
+
+
+def run(acc, splitNum, splitNo):
+    # open requested accession using SRA implementation of the API
+    with NGS.openReadCollection(acc) as run:
+        run_name = run.getName()
+        
+        # compute window to iterate through
+        MAX_ROW = run.getAlignmentCount()
+        chunk = MAX_ROW / splitNum
+        first = int(round(chunk * (splitNo-1)))
+        next_first = int(round(chunk * (splitNo)))
+        if next_first > MAX_ROW:
+            next_first = MAX_ROW
+
+        # start iterator on reads
+        with run.getAlignmentRange(first+1, next_first-first, Alignment.primaryAlignment) as it:
+            i = 0
+            while it.nextAlignment():
+                print ("{}\t{}\t{}\t{}\t{}".format(it.getReadId(),
+                    it.getReferenceSpec(),
+                    it.getAlignmentPosition(),
+                    it.getShortCigar(False),
+                    it.getFragmentBases(),
+                ))
+                i += 1
+            print ("Read {} alignments for {}".format(i, run_name))
+
+
+if len(sys.argv) != 4:
+    print ("Usage: FragTest accession NumChunks ChunkNo\n")
+else:
+    try:
+        run(sys.argv[1], int(sys.argv[2]), int(sys.argv[3]))
+    except ErrorMsg as x:
+        print (x)
+        traceback.print_exc()
+        # x.printStackTrace - not implemented
+    except BaseException as x:
+        traceback.print_exc()
+
diff --git a/ngs-python/examples/AlignTest26.py b/ngs-python/examples/AlignTest26.py
new file mode 100644
index 0000000..445bea9
--- /dev/null
+++ b/ngs-python/examples/AlignTest26.py
@@ -0,0 +1,73 @@
+#===========================================================================
+#
+#                           PUBLIC DOMAIN NOTICE
+#              National Center for Biotechnology Information
+#
+# This software/database is a "United States Government Work" under the
+# terms of the United States Copyright Act.  It was written as part of
+# the author's official duties as a United States Government employee and
+# thus cannot be copyrighted.  This software/database is freely available
+# to the public for use. The National Library of Medicine and the U.S.
+# Government have not placed any restriction on its use or reproduction.
+#
+# Although all reasonable efforts have been taken to ensure the accuracy
+# and reliability of the software and data, the NLM and the U.S.
+# Government do not and cannot warrant the performance or results that
+# may be obtained by using this software or data. The NLM and the U.S.
+# Government disclaim all warranties, express or implied, including
+# warranties of performance, merchantability or fitness for any particular
+# purpose.
+#
+# Please cite the author in any work or product based on this material.
+#
+#===========================================================================
+#
+import sys
+import traceback
+
+from ngs import NGS
+from ngs.ErrorMsg import ErrorMsg
+from ngs.ReadCollection import ReadCollection
+from ngs.Alignment import Alignment
+from ngs.AlignmentIterator import AlignmentIterator
+
+
+def run(acc, splitNum, splitNo): # this function doesn't release NGS objects however it might
+    # open requested accession using SRA implementation of the API
+    run = NGS.openReadCollection(acc)
+    run_name = run.getName()
+    
+    # compute window to iterate through
+    MAX_ROW = run.getAlignmentCount()
+    chunk = MAX_ROW / splitNum
+    first = int(round(chunk * (splitNo-1)))
+    next_first = int(round(chunk * (splitNo)))
+    if next_first > MAX_ROW:
+        next_first = MAX_ROW
+
+    # start iterator on reads
+    it = run.getAlignmentRange(first+1, next_first-first, Alignment.primaryAlignment)
+    i = 0
+    while it.nextAlignment():
+        print (
+            it.getReadId() + "\t" +
+            it.getReferenceSpec() + "\t" +
+            str(it.getAlignmentPosition()) + "\t" +
+            it.getShortCigar(False) + "\t" +
+            it.getFragmentBases()
+        )
+        i += 1
+    print ("Read {} alignments for {}".format(i, run_name))
+
+
+if len(sys.argv) != 4:
+    print ("Usage: FragTest accession NumChunks ChunkNo\n")
+else:
+    try:
+        run(sys.argv[1], int(sys.argv[2]), int(sys.argv[3]))
+    except ErrorMsg, x:
+        print (x)
+        traceback.print_exc()
+        # x.printStackTrace - not implemented
+    except BaseException, x:
+        traceback.print_exc()
diff --git a/ngs-python/examples/FragTest.py b/ngs-python/examples/FragTest.py
new file mode 100644
index 0000000..f346e33
--- /dev/null
+++ b/ngs-python/examples/FragTest.py
@@ -0,0 +1,70 @@
+#===========================================================================
+#
+#                           PUBLIC DOMAIN NOTICE
+#              National Center for Biotechnology Information
+#
+# This software/database is a "United States Government Work" under the
+# terms of the United States Copyright Act.  It was written as part of
+# the author's official duties as a United States Government employee and
+# thus cannot be copyrighted.  This software/database is freely available
+# to the public for use. The National Library of Medicine and the U.S.
+# Government have not placed any restriction on its use or reproduction.
+#
+# Although all reasonable efforts have been taken to ensure the accuracy
+# and reliability of the software and data, the NLM and the U.S.
+# Government do not and cannot warrant the performance or results that
+# may be obtained by using this software or data. The NLM and the U.S.
+# Government disclaim all warranties, express or implied, including
+# warranties of performance, merchantability or fitness for any particular
+# purpose.
+#
+# Please cite the author in any work or product based on this material.
+#
+#===========================================================================
+#
+import sys
+import traceback
+
+from ngs import NGS
+from ngs.ErrorMsg import ErrorMsg
+from ngs.ReadCollection import ReadCollection
+from ngs.Read import Read
+from ngs.ReadIterator import ReadIterator
+
+
+def run(acc, splitNum, splitNo):
+    # open requested accession using SRA implementation of the API
+    with NGS.openReadCollection(acc) as run:
+        run_name = run.getName()
+
+        # compute window to iterate through
+        MAX_ROW = run.getReadCount()
+        chunk = MAX_ROW/splitNum
+        first = int(round(chunk*(splitNo-1)))
+        next_first = int(round(chunk*(splitNo)))
+        if next_first > MAX_ROW:
+            next_first = MAX_ROW
+
+        # start iterator on reads
+        with run.getReadRange(first+1, next_first-first, Read.all) as it:
+            i = 0
+            while it.nextRead():
+                print (it.getReadId())
+                # iterate through fragments
+                while it.nextFragment():
+                    print ("\t{}".format(it.getFragmentBases()))
+                print ("\n")
+            print ("Read {} spots for {}".format(i,  run_name))
+
+
+if len(sys.argv) != 4:
+    print ("Usage: FragTest accession NumChunks ChunkNo\n")
+else:
+    try:
+        run(sys.argv[1], int(sys.argv[2]), int(sys.argv[3]))
+    except ErrorMsg as x:
+        print (x)
+        traceback.print_exc()
+        # x.printStackTrace - not implemented
+    except BaseException as x:
+        traceback.print_exc()
diff --git a/ngs-python/examples/FragTest26.py b/ngs-python/examples/FragTest26.py
new file mode 100644
index 0000000..a5557fa
--- /dev/null
+++ b/ngs-python/examples/FragTest26.py
@@ -0,0 +1,70 @@
+#===========================================================================
+#
+#                           PUBLIC DOMAIN NOTICE
+#              National Center for Biotechnology Information
+#
+# This software/database is a "United States Government Work" under the
+# terms of the United States Copyright Act.  It was written as part of
+# the author's official duties as a United States Government employee and
+# thus cannot be copyrighted.  This software/database is freely available
+# to the public for use. The National Library of Medicine and the U.S.
+# Government have not placed any restriction on its use or reproduction.
+#
+# Although all reasonable efforts have been taken to ensure the accuracy
+# and reliability of the software and data, the NLM and the U.S.
+# Government do not and cannot warrant the performance or results that
+# may be obtained by using this software or data. The NLM and the U.S.
+# Government disclaim all warranties, express or implied, including
+# warranties of performance, merchantability or fitness for any particular
+# purpose.
+#
+# Please cite the author in any work or product based on this material.
+#
+#===========================================================================
+#
+import sys
+import traceback
+
+from ngs import NGS
+from ngs.ErrorMsg import ErrorMsg
+from ngs.ReadCollection import ReadCollection
+from ngs.Read import Read
+from ngs.ReadIterator import ReadIterator
+
+
+def run(acc, splitNum, splitNo): # this function doesn't release NGS objects however it might
+    # open requested accession using SRA implementation of the API
+    run = NGS.openReadCollection(acc)
+    run_name = run.getName()
+
+    # compute window to iterate through
+    MAX_ROW = run.getReadCount()
+    chunk = MAX_ROW/splitNum
+    first = int(round(chunk*(splitNo-1)))
+    next_first = int(round(chunk*(splitNo)))
+    if next_first > MAX_ROW:
+        next_first = MAX_ROW
+
+    # start iterator on reads
+    it = run.getReadRange(first+1, next_first-first, Read.all)
+    i = 0
+    while it.nextRead():
+        print (it.getReadId())
+        # iterate through fragments
+        while it.nextFragment():
+            print ("\t" + it.getFragmentBases())
+        print ("\n")
+    print ("Read {} spots for {}".format(i,  run_name))
+
+
+if len(sys.argv) != 4:
+    print ("Usage: FragTest accession NumChunks ChunkNo\n")
+else:
+    try:
+        run(sys.argv[1], int(sys.argv[2]), int(sys.argv[3]))
+    except ErrorMsg, x:
+        print (x)
+        traceback.print_exc()
+        # x.printStackTrace - not implemented
+    except BaseException, x:
+        traceback.print_exc()
diff --git a/ngs-python/examples/RefTest.py b/ngs-python/examples/RefTest.py
new file mode 100644
index 0000000..72c15b6
--- /dev/null
+++ b/ngs-python/examples/RefTest.py
@@ -0,0 +1,62 @@
+#===========================================================================
+#
+#                           PUBLIC DOMAIN NOTICE
+#              National Center for Biotechnology Information
+#
+# This software/database is a "United States Government Work" under the
+# terms of the United States Copyright Act.  It was written as part of
+# the author's official duties as a United States Government employee and
+# thus cannot be copyrighted.  This software/database is freely available
+# to the public for use. The National Library of Medicine and the U.S.
+# Government have not placed any restriction on its use or reproduction.
+#
+# Although all reasonable efforts have been taken to ensure the accuracy
+# and reliability of the software and data, the NLM and the U.S.
+# Government do not and cannot warrant the performance or results that
+# may be obtained by using this software or data. The NLM and the U.S.
+# Government disclaim all warranties, express or implied, including
+# warranties of performance, merchantability or fitness for any particular
+# purpose.
+#
+# Please cite the author in any work or product based on this material.
+#
+#===========================================================================
+#
+import sys
+import traceback
+
+from ngs import NGS
+from ngs.ErrorMsg import ErrorMsg
+from ngs.ReadCollection import ReadCollection
+from ngs.Reference import Reference
+from ngs.ReferenceIterator import ReferenceIterator
+
+def run(acc):
+    # open requested accession using SRA implementation of the API
+    with NGS.openReadCollection(acc) as run:
+        run_name = run.getName()
+
+        # get requested reference
+        with run.getReferences() as it:
+            i = 0
+            while it.nextReference():
+                print ("{}\t{}\t{}\t{}".format(it.getCommonName(),
+                    it.getCanonicalName(),
+                    it.getLength(),
+                    "circular" if it.getIsCircular() else "linear",
+                ))
+
+            print ("Read {} references for {}".format(i, run_name))
+
+
+if len(sys.argv) != 2:
+    print ("Usage: RefTest accession\n")
+else:
+    try:
+        run(sys.argv[1])
+    except ErrorMsg as x:
+        print (x)
+        traceback.print_exc()
+        # x.printStackTrace - not implemented
+    except BaseException as x:
+        traceback.print_exc()
diff --git a/ngs-python/examples/RefTest26.py b/ngs-python/examples/RefTest26.py
new file mode 100644
index 0000000..e5eea33
--- /dev/null
+++ b/ngs-python/examples/RefTest26.py
@@ -0,0 +1,63 @@
+#===========================================================================
+#
+#                           PUBLIC DOMAIN NOTICE
+#              National Center for Biotechnology Information
+#
+# This software/database is a "United States Government Work" under the
+# terms of the United States Copyright Act.  It was written as part of
+# the author's official duties as a United States Government employee and
+# thus cannot be copyrighted.  This software/database is freely available
+# to the public for use. The National Library of Medicine and the U.S.
+# Government have not placed any restriction on its use or reproduction.
+#
+# Although all reasonable efforts have been taken to ensure the accuracy
+# and reliability of the software and data, the NLM and the U.S.
+# Government do not and cannot warrant the performance or results that
+# may be obtained by using this software or data. The NLM and the U.S.
+# Government disclaim all warranties, express or implied, including
+# warranties of performance, merchantability or fitness for any particular
+# purpose.
+#
+# Please cite the author in any work or product based on this material.
+#
+#===========================================================================
+#
+import sys
+import traceback
+
+from ngs import NGS
+from ngs.ErrorMsg import ErrorMsg
+from ngs.ReadCollection import ReadCollection
+from ngs.Reference import Reference
+from ngs.ReferenceIterator import ReferenceIterator
+
+def run(acc): # this function doesn't release NGS objects however it might
+    # open requested accession using SRA implementation of the API
+    run = NGS.openReadCollection(acc)
+    run_name = run.getName()
+
+    # get requested reference
+    it = run.getReferences()
+
+    i = 0
+    while it.nextReference():
+        print (
+            it.getCommonName() + "\t" +
+            it.getCanonicalName() + "\t" +
+            str(it.getLength()) + "\t" +
+            ("circular" if it.getIsCircular() else "linear")
+        )
+    print ("Read {} references for {}".format(i, run_name))
+
+
+if len(sys.argv) != 2:
+    print ("Usage: RefTest accession\n")
+else:
+    try:
+        run(sys.argv[1])
+    except ErrorMsg, x:
+        print (x)
+        traceback.print_exc()
+        # x.printStackTrace - not implemented
+    except BaseException, x:
+        traceback.print_exc()
diff --git a/ngs-python/ngs/Alignment.py b/ngs-python/ngs/Alignment.py
index 88cbc9f..4aa7689 100644
--- a/ngs-python/ngs/Alignment.py
+++ b/ngs-python/ngs/Alignment.py
@@ -24,12 +24,12 @@
 # 
 # 
 
-from ctypes import byref, c_int, c_int32, c_uint32, c_int64, c_uint64, c_void_p
+from ctypes import byref, c_char, c_int, c_int32, c_uint32, c_int64, c_uint64, c_void_p
 from . import NGS
 
-from String import NGS_String, NGS_RawString, getNGSString, getNGSValue
+from .String import NGS_String, NGS_RawString, getNGSString, getNGSValue
 
-from Fragment import Fragment
+from .Fragment import Fragment
 
 # Represents an alignment between a Fragment and Reference sub-sequence
 # provides a path to Read and mate Alignment
@@ -121,9 +121,12 @@ class Alignment(Fragment):
         
     def getSoftClip(self, edge):
         ret = c_int32()
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_AlignmentGetSoftClip(self.ref, edge, byref(ret), byref(ngs_str_err.ref))
-        
+        finally:
+            ngs_str_err.close()
+
         return ret.value
 
     def getTemplateLength(self):
@@ -133,17 +136,39 @@ class Alignment(Fragment):
         """
         :returns: a text string describing alignment details
         """
-        with NGS_RawString() as ngs_str_err, NGS_String() as ngs_str_ret:
-            res = NGS.lib_manager.PY_NGS_AlignmentGetShortCigar(self.ref, clipped, byref(ngs_str_ret.ref), byref(ngs_str_err.ref))
-            return ngs_str_ret.getPyString()
+        ngs_str_err = NGS_RawString()
+        try:
+            ngs_str_ret = NGS_String()
+            try:
+                res = NGS.lib_manager.PY_NGS_AlignmentGetShortCigar(self.ref, clipped, byref(ngs_str_ret.ref), byref(ngs_str_err.ref))
+                return ngs_str_ret.getPyString()
+            finally:
+                ngs_str_ret.close()
+        finally:
+            ngs_str_err.close()
 
     def getLongCigar(self, clipped):
         """
         :returns: a text string describing alignment details
         """
-        with NGS_RawString() as ngs_str_err, NGS_String() as ngs_str_ret:
-            res = NGS.lib_manager.PY_NGS_AlignmentGetLongCigar(self.ref, clipped, byref(ngs_str_ret.ref), byref(ngs_str_err.ref))
-            return ngs_str_ret.getPyString()
+        ngs_str_err = NGS_RawString()
+        try:
+            ngs_str_ret = NGS_String()
+            try:
+                res = NGS.lib_manager.PY_NGS_AlignmentGetLongCigar(self.ref, clipped, byref(ngs_str_ret.ref), byref(ngs_str_err.ref))
+                return ngs_str_ret.getPyString()
+            finally:
+                ngs_str_ret.close()
+        finally:
+            ngs_str_err.close()
+
+    def getRNAOrientation(self):
+        """
+        :returns: '+' if positive strand is transcribed
+        :returns: '-' if negative strand is transcribed
+        :returns: '?' if unknown
+        """
+        return getNGSValue(self, NGS.lib_manager.PY_NGS_AlignmentGetRNAOrientation, c_char)
 
     # ------------------------------------------------------------------
     # details of mate alignment            
diff --git a/ngs-python/ngs/AlignmentIterator.py b/ngs-python/ngs/AlignmentIterator.py
index 25cab9d..40eb81c 100644
--- a/ngs-python/ngs/AlignmentIterator.py
+++ b/ngs-python/ngs/AlignmentIterator.py
@@ -27,8 +27,8 @@
 from ctypes import c_int
 
 from . import NGS
-from String import getNGSValue
-from Alignment import Alignment
+from .String import getNGSValue
+from .Alignment import Alignment
 
 class AlignmentIterator(Alignment):
     def nextAlignment(self):
diff --git a/ngs-python/ngs/Fragment.py b/ngs-python/ngs/Fragment.py
index 4a002fa..88916e2 100644
--- a/ngs-python/ngs/Fragment.py
+++ b/ngs-python/ngs/Fragment.py
@@ -27,8 +27,8 @@
 from ctypes import byref
 from . import NGS
 
-from Refcount import Refcount
-from String import NGS_String, NGS_RawString, getNGSString
+from .Refcount import Refcount
+from .String import NGS_String, NGS_RawString, getNGSString
 
 
 # Represents an NGS biological fragment
@@ -43,9 +43,16 @@ class Fragment(Refcount):
         :param: length must be >= 0
         :returns: sequence bases
         """
-        with NGS_RawString() as ngs_str_err, NGS_String() as ngs_str_seq:
-            res = NGS.lib_manager.PY_NGS_FragmentGetFragmentBases(self.ref, offset, length, byref(ngs_str_seq.ref), byref(ngs_str_err.ref))
-            return ngs_str_seq.getPyString()
+        ngs_str_err = NGS_RawString()
+        try:
+            ngs_str_seq = NGS_String()
+            try:
+                res = NGS.lib_manager.PY_NGS_FragmentGetFragmentBases(self.ref, offset, length, byref(ngs_str_seq.ref), byref(ngs_str_err.ref))
+                return ngs_str_seq.getPyString()
+            finally:
+                ngs_str_seq.close()
+        finally:
+            ngs_str_err.close()
 
     def getFragmentQualities(self, offset=0, length=-1):
         """getFragmentQualities using ASCII offset of 33
@@ -53,6 +60,13 @@ class Fragment(Refcount):
         :param: length must be >= 0
         :returns: phred quality values
         """
-        with NGS_RawString() as ngs_str_err, NGS_String() as ngs_str_seq:
-            res = NGS.lib_manager.PY_NGS_FragmentGetFragmentQualities(self.ref, offset, length, byref(ngs_str_seq.ref), byref(ngs_str_err.ref))
-            return ngs_str_seq.getPyString()
+        ngs_str_err = NGS_RawString()
+        try:
+            ngs_str_seq = NGS_String()
+            try:
+                res = NGS.lib_manager.PY_NGS_FragmentGetFragmentQualities(self.ref, offset, length, byref(ngs_str_seq.ref), byref(ngs_str_err.ref))
+                return ngs_str_seq.getPyString()
+            finally:
+                ngs_str_seq.close()
+        finally:
+            ngs_str_err.close()
diff --git a/ngs-python/ngs/FragmentIterator.py b/ngs-python/ngs/FragmentIterator.py
index 3dcfec3..a9969ea 100644
--- a/ngs-python/ngs/FragmentIterator.py
+++ b/ngs-python/ngs/FragmentIterator.py
@@ -27,8 +27,8 @@
 from ctypes import c_int
 
 from . import NGS
-from String import getNGSValue
-from Fragment import Fragment
+from .String import getNGSValue
+from .Fragment import Fragment
 
 class FragmentIterator(Fragment):
     def nextFragment(self):
diff --git a/ngs-python/ngs/LibManager.py b/ngs-python/ngs/LibManager.py
index 9155937..c1d4359 100644
--- a/ngs-python/ngs/LibManager.py
+++ b/ngs-python/ngs/LibManager.py
@@ -1,15 +1,133 @@
+# ===========================================================================
+# 
+#                            PUBLIC DOMAIN NOTICE
+#               National Center for Biotechnology Information
+# 
+#  This software/database is a "United States Government Work" under the
+#  terms of the United States Copyright Act.  It was written as part of
+#  the author's official duties as a United States Government employee and
+#  thus cannot be copyrighted.  This software/database is freely available
+#  to the public for use. The National Library of Medicine and the U.S.
+#  Government have not placed any restriction on its use or reproduction.
+# 
+#  Although all reasonable efforts have been taken to ensure the accuracy
+#  and reliability of the software and data, the NLM and the U.S.
+#  Government do not and cannot warrant the performance or results that
+#  may be obtained by using this software or data. The NLM and the U.S.
+#  Government disclaim all warranties, express or implied, including
+#  warranties of performance, merchantability or fitness for any particular
+#  purpose.
+# 
+#  Please cite the author in any work or product based on this material.
+# 
+# ===========================================================================
+# 
+# 
+
 from ctypes import cdll, c_char, c_int, c_char_p, c_int32, c_int64, c_double, POINTER, c_size_t, c_void_p, c_uint64, c_uint32
-import os, tempfile, platform
+import os, sys, platform, tempfile
+if sys.version_info[0] > 2:
+    from urllib.parse import urlencode
+    from urllib.request import urlopen
+else:
+    from urllib import urlencode
+    from urllib2 import urlopen
 
-from ErrorMsg import check_res_embedded
+from .ErrorMsg import check_res_embedded
+from . import ErrorMsg
 
-class LibManager:
-    # lib_path_engine = "/home/ukrainch/centos/gcc/x86_64/rel/lib/libncbi-vdb.so"
-    # lib_path_sdk = "/home/ukrainch/ncbi-outdir/ngs-sdk/x86_64/lib/libngs-sdk.so"
+def machine():
+    """Return type of machine."""
+    if os.name == 'nt' and sys.version_info[:2] < (2,7):
+        return os.environ.get("PROCESSOR_ARCHITEW6432", 
+               os.environ.get('PROCESSOR_ARCHITECTURE', ''))
+    else:
+        return platform.machine()
+
+def os_bits(machine=machine()):
+    """Return bitness of operating system, or None if unknown."""
+    machine2bits = {'AMD64': 64, 'x86_64': 64, 'i386': 32, 'x86': 32}
+    return machine2bits.get(machine, None)
+
+def lib_filename(lib_name):
+    return "lib"+lib_name+LibManager.get_lib_extension()
+    
+def load_saved_library(lib_name):
+    """search library in different possible locations
+    and load it if found
+    """
+    lib = None
+        
+    for dir in LibManager.get_directories_to_find_dll():
+        try:
+            lib = cdll.LoadLibrary(os.path.join(dir, lib_filename(lib_name) ))
+            if lib:
+                break
+        except OSError:
+            pass
+    
+    return lib
+
+def load_updated_library(lib_name):
+    """download library from ncbi and load it
+    """
+    directory_created = (False, None)
+    file_created      = (False, None)
+    file_saved        = (False, None)
+    for dir in LibManager.get_directories_to_find_dll():
+        try:
+            if not dir:
+                continue
+            if not os.path.exists(dir):
+                os.makedirs(dir)
+            directory_created = (True, dir)
+        except:
+            directory_created = (False, dir)
+            continue
+
+        lib_path = os.path.join(dir, lib_filename(lib_name))
+        
+        try:
+            f = open(lib_path, "wb")
+            file_created = (True, lib_path)
+        except:
+            file_created = (False, lib_path)
+            continue
+
+        params = urlencode({
+            'cmd':     'lib',
+            'libname': lib_name,
+            'os_name': LibManager.get_post_os_name_param(),
+            'bits':    str(os_bits())
+        })
+        resp = urlopen(url=LibManager.URL_NCBI_SRATOOLKIT, data=params.encode())
+        if resp.code != 200:
+            raise ErrorMsg("Failed to download dll: url=" + LibManager.URL_NCBI_SRATOOLKIT + "; params=" + params + "; response code=" + str(resp.code))
+        
+        try:
+            f.write(resp.read())
+            f.close()
+            file_saved = (True, lib_path)
+        except:
+            file_saved = (False, lib_path)
+            continue
+            
+        return cdll.LoadLibrary(lib_path)
     
+    if not directory_created[0]:
+        raise ErrorMsg("Failed to create directory '" + directory_created[1] + "' for " + lib_filename(lib_name))
+    elif not file_created[0]:
+        raise ErrorMsg("Failed to create file " + file_created[1])
+    elif not file_saved[0]:
+        raise ErrorMsg("Failed to save file " + file_saved[1])
+
+    
+class LibManager:
     c_lib_engine = None
     c_lib_sdk = None
     
+    URL_NCBI_SRATOOLKIT = 'http://trace.ncbi.nlm.nih.gov/Traces/sratoolkit/sratoolkit.cgi'
+    
     def _bind(self, c_lib, c_func_name_str, param_types_list, errorcheck):
         setattr(self, c_func_name_str, getattr(c_lib, c_func_name_str))
         func = getattr(self, c_func_name_str)
@@ -21,51 +139,43 @@ class LibManager:
     def bind_sdk(self, c_func_name_str, param_types_list):
         return self._bind(self.c_lib_sdk, c_func_name_str, param_types_list, check_res_embedded)
     
-    def resolve_libpath(self, lib_filename):
-        # Try to load so from the root of ngs package
-        #full_path = os.path.join(os.path.dirname(__file__), lib_filename)
-        full_path = lib_filename
-        return full_path
-        
-        # TODO: cannot check path to dll with isfile()
-        # waiting on VDB-1296 to modify this function or
-        # get rid of it at all
-        if not os.path.isfile(full_path):
-            full_path = "./" + lib_filename # Try to load just by filename (CWD, PATH?)
-            
-        if not os.path.isfile(full_path):
-            full_path = os.path.join(tempfile.gettempdir(), lib_filename) # Try to load from TMP
-        
-        # TODO: add more options here (download from ncbi, known path)
-        
-        if not os.path.isfile(full_path): # nothing worked - cannot resolve path
-            raise RuntimeError("FAILED to resolve path for " + lib_filename)
+    @staticmethod
+    def get_directories_to_find_dll():
+        return (
+            os.path.join(os.path.expanduser('~'), ".ncbi", "lib"+str(os_bits())),
+            "",
+            ".",
+            tempfile.gettempdir(),
+        )
+    
+    @staticmethod
+    def get_post_os_name_param():
+        if (platform.system() == "Darwin"):
+            return "Mac"
+        else:
+            return platform.system()
         
-        return full_path
-
     @staticmethod
     def get_lib_extension():
         if platform.system() == "Windows":
-            return "dll"
-        #elif platform.name() == "": # TODO: add mac os
+            return ".dll"
+        elif platform.system() == "Darwin":
+            return ""
+        elif platform.system() == "Linux":
+            return ".so"
         else:
-            return "so"
+            return ""
     
     def initialize_ngs_bindings(self):
         if self.c_lib_engine and self.c_lib_sdk: # already initialized
             return
 
-        lib_ext = "." + LibManager.get_lib_extension()
-        
-        libname_engine = "libncbi-vdb" + lib_ext
-        libname_sdk = "libngs-sdk" + lib_ext
+        libname_engine = "ncbi-vdb"
+        libname_sdk = "ngs-sdk"
 
-        path_engine = self.resolve_libpath(libname_engine)
-        path_sdk = self.resolve_libpath(libname_sdk)
+        self.c_lib_engine = load_saved_library(libname_engine) or load_updated_library(libname_engine)
+        self.c_lib_sdk = load_saved_library(libname_sdk) or load_updated_library(libname_sdk)
         
-        self.c_lib_engine = cdll.LoadLibrary(path_engine)
-        self.c_lib_sdk = cdll.LoadLibrary(path_sdk)
-
         ##############  ngs-engine imports below  ####################
         
         self._bind(self.c_lib_engine, "PY_NGS_Engine_ReadCollectionMake", [c_char_p, POINTER(c_void_p), POINTER(c_char), c_size_t], None)
@@ -117,6 +227,7 @@ class LibManager:
         self.bind_sdk("PY_NGS_AlignmentGetTemplateLength",            [c_void_p, POINTER(c_uint64), POINTER(c_void_p)])
         self.bind_sdk("PY_NGS_AlignmentGetShortCigar",                [c_void_p, c_int, POINTER(c_void_p), POINTER(c_void_p)])
         self.bind_sdk("PY_NGS_AlignmentGetLongCigar",                 [c_void_p, c_int, POINTER(c_void_p), POINTER(c_void_p)])
+        self.bind_sdk("PY_NGS_AlignmentGetRNAOrientation",            [c_void_p, POINTER(c_char), POINTER(c_void_p)])
         self.bind_sdk("PY_NGS_AlignmentHasMate",                      [c_void_p, POINTER(c_int), POINTER(c_void_p)])
         self.bind_sdk("PY_NGS_AlignmentGetMateAlignmentId",           [c_void_p, POINTER(c_void_p), POINTER(c_void_p)])
         self.bind_sdk("PY_NGS_AlignmentGetMateAlignment",             [c_void_p, POINTER(c_void_p), POINTER(c_void_p)])
diff --git a/ngs-python/ngs/Pileup.py b/ngs-python/ngs/Pileup.py
index ad16429..46bd835 100644
--- a/ngs-python/ngs/Pileup.py
+++ b/ngs-python/ngs/Pileup.py
@@ -27,10 +27,10 @@
 from ctypes import c_void_p, c_uint32, c_int64
 from . import NGS
 
-from String import getNGSString, getNGSValue
-from Refcount import Refcount
+from .String import getNGSString, getNGSValue
+from .Refcount import Refcount
 
-from PileupEventIterator import PileupEventIterator
+from .PileupEventIterator import PileupEventIterator
 
 # Represents a slice through a stack of Alignments at a given position on the Reference
 
diff --git a/ngs-python/ngs/PileupEvent.py b/ngs-python/ngs/PileupEvent.py
index 9c3c4bf..e1e3117 100644
--- a/ngs-python/ngs/PileupEvent.py
+++ b/ngs-python/ngs/PileupEvent.py
@@ -26,10 +26,10 @@
 from ctypes import c_char, c_int32, c_uint32, c_int64, c_void_p
 from . import NGS
 
-from String import getNGSString, getNGSValue
-from Refcount import Refcount
+from .String import getNGSString, getNGSValue
+from .Refcount import Refcount
 
-from Alignment import Alignment
+from .Alignment import Alignment
 
 
 # Represents a single cell of a sparse 2D matrix with Reference coordinates on one axis
diff --git a/ngs-python/ngs/PileupEventIterator.py b/ngs-python/ngs/PileupEventIterator.py
index 06602ab..a0d4d39 100644
--- a/ngs-python/ngs/PileupEventIterator.py
+++ b/ngs-python/ngs/PileupEventIterator.py
@@ -27,8 +27,8 @@
 from ctypes import c_int
 
 from . import NGS
-from String import getNGSValue
-from PileupEvent import PileupEvent
+from .String import getNGSValue
+from .PileupEvent import PileupEvent
 
 #Iterates across a list of PileupEvents
 
diff --git a/ngs-python/ngs/PileupIterator.py b/ngs-python/ngs/PileupIterator.py
index 9b99c02..430bd1d 100644
--- a/ngs-python/ngs/PileupIterator.py
+++ b/ngs-python/ngs/PileupIterator.py
@@ -27,8 +27,8 @@
 from ctypes import c_int
 
 from . import NGS
-from String import getNGSValue
-from Pileup import Pileup
+from .String import getNGSValue
+from .Pileup import Pileup
 
 # Iterates across a list of Pileups
 
diff --git a/ngs-python/ngs/Read.py b/ngs-python/ngs/Read.py
index b4b7bef..84595fd 100644
--- a/ngs-python/ngs/Read.py
+++ b/ngs-python/ngs/Read.py
@@ -27,8 +27,8 @@
 from ctypes import byref, c_uint32
 from . import NGS
 
-from String import NGS_String, NGS_RawString, getNGSString, getNGSValue
-from FragmentIterator import FragmentIterator
+from .String import NGS_String, NGS_RawString, getNGSString, getNGSValue
+from .FragmentIterator import FragmentIterator
 
     # Read
     # represents an NGS machine read
@@ -70,9 +70,16 @@ class Read(FragmentIterator):
         :param: length must be >= 0
         :returns: sequence bases
         """
-        with NGS_RawString() as ngs_str_err, NGS_String() as ngs_str_seq:
-            res = NGS.lib_manager.PY_NGS_ReadGetReadBases(self.ref, offset, length, byref(ngs_str_seq.ref), byref(ngs_str_err.ref))
-            return ngs_str_seq.getPyString()
+        ngs_str_err = NGS_RawString()
+        try:
+            ngs_str_seq = NGS_String()
+            try:
+                res = NGS.lib_manager.PY_NGS_ReadGetReadBases(self.ref, offset, length, byref(ngs_str_seq.ref), byref(ngs_str_err.ref))
+                return ngs_str_seq.getPyString()
+            finally:
+                ngs_str_seq.close()
+        finally:
+            ngs_str_err.close()
         
     def getReadQualities(self, offset=0, length=-1):
         """
@@ -80,7 +87,13 @@ class Read(FragmentIterator):
         :param: length must be >= 0
         :returns: phred quality values using ASCII offset of 33
         """
-        with NGS_RawString() as ngs_str_err, NGS_String() as ngs_str_seq:
-            res = NGS.lib_manager.PY_NGS_ReadGetReadQualities(self.ref, offset, length, byref(ngs_str_seq.ref), byref(ngs_str_err.ref))
-            return ngs_str_seq.getPyString()
-
+        ngs_str_err = NGS_RawString()
+        try:
+            ngs_str_seq = NGS_String()
+            try:
+                res = NGS.lib_manager.PY_NGS_ReadGetReadQualities(self.ref, offset, length, byref(ngs_str_seq.ref), byref(ngs_str_err.ref))
+                return ngs_str_seq.getPyString()
+            finally:
+                ngs_str_seq.close()
+        finally:
+            ngs_str_err.close()
diff --git a/ngs-python/ngs/ReadCollection.py b/ngs-python/ngs/ReadCollection.py
index dac7ae6..13619ca 100644
--- a/ngs-python/ngs/ReadCollection.py
+++ b/ngs-python/ngs/ReadCollection.py
@@ -25,20 +25,20 @@
 # 
 
 
-from ctypes import c_void_p, c_uint64, byref, create_string_buffer
+from ctypes import c_void_p, c_uint64, byref, create_string_buffer, c_char_p
 from . import NGS
-
-from Refcount import Refcount
-from ErrorMsg import ErrorMsg
-from String import NGS_RawString, getNGSString, getNGSValue
-from Read import Read
-from ReadIterator import ReadIterator
-from ReadGroup import ReadGroup
-from ReadGroupIterator import ReadGroupIterator
-from Reference import Reference
-from ReferenceIterator import ReferenceIterator
-from Alignment import Alignment
-from AlignmentIterator import AlignmentIterator
+    
+from .Refcount import Refcount
+from .ErrorMsg import ErrorMsg
+from .String import NGS_RawString, getNGSString, getNGSValue
+from .Read import Read
+from .ReadIterator import ReadIterator
+from .ReadGroup import ReadGroup
+from .ReadGroupIterator import ReadGroupIterator
+from .Reference import Reference
+from .ReferenceIterator import ReferenceIterator
+from .Alignment import Alignment
+from .AlignmentIterator import AlignmentIterator
 
 class ReadCollection(Refcount):
     """Represents an NGS-capable object with a collection of
@@ -93,9 +93,11 @@ class ReadCollection(Refcount):
         :throws: ErrorMsg upon an error accessing data
         """
         ret = ReadGroup()
-
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_ReadCollectionGetReadGroup(self.ref, spec, byref(ret.ref), byref(ngs_str_err.ref))
+        finally:
+            ngs_str_err.close()
         
         return ret
     
@@ -116,9 +118,11 @@ class ReadCollection(Refcount):
 
     def getReference(self, spec):
         ret = Reference()
-
-        with NGS_RawString() as ngs_str_err:
-            res = NGS.lib_manager.PY_NGS_ReadCollectionGetReference(self.ref, spec, byref(ret.ref), byref(ngs_str_err.ref))
+        ngs_str_err = NGS_RawString()
+        try:
+            res = NGS.lib_manager.PY_NGS_ReadCollectionGetReference(self.ref, spec.encode(), byref(ret.ref), byref(ngs_str_err.ref))
+        finally:
+            ngs_str_err.close()
         
         return ret
         
@@ -130,10 +134,12 @@ class ReadCollection(Refcount):
         :throws: ErrorMsg if Alignment does not exist
         """
         ret = Alignment()
-
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_ReadCollectionGetAlignment(self.ref, alignmentId, byref(ret.ref), byref(ngs_str_err.ref))
-        
+        finally:
+            ngs_str_err.close()
+
         return ret
     
     # AlignmentCategory
@@ -144,10 +150,12 @@ class ReadCollection(Refcount):
         :returns: an iterator of all Alignments from specified categories
         """
         ret = AlignmentIterator()
-
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_ReadCollectionGetAlignments(self.ref, categories, byref(ret.ref), byref(ngs_str_err.ref))
-        
+        finally:
+            ngs_str_err.close()
+
         return ret
         
     def getAlignmentCount(self, categories=Alignment.all):
@@ -155,10 +163,12 @@ class ReadCollection(Refcount):
         :returns: count of all alignments
         '''
         ret = c_uint64()
-
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_ReadCollectionGetAlignmentCount(self.ref, categories, byref(ret), byref(ngs_str_err.ref))
-        
+        finally:
+            ngs_str_err.close()
+
         return ret.value
         
     def getAlignmentRange(self, first, count, categories=Alignment.all): # TODO: parameters order!
@@ -167,10 +177,12 @@ class ReadCollection(Refcount):
         :returns: an iterator across a range of Alignments
         '''
         ret = AlignmentIterator()
-
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_ReadCollectionGetAlignmentRange(self.ref, first, count, categories, byref(ret.ref), byref(ngs_str_err.ref))
-        
+        finally:
+            ngs_str_err.close()
+
         return ret
 
     #----------------------------------------------------------------------
@@ -182,10 +194,12 @@ class ReadCollection(Refcount):
         :throws: ErrorMsg if Read does not exist
         """
         ret = Read()
-
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_ReadCollectionGetRead(self.ref, readId, byref(ret.ref), byref(ngs_str_err.ref))
-        
+        finally:
+            ngs_str_err.close()
+
         return ret
     
     # ReadCategory
@@ -196,10 +210,12 @@ class ReadCollection(Refcount):
         :returns: an iterator of all contained machine Reads
         """
         ret = ReadIterator()
-
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_ReadCollectionGetReads(self.ref, categories, byref(ret.ref), byref(ngs_str_err.ref))
-        
+        finally:
+            ngs_str_err.close()
+
         return ret
 
     def getReadCount(self, categories=Read.all):
@@ -207,18 +223,22 @@ class ReadCollection(Refcount):
         :returns: the number of reads in the collection
         """
         ret = c_uint64()
-
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_ReadCollectionGetReadCount(self.ref, categories, byref(ret), byref(ngs_str_err.ref))
-        
+        finally:
+            ngs_str_err.close()
+
         return ret.value
 
     def getReadRange(self, first, count, categories=Read.all):
         ret = ReadIterator()
-
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_ReadCollectionGetReadRange(self.ref, first, count, categories, byref(ret.ref), byref(ngs_str_err.ref))
-        
+        finally:
+            ngs_str_err.close()
+
         return ret
 
 
@@ -235,9 +255,8 @@ def openReadCollection(spec):
     ret = ReadCollection()
     ERROR_BUFFER_SIZE = 4096
     str_err = create_string_buffer(ERROR_BUFFER_SIZE)
-    from ctypes import cast
     from . import PY_RES_OK
-    res = NGS.lib_manager.PY_NGS_Engine_ReadCollectionMake(spec, byref(ret.ref), str_err, len(str_err))
+    res = NGS.lib_manager.PY_NGS_Engine_ReadCollectionMake(spec.encode(), byref(ret.ref), str_err, len(str_err))
     if res != PY_RES_OK:
         raise ErrorMsg(str_err.value)
         
diff --git a/ngs-python/ngs/ReadGroup.py b/ngs-python/ngs/ReadGroup.py
index ab113d5..96a44eb 100644
--- a/ngs-python/ngs/ReadGroup.py
+++ b/ngs-python/ngs/ReadGroup.py
@@ -27,10 +27,10 @@
 from ctypes import c_void_p
 from . import NGS
 
-from Refcount import Refcount
-from String import getNGSString, getNGSValue
+from .Refcount import Refcount
+from .String import getNGSString, getNGSValue
 
-from Statistics import Statistics
+from .Statistics import Statistics
 
 # Represents an NGS-capable object with a group of Reads
 
diff --git a/ngs-python/ngs/ReadGroupIterator.py b/ngs-python/ngs/ReadGroupIterator.py
index db58bc0..519a8c3 100644
--- a/ngs-python/ngs/ReadGroupIterator.py
+++ b/ngs-python/ngs/ReadGroupIterator.py
@@ -26,8 +26,8 @@
 
 from ctypes import c_int
 from . import NGS
-from String import getNGSValue
-from ReadGroup import ReadGroup
+from .String import getNGSValue
+from .ReadGroup import ReadGroup
 
 # Iterates across a list of ReadGroups
 
diff --git a/ngs-python/ngs/ReadIterator.py b/ngs-python/ngs/ReadIterator.py
index a623e1e..ea0cb49 100644
--- a/ngs-python/ngs/ReadIterator.py
+++ b/ngs-python/ngs/ReadIterator.py
@@ -27,8 +27,8 @@
 from ctypes import c_int
 
 from . import NGS
-from String import getNGSValue
-from Read import Read
+from .String import getNGSValue
+from .Read import Read
 
 # ReadIterator
 # iterates across a list of Reads
diff --git a/ngs-python/ngs/Refcount.py b/ngs-python/ngs/Refcount.py
index 8597a59..11784cb 100644
--- a/ngs-python/ngs/Refcount.py
+++ b/ngs-python/ngs/Refcount.py
@@ -1,7 +1,7 @@
 from ctypes import byref, c_void_p
 
 from . import NGS
-from String import NGS_RawString
+from .String import NGS_RawString
 
 def RefcountRelease(ref):
     """Releases NGS-object imported from ngs-sdk
@@ -10,8 +10,11 @@ def RefcountRelease(ref):
     :returns: None
     :throws: ErrorMsg
     """
-    with NGS_RawString() as ngs_str_err:
+    ngs_str_err = NGS_RawString()
+    try:
         res = NGS.lib_manager.PY_NGS_RefcountRelease(ref, byref(ngs_str_err.ref))
+    finally:
+        ngs_str_err.close()
 
 def RefcountRawStringRelease(ref):
     """Releases raw string imported from ngs-sdk
@@ -20,8 +23,11 @@ def RefcountRawStringRelease(ref):
     :returns: None
     :throws: ErrorMsg
     """
-    with NGS_RawString() as ngs_str_err:
+    ngs_str_err = NGS_RawString()
+    try:
         res = NGS.lib_manager.PY_NGS_RawStringRelease(ref, byref(ngs_str_err.ref))
+    finally:
+        ngs_str_err.close()
 
 # def RefcountEngineRelease(ref):
     # """Releases NGS-object imported from ngs engine
diff --git a/ngs-python/ngs/Reference.py b/ngs-python/ngs/Reference.py
index a791e3c..b63875b 100644
--- a/ngs-python/ngs/Reference.py
+++ b/ngs-python/ngs/Reference.py
@@ -26,12 +26,12 @@
 
 from ctypes import byref, c_int, c_uint64
 from . import NGS
-from Refcount import Refcount
-from String import NGS_RawString, NGS_String, getNGSString, getNGSValue
+from .Refcount import Refcount
+from .String import NGS_RawString, NGS_String, getNGSString, getNGSValue
 
-from Alignment import Alignment
-from AlignmentIterator import AlignmentIterator
-from PileupIterator import PileupIterator
+from .Alignment import Alignment
+from .AlignmentIterator import AlignmentIterator
+from .PileupIterator import PileupIterator
 
 # Represents a reference sequence
 
@@ -61,10 +61,17 @@ class Reference(Refcount):
         :param: length must be >= 0
         :returns: sub-sequence bases for Reference
         """
-        with NGS_RawString() as ngs_str_err, NGS_String() as ngs_str_ret:
-            res = NGS.lib_manager.PY_NGS_ReferenceGetReferenceBases(self.ref, offset, length, byref(ngs_str_ret.ref), byref(ngs_str_err.ref))
-            return ngs_str_ret.getPyString()
-    
+        ngs_str_err = NGS_RawString()
+        try:
+            ngs_str_ret = NGS_String()
+            try:
+                res = NGS.lib_manager.PY_NGS_ReferenceGetReferenceBases(self.ref, offset, length, byref(ngs_str_ret.ref), byref(ngs_str_err.ref))
+                return ngs_str_ret.getPyString()
+            finally:
+                ngs_str_ret.close()
+        finally:
+            ngs_str_err.close()
+
     def getReferenceChunk(self, offset, length=-1):
         """
         :param: offset is zero-based and non-negative
@@ -74,9 +81,16 @@ class Reference(Refcount):
         than requested. to obtain all bases available
         in chunk, use a negative "size" value
         """
-        with NGS_RawString() as ngs_str_err, NGS_String() as ngs_str_ret:
-            res = NGS.lib_manager.PY_NGS_ReferenceGetReferenceChunk(self.ref, offset, length, byref(ngs_str_ret.ref), byref(ngs_str_err.ref))
-            return ngs_str_ret.getPyString()
+        ngs_str_err = NGS_RawString()
+        try:
+            ngs_str_ret = NGS_String()
+            try:
+                res = NGS.lib_manager.PY_NGS_ReferenceGetReferenceChunk(self.ref, offset, length, byref(ngs_str_ret.ref), byref(ngs_str_err.ref))
+                return ngs_str_ret.getPyString()
+            finally:
+                ngs_str_ret.close()
+        finally:
+            ngs_str_err.close()
 
     # ----------------------------------------------------------------------
     # ALIGNMENTS
@@ -87,9 +101,11 @@ class Reference(Refcount):
         :throws: ErrorMsg if Alignment does not exist or is not part of this Reference
         """
         ret = Alignment()
-
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_ReferenceGetAlignment(self.ref, alignmentId, byref(ret.ref), byref(ngs_str_err.ref))
+        finally:
+            ngs_str_err.close()
         
         return ret
 
@@ -98,9 +114,11 @@ class Reference(Refcount):
         :returns: an iterator of contained alignments
         """
         ret = AlignmentIterator()
-        
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_ReferenceGetAlignments(self.ref, categories, byref(ret.ref), byref(ngs_str_err.ref))
+        finally:
+            ngs_str_err.close()
         
         return ret
 
@@ -112,9 +130,11 @@ class Reference(Refcount):
         :returns: an iterator across a range of Alignments
         """
         ret = AlignmentIterator()
-        
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_ReferenceGetAlignmentSlice(self.ref, start, length, categories, byref(ret.ref), byref(ngs_str_err.ref))
+        finally:
+            ngs_str_err.close()
         
         return ret
 
@@ -126,9 +146,11 @@ class Reference(Refcount):
         :returns: an iterator of contained Pileups
         """
         ret = PileupIterator()
-        
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_ReferenceGetPileups(self.ref, categories, byref(ret.ref), byref(ngs_str_err.ref))
+        finally:
+            ngs_str_err.close()
         
         return ret
 
@@ -140,9 +162,11 @@ class Reference(Refcount):
         :returns: an iterator of contained Pileups
         """
         ret = PileupIterator()
-        
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_ReferenceGetPileupSlice(self.ref, start, length, categories, byref(ret.ref), byref(ngs_str_err.ref))
+        finally:
+            ngs_str_err.close()
         
         return ret
     
diff --git a/ngs-python/ngs/ReferenceIterator.py b/ngs-python/ngs/ReferenceIterator.py
index d7cf9f8..ae8059e 100644
--- a/ngs-python/ngs/ReferenceIterator.py
+++ b/ngs-python/ngs/ReferenceIterator.py
@@ -27,8 +27,8 @@
 from ctypes import c_int
 
 from . import NGS
-from String import getNGSValue
-from Reference import Reference
+from .String import getNGSValue
+from .Reference import Reference
 
 # Iterates across a list of References
 
diff --git a/ngs-python/ngs/Statistics.py b/ngs-python/ngs/Statistics.py
index 1bbf30b..fc85965 100644
--- a/ngs-python/ngs/Statistics.py
+++ b/ngs-python/ngs/Statistics.py
@@ -27,8 +27,8 @@
 from ctypes import byref, c_uint32, c_int64, c_uint64, c_double
 from . import NGS
 
-from String import NGS_String, NGS_RawString, getNGSString, getNGSValue
-from Refcount import Refcount
+from .String import NGS_String, NGS_RawString, getNGSString, getNGSValue
+from .Refcount import Refcount
 
 # Statistical data container
 
@@ -41,8 +41,11 @@ class Statistics(Refcount):
 
     def getValueType(self, path):
         ret = c_uint32()
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_StatisticsGetValueType(self.ref, path, byref(ret), byref(ngs_str_err.ref))
+        finally:
+            ngs_str_err.close()
         
         return ret.value
 
@@ -52,9 +55,16 @@ class Statistics(Refcount):
         :returns: textual representation of value
         :throws: ErrorMsg if path not found or value cannot be converted
         """
-        with NGS_RawString() as ngs_str_err, NGS_String() as ngs_str_ret:
-            res = NGS.lib_manager.PY_NGS_StatisticsGetAsString(self.ref, path, byref(ngs_str_ret.ref), byref(ngs_str_err.ref))
-            return ngs_str_ret.getPyString()
+        ngs_str_err = NGS_RawString()
+        try:
+            ngs_str_ret = NGS_String()
+            try:
+                res = NGS.lib_manager.PY_NGS_StatisticsGetAsString(self.ref, path, byref(ngs_str_ret.ref), byref(ngs_str_err.ref))
+                return ngs_str_ret.getPyString()
+            finally:
+                ngs_str_ret.close()
+        finally:
+            ngs_str_err.close()
 
     def getAsI64(self, path):
         """
@@ -63,8 +73,11 @@ class Statistics(Refcount):
         :throws: ErrorMsg if path not found or value cannot be converted
         """
         ret = c_int64()
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_StatisticsGetAsI64(self.ref, path, byref(ret), byref(ngs_str_err.ref))
+        finally:
+            ngs_str_err.close()
         
         return ret.value
 
@@ -75,8 +88,11 @@ class Statistics(Refcount):
         :throws: ErrorMsg if path not found or value cannot be converted
         """
         ret = c_uint64()
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_StatisticsGetAsU64(self.ref, path, byref(ret), byref(ngs_str_err.ref))
+        finally:
+            ngs_str_err.close()
         
         return ret.value
 
@@ -87,8 +103,11 @@ class Statistics(Refcount):
         :throws: ErrorMsg if path not found or value cannot be converted
         """
         ret = c_double()
-        with NGS_RawString() as ngs_str_err:
+        ngs_str_err = NGS_RawString()
+        try:
             res = NGS.lib_manager.PY_NGS_StatisticsGetAsDouble(self.ref, path, byref(ret), byref(ngs_str_err.ref))
+        finally:
+            ngs_str_err.close()
         
         return ret.value
 
@@ -97,6 +116,13 @@ class Statistics(Refcount):
         :param: path is null or empty to request first path, or a valid path string
         :returns: null if no more paths, or a valid path string
         """
-        with NGS_RawString() as ngs_str_err, NGS_String() as ngs_str_ret:
-            res = NGS.lib_manager.PY_NGS_StatisticsGetNextPath(self.ref, path, byref(ngs_str_ret.ref), byref(ngs_str_err.ref))
-            return ngs_str_ret.getPyString()
+        ngs_str_err = NGS_RawString()
+        try:
+            ngs_str_ret = NGS_String()
+            try:
+                res = NGS.lib_manager.PY_NGS_StatisticsGetNextPath(self.ref, path, byref(ngs_str_ret.ref), byref(ngs_str_err.ref))
+                return ngs_str_ret.getPyString()
+            finally:
+                ngs_str_ret.close()
+        finally:
+            ngs_str_err.close()
diff --git a/ngs-python/ngs/String.py b/ngs-python/ngs/String.py
index c35dcc1..0225386 100644
--- a/ngs-python/ngs/String.py
+++ b/ngs-python/ngs/String.py
@@ -47,7 +47,7 @@ class NGS_String:
 
     def close(self):
         if self.ref:
-            from Refcount import RefcountRelease
+            from .Refcount import RefcountRelease
             RefcountRelease(self.ref)
             self.init_members_with_null()
             
@@ -71,7 +71,7 @@ class NGS_String:
         return self.size.value
         
     def getPyString(self):
-        return string_at(self.getData(), self.getSize())
+        return string_at(self.getData(), self.getSize()).decode()
 
 
 class NGS_RawString:
@@ -117,7 +117,7 @@ class NGS_RawString:
         return len(self.ref_to_char_p().value)
         
     def getPyString(self):
-        return string_at(self.getData(), self.getSize())
+        return string_at(self.getData(), self.getSize()).decode()
 
 
 def getNGSString(self, py_func):
@@ -130,10 +130,17 @@ def getNGSString(self, py_func):
     
     :remarks: NGS_String object is automatically released after this function returns
     """
-    with NGS_RawString() as ngs_str_err, NGS_String() as ngs_str_seq:
-        res = py_func(self.ref, byref(ngs_str_seq.ref), byref(ngs_str_err.ref))
-        #check_res(res, ngs_str_err)
-        return ngs_str_seq.getPyString()
+    ngs_str_err = NGS_RawString()
+    try:
+        ngs_str_seq = NGS_String()
+        try:
+            res = py_func(self.ref, byref(ngs_str_seq.ref), byref(ngs_str_err.ref))
+            #check_res(res, ngs_str_err)
+            return ngs_str_seq.getPyString()
+        finally:
+            ngs_str_seq.close()
+    finally:
+        ngs_str_err.close()
 
         
 def getNGSValue(self, py_func, value_type):
@@ -146,9 +153,12 @@ def getNGSValue(self, py_func, value_type):
     :throws: ErrorMsg
     """
     ret = value_type()
-    with NGS_RawString() as ngs_str_err:
+    ngs_str_err = NGS_RawString()
+    try:
         res = py_func(self.ref, byref(ret), byref(ngs_str_err.ref))
         #check_res(res, ngs_str_err)
+    finally:
+        ngs_str_err.close()
     
     return ret.value
 
diff --git a/ngs-python/ngs/__init__.py b/ngs-python/ngs/__init__.py
index 8bf6ef3..4fd14da 100644
--- a/ngs-python/ngs/__init__.py
+++ b/ngs-python/ngs/__init__.py
@@ -37,7 +37,7 @@ class NGS:
     def openReadCollection(spec):
         NGS.lib_manager.initialize_ngs_bindings()
     
-        from ReadCollection import openReadCollection  # entry point - adding name to ngs package global namespace
+        from .ReadCollection import openReadCollection  # entry point - adding name to ngs package global namespace
         return openReadCollection(spec)
 
 
diff --git a/ngs-python/setup.py b/ngs-python/setup.py
index 6275d08..fd48903 100644
--- a/ngs-python/setup.py
+++ b/ngs-python/setup.py
@@ -1,15 +1,15 @@
-from setuptools import setup
+from distutils.core import setup
 import sys
 #import version
 
 #ver = version.get_git_version()
 
 decimal_ver = sys.version_info[0]*10 + sys.version_info[1]
-min_version = 27
+min_version = 26
 
 if decimal_ver < min_version:
-    print ("At least python {} is required to run ngs package, and you're using {}".format(min_version/10., decimal_ver/10.))
-    exit()
+    print ("At least python " + str(min_version/10.) + " is required to automatically install ngs package, and you're using " + str(decimal_ver/10.))
+    exit(1)
 
 setup(name='ngs',
       #version=ver,
diff --git a/ngs-python/configure b/ngs-python/setup/install
similarity index 83%
copy from ngs-python/configure
copy to ngs-python/setup/install
index 3313aac..4dcf8cf 100755
--- a/ngs-python/configure
+++ b/ngs-python/setup/install
@@ -29,17 +29,17 @@ CURDIR="`dirname $0`"
 
 if [ -z "$CURDIR" ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
     exit 1
 fi
 
-if [ "$FILENAME" != configure -a ! -s konfigure.perl ]
+if [ "$FILENAME" != install -a ! -s install.perl ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
 else
     perl -v > /dev/null 2>&1 || { echo "checking for perl... no"; \
-        echo >&2 "configure: error: perl not found."; exit 1; }
+        echo >&2 "error: perl not found."; exit 1; }
 
     cd $CURDIR
-    perl -w ./konfigure.perl $@
+    perl -w ./install.perl "$@"
 fi
diff --git a/ngs-python/setup/install.perl b/ngs-python/setup/install.perl
new file mode 100644
index 0000000..5e5f33e
--- /dev/null
+++ b/ngs-python/setup/install.perl
@@ -0,0 +1,1324 @@
+################################################################################
+
+use strict;
+
+require 'install.prl';
+
+use Config;
+use Cwd        "abs_path";
+use File::Copy "copy";
+use File::Copy::Recursive qw(dircopy);
+use File::Path   "make_path";
+use FindBin    qw($Bin);
+use Getopt::Long "GetOptions";
+
+my ($OS, $MAKING, %INSTALLED_LIBS);
+{
+    my $file = 'os.prl';
+    if (-e $file) {
+        require $file;
+        $OS = OS();
+    } else {
+        ++$MAKING;
+    }
+}
+
+my %HAVE = HAVE();
+BINS() if ($HAVE{BINS});
+if ($HAVE{LIBS}) {
+    ++$HAVE{INCLUDES};
+    LIBS();
+}
+if ($HAVE{INCLUDES} || $HAVE{USR_INCLUDES}) {
+    die "no INCLUDES" unless INCLUDES();
+}
+die "no CONFIG_OUT" unless CONFIG_OUT();
+
+my @bits;
+my @options = ( 'debug', 'examplesdir=s', 'force', 'help',
+                'includedir=s', 'no-create', 'prefix=s', 'root=s', );
+push @options, 'oldincludedir=s' if ($HAVE{USR_INCLUDES});
+if ($HAVE{JAR}) {
+    push @options, 'jardir=s';
+    if (-e "$Bin/../jar") {
+        ++$HAVE{LIBS};
+        $_{JARDIR} = expand_path("$Bin/../jar");
+    }
+} elsif ($HAVE{PYTHON} && ! $MAKING) {
+    ++$HAVE{LIBS};
+}
+if (! $MAKING && ($HAVE{JAR} || $HAVE{PYTHON})) {
+    ++$HAVE{TWO_LIBS};
+    push @options, 'ngslibdir=s', 'vdblibdir=s';
+}
+push @options, 'bindir=s'                     if ($HAVE{BINS});
+push @options, 'bits=s' => \@bits, 'libdir=s' if ($HAVE{LIBS});
+
+my %OPT;
+unless (GetOptions(\%OPT, @options)) {
+    print "install: error\n";
+    exit 1;
+}
+ at bits = split(/,/,join(',', at bits));
+foreach (@bits) {
+    unless (/^32$/ || /^64$/) {
+        print "install: error: bad bits option argument value\n";
+        exit 1;
+    }
+}
+if ($#bits > 0) {
+    foreach (qw(bindir libdir ngslibdir vdblibdir)) {
+        if ($OPT{$_}) {
+            print "install: error: cannot supply multiple bits arguments "
+                . "when $_ argument is provided\n";
+            exit 1;
+        }
+    }
+}
+
+$OPT{root} = expand_path($OPT{root}) if ($OPT{root});
+
+prepare();
+
+my $LINUX_ROOT;
+++$LINUX_ROOT if (linux_root());
+my $ROOT = '';
+if ($OPT{root}) {
+    $ROOT = "$OPT{root}/root";
+    ++$LINUX_ROOT;
+    foreach ("$ROOT/usr/include", "$ROOT/etc/profile.d") {
+        unless (-e $_) {
+            print "mkdir -p $_... ";
+            eval { make_path($_) };
+            if ($@) {
+                print "failure: $@\n";
+                exit 1;
+            }
+            print "ok\n";
+        }
+    }
+}
+
+my $oldincludedir = "$ROOT/usr/include";
+
+my $EXAMPLES_DIR = "$Bin/../examples";
+
+ at _ = CONFIGURE();
+
+if ($OPT{help}) {
+    help();
+    exit 0;
+}
+
+foreach (qw(BITS INCDIR
+ INST_INCDIR INST_JARDIR INST_LIBDIR INST_NGSLIBDIR INST_SHAREDIR INST_VDBLIBDIR
+ LIBX LPFX MAJVERS MAJVERS_SHLX OS OTHER_PREFIX
+ PACKAGE_NAME PREFIX SHLX VERSION VERSION_LIBX VERSION_SHLX))
+{
+    unless ($_{$_}) {
+        next if (/^INST_JARDIR$/    && ! $HAVE{JAR});
+        next if (/^INST_NGSLIBDIR$/ && ! $HAVE{TWO_LIBS});
+        next if (/^INST_SHAREDIR$/  && ! $HAVE{EXAMPLES});
+        next if (/^INST_VDBLIBDIR$/ && ! $HAVE{TWO_LIBS});
+        fatal_config("$_ not found");
+    }
+}
+unless ($_{LIBDIR32} || $_{LIBDIR64} || ($HAVE{PYTHON} && $MAKING)) {
+    fatal_config('LIBDIR not found');
+}
+ 
+if ($OPT{prefix}) {
+    $OPT{prefix} = expand_path($OPT{prefix});
+    $_{INST_BINDIR  } = "$OPT{prefix}/bin";
+    $_{INST_LIBDIR  } = "$OPT{prefix}/lib";
+    $_{INST_NGSLIBDIR} = $_{INST_VDBLIBDIR} = $_{INST_LIBDIR};
+    $_{INST_INCDIR  } = "$OPT{prefix}/include";
+    $_{INST_JARDIR  } = "$OPT{prefix}/jar";
+    $_{INST_SHAREDIR} = "$OPT{prefix}/share";
+}
+$_{INST_SHAREDIR} = expand_path($OPT{examplesdir  }) if ($OPT{examplesdir  });
+$_{INST_INCDIR  } = expand_path($OPT{includedir   }) if ($OPT{includedir   });
+$_{INST_JARDIR  } = expand_path($OPT{jardir       }) if ($OPT{jardir       });
+$_{BIN_TARGET   } = expand_path($OPT{bindir       }) if ($OPT{bindir       });
+$oldincludedir    = expand_path($OPT{oldincludedir}) if ($OPT{oldincludedir});
+if ($OPT{libdir}) {
+    $_{INST_NGSLIBDIR} = $_{LIB_TARGET} = expand_path($OPT{libdir}) ;
+    $_{INST_VDBLIBDIR} = $_{LIB_TARGET};
+}
+$_{INST_NGSLIBDIR}= expand_path($OPT{ngslibdir}) if ($OPT{ngslibdir});
+$_{INST_VDBLIBDIR}= expand_path($OPT{vdblibdir}) if ($OPT{vdblibdir});
+
+if ($OPT{'no-create'} && $_{OS} eq 'linux') {
+    if ($LINUX_ROOT) {
+        print "root user\n\n";
+    } else {
+        print "non root user\n\n";
+    }
+}
+
+my $failures = 0;
+my $bFailure = 1;
+
+push @bits, $_{BITS} unless (@bits);
+foreach (@bits) {
+    $_{BITS} = $_;
+
+    print "installing $_{PACKAGE_NAME} ($_{VERSION}) package";
+    print " for $_{OS}-$_{BITS}" if ($HAVE{BINS} || $HAVE{LIBS});
+    print "...\n";
+
+    if ($HAVE{BINS}) {
+        $_{BINDIR} = $_{"BINDIR$_{BITS}"};
+        unless ($_{BINDIR}) {
+            print "install: error: $_{BITS}-bit version is not available\n\n";
+            next;
+        }
+    }
+    if ($HAVE{LIBS} || $HAVE{PYTHON}) {
+# ($_{LIBDIR} for python points where ngs-sdk and ncbi-vdb dynamic libraries
+# can be found to correctly set up LD_LIBRARY_PATH
+        $_{LIBDIR} = $_{"LIBDIR$_{BITS}"};
+        unless ($_{LIBDIR}) {
+            print "install: error: $_{BITS}-bit version is not available\n\n";
+            next;
+        }
+    }
+    if ($HAVE{JAR} && ! $_{JARDIR}) {
+        $_{JARDIR} = $_{"LIBDIR$_{BITS}"};
+        unless ($_{JARDIR}) {
+            if ($_{BITS} == 64) {
+                $_{JARDIR} = $_{LIBDIR32};
+            } else {
+                $_{JARDIR} = $_{LIBDIR64};
+            }
+            unless ($_{JARDIR}) {
+                print "install: error: jar file was not cannot found\n";
+                exit 1;
+            }
+        }
+    }
+    $bFailure = 0;
+
+    if ($OPT{'no-create'}) {
+        print     "includedir : '$_{INST_INCDIR  }'\n" if ($HAVE{INCLUDES  });
+        print     "libdir     : '$_{INST_LIBDIR}$_{BITS}'\n" if ($HAVE{LIBS});
+        print     "jardir     : '$_{INST_JARDIR  }'\n" if ($HAVE{JAR       });
+        print     "examplesdir: '$_{INST_SHAREDIR}'\n" if ($HAVE{EXAMPLES  });;
+        if ($LINUX_ROOT) {
+            print "oldincludedir: '$oldincludedir'\n"  if ($HAVE{USR_INCLUDES});
+        }
+        print "\n";
+        next;
+    }
+
+    $_{BIN_TARGET} = "$_{INST_BINDIR}$_{BITS}" unless ($OPT{bindir});
+    $_{LIB_TARGET} = "$_{INST_LIBDIR}$_{BITS}" unless ($OPT{libdir});
+
+    $File::Copy::Recursive::CPRFComp = 1;
+
+    $failures += copybins    () if ($HAVE{BINS});
+    $failures += copylibs    () if ($HAVE{LIBS});
+    $failures += copyincludes() if ($HAVE{INCLUDES});
+    $failures += copyjars    () if ($HAVE{JAR});
+    $failures += copyconfig  () if ($HAVE{CONFIG});
+
+    if ($HAVE{JAR}) {
+        $File::Copy::Recursive::CPRFComp = 0;
+        $failures += copydocs() ;
+        $File::Copy::Recursive::CPRFComp = 1;
+    }
+
+    $failures += copyexamples();
+    $failures += finishinstall() unless ($failures);
+
+    unless ($failures) {
+        print "\nsuccessfully installed $_{PACKAGE_NAME} ($_{VERSION}) package";
+    } else {
+        print "\nfailed to install $_{PACKAGE_NAME} ($_{VERSION}) package";
+    }
+    print " for $_{OS}-$_{BITS}" if ($HAVE{BINS} || $HAVE{LIBS});
+    print ".\n\n";
+}
+
+$failures = 1 if (!$failures && $bFailure);
+
+exit $failures;
+
+################################################################################
+
+sub copybins {
+    unless ($_{BIN_TARGET}) {
+        print "error: cannot install executables: no BIN_TARGET\n";
+        return 1;
+    }
+    my $s = $_{BINDIR};
+    my $d = $_{BIN_TARGET};
+    print "installing executables to $d...";
+    unless (-e $s) {
+        print " failure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+    print "\t\tcd $d\n" if ($OPT{debug});
+    chdir $d or die "cannot cd $d";
+    my $failures = 0;
+    foreach (BINS()) {
+        print "installing '$_'..." if ($OPT{debug});
+        my $df = "$_$_{VERSION_EXEX}";
+        my $sf = "$s/$df";
+        print "\n\t\t$sf -> $df\n\t" if ($OPT{debug});
+        unless (-e $sf) {
+            print " skipped\n" if ($OPT{debug});
+            next;
+        }
+        if ((! $OPT{force}) && (-e $df) && (-M $df < -M $sf)) {
+            print " found\n" if ($OPT{debug});
+        } else {
+            unless (copy($sf, $df)) {
+                print "failure\n";
+                print "install: error: cannot copy '$sf' '$df'.\n";
+                ++$failures;
+                next;
+            }
+            my $mode = 0755;
+            printf "\tchmod %o $df\n\t", $mode if ($OPT{debug});
+            unless (chmod($mode, $df)) {
+                print " failure\n" if ($OPT{debug});
+                print "install: error: cannot chmod '$df': $!\n";
+                ++$failures;
+                next;
+            }
+            unless (symlinks($_, $df, 'bin')) {
+                print " success\n" if ($OPT{debug});
+            } else {
+                print " failure\n" if ($OPT{debug});
+                ++$failures;
+            }
+        }
+    }
+    return $failures;
+}
+
+sub copyconfig {
+    my $d;
+    if ($LINUX_ROOT) {
+        $d = "$ROOT/etc";
+    }
+    elsif ($HAVE{BINS}) {
+        $d = $_{BIN_TARGET};
+        unless ($d) {
+            print
+               "error: cannot install configuration files: no BIN_TARGET\n";
+            return 1;
+        }
+    } else {
+        $d = $_{LIB_TARGET};
+        unless ($d) {
+            print
+               "error: cannot install configuration files: no LIB_TARGET\n";
+            return 1;
+        }
+    }
+    $d = File::Spec->catdir($d, 'ncbi');
+    my $kfg = File::Spec->catdir($Bin, '..', 'libs/kfg/default.kfg');
+    unless (-e $kfg) {
+        $kfg = File::Spec->catdir($Bin, '..', 'tools/vdb-copy/vdb-copy.kfg');
+    }
+    unless (-e $kfg) {
+        if ($_{BINDIR}) {
+            $kfg = File::Spec->catdir($_{BINDIR}, 'ncbi', 'vdb-copy.kfg');
+        } elsif ($_{LIBDIR}) {
+            $kfg = File::Spec->catdir($_{LIBDIR}, 'ncbi', 'default.kfg');
+            unless (-e $kfg) {
+                print
+                  "error: cannot install configuration files: no default.kfg\n";
+                return 1;
+            }
+        }
+    }
+    print "installing configuration files to $d... ";
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+    my $df = File::Spec->catdir($d, 'ncbi-vdb.kfg');
+    print "\t\t$kfg -> $df\n" if ($OPT{debug});
+    unless (copy($kfg, $df)) {
+        print "install: error: cannot copy '$kfg' '$df'.\n";
+        return 1;
+    } else {
+        print "success\n";
+        return 0;
+    }
+}
+
+sub copylibs {
+    die unless ($HAVE{LIBS});
+
+    my $s = $_{LIBDIR};
+    my $d = $_{LIB_TARGET};
+
+    print "installing libraries to $d... ";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    if ($HAVE{TWO_LIBS}) {
+        my $ngs = $_{INST_NGSLIBDIR};
+        if ($ngs && ! ($OPT{prefix} && $OPT{libdir} && $OPT{ngslibdir})) {
+            $ngs .= $_{BITS};
+        }
+        my $vdb = $_{INST_VDBLIBDIR};
+        if ($vdb && ! ($OPT{prefix} && $OPT{libdir} && $OPT{vdblibdir})) {
+            $vdb .= $_{BITS};
+        }
+        if ($ngs || $vdb) {
+            unless ($ngs && $vdb) {
+                $ngs = $d unless ($ngs);
+                $vdb = $d unless ($vdb);
+            }
+            $INSTALLED_LIBS{'ngs-sdk' } = $ngs;
+            $INSTALLED_LIBS{'ncbi-vdb'} = $vdb;
+        }
+    }
+    $INSTALLED_LIBS{0} = $d unless (%INSTALLED_LIBS);
+
+    foreach (keys %INSTALLED_LIBS) {
+        my $d = $INSTALLED_LIBS{$_};
+        print "\nchecking $d... ";
+        unless (-e $d) {
+            print "not found\n";
+            print "mkdir -p $d... ";
+            eval { make_path($d) };
+            if ($@) {
+                print "failure\ninstall: error: cannot mkdir $d\n";
+                return 1;
+            } else {
+                print "success\n";
+            }
+        } else {
+            print "exists\n";
+        }
+    }
+
+    return $MAKING ? copybldlibs($s, $d) : copydir($s, %INSTALLED_LIBS);
+}
+
+sub copybldlibs {
+    my ($s, $d) = @_;
+
+    print "\t\tcd $d\n" if ($OPT{debug});
+    chdir $d or die "cannot cd $d";
+
+    my $failures = 0;
+
+    my %LIBRARIES_TO_INSTALL = LIBS();
+    foreach (keys %LIBRARIES_TO_INSTALL) {
+        print "installing '$_'... ";
+
+        my $nb = "$_{LPFX}$_";
+        my $nv = "$nb.";
+        my $lib = 'dll';
+        if ($LIBRARIES_TO_INSTALL{$_} eq 'SHL') {
+            $nv .= $_{VERSION_SHLX};
+        } elsif ($LIBRARIES_TO_INSTALL{$_} eq 'LIB') {
+            $nv .= $_{VERSION_LIBX};
+            $lib = 'lib';
+        } else {
+            die "bad library type";
+        }
+
+        my $sf = "$s/$nv";
+        my $df = "$d/$nv";
+
+        print "\n\t\t$sf -> $df\n\t" if ($OPT{debug});
+
+        unless (-e $sf) {
+            print "failure\n";
+            print "install: error: '$sf' is not found.\n";
+            ++$failures;
+            next;
+        }
+
+        if ((! $OPT{force}) && (-e $df) && (-M $df < -M $sf)) {
+            print "found\n";
+        } else {
+            unless (copy($sf, $df)) {
+                print "failure\n";
+                print "install: error: cannot copy '$sf' '$df'.\n";
+                ++$failures;
+                next;
+            }
+            my $mode = 0644;
+            $mode = 0755 if ($lib eq 'dll');
+            printf "\tchmod %o $df\n\t", $mode if ($OPT{debug});
+            unless (chmod($mode, $df)) {
+                print "failure\n";
+                print "install: error: cannot chmod '$df': $!\n";
+                ++$failures;
+                next;
+            }
+            unless (symlinks($nb, $nv, $lib)) {
+                print "success\n";
+            } else {
+                print "failure\n";
+                ++$failures;
+            }
+        }
+    }
+
+    return $failures;
+}
+
+sub symlinks {
+    my ($nb, $nv, $type) = @_;
+
+    my @l;
+    if ($type eq 'lib') {
+        push @l, "$nb-static.$_{LIBX}";
+        push @l, "$nb.$_{LIBX}";
+        push @l, "$nb.$_{MAJVERS_LIBX}";
+    } elsif ($type eq 'dll') {
+        push @l, "$nb.$_{SHLX}";
+        push @l, "$nb.$_{MAJVERS_SHLX}";
+    } elsif ($type eq 'bin' || $type eq 'jar') {
+        push @l, $nb;
+        push @l, "$nb.$_{MAJVERS}";
+    } else {
+        print "failure\n";
+        print "install: error: unknown symlink type '$type'\n";
+        return 1;
+    }
+
+    my $failures = 0;
+
+    for (my $i = 0; $i <= $#l; ++$i) {
+        my $file = $l[$i];
+        if (-e $file) {
+            print "\trm $file\n\t" if ($OPT{debug});
+            unless (unlink $file) {
+                print "failure\n";
+                print "install: error: cannot rm '$file': $!\n";
+                ++$failures;
+                next;
+            }
+        }
+
+        my $o = $nv;
+        $o = $l[$i + 1] if ($i < $#l);
+
+        print "\tln -s $o $file\n\t" if ($OPT{debug});
+        unless (symlink $o, $file) {
+            print "failure\n";
+            print "install: error: cannot symlink '$o' '$file': $!\n";
+            ++$failures;
+            next;
+        }
+    }
+
+    return $failures;
+}
+
+sub copydir {
+    my ($s, %d) = @_;
+
+    my $failures = 0;
+
+    foreach my $pattern(keys %d) {
+        my $d = $d{$pattern};
+        print "\t\tcd $d\n" if ($OPT{debug});
+        chdir $d or die "cannot cd $d";
+
+        opendir(D, $s) or die "cannot opendir $s: $!";
+
+        while (readdir D) {
+            next if (/^\.{1,2}$/);
+            next if ($pattern && ! /$pattern/);
+
+            my $n = "$s/$_";
+
+            if (-l $n) {
+                print "\t\t$_ (symlink)... " if ($OPT{debug});
+                my $l = readlink $n;
+                if ((-e $_) && (!unlink $_)) {
+                    print "error: cannot remove $l: $!\n";
+                    ++$failures;
+                    next;
+                }
+                unless (symlink($l, $_)) {
+                    print "error: cannot create symlink from $_ to $l: $!\n";
+                    ++$failures;
+                    next;
+                }
+                print "success\n" if ($OPT{debug});
+            } else {
+                print "\t\t$_... " if ($OPT{debug});
+                if ((-e $_) && (!unlink $_)) {
+                    print "error: cannot remove $_: $!\n";
+                    ++$failures;
+                    next;
+                }
+                unless (copy($n, $_)) {
+                    print "error: cannot copy '$n' to '$_': $!\n";
+                    ++$failures;
+                    next;
+                }
+                print "success\n" if ($OPT{debug});
+            }
+        }
+
+        closedir D;
+    }
+
+    return $failures;
+}
+
+sub includes_out {
+    my $out = '';
+    eval { $out = INCLUDES_OUT(); };
+    $out = File::Spec->catdir($_{INST_INCDIR}, $out);
+    $out;
+}
+
+sub copyincludes {
+    print "installing includes to $_{INST_INCDIR}... ";
+
+    my $s = "$_{INCDIR}/" . INCLUDES();
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    my $out = includes_out();
+    my $d = $out;
+    $d = $_{INST_INCDIR} unless ($d);
+
+    unless (-e $d) {
+        print "\n\t\tmkdir -p $d" if ($OPT{debug});
+        eval { make_path($d) };
+        if ($@) {
+            print "\tfailure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        }
+    }
+
+    if ($out && -f $s) {
+        print "\n\t\tcp $s $d\n\t" if ($OPT{debug});
+        unless (copy($s, $d)) {
+            print "failure\n";
+            return 1;
+        }
+    } else {
+        print "\n\t\tcp -r $s $d\n\t" if ($OPT{debug});
+        unless (dircopy($s, $d)) {
+            print "\tfailure\ninstall: error: cannot copy '$s' 'd'";
+            return 1;
+        }
+    }
+
+    print "success\n";
+    return 0;
+}
+
+sub copyjars {
+    my $s = $_{JARDIR};
+    my $d = $_{INST_JARDIR};
+
+    print "installing jar files to $d... ";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+
+    return $MAKING ? copybldjars($s, $d) : copydir($s, 0 => $d);
+}
+
+sub copybldjars {
+    my ($s, $d) = @_;
+    my $n = 'ngs-java.jar';
+    $s .= "/$n";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    my $nd = "$n.$_{VERSION}";
+    print "installing '$n'... ";
+
+    print "\t\tcd $d\n" if ($OPT{debug});
+    chdir $d or die "cannot cd $d";
+
+    $d .= "/$nd";
+
+    print "\n\t\t$s -> $d\n\t" if ($OPT{debug});
+
+    if ((! $OPT{force}) && (-e $d) && (-M $d < -M $s)) {
+        print "found\n";
+    } else {
+        unless (copy($s, $d)) {
+            print "failure\n";
+            print "install: error: cannot copy '$s' '$d'.\n";
+            return 1;
+        }
+        my $mode = 0644;
+        printf "\tchmod %o $d\n\t", $mode if ($OPT{debug});
+        unless (chmod($mode, $d)) {
+            print "failure\n";
+            print "install: error: cannot chmod '$d': $!\n";
+            return 1;
+        }
+        unless (symlinks($n, $nd, 'jar')) {
+            print "success\n";
+        } else {
+            print "failure\n";
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+sub copydocs {
+    my $s = "$_{JARDIR}/javadoc";
+    $s = expand_path("$Bin/../doc") unless ($MAKING);
+    my $d = "$_{INST_SHAREDIR}/doc";
+
+    print "installing html documents to $d... ";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+
+    print "\t\t$s -> $d\n\t" if ($OPT{debug});
+    unless (dircopy($s, $d)) {
+        print "\tfailure\ninstall: error: cannot copy '$s' to '$d'";
+        return 1;
+    }
+
+    print "success\n";
+    return 0;
+}
+
+sub copyexamples {
+    my $failures = 0;
+    my $CPRFComp = $File::Copy::Recursive::CPRFComp;
+    my $sd = $EXAMPLES_DIR;
+    return 0 unless (-e $sd);
+
+    my $d = $_{INST_SHAREDIR};
+    if ($HAVE{JAR}) {
+        $d .= '/examples-java';
+    } elsif ($HAVE{PYTHON}) {
+        $File::Copy::Recursive::CPRFComp = 0;
+        $d .= '/examples-python';
+    }
+
+    print "installing examples to $d... ";
+
+    my $s = $sd;
+    $s = "$sd/examples" if ($HAVE{JAR} && $MAKING);
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        ++$failures;
+    }
+
+    unless ($failures) {
+        print "\nchecking $d... ";
+        unless (-e $d) {
+            print "not found\n";
+            print "mkdir -p $d... ";
+            eval { make_path($d) };
+            if ($@) {
+                print "failure\ninstall: error: cannot mkdir $d\n";
+                ++$failures;
+            } else {
+                print "success\n";
+            }
+        } else {
+            print "exists\n";
+        }
+    }
+
+    unless ($failures) {
+        print "\t\t$s -> $d\n\t" if ($OPT{debug});
+        if ($HAVE{JAR} && ! $MAKING) {
+            if (copydir($s, 0 => $d)) {
+                ++$failures;
+            }
+        } else {
+            unless (dircopy($s, $d)) {
+                print "\tfailure\ninstall: error: cannot copy '$s' to '$d'";
+                ++$failures;
+            }
+        }
+    }
+
+    unless ($failures) {
+        if ($HAVE{JAR} && $MAKING) {
+            $sd = "$sd/Makefile";
+            $d = "$d/Makefile";
+            print "\t$sd -> $d\n\t" if ($OPT{debug});
+            unless (-e $sd) {
+                print "\tfailure\n";
+                print "install: error: '$sd' is not found.\n";
+                ++$failures;
+            }
+            unless ($failures) {
+                if (-e $d) {
+                unless (unlink $d) {
+                    print "failure\n";
+                    print "install: error: cannot rm '$d': $!\n";
+                    ++$failures;
+                }
+            }
+            unless ($failures) {
+                unless (copy($sd, $d)) {
+                    print "error: cannot copy '$sd' to '$d': $!\n";
+                    ++$failures;
+                }
+            }
+        }
+      }
+    }
+
+    print "success\n" unless ($failures);
+
+    $File::Copy::Recursive::CPRFComp = $CPRFComp;
+
+    return $failures;
+}
+
+sub finishinstall {
+    my $failures = 0;
+
+    $_{JAR_TARGET} = "$_{INST_JARDIR}/ngs-java.jar";
+
+    my @libs;
+    if (%INSTALLED_LIBS) {
+        my %libs;
+        ++$libs{$INSTALLED_LIBS{$_}} foreach (keys %INSTALLED_LIBS);
+        push @libs, $_ foreach (keys %libs);
+    } else {
+        push @libs, $_{LIB_TARGET};
+    }
+    my $libs;
+    foreach (@libs) {
+        $libs .= ":" if ($libs);
+        $libs .= $_;
+    }
+
+    if ($HAVE{PYTHON}) {
+        chdir "$Bin/.." or die "cannot cd '$Bin/..'";
+        my $cmd = "python setup.py install";
+        $cmd .= ' --user' unless (linux_root());
+        print `$cmd`;
+        if ($?) {
+            ++$failures;
+        } else {
+            unless ($libs) {
+                print "internal python failure\n";
+                ++$failures;
+            } elsif ($HAVE{LIBS}) {
+                print <<EndText;
+Please add $libs to your LD_LIBRARY_PATH, e.g.:
+      export LD_LIBRARY_PATH=$libs:\$LD_LIBRARY_PATH
+EndText
+            }
+        }
+    } elsif ($LINUX_ROOT) {
+        print "\t\tlinux root\n" if ($OPT{debug});
+
+        if ($HAVE{USR_INCLUDES}) {
+            unless (-e $oldincludedir) {
+                print "install: error: '$oldincludedir' does not exist\n";
+                ++$failures;
+            } else {
+                my $o = includes_out();
+                if ($o) {
+                    eval { INCLUDES_OUT(); };
+                    if (@_) {
+                        print "install: cannot find INCLUDES_OUT\n";
+                        ++$failures;
+                    } else {
+                        my $INCLUDE_SYMLINK
+                            = "$oldincludedir/" . INCLUDES_OUT();
+                        print "updating $INCLUDE_SYMLINK... ";
+                        unlink $INCLUDE_SYMLINK;
+                        if ($OPT{debug}) {
+                            print "\n\t\tln -s $o $INCLUDE_SYMLINK... ";
+                        }
+                        unless (symlink $o, $INCLUDE_SYMLINK) {
+                            print "failure\n";
+                            print "install: error: " .
+                                "cannot symlink '$o' '$INCLUDE_SYMLINK': $!\n";
+                            ++$failures;
+                        } else {
+                            print "success\n";
+                        }
+                    }
+                } else {
+                    my $INCLUDE_SYMLINK = "$oldincludedir/" . INCLUDES();
+                    print "updating $INCLUDE_SYMLINK... ";
+                    unlink $INCLUDE_SYMLINK;
+                    my $o = "$_{INST_INCDIR}/" . INCLUDES();
+                    unless (symlink $o, $INCLUDE_SYMLINK) {
+                        print "failure\n";
+                        print "install: error: "
+                            . "cannot symlink '$o' '$INCLUDE_SYMLINK': $!\n";
+                        ++$failures;
+                    } else {
+                        print "success\n";
+                    }
+                }
+            }
+        }
+
+        my $NAME = PACKAGE_NAME();
+        if ($HAVE{BINS} || $HAVE{JAR}
+            || ($HAVE{LIBS}
+                && ($HAVE{DLLS} || $NAME eq 'NGS-SDK' || $NAME eq 'NGS-BAM')
+               )
+            )
+        {
+            my $profile = "$ROOT/etc/profile.d";
+            my $PROFILE_FILE = "$profile/" . lc(PACKAGE_NAME());
+            unless (-e $profile) {
+                print "install: error: '$profile' does not exist\n";
+                ++$failures;
+            } else {
+                print "updating $PROFILE_FILE.[c]sh... ";
+
+                my $f = "$PROFILE_FILE.sh";
+                if (!open F, ">$f") {
+                    print "failure\n";
+                    print "install: error: cannot open '$f': $!\n";
+                    ++$failures;
+                } else {
+                    print F "#version $_{VERSION}\n\n";
+
+                    if ($HAVE{LIBS}) {
+                        unless (@libs) {
+                            print "internal root libraries failure\n";
+                            ++$failures;
+                        } else {
+                            if ($HAVE{DLLS}) {
+                                foreach (@libs) {
+                                    print F <<EndText;
+if ! echo \$LD_LIBRARY_PATH | /bin/grep -q $_
+then export LD_LIBRARY_PATH=$_:\$LD_LIBRARY_PATH
+fi
+
+EndText
+                                }
+                            }
+                            if ($NAME eq 'NGS-SDK') {
+                                print F "export NGS_LIBDIR=$_{LIB_TARGET}\n";
+                            } elsif ($NAME eq 'NGS-BAM') {
+                                print F
+                                      "\nexport NGS_BAM_LIBDIR=$_{LIB_TARGET}\n"
+                            }
+                        }
+                    }
+                    if ($HAVE{JAR}) {
+                        print F <<EndText;
+if ! echo \$CLASSPATH | /bin/grep -q $_{JAR_TARGET}
+then export CLASSPATH=$_{JAR_TARGET}:\$CLASSPATH
+fi
+EndText
+                    }
+                    if ($HAVE{BINS}) {
+                        print F <<EndText;
+if ! echo \$PATH | /bin/grep -q $_{INST_BINDIR}
+then export PATH=$_{INST_BINDIR}:\$PATH
+fi
+EndText
+                    }
+                    close F;
+                    unless (chmod(0644, $f)) {
+                        print "failure\n";
+                        print "install: error: cannot chmod '$f': $!\n";
+                        ++$failures;
+                    }
+                }
+            }
+
+            my $f = "$PROFILE_FILE.csh";
+            if (!open F, ">$f") {
+                print "failure\n";
+                print "install: error: cannot open '$f': $!\n";
+                ++$failures;
+            } else {
+                print F "#version $_{VERSION}\n\n";
+
+                if ($HAVE{LIBS}) {
+                    unless (@libs) {
+                        print "internal libraries failure\n";
+                        ++$failures;
+                    } else {
+                        if ($HAVE{DLLS}) {
+                            foreach (@libs) {
+                                print F <<EndText;
+echo \$LD_LIBRARY_PATH | /bin/grep -q $_
+if ( \$status ) setenv LD_LIBRARY_PATH $_:\$LD_LIBRARY_PATH
+
+EndText
+                            }
+                        }
+                    }
+                    if (PACKAGE_NAME() eq 'NGS-BAM') {
+                        print F "setenv NGS_BAM_LIBDIR $_{LIB_TARGET}\n";
+                    } elsif (PACKAGE_NAME() eq 'NGS-SDK') {
+                        print F "setenv NGS_LIBDIR $_{LIB_TARGET}\n";
+                    } elsif (PACKAGE_NAME() eq 'NCBI-VDB') {
+                        print F "setenv NCBI_VDB_LIBDIR $_{LIB_TARGET}\n";
+                    }
+                }
+                if ($HAVE{JAR}) {
+                    print F <<EndText;
+echo \$CLASSPATH | /bin/grep -q $_{JAR_TARGET}
+if ( \$status ) setenv CLASSPATH $_{JAR_TARGET}:\$CLASSPATH
+EndText
+                }
+                if ($HAVE{BINS}) {
+                    print F <<EndText;
+echo \$PATH | /bin/grep -q $_{INST_BINDIR}
+if ( \$status ) setenv PATH $_{INST_BINDIR}:\$PATH
+EndText
+                }
+                close F;
+                unless (chmod(0644, $f)) {
+                    print "failure\n";
+                    print "install: error: cannot chmod '$f': $!\n";
+                    ++$failures;
+                }
+            }
+#	@ #TODO: check version of the files above
+            print "success\n" unless ($failures);
+        }
+
+        unless ($failures) {
+            if ($HAVE{LIBS}) {
+                if (PACKAGE_NAME() eq 'NGS-BAM') {
+                    print "\n";
+                    print "Use \$NGS_BAM_LIBDIR in your link commands, e.g.:\n";
+                    print "      ld -L\$NGS_BAM_LIBDIR -lngs-bam ...\n";
+                } elsif (PACKAGE_NAME() eq 'NGS-SDK') {
+                    print "\nUse \$NGS_LIBDIR in your link commands, e.g.:\n";
+                    print "      ld -L\$NGS_LIBDIR -lngs-sdk ...\n";
+                } elsif (PACKAGE_NAME() eq 'NCBI-VDB') {
+                    print "\n"
+                       . "Use \$NCBI_VDB_LIBDIR in your link commands, e.g.:\n";
+                    print "      ld -L\$NCBI_VDB_LIBDIR -lncbi-vdb ...\n";
+                }
+            }
+        }
+    } else {
+        print "\t\tnot linux root\n" if ($OPT{debug});
+        if ($HAVE{LIBS}) {
+            unless ($libs) {
+                print "internal libraries failure\n";
+                ++$failures;
+            } else {
+                print "\n";
+                print <<EndText if ($HAVE{DLLS});
+Please add $libs to your LD_LIBRARY_PATH, e.g.:
+      export LD_LIBRARY_PATH=$libs:\$LD_LIBRARY_PATH
+EndText
+                if (PACKAGE_NAME() eq 'NGS-SDK') {
+                    print "Use $libs in your link commands, e.g.:\n"
+                        . "export NGS_LIBDIR=$libs\n"
+                        . "ld -L\$NGS_LIBDIR -lngs-sdk ...\n";
+                } elsif (PACKAGE_NAME() eq 'NGS-BAM') {
+                    print "Use $libs in your link commands, e.g.:\n"
+                        . "export NGS_BAM_LIBDIR=$libs\n"
+                        . "ld -L\$NGS_BAM_LIBDIR -lngs-bam ...\n";
+                }
+            }
+        }
+        if ($HAVE{JAR}) {
+            print <<EndText;
+
+Please add $_{JAR_TARGET} to your CLASSPATH, i.e.:
+      export CLASSPATH=$_{JAR_TARGET}:\$CLASSPATH
+EndText
+        }
+    }
+
+    return $failures;
+}
+
+sub expand_path {
+    my ($filename) = @_;
+    return unless ($filename);
+
+    if ($filename =~ /^~/) {
+        if ($filename =~ m|^~([^/]*)|) {
+            if ($1 && ! getpwnam($1)) {
+                print "install: error: bad path: '$filename'\n";
+                exit 1;
+            }
+        }
+
+        $filename =~ s{ ^ ~ ( [^/]* ) }
+                      { $1
+                            ? (getpwnam($1))[7]
+                            : ( $ENV{HOME} || $ENV{USERPROFILE} || $ENV{LOGDIR}
+                                || (getpwuid($<))[7]
+                              )
+                      }ex;
+    }
+
+    my $a = abs_path($filename);
+    $filename = $a if ($a);
+
+    $filename;
+}
+
+sub help {
+    $_{LIB_TARGET} = "$_{INST_LIBDIR}$_{BITS}";
+
+    print <<EndText;
+'install' installs $_{PACKAGE_NAME} $_{VERSION} package.
+
+Usage: ./install [OPTION]...
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+  -n, --no-create         do not run installation
+
+EndText
+
+    if ($HAVE{TWO_LIBS}) {
+        my $p = lc(PACKAGE_NAME());
+        print "By default, `./install' will install all the files in\n";
+        print "`/usr/local/ngs/$p/jar', " if ($HAVE{JAR});
+        print <<EndText;
+`/usr/local/ngs/$p/share',
+`/usr/local/ngs/ngs-sdk/lib$_{BITS}', `/usr/local/ncbi/ncbi-vdb/lib$_{BITS}'.
+You can spefify other installation directories using the options below.
+
+Fine tuning of the installation directories:
+EndText
+        if ($HAVE{JAR}) {
+            print
+                "  --jardir=DIR         jar files [/usr/local/ngs/$p/jar]\n"
+        }
+        print <<EndText;
+  --ngslibdir=DIR      ngs-sdk libraries [/usr/local/ngs/ngs-sdk/lib$_{BITS}]
+  --vdblibdir=DIR      ncbi-vdb libraries [/usr/local/ncbi/ncbi-vdb/lib$_{BITS}]
+  --examplesdir=DIR    example files [/usr/local/ngs/$p/share]
+
+  --libdir=DIR         install all libraries in the same directory
+  --prefix=DIR         install files in PREFIX/lib$_{BITS}, PREFIX/share etc.
+EndText
+    } else {
+        print <<EndText;
+Installation directories:
+  --prefix=PREFIX         install all files in PREFIX
+                          [$_{PREFIX}]
+
+By default, `./install' will install all the files in
+EndText
+
+        if ($HAVE{INCLUDES}) {
+            print
+"`$_{PREFIX}/include', `$_{PREFIX}/lib$_{BITS}' etc.  You can specify\n"
+        } elsif ($HAVE{JAR}) {
+            print "`$_{PREFIX}/jar', `$_{PREFIX}/share' etc.  You can specify\n"
+        } elsif ($MAKING) {
+            print "`$_{PREFIX}/share' etc.  You can specify\n"
+        } else {
+            print
+"`$_{PREFIX}/lib$_{BITS}' `$_{PREFIX}/share' etc.  You can specify\n"
+        }
+
+        print <<EndText;
+an installation prefix other than `$_{PREFIX}' using `--prefix',
+for instance `--prefix=$_{OTHER_PREFIX}'.
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+EndText
+
+        if ($HAVE{BINS}) {
+            print "  --bindir=DIR            executables [PREFIX/bin]\n";
+        }
+        if ($HAVE{JAR}) {
+            print "  --jardir=DIR            jar files [PREFIX/jar]\n";
+        }
+        if ($HAVE{LIBS}) {
+            print
+"  --libdir=DIR            object code libraries [PREFIX/lib$_{BITS}]\n"
+        }
+        if ($HAVE{INCLUDES}) {
+            print "  --includedir=DIR        C header files [PREFIX/include]\n";
+        }
+        if ($HAVE{USR_INCLUDES}) {
+            print
+"  --oldincludedir=DIR     C header files for non-gcc [$oldincludedir]\n"
+        }
+
+        if (-e $EXAMPLES_DIR) {
+            print "  --examplesdir=DIR       example files [PREFIX/share]\n";
+        }
+    }
+
+    if ($HAVE{LIBS}) {
+        print <<EndText;
+
+System types:
+  --bits=[32|64]          use a 32- or 64-bit data model
+EndText
+    }
+
+    print "\nReport bugs to sra-tools\@ncbi.nlm.nih.gov\n";
+}
+
+sub prepare {
+    if ($MAKING) {
+        my $os_arch = `perl -w $Bin/os-arch.perl`;
+        unless ($os_arch) {
+            print "install: error\n";
+            exit 1;
+        }
+        chomp $os_arch;
+        my $config =
+            "$Bin/../" . CONFIG_OUT() . "/Makefile.config.install.$os_arch.prl";
+        fatal_config("$config not found") unless (-e "$config");
+
+        eval { require $config; };
+        fatal_config($@) if ($@);
+    } else {
+        my $a = $Config{archname64};
+        $_ = lc PACKAGE_NAME();
+        my $root = '';
+        $root = $OPT{root} if ($OPT{root});
+        my $code = 
+            'sub CONFIGURE { ' .
+            '   $_{OS           } = $OS; ' .
+            '   $_{VERSION      } = "1.0.0"; ' .
+            '   $_{MAJVERS      } = "1"; ' .
+            '   $_{LPFX         } = "lib"; ' .
+            '   $_{LIBX         } = "a"; ' .
+            '   $_{MAJVERS_LIBX } = "a.1"; ' .
+            '   $_{VERSION_LIBX } = "a.1.0.0"; ' .
+            '   $_{SHLX         } = "so"; ' .
+            '   $_{OTHER_PREFIX } = \'$HOME/ngs/' . $_ . '\'; ' .
+            '   $_{PREFIX       } = "' . "$root/usr/local/ngs/$_" . '"; ' .
+            '   $_{INST_INCDIR  } = "$_{PREFIX}/include"; ' .
+            '   $_{INST_LIBDIR  } = "$_{PREFIX}/lib"; ' .
+            '   $_{INST_JARDIR  } = "$_{PREFIX}/jar"; ' .
+            '   $_{INST_SHAREDIR} = "$_{PREFIX}/share"; ' .
+            '   $_{INCDIR       } = "$Bin/../include"; ' .
+            '   $_{LIBDIR64     } = "$Bin/../lib64"; ' .
+            '   $_{LIBDIR32     } = "$Bin/../lib32"; ';
+        if ($HAVE{TWO_LIBS}) {
+            $code .=
+               '$_{INST_NGSLIBDIR} = "' . "$root/usr/local/ngs/ngs-sdk/lib\";"
+             . '$_{INST_VDBLIBDIR} = "' . "$root/usr/local/ncbi/ncbi-vdb/lib\";"
+        }
+        $code .= ' $_{PACKAGE_NAME} = "' . PACKAGE_NAME() . '"; ';
+
+        if (defined $Config{archname64}) {
+            $code .= ' $_{BITS} = 64; ';
+        } else {
+            $code .= ' $_{BITS} = 32; ';
+        }
+
+        $code .= 
+            '   $_{MAJVERS_SHLX } = "so.1"; ' .
+            '   $_{VERSION_SHLX } = "so.1.0.0"; ' ;
+
+        $code .= 
+            '   @_ ' .
+            '}';
+
+        eval $code;
+
+        die $@ if ($@);
+    }
+}
+
+sub linux_root { $^O eq 'linux' && `id -u` == 0 }
+
+sub fatal_config {
+    if ($OPT{debug}) {
+        print "\t\t";
+        print "@_";
+        print "\n";
+    }
+
+    print "install: error: run ./configure [OPTIONS] first.\n";
+
+    exit 1;
+}
+
+################################################################################
diff --git a/ngs-python/setup/install.prl b/ngs-python/setup/install.prl
new file mode 100644
index 0000000..9208fcf
--- /dev/null
+++ b/ngs-python/setup/install.prl
@@ -0,0 +1,4 @@
+sub PACKAGE_NAME { 'NGS-PYTHON' }
+sub HAVE        { ( DLLS => 1, EXAMPLES => 1, PYTHON => 1, ) }
+sub CONFIG_OUT  {   '.' }
+1
diff --git a/ngs-sdk/konfigure.perl b/ngs-python/setup/konfigure.perl
similarity index 60%
rename from ngs-sdk/konfigure.perl
rename to ngs-python/setup/konfigure.perl
index 2a7fde7..7b7780e 100644
--- a/ngs-sdk/konfigure.perl
+++ b/ngs-python/setup/konfigure.perl
@@ -32,65 +32,117 @@ if ($directories ne "./") {
     exit 1;
 }
 
-require 'package.pm';
-require 'os-arch.pm';
+require 'package.prl';
+require 'os-arch.prl';
 
-use Cwd qw (abs_path getcwd);
+use Cwd qw(abs_path getcwd);
 use File::Basename 'fileparse';
 use File::Spec 'catdir';
 use FindBin qw($Bin);
-use Getopt::Long 'GetOptions';
+use Getopt::Long "GetOptions";
+
+chdir '..' or die "cannot cd to package root";
 
 check();
 
+my $LOCAL_BUILD_OUT
+    = -e File::Spec->catdir($ENV{HOME}, 'tmp', 'local-build-out');
+
+my ($CONFIGURED, $RECONFIGURE) = ('');
+if (@ARGV) {
+    foreach (@ARGV) {
+        $CONFIGURED .= "\t" if ($CONFIGURED);
+        $CONFIGURED .= "'$_'";
+    }
+} elsif (-f 'reconfigure') {
+    ++$RECONFIGURE unless ($LOCAL_BUILD_OUT);
+}
+
 my %PKG = PKG();
 
 my $PACKAGE_NAME = PACKAGE_NAME();
 my $OUT_MAKEFILE = 'Makefile.config';
+my $INS_MAKEFILE = 'Makefile.config.install';
 
 my $PACKAGE = PACKAGE();
 
 my $HOME = $ENV{HOME} || $ENV{USERPROFILE}
     || $ENV{LOGDIR} || getcwd || (getpwuid($<))[7] || abs_path('.');
 
-$PKG{UPATH} =~ s/(\$\w+)/$1/eeg;
-
-my $OUTDIR = File::Spec->catdir($HOME, $PKG{OUT});
+$PKG{UPATH} = expand($PKG{UPATH});
 
 my $package_default_prefix = $PKG{PATH};
 my $schema_default_dir = $PKG{SCHEMA_PATH} if ($PKG{SCHEMA_PATH});
 
 my @REQ = REQ();
 
-my @options = ( "arch=s",
-                "build=s",
-                "clean",
-                "debug",
-                "help",
-#               "output-makefile=s",
-                "prefix=s",
-                "status",
-                "with-debug",
-                "without-debug" );
+my @options = ( 'build-prefix=s',
+                'clean',
+                'debug',
+                'help',
+                'prefix=s',
+                'reconfigure',
+                'status',
+                'with-debug',
+                'without-debug', );
+{
+    my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
+    push @options, 'arch=s'    if (@ARCHITECTURES);
+}
+push @options, 'enable-static' if (PACKAGE_TYPE() eq 'B');
 foreach my $href (@REQ) {
     my %a = %$href;
     push @options, "$a{option}=s";
     push @options, "$a{boption}=s" if ($a{boption});
-    $href->{usrpath} =~ s/(\$\w+)/$1/eeg;
+    $href->{usrpath} = '' unless ($href->{usrpath});
+    $href->{usrpath} = expand($href->{usrpath});
 }
 push @options, "shemadir" if ($PKG{SCHEMA_PATH});
 
 my %OPT;
 die "configure: error" unless (GetOptions(\%OPT, @options));
+++$OPT{'reconfigure'} if ($RECONFIGURE);
+
+if ($OPT{'reconfigure'}) {
+    unless (eval 'use Getopt::Long qw(GetOptionsFromString); 1') {
+        print <<EndText;
+configure: error: your perl does not support Getopt::Long::GetOptionsFromString
+                  reconfigure option is not avaliable.
+Run "sh ./reconfigure" instead.
+EndText
+        exit 1;
+    }
+    println "reconfiguring...";
+    open F, 'reconfigure' or die 'cannot open reconfigure';
+    $_ = <F>;
+    chomp;
+    unless (m|^\./configure\s*(.*)$|) {
+        println 'configure: error: cannot reconfigure';
+        println 'run "./configure --clean" then run "./configure [OPTIONS]"';
+        exit 1;
+    }
+
+    println "running \"./configure $1\"...";
+    undef %OPT;
+    die "configure: error" unless (GetOptionsFromString($1, \%OPT, @options));
+    ++$OPT{reconfigure};
+}
+
+$OPT{'local-build-out'} = $LOCAL_BUILD_OUT;
+my $OUTDIR = File::Spec->catdir($HOME, $PKG{OUT});
+if ($OPT{'local-build-out'}) {
+    my $o = expand_path(File::Spec->catdir($Bin, $PKG{LOCOUT}));
+    $OUTDIR = $o if ($o);
+}
 
 if ($OPT{'help'}) {
     help();
-    exit(0);
+    exit 0;
 } elsif ($OPT{'clean'}) {
     {
-        foreach (glob(CONFIG_OUT() . '/Makefile.config*'),
-            File::Spec->catdir(CONFIG_OUT(), 'user.status'),
-            File::Spec->catdir(CONFIG_OUT(), 'Makefile.userconfig'))
+        foreach ('reconfigure', glob(CONFIG_OUT() . '/Makefile.config*'),
+            File::Spec->catdir(CONFIG_OUT(), 'Makefile.userconfig'),
+            File::Spec->catdir(CONFIG_OUT(), 'user.status'))
         {
             my $f = $_;
             print "removing $f... ";
@@ -122,11 +174,14 @@ if ($OPT{'help'}) {
             }
         }
     }
-    exit(0);
+    exit 0;
 } elsif ($OPT{'status'}) {
     status(1);
-    exit(0);
+    exit 0;
 }
+
+println "Configuring $PACKAGE_NAME package";
+
 $OPT{'prefix'} = $package_default_prefix unless ($OPT{'prefix'});
 
 my $AUTORUN = $OPT{status};
@@ -134,34 +189,52 @@ print "checking system type... " unless ($AUTORUN);
 my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
 println $OSTYPE unless ($AUTORUN);
 
+unless ($OSTYPE =~ /linux/i || $OSTYPE =~ /darwin/i || $OSTYPE eq 'win') {
+    println "configure: error: unsupported system '$OSTYPE'";
+    exit 1;
+}
+
+print "checking machine architecture... " unless ($AUTORUN);
+println $MARCH unless ($AUTORUN);
+unless ($MARCH =~ /x86_64/i || $MARCH =~ /i?86/i) {
+    println "configure: error: unsupported architecture '$OSTYPE'";
+    exit 1;
+}
+
 {
-    $OPT{'prefix'} = expand($OPT{'prefix'});
+    $OPT{'prefix'} = expand_path($OPT{'prefix'});
     my $prefix = $OPT{'prefix'};
-    $OPT{eprefix} = $prefix unless ($OPT{eprefix} || $OS eq 'win');
-    my $eprefix = $OPT{eprefix};
-    unless ($OPT{bindir} || $OS eq 'win') {
-        $OPT{bindir} = File::Spec->catdir($eprefix, 'bin') ;
+    $OPT{'eprefix'} = $prefix unless ($OPT{'eprefix'} || $OS eq 'win');
+    my $eprefix = $OPT{'eprefix'};
+    unless ($OPT{'bindir'} || $OS eq 'win') {
+        $OPT{'bindir'} = File::Spec->catdir($eprefix, 'bin') ;
     }
-    unless ($OPT{libdir} || $OS eq 'win') {
-        $OPT{libdir} = File::Spec->catdir($eprefix, 'lib');
+    unless ($OPT{'libdir'} || $OS eq 'win') {
+        $OPT{'libdir'} = File::Spec->catdir($eprefix, 'lib');
     }
-    unless ($OPT{includedir} || $OS eq 'win') {
-        $OPT{includedir} = File::Spec->catdir($eprefix, 'include');
+    unless ($OPT{'includedir'} || $OS eq 'win') {
+        $OPT{'includedir'} = File::Spec->catdir($eprefix, 'include');
     }
-    if ($PKG{LNG} eq 'PYTHON' && ! $OPT{pythondir} && $OS ne 'win') {
-        $OPT{pythondir} = $eprefix;
+    if ($PKG{LNG} eq 'PYTHON' && ! $OPT{'pythondir'} && $OS ne 'win') {
+        $OPT{'pythondir'} = $eprefix;
     }
-    if ($PKG{LNG} eq 'JAVA' && ! $OPT{javadir} && $OS ne 'win') {
-        $OPT{javadir} = File::Spec->catdir($eprefix, 'jar');
+    if ($PKG{LNG} eq 'JAVA' && ! $OPT{'javadir'} && $OS ne 'win') {
+        $OPT{'javadir'} = File::Spec->catdir($eprefix, 'jar');
     }
-    if ($PKG{EXAMP} && ! $OPT{sharedir} && $OS ne 'win') {
-        $OPT{sharedir} = File::Spec->catdir($eprefix, 'share');
+    if ($PKG{EXAMP} && ! $OPT{'sharedir'} && $OS ne 'win') {
+        $OPT{'sharedir'} = File::Spec->catdir($eprefix, 'share');
     }
 }
 
 # initial values
 my $TARGDIR = File::Spec->catdir($OUTDIR, $PACKAGE);
-$TARGDIR = expand($OPT{'build'}) if ($OPT{'build'});
+if ($OPT{'build-prefix'}) {
+    $TARGDIR = $OPT{'build-prefix'} = expand_path($OPT{'build-prefix'});
+    unless ($TARGDIR =~ /$PACKAGE$/) {
+        $TARGDIR = File::Spec->catdir($TARGDIR, $PACKAGE);
+    }
+}
+my $BUILD_PREFIX = $TARGDIR;
 
 my $BUILD = 'rel';
 
@@ -195,14 +268,8 @@ if ($OPT{arch}) {
     }
 }
 
-$OUT_MAKEFILE .= ".$OS.$ARCH";
-$OUT_MAKEFILE = File::Spec->catdir(CONFIG_OUT(), $OUT_MAKEFILE);
-
-#my $OSTYPE = `uname -s`; chomp $OSTYPE;
-
-print "checking machine architecture... " unless ($AUTORUN);
-#my $MARCH = `uname -m`; chomp $MARCH;
-println $MARCH unless ($AUTORUN);
+$OUT_MAKEFILE = File::Spec->catdir(CONFIG_OUT(), "$OUT_MAKEFILE.$OS.$ARCH");
+$INS_MAKEFILE = File::Spec->catdir(CONFIG_OUT(), "$INS_MAKEFILE.$OS.$ARCH.prl");
 
 my $TOOLS = "";
 $TOOLS = "jdk" if ($PKG{LNG} eq 'JAVA');
@@ -217,17 +284,12 @@ print "checking for supported architecture... " unless ($AUTORUN);
 
 my $BITS;
 
-if ( $MARCH =~ m/x86_64/i )
-{
+if ($MARCH =~ /x86_64/i) {
     $BITS = 64;
-}
-elsif ( $MARCH =~ m/i?86/i )
-{
+} elsif ($MARCH =~ /i?86/i) {
     $BITS = 32;
-}
-else
-{
-    die "unrecognized Architecture - " . $ARCH;
+} else {
+    die "unrecognized Architecture '$ARCH'";
 }
 println "$MARCH ($BITS bits) is supported" unless ($AUTORUN);
 
@@ -235,105 +297,111 @@ println "$MARCH ($BITS bits) is supported" unless ($AUTORUN);
 my ($LPFX, $OBJX, $LOBX, $LIBX, $SHLX, $EXEX, $OSINC);
 
 print "checking for supported OS... " unless ($AUTORUN);
-if ( $OSTYPE =~ m/linux/i )
-{
-    $LPFX = "lib";
-    $OBJX = "o";
-    $LOBX = "pic.o";
-    $LIBX = "a";
-    $SHLX = "so";
-    $EXEX = "";
-    $OSINC = "unix";
-    if ( $TOOLS eq "" )
-    {
-        $TOOLS = "gcc";
-    }
-}
-elsif ( $OSTYPE =~ m/darwin/i )
-{
-    $LPFX = "lib";
-    $OBJX = "o";
-    $LOBX = "pic.o";
-    $LIBX = "a";
-    $SHLX = "dylib";
-    $EXEX = "";
-    $OSINC = "unix";
-    if ( $TOOLS eq "" )
-    {
-        $TOOLS = "clang";
-    }
+if ($OSTYPE =~ /linux/i) {
+    $LPFX = 'lib';
+    $OBJX = 'o';
+    $LOBX = 'pic.o';
+    $LIBX = 'a';
+    $SHLX = 'so';
+    $EXEX = '';
+    $OSINC = 'unix';
+    $TOOLS = 'gcc' unless ($TOOLS);
+} elsif ($OSTYPE =~ /darwin/i) {
+    $LPFX = 'lib';
+    $OBJX = 'o';
+    $LOBX = 'pic.o';
+    $LIBX = 'a';
+    $SHLX = 'dylib';
+    $EXEX = '';
+    $OSINC = 'unix';
+    $TOOLS = 'clang' unless ($TOOLS);
 } elsif ($OSTYPE eq 'win') {
-    $TOOLS = "vc++";
-} else
-{
-    die "unrecognized OS - " . $OSTYPE;
+    $TOOLS = 'vc++';
+} else {
+    die "unrecognized OS '$OSTYPE'";
 }
 println "$OSTYPE ($OS) is supported" unless ($AUTORUN);
 
 # tool chain
-my ($CC, $CP, $AR, $ARX, $ARLS, $LD, $LP);
+my ($CPP, $CC, $CP, $AR, $ARX, $ARLS, $LD, $LP);
 my ($JAVAC, $JAVAH, $JAR);
 my ($DBG, $OPT, $PIC, $INC, $MD);
 
 print "checking for supported tool chain... " unless ($AUTORUN);
-if ( $TOOLS =~ m/gcc/i )
-{
-    $CC = "gcc -c";
-    $CP = "g++ -c";
-    $AR = "ar rc";
-    $ARX = "ar x";
-    $ARLS = "ar t";
-    $LD = "gcc";
-    $LP = "g++";
-
-    $DBG = "-g -DDEBUG";
-    $OPT = "-O3";
-    $PIC = "-fPIC";
-    $INC = "-I";
-    $MD  = "-MD";
-}
-elsif ( $TOOLS =~ m/clang/i )
-{
-    $CC = "clang -c";
-    $CP = "clang++ -c";
-    $AR = "ar rc";
-    $ARX = "ar x";
-    $ARLS = "ar t";
-    $LD = "clang";
-    $LP = "clang++";
-
-    $DBG = "-g -DDEBUG";
-    $OPT = "-O3";
-    $PIC = "-fPIC";
-    $INC = "-I";
-    $MD  = "-MD";
-}
-elsif ( $TOOLS =~ m/jdk/i )
-{
-    $JAVAC = "javac";
-    $JAVAH = "javah";
-    $JAR   = "jar cf";
-
-    $DBG = "-g";
+if ($TOOLS eq 'gcc') {
+    $CPP  = 'g++';
+    $CC   = 'gcc -c';
+    $CP   = "$CPP -c";
+    $AR   = 'ar rc';
+    $ARX  = 'ar x';
+    $ARLS = 'ar t';
+    $LD   = 'gcc';
+    $LP   = $CPP;
+
+    $DBG = '-g -DDEBUG';
+    $OPT = '-O3';
+    $PIC = '-fPIC';
+    $INC = '-I';
+    $MD  = '-MD';
+} elsif ($TOOLS eq 'clang') {
+    $CPP  = 'clang++';
+    $CC   = 'clang -c';
+    $CP   = "$CPP -c -mmacosx-version-min=10.6";
+    $AR   = 'ar rc';
+    $ARX  = 'ar x';
+    $ARLS = 'ar t';
+    $LD   = 'clang';
+    $LP   = "$CPP -mmacosx-version-min=10.6";
+
+    $DBG = '-g -DDEBUG';
+    $OPT = '-O3';
+    $PIC = '-fPIC';
+    $INC = '-I';
+    $MD  = '-MD';
+} elsif ($TOOLS eq 'jdk') {
+    $JAVAC = 'javac';
+    $JAVAH = 'javah';
+    $JAR   = 'jar cf';
+
+    $DBG = '-g';
 } elsif ($TOOLS eq 'vc++') {
-} else
-{
-    die "unrecognized tool chain - " . $TOOLS;
+} else {
+    die "unrecognized tool chain '$TOOLS'";
 }
 println "$TOOLS tool chain is supported" unless ($AUTORUN);
 
-if ($OS ne 'win') {
+if ($OS ne 'win' && $PKG{LNG} ne 'JAVA') {
     $TARGDIR = File::Spec->catdir($TARGDIR, $OS, $TOOLS, $ARCH, $BUILD);
 }
 
+if ($CPP) {
+    unless (check_tool($CPP)) {
+        println "configure: error: '$CPP' cannot be found";
+        exit 1;
+    }
+}
+
+my $NO_ARRAY_BOUNDS_WARNING = '';
+if ($TOOLS eq 'gcc' && check_no_array_bounds()) {
+    $NO_ARRAY_BOUNDS_WARNING = '-Wno-array-bounds';
+}
+
 my @dependencies;
 
+my %DEPEND_OPTIONS;
 foreach my $href (DEPENDS()) {
     $_ = $href->{name};
     my ($I, $L) = ($href->{Include});
-    if ($OPT{"with-$_-prefix"}) {
-        $I = File::Spec->catdir($OPT{"with-$_-prefix"}, 'include'); 
-        $L = File::Spec->catdir($OPT{"with-$_-prefix"}, 'lib'); 
+    my $o = "with-$_-prefix";
+    ++$DEPEND_OPTIONS{$o};
+    if ($OPT{$o}) {
+        $OPT{$o} = expand_path($OPT{$o});
+        $I = File::Spec->catdir($OPT{$o}, 'include');
+        if (/^xml2$/) {
+            my $t = File::Spec->catdir($I, 'libxml2');
+            $I = $t if (-e $t);
+        }
+        $L = File::Spec->catdir($OPT{$o}, 'lib');
     }
     my ($i, $l) = find_lib($_, $I, $L);
     if (defined $i || $l) {
@@ -354,16 +422,21 @@ foreach my $href (DEPENDS()) {
 }
 
 foreach my $href (@REQ) {
-    $href->{bldpath} =~ s/(\$\w+)/$1/eeg if ($href->{bldpath});
+    $href->{   bldpath} = expand($href->{   bldpath}) if ($href->{   bldpath});
+    $href->{locbldpath} = expand($href->{locbldpath}) if ($href->{locbldpath});
     my ($found_itf, $found_lib, $found_ilib);        # found directories
     my %a = %$href;
+    next if ($a{option} && $DEPEND_OPTIONS{$a{option}});
     my $is_optional = optional($a{type});
+    my $quasi_optional = $a{type} =~ /Q/;
     my $need_source = $a{type} =~ /S/;
     my $need_build = $a{type} =~ /B/;
-    my $need_lib = $a{type} =~ /L/;
+    my $need_lib = $a{type} =~ /L|D/;
+    my $need_itf = ! ($a{type} =~ /D/);
     
     my ($inc, $lib, $ilib) = ($a{include}, $a{lib}); # file names to check
-    $lib =~ s/(\$\w+)/$1/eeg;
+    $lib = '' unless ($lib);
+    $lib = expand($lib);
 
     if ($need_build) {
         $ilib = $a{ilib};
@@ -383,7 +456,7 @@ foreach my $href (@REQ) {
     foreach my $option ($a{option}, $a{boption}) {
         next unless ($option);
         if ($OPT{$option}) {
-            my $try = expand($OPT{$option});
+            my $try = expand_path($OPT{$option});
             my ($i, $l, $il) = ($inc, $lib, $ilib);
             if ($option =~ /-build$/) {
                 undef $i;
@@ -397,9 +470,18 @@ foreach my $href (@REQ) {
                 ++$has_option{sources};
             }
             my ($fi, $fl, $fil) = find_in_dir($try, $i, $l, $il);
-            $found_itf  = $fi  if (! $found_itf  && $fi);
-            $found_lib  = $fl  if (! $found_lib  && $fl);
-            $found_ilib = $fil if (! $found_ilib && $fil);
+            if ($fi || $fl || $fil) {
+                $found_itf  = $fi  if (! $found_itf  && $fi);
+                $found_lib  = $fl  if (! $found_lib  && $fl);
+                $found_ilib = $fil if (! $found_ilib && $fil);
+            }
+            elsif (! ($try =~ /$a{name}$/)) {
+                $try = File::Spec->catdir($try, $a{name});
+                ($fi, $fl, $fil) = find_in_dir($try, $i, $l, $il);
+                $found_itf  = $fi  if (! $found_itf  && $fi);
+                $found_lib  = $fl  if (! $found_lib  && $fl);
+                $found_ilib = $fil if (! $found_ilib && $fil);
+            }
         }
     }
     if (! $found_itf && ! $has_option{sources} && $a{srcpath}) {
@@ -423,16 +505,39 @@ foreach my $href (@REQ) {
     }
     if (! $has_option{build}) {
         if (($need_build || ($need_lib && ! $found_lib)) && $a{bldpath}) {
-            my $try = $a{bldpath};
-            my (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
-            $found_lib  = $fl  if (! $found_lib  && $fl);
-            $found_ilib = $fil if (! $found_ilib && $fil);
+            my ($fl, $fil);
+            if ($OPT{'build-prefix'}) {
+                my $try = $OPT{'build-prefix'};
+                (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
+                if ($fl || $fil) {
+                    $found_lib  = $fl  if (! $found_lib  && $fl);
+                    $found_ilib = $fil if (! $found_ilib && $fil);
+                } elsif (! ($try =~ /$a{name}$/)) {
+                    $try = File::Spec->catdir($try, $a{name});
+                    (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
+                    if ($fl || $fil) {
+                        $found_lib  = $fl  if (! $found_lib  && $fl);
+                        $found_ilib = $fil if (! $found_ilib && $fil);
+                    }
+                }
+            }
+            unless ($fl || $fil) {
+                my $try = $a{bldpath};
+                $try = $a{locbldpath} if ($OPT{'local-build-out'});
+                (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
+                $found_lib  = $fl  if (! $found_lib  && $fl);
+                $found_ilib = $fil if (! $found_ilib && $fil);
+            }
         }
     }
-    if (! $found_itf || ($need_lib && ! $found_lib) || ($ilib && ! $found_ilib))
+    if (($need_itf && ! $found_itf) ||
+        ($need_lib && ! $found_lib) || ($ilib && ! $found_ilib))
     {
         if ($is_optional) {
             println "configure: optional $a{name} package not found: skipped.";
+        } elsif ($quasi_optional && $found_itf && ($need_lib && ! $found_lib)) {
+            println "configure: $a{name} package: "
+                . "found interface files but not libraries.";
         } else {
             if ($OPT{'debug'}) {
                 $_ = "$a{name}: includes: ";
@@ -456,20 +561,42 @@ foreach my $href (@REQ) {
             exit 1;
         }
     } else {
-        $found_itf = abs_path($found_itf);
-        push(@dependencies, "$a{namew}_INCDIR = $found_itf");
+        if ($found_itf) {
+            $found_itf = abs_path($found_itf);
+            push(@dependencies, "$a{aname}_INCDIR = $found_itf");
+        }
         if ($found_lib) {
             $found_lib = abs_path($found_lib);
-            push(@dependencies, "$a{namew}_LIBDIR = $found_lib");
+            if ($a{aname} eq 'NGS' || $a{aname} eq 'VDB') {
+                if ($OPT{PYTHON_LIB_PATH}) {
+                    $OPT{PYTHON_LIB_PATH} .= ':';
+                } else {
+                    $OPT{PYTHON_LIB_PATH} = '';
+                }
+                $OPT{PYTHON_LIB_PATH} .= $found_lib;
+            }
+            push(@dependencies, "$a{aname}_LIBDIR = $found_lib");
         }
         if ($ilib && $found_ilib) {
             $found_ilib = abs_path($found_ilib);
-            push(@dependencies, "$a{namew}_ILIBDIR = $found_ilib");
+            push(@dependencies, "$a{aname}_ILIBDIR = $found_ilib");
         }
     }
 }
 
+my ($E_BINDIR, $E_LIBDIR, $VERSION, $MAJVERS, $E_VERSION_LIBX, $E_MAJVERS_LIBX,
+                                              $E_VERSION_EXEX, $E_MAJVERS_EXEX)
+    = (''    , '');
+
 if ($OS ne 'win' && ! $OPT{'status'}) {
+    if ($OSTYPE =~ /darwin/i && CONFIG_OUT() ne '.') {
+        my $COMP = File::Spec->catdir(CONFIG_OUT(), 'COMP.mac');
+        println "configure: creating '$COMP' ($TOOLS)" unless ($AUTORUN);
+        open F, ">$COMP" or die "cannot open $COMP to write";
+        print F "$TOOLS\n";
+        close F;
+    }
+
     # create Makefile.config
     println "configure: creating '$OUT_MAKEFILE'" unless ($AUTORUN);
     open my $F, ">$OUT_MAKEFILE" or die "cannot open $OUT_MAKEFILE to write";
@@ -477,34 +604,53 @@ if ($OS ne 'win' && ! $OPT{'status'}) {
     print $F <<EndText;
 ### AUTO-GENERATED FILE ###
 
-OS_ARCH = \$(shell perl \$(TOP)/os-arch.perl)
+# configuration command
+
+CONFIGURED = $CONFIGURED
+
+OS_ARCH = \$(shell perl \$(TOP)/setup/os-arch.perl)
 
 # install paths
 EndText
 
-    L($F, "INST_BINDIR = $OPT{bindir}"        ) if ($OPT{bindir});
-    L($F, "INST_LIBDIR = $OPT{libdir}"        ) if ($OPT{libdir});
-    L($F, "INST_INCDIR = $OPT{includedir}"    ) if ($OPT{includedir});
+    L($F, "INST_BINDIR = $OPT{'bindir'}"      ) if ($OPT{'bindir'});
+    L($F, "INST_LIBDIR = $OPT{'libdir'}"      ) if ($OPT{'libdir'});
+    L($F, "INST_INCDIR = $OPT{'includedir'}"  ) if ($OPT{'includedir'});
     L($F, "INST_SCHEMADIR = $OPT{'shemadir'}" ) if ($OPT{'shemadir'});
     L($F, "INST_SHAREDIR = $OPT{'sharedir'}"  ) if ($OPT{'sharedir'});
     L($F, "INST_JARDIR = $OPT{'javadir'}"     ) if ($OPT{'javadir'});
     L($F, "INST_PYTHONDIR = $OPT{'pythondir'}") if ($OPT{'pythondir'});
 
-    my ($VERSION_SHLX, $MAJMIN_SHLX, $MAJVERS_SHLX);
+    my ($E_VERSION_SHLX, $VERSION_SHLX,
+        $E_MAJVERS_SHLX , $MAJMIN_SHLX, $MAJVERS_SHLX);
     if ($OSTYPE =~ /darwin/i) {
+        $E_VERSION_SHLX =  '$VERSION.$SHLX';
         $VERSION_SHLX = '$(VERSION).$(SHLX)';
         $MAJMIN_SHLX  = '$(MAJMIN).$(SHLX)';
+        $E_MAJVERS_SHLX = '$MAJVERS.$SHLX';
         $MAJVERS_SHLX = '$(MAJVERS).$(SHLX)';
     } else {
+        $E_VERSION_SHLX =  '$SHLX.$VERSION';
         $VERSION_SHLX = '$(SHLX).$(VERSION)';
         $MAJMIN_SHLX  = '$(SHLX).$(MAJMIN)';
+        $E_MAJVERS_SHLX =  '$SHLX.$MAJVERS';
         $MAJVERS_SHLX = '$(SHLX).$(MAJVERS)';
     }
 
+    $E_VERSION_LIBX = '$LIBX.$VERSION';
+    $E_MAJVERS_LIBX = '$LIBX.$MAJVERS';
 
-    print $F <<EndText;
+    L($F);
+    L($F, "# build type");
+
+    if ($OPT{'enable-static'}) {
+        L($F, "WANTS_STATIC = 1");
+    }
 
-# build type
+    $E_VERSION_EXEX = '$EXEX.$VERSION';
+    $E_MAJVERS_EXEX = '$LIBX.$MAJVERS';
+
+    print $F <<EndText;
 BUILD = $BUILD
 
 # target OS
@@ -587,11 +733,12 @@ EndText
     }
 
     L($F, 'CLSPATH = -classpath $(CLSDIR)');
+    L($F, "NO_ARRAY_BOUNDS_WARNING = $NO_ARRAY_BOUNDS_WARNING");
     L($F);
 
     # version information
 
-    my ($VERSION, $MAJMIN, $MAJVERS);
+    my $MAJMIN;
 
     if ($FULL_VERSION =~ /(\d+)\.(\d+)\.(\d+)-?\w*\d*/) {
         $VERSION = "$1.$2.$3";
@@ -608,6 +755,7 @@ MAJMIN  = $MAJMIN
 MAJVERS = $MAJVERS
 
 # output path
+BUILD_PREFIX = $BUILD_PREFIX
 TARGDIR = $TARGDIR
 
 # derived paths
@@ -618,16 +766,21 @@ BINDIR    = \$(TARGDIR)/bin
 EndText
 
     if ($PKG{LNG} eq 'C') {
+        $E_BINDIR        = '$TARGDIR/bin';
+        $E_LIBDIR        = '$TARGDIR/lib';
         L($F, 'LIBDIR    = $(TARGDIR)/lib');
     } elsif ($PKG{LNG} eq 'JAVA') {
+        $E_LIBDIR        = '$TARGDIR/jar';
         L($F, 'LIBDIR    = $(TARGDIR)/jar');
     }
 
-    print $F <<EndText;
-ILIBDIR   = \$(TARGDIR)/ilib
-OBJDIR    = \$(TARGDIR)/obj/\$(MODPATH)
-CLSDIR    = \$(TARGDIR)/cls
-EndText
+    L($F, 'ILIBDIR   = $(TARGDIR)/ilib');
+    if ($PKG{NOMODPATH}) {
+        L($F, 'OBJDIR    = $(TARGDIR)/obj');
+    } else {
+        L($F, 'OBJDIR    = $(TARGDIR)/obj/$(MODPATH)');
+    }
+    L($F, 'CLSDIR    = $(TARGDIR)/cls');
 
     if ($PKG{LNG} eq 'JAVA') {
         L($F,
@@ -747,6 +900,51 @@ EndText
         T($F, '  fi');
     }
     close $F;
+
+    # create Makefile.config.install
+    println "configure: creating '$INS_MAKEFILE'" unless ($AUTORUN);
+    open $F, ">$INS_MAKEFILE" or die "cannot open $INS_MAKEFILE to write";
+
+    $OPT{'javadir' } = '' unless ($OPT{'javadir' });
+    $OPT{'sharedir'} = '' unless ($OPT{'sharedir'});
+
+    print $F "sub CONFIGURE {\n";
+    print $F "    \$_{PACKAGE_NAME } = '$PACKAGE_NAME';\n";
+    print $F "    \$_{VERSION      } = '$VERSION';\n";
+    print $F "    \$_{LNG          } = '$PKG{LNG}';\n";
+    print $F "    \$_{OS           } = '$OS';\n";
+    print $F "    \$_{BITS         } =  $BITS;\n";
+    print $F "    \$_{MAJVERS      } =  $MAJVERS;\n";
+    print $F "    \$_{LPFX         } = '$LPFX';\n";
+    print $F "    \$_{LIBX         } = '$LIBX';\n";
+    print $F "    \$_{MAJVERS_LIBX } = '" . expand($E_MAJVERS_LIBX) . "';\n";
+    print $F "    \$_{VERSION_LIBX } = '" . expand($E_VERSION_LIBX) . "';\n";
+    print $F "    \$_{SHLX         } = '$SHLX';\n";
+    print $F "    \$_{MAJVERS_SHLX } = '" . expand($E_MAJVERS_SHLX) . "';\n";
+    print $F "    \$_{VERSION_SHLX } = '" . expand($E_VERSION_SHLX) . "';\n";
+    print $F "    \$_{VERSION_EXEX } = '" . expand($E_VERSION_EXEX) . "';\n";
+    print $F "    \$_{MAJVERS_EXEX } = '" . expand($E_MAJVERS_EXEX) . "';\n";
+    print $F "    \$_{INCDIR       } = '" . expand("$Bin/.."      ) . "';\n";
+    if ($PKG{LNG} ne 'PYTHON') {
+        print $F "  \$_{BINDIR$BITS} = '" . expand($E_BINDIR      ) . "';\n";
+        print $F "  \$_{LIBDIR$BITS} = '" . expand($E_LIBDIR      ) . "';\n";
+    } elsif ($OPT{PYTHON_LIB_PATH}) {
+        print $F "  \$_{LIBDIR$BITS} = '$OPT{PYTHON_LIB_PATH}';\n";
+    }
+    print $F "    \$_{OTHER_PREFIX } = '$PKG{UPATH}';\n";
+    print $F "    \$_{PREFIX       } = '$OPT{'prefix'}';\n";
+    print $F "    \$_{INST_INCDIR  } = '$OPT{'includedir'}';\n";
+    print $F "    \$_{INST_BINDIR  } = '$OPT{'bindir'}';\n";
+    print $F "    \$_{INST_LIBDIR  } = '$OPT{'libdir'}';\n";
+    print $F "    \$_{INST_JARDIR  } = '$OPT{'javadir'}';\n";
+    print $F "    \$_{INST_SHAREDIR} = '$OPT{'sharedir'}';\n";
+    print $F "\n";
+    print $F "    \@_\n";
+    print $F "}\n";
+    print $F "\n";
+    print $F "1\n";
+
+    close $F;
 }
 
 if (! $OPT{'status'} ) {
@@ -768,7 +966,7 @@ EndText
             my $NGS_SDK_PREFIX = '';
             $NGS_SDK_PREFIX = $a{found_itf} if ($a{found_itf});
             if ($a{name} eq 'ngs-sdk') {
-                my $root = "$a{namew}_ROOT";
+                my $root = "$a{aname}_ROOT";
                 print OUT "    <$root>$NGS_SDK_PREFIX\/</$root>\n";
                 last;
             }
@@ -786,12 +984,20 @@ EndText
         open COUT, ">$out" or die "cannot open $out to write";
         print COUT "### AUTO-GENERATED FILE ###\n";
         print COUT "\n";
-        print COUT "OS_ARCH = \$(shell perl \$(TOP)/os-arch.perl)\n";
+        print COUT "OS_ARCH = \$(shell perl \$(TOP)/setup/os-arch.perl)\n";
         print COUT "include \$(TOP)/$CONFIG_OUT/Makefile.config.\$(OS_ARCH)\n";
         close COUT;
     }
 }
 
+unless ($OPT{'reconfigure'}) {
+    println "configure: creating 'reconfigure'" unless ($AUTORUN);
+    $CONFIGURED =~ s/\t/ /g;
+    open my $F, '>reconfigure' or die 'cannot open reconfigure to write';
+    print $F "./configure $CONFIGURED\n";
+    close $F;
+}
+
 status() if ($OS ne 'win');
 
 unlink 'a.out';
@@ -817,8 +1023,11 @@ sub status {
                 $BUILD_TYPE = $1;
             } elsif (/BUILD \?= /) {
                 $BUILD_TYPE = $_ unless ($BUILD_TYPE);
-            }
-            elsif (/TARGDIR = /) {
+            } elsif (/BUILD_PREFIX = /) {
+                $BUILD_PREFIX = $_;
+            } elsif (/CONFIGURED = (.*)/) {
+                $CONFIGURED = $1;
+            } elsif (/TARGDIR = /) {
                 $TARGDIR = $_;
                 println "\t\tgot $_" if ($OPT{'debug'});
             } elsif (/TARGDIR \?= (.+)/) {
@@ -826,18 +1035,19 @@ sub status {
                 println "\t\tgot $_" if ($OPT{'debug'});
             }
             elsif (/INST_INCDIR = (.+)/) {
-                $OPT{includedir} = $1;
+                $OPT{'includedir'} = $1;
             }
             elsif (/INST_BINDIR = (.+)/) {
-                $OPT{bindir} = $1;
+                $OPT{'bindir'} = $1;
             }
             elsif (/INST_LIBDIR = (.+)/) {
-                $OPT{libdir} = $1;
+                $OPT{'libdir'} = $1;
             }
         }
     }
 
     println "build type: $BUILD_TYPE";
+    println "build prefix: $BUILD_PREFIX" if ($OS ne 'win');
     println "build output path: $TARGDIR" if ($OS ne 'win');
 
 #   print "prefix: ";    print $OPT{'prefix'} if ($OS ne 'win');    println;
@@ -860,13 +1070,24 @@ sub status {
     println "javadir: $OPT{'javadir'}" if ($OPT{'javadir'});
     println "pythondir: $OPT{'pythondir'}" if ($OPT{'pythondir'});
 
-    println;
+    $CONFIGURED =~ s/\t/ /g;
+    println "configured with: \"$CONFIGURED\"";
 }
 
-sub expand {
+sub expand { $_[0] =~ s/(\$\w+)/$1/eeg; $_[0]; }
+
+sub expand_path {
     my ($filename) = @_;
     return unless ($filename);
+
     if ($filename =~ /^~/) {
+        if ($filename =~ m|^~([^/]*)|) {
+            if ($1 && ! getpwnam($1)) {
+                print "configure: error: bad path: '$filename'\n";
+                exit 1;
+            }
+        }
+
         $filename =~ s{ ^ ~ ( [^/]* ) }
                       { $1
                             ? (getpwnam($1))[7]
@@ -875,6 +1096,7 @@ sub expand {
                               )
                       }ex;
     }
+
     my $a = abs_path($filename);
     $filename = $a if ($a);
     $filename;
@@ -882,34 +1104,33 @@ sub expand {
 
 sub find_in_dir {
     my ($dir, $include, $lib, $ilib) = @_;
-    print "\t$dir... " unless ($AUTORUN);
     unless (-d $dir) {
-        println "no" unless ($AUTORUN);
+#       println "no" unless ($AUTORUN);
         println "\t\tnot found $dir" if ($OPT{'debug'});
         return;
     }
-    print "[found] " if ($OPT{'debug'});
+#   print "\t$dir... " unless ($AUTORUN);
+#   print "[found] " if ($OPT{'debug'});
     my ($found_inc, $found_lib, $found_ilib);
-    my $nl = 1;
     if ($include) {
-        print "includes... " unless ($AUTORUN);
+        print "\tincludes... " unless ($AUTORUN);
         if (-e "$dir/$include") {
-            println 'yes' unless ($AUTORUN);
+            println $dir unless ($AUTORUN);
             $found_inc = $dir;
         } elsif (-e "$dir/include/$include") {
-            println 'yes' unless ($AUTORUN);
+            println $dir unless ($AUTORUN);
             $found_inc = "$dir/include";
         } elsif (-e "$dir/interfaces/$include") {
-            println 'yes' unless ($AUTORUN);
+            println $dir unless ($AUTORUN);
             $found_inc = "$dir/interfaces";
         } else {
+            print "$dir: " if ($OPT{'debug'});
             println 'no' unless ($AUTORUN);
         }
-        $nl = 0;
     }
     if ($lib || $ilib) {
-        print "\n\t" if ($nl && !$AUTORUN);
-        print "libraries... " unless ($AUTORUN);
+#       print "\n\t" if ($nl && !$AUTORUN);
+        print "\tlibraries... " unless ($AUTORUN);
         if ($lib) {
             my $builddir = File::Spec->catdir($dir, $OS, $TOOLS, $ARCH, $BUILD);
             my $libdir  = File::Spec->catdir($builddir, 'lib');
@@ -923,14 +1144,14 @@ sub find_in_dir {
                     my $f = File::Spec->catdir($ilibdir, $ilib);
                     print "\tchecking $f\n\t" if ($OPT{'debug'});
                     if (-e $f) {
-                        println 'yes';
+                        println $ilibdir;
                         $found_ilib = $ilibdir;
                     } else {
                         println 'no' unless ($AUTORUN);
                         return;
                     }
                 } else {
-                    println 'yes';
+                    println $libdir;
                 }
                 ++$found;
             }
@@ -939,7 +1160,7 @@ sub find_in_dir {
                 my $f = File::Spec->catdir($libdir, $lib);
                 print "\tchecking $f\n\t" if ($OPT{'debug'});
                 if (-e $f) {
-                    println 'yes';
+                    println $libdir;
                     $found_lib = $libdir;
                     ++$found;
                 }
@@ -957,16 +1178,18 @@ sub find_in_dir {
                         my $f = File::Spec->catdir($ilibdir, $ilib);
                         print "\tchecking $f\n\t" if ($OPT{'debug'});
                         if (-e $f) {
-                            println 'yes';
+                            println $ilibdir;
                             $found_ilib = $ilibdir;
                         } else {
                             println 'no' unless ($AUTORUN);
                             return;
                         }
                     } else {
-                        println 'yes';
+                        println $libdir;
                     }
                     ++$found;
+                } else {
+                    println 'no' unless ($AUTORUN);
                 }
             }
         }
@@ -976,7 +1199,6 @@ sub find_in_dir {
             println 'no' unless ($AUTORUN);
             undef $found_lib;
         }
-        ++$nl;
     }
     return ($found_inc, $found_lib, $found_ilib);
 }
@@ -994,38 +1216,90 @@ sub reverse_build {
 
 ################################################################################
 
+sub check_tool {
+    my ($tool) = @_;
+    print "checking for $tool... ";
+    my $cmd = "$tool --help";
+    print "\n\t\trunning $cmd\n\t" if ($OPT{'debug'});
+    my $out = `$cmd 2>&1`;
+    if ($? == 0) {
+        println "yes";
+        return 1;
+    } else {
+        println "no";
+        return 0;
+    }
+}
+
+sub check_no_array_bounds {
+    check_compiler('O', '-Wno-array-bounds');
+}
+
 sub find_lib {
-    my ($n, $i, $l) = @_;
+    check_compiler('L', @_);
+}
 
-    print "checking for $n library... ";
+sub check_compiler {
+    my ($t, $n, $i, $l) = @_;
+    my $tool = $TOOLS;
+
+    if ($t eq 'L') {
+        print "checking for $n library... ";
+    } elsif ($t eq 'O') {
+        if ($tool && $tool eq 'gcc') {
+            print "checking whether gcc accepts $n... ";
+        } else {
+            return;
+        }
+    } else {
+        die "Unknown check_compiler option: '$t'";
+    }
+
+    unless ($tool) {
+        println "warning: unknown tool";
+        return;
+    }
 
     while (1) {
-        my ($library, $log);
+        my ($flags, $library, $log) = ('', '');
 
-        if ($n eq 'hdf5') {
+        if ($t eq 'O') {
+            $flags = $n;
+            $log = '                      int main() {                     }\n'
+        } elsif ($n eq 'hdf5') {
             $library = '-lhdf5';
-            $log = '#include <hdf5.h>            \n main() { H5close     (); }';
-        } elsif ($n eq 'xml2') {
-            $library = '-lxml2';
-            $log = '#include <libxml/xmlreader.h>\n main() { xmlInitParser();}';
+            $log = '#include <hdf5.h>  \n int main() { H5close         (); }\n'
+        } elsif ($n eq 'fuse') {
+            $flags = '-D_FILE_OFFSET_BITS=64';
+            $library = '-lfuse';
+            $log = '#include <fuse.h>  \n int main() { fuse_get_context(); }\n'
         } elsif ($n eq 'magic') {
             $library = '-lmagic';
-            $log = '#include <magic.h>           \n main() { magic_open (0); }';
+            $log = '#include <magic.h> \n int main() { magic_open     (0); }\n'
+        } elsif ($n eq 'xml2') {
+            $library = '-lxml2';
+            $log = '#include <libxml/xmlreader.h>\n' .
+                                         'int main() { xmlInitParser  ( ); }\n'
         } else {
             println 'unknown: skipped';
             return;
         }
 
-        if (($i && ! -d $i) || ($l && ! -d $l)) {
+        if ($i && ! -d $i) {
+            print "'$i': " if ($OPT{'debug'});
             println 'no';
             return;
         }
+        if ($l && ! -d $l) {
+            print "'$l': " if ($OPT{'debug'});            println 'no';
+            return;
+        }
 
         my $cmd = $log;
         $cmd =~ s/\\n/\n/g;
 
-        my $gcc = "| gcc -xc " . ($i ? "-I$i " : ' ')
-                               . ($l ? "-L$l " : ' ') . "- $library";
+        my $gcc = "| $tool -xc $flags " . ($i ? "-I$i " : ' ')
+                                      . ($l ? "-L$l " : ' ') . "- $library";
         $gcc .= ' 2> /dev/null' unless ($OPT{'debug'});
 
         open GCC, $gcc or last;
@@ -1039,6 +1313,8 @@ sub find_lib {
 
         return if (!$ok);
 
+        return 1 if ($t eq 'O');
+
         return ($i, $l);
     }
 
@@ -1057,36 +1333,47 @@ sub check {
 
     my %PKG = PKG();
 
-    die "No LNG"   unless $PKG{LNG};
-    die "No OUT"   unless $PKG{OUT};
-    die "No PATH"  unless $PKG{PATH};
-    die "No UPATH" unless $PKG{UPATH};
+    die "No LNG"    unless $PKG{LNG};
+    die "No LOCOUT" unless $PKG{LOCOUT};
+    die "No OUT"    unless $PKG{OUT};
+    die "No PATH"   unless $PKG{PATH};
+    die "No UPATH"  unless $PKG{UPATH};
 
     foreach my $href (DEPENDS()) { die "No DEPENDS::name" unless $href->{name} }
 
     foreach my $href (REQ()) {
-        die "No REQ::name" unless $href->{name};
-
-        my $origin = $href->{origin};
-        die  "No $href->{name}:origin"  unless $origin;
-        die  "No $href->{name}:include" unless $href->{include};
-        die  "No $href->{name}:lib"     unless $href->{lib};
-        die  "No $href->{name}:option"  unless $href->{option};
-        die  "No $href->{name}:pkgpath" unless $href->{pkgpath};
-        die  "No $href->{name}:type"    unless $href->{type};
-        die  "No $href->{name}:usrpath" unless $href->{usrpath};
-        if ($origin eq 'I') {
-         die "No $href->{name}:bldpath" unless $href->{bldpath};
-         die "No $href->{name}:ilib"    unless $href->{ilib};
-         die "No $href->{name}:namew"   unless $href->{namew};
-         die "No $href->{name}:srcpath" unless $href->{srcpath};
+        die         "No REQ::name" unless $href->{name};
+
+        die         "No $href->{name}:option"  unless $href->{option};
+
+        die         "No $href->{name}:type"    unless $href->{type};
+        unless ($href->{type} =~ /I/) {
+            die     "No $href->{name}:lib"     unless $href->{lib};
+            die     "No $href->{name}:pkgpath" unless $href->{pkgpath};
+            die     "No $href->{name}:usrpath" unless $href->{usrpath};
+        }
+
+        die         "No $href->{name}:origin"  unless $href->{origin};
+        if ($href->{origin} eq 'I') {
+            die     "No $href->{name}:aname"   unless $href->{aname};
+            unless ($href->{type} =~ /D/) {
+                die "No $href->{name}:include" unless $href->{include};
+                die "No $href->{name}:srcpath" unless $href->{srcpath};
+            }
+            unless ($href->{type} =~ /I/) {
+                die "No $href->{name}:bldpath"    unless $href->{bldpath   };
+                die "No $href->{name}:locbldpath" unless $href->{locbldpath};
+            }
+            if ($href->{type} =~ /B/) {
+                die "No $href->{name}:ilib"    unless $href->{ilib};
+            }
         }
     }
 }
 
 ################################################################################
 
-sub optional { $_[0] =~ /^[LS]I$/ }
+sub optional { $_[0] =~ /O/ }
 
 sub help {
 #  --prefix=PREFIX         install architecture-independent files in PREFIX
@@ -1123,10 +1410,14 @@ EndText
     
         if (PACKAGE_TYPE() eq 'B') {
             print "\`$package_default_prefix/bin', ";
-        } else {
+        } elsif (PACKAGE_TYPE() eq 'L') {
             print "\`$package_default_prefix/include', ";
         }
-        println "\`$package_default_prefix/lib' etc.";
+        if (PACKAGE_TYPE() eq 'P') {
+            println "\`$package_default_prefix/share' etc.";
+        } else {
+            println "\`$package_default_prefix/lib' etc.";
+        }
 
         print <<EndText;
 You can specify an installation prefix other than \`$package_default_prefix'
@@ -1184,27 +1475,50 @@ EndText
         println;
     }
 
-    print <<EndText if ($^O ne 'MSWin32');
+    print <<EndText if (PACKAGE_TYPE() eq 'B');
+Optional Features:
+  --enable-static         build static executable [default=no]
+
+EndText
+
+    my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
+
+    if ($^O ne 'MSWin32') {
+        print <<EndText;
 Build tuning:
   --with-debug
   --without-debug
-  --arch=name             specify the name of the target architecture
+EndText
 
-  --build=DIR             generate build output into DIR directory
+        if (@ARCHITECTURES) {
+            print
+"  --arch=name             specify the name of the target architecture\n";
+        }
+
+        print <<EndText;
+
+  --build-prefix=DIR      generate build output into DIR directory
                           [$OUTDIR]
 
 EndText
+    }
 
-    println "Miscellaneous:";
+    println 'Miscellaneous:';
+    println '  --reconfigure           rerun `configure\'';
+    println '                          using the same command-line arguments';
     if ($^O ne 'MSWin32') {
         println
-            "  --status                print current configuration information"
+            '  --status                print current configuration information'
     }
-    println "  --clean                 remove all configuration results";
-    println "  --debug                 print lots of debugging information";
-    println;
+    print <<EndText;
+  --clean                 remove all configuration results
+  --debug                 print lots of debugging information
+
+If `configure' was arleady run running `configure' without options
+will rerun `configure' using the same command-line arguments.
+
+Report bugs to sra-tools\@ncbi.nlm.nih.gov
+EndText
 }
 
-=pod
 ################################################################################
-=cut
diff --git a/ngs-python/configure b/ngs-python/setup/ngs-python/install
similarity index 82%
copy from ngs-python/configure
copy to ngs-python/setup/ngs-python/install
index 3313aac..b1e201d 100755
--- a/ngs-python/configure
+++ b/ngs-python/setup/ngs-python/install
@@ -29,17 +29,17 @@ CURDIR="`dirname $0`"
 
 if [ -z "$CURDIR" ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
     exit 1
 fi
 
-if [ "$FILENAME" != configure -a ! -s konfigure.perl ]
+if [ "$FILENAME" != install -a ! -s setup/install.perl ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
 else
     perl -v > /dev/null 2>&1 || { echo "checking for perl... no"; \
-        echo >&2 "configure: error: perl not found."; exit 1; }
+        echo >&2 "error: perl not found."; exit 1; }
 
-    cd $CURDIR
-    perl -w ./konfigure.perl $@
+    cd $CURDIR/setup
+    perl -w ./install.perl "$@"
 fi
diff --git a/ngs-python/setup/ngs-python/linux/os.prl b/ngs-python/setup/ngs-python/linux/os.prl
new file mode 100644
index 0000000..5f75471
--- /dev/null
+++ b/ngs-python/setup/ngs-python/linux/os.prl
@@ -0,0 +1,2 @@
+sub OS { 'linux' }
+1
diff --git a/ngs-python/setup/ngs-python/mac/os.prl b/ngs-python/setup/ngs-python/mac/os.prl
new file mode 100644
index 0000000..b962c57
--- /dev/null
+++ b/ngs-python/setup/ngs-python/mac/os.prl
@@ -0,0 +1,2 @@
+sub OS { 'mac' }
+1
diff --git a/ngs-sdk/os-arch.perl b/ngs-python/setup/os-arch.perl
similarity index 80%
rename from ngs-sdk/os-arch.perl
rename to ngs-python/setup/os-arch.perl
index a7b4990..5f3f87a 100644
--- a/ngs-sdk/os-arch.perl
+++ b/ngs-python/setup/os-arch.perl
@@ -1,14 +1,14 @@
 use strict;
 
 use FindBin qw($Bin);
-require "$Bin/os-arch.pm";
+require "$Bin/os-arch.prl";
 
 my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
 
 my $res = "$OS.$ARCH";
 
 if (@ARCHITECTURES) {
-    my $name = "$Bin/Makefile.config.$OS.arch";
+    my $name = "$Bin/../Makefile.config.$OS.arch";
     if (-e $name) {
         while (1) {
             open F, $name or last;
diff --git a/ngs-python/os-arch.pm b/ngs-python/setup/os-arch.prl
similarity index 95%
rename from ngs-python/os-arch.pm
rename to ngs-python/setup/os-arch.prl
index 6fbd606..791b556 100644
--- a/ngs-python/os-arch.pm
+++ b/ngs-python/setup/os-arch.prl
@@ -18,6 +18,8 @@ sub OsArch {
             $HOST_OS = 'win';
         } elsif ($UNAME =~ /xMINGW/) {
             $HOST_OS = 'win';
+        } else {
+            $HOST_OS = $UNAME;
         }
         if ($HOST_OS eq 'mac') {
             $MARCH = $HOST_ARCH = MacArch();
@@ -50,7 +52,9 @@ sub OsArch {
                 @ARCHITECTURES = qw(x86_64 i386);
             } elsif ($MARCH =~ /sun4v/) {
                 $HOST_ARCH = 'sparc64';
-		        @ARCHITECTURES = qw(sparc64 sparc32);
+                @ARCHITECTURES = qw(sparc64 sparc32);
+            } else {
+                $HOST_ARCH = $MARCH;
             }
         }
     }
diff --git a/ngs-python/package.pm b/ngs-python/setup/package.prl
similarity index 67%
rename from ngs-python/package.pm
rename to ngs-python/setup/package.prl
index 094f4f6..800c556 100644
--- a/ngs-python/package.pm
+++ b/ngs-python/setup/package.prl
@@ -1,42 +1,38 @@
 ################################################################################
 sub PACKAGE      { "ngs-python" }
-sub VERSION      { "1.0.0" }
-sub PACKAGE_TYPE { 'B' }
+sub VERSION      { "1.0.1" }
+sub PACKAGE_TYPE { 'P' }
 sub PACKAGE_NAME { "NGS-PYTHON" }
 sub PACKAGE_NAMW { "NGS_PYTHON" }
 sub DEPENDS      {}
 sub CONFIG_OUT   { '.' }
-sub PKG { ( LNG  => 'PYTHON',
-            OUT  => 'ncbi-outdir',
+sub PKG { ( LNG   => 'PYTHON',
+            OUT   => 'ncbi-outdir',
+            LOCOUT=> '../../../OUTDIR',
             PATH  => '/usr/local/ngs/ngs-python',
             UPATH =>      '$HOME/ngs/ngs-python',
             EXAMP => '1', ) }
 sub REQ { (
             { name    => 'ngs-sdk',
-              namew   => 'NGS',
+              aname   => 'NGS',
               option  => 'with-ngs-sdk-prefix',
               origin  => 'I',
-              type    => 'L',
-              srcpath => '../ngs-sdk',
+              type    => 'DO',
               pkgpath => '/usr/local/ngs/ngs-sdk',
               usrpath =>      '$HOME/ngs/ngs-sdk',
               bldpath => '$HOME/ncbi-outdir/ngs-sdk',
-              include => 'ngs/itf/Refcount.h',
+              locbldpath=>'$Bin/../../../OUTDIR/ngs-sdk',
               lib     => 'libngs-sdk.$SHLX',
-              ilib    => 'libngs-bind-c++.a',
             },
             { name    => 'ncbi-vdb',
-              namew   => 'VDB',
+              aname   => 'VDB',
               option  => 'with-ncbi-vdb-prefix',
               origin  => 'I',
-              type    => 'L',
-              srcpath => '../../ncbi-vdb',
+              type    => 'DO',
               pkgpath => '/usr/local/ncbi/ncbi-vdb',
               usrpath =>      '$HOME/ncbi/ncbi-vdb',
               bldpath => '$HOME/ncbi-outdir/ncbi-vdb',
-              include => 'klib/rc.h',
+              locbldpath=>'$Bin/../../../OUTDIR/ncbi-vdb',
               lib     => 'libncbi-vdb.$SHLX',
-              ilib    => 'libkapp.a',
              } ) }
-
 1
diff --git a/ngs-python/win-configure.bat b/ngs-python/win-configure.bat
deleted file mode 100644
index 47a955e..0000000
--- a/ngs-python/win-configure.bat
+++ /dev/null
@@ -1 +0,0 @@
-perl -w ./konfigure.perl %*
diff --git a/ngs-sdk/.gitignore b/ngs-sdk/.gitignore
index 3d8aed4..966470c 100644
--- a/ngs-sdk/.gitignore
+++ b/ngs-sdk/.gitignore
@@ -1,5 +1,10 @@
-Makefile.userconfig
-Makefile.config*
-user.status
 *.o
-
+/Makefile.config*
+/Makefile.userconfig
+/reconfigure
+/user.status
+/win/ipch
+/win/ngs-sdk.opensdf
+/win/ngs-sdk.sdf
+/win/ngs-sdk.suo
+/win/ipch
diff --git a/ngs-sdk/Makefile.install b/ngs-sdk/Makefile.install
index f42deb8..40d079a 100644
--- a/ngs-sdk/Makefile.install
+++ b/ngs-sdk/Makefile.install
@@ -32,8 +32,6 @@ include $(TOP)/Makefile.config
 #-------------------------------------------------------------------------------
 # install
 # 
-ifeq (linux, $(OS))
-
 LIBRARIES_TO_INSTALL = \
     ngs-sdk.$(VERSION_SHLX) \
     ngs-c++.$(VERSION_LIBX) \
@@ -63,8 +61,14 @@ copyexamples:
 INCLUDE_SYMLINK = $(ROOT)/usr/include/ngs
 PROFILE_FILE = $(ROOT)/etc/profile.d/ngs-sdk
 
+ifeq (linux, $(OS))
+    ifeq (0, $(shell id -u))
+        LINUX_ROOT = true
+    endif
+endif
+
 install: copylibs copyincludes copyexamples
-ifeq (0, $(shell id -u))
+ifeq (true, $(LINUX_ROOT))
 	@ # install symlink to includes 
 	@ echo "Updating $(INCLUDE_SYMLINK)"
 	@ rm -f $(INCLUDE_SYMLINK)
@@ -97,12 +101,6 @@ else
 	@ echo "      export NGS_LIBDIR=$(LIB_TARGET)"   
 	@ echo "      ld -L\$$NGS_LIBDIR -lngs-sdk ..."
 endif
-.PHONY: copylibs copyincludes copyexamples
-
-else
-install:
-
-endif
 
-.PHONY: install
+.PHONY: install copylibs copyincludes copyexamples
 
diff --git a/ngs-sdk/Makefile.libs b/ngs-sdk/Makefile.libs
index 31068d1..289335d 100644
--- a/ngs-sdk/Makefile.libs
+++ b/ngs-sdk/Makefile.libs
@@ -43,7 +43,7 @@ TARGETS =      \
 all std: $(TARGETS)
 
 clean:
-	@ rm -rf $(OBJDIR)ngs-bind-c++ $(OBJDIR)ngs-disp
+	@ rm -rf $(OBJDIR)/*
 	@ rm -f $(addprefix $(ILIBDIR)/$(LPFX),$(addsuffix *,$(INTLIBS))) \
 			$(addprefix $(LIBDIR)/$(LPFX),$(addsuffix *,$(EXTLIBS)))
 
@@ -51,15 +51,19 @@ clean:
 # C++ client library that provides API to any engine
 ngs-c++: $(LIBDIR) $(LIBDIR)/$(LPFX)ngs-c++.$(LIBX)
 
+ifeq (,$(MAKE_MANIFEST))
+MAKE_MANIFEST = ( cd $@; $(ARX) $^; $(ARLS) $^ | sed -e '/__\.SYMDEF/d' -e 's/^\(..*\)$$/$(subst /,\/,$@)\/\1/' > $@/manifest )
+endif
+
 $(OBJDIR)ngs-bind-c++: $(ILIBDIR)/$(LPFX)ngs-bind-c++.$(LIBX)
 	rm -rf $@
 	mkdir -p $@
-	( cd $@; $(ARX) $^; $(ARLS) $^ | sed -e '/__\.SYMDEF/d' -e 's/^\(..*\)$$/$(subst /,\/,$@)\/\1/' > $@/manifest )
+	$(MAKE_MANIFEST)
 
 $(OBJDIR)ngs-disp: $(ILIBDIR)/$(LPFX)ngs-disp.$(LIBX)
 	rm -rf $@
 	mkdir -p $@
-	( cd $@; $(ARX) $^; $(ARLS) $^ | sed -e '/__\.SYMDEF/d' -e 's/^\(..*\)$$/$(subst /,\/,$@)\/\1/' > $@/manifest )
+	$(MAKE_MANIFEST)
 
 $(LIBDIR)/$(LPFX)ngs-c++.$(VERSION_LIBX): $(OBJDIR)ngs-bind-c++ $(OBJDIR)ngs-disp
 	( $(AR) $@ `cat $(addsuffix /manifest,$^)` )
@@ -80,12 +84,12 @@ ngs-sdk: $(LIBDIR) $(LIBDIR)/$(LPFX)ngs-sdk.$(SHLX)
 $(OBJDIR)ngs-bind-java: $(ILIBDIR)/$(LPFX)ngs-bind-java.$(LIBX)
 	rm -rf $@
 	mkdir -p $@
-	( cd $@; $(ARX) $^; $(ARLS) $^ | sed -e '/__\.SYMDEF/d' -e 's/^\(..*\)$$/$(subst /,\/,$@)\/\1/' > $@/manifest )
+	$(MAKE_MANIFEST)
 
 $(OBJDIR)ngs-bind-python: $(ILIBDIR)/$(LPFX)ngs-bind-python.$(LIBX)
 	rm -rf $@
 	mkdir -p $@
-	( cd $@; $(ARX) $^; $(ARLS) $^ | sed -e '/__\.SYMDEF/d' -e 's/^\(..*\)$$/$(subst /,\/,$@)\/\1/' > $@/manifest )
+	$(MAKE_MANIFEST)
 
 # sub-libraries to link against
 SDK_LIB =        \
diff --git a/ngs-sdk/Makefile.rules b/ngs-sdk/Makefile.rules
index 1ac77d3..b67ceaa 100644
--- a/ngs-sdk/Makefile.rules
+++ b/ngs-sdk/Makefile.rules
@@ -61,9 +61,9 @@ test runtests: Makefile.config default
 	@ $(MAKE) -C test runtests
 
 # rule to run configuration
-Makefile.config: Makefile.config.$(shell perl $(TOP)/os-arch.perl) konfigure.perl
+Makefile.config: Makefile.config.$(shell perl $(TOP)/setup/os-arch.perl) setup/konfigure.perl
 
-Makefile.config.$(shell perl $(TOP)/os-arch.perl):
+Makefile.config.$(shell perl $(TOP)/setup/os-arch.perl):
 	@echo "*** File '$@' is missing. Please run ./configure"
 	@false
 
diff --git a/ngs-sdk/adapter/AlignmentItf.cpp b/ngs-sdk/adapter/AlignmentItf.cpp
index d9854fd..2f3996d 100644
--- a/ngs-sdk/adapter/AlignmentItf.cpp
+++ b/ngs-sdk/adapter/AlignmentItf.cpp
@@ -312,6 +312,21 @@ namespace ngs_adapt
         return 0;
     }
 
+    char CC AlignmentItf :: get_rna_orientation ( const NGS_Alignment_v1 * iself, NGS_ErrBlock_v1 * err )
+    {
+        const AlignmentItf * self = Self ( iself );
+        try
+        {
+            return self -> getRNAOrientation ();
+        }
+        catch ( ... )
+        {
+            ErrBlockHandleException ( err );
+        }
+
+        return false;
+    }
+
     bool CC AlignmentItf :: has_mate ( const NGS_Alignment_v1 * iself, NGS_ErrBlock_v1 * err )
     {
         const AlignmentItf * self = Self ( iself );
@@ -410,10 +425,11 @@ namespace ngs_adapt
         {
             "ngs_adapt::AlignmentItf",
             "NGS_Alignment_v1",
-            0,
+            1,
             & FragmentItf :: ivt . dad
         },
 
+        // v1.0
         get_id,
         get_ref_spec,
         get_map_qual,
@@ -436,7 +452,10 @@ namespace ngs_adapt
         get_mate_alignment,
         get_mate_ref_spec,
         get_mate_is_reversed,
-        next
+        next,
+
+        // v1.1
+        get_rna_orientation
     };
 
 } // namespace ngs_adapt
diff --git a/ngs-sdk/adapter/Makefile b/ngs-sdk/adapter/Makefile
index 9079055..816746a 100644
--- a/ngs-sdk/adapter/Makefile
+++ b/ngs-sdk/adapter/Makefile
@@ -68,7 +68,7 @@ ADAPT_OBJ = \
 
 $(LIBDIR)/$(LPFX)ngs-adapt-c++.$(VERSION_LIBX): $(ADAPT_OBJ)
 	$(AR) $@ $^
-    
+
 $(LIBDIR)/$(LPFX)ngs-adapt-c++.$(MAJVERS_LIBX): $(LIBDIR)/$(LPFX)ngs-adapt-c++.$(VERSION_LIBX)
 	rm -f $@
 	ln -s $(notdir $^) $@
diff --git a/ngs-sdk/ngs/defs.h b/ngs-sdk/adapter/unix/fat86/atomic32.h
similarity index 78%
rename from ngs-sdk/ngs/defs.h
rename to ngs-sdk/adapter/unix/fat86/atomic32.h
index 5661ede..73a397f 100644
--- a/ngs-sdk/ngs/defs.h
+++ b/ngs-sdk/adapter/unix/fat86/atomic32.h
@@ -24,20 +24,10 @@
 *
 */
 
-#ifndef _h_ngs_defs_
-#define _h_ngs_defs_
-
-/*--------------------------------------------------------------------------
- * DLL interface
- */
-#if defined _MSC_VER
- #if defined _LIBRARY
-  #define NGS_EXTERN   __declspec( dllexport ) 
- #else
-  #define NGS_EXTERN   __declspec( dllimport ) 
- #endif
+#if _ARCH_BITS == 32
+#include "../i386/atomic32.h"
+#elif _ARCH_BITS == 64
+#include "../x86_64/atomic32.h"
 #else
- #define NGS_EXTERN   
+#error "_ARCH_BITS not defined to be 32 or 64"
 #endif
-
-#endif /* _h_ngs_defs_ */
diff --git a/ngs-sdk/configure b/ngs-sdk/configure
index 3313aac..baa556f 100755
--- a/ngs-sdk/configure
+++ b/ngs-sdk/configure
@@ -33,13 +33,13 @@ if [ -z "$CURDIR" ]
     exit 1
 fi
 
-if [ "$FILENAME" != configure -a ! -s konfigure.perl ]
+if [ "$FILENAME" != configure -a ! -s setup/konfigure.perl ]
     then
     echo configure: error: configure should be run as ./configure
 else
     perl -v > /dev/null 2>&1 || { echo "checking for perl... no"; \
         echo >&2 "configure: error: perl not found."; exit 1; }
 
-    cd $CURDIR
-    perl -w ./konfigure.perl $@
+    cd $CURDIR/setup
+    perl -w konfigure.perl "$@"
 fi
diff --git a/ngs-sdk/dispatch/AlignmentItf.cpp b/ngs-sdk/dispatch/AlignmentItf.cpp
index 1294870..0749002 100644
--- a/ngs-sdk/dispatch/AlignmentItf.cpp
+++ b/ngs-sdk/dispatch/AlignmentItf.cpp
@@ -400,6 +400,30 @@ namespace ngs
         return StringItf :: Cast ( ret );
     }
 
+    char AlignmentItf :: getRNAOrientation () const
+        throw ( ErrorMsg )
+    {
+        // the object is really from C
+        const NGS_Alignment_v1 * self = Test ();
+
+        // cast vtable to our level
+        const NGS_Alignment_v1_vt * vt = Access ( self -> vt );
+
+        // test for v1.1
+        if ( vt -> dad . minor_version < 1 )
+            throw ErrorMsg ( "the Alignment interface provided by this NGS engine is too old to support this message" );
+
+        // call through C vtable
+        ErrBlock err;
+        assert ( vt -> get_rna_orientation != 0 );
+        char orientation  = ( * vt -> get_rna_orientation ) ( self, & err );
+
+        // check for errors
+        err . Check ();
+
+        return orientation;
+    }
+
     bool AlignmentItf :: hasMate () const
         throw ()
     {
diff --git a/ngs-sdk/language/java/jni_AlignmentItf.cpp b/ngs-sdk/language/java/jni_AlignmentItf.cpp
index 6a2192b..11b945d 100644
--- a/ngs-sdk/language/java/jni_AlignmentItf.cpp
+++ b/ngs-sdk/language/java/jni_AlignmentItf.cpp
@@ -641,6 +641,34 @@ JNIEXPORT jstring JNICALL Java_ngs_itf_AlignmentItf_GetLongCigar
 
 /*
  * Class:     ngs_itf_AlignmentItf
+ * Method:    GetRNAOrientation
+ * Signature: (J)C
+ */
+JNIEXPORT jchar JNICALL Java_ngs_itf_AlignmentItf_GetRNAOrientation
+    ( JNIEnv * jenv, jobject jthis , jlong jself )
+{
+    try
+    {
+        return Self ( jself ) -> getRNAOrientation ();
+    }
+    catch ( ErrorMsg & x )
+    {
+        ErrorMsgThrow ( jenv, xt_error_msg, x . what () );
+    }
+    catch ( std :: exception & x )
+    {
+        ErrorMsgThrow ( jenv, xt_runtime, x . what () );
+    }
+    catch ( ... )
+    {
+        JNI_INTERNAL_ERROR ( jenv, "%s", __func__ );
+    }
+
+    return 0;
+}
+
+/*
+ * Class:     ngs_itf_AlignmentItf
  * Method:    HasMate
  * Signature: (J)Z
  */
diff --git a/ngs-sdk/language/java/jni_AlignmentItf.h b/ngs-sdk/language/java/jni_AlignmentItf.h
index 9a315e8..f1943e5 100644
--- a/ngs-sdk/language/java/jni_AlignmentItf.h
+++ b/ngs-sdk/language/java/jni_AlignmentItf.h
@@ -169,6 +169,14 @@ JNIEXPORT jstring JNICALL Java_ngs_itf_AlignmentItf_GetLongCigar
 
 /*
  * Class:     ngs_itf_AlignmentItf
+ * Method:    GetRNAOrientation
+ * Signature: (J)C
+ */
+JNIEXPORT jchar JNICALL Java_ngs_itf_AlignmentItf_GetRNAOrientation
+  (JNIEnv *, jobject, jlong);
+
+/*
+ * Class:     ngs_itf_AlignmentItf
  * Method:    HasMate
  * Signature: (J)Z
  */
diff --git a/ngs-sdk/language/python/py_AlignmentItf.cpp b/ngs-sdk/language/python/py_AlignmentItf.cpp
index 2c3561b..91d53ca 100644
--- a/ngs-sdk/language/python/py_AlignmentItf.cpp
+++ b/ngs-sdk/language/python/py_AlignmentItf.cpp
@@ -53,6 +53,7 @@ GEN_PY_FUNC_GET_BY_PARAMS_1             ( Alignment, SoftClip, int32_t, uint32_t
 GEN_PY_FUNC_GET                         ( Alignment, TemplateLength, uint64_t )
 GEN_PY_FUNC_GET_STRING_BY_PARAMS_1      ( Alignment, ShortCigar, bool, clipped )
 GEN_PY_FUNC_GET_STRING_BY_PARAMS_1      ( Alignment, LongCigar, bool, clipped )
+GEN_PY_FUNC_GET                         ( Alignment, RNAOrientation, char )
 //GEN_PY_FUNC_GET                         ( Alignment, HasMate, bool ) // TODO: decide what to do with non-standard names
 GEN_PY_FUNC_GET_EXPLICIT_NAMES          ( Alignment, bool, PY_NGS_AlignmentHasMate, hasMate )
 GEN_PY_FUNC_GET_STRING                  ( Alignment, MateAlignmentId )
diff --git a/ngs-sdk/language/python/py_AlignmentItf.h b/ngs-sdk/language/python/py_AlignmentItf.h
index f72880b..68026f7 100644
--- a/ngs-sdk/language/python/py_AlignmentItf.h
+++ b/ngs-sdk/language/python/py_AlignmentItf.h
@@ -55,6 +55,7 @@ PY_RES_TYPE PY_NGS_AlignmentGetSoftClip                  ( void* pRef, uint32_t
 PY_RES_TYPE PY_NGS_AlignmentGetTemplateLength            ( void* pRef, uint64_t* pRet, void** ppNGSStrError );
 PY_RES_TYPE PY_NGS_AlignmentGetShortCigar                ( void* pRef, int clipped, void** ppNGSStringBuf, void** ppNGSStrError );
 PY_RES_TYPE PY_NGS_AlignmentGetLongCigar                 ( void* pRef, int clipped, void** ppNGSStringBuf, void** ppNGSStrError );
+PY_RES_TYPE PY_NGS_AlignmentGetRNAOrientation            ( void* pRef, char* pRet, void** ppNGSStrError );
 PY_RES_TYPE PY_NGS_AlignmentHasMate                      ( void* pRef, int* pRet, void** ppNGSStrError );
 PY_RES_TYPE PY_NGS_AlignmentGetMateAlignmentId           ( void* pRef, void** ppNGSStringBuf, void** ppNGSStrError );
 PY_RES_TYPE PY_NGS_AlignmentGetMateAlignment             ( void* pRef, void** ppRet, void** ppNGSStrError );
diff --git a/ngs-sdk/ngs/Alignment.hpp b/ngs-sdk/ngs/Alignment.hpp
index e76dd36..8587c22 100644
--- a/ngs-sdk/ngs/Alignment.hpp
+++ b/ngs-sdk/ngs/Alignment.hpp
@@ -45,7 +45,7 @@ namespace ngs
      *  represents an alignment between a Fragment and Reference sub-sequence
      *  provides a path to Read and mate Alignment
      */
-    class NGS_EXTERN Alignment : public Fragment
+    class Alignment : public Fragment
     {
     public:
 
@@ -186,6 +186,14 @@ namespace ngs
         StringRef getLongCigar ( bool clipped ) const
             throw ( ErrorMsg );
 
+        /* getRNAOrientation
+         *  returns '+' if positive strand is transcribed
+         *  returns '-' if negative strand is transcribed
+         *  returns '?' if unknown
+         */
+        char getRNAOrientation () const
+            throw ( ErrorMsg );
+
 
         /*------------------------------------------------------------------
          * details of mate alignment
diff --git a/ngs-sdk/ngs/AlignmentIterator.hpp b/ngs-sdk/ngs/AlignmentIterator.hpp
index c0915bb..4187d27 100644
--- a/ngs-sdk/ngs/AlignmentIterator.hpp
+++ b/ngs-sdk/ngs/AlignmentIterator.hpp
@@ -37,7 +37,7 @@ namespace ngs
      * AlignmentIterator
      *  iterates across a list of Alignments
      */
-    class NGS_EXTERN AlignmentIterator : public Alignment
+    class AlignmentIterator : public Alignment
     {
     public:
 
diff --git a/ngs-sdk/ngs/Fragment.hpp b/ngs-sdk/ngs/Fragment.hpp
index fd6b0c9..ce1ee14 100644
--- a/ngs-sdk/ngs/Fragment.hpp
+++ b/ngs-sdk/ngs/Fragment.hpp
@@ -50,7 +50,7 @@ namespace ngs
      * Fragment
      *  represents an NGS biological fragment
      */
-    class NGS_EXTERN Fragment
+    class Fragment
     {
     public:
 
diff --git a/ngs-sdk/ngs/FragmentIterator.hpp b/ngs-sdk/ngs/FragmentIterator.hpp
index 942b515..a7d5053 100644
--- a/ngs-sdk/ngs/FragmentIterator.hpp
+++ b/ngs-sdk/ngs/FragmentIterator.hpp
@@ -37,7 +37,7 @@ namespace ngs
      * FragmentIterator
      *  iterates across a list of Fragments
      */
-    class NGS_EXTERN FragmentIterator : public Fragment
+    class FragmentIterator : public Fragment
     {
     public:
 
diff --git a/ngs-sdk/ngs/Pileup.hpp b/ngs-sdk/ngs/Pileup.hpp
index 970a97e..377e1fa 100644
--- a/ngs-sdk/ngs/Pileup.hpp
+++ b/ngs-sdk/ngs/Pileup.hpp
@@ -45,7 +45,7 @@ namespace ngs
      *  represents a slice through a stack of Alignments
      *  at a given position on the Reference
      */
-    class NGS_EXTERN Pileup
+    class Pileup
     {
     public:
 
diff --git a/ngs-sdk/ngs/PileupEvent.hpp b/ngs-sdk/ngs/PileupEvent.hpp
index 400944c..a2e8947 100644
--- a/ngs-sdk/ngs/PileupEvent.hpp
+++ b/ngs-sdk/ngs/PileupEvent.hpp
@@ -48,7 +48,7 @@ namespace ngs
      *  with Reference coordinates on one axis
      *  and stacked Alignments on the other axis
      */
-    class NGS_EXTERN PileupEvent
+    class PileupEvent
     {
     public:
 
@@ -115,11 +115,42 @@ namespace ngs
          */
         enum PileupEventType
         {
-            match     = 0,
-            mismatch  = 1,
-            insertion = 2,
-            deletion  = 3
-        };         
+            // no change to coordinate mapping
+            match                     = 0,
+            mismatch                  = 1,
+
+            // insertions into the reference
+            insertion_before_match    = 2,
+            insertion_before_mismatch = 3,
+
+            // overlap behaves like insertion
+            // (i.e. can retrieve insertion bases),
+            // but is actually an overlap in the read
+            // inherent in technology like Complete Genomics
+            read_overlap              = 4,
+
+            // deletions from the reference
+            deletion                  = 5,
+
+            // introns behave like deletions
+            // (i.e. can retrieve deletion count),
+            // "_plus" and "_minus" signify direction
+            // of transcription if known
+            intron_plus               = 6,
+            intron_minus              = 7,
+            intron_unknown            = 8,
+
+            // gap behaves like a deletion
+            // (i.e. can retrieve deletion count),
+            // but is actuall a gap in the read
+            // inherent in technology like Complete Genomics
+            read_gap                  = 9,
+            
+            
+            alignment_start           = 0x80,
+            alignment_stop            = 0x40,
+            alignment_minus_strand    = 0x20,
+        };
 
         /* getEventType
          *  the type of event being represented
@@ -135,13 +166,13 @@ namespace ngs
             throw ( ErrorMsg );
 
         /* getAlignmentQuality
-         *  retrieves base aligned at current Reference position
+         *  retrieves quality aligned at current Reference position
          *  throws exception if event is an insertion or deletion
+         *  quality is ascii-encoded phred score
          */
         char getAlignmentQuality () const
             throw ( ErrorMsg );
 
-
         /* getInsertionBases
          *  returns bases corresponding to insertion event
          */
diff --git a/ngs-sdk/ngs/PileupEventIterator.hpp b/ngs-sdk/ngs/PileupEventIterator.hpp
index 6b70307..e425a24 100644
--- a/ngs-sdk/ngs/PileupEventIterator.hpp
+++ b/ngs-sdk/ngs/PileupEventIterator.hpp
@@ -37,7 +37,7 @@ namespace ngs
      * PileupEventIterator
      *  iterates across a list of PileupEvents
      */
-    class NGS_EXTERN PileupEventIterator : public PileupEvent
+    class PileupEventIterator : public PileupEvent
     {
     public:
 
diff --git a/ngs-sdk/ngs/PileupIterator.hpp b/ngs-sdk/ngs/PileupIterator.hpp
index da9cbcc..be5f743 100644
--- a/ngs-sdk/ngs/PileupIterator.hpp
+++ b/ngs-sdk/ngs/PileupIterator.hpp
@@ -37,7 +37,7 @@ namespace ngs
      * PileupIterator
      *  iterates across a list of Pileups
      */
-    class NGS_EXTERN PileupIterator : public Pileup
+    class PileupIterator : public Pileup
     {
     public:
 
diff --git a/ngs-sdk/ngs/Read.hpp b/ngs-sdk/ngs/Read.hpp
index ad361a5..18de261 100644
--- a/ngs-sdk/ngs/Read.hpp
+++ b/ngs-sdk/ngs/Read.hpp
@@ -45,7 +45,7 @@ namespace ngs
      *  represents an NGS machine read
      *  having some number of biological Fragments
      */
-    class NGS_EXTERN Read : public FragmentIterator
+    class Read : public FragmentIterator
     {
     public:
 
diff --git a/ngs-sdk/ngs/ReadCollection.hpp b/ngs-sdk/ngs/ReadCollection.hpp
index 3185283..640dd9c 100644
--- a/ngs-sdk/ngs/ReadCollection.hpp
+++ b/ngs-sdk/ngs/ReadCollection.hpp
@@ -52,7 +52,7 @@ namespace ngs
      * ReadCollection
      *  represents an NGS-capable object with a collection of Reads
      */
-    class NGS_EXTERN ReadCollection
+    class ReadCollection
     {
     public:
         
diff --git a/ngs-sdk/ngs/ReadGroup.hpp b/ngs-sdk/ngs/ReadGroup.hpp
index c832d2d..12db464 100644
--- a/ngs-sdk/ngs/ReadGroup.hpp
+++ b/ngs-sdk/ngs/ReadGroup.hpp
@@ -48,7 +48,7 @@ namespace ngs
      * ReadGroup
      *  represents an NGS-capable object with a group of Reads
      */
-    class NGS_EXTERN ReadGroup
+    class ReadGroup
     {
     public:
 
diff --git a/ngs-sdk/ngs/ReadGroupIterator.hpp b/ngs-sdk/ngs/ReadGroupIterator.hpp
index e677332..050261f 100644
--- a/ngs-sdk/ngs/ReadGroupIterator.hpp
+++ b/ngs-sdk/ngs/ReadGroupIterator.hpp
@@ -37,7 +37,7 @@ namespace ngs
      * ReadGroupIterator
      *  iterates across a list of ReadGroups
      */
-    class NGS_EXTERN ReadGroupIterator : public ReadGroup
+    class ReadGroupIterator : public ReadGroup
     {
     public:
 
diff --git a/ngs-sdk/ngs/ReadIterator.hpp b/ngs-sdk/ngs/ReadIterator.hpp
index a7c64df..e884b80 100644
--- a/ngs-sdk/ngs/ReadIterator.hpp
+++ b/ngs-sdk/ngs/ReadIterator.hpp
@@ -37,7 +37,7 @@ namespace ngs
      * ReadIterator
      *  iterates across a list of Reads
      */
-    class NGS_EXTERN ReadIterator : public Read
+    class ReadIterator : public Read
     {
     public:
 
diff --git a/ngs-sdk/ngs/Reference.hpp b/ngs-sdk/ngs/Reference.hpp
index a51e2f4..fdaeab4 100644
--- a/ngs-sdk/ngs/Reference.hpp
+++ b/ngs-sdk/ngs/Reference.hpp
@@ -48,7 +48,7 @@ namespace ngs
      * Reference
      *  represents a reference sequence
      */
-    class NGS_EXTERN Reference
+    class Reference
     {
     public:
 
diff --git a/ngs-sdk/ngs/ReferenceIterator.hpp b/ngs-sdk/ngs/ReferenceIterator.hpp
index 9e281ed..b66887b 100644
--- a/ngs-sdk/ngs/ReferenceIterator.hpp
+++ b/ngs-sdk/ngs/ReferenceIterator.hpp
@@ -37,7 +37,7 @@ namespace ngs
      * ReferenceIterator
      *  iterates across a list of References
      */
-    class NGS_EXTERN ReferenceIterator : public Reference
+    class ReferenceIterator : public Reference
     {
     public:
 
diff --git a/ngs-sdk/ngs/Statistics.hpp b/ngs-sdk/ngs/Statistics.hpp
index 46ec1d8..efc3fe0 100644
--- a/ngs-sdk/ngs/Statistics.hpp
+++ b/ngs-sdk/ngs/Statistics.hpp
@@ -50,7 +50,7 @@ namespace ngs
      * Statistics
      *  represents a set of statistics as a collection of path/value pairs
      */
-    class NGS_EXTERN Statistics 
+    class Statistics 
     {
     public:
 
diff --git a/ngs-sdk/ngs/StringRef.hpp b/ngs-sdk/ngs/StringRef.hpp
index 7627659..e1a33d2 100644
--- a/ngs-sdk/ngs/StringRef.hpp
+++ b/ngs-sdk/ngs/StringRef.hpp
@@ -27,10 +27,6 @@
 #ifndef _hpp_ngs_stringref_
 #define _hpp_ngs_stringref_
 
-#ifndef _h_ngs_defs_
-#include <ngs/defs.h>
-#endif
-
 #ifndef _hpp_ngs_error_msg_
 #include <ngs/ErrorMsg.hpp>
 #endif
@@ -54,7 +50,7 @@ namespace ngs
      *  main purpose is to avoid copying
      *  provides a cast operator to create a language-specific String
      */
-    class NGS_EXTERN  StringRef
+    class StringRef
     {
     public:
 
@@ -116,7 +112,7 @@ namespace ngs
     };
 
     // support for C++ ostream
-      NGS_EXTERN :: std :: ostream & operator << ( :: std :: ostream & s, const StringRef & str );
+       :: std :: ostream & operator << ( :: std :: ostream & s, const StringRef & str );
 
 } // namespace ngs
 
diff --git a/ngs-sdk/ngs/adapter/AlignmentItf.hpp b/ngs-sdk/ngs/adapter/AlignmentItf.hpp
index e449fd6..c02a2a1 100644
--- a/ngs-sdk/ngs/adapter/AlignmentItf.hpp
+++ b/ngs-sdk/ngs/adapter/AlignmentItf.hpp
@@ -67,6 +67,7 @@ namespace ngs_adapt
         virtual uint64_t getTemplateLength () const = 0;
         virtual StringItf * getShortCigar ( bool clipped ) const = 0;
         virtual StringItf * getLongCigar ( bool clipped ) const = 0;
+        virtual char getRNAOrientation () const = 0;
         virtual bool hasMate () const = 0;
         virtual StringItf * getMateAlignmentId () const = 0;
         virtual AlignmentItf * getMateAlignment () const = 0;
@@ -114,6 +115,7 @@ namespace ngs_adapt
         static uint64_t CC get_template_len ( const NGS_Alignment_v1 * self, NGS_ErrBlock_v1 * err );
         static NGS_String_v1 * CC get_short_cigar ( const NGS_Alignment_v1 * self, NGS_ErrBlock_v1 * err, bool clipped );
         static NGS_String_v1 * CC get_long_cigar ( const NGS_Alignment_v1 * self, NGS_ErrBlock_v1 * err, bool clipped );
+        static char CC get_rna_orientation ( const NGS_Alignment_v1 * self, NGS_ErrBlock_v1 * err );
         static bool CC has_mate ( const NGS_Alignment_v1 * self, NGS_ErrBlock_v1 * err );
         static NGS_String_v1 * CC get_mate_id ( const NGS_Alignment_v1 * self, NGS_ErrBlock_v1 * err );
         static NGS_Alignment_v1 * CC get_mate_alignment ( const NGS_Alignment_v1 * self, NGS_ErrBlock_v1 * err );
diff --git a/ngs-sdk/ngs/itf/AlignmentItf.h b/ngs-sdk/ngs/itf/AlignmentItf.h
index 6697452..771ccfc 100644
--- a/ngs-sdk/ngs/itf/AlignmentItf.h
+++ b/ngs-sdk/ngs/itf/AlignmentItf.h
@@ -49,6 +49,7 @@ struct NGS_Alignment_v1_vt
 {
     NGS_VTable dad;
 
+    /* v1.0 interface */
     NGS_String_v1 * ( CC * get_id ) ( const NGS_Alignment_v1 * self, NGS_ErrBlock_v1 * err );
     NGS_String_v1 * ( CC * get_ref_spec ) ( const NGS_Alignment_v1 * self, NGS_ErrBlock_v1 * err );
     int32_t ( CC * get_map_qual ) ( const NGS_Alignment_v1 * self, NGS_ErrBlock_v1 * err );
@@ -72,6 +73,9 @@ struct NGS_Alignment_v1_vt
     NGS_String_v1 * ( CC * get_mate_ref_spec ) ( const NGS_Alignment_v1 * self, NGS_ErrBlock_v1 * err );
     bool ( CC * get_mate_is_reversed ) ( const NGS_Alignment_v1 * self, NGS_ErrBlock_v1 * err );
     bool ( CC * next ) ( NGS_Alignment_v1 * self, NGS_ErrBlock_v1 * err );
+
+    /* v1.1 */
+    char ( CC * get_rna_orientation ) ( const NGS_Alignment_v1 * self, NGS_ErrBlock_v1 * err );
 };
 
 
diff --git a/ngs-sdk/ngs/itf/AlignmentItf.hpp b/ngs-sdk/ngs/itf/AlignmentItf.hpp
index 688cabe..3e7ddc9 100644
--- a/ngs-sdk/ngs/itf/AlignmentItf.hpp
+++ b/ngs-sdk/ngs/itf/AlignmentItf.hpp
@@ -44,7 +44,7 @@ namespace ngs
     /*----------------------------------------------------------------------
      * AlignmentItf
      */
-    class NGS_ITF_EXTERN  AlignmentItf : public Refcount < AlignmentItf, NGS_Alignment_v1 >
+    class   AlignmentItf : public Refcount < AlignmentItf, NGS_Alignment_v1 >
     {
     public:
 
@@ -82,6 +82,8 @@ namespace ngs
             throw ( ErrorMsg );
         StringItf * getLongCigar ( bool clipped ) const
             throw ( ErrorMsg );
+        char getRNAOrientation () const
+            throw ( ErrorMsg );
         bool hasMate () const
             throw ();
         StringItf * getMateAlignmentId () const
diff --git a/ngs-sdk/ngs/itf/ErrBlock.hpp b/ngs-sdk/ngs/itf/ErrBlock.hpp
index ac887c9..3c0bbc6 100644
--- a/ngs-sdk/ngs/itf/ErrBlock.hpp
+++ b/ngs-sdk/ngs/itf/ErrBlock.hpp
@@ -42,7 +42,7 @@ namespace ngs
      * ErrBlock
      *  holds a message describing what happened
      */
-    struct NGS_ITF_EXTERN  ErrBlock : public :: NGS_ErrBlock_v1
+    struct   ErrBlock : public :: NGS_ErrBlock_v1
     {
         void Throw () const
             throw ( ErrorMsg );
diff --git a/ngs-sdk/ngs/itf/ErrorMsg.hpp b/ngs-sdk/ngs/itf/ErrorMsg.hpp
index 43aeea6..bb174ff 100644
--- a/ngs-sdk/ngs/itf/ErrorMsg.hpp
+++ b/ngs-sdk/ngs/itf/ErrorMsg.hpp
@@ -42,7 +42,7 @@ namespace ngs
      *  a generic NGS error class
      *  holds a message describing what happened
      */
-    class NGS_ITF_EXTERN  ErrorMsg : public :: std :: exception
+    class   ErrorMsg : public :: std :: exception
     {
     public:
 
diff --git a/ngs-sdk/ngs/itf/FragmentItf.hpp b/ngs-sdk/ngs/itf/FragmentItf.hpp
index be15fd3..2eb3bae 100644
--- a/ngs-sdk/ngs/itf/FragmentItf.hpp
+++ b/ngs-sdk/ngs/itf/FragmentItf.hpp
@@ -44,7 +44,7 @@ namespace ngs
     /*----------------------------------------------------------------------
      * FragmentItf
      */
-    class NGS_ITF_EXTERN  FragmentItf : public Refcount < FragmentItf, NGS_Fragment_v1 >
+    class   FragmentItf : public Refcount < FragmentItf, NGS_Fragment_v1 >
     {
     public:
 
diff --git a/ngs-sdk/ngs/itf/PileupEventItf.hpp b/ngs-sdk/ngs/itf/PileupEventItf.hpp
index 77bad5a..9ff2703 100644
--- a/ngs-sdk/ngs/itf/PileupEventItf.hpp
+++ b/ngs-sdk/ngs/itf/PileupEventItf.hpp
@@ -45,7 +45,7 @@ namespace ngs
     /*----------------------------------------------------------------------
      * PileupEventItf
      */
-    class NGS_ITF_EXTERN  PileupEventItf : public Refcount < PileupEventItf, NGS_PileupEvent_v1 >
+    class   PileupEventItf : public Refcount < PileupEventItf, NGS_PileupEvent_v1 >
     {
     public:
 
diff --git a/ngs-sdk/ngs/itf/PileupItf.hpp b/ngs-sdk/ngs/itf/PileupItf.hpp
index 5f5db08..effe92f 100644
--- a/ngs-sdk/ngs/itf/PileupItf.hpp
+++ b/ngs-sdk/ngs/itf/PileupItf.hpp
@@ -45,7 +45,7 @@ namespace ngs
     /*----------------------------------------------------------------------
      * PileupItf
      */
-    class NGS_ITF_EXTERN  PileupItf : public Refcount < PileupItf, NGS_Pileup_v1 >
+    class   PileupItf : public Refcount < PileupItf, NGS_Pileup_v1 >
     {
     public:
 
diff --git a/ngs-sdk/ngs/itf/ReadCollectionItf.hpp b/ngs-sdk/ngs/itf/ReadCollectionItf.hpp
index b1672f4..14b4b32 100644
--- a/ngs-sdk/ngs/itf/ReadCollectionItf.hpp
+++ b/ngs-sdk/ngs/itf/ReadCollectionItf.hpp
@@ -48,7 +48,7 @@ namespace ngs
     /*----------------------------------------------------------------------
      * ReadCollectionItf
      */
-    class NGS_ITF_EXTERN  ReadCollectionItf : public Refcount < ReadCollectionItf, NGS_ReadCollection_v1 >
+    class   ReadCollectionItf : public Refcount < ReadCollectionItf, NGS_ReadCollection_v1 >
     {
     public:
         
diff --git a/ngs-sdk/ngs/itf/ReadGroupItf.hpp b/ngs-sdk/ngs/itf/ReadGroupItf.hpp
index 6e71a41..f039a9c 100644
--- a/ngs-sdk/ngs/itf/ReadGroupItf.hpp
+++ b/ngs-sdk/ngs/itf/ReadGroupItf.hpp
@@ -46,7 +46,7 @@ namespace ngs
     /*----------------------------------------------------------------------
      * ReadGroupItf
      */
-    class NGS_ITF_EXTERN  ReadGroupItf : public Refcount < ReadGroupItf, NGS_ReadGroup_v1 >
+    class   ReadGroupItf : public Refcount < ReadGroupItf, NGS_ReadGroup_v1 >
     {
     public:
 
diff --git a/ngs-sdk/ngs/itf/ReadItf.hpp b/ngs-sdk/ngs/itf/ReadItf.hpp
index 5582a20..678798a 100644
--- a/ngs-sdk/ngs/itf/ReadItf.hpp
+++ b/ngs-sdk/ngs/itf/ReadItf.hpp
@@ -44,7 +44,7 @@ namespace ngs
     /*----------------------------------------------------------------------
      * ReadItf
      */
-    class NGS_ITF_EXTERN  ReadItf : public Refcount < ReadItf, NGS_Read_v1 >
+    class   ReadItf : public Refcount < ReadItf, NGS_Read_v1 >
     {
     public:
 
diff --git a/ngs-sdk/ngs/itf/Refcount.hpp b/ngs-sdk/ngs/itf/Refcount.hpp
index 99552c3..5f93a83 100644
--- a/ngs-sdk/ngs/itf/Refcount.hpp
+++ b/ngs-sdk/ngs/itf/Refcount.hpp
@@ -43,7 +43,7 @@ namespace ngs
     /*----------------------------------------------------------------------
      * OpaqueRefcount
      */
-    class NGS_ITF_EXTERN  OpaqueRefcount
+    class   OpaqueRefcount
     {
     public:
 
@@ -65,7 +65,7 @@ namespace ngs
      * Refcount
      */
     template < class T, class C >
-    class NGS_ITF_EXTERN  Refcount : protected OpaqueRefcount
+    class   Refcount : protected OpaqueRefcount
     {
     public:
 
diff --git a/ngs-sdk/ngs/itf/ReferenceItf.hpp b/ngs-sdk/ngs/itf/ReferenceItf.hpp
index d5f855c..57b9187 100644
--- a/ngs-sdk/ngs/itf/ReferenceItf.hpp
+++ b/ngs-sdk/ngs/itf/ReferenceItf.hpp
@@ -46,7 +46,7 @@ namespace ngs
     /*----------------------------------------------------------------------
      * Reference
      */
-    class NGS_ITF_EXTERN   ReferenceItf : public Refcount < ReferenceItf, NGS_Reference_v1 >
+    class    ReferenceItf : public Refcount < ReferenceItf, NGS_Reference_v1 >
     {
     public:
 
diff --git a/ngs-sdk/ngs/itf/StatisticsItf.hpp b/ngs-sdk/ngs/itf/StatisticsItf.hpp
index 8733475..c745a8e 100644
--- a/ngs-sdk/ngs/itf/StatisticsItf.hpp
+++ b/ngs-sdk/ngs/itf/StatisticsItf.hpp
@@ -44,7 +44,7 @@ namespace ngs
     /*----------------------------------------------------------------------
      * StatisticsItf
      */
-    class NGS_ITF_EXTERN  StatisticsItf : public Refcount < StatisticsItf, NGS_Statistics_v1 >
+    class   StatisticsItf : public Refcount < StatisticsItf, NGS_Statistics_v1 >
     {
     public:
 
diff --git a/ngs-sdk/ngs/itf/StringItf.hpp b/ngs-sdk/ngs/itf/StringItf.hpp
index f7de0db..be9b04f 100644
--- a/ngs-sdk/ngs/itf/StringItf.hpp
+++ b/ngs-sdk/ngs/itf/StringItf.hpp
@@ -39,7 +39,7 @@ namespace ngs
      * StringItf
      *  a dynamically allocated object representing a string reference
      */
-    class NGS_ITF_EXTERN  StringItf : public Refcount < StringItf, NGS_String_v1 >
+    class   StringItf : public Refcount < StringItf, NGS_String_v1 >
     {
     public:
 
diff --git a/ngs-sdk/ngs/itf/defs.h b/ngs-sdk/ngs/itf/defs.h
index 759bfee..abf0521 100644
--- a/ngs-sdk/ngs/itf/defs.h
+++ b/ngs-sdk/ngs/itf/defs.h
@@ -48,19 +48,6 @@ extern "C" {
 #endif
 
 /*--------------------------------------------------------------------------
- * DLL interface
- */
-#if defined _MSC_VER
- #if defined _LIBRARY
-  #define NGS_ITF_EXTERN   __declspec( dllexport ) 
- #else
-  #define NGS_ITF_EXTERN   __declspec( dllimport ) 
- #endif
-#else
- #define NGS_ITF_EXTERN   
-#endif
-
-/*--------------------------------------------------------------------------
  * NGS_ErrBlock
  *  see "ErrBlock.h"
  */
diff --git a/ngs-python/configure b/ngs-sdk/setup/install
similarity index 83%
copy from ngs-python/configure
copy to ngs-sdk/setup/install
index 3313aac..4dcf8cf 100755
--- a/ngs-python/configure
+++ b/ngs-sdk/setup/install
@@ -29,17 +29,17 @@ CURDIR="`dirname $0`"
 
 if [ -z "$CURDIR" ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
     exit 1
 fi
 
-if [ "$FILENAME" != configure -a ! -s konfigure.perl ]
+if [ "$FILENAME" != install -a ! -s install.perl ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
 else
     perl -v > /dev/null 2>&1 || { echo "checking for perl... no"; \
-        echo >&2 "configure: error: perl not found."; exit 1; }
+        echo >&2 "error: perl not found."; exit 1; }
 
     cd $CURDIR
-    perl -w ./konfigure.perl $@
+    perl -w ./install.perl "$@"
 fi
diff --git a/ngs-sdk/setup/install.perl b/ngs-sdk/setup/install.perl
new file mode 100644
index 0000000..5e5f33e
--- /dev/null
+++ b/ngs-sdk/setup/install.perl
@@ -0,0 +1,1324 @@
+################################################################################
+
+use strict;
+
+require 'install.prl';
+
+use Config;
+use Cwd        "abs_path";
+use File::Copy "copy";
+use File::Copy::Recursive qw(dircopy);
+use File::Path   "make_path";
+use FindBin    qw($Bin);
+use Getopt::Long "GetOptions";
+
+my ($OS, $MAKING, %INSTALLED_LIBS);
+{
+    my $file = 'os.prl';
+    if (-e $file) {
+        require $file;
+        $OS = OS();
+    } else {
+        ++$MAKING;
+    }
+}
+
+my %HAVE = HAVE();
+BINS() if ($HAVE{BINS});
+if ($HAVE{LIBS}) {
+    ++$HAVE{INCLUDES};
+    LIBS();
+}
+if ($HAVE{INCLUDES} || $HAVE{USR_INCLUDES}) {
+    die "no INCLUDES" unless INCLUDES();
+}
+die "no CONFIG_OUT" unless CONFIG_OUT();
+
+my @bits;
+my @options = ( 'debug', 'examplesdir=s', 'force', 'help',
+                'includedir=s', 'no-create', 'prefix=s', 'root=s', );
+push @options, 'oldincludedir=s' if ($HAVE{USR_INCLUDES});
+if ($HAVE{JAR}) {
+    push @options, 'jardir=s';
+    if (-e "$Bin/../jar") {
+        ++$HAVE{LIBS};
+        $_{JARDIR} = expand_path("$Bin/../jar");
+    }
+} elsif ($HAVE{PYTHON} && ! $MAKING) {
+    ++$HAVE{LIBS};
+}
+if (! $MAKING && ($HAVE{JAR} || $HAVE{PYTHON})) {
+    ++$HAVE{TWO_LIBS};
+    push @options, 'ngslibdir=s', 'vdblibdir=s';
+}
+push @options, 'bindir=s'                     if ($HAVE{BINS});
+push @options, 'bits=s' => \@bits, 'libdir=s' if ($HAVE{LIBS});
+
+my %OPT;
+unless (GetOptions(\%OPT, @options)) {
+    print "install: error\n";
+    exit 1;
+}
+ at bits = split(/,/,join(',', at bits));
+foreach (@bits) {
+    unless (/^32$/ || /^64$/) {
+        print "install: error: bad bits option argument value\n";
+        exit 1;
+    }
+}
+if ($#bits > 0) {
+    foreach (qw(bindir libdir ngslibdir vdblibdir)) {
+        if ($OPT{$_}) {
+            print "install: error: cannot supply multiple bits arguments "
+                . "when $_ argument is provided\n";
+            exit 1;
+        }
+    }
+}
+
+$OPT{root} = expand_path($OPT{root}) if ($OPT{root});
+
+prepare();
+
+my $LINUX_ROOT;
+++$LINUX_ROOT if (linux_root());
+my $ROOT = '';
+if ($OPT{root}) {
+    $ROOT = "$OPT{root}/root";
+    ++$LINUX_ROOT;
+    foreach ("$ROOT/usr/include", "$ROOT/etc/profile.d") {
+        unless (-e $_) {
+            print "mkdir -p $_... ";
+            eval { make_path($_) };
+            if ($@) {
+                print "failure: $@\n";
+                exit 1;
+            }
+            print "ok\n";
+        }
+    }
+}
+
+my $oldincludedir = "$ROOT/usr/include";
+
+my $EXAMPLES_DIR = "$Bin/../examples";
+
+ at _ = CONFIGURE();
+
+if ($OPT{help}) {
+    help();
+    exit 0;
+}
+
+foreach (qw(BITS INCDIR
+ INST_INCDIR INST_JARDIR INST_LIBDIR INST_NGSLIBDIR INST_SHAREDIR INST_VDBLIBDIR
+ LIBX LPFX MAJVERS MAJVERS_SHLX OS OTHER_PREFIX
+ PACKAGE_NAME PREFIX SHLX VERSION VERSION_LIBX VERSION_SHLX))
+{
+    unless ($_{$_}) {
+        next if (/^INST_JARDIR$/    && ! $HAVE{JAR});
+        next if (/^INST_NGSLIBDIR$/ && ! $HAVE{TWO_LIBS});
+        next if (/^INST_SHAREDIR$/  && ! $HAVE{EXAMPLES});
+        next if (/^INST_VDBLIBDIR$/ && ! $HAVE{TWO_LIBS});
+        fatal_config("$_ not found");
+    }
+}
+unless ($_{LIBDIR32} || $_{LIBDIR64} || ($HAVE{PYTHON} && $MAKING)) {
+    fatal_config('LIBDIR not found');
+}
+ 
+if ($OPT{prefix}) {
+    $OPT{prefix} = expand_path($OPT{prefix});
+    $_{INST_BINDIR  } = "$OPT{prefix}/bin";
+    $_{INST_LIBDIR  } = "$OPT{prefix}/lib";
+    $_{INST_NGSLIBDIR} = $_{INST_VDBLIBDIR} = $_{INST_LIBDIR};
+    $_{INST_INCDIR  } = "$OPT{prefix}/include";
+    $_{INST_JARDIR  } = "$OPT{prefix}/jar";
+    $_{INST_SHAREDIR} = "$OPT{prefix}/share";
+}
+$_{INST_SHAREDIR} = expand_path($OPT{examplesdir  }) if ($OPT{examplesdir  });
+$_{INST_INCDIR  } = expand_path($OPT{includedir   }) if ($OPT{includedir   });
+$_{INST_JARDIR  } = expand_path($OPT{jardir       }) if ($OPT{jardir       });
+$_{BIN_TARGET   } = expand_path($OPT{bindir       }) if ($OPT{bindir       });
+$oldincludedir    = expand_path($OPT{oldincludedir}) if ($OPT{oldincludedir});
+if ($OPT{libdir}) {
+    $_{INST_NGSLIBDIR} = $_{LIB_TARGET} = expand_path($OPT{libdir}) ;
+    $_{INST_VDBLIBDIR} = $_{LIB_TARGET};
+}
+$_{INST_NGSLIBDIR}= expand_path($OPT{ngslibdir}) if ($OPT{ngslibdir});
+$_{INST_VDBLIBDIR}= expand_path($OPT{vdblibdir}) if ($OPT{vdblibdir});
+
+if ($OPT{'no-create'} && $_{OS} eq 'linux') {
+    if ($LINUX_ROOT) {
+        print "root user\n\n";
+    } else {
+        print "non root user\n\n";
+    }
+}
+
+my $failures = 0;
+my $bFailure = 1;
+
+push @bits, $_{BITS} unless (@bits);
+foreach (@bits) {
+    $_{BITS} = $_;
+
+    print "installing $_{PACKAGE_NAME} ($_{VERSION}) package";
+    print " for $_{OS}-$_{BITS}" if ($HAVE{BINS} || $HAVE{LIBS});
+    print "...\n";
+
+    if ($HAVE{BINS}) {
+        $_{BINDIR} = $_{"BINDIR$_{BITS}"};
+        unless ($_{BINDIR}) {
+            print "install: error: $_{BITS}-bit version is not available\n\n";
+            next;
+        }
+    }
+    if ($HAVE{LIBS} || $HAVE{PYTHON}) {
+# ($_{LIBDIR} for python points where ngs-sdk and ncbi-vdb dynamic libraries
+# can be found to correctly set up LD_LIBRARY_PATH
+        $_{LIBDIR} = $_{"LIBDIR$_{BITS}"};
+        unless ($_{LIBDIR}) {
+            print "install: error: $_{BITS}-bit version is not available\n\n";
+            next;
+        }
+    }
+    if ($HAVE{JAR} && ! $_{JARDIR}) {
+        $_{JARDIR} = $_{"LIBDIR$_{BITS}"};
+        unless ($_{JARDIR}) {
+            if ($_{BITS} == 64) {
+                $_{JARDIR} = $_{LIBDIR32};
+            } else {
+                $_{JARDIR} = $_{LIBDIR64};
+            }
+            unless ($_{JARDIR}) {
+                print "install: error: jar file was not cannot found\n";
+                exit 1;
+            }
+        }
+    }
+    $bFailure = 0;
+
+    if ($OPT{'no-create'}) {
+        print     "includedir : '$_{INST_INCDIR  }'\n" if ($HAVE{INCLUDES  });
+        print     "libdir     : '$_{INST_LIBDIR}$_{BITS}'\n" if ($HAVE{LIBS});
+        print     "jardir     : '$_{INST_JARDIR  }'\n" if ($HAVE{JAR       });
+        print     "examplesdir: '$_{INST_SHAREDIR}'\n" if ($HAVE{EXAMPLES  });;
+        if ($LINUX_ROOT) {
+            print "oldincludedir: '$oldincludedir'\n"  if ($HAVE{USR_INCLUDES});
+        }
+        print "\n";
+        next;
+    }
+
+    $_{BIN_TARGET} = "$_{INST_BINDIR}$_{BITS}" unless ($OPT{bindir});
+    $_{LIB_TARGET} = "$_{INST_LIBDIR}$_{BITS}" unless ($OPT{libdir});
+
+    $File::Copy::Recursive::CPRFComp = 1;
+
+    $failures += copybins    () if ($HAVE{BINS});
+    $failures += copylibs    () if ($HAVE{LIBS});
+    $failures += copyincludes() if ($HAVE{INCLUDES});
+    $failures += copyjars    () if ($HAVE{JAR});
+    $failures += copyconfig  () if ($HAVE{CONFIG});
+
+    if ($HAVE{JAR}) {
+        $File::Copy::Recursive::CPRFComp = 0;
+        $failures += copydocs() ;
+        $File::Copy::Recursive::CPRFComp = 1;
+    }
+
+    $failures += copyexamples();
+    $failures += finishinstall() unless ($failures);
+
+    unless ($failures) {
+        print "\nsuccessfully installed $_{PACKAGE_NAME} ($_{VERSION}) package";
+    } else {
+        print "\nfailed to install $_{PACKAGE_NAME} ($_{VERSION}) package";
+    }
+    print " for $_{OS}-$_{BITS}" if ($HAVE{BINS} || $HAVE{LIBS});
+    print ".\n\n";
+}
+
+$failures = 1 if (!$failures && $bFailure);
+
+exit $failures;
+
+################################################################################
+
+sub copybins {
+    unless ($_{BIN_TARGET}) {
+        print "error: cannot install executables: no BIN_TARGET\n";
+        return 1;
+    }
+    my $s = $_{BINDIR};
+    my $d = $_{BIN_TARGET};
+    print "installing executables to $d...";
+    unless (-e $s) {
+        print " failure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+    print "\t\tcd $d\n" if ($OPT{debug});
+    chdir $d or die "cannot cd $d";
+    my $failures = 0;
+    foreach (BINS()) {
+        print "installing '$_'..." if ($OPT{debug});
+        my $df = "$_$_{VERSION_EXEX}";
+        my $sf = "$s/$df";
+        print "\n\t\t$sf -> $df\n\t" if ($OPT{debug});
+        unless (-e $sf) {
+            print " skipped\n" if ($OPT{debug});
+            next;
+        }
+        if ((! $OPT{force}) && (-e $df) && (-M $df < -M $sf)) {
+            print " found\n" if ($OPT{debug});
+        } else {
+            unless (copy($sf, $df)) {
+                print "failure\n";
+                print "install: error: cannot copy '$sf' '$df'.\n";
+                ++$failures;
+                next;
+            }
+            my $mode = 0755;
+            printf "\tchmod %o $df\n\t", $mode if ($OPT{debug});
+            unless (chmod($mode, $df)) {
+                print " failure\n" if ($OPT{debug});
+                print "install: error: cannot chmod '$df': $!\n";
+                ++$failures;
+                next;
+            }
+            unless (symlinks($_, $df, 'bin')) {
+                print " success\n" if ($OPT{debug});
+            } else {
+                print " failure\n" if ($OPT{debug});
+                ++$failures;
+            }
+        }
+    }
+    return $failures;
+}
+
+sub copyconfig {
+    my $d;
+    if ($LINUX_ROOT) {
+        $d = "$ROOT/etc";
+    }
+    elsif ($HAVE{BINS}) {
+        $d = $_{BIN_TARGET};
+        unless ($d) {
+            print
+               "error: cannot install configuration files: no BIN_TARGET\n";
+            return 1;
+        }
+    } else {
+        $d = $_{LIB_TARGET};
+        unless ($d) {
+            print
+               "error: cannot install configuration files: no LIB_TARGET\n";
+            return 1;
+        }
+    }
+    $d = File::Spec->catdir($d, 'ncbi');
+    my $kfg = File::Spec->catdir($Bin, '..', 'libs/kfg/default.kfg');
+    unless (-e $kfg) {
+        $kfg = File::Spec->catdir($Bin, '..', 'tools/vdb-copy/vdb-copy.kfg');
+    }
+    unless (-e $kfg) {
+        if ($_{BINDIR}) {
+            $kfg = File::Spec->catdir($_{BINDIR}, 'ncbi', 'vdb-copy.kfg');
+        } elsif ($_{LIBDIR}) {
+            $kfg = File::Spec->catdir($_{LIBDIR}, 'ncbi', 'default.kfg');
+            unless (-e $kfg) {
+                print
+                  "error: cannot install configuration files: no default.kfg\n";
+                return 1;
+            }
+        }
+    }
+    print "installing configuration files to $d... ";
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+    my $df = File::Spec->catdir($d, 'ncbi-vdb.kfg');
+    print "\t\t$kfg -> $df\n" if ($OPT{debug});
+    unless (copy($kfg, $df)) {
+        print "install: error: cannot copy '$kfg' '$df'.\n";
+        return 1;
+    } else {
+        print "success\n";
+        return 0;
+    }
+}
+
+sub copylibs {
+    die unless ($HAVE{LIBS});
+
+    my $s = $_{LIBDIR};
+    my $d = $_{LIB_TARGET};
+
+    print "installing libraries to $d... ";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    if ($HAVE{TWO_LIBS}) {
+        my $ngs = $_{INST_NGSLIBDIR};
+        if ($ngs && ! ($OPT{prefix} && $OPT{libdir} && $OPT{ngslibdir})) {
+            $ngs .= $_{BITS};
+        }
+        my $vdb = $_{INST_VDBLIBDIR};
+        if ($vdb && ! ($OPT{prefix} && $OPT{libdir} && $OPT{vdblibdir})) {
+            $vdb .= $_{BITS};
+        }
+        if ($ngs || $vdb) {
+            unless ($ngs && $vdb) {
+                $ngs = $d unless ($ngs);
+                $vdb = $d unless ($vdb);
+            }
+            $INSTALLED_LIBS{'ngs-sdk' } = $ngs;
+            $INSTALLED_LIBS{'ncbi-vdb'} = $vdb;
+        }
+    }
+    $INSTALLED_LIBS{0} = $d unless (%INSTALLED_LIBS);
+
+    foreach (keys %INSTALLED_LIBS) {
+        my $d = $INSTALLED_LIBS{$_};
+        print "\nchecking $d... ";
+        unless (-e $d) {
+            print "not found\n";
+            print "mkdir -p $d... ";
+            eval { make_path($d) };
+            if ($@) {
+                print "failure\ninstall: error: cannot mkdir $d\n";
+                return 1;
+            } else {
+                print "success\n";
+            }
+        } else {
+            print "exists\n";
+        }
+    }
+
+    return $MAKING ? copybldlibs($s, $d) : copydir($s, %INSTALLED_LIBS);
+}
+
+sub copybldlibs {
+    my ($s, $d) = @_;
+
+    print "\t\tcd $d\n" if ($OPT{debug});
+    chdir $d or die "cannot cd $d";
+
+    my $failures = 0;
+
+    my %LIBRARIES_TO_INSTALL = LIBS();
+    foreach (keys %LIBRARIES_TO_INSTALL) {
+        print "installing '$_'... ";
+
+        my $nb = "$_{LPFX}$_";
+        my $nv = "$nb.";
+        my $lib = 'dll';
+        if ($LIBRARIES_TO_INSTALL{$_} eq 'SHL') {
+            $nv .= $_{VERSION_SHLX};
+        } elsif ($LIBRARIES_TO_INSTALL{$_} eq 'LIB') {
+            $nv .= $_{VERSION_LIBX};
+            $lib = 'lib';
+        } else {
+            die "bad library type";
+        }
+
+        my $sf = "$s/$nv";
+        my $df = "$d/$nv";
+
+        print "\n\t\t$sf -> $df\n\t" if ($OPT{debug});
+
+        unless (-e $sf) {
+            print "failure\n";
+            print "install: error: '$sf' is not found.\n";
+            ++$failures;
+            next;
+        }
+
+        if ((! $OPT{force}) && (-e $df) && (-M $df < -M $sf)) {
+            print "found\n";
+        } else {
+            unless (copy($sf, $df)) {
+                print "failure\n";
+                print "install: error: cannot copy '$sf' '$df'.\n";
+                ++$failures;
+                next;
+            }
+            my $mode = 0644;
+            $mode = 0755 if ($lib eq 'dll');
+            printf "\tchmod %o $df\n\t", $mode if ($OPT{debug});
+            unless (chmod($mode, $df)) {
+                print "failure\n";
+                print "install: error: cannot chmod '$df': $!\n";
+                ++$failures;
+                next;
+            }
+            unless (symlinks($nb, $nv, $lib)) {
+                print "success\n";
+            } else {
+                print "failure\n";
+                ++$failures;
+            }
+        }
+    }
+
+    return $failures;
+}
+
+sub symlinks {
+    my ($nb, $nv, $type) = @_;
+
+    my @l;
+    if ($type eq 'lib') {
+        push @l, "$nb-static.$_{LIBX}";
+        push @l, "$nb.$_{LIBX}";
+        push @l, "$nb.$_{MAJVERS_LIBX}";
+    } elsif ($type eq 'dll') {
+        push @l, "$nb.$_{SHLX}";
+        push @l, "$nb.$_{MAJVERS_SHLX}";
+    } elsif ($type eq 'bin' || $type eq 'jar') {
+        push @l, $nb;
+        push @l, "$nb.$_{MAJVERS}";
+    } else {
+        print "failure\n";
+        print "install: error: unknown symlink type '$type'\n";
+        return 1;
+    }
+
+    my $failures = 0;
+
+    for (my $i = 0; $i <= $#l; ++$i) {
+        my $file = $l[$i];
+        if (-e $file) {
+            print "\trm $file\n\t" if ($OPT{debug});
+            unless (unlink $file) {
+                print "failure\n";
+                print "install: error: cannot rm '$file': $!\n";
+                ++$failures;
+                next;
+            }
+        }
+
+        my $o = $nv;
+        $o = $l[$i + 1] if ($i < $#l);
+
+        print "\tln -s $o $file\n\t" if ($OPT{debug});
+        unless (symlink $o, $file) {
+            print "failure\n";
+            print "install: error: cannot symlink '$o' '$file': $!\n";
+            ++$failures;
+            next;
+        }
+    }
+
+    return $failures;
+}
+
+sub copydir {
+    my ($s, %d) = @_;
+
+    my $failures = 0;
+
+    foreach my $pattern(keys %d) {
+        my $d = $d{$pattern};
+        print "\t\tcd $d\n" if ($OPT{debug});
+        chdir $d or die "cannot cd $d";
+
+        opendir(D, $s) or die "cannot opendir $s: $!";
+
+        while (readdir D) {
+            next if (/^\.{1,2}$/);
+            next if ($pattern && ! /$pattern/);
+
+            my $n = "$s/$_";
+
+            if (-l $n) {
+                print "\t\t$_ (symlink)... " if ($OPT{debug});
+                my $l = readlink $n;
+                if ((-e $_) && (!unlink $_)) {
+                    print "error: cannot remove $l: $!\n";
+                    ++$failures;
+                    next;
+                }
+                unless (symlink($l, $_)) {
+                    print "error: cannot create symlink from $_ to $l: $!\n";
+                    ++$failures;
+                    next;
+                }
+                print "success\n" if ($OPT{debug});
+            } else {
+                print "\t\t$_... " if ($OPT{debug});
+                if ((-e $_) && (!unlink $_)) {
+                    print "error: cannot remove $_: $!\n";
+                    ++$failures;
+                    next;
+                }
+                unless (copy($n, $_)) {
+                    print "error: cannot copy '$n' to '$_': $!\n";
+                    ++$failures;
+                    next;
+                }
+                print "success\n" if ($OPT{debug});
+            }
+        }
+
+        closedir D;
+    }
+
+    return $failures;
+}
+
+sub includes_out {
+    my $out = '';
+    eval { $out = INCLUDES_OUT(); };
+    $out = File::Spec->catdir($_{INST_INCDIR}, $out);
+    $out;
+}
+
+sub copyincludes {
+    print "installing includes to $_{INST_INCDIR}... ";
+
+    my $s = "$_{INCDIR}/" . INCLUDES();
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    my $out = includes_out();
+    my $d = $out;
+    $d = $_{INST_INCDIR} unless ($d);
+
+    unless (-e $d) {
+        print "\n\t\tmkdir -p $d" if ($OPT{debug});
+        eval { make_path($d) };
+        if ($@) {
+            print "\tfailure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        }
+    }
+
+    if ($out && -f $s) {
+        print "\n\t\tcp $s $d\n\t" if ($OPT{debug});
+        unless (copy($s, $d)) {
+            print "failure\n";
+            return 1;
+        }
+    } else {
+        print "\n\t\tcp -r $s $d\n\t" if ($OPT{debug});
+        unless (dircopy($s, $d)) {
+            print "\tfailure\ninstall: error: cannot copy '$s' 'd'";
+            return 1;
+        }
+    }
+
+    print "success\n";
+    return 0;
+}
+
+sub copyjars {
+    my $s = $_{JARDIR};
+    my $d = $_{INST_JARDIR};
+
+    print "installing jar files to $d... ";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+
+    return $MAKING ? copybldjars($s, $d) : copydir($s, 0 => $d);
+}
+
+sub copybldjars {
+    my ($s, $d) = @_;
+    my $n = 'ngs-java.jar';
+    $s .= "/$n";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    my $nd = "$n.$_{VERSION}";
+    print "installing '$n'... ";
+
+    print "\t\tcd $d\n" if ($OPT{debug});
+    chdir $d or die "cannot cd $d";
+
+    $d .= "/$nd";
+
+    print "\n\t\t$s -> $d\n\t" if ($OPT{debug});
+
+    if ((! $OPT{force}) && (-e $d) && (-M $d < -M $s)) {
+        print "found\n";
+    } else {
+        unless (copy($s, $d)) {
+            print "failure\n";
+            print "install: error: cannot copy '$s' '$d'.\n";
+            return 1;
+        }
+        my $mode = 0644;
+        printf "\tchmod %o $d\n\t", $mode if ($OPT{debug});
+        unless (chmod($mode, $d)) {
+            print "failure\n";
+            print "install: error: cannot chmod '$d': $!\n";
+            return 1;
+        }
+        unless (symlinks($n, $nd, 'jar')) {
+            print "success\n";
+        } else {
+            print "failure\n";
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+sub copydocs {
+    my $s = "$_{JARDIR}/javadoc";
+    $s = expand_path("$Bin/../doc") unless ($MAKING);
+    my $d = "$_{INST_SHAREDIR}/doc";
+
+    print "installing html documents to $d... ";
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        return 1;
+    }
+
+    print "\nchecking $d... ";
+    unless (-e $d) {
+        print "not found\n";
+        print "mkdir -p $d... ";
+        eval { make_path($d) };
+        if ($@) {
+            print "failure\ninstall: error: cannot mkdir $d\n";
+            return 1;
+        } else {
+            print "success\n";
+        }
+    } else {
+        print "exists\n";
+    }
+
+    print "\t\t$s -> $d\n\t" if ($OPT{debug});
+    unless (dircopy($s, $d)) {
+        print "\tfailure\ninstall: error: cannot copy '$s' to '$d'";
+        return 1;
+    }
+
+    print "success\n";
+    return 0;
+}
+
+sub copyexamples {
+    my $failures = 0;
+    my $CPRFComp = $File::Copy::Recursive::CPRFComp;
+    my $sd = $EXAMPLES_DIR;
+    return 0 unless (-e $sd);
+
+    my $d = $_{INST_SHAREDIR};
+    if ($HAVE{JAR}) {
+        $d .= '/examples-java';
+    } elsif ($HAVE{PYTHON}) {
+        $File::Copy::Recursive::CPRFComp = 0;
+        $d .= '/examples-python';
+    }
+
+    print "installing examples to $d... ";
+
+    my $s = $sd;
+    $s = "$sd/examples" if ($HAVE{JAR} && $MAKING);
+
+    unless (-e $s) {
+        print "\tfailure\n";
+        print "install: error: '$s' is not found.\n";
+        ++$failures;
+    }
+
+    unless ($failures) {
+        print "\nchecking $d... ";
+        unless (-e $d) {
+            print "not found\n";
+            print "mkdir -p $d... ";
+            eval { make_path($d) };
+            if ($@) {
+                print "failure\ninstall: error: cannot mkdir $d\n";
+                ++$failures;
+            } else {
+                print "success\n";
+            }
+        } else {
+            print "exists\n";
+        }
+    }
+
+    unless ($failures) {
+        print "\t\t$s -> $d\n\t" if ($OPT{debug});
+        if ($HAVE{JAR} && ! $MAKING) {
+            if (copydir($s, 0 => $d)) {
+                ++$failures;
+            }
+        } else {
+            unless (dircopy($s, $d)) {
+                print "\tfailure\ninstall: error: cannot copy '$s' to '$d'";
+                ++$failures;
+            }
+        }
+    }
+
+    unless ($failures) {
+        if ($HAVE{JAR} && $MAKING) {
+            $sd = "$sd/Makefile";
+            $d = "$d/Makefile";
+            print "\t$sd -> $d\n\t" if ($OPT{debug});
+            unless (-e $sd) {
+                print "\tfailure\n";
+                print "install: error: '$sd' is not found.\n";
+                ++$failures;
+            }
+            unless ($failures) {
+                if (-e $d) {
+                unless (unlink $d) {
+                    print "failure\n";
+                    print "install: error: cannot rm '$d': $!\n";
+                    ++$failures;
+                }
+            }
+            unless ($failures) {
+                unless (copy($sd, $d)) {
+                    print "error: cannot copy '$sd' to '$d': $!\n";
+                    ++$failures;
+                }
+            }
+        }
+      }
+    }
+
+    print "success\n" unless ($failures);
+
+    $File::Copy::Recursive::CPRFComp = $CPRFComp;
+
+    return $failures;
+}
+
+sub finishinstall {
+    my $failures = 0;
+
+    $_{JAR_TARGET} = "$_{INST_JARDIR}/ngs-java.jar";
+
+    my @libs;
+    if (%INSTALLED_LIBS) {
+        my %libs;
+        ++$libs{$INSTALLED_LIBS{$_}} foreach (keys %INSTALLED_LIBS);
+        push @libs, $_ foreach (keys %libs);
+    } else {
+        push @libs, $_{LIB_TARGET};
+    }
+    my $libs;
+    foreach (@libs) {
+        $libs .= ":" if ($libs);
+        $libs .= $_;
+    }
+
+    if ($HAVE{PYTHON}) {
+        chdir "$Bin/.." or die "cannot cd '$Bin/..'";
+        my $cmd = "python setup.py install";
+        $cmd .= ' --user' unless (linux_root());
+        print `$cmd`;
+        if ($?) {
+            ++$failures;
+        } else {
+            unless ($libs) {
+                print "internal python failure\n";
+                ++$failures;
+            } elsif ($HAVE{LIBS}) {
+                print <<EndText;
+Please add $libs to your LD_LIBRARY_PATH, e.g.:
+      export LD_LIBRARY_PATH=$libs:\$LD_LIBRARY_PATH
+EndText
+            }
+        }
+    } elsif ($LINUX_ROOT) {
+        print "\t\tlinux root\n" if ($OPT{debug});
+
+        if ($HAVE{USR_INCLUDES}) {
+            unless (-e $oldincludedir) {
+                print "install: error: '$oldincludedir' does not exist\n";
+                ++$failures;
+            } else {
+                my $o = includes_out();
+                if ($o) {
+                    eval { INCLUDES_OUT(); };
+                    if (@_) {
+                        print "install: cannot find INCLUDES_OUT\n";
+                        ++$failures;
+                    } else {
+                        my $INCLUDE_SYMLINK
+                            = "$oldincludedir/" . INCLUDES_OUT();
+                        print "updating $INCLUDE_SYMLINK... ";
+                        unlink $INCLUDE_SYMLINK;
+                        if ($OPT{debug}) {
+                            print "\n\t\tln -s $o $INCLUDE_SYMLINK... ";
+                        }
+                        unless (symlink $o, $INCLUDE_SYMLINK) {
+                            print "failure\n";
+                            print "install: error: " .
+                                "cannot symlink '$o' '$INCLUDE_SYMLINK': $!\n";
+                            ++$failures;
+                        } else {
+                            print "success\n";
+                        }
+                    }
+                } else {
+                    my $INCLUDE_SYMLINK = "$oldincludedir/" . INCLUDES();
+                    print "updating $INCLUDE_SYMLINK... ";
+                    unlink $INCLUDE_SYMLINK;
+                    my $o = "$_{INST_INCDIR}/" . INCLUDES();
+                    unless (symlink $o, $INCLUDE_SYMLINK) {
+                        print "failure\n";
+                        print "install: error: "
+                            . "cannot symlink '$o' '$INCLUDE_SYMLINK': $!\n";
+                        ++$failures;
+                    } else {
+                        print "success\n";
+                    }
+                }
+            }
+        }
+
+        my $NAME = PACKAGE_NAME();
+        if ($HAVE{BINS} || $HAVE{JAR}
+            || ($HAVE{LIBS}
+                && ($HAVE{DLLS} || $NAME eq 'NGS-SDK' || $NAME eq 'NGS-BAM')
+               )
+            )
+        {
+            my $profile = "$ROOT/etc/profile.d";
+            my $PROFILE_FILE = "$profile/" . lc(PACKAGE_NAME());
+            unless (-e $profile) {
+                print "install: error: '$profile' does not exist\n";
+                ++$failures;
+            } else {
+                print "updating $PROFILE_FILE.[c]sh... ";
+
+                my $f = "$PROFILE_FILE.sh";
+                if (!open F, ">$f") {
+                    print "failure\n";
+                    print "install: error: cannot open '$f': $!\n";
+                    ++$failures;
+                } else {
+                    print F "#version $_{VERSION}\n\n";
+
+                    if ($HAVE{LIBS}) {
+                        unless (@libs) {
+                            print "internal root libraries failure\n";
+                            ++$failures;
+                        } else {
+                            if ($HAVE{DLLS}) {
+                                foreach (@libs) {
+                                    print F <<EndText;
+if ! echo \$LD_LIBRARY_PATH | /bin/grep -q $_
+then export LD_LIBRARY_PATH=$_:\$LD_LIBRARY_PATH
+fi
+
+EndText
+                                }
+                            }
+                            if ($NAME eq 'NGS-SDK') {
+                                print F "export NGS_LIBDIR=$_{LIB_TARGET}\n";
+                            } elsif ($NAME eq 'NGS-BAM') {
+                                print F
+                                      "\nexport NGS_BAM_LIBDIR=$_{LIB_TARGET}\n"
+                            }
+                        }
+                    }
+                    if ($HAVE{JAR}) {
+                        print F <<EndText;
+if ! echo \$CLASSPATH | /bin/grep -q $_{JAR_TARGET}
+then export CLASSPATH=$_{JAR_TARGET}:\$CLASSPATH
+fi
+EndText
+                    }
+                    if ($HAVE{BINS}) {
+                        print F <<EndText;
+if ! echo \$PATH | /bin/grep -q $_{INST_BINDIR}
+then export PATH=$_{INST_BINDIR}:\$PATH
+fi
+EndText
+                    }
+                    close F;
+                    unless (chmod(0644, $f)) {
+                        print "failure\n";
+                        print "install: error: cannot chmod '$f': $!\n";
+                        ++$failures;
+                    }
+                }
+            }
+
+            my $f = "$PROFILE_FILE.csh";
+            if (!open F, ">$f") {
+                print "failure\n";
+                print "install: error: cannot open '$f': $!\n";
+                ++$failures;
+            } else {
+                print F "#version $_{VERSION}\n\n";
+
+                if ($HAVE{LIBS}) {
+                    unless (@libs) {
+                        print "internal libraries failure\n";
+                        ++$failures;
+                    } else {
+                        if ($HAVE{DLLS}) {
+                            foreach (@libs) {
+                                print F <<EndText;
+echo \$LD_LIBRARY_PATH | /bin/grep -q $_
+if ( \$status ) setenv LD_LIBRARY_PATH $_:\$LD_LIBRARY_PATH
+
+EndText
+                            }
+                        }
+                    }
+                    if (PACKAGE_NAME() eq 'NGS-BAM') {
+                        print F "setenv NGS_BAM_LIBDIR $_{LIB_TARGET}\n";
+                    } elsif (PACKAGE_NAME() eq 'NGS-SDK') {
+                        print F "setenv NGS_LIBDIR $_{LIB_TARGET}\n";
+                    } elsif (PACKAGE_NAME() eq 'NCBI-VDB') {
+                        print F "setenv NCBI_VDB_LIBDIR $_{LIB_TARGET}\n";
+                    }
+                }
+                if ($HAVE{JAR}) {
+                    print F <<EndText;
+echo \$CLASSPATH | /bin/grep -q $_{JAR_TARGET}
+if ( \$status ) setenv CLASSPATH $_{JAR_TARGET}:\$CLASSPATH
+EndText
+                }
+                if ($HAVE{BINS}) {
+                    print F <<EndText;
+echo \$PATH | /bin/grep -q $_{INST_BINDIR}
+if ( \$status ) setenv PATH $_{INST_BINDIR}:\$PATH
+EndText
+                }
+                close F;
+                unless (chmod(0644, $f)) {
+                    print "failure\n";
+                    print "install: error: cannot chmod '$f': $!\n";
+                    ++$failures;
+                }
+            }
+#	@ #TODO: check version of the files above
+            print "success\n" unless ($failures);
+        }
+
+        unless ($failures) {
+            if ($HAVE{LIBS}) {
+                if (PACKAGE_NAME() eq 'NGS-BAM') {
+                    print "\n";
+                    print "Use \$NGS_BAM_LIBDIR in your link commands, e.g.:\n";
+                    print "      ld -L\$NGS_BAM_LIBDIR -lngs-bam ...\n";
+                } elsif (PACKAGE_NAME() eq 'NGS-SDK') {
+                    print "\nUse \$NGS_LIBDIR in your link commands, e.g.:\n";
+                    print "      ld -L\$NGS_LIBDIR -lngs-sdk ...\n";
+                } elsif (PACKAGE_NAME() eq 'NCBI-VDB') {
+                    print "\n"
+                       . "Use \$NCBI_VDB_LIBDIR in your link commands, e.g.:\n";
+                    print "      ld -L\$NCBI_VDB_LIBDIR -lncbi-vdb ...\n";
+                }
+            }
+        }
+    } else {
+        print "\t\tnot linux root\n" if ($OPT{debug});
+        if ($HAVE{LIBS}) {
+            unless ($libs) {
+                print "internal libraries failure\n";
+                ++$failures;
+            } else {
+                print "\n";
+                print <<EndText if ($HAVE{DLLS});
+Please add $libs to your LD_LIBRARY_PATH, e.g.:
+      export LD_LIBRARY_PATH=$libs:\$LD_LIBRARY_PATH
+EndText
+                if (PACKAGE_NAME() eq 'NGS-SDK') {
+                    print "Use $libs in your link commands, e.g.:\n"
+                        . "export NGS_LIBDIR=$libs\n"
+                        . "ld -L\$NGS_LIBDIR -lngs-sdk ...\n";
+                } elsif (PACKAGE_NAME() eq 'NGS-BAM') {
+                    print "Use $libs in your link commands, e.g.:\n"
+                        . "export NGS_BAM_LIBDIR=$libs\n"
+                        . "ld -L\$NGS_BAM_LIBDIR -lngs-bam ...\n";
+                }
+            }
+        }
+        if ($HAVE{JAR}) {
+            print <<EndText;
+
+Please add $_{JAR_TARGET} to your CLASSPATH, i.e.:
+      export CLASSPATH=$_{JAR_TARGET}:\$CLASSPATH
+EndText
+        }
+    }
+
+    return $failures;
+}
+
+sub expand_path {
+    my ($filename) = @_;
+    return unless ($filename);
+
+    if ($filename =~ /^~/) {
+        if ($filename =~ m|^~([^/]*)|) {
+            if ($1 && ! getpwnam($1)) {
+                print "install: error: bad path: '$filename'\n";
+                exit 1;
+            }
+        }
+
+        $filename =~ s{ ^ ~ ( [^/]* ) }
+                      { $1
+                            ? (getpwnam($1))[7]
+                            : ( $ENV{HOME} || $ENV{USERPROFILE} || $ENV{LOGDIR}
+                                || (getpwuid($<))[7]
+                              )
+                      }ex;
+    }
+
+    my $a = abs_path($filename);
+    $filename = $a if ($a);
+
+    $filename;
+}
+
+sub help {
+    $_{LIB_TARGET} = "$_{INST_LIBDIR}$_{BITS}";
+
+    print <<EndText;
+'install' installs $_{PACKAGE_NAME} $_{VERSION} package.
+
+Usage: ./install [OPTION]...
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+  -n, --no-create         do not run installation
+
+EndText
+
+    if ($HAVE{TWO_LIBS}) {
+        my $p = lc(PACKAGE_NAME());
+        print "By default, `./install' will install all the files in\n";
+        print "`/usr/local/ngs/$p/jar', " if ($HAVE{JAR});
+        print <<EndText;
+`/usr/local/ngs/$p/share',
+`/usr/local/ngs/ngs-sdk/lib$_{BITS}', `/usr/local/ncbi/ncbi-vdb/lib$_{BITS}'.
+You can spefify other installation directories using the options below.
+
+Fine tuning of the installation directories:
+EndText
+        if ($HAVE{JAR}) {
+            print
+                "  --jardir=DIR         jar files [/usr/local/ngs/$p/jar]\n"
+        }
+        print <<EndText;
+  --ngslibdir=DIR      ngs-sdk libraries [/usr/local/ngs/ngs-sdk/lib$_{BITS}]
+  --vdblibdir=DIR      ncbi-vdb libraries [/usr/local/ncbi/ncbi-vdb/lib$_{BITS}]
+  --examplesdir=DIR    example files [/usr/local/ngs/$p/share]
+
+  --libdir=DIR         install all libraries in the same directory
+  --prefix=DIR         install files in PREFIX/lib$_{BITS}, PREFIX/share etc.
+EndText
+    } else {
+        print <<EndText;
+Installation directories:
+  --prefix=PREFIX         install all files in PREFIX
+                          [$_{PREFIX}]
+
+By default, `./install' will install all the files in
+EndText
+
+        if ($HAVE{INCLUDES}) {
+            print
+"`$_{PREFIX}/include', `$_{PREFIX}/lib$_{BITS}' etc.  You can specify\n"
+        } elsif ($HAVE{JAR}) {
+            print "`$_{PREFIX}/jar', `$_{PREFIX}/share' etc.  You can specify\n"
+        } elsif ($MAKING) {
+            print "`$_{PREFIX}/share' etc.  You can specify\n"
+        } else {
+            print
+"`$_{PREFIX}/lib$_{BITS}' `$_{PREFIX}/share' etc.  You can specify\n"
+        }
+
+        print <<EndText;
+an installation prefix other than `$_{PREFIX}' using `--prefix',
+for instance `--prefix=$_{OTHER_PREFIX}'.
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+EndText
+
+        if ($HAVE{BINS}) {
+            print "  --bindir=DIR            executables [PREFIX/bin]\n";
+        }
+        if ($HAVE{JAR}) {
+            print "  --jardir=DIR            jar files [PREFIX/jar]\n";
+        }
+        if ($HAVE{LIBS}) {
+            print
+"  --libdir=DIR            object code libraries [PREFIX/lib$_{BITS}]\n"
+        }
+        if ($HAVE{INCLUDES}) {
+            print "  --includedir=DIR        C header files [PREFIX/include]\n";
+        }
+        if ($HAVE{USR_INCLUDES}) {
+            print
+"  --oldincludedir=DIR     C header files for non-gcc [$oldincludedir]\n"
+        }
+
+        if (-e $EXAMPLES_DIR) {
+            print "  --examplesdir=DIR       example files [PREFIX/share]\n";
+        }
+    }
+
+    if ($HAVE{LIBS}) {
+        print <<EndText;
+
+System types:
+  --bits=[32|64]          use a 32- or 64-bit data model
+EndText
+    }
+
+    print "\nReport bugs to sra-tools\@ncbi.nlm.nih.gov\n";
+}
+
+sub prepare {
+    if ($MAKING) {
+        my $os_arch = `perl -w $Bin/os-arch.perl`;
+        unless ($os_arch) {
+            print "install: error\n";
+            exit 1;
+        }
+        chomp $os_arch;
+        my $config =
+            "$Bin/../" . CONFIG_OUT() . "/Makefile.config.install.$os_arch.prl";
+        fatal_config("$config not found") unless (-e "$config");
+
+        eval { require $config; };
+        fatal_config($@) if ($@);
+    } else {
+        my $a = $Config{archname64};
+        $_ = lc PACKAGE_NAME();
+        my $root = '';
+        $root = $OPT{root} if ($OPT{root});
+        my $code = 
+            'sub CONFIGURE { ' .
+            '   $_{OS           } = $OS; ' .
+            '   $_{VERSION      } = "1.0.0"; ' .
+            '   $_{MAJVERS      } = "1"; ' .
+            '   $_{LPFX         } = "lib"; ' .
+            '   $_{LIBX         } = "a"; ' .
+            '   $_{MAJVERS_LIBX } = "a.1"; ' .
+            '   $_{VERSION_LIBX } = "a.1.0.0"; ' .
+            '   $_{SHLX         } = "so"; ' .
+            '   $_{OTHER_PREFIX } = \'$HOME/ngs/' . $_ . '\'; ' .
+            '   $_{PREFIX       } = "' . "$root/usr/local/ngs/$_" . '"; ' .
+            '   $_{INST_INCDIR  } = "$_{PREFIX}/include"; ' .
+            '   $_{INST_LIBDIR  } = "$_{PREFIX}/lib"; ' .
+            '   $_{INST_JARDIR  } = "$_{PREFIX}/jar"; ' .
+            '   $_{INST_SHAREDIR} = "$_{PREFIX}/share"; ' .
+            '   $_{INCDIR       } = "$Bin/../include"; ' .
+            '   $_{LIBDIR64     } = "$Bin/../lib64"; ' .
+            '   $_{LIBDIR32     } = "$Bin/../lib32"; ';
+        if ($HAVE{TWO_LIBS}) {
+            $code .=
+               '$_{INST_NGSLIBDIR} = "' . "$root/usr/local/ngs/ngs-sdk/lib\";"
+             . '$_{INST_VDBLIBDIR} = "' . "$root/usr/local/ncbi/ncbi-vdb/lib\";"
+        }
+        $code .= ' $_{PACKAGE_NAME} = "' . PACKAGE_NAME() . '"; ';
+
+        if (defined $Config{archname64}) {
+            $code .= ' $_{BITS} = 64; ';
+        } else {
+            $code .= ' $_{BITS} = 32; ';
+        }
+
+        $code .= 
+            '   $_{MAJVERS_SHLX } = "so.1"; ' .
+            '   $_{VERSION_SHLX } = "so.1.0.0"; ' ;
+
+        $code .= 
+            '   @_ ' .
+            '}';
+
+        eval $code;
+
+        die $@ if ($@);
+    }
+}
+
+sub linux_root { $^O eq 'linux' && `id -u` == 0 }
+
+sub fatal_config {
+    if ($OPT{debug}) {
+        print "\t\t";
+        print "@_";
+        print "\n";
+    }
+
+    print "install: error: run ./configure [OPTIONS] first.\n";
+
+    exit 1;
+}
+
+################################################################################
diff --git a/ngs-sdk/setup/install.prl b/ngs-sdk/setup/install.prl
new file mode 100644
index 0000000..da45015
--- /dev/null
+++ b/ngs-sdk/setup/install.prl
@@ -0,0 +1,6 @@
+sub PACKAGE_NAME { 'NGS-SDK' }
+sub HAVE        { ( EXAMPLES => 1, LIBS => 1, USR_INCLUDES => 1, ) }
+sub CONFIG_OUT  {  '.' }
+sub INCLUDES    {  'ngs' }
+sub LIBS {( 'ngs-sdk' => 'SHL', 'ngs-c++' => 'LIB', 'ngs-adapt-c++' => 'LIB' )}
+1
diff --git a/ngs-java/konfigure.perl b/ngs-sdk/setup/konfigure.perl
similarity index 60%
rename from ngs-java/konfigure.perl
rename to ngs-sdk/setup/konfigure.perl
index 2a7fde7..7b7780e 100644
--- a/ngs-java/konfigure.perl
+++ b/ngs-sdk/setup/konfigure.perl
@@ -32,65 +32,117 @@ if ($directories ne "./") {
     exit 1;
 }
 
-require 'package.pm';
-require 'os-arch.pm';
+require 'package.prl';
+require 'os-arch.prl';
 
-use Cwd qw (abs_path getcwd);
+use Cwd qw(abs_path getcwd);
 use File::Basename 'fileparse';
 use File::Spec 'catdir';
 use FindBin qw($Bin);
-use Getopt::Long 'GetOptions';
+use Getopt::Long "GetOptions";
+
+chdir '..' or die "cannot cd to package root";
 
 check();
 
+my $LOCAL_BUILD_OUT
+    = -e File::Spec->catdir($ENV{HOME}, 'tmp', 'local-build-out');
+
+my ($CONFIGURED, $RECONFIGURE) = ('');
+if (@ARGV) {
+    foreach (@ARGV) {
+        $CONFIGURED .= "\t" if ($CONFIGURED);
+        $CONFIGURED .= "'$_'";
+    }
+} elsif (-f 'reconfigure') {
+    ++$RECONFIGURE unless ($LOCAL_BUILD_OUT);
+}
+
 my %PKG = PKG();
 
 my $PACKAGE_NAME = PACKAGE_NAME();
 my $OUT_MAKEFILE = 'Makefile.config';
+my $INS_MAKEFILE = 'Makefile.config.install';
 
 my $PACKAGE = PACKAGE();
 
 my $HOME = $ENV{HOME} || $ENV{USERPROFILE}
     || $ENV{LOGDIR} || getcwd || (getpwuid($<))[7] || abs_path('.');
 
-$PKG{UPATH} =~ s/(\$\w+)/$1/eeg;
-
-my $OUTDIR = File::Spec->catdir($HOME, $PKG{OUT});
+$PKG{UPATH} = expand($PKG{UPATH});
 
 my $package_default_prefix = $PKG{PATH};
 my $schema_default_dir = $PKG{SCHEMA_PATH} if ($PKG{SCHEMA_PATH});
 
 my @REQ = REQ();
 
-my @options = ( "arch=s",
-                "build=s",
-                "clean",
-                "debug",
-                "help",
-#               "output-makefile=s",
-                "prefix=s",
-                "status",
-                "with-debug",
-                "without-debug" );
+my @options = ( 'build-prefix=s',
+                'clean',
+                'debug',
+                'help',
+                'prefix=s',
+                'reconfigure',
+                'status',
+                'with-debug',
+                'without-debug', );
+{
+    my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
+    push @options, 'arch=s'    if (@ARCHITECTURES);
+}
+push @options, 'enable-static' if (PACKAGE_TYPE() eq 'B');
 foreach my $href (@REQ) {
     my %a = %$href;
     push @options, "$a{option}=s";
     push @options, "$a{boption}=s" if ($a{boption});
-    $href->{usrpath} =~ s/(\$\w+)/$1/eeg;
+    $href->{usrpath} = '' unless ($href->{usrpath});
+    $href->{usrpath} = expand($href->{usrpath});
 }
 push @options, "shemadir" if ($PKG{SCHEMA_PATH});
 
 my %OPT;
 die "configure: error" unless (GetOptions(\%OPT, @options));
+++$OPT{'reconfigure'} if ($RECONFIGURE);
+
+if ($OPT{'reconfigure'}) {
+    unless (eval 'use Getopt::Long qw(GetOptionsFromString); 1') {
+        print <<EndText;
+configure: error: your perl does not support Getopt::Long::GetOptionsFromString
+                  reconfigure option is not avaliable.
+Run "sh ./reconfigure" instead.
+EndText
+        exit 1;
+    }
+    println "reconfiguring...";
+    open F, 'reconfigure' or die 'cannot open reconfigure';
+    $_ = <F>;
+    chomp;
+    unless (m|^\./configure\s*(.*)$|) {
+        println 'configure: error: cannot reconfigure';
+        println 'run "./configure --clean" then run "./configure [OPTIONS]"';
+        exit 1;
+    }
+
+    println "running \"./configure $1\"...";
+    undef %OPT;
+    die "configure: error" unless (GetOptionsFromString($1, \%OPT, @options));
+    ++$OPT{reconfigure};
+}
+
+$OPT{'local-build-out'} = $LOCAL_BUILD_OUT;
+my $OUTDIR = File::Spec->catdir($HOME, $PKG{OUT});
+if ($OPT{'local-build-out'}) {
+    my $o = expand_path(File::Spec->catdir($Bin, $PKG{LOCOUT}));
+    $OUTDIR = $o if ($o);
+}
 
 if ($OPT{'help'}) {
     help();
-    exit(0);
+    exit 0;
 } elsif ($OPT{'clean'}) {
     {
-        foreach (glob(CONFIG_OUT() . '/Makefile.config*'),
-            File::Spec->catdir(CONFIG_OUT(), 'user.status'),
-            File::Spec->catdir(CONFIG_OUT(), 'Makefile.userconfig'))
+        foreach ('reconfigure', glob(CONFIG_OUT() . '/Makefile.config*'),
+            File::Spec->catdir(CONFIG_OUT(), 'Makefile.userconfig'),
+            File::Spec->catdir(CONFIG_OUT(), 'user.status'))
         {
             my $f = $_;
             print "removing $f... ";
@@ -122,11 +174,14 @@ if ($OPT{'help'}) {
             }
         }
     }
-    exit(0);
+    exit 0;
 } elsif ($OPT{'status'}) {
     status(1);
-    exit(0);
+    exit 0;
 }
+
+println "Configuring $PACKAGE_NAME package";
+
 $OPT{'prefix'} = $package_default_prefix unless ($OPT{'prefix'});
 
 my $AUTORUN = $OPT{status};
@@ -134,34 +189,52 @@ print "checking system type... " unless ($AUTORUN);
 my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
 println $OSTYPE unless ($AUTORUN);
 
+unless ($OSTYPE =~ /linux/i || $OSTYPE =~ /darwin/i || $OSTYPE eq 'win') {
+    println "configure: error: unsupported system '$OSTYPE'";
+    exit 1;
+}
+
+print "checking machine architecture... " unless ($AUTORUN);
+println $MARCH unless ($AUTORUN);
+unless ($MARCH =~ /x86_64/i || $MARCH =~ /i?86/i) {
+    println "configure: error: unsupported architecture '$OSTYPE'";
+    exit 1;
+}
+
 {
-    $OPT{'prefix'} = expand($OPT{'prefix'});
+    $OPT{'prefix'} = expand_path($OPT{'prefix'});
     my $prefix = $OPT{'prefix'};
-    $OPT{eprefix} = $prefix unless ($OPT{eprefix} || $OS eq 'win');
-    my $eprefix = $OPT{eprefix};
-    unless ($OPT{bindir} || $OS eq 'win') {
-        $OPT{bindir} = File::Spec->catdir($eprefix, 'bin') ;
+    $OPT{'eprefix'} = $prefix unless ($OPT{'eprefix'} || $OS eq 'win');
+    my $eprefix = $OPT{'eprefix'};
+    unless ($OPT{'bindir'} || $OS eq 'win') {
+        $OPT{'bindir'} = File::Spec->catdir($eprefix, 'bin') ;
     }
-    unless ($OPT{libdir} || $OS eq 'win') {
-        $OPT{libdir} = File::Spec->catdir($eprefix, 'lib');
+    unless ($OPT{'libdir'} || $OS eq 'win') {
+        $OPT{'libdir'} = File::Spec->catdir($eprefix, 'lib');
     }
-    unless ($OPT{includedir} || $OS eq 'win') {
-        $OPT{includedir} = File::Spec->catdir($eprefix, 'include');
+    unless ($OPT{'includedir'} || $OS eq 'win') {
+        $OPT{'includedir'} = File::Spec->catdir($eprefix, 'include');
     }
-    if ($PKG{LNG} eq 'PYTHON' && ! $OPT{pythondir} && $OS ne 'win') {
-        $OPT{pythondir} = $eprefix;
+    if ($PKG{LNG} eq 'PYTHON' && ! $OPT{'pythondir'} && $OS ne 'win') {
+        $OPT{'pythondir'} = $eprefix;
     }
-    if ($PKG{LNG} eq 'JAVA' && ! $OPT{javadir} && $OS ne 'win') {
-        $OPT{javadir} = File::Spec->catdir($eprefix, 'jar');
+    if ($PKG{LNG} eq 'JAVA' && ! $OPT{'javadir'} && $OS ne 'win') {
+        $OPT{'javadir'} = File::Spec->catdir($eprefix, 'jar');
     }
-    if ($PKG{EXAMP} && ! $OPT{sharedir} && $OS ne 'win') {
-        $OPT{sharedir} = File::Spec->catdir($eprefix, 'share');
+    if ($PKG{EXAMP} && ! $OPT{'sharedir'} && $OS ne 'win') {
+        $OPT{'sharedir'} = File::Spec->catdir($eprefix, 'share');
     }
 }
 
 # initial values
 my $TARGDIR = File::Spec->catdir($OUTDIR, $PACKAGE);
-$TARGDIR = expand($OPT{'build'}) if ($OPT{'build'});
+if ($OPT{'build-prefix'}) {
+    $TARGDIR = $OPT{'build-prefix'} = expand_path($OPT{'build-prefix'});
+    unless ($TARGDIR =~ /$PACKAGE$/) {
+        $TARGDIR = File::Spec->catdir($TARGDIR, $PACKAGE);
+    }
+}
+my $BUILD_PREFIX = $TARGDIR;
 
 my $BUILD = 'rel';
 
@@ -195,14 +268,8 @@ if ($OPT{arch}) {
     }
 }
 
-$OUT_MAKEFILE .= ".$OS.$ARCH";
-$OUT_MAKEFILE = File::Spec->catdir(CONFIG_OUT(), $OUT_MAKEFILE);
-
-#my $OSTYPE = `uname -s`; chomp $OSTYPE;
-
-print "checking machine architecture... " unless ($AUTORUN);
-#my $MARCH = `uname -m`; chomp $MARCH;
-println $MARCH unless ($AUTORUN);
+$OUT_MAKEFILE = File::Spec->catdir(CONFIG_OUT(), "$OUT_MAKEFILE.$OS.$ARCH");
+$INS_MAKEFILE = File::Spec->catdir(CONFIG_OUT(), "$INS_MAKEFILE.$OS.$ARCH.prl");
 
 my $TOOLS = "";
 $TOOLS = "jdk" if ($PKG{LNG} eq 'JAVA');
@@ -217,17 +284,12 @@ print "checking for supported architecture... " unless ($AUTORUN);
 
 my $BITS;
 
-if ( $MARCH =~ m/x86_64/i )
-{
+if ($MARCH =~ /x86_64/i) {
     $BITS = 64;
-}
-elsif ( $MARCH =~ m/i?86/i )
-{
+} elsif ($MARCH =~ /i?86/i) {
     $BITS = 32;
-}
-else
-{
-    die "unrecognized Architecture - " . $ARCH;
+} else {
+    die "unrecognized Architecture '$ARCH'";
 }
 println "$MARCH ($BITS bits) is supported" unless ($AUTORUN);
 
@@ -235,105 +297,111 @@ println "$MARCH ($BITS bits) is supported" unless ($AUTORUN);
 my ($LPFX, $OBJX, $LOBX, $LIBX, $SHLX, $EXEX, $OSINC);
 
 print "checking for supported OS... " unless ($AUTORUN);
-if ( $OSTYPE =~ m/linux/i )
-{
-    $LPFX = "lib";
-    $OBJX = "o";
-    $LOBX = "pic.o";
-    $LIBX = "a";
-    $SHLX = "so";
-    $EXEX = "";
-    $OSINC = "unix";
-    if ( $TOOLS eq "" )
-    {
-        $TOOLS = "gcc";
-    }
-}
-elsif ( $OSTYPE =~ m/darwin/i )
-{
-    $LPFX = "lib";
-    $OBJX = "o";
-    $LOBX = "pic.o";
-    $LIBX = "a";
-    $SHLX = "dylib";
-    $EXEX = "";
-    $OSINC = "unix";
-    if ( $TOOLS eq "" )
-    {
-        $TOOLS = "clang";
-    }
+if ($OSTYPE =~ /linux/i) {
+    $LPFX = 'lib';
+    $OBJX = 'o';
+    $LOBX = 'pic.o';
+    $LIBX = 'a';
+    $SHLX = 'so';
+    $EXEX = '';
+    $OSINC = 'unix';
+    $TOOLS = 'gcc' unless ($TOOLS);
+} elsif ($OSTYPE =~ /darwin/i) {
+    $LPFX = 'lib';
+    $OBJX = 'o';
+    $LOBX = 'pic.o';
+    $LIBX = 'a';
+    $SHLX = 'dylib';
+    $EXEX = '';
+    $OSINC = 'unix';
+    $TOOLS = 'clang' unless ($TOOLS);
 } elsif ($OSTYPE eq 'win') {
-    $TOOLS = "vc++";
-} else
-{
-    die "unrecognized OS - " . $OSTYPE;
+    $TOOLS = 'vc++';
+} else {
+    die "unrecognized OS '$OSTYPE'";
 }
 println "$OSTYPE ($OS) is supported" unless ($AUTORUN);
 
 # tool chain
-my ($CC, $CP, $AR, $ARX, $ARLS, $LD, $LP);
+my ($CPP, $CC, $CP, $AR, $ARX, $ARLS, $LD, $LP);
 my ($JAVAC, $JAVAH, $JAR);
 my ($DBG, $OPT, $PIC, $INC, $MD);
 
 print "checking for supported tool chain... " unless ($AUTORUN);
-if ( $TOOLS =~ m/gcc/i )
-{
-    $CC = "gcc -c";
-    $CP = "g++ -c";
-    $AR = "ar rc";
-    $ARX = "ar x";
-    $ARLS = "ar t";
-    $LD = "gcc";
-    $LP = "g++";
-
-    $DBG = "-g -DDEBUG";
-    $OPT = "-O3";
-    $PIC = "-fPIC";
-    $INC = "-I";
-    $MD  = "-MD";
-}
-elsif ( $TOOLS =~ m/clang/i )
-{
-    $CC = "clang -c";
-    $CP = "clang++ -c";
-    $AR = "ar rc";
-    $ARX = "ar x";
-    $ARLS = "ar t";
-    $LD = "clang";
-    $LP = "clang++";
-
-    $DBG = "-g -DDEBUG";
-    $OPT = "-O3";
-    $PIC = "-fPIC";
-    $INC = "-I";
-    $MD  = "-MD";
-}
-elsif ( $TOOLS =~ m/jdk/i )
-{
-    $JAVAC = "javac";
-    $JAVAH = "javah";
-    $JAR   = "jar cf";
-
-    $DBG = "-g";
+if ($TOOLS eq 'gcc') {
+    $CPP  = 'g++';
+    $CC   = 'gcc -c';
+    $CP   = "$CPP -c";
+    $AR   = 'ar rc';
+    $ARX  = 'ar x';
+    $ARLS = 'ar t';
+    $LD   = 'gcc';
+    $LP   = $CPP;
+
+    $DBG = '-g -DDEBUG';
+    $OPT = '-O3';
+    $PIC = '-fPIC';
+    $INC = '-I';
+    $MD  = '-MD';
+} elsif ($TOOLS eq 'clang') {
+    $CPP  = 'clang++';
+    $CC   = 'clang -c';
+    $CP   = "$CPP -c -mmacosx-version-min=10.6";
+    $AR   = 'ar rc';
+    $ARX  = 'ar x';
+    $ARLS = 'ar t';
+    $LD   = 'clang';
+    $LP   = "$CPP -mmacosx-version-min=10.6";
+
+    $DBG = '-g -DDEBUG';
+    $OPT = '-O3';
+    $PIC = '-fPIC';
+    $INC = '-I';
+    $MD  = '-MD';
+} elsif ($TOOLS eq 'jdk') {
+    $JAVAC = 'javac';
+    $JAVAH = 'javah';
+    $JAR   = 'jar cf';
+
+    $DBG = '-g';
 } elsif ($TOOLS eq 'vc++') {
-} else
-{
-    die "unrecognized tool chain - " . $TOOLS;
+} else {
+    die "unrecognized tool chain '$TOOLS'";
 }
 println "$TOOLS tool chain is supported" unless ($AUTORUN);
 
-if ($OS ne 'win') {
+if ($OS ne 'win' && $PKG{LNG} ne 'JAVA') {
     $TARGDIR = File::Spec->catdir($TARGDIR, $OS, $TOOLS, $ARCH, $BUILD);
 }
 
+if ($CPP) {
+    unless (check_tool($CPP)) {
+        println "configure: error: '$CPP' cannot be found";
+        exit 1;
+    }
+}
+
+my $NO_ARRAY_BOUNDS_WARNING = '';
+if ($TOOLS eq 'gcc' && check_no_array_bounds()) {
+    $NO_ARRAY_BOUNDS_WARNING = '-Wno-array-bounds';
+}
+
 my @dependencies;
 
+my %DEPEND_OPTIONS;
 foreach my $href (DEPENDS()) {
     $_ = $href->{name};
     my ($I, $L) = ($href->{Include});
-    if ($OPT{"with-$_-prefix"}) {
-        $I = File::Spec->catdir($OPT{"with-$_-prefix"}, 'include'); 
-        $L = File::Spec->catdir($OPT{"with-$_-prefix"}, 'lib'); 
+    my $o = "with-$_-prefix";
+    ++$DEPEND_OPTIONS{$o};
+    if ($OPT{$o}) {
+        $OPT{$o} = expand_path($OPT{$o});
+        $I = File::Spec->catdir($OPT{$o}, 'include');
+        if (/^xml2$/) {
+            my $t = File::Spec->catdir($I, 'libxml2');
+            $I = $t if (-e $t);
+        }
+        $L = File::Spec->catdir($OPT{$o}, 'lib');
     }
     my ($i, $l) = find_lib($_, $I, $L);
     if (defined $i || $l) {
@@ -354,16 +422,21 @@ foreach my $href (DEPENDS()) {
 }
 
 foreach my $href (@REQ) {
-    $href->{bldpath} =~ s/(\$\w+)/$1/eeg if ($href->{bldpath});
+    $href->{   bldpath} = expand($href->{   bldpath}) if ($href->{   bldpath});
+    $href->{locbldpath} = expand($href->{locbldpath}) if ($href->{locbldpath});
     my ($found_itf, $found_lib, $found_ilib);        # found directories
     my %a = %$href;
+    next if ($a{option} && $DEPEND_OPTIONS{$a{option}});
     my $is_optional = optional($a{type});
+    my $quasi_optional = $a{type} =~ /Q/;
     my $need_source = $a{type} =~ /S/;
     my $need_build = $a{type} =~ /B/;
-    my $need_lib = $a{type} =~ /L/;
+    my $need_lib = $a{type} =~ /L|D/;
+    my $need_itf = ! ($a{type} =~ /D/);
     
     my ($inc, $lib, $ilib) = ($a{include}, $a{lib}); # file names to check
-    $lib =~ s/(\$\w+)/$1/eeg;
+    $lib = '' unless ($lib);
+    $lib = expand($lib);
 
     if ($need_build) {
         $ilib = $a{ilib};
@@ -383,7 +456,7 @@ foreach my $href (@REQ) {
     foreach my $option ($a{option}, $a{boption}) {
         next unless ($option);
         if ($OPT{$option}) {
-            my $try = expand($OPT{$option});
+            my $try = expand_path($OPT{$option});
             my ($i, $l, $il) = ($inc, $lib, $ilib);
             if ($option =~ /-build$/) {
                 undef $i;
@@ -397,9 +470,18 @@ foreach my $href (@REQ) {
                 ++$has_option{sources};
             }
             my ($fi, $fl, $fil) = find_in_dir($try, $i, $l, $il);
-            $found_itf  = $fi  if (! $found_itf  && $fi);
-            $found_lib  = $fl  if (! $found_lib  && $fl);
-            $found_ilib = $fil if (! $found_ilib && $fil);
+            if ($fi || $fl || $fil) {
+                $found_itf  = $fi  if (! $found_itf  && $fi);
+                $found_lib  = $fl  if (! $found_lib  && $fl);
+                $found_ilib = $fil if (! $found_ilib && $fil);
+            }
+            elsif (! ($try =~ /$a{name}$/)) {
+                $try = File::Spec->catdir($try, $a{name});
+                ($fi, $fl, $fil) = find_in_dir($try, $i, $l, $il);
+                $found_itf  = $fi  if (! $found_itf  && $fi);
+                $found_lib  = $fl  if (! $found_lib  && $fl);
+                $found_ilib = $fil if (! $found_ilib && $fil);
+            }
         }
     }
     if (! $found_itf && ! $has_option{sources} && $a{srcpath}) {
@@ -423,16 +505,39 @@ foreach my $href (@REQ) {
     }
     if (! $has_option{build}) {
         if (($need_build || ($need_lib && ! $found_lib)) && $a{bldpath}) {
-            my $try = $a{bldpath};
-            my (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
-            $found_lib  = $fl  if (! $found_lib  && $fl);
-            $found_ilib = $fil if (! $found_ilib && $fil);
+            my ($fl, $fil);
+            if ($OPT{'build-prefix'}) {
+                my $try = $OPT{'build-prefix'};
+                (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
+                if ($fl || $fil) {
+                    $found_lib  = $fl  if (! $found_lib  && $fl);
+                    $found_ilib = $fil if (! $found_ilib && $fil);
+                } elsif (! ($try =~ /$a{name}$/)) {
+                    $try = File::Spec->catdir($try, $a{name});
+                    (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
+                    if ($fl || $fil) {
+                        $found_lib  = $fl  if (! $found_lib  && $fl);
+                        $found_ilib = $fil if (! $found_ilib && $fil);
+                    }
+                }
+            }
+            unless ($fl || $fil) {
+                my $try = $a{bldpath};
+                $try = $a{locbldpath} if ($OPT{'local-build-out'});
+                (undef, $fl, $fil) = find_in_dir($try, undef, $lib, $ilib);
+                $found_lib  = $fl  if (! $found_lib  && $fl);
+                $found_ilib = $fil if (! $found_ilib && $fil);
+            }
         }
     }
-    if (! $found_itf || ($need_lib && ! $found_lib) || ($ilib && ! $found_ilib))
+    if (($need_itf && ! $found_itf) ||
+        ($need_lib && ! $found_lib) || ($ilib && ! $found_ilib))
     {
         if ($is_optional) {
             println "configure: optional $a{name} package not found: skipped.";
+        } elsif ($quasi_optional && $found_itf && ($need_lib && ! $found_lib)) {
+            println "configure: $a{name} package: "
+                . "found interface files but not libraries.";
         } else {
             if ($OPT{'debug'}) {
                 $_ = "$a{name}: includes: ";
@@ -456,20 +561,42 @@ foreach my $href (@REQ) {
             exit 1;
         }
     } else {
-        $found_itf = abs_path($found_itf);
-        push(@dependencies, "$a{namew}_INCDIR = $found_itf");
+        if ($found_itf) {
+            $found_itf = abs_path($found_itf);
+            push(@dependencies, "$a{aname}_INCDIR = $found_itf");
+        }
         if ($found_lib) {
             $found_lib = abs_path($found_lib);
-            push(@dependencies, "$a{namew}_LIBDIR = $found_lib");
+            if ($a{aname} eq 'NGS' || $a{aname} eq 'VDB') {
+                if ($OPT{PYTHON_LIB_PATH}) {
+                    $OPT{PYTHON_LIB_PATH} .= ':';
+                } else {
+                    $OPT{PYTHON_LIB_PATH} = '';
+                }
+                $OPT{PYTHON_LIB_PATH} .= $found_lib;
+            }
+            push(@dependencies, "$a{aname}_LIBDIR = $found_lib");
         }
         if ($ilib && $found_ilib) {
             $found_ilib = abs_path($found_ilib);
-            push(@dependencies, "$a{namew}_ILIBDIR = $found_ilib");
+            push(@dependencies, "$a{aname}_ILIBDIR = $found_ilib");
         }
     }
 }
 
+my ($E_BINDIR, $E_LIBDIR, $VERSION, $MAJVERS, $E_VERSION_LIBX, $E_MAJVERS_LIBX,
+                                              $E_VERSION_EXEX, $E_MAJVERS_EXEX)
+    = (''    , '');
+
 if ($OS ne 'win' && ! $OPT{'status'}) {
+    if ($OSTYPE =~ /darwin/i && CONFIG_OUT() ne '.') {
+        my $COMP = File::Spec->catdir(CONFIG_OUT(), 'COMP.mac');
+        println "configure: creating '$COMP' ($TOOLS)" unless ($AUTORUN);
+        open F, ">$COMP" or die "cannot open $COMP to write";
+        print F "$TOOLS\n";
+        close F;
+    }
+
     # create Makefile.config
     println "configure: creating '$OUT_MAKEFILE'" unless ($AUTORUN);
     open my $F, ">$OUT_MAKEFILE" or die "cannot open $OUT_MAKEFILE to write";
@@ -477,34 +604,53 @@ if ($OS ne 'win' && ! $OPT{'status'}) {
     print $F <<EndText;
 ### AUTO-GENERATED FILE ###
 
-OS_ARCH = \$(shell perl \$(TOP)/os-arch.perl)
+# configuration command
+
+CONFIGURED = $CONFIGURED
+
+OS_ARCH = \$(shell perl \$(TOP)/setup/os-arch.perl)
 
 # install paths
 EndText
 
-    L($F, "INST_BINDIR = $OPT{bindir}"        ) if ($OPT{bindir});
-    L($F, "INST_LIBDIR = $OPT{libdir}"        ) if ($OPT{libdir});
-    L($F, "INST_INCDIR = $OPT{includedir}"    ) if ($OPT{includedir});
+    L($F, "INST_BINDIR = $OPT{'bindir'}"      ) if ($OPT{'bindir'});
+    L($F, "INST_LIBDIR = $OPT{'libdir'}"      ) if ($OPT{'libdir'});
+    L($F, "INST_INCDIR = $OPT{'includedir'}"  ) if ($OPT{'includedir'});
     L($F, "INST_SCHEMADIR = $OPT{'shemadir'}" ) if ($OPT{'shemadir'});
     L($F, "INST_SHAREDIR = $OPT{'sharedir'}"  ) if ($OPT{'sharedir'});
     L($F, "INST_JARDIR = $OPT{'javadir'}"     ) if ($OPT{'javadir'});
     L($F, "INST_PYTHONDIR = $OPT{'pythondir'}") if ($OPT{'pythondir'});
 
-    my ($VERSION_SHLX, $MAJMIN_SHLX, $MAJVERS_SHLX);
+    my ($E_VERSION_SHLX, $VERSION_SHLX,
+        $E_MAJVERS_SHLX , $MAJMIN_SHLX, $MAJVERS_SHLX);
     if ($OSTYPE =~ /darwin/i) {
+        $E_VERSION_SHLX =  '$VERSION.$SHLX';
         $VERSION_SHLX = '$(VERSION).$(SHLX)';
         $MAJMIN_SHLX  = '$(MAJMIN).$(SHLX)';
+        $E_MAJVERS_SHLX = '$MAJVERS.$SHLX';
         $MAJVERS_SHLX = '$(MAJVERS).$(SHLX)';
     } else {
+        $E_VERSION_SHLX =  '$SHLX.$VERSION';
         $VERSION_SHLX = '$(SHLX).$(VERSION)';
         $MAJMIN_SHLX  = '$(SHLX).$(MAJMIN)';
+        $E_MAJVERS_SHLX =  '$SHLX.$MAJVERS';
         $MAJVERS_SHLX = '$(SHLX).$(MAJVERS)';
     }
 
+    $E_VERSION_LIBX = '$LIBX.$VERSION';
+    $E_MAJVERS_LIBX = '$LIBX.$MAJVERS';
 
-    print $F <<EndText;
+    L($F);
+    L($F, "# build type");
+
+    if ($OPT{'enable-static'}) {
+        L($F, "WANTS_STATIC = 1");
+    }
 
-# build type
+    $E_VERSION_EXEX = '$EXEX.$VERSION';
+    $E_MAJVERS_EXEX = '$LIBX.$MAJVERS';
+
+    print $F <<EndText;
 BUILD = $BUILD
 
 # target OS
@@ -587,11 +733,12 @@ EndText
     }
 
     L($F, 'CLSPATH = -classpath $(CLSDIR)');
+    L($F, "NO_ARRAY_BOUNDS_WARNING = $NO_ARRAY_BOUNDS_WARNING");
     L($F);
 
     # version information
 
-    my ($VERSION, $MAJMIN, $MAJVERS);
+    my $MAJMIN;
 
     if ($FULL_VERSION =~ /(\d+)\.(\d+)\.(\d+)-?\w*\d*/) {
         $VERSION = "$1.$2.$3";
@@ -608,6 +755,7 @@ MAJMIN  = $MAJMIN
 MAJVERS = $MAJVERS
 
 # output path
+BUILD_PREFIX = $BUILD_PREFIX
 TARGDIR = $TARGDIR
 
 # derived paths
@@ -618,16 +766,21 @@ BINDIR    = \$(TARGDIR)/bin
 EndText
 
     if ($PKG{LNG} eq 'C') {
+        $E_BINDIR        = '$TARGDIR/bin';
+        $E_LIBDIR        = '$TARGDIR/lib';
         L($F, 'LIBDIR    = $(TARGDIR)/lib');
     } elsif ($PKG{LNG} eq 'JAVA') {
+        $E_LIBDIR        = '$TARGDIR/jar';
         L($F, 'LIBDIR    = $(TARGDIR)/jar');
     }
 
-    print $F <<EndText;
-ILIBDIR   = \$(TARGDIR)/ilib
-OBJDIR    = \$(TARGDIR)/obj/\$(MODPATH)
-CLSDIR    = \$(TARGDIR)/cls
-EndText
+    L($F, 'ILIBDIR   = $(TARGDIR)/ilib');
+    if ($PKG{NOMODPATH}) {
+        L($F, 'OBJDIR    = $(TARGDIR)/obj');
+    } else {
+        L($F, 'OBJDIR    = $(TARGDIR)/obj/$(MODPATH)');
+    }
+    L($F, 'CLSDIR    = $(TARGDIR)/cls');
 
     if ($PKG{LNG} eq 'JAVA') {
         L($F,
@@ -747,6 +900,51 @@ EndText
         T($F, '  fi');
     }
     close $F;
+
+    # create Makefile.config.install
+    println "configure: creating '$INS_MAKEFILE'" unless ($AUTORUN);
+    open $F, ">$INS_MAKEFILE" or die "cannot open $INS_MAKEFILE to write";
+
+    $OPT{'javadir' } = '' unless ($OPT{'javadir' });
+    $OPT{'sharedir'} = '' unless ($OPT{'sharedir'});
+
+    print $F "sub CONFIGURE {\n";
+    print $F "    \$_{PACKAGE_NAME } = '$PACKAGE_NAME';\n";
+    print $F "    \$_{VERSION      } = '$VERSION';\n";
+    print $F "    \$_{LNG          } = '$PKG{LNG}';\n";
+    print $F "    \$_{OS           } = '$OS';\n";
+    print $F "    \$_{BITS         } =  $BITS;\n";
+    print $F "    \$_{MAJVERS      } =  $MAJVERS;\n";
+    print $F "    \$_{LPFX         } = '$LPFX';\n";
+    print $F "    \$_{LIBX         } = '$LIBX';\n";
+    print $F "    \$_{MAJVERS_LIBX } = '" . expand($E_MAJVERS_LIBX) . "';\n";
+    print $F "    \$_{VERSION_LIBX } = '" . expand($E_VERSION_LIBX) . "';\n";
+    print $F "    \$_{SHLX         } = '$SHLX';\n";
+    print $F "    \$_{MAJVERS_SHLX } = '" . expand($E_MAJVERS_SHLX) . "';\n";
+    print $F "    \$_{VERSION_SHLX } = '" . expand($E_VERSION_SHLX) . "';\n";
+    print $F "    \$_{VERSION_EXEX } = '" . expand($E_VERSION_EXEX) . "';\n";
+    print $F "    \$_{MAJVERS_EXEX } = '" . expand($E_MAJVERS_EXEX) . "';\n";
+    print $F "    \$_{INCDIR       } = '" . expand("$Bin/.."      ) . "';\n";
+    if ($PKG{LNG} ne 'PYTHON') {
+        print $F "  \$_{BINDIR$BITS} = '" . expand($E_BINDIR      ) . "';\n";
+        print $F "  \$_{LIBDIR$BITS} = '" . expand($E_LIBDIR      ) . "';\n";
+    } elsif ($OPT{PYTHON_LIB_PATH}) {
+        print $F "  \$_{LIBDIR$BITS} = '$OPT{PYTHON_LIB_PATH}';\n";
+    }
+    print $F "    \$_{OTHER_PREFIX } = '$PKG{UPATH}';\n";
+    print $F "    \$_{PREFIX       } = '$OPT{'prefix'}';\n";
+    print $F "    \$_{INST_INCDIR  } = '$OPT{'includedir'}';\n";
+    print $F "    \$_{INST_BINDIR  } = '$OPT{'bindir'}';\n";
+    print $F "    \$_{INST_LIBDIR  } = '$OPT{'libdir'}';\n";
+    print $F "    \$_{INST_JARDIR  } = '$OPT{'javadir'}';\n";
+    print $F "    \$_{INST_SHAREDIR} = '$OPT{'sharedir'}';\n";
+    print $F "\n";
+    print $F "    \@_\n";
+    print $F "}\n";
+    print $F "\n";
+    print $F "1\n";
+
+    close $F;
 }
 
 if (! $OPT{'status'} ) {
@@ -768,7 +966,7 @@ EndText
             my $NGS_SDK_PREFIX = '';
             $NGS_SDK_PREFIX = $a{found_itf} if ($a{found_itf});
             if ($a{name} eq 'ngs-sdk') {
-                my $root = "$a{namew}_ROOT";
+                my $root = "$a{aname}_ROOT";
                 print OUT "    <$root>$NGS_SDK_PREFIX\/</$root>\n";
                 last;
             }
@@ -786,12 +984,20 @@ EndText
         open COUT, ">$out" or die "cannot open $out to write";
         print COUT "### AUTO-GENERATED FILE ###\n";
         print COUT "\n";
-        print COUT "OS_ARCH = \$(shell perl \$(TOP)/os-arch.perl)\n";
+        print COUT "OS_ARCH = \$(shell perl \$(TOP)/setup/os-arch.perl)\n";
         print COUT "include \$(TOP)/$CONFIG_OUT/Makefile.config.\$(OS_ARCH)\n";
         close COUT;
     }
 }
 
+unless ($OPT{'reconfigure'}) {
+    println "configure: creating 'reconfigure'" unless ($AUTORUN);
+    $CONFIGURED =~ s/\t/ /g;
+    open my $F, '>reconfigure' or die 'cannot open reconfigure to write';
+    print $F "./configure $CONFIGURED\n";
+    close $F;
+}
+
 status() if ($OS ne 'win');
 
 unlink 'a.out';
@@ -817,8 +1023,11 @@ sub status {
                 $BUILD_TYPE = $1;
             } elsif (/BUILD \?= /) {
                 $BUILD_TYPE = $_ unless ($BUILD_TYPE);
-            }
-            elsif (/TARGDIR = /) {
+            } elsif (/BUILD_PREFIX = /) {
+                $BUILD_PREFIX = $_;
+            } elsif (/CONFIGURED = (.*)/) {
+                $CONFIGURED = $1;
+            } elsif (/TARGDIR = /) {
                 $TARGDIR = $_;
                 println "\t\tgot $_" if ($OPT{'debug'});
             } elsif (/TARGDIR \?= (.+)/) {
@@ -826,18 +1035,19 @@ sub status {
                 println "\t\tgot $_" if ($OPT{'debug'});
             }
             elsif (/INST_INCDIR = (.+)/) {
-                $OPT{includedir} = $1;
+                $OPT{'includedir'} = $1;
             }
             elsif (/INST_BINDIR = (.+)/) {
-                $OPT{bindir} = $1;
+                $OPT{'bindir'} = $1;
             }
             elsif (/INST_LIBDIR = (.+)/) {
-                $OPT{libdir} = $1;
+                $OPT{'libdir'} = $1;
             }
         }
     }
 
     println "build type: $BUILD_TYPE";
+    println "build prefix: $BUILD_PREFIX" if ($OS ne 'win');
     println "build output path: $TARGDIR" if ($OS ne 'win');
 
 #   print "prefix: ";    print $OPT{'prefix'} if ($OS ne 'win');    println;
@@ -860,13 +1070,24 @@ sub status {
     println "javadir: $OPT{'javadir'}" if ($OPT{'javadir'});
     println "pythondir: $OPT{'pythondir'}" if ($OPT{'pythondir'});
 
-    println;
+    $CONFIGURED =~ s/\t/ /g;
+    println "configured with: \"$CONFIGURED\"";
 }
 
-sub expand {
+sub expand { $_[0] =~ s/(\$\w+)/$1/eeg; $_[0]; }
+
+sub expand_path {
     my ($filename) = @_;
     return unless ($filename);
+
     if ($filename =~ /^~/) {
+        if ($filename =~ m|^~([^/]*)|) {
+            if ($1 && ! getpwnam($1)) {
+                print "configure: error: bad path: '$filename'\n";
+                exit 1;
+            }
+        }
+
         $filename =~ s{ ^ ~ ( [^/]* ) }
                       { $1
                             ? (getpwnam($1))[7]
@@ -875,6 +1096,7 @@ sub expand {
                               )
                       }ex;
     }
+
     my $a = abs_path($filename);
     $filename = $a if ($a);
     $filename;
@@ -882,34 +1104,33 @@ sub expand {
 
 sub find_in_dir {
     my ($dir, $include, $lib, $ilib) = @_;
-    print "\t$dir... " unless ($AUTORUN);
     unless (-d $dir) {
-        println "no" unless ($AUTORUN);
+#       println "no" unless ($AUTORUN);
         println "\t\tnot found $dir" if ($OPT{'debug'});
         return;
     }
-    print "[found] " if ($OPT{'debug'});
+#   print "\t$dir... " unless ($AUTORUN);
+#   print "[found] " if ($OPT{'debug'});
     my ($found_inc, $found_lib, $found_ilib);
-    my $nl = 1;
     if ($include) {
-        print "includes... " unless ($AUTORUN);
+        print "\tincludes... " unless ($AUTORUN);
         if (-e "$dir/$include") {
-            println 'yes' unless ($AUTORUN);
+            println $dir unless ($AUTORUN);
             $found_inc = $dir;
         } elsif (-e "$dir/include/$include") {
-            println 'yes' unless ($AUTORUN);
+            println $dir unless ($AUTORUN);
             $found_inc = "$dir/include";
         } elsif (-e "$dir/interfaces/$include") {
-            println 'yes' unless ($AUTORUN);
+            println $dir unless ($AUTORUN);
             $found_inc = "$dir/interfaces";
         } else {
+            print "$dir: " if ($OPT{'debug'});
             println 'no' unless ($AUTORUN);
         }
-        $nl = 0;
     }
     if ($lib || $ilib) {
-        print "\n\t" if ($nl && !$AUTORUN);
-        print "libraries... " unless ($AUTORUN);
+#       print "\n\t" if ($nl && !$AUTORUN);
+        print "\tlibraries... " unless ($AUTORUN);
         if ($lib) {
             my $builddir = File::Spec->catdir($dir, $OS, $TOOLS, $ARCH, $BUILD);
             my $libdir  = File::Spec->catdir($builddir, 'lib');
@@ -923,14 +1144,14 @@ sub find_in_dir {
                     my $f = File::Spec->catdir($ilibdir, $ilib);
                     print "\tchecking $f\n\t" if ($OPT{'debug'});
                     if (-e $f) {
-                        println 'yes';
+                        println $ilibdir;
                         $found_ilib = $ilibdir;
                     } else {
                         println 'no' unless ($AUTORUN);
                         return;
                     }
                 } else {
-                    println 'yes';
+                    println $libdir;
                 }
                 ++$found;
             }
@@ -939,7 +1160,7 @@ sub find_in_dir {
                 my $f = File::Spec->catdir($libdir, $lib);
                 print "\tchecking $f\n\t" if ($OPT{'debug'});
                 if (-e $f) {
-                    println 'yes';
+                    println $libdir;
                     $found_lib = $libdir;
                     ++$found;
                 }
@@ -957,16 +1178,18 @@ sub find_in_dir {
                         my $f = File::Spec->catdir($ilibdir, $ilib);
                         print "\tchecking $f\n\t" if ($OPT{'debug'});
                         if (-e $f) {
-                            println 'yes';
+                            println $ilibdir;
                             $found_ilib = $ilibdir;
                         } else {
                             println 'no' unless ($AUTORUN);
                             return;
                         }
                     } else {
-                        println 'yes';
+                        println $libdir;
                     }
                     ++$found;
+                } else {
+                    println 'no' unless ($AUTORUN);
                 }
             }
         }
@@ -976,7 +1199,6 @@ sub find_in_dir {
             println 'no' unless ($AUTORUN);
             undef $found_lib;
         }
-        ++$nl;
     }
     return ($found_inc, $found_lib, $found_ilib);
 }
@@ -994,38 +1216,90 @@ sub reverse_build {
 
 ################################################################################
 
+sub check_tool {
+    my ($tool) = @_;
+    print "checking for $tool... ";
+    my $cmd = "$tool --help";
+    print "\n\t\trunning $cmd\n\t" if ($OPT{'debug'});
+    my $out = `$cmd 2>&1`;
+    if ($? == 0) {
+        println "yes";
+        return 1;
+    } else {
+        println "no";
+        return 0;
+    }
+}
+
+sub check_no_array_bounds {
+    check_compiler('O', '-Wno-array-bounds');
+}
+
 sub find_lib {
-    my ($n, $i, $l) = @_;
+    check_compiler('L', @_);
+}
 
-    print "checking for $n library... ";
+sub check_compiler {
+    my ($t, $n, $i, $l) = @_;
+    my $tool = $TOOLS;
+
+    if ($t eq 'L') {
+        print "checking for $n library... ";
+    } elsif ($t eq 'O') {
+        if ($tool && $tool eq 'gcc') {
+            print "checking whether gcc accepts $n... ";
+        } else {
+            return;
+        }
+    } else {
+        die "Unknown check_compiler option: '$t'";
+    }
+
+    unless ($tool) {
+        println "warning: unknown tool";
+        return;
+    }
 
     while (1) {
-        my ($library, $log);
+        my ($flags, $library, $log) = ('', '');
 
-        if ($n eq 'hdf5') {
+        if ($t eq 'O') {
+            $flags = $n;
+            $log = '                      int main() {                     }\n'
+        } elsif ($n eq 'hdf5') {
             $library = '-lhdf5';
-            $log = '#include <hdf5.h>            \n main() { H5close     (); }';
-        } elsif ($n eq 'xml2') {
-            $library = '-lxml2';
-            $log = '#include <libxml/xmlreader.h>\n main() { xmlInitParser();}';
+            $log = '#include <hdf5.h>  \n int main() { H5close         (); }\n'
+        } elsif ($n eq 'fuse') {
+            $flags = '-D_FILE_OFFSET_BITS=64';
+            $library = '-lfuse';
+            $log = '#include <fuse.h>  \n int main() { fuse_get_context(); }\n'
         } elsif ($n eq 'magic') {
             $library = '-lmagic';
-            $log = '#include <magic.h>           \n main() { magic_open (0); }';
+            $log = '#include <magic.h> \n int main() { magic_open     (0); }\n'
+        } elsif ($n eq 'xml2') {
+            $library = '-lxml2';
+            $log = '#include <libxml/xmlreader.h>\n' .
+                                         'int main() { xmlInitParser  ( ); }\n'
         } else {
             println 'unknown: skipped';
             return;
         }
 
-        if (($i && ! -d $i) || ($l && ! -d $l)) {
+        if ($i && ! -d $i) {
+            print "'$i': " if ($OPT{'debug'});
             println 'no';
             return;
         }
+        if ($l && ! -d $l) {
+            print "'$l': " if ($OPT{'debug'});            println 'no';
+            return;
+        }
 
         my $cmd = $log;
         $cmd =~ s/\\n/\n/g;
 
-        my $gcc = "| gcc -xc " . ($i ? "-I$i " : ' ')
-                               . ($l ? "-L$l " : ' ') . "- $library";
+        my $gcc = "| $tool -xc $flags " . ($i ? "-I$i " : ' ')
+                                      . ($l ? "-L$l " : ' ') . "- $library";
         $gcc .= ' 2> /dev/null' unless ($OPT{'debug'});
 
         open GCC, $gcc or last;
@@ -1039,6 +1313,8 @@ sub find_lib {
 
         return if (!$ok);
 
+        return 1 if ($t eq 'O');
+
         return ($i, $l);
     }
 
@@ -1057,36 +1333,47 @@ sub check {
 
     my %PKG = PKG();
 
-    die "No LNG"   unless $PKG{LNG};
-    die "No OUT"   unless $PKG{OUT};
-    die "No PATH"  unless $PKG{PATH};
-    die "No UPATH" unless $PKG{UPATH};
+    die "No LNG"    unless $PKG{LNG};
+    die "No LOCOUT" unless $PKG{LOCOUT};
+    die "No OUT"    unless $PKG{OUT};
+    die "No PATH"   unless $PKG{PATH};
+    die "No UPATH"  unless $PKG{UPATH};
 
     foreach my $href (DEPENDS()) { die "No DEPENDS::name" unless $href->{name} }
 
     foreach my $href (REQ()) {
-        die "No REQ::name" unless $href->{name};
-
-        my $origin = $href->{origin};
-        die  "No $href->{name}:origin"  unless $origin;
-        die  "No $href->{name}:include" unless $href->{include};
-        die  "No $href->{name}:lib"     unless $href->{lib};
-        die  "No $href->{name}:option"  unless $href->{option};
-        die  "No $href->{name}:pkgpath" unless $href->{pkgpath};
-        die  "No $href->{name}:type"    unless $href->{type};
-        die  "No $href->{name}:usrpath" unless $href->{usrpath};
-        if ($origin eq 'I') {
-         die "No $href->{name}:bldpath" unless $href->{bldpath};
-         die "No $href->{name}:ilib"    unless $href->{ilib};
-         die "No $href->{name}:namew"   unless $href->{namew};
-         die "No $href->{name}:srcpath" unless $href->{srcpath};
+        die         "No REQ::name" unless $href->{name};
+
+        die         "No $href->{name}:option"  unless $href->{option};
+
+        die         "No $href->{name}:type"    unless $href->{type};
+        unless ($href->{type} =~ /I/) {
+            die     "No $href->{name}:lib"     unless $href->{lib};
+            die     "No $href->{name}:pkgpath" unless $href->{pkgpath};
+            die     "No $href->{name}:usrpath" unless $href->{usrpath};
+        }
+
+        die         "No $href->{name}:origin"  unless $href->{origin};
+        if ($href->{origin} eq 'I') {
+            die     "No $href->{name}:aname"   unless $href->{aname};
+            unless ($href->{type} =~ /D/) {
+                die "No $href->{name}:include" unless $href->{include};
+                die "No $href->{name}:srcpath" unless $href->{srcpath};
+            }
+            unless ($href->{type} =~ /I/) {
+                die "No $href->{name}:bldpath"    unless $href->{bldpath   };
+                die "No $href->{name}:locbldpath" unless $href->{locbldpath};
+            }
+            if ($href->{type} =~ /B/) {
+                die "No $href->{name}:ilib"    unless $href->{ilib};
+            }
         }
     }
 }
 
 ################################################################################
 
-sub optional { $_[0] =~ /^[LS]I$/ }
+sub optional { $_[0] =~ /O/ }
 
 sub help {
 #  --prefix=PREFIX         install architecture-independent files in PREFIX
@@ -1123,10 +1410,14 @@ EndText
     
         if (PACKAGE_TYPE() eq 'B') {
             print "\`$package_default_prefix/bin', ";
-        } else {
+        } elsif (PACKAGE_TYPE() eq 'L') {
             print "\`$package_default_prefix/include', ";
         }
-        println "\`$package_default_prefix/lib' etc.";
+        if (PACKAGE_TYPE() eq 'P') {
+            println "\`$package_default_prefix/share' etc.";
+        } else {
+            println "\`$package_default_prefix/lib' etc.";
+        }
 
         print <<EndText;
 You can specify an installation prefix other than \`$package_default_prefix'
@@ -1184,27 +1475,50 @@ EndText
         println;
     }
 
-    print <<EndText if ($^O ne 'MSWin32');
+    print <<EndText if (PACKAGE_TYPE() eq 'B');
+Optional Features:
+  --enable-static         build static executable [default=no]
+
+EndText
+
+    my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
+
+    if ($^O ne 'MSWin32') {
+        print <<EndText;
 Build tuning:
   --with-debug
   --without-debug
-  --arch=name             specify the name of the target architecture
+EndText
 
-  --build=DIR             generate build output into DIR directory
+        if (@ARCHITECTURES) {
+            print
+"  --arch=name             specify the name of the target architecture\n";
+        }
+
+        print <<EndText;
+
+  --build-prefix=DIR      generate build output into DIR directory
                           [$OUTDIR]
 
 EndText
+    }
 
-    println "Miscellaneous:";
+    println 'Miscellaneous:';
+    println '  --reconfigure           rerun `configure\'';
+    println '                          using the same command-line arguments';
     if ($^O ne 'MSWin32') {
         println
-            "  --status                print current configuration information"
+            '  --status                print current configuration information'
     }
-    println "  --clean                 remove all configuration results";
-    println "  --debug                 print lots of debugging information";
-    println;
+    print <<EndText;
+  --clean                 remove all configuration results
+  --debug                 print lots of debugging information
+
+If `configure' was arleady run running `configure' without options
+will rerun `configure' using the same command-line arguments.
+
+Report bugs to sra-tools\@ncbi.nlm.nih.gov
+EndText
 }
 
-=pod
 ################################################################################
-=cut
diff --git a/ngs-python/configure b/ngs-sdk/setup/ngs-c++/install
similarity index 82%
copy from ngs-python/configure
copy to ngs-sdk/setup/ngs-c++/install
index 3313aac..b1e201d 100755
--- a/ngs-python/configure
+++ b/ngs-sdk/setup/ngs-c++/install
@@ -29,17 +29,17 @@ CURDIR="`dirname $0`"
 
 if [ -z "$CURDIR" ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
     exit 1
 fi
 
-if [ "$FILENAME" != configure -a ! -s konfigure.perl ]
+if [ "$FILENAME" != install -a ! -s setup/install.perl ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
 else
     perl -v > /dev/null 2>&1 || { echo "checking for perl... no"; \
-        echo >&2 "configure: error: perl not found."; exit 1; }
+        echo >&2 "error: perl not found."; exit 1; }
 
-    cd $CURDIR
-    perl -w ./konfigure.perl $@
+    cd $CURDIR/setup
+    perl -w ./install.perl "$@"
 fi
diff --git a/ngs-sdk/setup/ngs-c++/install.prl b/ngs-sdk/setup/ngs-c++/install.prl
new file mode 100644
index 0000000..422feec
--- /dev/null
+++ b/ngs-sdk/setup/ngs-c++/install.prl
@@ -0,0 +1,5 @@
+sub PACKAGE_NAME { 'NGS-C++' }
+sub HAVE        { ( EXAMPLES => 1, LIBS => 1, USR_INCLUDES => 1, ) }
+sub INCLUDES    { 'ngs' }
+sub LIBS        {       }
+1
diff --git a/ngs-sdk/setup/ngs-c++/linux/os.prl b/ngs-sdk/setup/ngs-c++/linux/os.prl
new file mode 100644
index 0000000..5f75471
--- /dev/null
+++ b/ngs-sdk/setup/ngs-c++/linux/os.prl
@@ -0,0 +1,2 @@
+sub OS { 'linux' }
+1
diff --git a/ngs-sdk/setup/ngs-c++/mac/os.prl b/ngs-sdk/setup/ngs-c++/mac/os.prl
new file mode 100644
index 0000000..b962c57
--- /dev/null
+++ b/ngs-sdk/setup/ngs-c++/mac/os.prl
@@ -0,0 +1,2 @@
+sub OS { 'mac' }
+1
diff --git a/ngs-python/configure b/ngs-sdk/setup/ngs-engine-dev/install
similarity index 82%
copy from ngs-python/configure
copy to ngs-sdk/setup/ngs-engine-dev/install
index 3313aac..b1e201d 100755
--- a/ngs-python/configure
+++ b/ngs-sdk/setup/ngs-engine-dev/install
@@ -29,17 +29,17 @@ CURDIR="`dirname $0`"
 
 if [ -z "$CURDIR" ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
     exit 1
 fi
 
-if [ "$FILENAME" != configure -a ! -s konfigure.perl ]
+if [ "$FILENAME" != install -a ! -s setup/install.perl ]
     then
-    echo configure: error: configure should be run as ./configure
+    echo error: install should be run as ./install
 else
     perl -v > /dev/null 2>&1 || { echo "checking for perl... no"; \
-        echo >&2 "configure: error: perl not found."; exit 1; }
+        echo >&2 "error: perl not found."; exit 1; }
 
-    cd $CURDIR
-    perl -w ./konfigure.perl $@
+    cd $CURDIR/setup
+    perl -w ./install.perl "$@"
 fi
diff --git a/ngs-sdk/setup/ngs-engine-dev/install.prl b/ngs-sdk/setup/ngs-engine-dev/install.prl
new file mode 100644
index 0000000..10aac14
--- /dev/null
+++ b/ngs-sdk/setup/ngs-engine-dev/install.prl
@@ -0,0 +1,5 @@
+sub PACKAGE_NAME { 'NGS-ENGINE-DEV' }
+sub HAVE        { ( LIBS => 1, USR_INCLUDES => 1, ) }
+sub INCLUDES    {  'ngs' }
+sub LIBS        {        }
+1
diff --git a/ngs-sdk/setup/ngs-engine-dev/linux/os.prl b/ngs-sdk/setup/ngs-engine-dev/linux/os.prl
new file mode 100644
index 0000000..5f75471
--- /dev/null
+++ b/ngs-sdk/setup/ngs-engine-dev/linux/os.prl
@@ -0,0 +1,2 @@
+sub OS { 'linux' }
+1
diff --git a/ngs-sdk/setup/ngs-engine-dev/mac/os.prl b/ngs-sdk/setup/ngs-engine-dev/mac/os.prl
new file mode 100644
index 0000000..b962c57
--- /dev/null
+++ b/ngs-sdk/setup/ngs-engine-dev/mac/os.prl
@@ -0,0 +1,2 @@
+sub OS { 'mac' }
+1
diff --git a/ngs-java/os-arch.perl b/ngs-sdk/setup/os-arch.perl
similarity index 80%
rename from ngs-java/os-arch.perl
rename to ngs-sdk/setup/os-arch.perl
index a7b4990..5f3f87a 100644
--- a/ngs-java/os-arch.perl
+++ b/ngs-sdk/setup/os-arch.perl
@@ -1,14 +1,14 @@
 use strict;
 
 use FindBin qw($Bin);
-require "$Bin/os-arch.pm";
+require "$Bin/os-arch.prl";
 
 my ($OS, $ARCH, $OSTYPE, $MARCH, @ARCHITECTURES) = OsArch();
 
 my $res = "$OS.$ARCH";
 
 if (@ARCHITECTURES) {
-    my $name = "$Bin/Makefile.config.$OS.arch";
+    my $name = "$Bin/../Makefile.config.$OS.arch";
     if (-e $name) {
         while (1) {
             open F, $name or last;
diff --git a/ngs-java/os-arch.pm b/ngs-sdk/setup/os-arch.prl
similarity index 95%
rename from ngs-java/os-arch.pm
rename to ngs-sdk/setup/os-arch.prl
index 6fbd606..791b556 100644
--- a/ngs-java/os-arch.pm
+++ b/ngs-sdk/setup/os-arch.prl
@@ -18,6 +18,8 @@ sub OsArch {
             $HOST_OS = 'win';
         } elsif ($UNAME =~ /xMINGW/) {
             $HOST_OS = 'win';
+        } else {
+            $HOST_OS = $UNAME;
         }
         if ($HOST_OS eq 'mac') {
             $MARCH = $HOST_ARCH = MacArch();
@@ -50,7 +52,9 @@ sub OsArch {
                 @ARCHITECTURES = qw(x86_64 i386);
             } elsif ($MARCH =~ /sun4v/) {
                 $HOST_ARCH = 'sparc64';
-		        @ARCHITECTURES = qw(sparc64 sparc32);
+                @ARCHITECTURES = qw(sparc64 sparc32);
+            } else {
+                $HOST_ARCH = $MARCH;
             }
         }
     }
diff --git a/ngs-sdk/package.pm b/ngs-sdk/setup/package.prl
similarity index 86%
rename from ngs-sdk/package.pm
rename to ngs-sdk/setup/package.prl
index 025a876..e27b5a0 100644
--- a/ngs-sdk/package.pm
+++ b/ngs-sdk/setup/package.prl
@@ -1,6 +1,6 @@
 ################################################################################
 sub PACKAGE      { 'ngs-sdk' }
-sub VERSION      { '1.0.0' }
+sub VERSION      { '1.0.1' }
 sub PACKAGE_TYPE { 'L' }
 sub PACKAGE_NAME { 'NGS-SDK' }
 sub PACKAGE_NAMW { 'NGS' }
@@ -8,6 +8,7 @@ sub DEPENDS      {}
 sub CONFIG_OUT   { '.' }
 sub PKG { ( LNG   => 'C',
             OUT   => 'ncbi-outdir',
+            LOCOUT=> '../../../OUTDIR',
             PATH  => '/usr/local/ngs/ngs-sdk',
             UPATH =>      '$HOME/ngs/ngs-sdk',
             EXAMP => '1' ) }
diff --git a/ngs-sdk/test/test_engine/AlignmentItf.hpp b/ngs-sdk/test/test_engine/AlignmentItf.hpp
index 9612843..a2bc5e6 100644
--- a/ngs-sdk/test/test_engine/AlignmentItf.hpp
+++ b/ngs-sdk/test/test_engine/AlignmentItf.hpp
@@ -161,6 +161,11 @@ namespace ngs_test_engine
             return new ngs_adapt::StringItf( cigar.c_str(), cigar.size() ); 
         }
 
+        virtual char getRNAOrientation () const 
+        { 
+            return '+'; 
+        }
+
         virtual bool hasMate () const 
         { 
             return true; 
@@ -221,7 +226,7 @@ namespace ngs_test_engine
             --instanceCount;
         }
 
-        static NGS_EXTERN  unsigned int instanceCount;
+        static   unsigned int instanceCount;
 
         std::string id;
         int iterateFor;
diff --git a/ngs-sdk/test/test_engine/PileupEventItf.hpp b/ngs-sdk/test/test_engine/PileupEventItf.hpp
index 06411a1..e4d1449 100644
--- a/ngs-sdk/test/test_engine/PileupEventItf.hpp
+++ b/ngs-sdk/test/test_engine/PileupEventItf.hpp
@@ -139,7 +139,7 @@ namespace ngs_test_engine
             --instanceCount;
         }
 
-        static NGS_EXTERN  unsigned int instanceCount;
+        static   unsigned int instanceCount;
 
         unsigned int iterateFor;
     };
diff --git a/ngs-sdk/test/test_engine/PileupItf.hpp b/ngs-sdk/test/test_engine/PileupItf.hpp
index e69891a..b5aecbe 100644
--- a/ngs-sdk/test/test_engine/PileupItf.hpp
+++ b/ngs-sdk/test/test_engine/PileupItf.hpp
@@ -90,7 +90,7 @@ namespace ngs_test_engine
             --instanceCount;
         }
 
-        static NGS_EXTERN  unsigned int instanceCount;
+        static   unsigned int instanceCount;
 
         unsigned int iterateFor;
     };
diff --git a/ngs-sdk/test/test_engine/ReadCollectionItf.hpp b/ngs-sdk/test/test_engine/ReadCollectionItf.hpp
index 59020b6..3bb9f8a 100644
--- a/ngs-sdk/test/test_engine/ReadCollectionItf.hpp
+++ b/ngs-sdk/test/test_engine/ReadCollectionItf.hpp
@@ -126,7 +126,7 @@ namespace ngs_test_engine
             --instanceCount;
         }
 
-        static NGS_EXTERN  unsigned int instanceCount;
+        static   unsigned int instanceCount;
 
     private:
         std::string name;
diff --git a/ngs-sdk/test/test_engine/ReadGroupItf.hpp b/ngs-sdk/test/test_engine/ReadGroupItf.hpp
index 5a3a479..a80038d 100644
--- a/ngs-sdk/test/test_engine/ReadGroupItf.hpp
+++ b/ngs-sdk/test/test_engine/ReadGroupItf.hpp
@@ -85,7 +85,7 @@ namespace ngs_test_engine
             --instanceCount;
         }
 
-        static NGS_EXTERN  unsigned int instanceCount;
+        static   unsigned int instanceCount;
 
         int iterateFor;
     };
diff --git a/ngs-sdk/test/test_engine/ReadItf.hpp b/ngs-sdk/test/test_engine/ReadItf.hpp
index fe04c2d..aa03f10 100644
--- a/ngs-sdk/test/test_engine/ReadItf.hpp
+++ b/ngs-sdk/test/test_engine/ReadItf.hpp
@@ -157,7 +157,7 @@ namespace ngs_test_engine
             --instanceCount;
         }
 
-        static NGS_EXTERN  unsigned int instanceCount;
+        static   unsigned int instanceCount;
 
         std::string id;
         int iterateFor;
diff --git a/ngs-sdk/test/test_engine/ReferenceItf.hpp b/ngs-sdk/test/test_engine/ReferenceItf.hpp
index a2a1afe..f5a9a97 100644
--- a/ngs-sdk/test/test_engine/ReferenceItf.hpp
+++ b/ngs-sdk/test/test_engine/ReferenceItf.hpp
@@ -134,7 +134,7 @@ namespace ngs_test_engine
             --instanceCount;
         }
 
-        static NGS_EXTERN  unsigned int instanceCount;
+        static   unsigned int instanceCount;
 
         int iterateFor;
     };
diff --git a/ngs-sdk/test/test_engine/StatisticsItf.hpp b/ngs-sdk/test/test_engine/StatisticsItf.hpp
index d925a00..44d3781 100644
--- a/ngs-sdk/test/test_engine/StatisticsItf.hpp
+++ b/ngs-sdk/test/test_engine/StatisticsItf.hpp
@@ -84,7 +84,7 @@ namespace ngs_test_engine
             --instanceCount;
         }
 
-        static NGS_EXTERN  unsigned int instanceCount;
+        static   unsigned int instanceCount;
     };
 
 } // namespace ngs_test_engine
diff --git a/ngs-sdk/test/test_engine/test_engine.cpp b/ngs-sdk/test/test_engine/test_engine.cpp
index 5da028d..06a7800 100644
--- a/ngs-sdk/test/test_engine/test_engine.cpp
+++ b/ngs-sdk/test/test_engine/test_engine.cpp
@@ -35,19 +35,19 @@
 #include "PileupItf.hpp"
 #include "PileupEventItf.hpp"
 
-NGS_EXTERN  unsigned int ngs_test_engine::ReadCollectionItf::instanceCount = 0;
-NGS_EXTERN  unsigned int ngs_test_engine::ReadGroupItf::instanceCount = 0;
-NGS_EXTERN  unsigned int ngs_test_engine::ReferenceItf::instanceCount = 0;
-NGS_EXTERN  unsigned int ngs_test_engine::AlignmentItf::instanceCount = 0;
-NGS_EXTERN  unsigned int ngs_test_engine::ReadItf::instanceCount = 0;
-NGS_EXTERN  unsigned int ngs_test_engine::StatisticsItf::instanceCount = 0;
-NGS_EXTERN  unsigned int ngs_test_engine::PileupItf::instanceCount = 0;
-NGS_EXTERN  unsigned int ngs_test_engine::PileupEventItf::instanceCount = 0;
+  unsigned int ngs_test_engine::ReadCollectionItf::instanceCount = 0;
+  unsigned int ngs_test_engine::ReadGroupItf::instanceCount = 0;
+  unsigned int ngs_test_engine::ReferenceItf::instanceCount = 0;
+  unsigned int ngs_test_engine::AlignmentItf::instanceCount = 0;
+  unsigned int ngs_test_engine::ReadItf::instanceCount = 0;
+  unsigned int ngs_test_engine::StatisticsItf::instanceCount = 0;
+  unsigned int ngs_test_engine::PileupItf::instanceCount = 0;
+  unsigned int ngs_test_engine::PileupEventItf::instanceCount = 0;
 
 namespace ngs_test_engine
 {
 
-	NGS_EXTERN  ngs::ReadCollection NGS::openReadCollection ( const String & spec ) throw ( ErrorMsg )
+	  ngs::ReadCollection NGS::openReadCollection ( const String & spec ) throw ( ErrorMsg )
 	{
         ngs_adapt::ReadCollectionItf * ad_itf = new ngs_test_engine::ReadCollectionItf ( spec . c_str () );
         NGS_ReadCollection_v1 * c_obj = ad_itf -> Cast ();
diff --git a/ngs-sdk/test/test_engine/test_engine.hpp b/ngs-sdk/test/test_engine/test_engine.hpp
index d5a3f5d..e8097b2 100644
--- a/ngs-sdk/test/test_engine/test_engine.hpp
+++ b/ngs-sdk/test/test_engine/test_engine.hpp
@@ -42,7 +42,7 @@ namespace ngs_test_engine
          *  "spec" may be a path to an object
          *  or may be an id, accession, or URL
          */
-        static NGS_EXTERN ReadCollection openReadCollection ( const String & spec ) throw ( ErrorMsg );
+        static  ReadCollection openReadCollection ( const String & spec ) throw ( ErrorMsg );
     };
 
 } // namespace ngs_test_engine
diff --git a/ngs-sdk/win-configure.bat b/ngs-sdk/win-configure.bat
deleted file mode 100644
index 7b35820..0000000
--- a/ngs-sdk/win-configure.bat
+++ /dev/null
@@ -1,2 +0,0 @@
-perl -w ./konfigure.perl %*
-
diff --git a/ngs-sdk/win/lib-project.props b/ngs-sdk/win/lib-project.props
new file mode 100644
index 0000000..d5834bf
--- /dev/null
+++ b/ngs-sdk/win/lib-project.props
@@ -0,0 +1,13 @@
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  
+
+    <Import Project="ngs-common.props" />
+  
+    <PropertyGroup Label="Configuration">
+        <ConfigurationType>StaticLibrary</ConfigurationType>
+        <TargetExt>.lib</TargetExt>
+        <OutDir>$(NGS_TARGET)\lib\</OutDir>
+    </PropertyGroup>
+    
+    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+    
+</Project>
\ No newline at end of file
diff --git a/ngs-sdk/win/libadapter.vcxproj b/ngs-sdk/win/libadapter.vcxproj
index 93f7715..ac7167d 100644
--- a/ngs-sdk/win/libadapter.vcxproj
+++ b/ngs-sdk/win/libadapter.vcxproj
@@ -18,176 +18,45 @@
       <Platform>x64</Platform>
     </ProjectConfiguration>
   </ItemGroup>
-
-  <Import Project="ngs-common.props" />
   
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{B9096FEF-5B55-4308-A81F-3B52CA968BE9}</ProjectGuid>
-    <RootNamespace>libadapter</RootNamespace>
-    <ProjectName>ngs-adapt-c++</ProjectName>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <OutDir>$(NGS_TARGET)\lib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetExt>.lib</TargetExt>
-    <TargetName>lib$(ProjectName)</TargetName>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <OutDir>$(NGS_TARGET)\lib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetExt>.lib</TargetExt>
-    <TargetName>lib$(ProjectName)</TargetName>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <OutDir>$(NGS_TARGET)\lib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetExt>.lib</TargetExt>
-    <TargetName>lib$(ProjectName)</TargetName>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <OutDir>$(NGS_TARGET)\lib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetExt>.lib</TargetExt>
-    <TargetName>lib$(ProjectName)</TargetName>
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <DisableSpecificWarnings>4251;</DisableSpecificWarnings>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <MinimalRebuild>true</MinimalRebuild>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <DisableSpecificWarnings>4251;</DisableSpecificWarnings>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <MinimalRebuild>true</MinimalRebuild>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClInclude Include="..\ngs\adapter\AlignmentItf.hpp" />
-    <ClInclude Include="..\ngs\adapter\defs.h" />
-    <ClInclude Include="..\ngs\adapter\ErrorMsg.hpp" />
-    <ClInclude Include="..\ngs\adapter\FragmentItf.hpp" />
-    <ClInclude Include="..\ngs\adapter\PileupEventItf.hpp" />
-    <ClInclude Include="..\ngs\adapter\PileupItf.hpp" />
-    <ClInclude Include="..\ngs\adapter\ReadCollectionItf.hpp" />
-    <ClInclude Include="..\ngs\adapter\ReadGroupItf.hpp" />
-    <ClInclude Include="..\ngs\adapter\ReadItf.hpp" />
-    <ClInclude Include="..\ngs\adapter\Refcount.hpp" />
-    <ClInclude Include="..\ngs\adapter\ReferenceItf.hpp" />
-    <ClInclude Include="..\ngs\adapter\StatisticsItf.hpp" />
-    <ClInclude Include="..\ngs\adapter\StringItf.hpp" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="..\adapter\AlignmentItf.cpp" />
-    <ClCompile Include="..\adapter\ErrBlock.cpp" />
-    <ClCompile Include="..\adapter\ErrorMsg.cpp" />
-    <ClCompile Include="..\adapter\FragmentItf.cpp" />
-    <ClCompile Include="..\adapter\PileupEventItf.cpp" />
-    <ClCompile Include="..\adapter\PileupItf.cpp" />
-    <ClCompile Include="..\adapter\ReadCollectionItf.cpp" />
-    <ClCompile Include="..\adapter\ReadGroupItf.cpp" />
-    <ClCompile Include="..\adapter\ReadItf.cpp" />
-    <ClCompile Include="..\adapter\Refcount.cpp" />
-    <ClCompile Include="..\adapter\ReferenceItf.cpp" />
-    <ClCompile Include="..\adapter\StatisticsItf.cpp" />
-    <ClCompile Include="..\adapter\StringItf.cpp" />
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+    <PropertyGroup Label="Globals">
+        <ProjectGuid>{B9096FEF-5B55-4308-A81F-3B52CA968BE9}</ProjectGuid>
+        <ProjectName>libngs-adapt-c++</ProjectName>
+    </PropertyGroup>
+    
+    <Import Project="lib-project.props" />
+  
+    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+    <ImportGroup Label="ExtensionTargets" />
+    
+    <ItemGroup>
+        <ClInclude Include="..\ngs\adapter\AlignmentItf.hpp" />
+        <ClInclude Include="..\ngs\adapter\defs.h" />
+        <ClInclude Include="..\ngs\adapter\ErrorMsg.hpp" />
+        <ClInclude Include="..\ngs\adapter\FragmentItf.hpp" />
+        <ClInclude Include="..\ngs\adapter\PileupEventItf.hpp" />
+        <ClInclude Include="..\ngs\adapter\PileupItf.hpp" />
+        <ClInclude Include="..\ngs\adapter\ReadCollectionItf.hpp" />
+        <ClInclude Include="..\ngs\adapter\ReadGroupItf.hpp" />
+        <ClInclude Include="..\ngs\adapter\ReadItf.hpp" />
+        <ClInclude Include="..\ngs\adapter\Refcount.hpp" />
+        <ClInclude Include="..\ngs\adapter\ReferenceItf.hpp" />
+        <ClInclude Include="..\ngs\adapter\StatisticsItf.hpp" />
+        <ClInclude Include="..\ngs\adapter\StringItf.hpp" />
+    </ItemGroup>
+    <ItemGroup>
+        <ClCompile Include="..\adapter\AlignmentItf.cpp" />
+        <ClCompile Include="..\adapter\ErrBlock.cpp" />
+        <ClCompile Include="..\adapter\ErrorMsg.cpp" />
+        <ClCompile Include="..\adapter\FragmentItf.cpp" />
+        <ClCompile Include="..\adapter\PileupEventItf.cpp" />
+        <ClCompile Include="..\adapter\PileupItf.cpp" />
+        <ClCompile Include="..\adapter\ReadCollectionItf.cpp" />
+        <ClCompile Include="..\adapter\ReadGroupItf.cpp" />
+        <ClCompile Include="..\adapter\ReadItf.cpp" />
+        <ClCompile Include="..\adapter\Refcount.cpp" />
+        <ClCompile Include="..\adapter\ReferenceItf.cpp" />
+        <ClCompile Include="..\adapter\StatisticsItf.cpp" />
+        <ClCompile Include="..\adapter\StringItf.cpp" />
+    </ItemGroup>
 </Project>
\ No newline at end of file
diff --git a/ngs-sdk/win/libdispatch.vcxproj b/ngs-sdk/win/libdispatch.vcxproj
index 0063877..e06ade2 100644
--- a/ngs-sdk/win/libdispatch.vcxproj
+++ b/ngs-sdk/win/libdispatch.vcxproj
@@ -18,190 +18,62 @@
       <Platform>x64</Platform>
     </ProjectConfiguration>
   </ItemGroup>
-
-  <Import Project="ngs-common.props" />
   
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{06FA485F-8AA9-4F3B-B1E3-D8CF1993637B}</ProjectGuid>
-    <RootNamespace>libdispatch</RootNamespace>
-    <ProjectName>ngs-disp</ProjectName>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <TargetExt>.lib</TargetExt>
-    <OutDir>$(NGS_TARGET)\ilib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetName>lib$(ProjectName)</TargetName>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <TargetExt>.lib</TargetExt>
-    <OutDir>$(NGS_TARGET)\ilib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetName>lib$(ProjectName)</TargetName>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <OutDir>$(NGS_TARGET)\ilib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetExt>.lib</TargetExt>
-    <TargetName>lib$(ProjectName)</TargetName>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <OutDir>$(NGS_TARGET)\ilib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetExt>.lib</TargetExt>
-    <TargetName>lib$(ProjectName)</TargetName>
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <DisableSpecificWarnings>4251;</DisableSpecificWarnings>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <MinimalRebuild>true</MinimalRebuild>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClInclude Include="..\ngs\itf\AlignmentItf.h" />
-    <ClInclude Include="..\ngs\itf\AlignmentItf.hpp" />
-    <ClInclude Include="..\ngs\itf\defs.h" />
-    <ClInclude Include="..\ngs\itf\ErrBlock.h" />
-    <ClInclude Include="..\ngs\itf\ErrBlock.hpp" />
-    <ClInclude Include="..\ngs\itf\ErrorMsg.hpp" />
-    <ClInclude Include="..\ngs\itf\FragmentItf.h" />
-    <ClInclude Include="..\ngs\itf\FragmentItf.hpp" />
-    <ClInclude Include="..\ngs\itf\PileupEventItf.h" />
-    <ClInclude Include="..\ngs\itf\PileupEventItf.hpp" />
-    <ClInclude Include="..\ngs\itf\PileupItf.h" />
-    <ClInclude Include="..\ngs\itf\PileupItf.hpp" />
-    <ClInclude Include="..\ngs\itf\ReadCollectionItf.h" />
-    <ClInclude Include="..\ngs\itf\ReadCollectionItf.hpp" />
-    <ClInclude Include="..\ngs\itf\ReadGroupItf.h" />
-    <ClInclude Include="..\ngs\itf\ReadGroupItf.hpp" />
-    <ClInclude Include="..\ngs\itf\ReadItf.h" />
-    <ClInclude Include="..\ngs\itf\ReadItf.hpp" />
-    <ClInclude Include="..\ngs\itf\Refcount.h" />
-    <ClInclude Include="..\ngs\itf\Refcount.hpp" />
-    <ClInclude Include="..\ngs\itf\ReferenceItf.h" />
-    <ClInclude Include="..\ngs\itf\ReferenceItf.hpp" />
-    <ClInclude Include="..\ngs\itf\StatisticsItf.h" />
-    <ClInclude Include="..\ngs\itf\StatisticsItf.hpp" />
-    <ClInclude Include="..\ngs\itf\StringItf.h" />
-    <ClInclude Include="..\ngs\itf\StringItf.hpp" />
-    <ClInclude Include="..\ngs\itf\VTable.h" />
-    <ClInclude Include="..\ngs\itf\VTable.hpp" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="..\dispatch\AlignmentItf.cpp" />
-    <ClCompile Include="..\dispatch\ErrBlock.cpp" />
-    <ClCompile Include="..\dispatch\ErrorMsg.cpp" />
-    <ClCompile Include="..\dispatch\FragmentItf.cpp" />
-    <ClCompile Include="..\dispatch\PileupEventItf.cpp" />
-    <ClCompile Include="..\dispatch\PileupItf.cpp" />
-    <ClCompile Include="..\dispatch\ReadCollectionItf.cpp" />
-    <ClCompile Include="..\dispatch\ReadGroupItf.cpp" />
-    <ClCompile Include="..\dispatch\ReadItf.cpp" />
-    <ClCompile Include="..\dispatch\Refcount.cpp" />
-    <ClCompile Include="..\dispatch\ReferenceItf.cpp" />
-    <ClCompile Include="..\dispatch\StatisticsItf.cpp" />
-    <ClCompile Include="..\dispatch\StringItf.cpp" />
-    <ClCompile Include="..\dispatch\VTable.cpp" />
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+    <PropertyGroup Label="Globals">
+        <ProjectGuid>{06FA485F-8AA9-4F3B-B1E3-D8CF1993637B}</ProjectGuid>
+        <ProjectName>libngs-disp</ProjectName>
+    </PropertyGroup>
+    
+    <Import Project="lib-project.props" />
+  
+    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+    <ImportGroup Label="ExtensionTargets" />
+  
+    <ItemGroup>
+        <ClInclude Include="..\ngs\itf\AlignmentItf.h" />
+        <ClInclude Include="..\ngs\itf\AlignmentItf.hpp" />
+        <ClInclude Include="..\ngs\itf\defs.h" />
+        <ClInclude Include="..\ngs\itf\ErrBlock.h" />
+        <ClInclude Include="..\ngs\itf\ErrBlock.hpp" />
+        <ClInclude Include="..\ngs\itf\ErrorMsg.hpp" />
+        <ClInclude Include="..\ngs\itf\FragmentItf.h" />
+        <ClInclude Include="..\ngs\itf\FragmentItf.hpp" />
+        <ClInclude Include="..\ngs\itf\PileupEventItf.h" />
+        <ClInclude Include="..\ngs\itf\PileupEventItf.hpp" />
+        <ClInclude Include="..\ngs\itf\PileupItf.h" />
+        <ClInclude Include="..\ngs\itf\PileupItf.hpp" />
+        <ClInclude Include="..\ngs\itf\ReadCollectionItf.h" />
+        <ClInclude Include="..\ngs\itf\ReadCollectionItf.hpp" />
+        <ClInclude Include="..\ngs\itf\ReadGroupItf.h" />
+        <ClInclude Include="..\ngs\itf\ReadGroupItf.hpp" />
+        <ClInclude Include="..\ngs\itf\ReadItf.h" />
+        <ClInclude Include="..\ngs\itf\ReadItf.hpp" />
+        <ClInclude Include="..\ngs\itf\Refcount.h" />
+        <ClInclude Include="..\ngs\itf\Refcount.hpp" />
+        <ClInclude Include="..\ngs\itf\ReferenceItf.h" />
+        <ClInclude Include="..\ngs\itf\ReferenceItf.hpp" />
+        <ClInclude Include="..\ngs\itf\StatisticsItf.h" />
+        <ClInclude Include="..\ngs\itf\StatisticsItf.hpp" />
+        <ClInclude Include="..\ngs\itf\StringItf.h" />
+        <ClInclude Include="..\ngs\itf\StringItf.hpp" />
+        <ClInclude Include="..\ngs\itf\VTable.h" />
+        <ClInclude Include="..\ngs\itf\VTable.hpp" />
+    </ItemGroup>
+    <ItemGroup>
+        <ClCompile Include="..\dispatch\AlignmentItf.cpp" />
+        <ClCompile Include="..\dispatch\ErrBlock.cpp" />
+        <ClCompile Include="..\dispatch\ErrorMsg.cpp" />
+        <ClCompile Include="..\dispatch\FragmentItf.cpp" />
+        <ClCompile Include="..\dispatch\PileupEventItf.cpp" />
+        <ClCompile Include="..\dispatch\PileupItf.cpp" />
+        <ClCompile Include="..\dispatch\ReadCollectionItf.cpp" />
+        <ClCompile Include="..\dispatch\ReadGroupItf.cpp" />
+        <ClCompile Include="..\dispatch\ReadItf.cpp" />
+        <ClCompile Include="..\dispatch\Refcount.cpp" />
+        <ClCompile Include="..\dispatch\ReferenceItf.cpp" />
+        <ClCompile Include="..\dispatch\StatisticsItf.cpp" />
+        <ClCompile Include="..\dispatch\StringItf.cpp" />
+        <ClCompile Include="..\dispatch\VTable.cpp" />
+    </ItemGroup>
+  
 </Project>
\ No newline at end of file
diff --git a/ngs-sdk/win/libngs-c++.vcxproj b/ngs-sdk/win/libngs-c++.vcxproj
index 0ffdd0e..bfef61e 100644
--- a/ngs-sdk/win/libngs-c++.vcxproj
+++ b/ngs-sdk/win/libngs-c++.vcxproj
@@ -18,162 +18,35 @@
       <Platform>x64</Platform>
     </ProjectConfiguration>
   </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="..\language\c++\Alignment.cpp" />
-    <ClCompile Include="..\language\c++\AlignmentIterator.cpp" />
-    <ClCompile Include="..\language\c++\Fragment.cpp" />
-    <ClCompile Include="..\language\c++\FragmentIterator.cpp" />
-    <ClCompile Include="..\language\c++\Pileup.cpp" />
-    <ClCompile Include="..\language\c++\PileupEvent.cpp" />
-    <ClCompile Include="..\language\c++\PileupEventIterator.cpp" />
-    <ClCompile Include="..\language\c++\PileupIterator.cpp" />
-    <ClCompile Include="..\language\c++\Read.cpp" />
-    <ClCompile Include="..\language\c++\ReadCollection.cpp" />
-    <ClCompile Include="..\language\c++\ReadGroup.cpp" />
-    <ClCompile Include="..\language\c++\ReadGroupIterator.cpp" />
-    <ClCompile Include="..\language\c++\ReadIterator.cpp" />
-    <ClCompile Include="..\language\c++\Reference.cpp" />
-    <ClCompile Include="..\language\c++\ReferenceIterator.cpp" />
-    <ClCompile Include="..\language\c++\Statistics.cpp" />
-    <ClCompile Include="..\language\c++\StringRef.cpp" />
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{A8AC88D2-FADA-4458-A251-DB2E039678A4}</ProjectGuid>
-    <RootNamespace>libngsc</RootNamespace>
-    <NGS_OUTDIR>$(USERPROFILE)\win\cl\</NGS_OUTDIR>
-    <NGS_TARGET>$(NGS_OUTDIR)\$(Platform)\$(Configuration)\</NGS_TARGET>
-    <ProjectName>ngs-bind-c++</ProjectName>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <TargetExt>.lib</TargetExt>
-    <OutDir>$(NGS_TARGET)\ilib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetName>lib$(ProjectName)</TargetName>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <TargetExt>.lib</TargetExt>
-    <OutDir>$(NGS_TARGET)\ilib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetName>lib$(ProjectName)</TargetName>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <TargetExt>.lib</TargetExt>
-    <OutDir>$(NGS_TARGET)\ilib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetName>lib$(ProjectName)</TargetName>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <TargetExt>.lib</TargetExt>
-    <OutDir>$(NGS_TARGET)\ilib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetName>lib$(ProjectName)</TargetName>
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-    </Link>
-  </ItemDefinitionGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+  
+    <PropertyGroup Label="Globals">
+        <ProjectGuid>{A8AC88D2-FADA-4458-A251-DB2E039678A4}</ProjectGuid>
+        <ProjectName>libngs-bind-c++</ProjectName>
+    </PropertyGroup>
+    
+   <Import Project="lib-project.props" />
+  
+    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+    <ImportGroup Label="ExtensionTargets" />
+
+    <ItemGroup>
+        <ClCompile Include="..\language\c++\Alignment.cpp" />
+        <ClCompile Include="..\language\c++\AlignmentIterator.cpp" />
+        <ClCompile Include="..\language\c++\Fragment.cpp" />
+        <ClCompile Include="..\language\c++\FragmentIterator.cpp" />
+        <ClCompile Include="..\language\c++\Pileup.cpp" />
+        <ClCompile Include="..\language\c++\PileupEvent.cpp" />
+        <ClCompile Include="..\language\c++\PileupEventIterator.cpp" />
+        <ClCompile Include="..\language\c++\PileupIterator.cpp" />
+        <ClCompile Include="..\language\c++\Read.cpp" />
+        <ClCompile Include="..\language\c++\ReadCollection.cpp" />
+        <ClCompile Include="..\language\c++\ReadGroup.cpp" />
+        <ClCompile Include="..\language\c++\ReadGroupIterator.cpp" />
+        <ClCompile Include="..\language\c++\ReadIterator.cpp" />
+        <ClCompile Include="..\language\c++\Reference.cpp" />
+        <ClCompile Include="..\language\c++\ReferenceIterator.cpp" />
+        <ClCompile Include="..\language\c++\Statistics.cpp" />
+        <ClCompile Include="..\language\c++\StringRef.cpp" />
+    </ItemGroup>
+  
 </Project>
\ No newline at end of file
diff --git a/ngs-sdk/win/libngs.vcxproj b/ngs-sdk/win/libngs.vcxproj
deleted file mode 100644
index c6b120f..0000000
--- a/ngs-sdk/win/libngs.vcxproj
+++ /dev/null
@@ -1,187 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Debug|x64">
-      <Configuration>Debug</Configuration>
-      <Platform>x64</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|Win32">
-      <Configuration>Release</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|x64">
-      <Configuration>Release</Configuration>
-      <Platform>x64</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{50EEF5E6-0B42-4529-8F01-D5C6DF91CAAE}</ProjectGuid>
-    <RootNamespace>libngs</RootNamespace>
-    <NGS_OUTDIR>$(USERPROFILE)\win\cl\</NGS_OUTDIR>
-    <NGS_TARGET>$(NGS_OUTDIR)\$(Platform)\$(Configuration)\</NGS_TARGET>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
-    <ConfigurationType>StaticLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <TargetExt>.lib</TargetExt>
-    <OutDir>$(NGS_TARGET)\lib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetName>libngs-sdk</TargetName>
-    <LinkIncremental>false</LinkIncremental>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <TargetExt>.lib</TargetExt>
-    <OutDir>$(NGS_TARGET)\lib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetName>libngs-sdk</TargetName>
-    <LinkIncremental>false</LinkIncremental>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <TargetExt>.lib</TargetExt>
-    <OutDir>$(NGS_TARGET)\lib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetName>libngs-sdk</TargetName>
-    <LinkIncremental>false</LinkIncremental>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <TargetExt>.lib</TargetExt>
-    <OutDir>$(NGS_TARGET)\lib\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <TargetName>libngs-sdk</TargetName>
-    <LinkIncremental>false</LinkIncremental>
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <NoEntryPoint>true</NoEntryPoint>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <NoEntryPoint>true</NoEntryPoint>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <NoEntryPoint>true</NoEntryPoint>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <NoEntryPoint>true</NoEntryPoint>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ProjectReference Include="libdispatch.vcxproj">
-      <Project>{06fa485f-8aa9-4f3b-b1e3-d8cf1993637b}</Project>
-    </ProjectReference>
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="..\ngs\Alignment.hpp" />
-    <ClInclude Include="..\ngs\AlignmentIterator.hpp" />
-    <ClInclude Include="..\ngs\ErrorMsg.hpp" />
-    <ClInclude Include="..\ngs\Fragment.hpp" />
-    <ClInclude Include="..\ngs\FragmentIterator.hpp" />
-    <ClInclude Include="..\ngs\inl\Alignment.hpp" />
-    <ClInclude Include="..\ngs\inl\AlignmentIterator.hpp" />
-    <ClInclude Include="..\ngs\inl\Fragment.hpp" />
-    <ClInclude Include="..\ngs\inl\FragmentIterator.hpp" />
-    <ClInclude Include="..\ngs\inl\Pileup.hpp" />
-    <ClInclude Include="..\ngs\inl\PileupEvent.hpp" />
-    <ClInclude Include="..\ngs\inl\PileupEventIterator.hpp" />
-    <ClInclude Include="..\ngs\inl\PileupIterator.hpp" />
-    <ClInclude Include="..\ngs\inl\Read.hpp" />
-    <ClInclude Include="..\ngs\inl\ReadCollection.hpp" />
-    <ClInclude Include="..\ngs\inl\ReadGroup.hpp" />
-    <ClInclude Include="..\ngs\inl\ReadGroupIterator.hpp" />
-    <ClInclude Include="..\ngs\inl\ReadIterator.hpp" />
-    <ClInclude Include="..\ngs\inl\Reference.hpp" />
-    <ClInclude Include="..\ngs\inl\ReferenceIterator.hpp" />
-    <ClInclude Include="..\ngs\inl\Statistics.hpp" />
-    <ClInclude Include="..\ngs\inl\StringRef.hpp" />
-    <ClInclude Include="..\ngs\Pileup.hpp" />
-    <ClInclude Include="..\ngs\PileupEvent.hpp" />
-    <ClInclude Include="..\ngs\PileupEventIterator.hpp" />
-    <ClInclude Include="..\ngs\PileupIterator.hpp" />
-    <ClInclude Include="..\ngs\Read.hpp" />
-    <ClInclude Include="..\ngs\ReadCollection.hpp" />
-    <ClInclude Include="..\ngs\ReadGroup.hpp" />
-    <ClInclude Include="..\ngs\ReadGroupIterator.hpp" />
-    <ClInclude Include="..\ngs\ReadIterator.hpp" />
-    <ClInclude Include="..\ngs\Reference.hpp" />
-    <ClInclude Include="..\ngs\ReferenceIterator.hpp" />
-    <ClInclude Include="..\ngs\Statistics.hpp" />
-    <ClInclude Include="..\ngs\StringRef.hpp" />
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
-</Project>
\ No newline at end of file
diff --git a/ngs-sdk/win/libngs.vcxproj.filters b/ngs-sdk/win/libngs.vcxproj.filters
deleted file mode 100644
index e759adc..0000000
--- a/ngs-sdk/win/libngs.vcxproj.filters
+++ /dev/null
@@ -1,123 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup>
-    <Filter Include="Source Files">
-      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
-      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
-    </Filter>
-    <Filter Include="Header Files">
-      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
-      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
-    </Filter>
-    <Filter Include="Header Files\inl">
-      <UniqueIdentifier>{8802bed9-e96d-4c55-8f6e-47bc3f32c439}</UniqueIdentifier>
-    </Filter>
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="..\ngs\inl\Alignment.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\AlignmentIterator.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\Fragment.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\FragmentIterator.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\Pileup.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\PileupEvent.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\PileupEventIterator.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\PileupIterator.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\Read.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\ReadCollection.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\ReadGroup.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\ReadGroupIterator.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\ReadIterator.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\Reference.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\ReferenceIterator.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\Statistics.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\inl\StringRef.hpp">
-      <Filter>Header Files\inl</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\Alignment.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\AlignmentIterator.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\ErrorMsg.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\Fragment.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\FragmentIterator.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\Pileup.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\PileupEvent.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\PileupEventIterator.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\PileupIterator.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\Read.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\ReadCollection.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\ReadGroup.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\ReadGroupIterator.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\ReadIterator.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\Reference.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\ReferenceIterator.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\Statistics.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-    <ClInclude Include="..\ngs\StringRef.hpp">
-      <Filter>Source Files</Filter>
-    </ClInclude>
-  </ItemGroup>
-</Project>
\ No newline at end of file
diff --git a/ngs-sdk/win/libtest_engine.vcxproj b/ngs-sdk/win/libtest_engine.vcxproj
index c41ed48..26db5a9 100644
--- a/ngs-sdk/win/libtest_engine.vcxproj
+++ b/ngs-sdk/win/libtest_engine.vcxproj
@@ -18,176 +18,41 @@
       <Platform>x64</Platform>
     </ProjectConfiguration>
   </ItemGroup>
-
-  <Import Project="ngs-common.props" />
   
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{FB574D6F-8684-45AE-A0AF-B52BA67E9FDE}</ProjectGuid>
-    <RootNamespace>libtest_engine</RootNamespace>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <TargetExt>.dll</TargetExt>
-    <OutDir>$(NGS_TARGET)\bin\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <LinkIncremental>false</LinkIncremental>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <TargetExt>.dll</TargetExt>
-    <OutDir>$(NGS_TARGET)\bin\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <LinkIncremental>false</LinkIncremental>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <TargetExt>.dll</TargetExt>
-    <OutDir>$(NGS_TARGET)\bin\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <LinkIncremental>false</LinkIncremental>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <TargetExt>.dll</TargetExt>
-    <OutDir>$(NGS_TARGET)\bin\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <LinkIncremental>false</LinkIncremental>
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <PreprocessorDefinitions>_LIBRARY;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <NoEntryPoint>false</NoEntryPoint>
-      <ImportLibrary>$(OutDir)\$(ProjectName).lib</ImportLibrary>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <PreprocessorDefinitions>_LIBRARY;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <NoEntryPoint>false</NoEntryPoint>
-      <ImportLibrary>$(OutDir)\$(ProjectName).lib</ImportLibrary>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <PreprocessorDefinitions>_LIBRARY;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <NoEntryPoint>false</NoEntryPoint>
-      <ImportLibrary>$(OutDir)\$(ProjectName).lib</ImportLibrary>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <PreprocessorDefinitions>_LIBRARY;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <NoEntryPoint>false</NoEntryPoint>
-      <ImportLibrary>$(OutDir)\$(ProjectName).lib</ImportLibrary>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClCompile Include="..\test\test_engine\test_engine.cpp" />
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="..\test\test_engine\AlignmentItf.hpp" />
-    <ClInclude Include="..\test\test_engine\PileupEventItf.hpp" />
-    <ClInclude Include="..\test\test_engine\PileupItf.hpp" />
-    <ClInclude Include="..\test\test_engine\ReadCollectionItf.hpp" />
-    <ClInclude Include="..\test\test_engine\ReadGroupItf.hpp" />
-    <ClInclude Include="..\test\test_engine\ReadItf.hpp" />
-    <ClInclude Include="..\test\test_engine\ReferenceItf.hpp" />
-    <ClInclude Include="..\test\test_engine\StatisticsItf.hpp" />
-    <ClInclude Include="..\test\test_engine\test_engine.hpp" />
-  </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="libadapter.vcxproj">
-      <Project>{b9096fef-5b55-4308-a81f-3b52ca968be9}</Project>
-    </ProjectReference>
-    <ProjectReference Include="libdispatch.vcxproj">
-      <Project>{06fa485f-8aa9-4f3b-b1e3-d8cf1993637b}</Project>
-    </ProjectReference>
-    <ProjectReference Include="libngs-c++.vcxproj">
-      <Project>{a8ac88d2-fada-4458-a251-db2e039678a4}</Project>
-    </ProjectReference>
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+    <Import Project="lib-project.props" />
+  
+    <PropertyGroup Label="Globals">
+        <ProjectGuid>{FB574D6F-8684-45AE-A0AF-B52BA67E9FDE}</ProjectGuid>
+    </PropertyGroup>
+  
+    <ItemGroup>
+        <ProjectReference Include="libadapter.vcxproj">
+            <Project>{b9096fef-5b55-4308-a81f-3b52ca968be9}</Project>
+        </ProjectReference>
+        <ProjectReference Include="libdispatch.vcxproj">
+            <Project>{06fa485f-8aa9-4f3b-b1e3-d8cf1993637b}</Project>
+        </ProjectReference>
+        <ProjectReference Include="libngs-c++.vcxproj">
+            <Project>{a8ac88d2-fada-4458-a251-db2e039678a4}</Project>
+        </ProjectReference>
+    </ItemGroup>
+  
+    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  
+    <ImportGroup Label="ExtensionTargets" />
+  
+    <ItemGroup>
+        <ClCompile Include="..\test\test_engine\test_engine.cpp" />
+    </ItemGroup>
+    <ItemGroup>
+        <ClInclude Include="..\test\test_engine\AlignmentItf.hpp" />
+        <ClInclude Include="..\test\test_engine\PileupEventItf.hpp" />
+        <ClInclude Include="..\test\test_engine\PileupItf.hpp" />
+        <ClInclude Include="..\test\test_engine\ReadCollectionItf.hpp" />
+        <ClInclude Include="..\test\test_engine\ReadGroupItf.hpp" />
+        <ClInclude Include="..\test\test_engine\ReadItf.hpp" />
+        <ClInclude Include="..\test\test_engine\ReferenceItf.hpp" />
+        <ClInclude Include="..\test\test_engine\StatisticsItf.hpp" />
+        <ClInclude Include="..\test\test_engine\test_engine.hpp" />
+    </ItemGroup>
 </Project>
\ No newline at end of file
diff --git a/ngs-sdk/win/ngs-common.props b/ngs-sdk/win/ngs-common.props
index d385a72..fb44c1f 100644
--- a/ngs-sdk/win/ngs-common.props
+++ b/ngs-sdk/win/ngs-common.props
@@ -1,14 +1,69 @@
 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  
 
-  <Import Condition="Exists('$(ProjectDir)..\Makefile.config.win')" Project="$(ProjectDir)..\Makefile.config.win" />
+    <Import Condition="Exists('$(ProjectDir)..\Makefile.config.win')" Project="$(ProjectDir)..\Makefile.config.win" />
 
-  <PropertyGroup Label="Globals">
-    <Platform Condition="'$(Platform)' == ''">x64</Platform>
-    <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
-    
-    <NGS_OUTDIR Condition="'$(NGS_OUTDIR)' == ''">$(USERPROFILE)\</NGS_OUTDIR>
-    <NGS_ROOT Condition="'$(NGS_ROOT)' == ''">$(ProjectDir)..\</NGS_ROOT>
-    <NGS_TARGET Condition="'$(NGS_TARGET)' == ''">$(NGS_OUTDIR)win\cl\$(Platform)\$(Configuration)\</NGS_TARGET>    
-  </PropertyGroup>
+    <PropertyGroup Label="Globals">
+        <Platform Condition="'$(Platform)' == ''">x64</Platform>
+        <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
+    
+        <NGS_OUTDIR Condition="'$(NGS_OUTDIR)' == ''">$(USERPROFILE)\</NGS_OUTDIR>
+        <NGS_ROOT Condition="'$(NGS_ROOT)' == ''">$(ProjectDir)..\</NGS_ROOT>
+        <NGS_TARGET Condition="'$(NGS_TARGET)' == ''">$(NGS_OUTDIR)win\cl\$(Platform)\$(Configuration)\</NGS_TARGET>    
+    </PropertyGroup>
   
+    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+
+    <PropertyGroup Label="Configuration">
+        <CharacterSet>Unicode</CharacterSet>
+        <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
+        <TargetName>$(ProjectName)</TargetName>
+        <LinkIncremental>false</LinkIncremental>
+        <WholeProgramOptimization>false</WholeProgramOptimization>
+    </PropertyGroup>
+    
+    <PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
+        <UseDebugLibraries>true</UseDebugLibraries>
+    </PropertyGroup>
+    <PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
+        <UseDebugLibraries>false</UseDebugLibraries>
+    </PropertyGroup>
+    
+    <ItemDefinitionGroup>
+        <ClCompile>
+            <WarningLevel>Level3</WarningLevel>
+            <CompileAsManaged>false</CompileAsManaged>
+            <MinimalRebuild>true</MinimalRebuild>
+            <DisableLanguageExtensions>false</DisableLanguageExtensions>
+            <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+            <DisableSpecificWarnings>4996;4101;4251;4290</DisableSpecificWarnings>
+             <StringPooling>true</StringPooling>
+            <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+        </ClCompile>
+    </ItemDefinitionGroup>
+    
+    <ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
+        <ClCompile>
+            <Optimization>Disabled</Optimization>
+            <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+            <PreprocessorDefinitions>_DEBUGGING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+        </ClCompile>
+        <Link>
+            <GenerateDebugInformation>true</GenerateDebugInformation>
+        </Link>
+    </ItemDefinitionGroup>
+    <ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
+        <ClCompile>
+            <Optimization>MaxSpeed</Optimization>
+            <FunctionLevelLinking>true</FunctionLevelLinking>
+            <IntrinsicFunctions>true</IntrinsicFunctions>
+            <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+            <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+        </ClCompile>
+        <Link>
+            <GenerateDebugInformation>false</GenerateDebugInformation>
+            <EnableCOMDATFolding>true</EnableCOMDATFolding>
+            <OptimizeReferences>true</OptimizeReferences>
+        </Link>
+    </ItemDefinitionGroup>
+    
 </Project>
\ No newline at end of file
diff --git a/ngs-sdk/win/ngs-sdk.vcxproj b/ngs-sdk/win/ngs-sdk.vcxproj
index 688c169..5ffbe88 100644
--- a/ngs-sdk/win/ngs-sdk.vcxproj
+++ b/ngs-sdk/win/ngs-sdk.vcxproj
@@ -20,194 +20,90 @@
   </ItemGroup>
   
   <Import Project="ngs-common.props" />
-
+  
   <PropertyGroup Label="Globals">
     <ProjectGuid>{A6A46CB4-760E-4F16-9499-BC712E99FB5D}</ProjectGuid>
-    <RootNamespace>ngstest</RootNamespace>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
+    <ProjectName>libngs-sdk</ProjectName>
   </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+  
+  <PropertyGroup>
     <ConfigurationType>DynamicLibrary</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <OutDir>$(NGS_TARGET)\bin\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <LinkIncremental>false</LinkIncremental>
-    <TargetName>lib$(ProjectName)</TargetName>
-    <TargetExt>.dll</TargetExt>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <OutDir>$(NGS_TARGET)\bin\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <LinkIncremental>false</LinkIncremental>
-    <TargetName>lib$(ProjectName)</TargetName>
     <TargetExt>.dll</TargetExt>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <OutDir>$(NGS_TARGET)\bin\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <LinkIncremental>false</LinkIncremental>
-    <TargetName>lib$(ProjectName)</TargetName>
-    <TargetExt>.dll</TargetExt>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <OutDir>$(NGS_TARGET)\bin\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <LinkIncremental>false</LinkIncremental>
-    <TargetName>lib$(ProjectName)</TargetName>
-    <TargetExt>.dll</TargetExt>
   </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <NoEntryPoint>false</NoEntryPoint>
-    </Link>
-    <ProjectReference>
-      <UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
-    </ProjectReference>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <NoEntryPoint>false</NoEntryPoint>
-    </Link>
-    <ProjectReference>
-      <UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
-    </ProjectReference>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <NoEntryPoint>false</NoEntryPoint>
-    </Link>
-    <ProjectReference>
-      <UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
-    </ProjectReference>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-      <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-      <NoEntryPoint>false</NoEntryPoint>
-    </Link>
-    <ProjectReference>
-      <UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
-    </ProjectReference>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ClCompile Include="..\dispatch\AlignmentItf.cpp" />
-    <ClCompile Include="..\dispatch\ErrBlock.cpp" />
-    <ClCompile Include="..\dispatch\ErrorMsg.cpp" />
-    <ClCompile Include="..\dispatch\FragmentItf.cpp" />
-    <ClCompile Include="..\dispatch\PileupEventItf.cpp" />
-    <ClCompile Include="..\dispatch\PileupItf.cpp" />
-    <ClCompile Include="..\dispatch\ReadCollectionItf.cpp" />
-    <ClCompile Include="..\dispatch\ReadGroupItf.cpp" />
-    <ClCompile Include="..\dispatch\ReadItf.cpp" />
-    <ClCompile Include="..\dispatch\Refcount.cpp" />
-    <ClCompile Include="..\dispatch\ReferenceItf.cpp" />
-    <ClCompile Include="..\dispatch\StatisticsItf.cpp" />
-    <ClCompile Include="..\dispatch\StringItf.cpp" />
-    <ClCompile Include="..\dispatch\VTable.cpp" />
-    <ClCompile Include="..\language\c++\Alignment.cpp" />
-    <ClCompile Include="..\language\c++\AlignmentIterator.cpp" />
-    <ClCompile Include="..\language\c++\Fragment.cpp" />
-    <ClCompile Include="..\language\c++\FragmentIterator.cpp" />
-    <ClCompile Include="..\language\c++\Pileup.cpp" />
-    <ClCompile Include="..\language\c++\PileupEvent.cpp" />
-    <ClCompile Include="..\language\c++\PileupEventIterator.cpp" />
-    <ClCompile Include="..\language\c++\PileupIterator.cpp" />
-    <ClCompile Include="..\language\c++\Read.cpp" />
-    <ClCompile Include="..\language\c++\ReadCollection.cpp" />
-    <ClCompile Include="..\language\c++\ReadGroup.cpp" />
-    <ClCompile Include="..\language\c++\ReadGroupIterator.cpp" />
-    <ClCompile Include="..\language\c++\ReadIterator.cpp" />
-    <ClCompile Include="..\language\c++\Reference.cpp" />
-    <ClCompile Include="..\language\c++\ReferenceIterator.cpp" />
-    <ClCompile Include="..\language\c++\Statistics.cpp" />
-    <ClCompile Include="..\language\c++\StringRef.cpp" />
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+  
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+
+    <ItemDefinitionGroup>
+        <ClCompile>
+            <PreprocessorDefinitions>_LIBRARY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+        </ClCompile>
+        <Link>
+            <NoEntryPoint>false</NoEntryPoint>
+        </Link>
+        <ProjectReference>
+            <UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
+        </ProjectReference>
+    </ItemDefinitionGroup>
+    
+    <ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
+        <ClCompile>
+            <Optimization>Disabled</Optimization>
+            <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+            <PreprocessorDefinitions>_DEBUGGING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+        </ClCompile>
+        <Link>
+            <GenerateDebugInformation>true</GenerateDebugInformation>
+        </Link>
+    </ItemDefinitionGroup>
+    <ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
+        <ClCompile>
+            <Optimization>MaxSpeed</Optimization>
+            <FunctionLevelLinking>true</FunctionLevelLinking>
+            <IntrinsicFunctions>true</IntrinsicFunctions>
+            <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+            <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+        </ClCompile>
+        <Link>
+            <GenerateDebugInformation>false</GenerateDebugInformation>
+        </Link>
+    </ItemDefinitionGroup>  
+    
+    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+    <ImportGroup Label="ExtensionTargets" />
+  
+    <ItemGroup>
+        <ClCompile Include="..\dispatch\AlignmentItf.cpp" />
+        <ClCompile Include="..\dispatch\ErrBlock.cpp" />
+        <ClCompile Include="..\dispatch\ErrorMsg.cpp" />
+        <ClCompile Include="..\dispatch\FragmentItf.cpp" />
+        <ClCompile Include="..\dispatch\PileupEventItf.cpp" />
+        <ClCompile Include="..\dispatch\PileupItf.cpp" />
+        <ClCompile Include="..\dispatch\ReadCollectionItf.cpp" />
+        <ClCompile Include="..\dispatch\ReadGroupItf.cpp" />
+        <ClCompile Include="..\dispatch\ReadItf.cpp" />
+        <ClCompile Include="..\dispatch\Refcount.cpp" />
+        <ClCompile Include="..\dispatch\ReferenceItf.cpp" />
+        <ClCompile Include="..\dispatch\StatisticsItf.cpp" />
+        <ClCompile Include="..\dispatch\StringItf.cpp" />
+        <ClCompile Include="..\dispatch\VTable.cpp" />
+        <ClCompile Include="..\language\c++\Alignment.cpp" />
+        <ClCompile Include="..\language\c++\AlignmentIterator.cpp" />
+        <ClCompile Include="..\language\c++\Fragment.cpp" />
+        <ClCompile Include="..\language\c++\FragmentIterator.cpp" />
+        <ClCompile Include="..\language\c++\Pileup.cpp" />
+        <ClCompile Include="..\language\c++\PileupEvent.cpp" />
+        <ClCompile Include="..\language\c++\PileupEventIterator.cpp" />
+        <ClCompile Include="..\language\c++\PileupIterator.cpp" />
+        <ClCompile Include="..\language\c++\Read.cpp" />
+        <ClCompile Include="..\language\c++\ReadCollection.cpp" />
+        <ClCompile Include="..\language\c++\ReadGroup.cpp" />
+        <ClCompile Include="..\language\c++\ReadGroupIterator.cpp" />
+        <ClCompile Include="..\language\c++\ReadIterator.cpp" />
+        <ClCompile Include="..\language\c++\Reference.cpp" />
+        <ClCompile Include="..\language\c++\ReferenceIterator.cpp" />
+        <ClCompile Include="..\language\c++\Statistics.cpp" />
+        <ClCompile Include="..\language\c++\StringRef.cpp" />
+    </ItemGroup>
+  
 </Project>
\ No newline at end of file
diff --git a/ngs-sdk/win/ngs-test.vcxproj b/ngs-sdk/win/ngs-test.vcxproj
index 6f102c9..cbe359f 100644
--- a/ngs-sdk/win/ngs-test.vcxproj
+++ b/ngs-sdk/win/ngs-test.vcxproj
@@ -18,152 +18,66 @@
       <Platform>x64</Platform>
     </ProjectConfiguration>
   </ItemGroup>
-
-  <Import Project="ngs-common.props" />
   
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>{33E73C44-6EEB-4CAE-8DE6-2546E7DE2133}</ProjectGuid>
-    <RootNamespace>ngstest</RootNamespace>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <UseDebugLibraries>false</UseDebugLibraries>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-    <CharacterSet>Unicode</CharacterSet>
-  </PropertyGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
-  <ImportGroup Label="ExtensionSettings">
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <OutDir>$(NGS_TARGET)\bin\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <LinkIncremental>false</LinkIncremental>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <OutDir>$(NGS_TARGET)\bin\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <LinkIncremental>false</LinkIncremental>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <OutDir>$(NGS_TARGET)\bin\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <LinkIncremental>false</LinkIncremental>
-  </PropertyGroup>
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <OutDir>$(NGS_TARGET)\bin\</OutDir>
-    <IntDir>$(NGS_TARGET)\obj\$(ProjectName)\</IntDir>
-    <LinkIncremental>false</LinkIncremental>
-  </PropertyGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>MaxSpeed</Optimization>
-      <FunctionLevelLinking>true</FunctionLevelLinking>
-      <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>$(ProjectDir);$(ProjectDir)..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <DisableSpecificWarnings>4251;4290</DisableSpecificWarnings>
-      <MinimalRebuild>true</MinimalRebuild>
-      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-      <EnableCOMDATFolding>true</EnableCOMDATFolding>
-      <OptimizeReferences>true</OptimizeReferences>
-    </Link>
-  </ItemDefinitionGroup>
-  <ItemGroup>
-    <ProjectReference Include="libtest_engine.vcxproj">
-      <Project>{fb574d6f-8684-45ae-a0af-b52ba67e9fde}</Project>
-    </ProjectReference>
-    <ProjectReference Include="ngs-sdk.vcxproj">
-      <Project>{a6a46cb4-760e-4f16-9499-bc712e99fb5d}</Project>
-    </ProjectReference>
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="..\test\ngs-test\main.cpp" />
-  </ItemGroup>
-  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
-  <ImportGroup Label="ExtensionTargets">
-  </ImportGroup>
+    <Import Project="ngs-common.props" />
+  
+    <PropertyGroup Label="Globals">
+        <ProjectGuid>{33E73C44-6EEB-4CAE-8DE6-2546E7DE2133}</ProjectGuid>
+    </PropertyGroup>
+  
+    <PropertyGroup>
+        <ConfigurationType>Application</ConfigurationType>
+        <TargetExt>.exe</TargetExt>
+        <OutDir>$(NGS_TARGET)\bin\</OutDir>
+    </PropertyGroup>
+  
+    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  
+    <ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
+        <ClCompile>
+            <Optimization>Disabled</Optimization>
+            <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+            <PreprocessorDefinitions>_DEBUGGING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+        </ClCompile>
+        <Link>
+        <GenerateDebugInformation>true</GenerateDebugInformation>
+        </Link>
+    </ItemDefinitionGroup>
+  
+    <ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
+        <ClCompile>
+            <Optimization>MaxSpeed</Optimization>
+            <FunctionLevelLinking>true</FunctionLevelLinking>
+            <IntrinsicFunctions>true</IntrinsicFunctions>
+            <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+            <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+        </ClCompile>
+        <Link>
+        <GenerateDebugInformation>false</GenerateDebugInformation>
+        </Link>
+    </ItemDefinitionGroup>
+  
+    <ItemGroup>
+        <ProjectReference Include="libdispatch.vcxproj">
+            <Project>{06fa485f-8aa9-4f3b-b1e3-d8cf1993637b}</Project>
+        </ProjectReference>
+        <ProjectReference Include="libngs-c++.vcxproj">
+            <Project>{a8ac88d2-fada-4458-a251-db2e039678a4}</Project>
+        </ProjectReference>
+        <ProjectReference Include="libtest_engine.vcxproj">
+            <Project>{fb574d6f-8684-45ae-a0af-b52ba67e9fde}</Project>
+        </ProjectReference>
+    </ItemGroup>
+  
+    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+    
+    <ImportGroup Label="ExtensionTargets" />
   
+    <ItemGroup>
+        <ClCompile Include="..\test\ngs-test\main.cpp" />
+    </ItemGroup>
   
-    <Target Name="AfterBuild">
-        <Exec Command="$(OutDir)$(TargetName)$(TargetExt)" WorkingDirectory="$(ProjectDir)"/>
+    <Target Name="AfterBuild" Condition="'$(Autorun)'=='true'">
+        <Exec Command="$(OutDir)$(TargetName)$(TargetExt)" WorkingDirectory="$(ProjectDir)\"/>
     </Target>
-      
 </Project>
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/ngs-sdk.git



More information about the debian-med-commit mailing list