* make Makefile DESTDIR-aware
* use $(MAKE) -C for making in subdirectories
* fix install mode of data files
* deinstall -> uninstall
* fix issues where the path in help pages is taken from the build-time location of the executables
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-# This can be overridden e.g.: make install INSTALL_DIR=...
-INSTALL_DIR?=$(PWD)
+# This can be overridden e.g.: make install PREFIX=...
+PREFIX:=/usr
 
 # Guess wether to use lib or lib64
 #libdir=`([ -d /usr/lib64 ] && echo lib64) || echo lib`
@@ -8,19 +8,17 @@
 
 # Overriding this is currently not fully supported as the code won't know
 # to what this is set then. You can try setting HHLIB.
-INSTALL_LIB_DIR?=$(INSTALL_DIR)/$(libdir)/hh
-INSTALL_SCRIPTS_DIR?=$(INSTALL_LIB_DIR)/scripts
-INSTALL_DATA_DIR?=$(INSTALL_LIB_DIR)/data
+INSTALL_LIB_DIR?=$(PREFIX)/$(libdir)/hhsuite
+INSTALL_SCRIPTS_DIR?=$(PREFIX)/share/hhsuite/scripts
+INSTALL_DATA_DIR?=$(PREFIX)/share/hhsuite/data
+INSTALL_BDATA_DIR?=$(INSTALL_LIB_DIR)/data
 INSTALL_LIB_BIN_DIR?=$(INSTALL_LIB_DIR)/bin
 
 dist_name=hhsuite-2.0.13
 
-.PHONY: all_static
-all_static: ffindex_static
-	$(MAKE) -C src all_static
-
 .PHONY: all
-all: ffindex
+all:
+	$(MAKE) -C data all
 	$(MAKE) -C src all
 
 doc:
@@ -40,35 +38,34 @@
 	$(MAKE) -C lib/ffindex FFINDEX_STATIC=1
 	
 install:
-	$(MAKE) -C lib/ffindex install INSTALL_DIR=$(INSTALL_DIR)
-	mkdir -p $(INSTALL_DIR)/bin
-	install src/hhblits     $(INSTALL_DIR)/bin/hhblits
-	install src/hhalign     $(INSTALL_DIR)/bin/hhalign
-	install src/hhconsensus $(INSTALL_DIR)/bin/hhconsensus
-	install src/hhfilter    $(INSTALL_DIR)/bin/hhfilter
-	install src/hhmake      $(INSTALL_DIR)/bin/hhmake
-	install src/hhsearch    $(INSTALL_DIR)/bin/hhsearch
-	mkdir -p $(INSTALL_LIB_DIR)
-	mkdir -p $(INSTALL_LIB_BIN_DIR)
-	install src/cstranslate $(INSTALL_LIB_BIN_DIR)/cstranslate
-	mkdir -p $(INSTALL_DATA_DIR)
-	install -m 0644 data/context_data.lib $(INSTALL_DATA_DIR)/context_data.lib
-	install -m 0644 data/cs219.lib        $(INSTALL_DATA_DIR)/cs219.lib
-	install -m 0644 data/do_not_delete    $(INSTALL_DATA_DIR)/do_not_delete
-	install -m 0644 data/do_not_delete.phr $(INSTALL_DATA_DIR)/do_not_delete.phr
-	install -m 0644 data/do_not_delete.pin $(INSTALL_DATA_DIR)/do_not_delete.pin
-	install -m 0644 data/do_not_delete.psq $(INSTALL_DATA_DIR)/do_not_delete.psq
-	mkdir -p $(INSTALL_SCRIPTS_DIR)
-	install -m 0644 scripts/Align.pm        $(INSTALL_SCRIPTS_DIR)/Align.pm
-	install -m 0644 scripts/HHPaths.pm      $(INSTALL_SCRIPTS_DIR)/HHPaths.pm
-	install scripts/addss.pl        $(INSTALL_SCRIPTS_DIR)/addss.pl
-	install scripts/create_profile_from_hhm.pl   $(INSTALL_SCRIPTS_DIR)/create_profile_from_hhm.pl
-	install scripts/create_profile_from_hmmer.pl $(INSTALL_SCRIPTS_DIR)/create_profile_from_hmmer.pl
-	install scripts/hhmakemodel.pl $(INSTALL_SCRIPTS_DIR)/hhmakemodel.pl
-	install scripts/reformat.pl    $(INSTALL_SCRIPTS_DIR)/reformat.pl
-	install scripts/splitfasta.pl    $(INSTALL_SCRIPTS_DIR)/splitfasta.pl
-	install scripts/multithread.pl    $(INSTALL_SCRIPTS_DIR)/multithread.pl
-	install scripts/hhblitsdb.pl    $(INSTALL_SCRIPTS_DIR)/hhblitsdb.pl
+	mkdir -p $(DESTDIR)$(PREFIX)/bin
+	install src/hhblits     $(DESTDIR)$(PREFIX)/bin/hhblits
+	install src/hhalign     $(DESTDIR)$(PREFIX)/bin/hhalign
+	install src/hhconsensus $(DESTDIR)$(PREFIX)/bin/hhconsensus
+	install src/hhfilter    $(DESTDIR)$(PREFIX)/bin/hhfilter
+	install src/hhmake      $(DESTDIR)$(PREFIX)/bin/hhmake
+	install src/hhsearch    $(DESTDIR)$(PREFIX)/bin/hhsearch
+	mkdir -p $(DESTDIR)$(INSTALL_LIB_DIR)
+	mkdir -p $(DESTDIR)$(INSTALL_LIB_BIN_DIR)
+	install src/cstranslate $(DESTDIR)$(INSTALL_LIB_BIN_DIR)/cstranslate
+	mkdir -p $(DESTDIR)$(INSTALL_DATA_DIR) $(DESTDIR)$(INSTALL_BDATA_DIR)
+	install --mode=0644 data/context_data.lib $(DESTDIR)$(INSTALL_DATA_DIR)/context_data.lib
+	install --mode=0644 data/cs219.lib        $(DESTDIR)$(INSTALL_DATA_DIR)/cs219.lib
+	install --mode=0644 data/do_not_delete    $(DESTDIR)$(INSTALL_BDATA_DIR)/do_not_delete
+	install --mode=0644 data/do_not_delete.phr $(DESTDIR)$(INSTALL_BDATA_DIR)/do_not_delete.phr
+	install --mode=0644 data/do_not_delete.pin $(DESTDIR)$(INSTALL_BDATA_DIR)/do_not_delete.pin
+	install --mode=0644 data/do_not_delete.psq $(DESTDIR)$(INSTALL_BDATA_DIR)/do_not_delete.psq
+	mkdir -p $(DESTDIR)$(INSTALL_SCRIPTS_DIR)
+	install --mode=0644 scripts/Align.pm        $(DESTDIR)$(INSTALL_SCRIPTS_DIR)/Align.pm
+	install --mode=0644 scripts/HHPaths.pm      $(DESTDIR)$(INSTALL_SCRIPTS_DIR)/HHPaths.pm
+	install scripts/addss.pl        $(DESTDIR)$(INSTALL_SCRIPTS_DIR)/addss.pl
+	install scripts/create_profile_from_hhm.pl   $(DESTDIR)$(INSTALL_SCRIPTS_DIR)/create_profile_from_hhm.pl
+	install scripts/create_profile_from_hmmer.pl $(DESTDIR)$(INSTALL_SCRIPTS_DIR)/create_profile_from_hmmer.pl
+	install scripts/hhmakemodel.pl $(DESTDIR)$(INSTALL_SCRIPTS_DIR)/hhmakemodel.pl
+	install scripts/reformat.pl    $(DESTDIR)$(INSTALL_SCRIPTS_DIR)/reformat.pl
+	install scripts/splitfasta.pl  $(DESTDIR)$(INSTALL_SCRIPTS_DIR)/splitfasta.pl
+	install scripts/multithread.pl $(DESTDIR)$(INSTALL_SCRIPTS_DIR)/multithread.pl
+	install scripts/hhblitsdb.pl   $(DESTDIR)$(INSTALL_SCRIPTS_DIR)/hhblitsdb.pl
 
 deinstall:
 	$(MAKE) -C lib/ffindex deinstall INSTALL_DIR=$(INSTALL_DIR)
@@ -89,9 +86,11 @@
 
 .PHONY: clean
 clean:
-	cd lib/ffindex && $(MAKE) clean
 	$(MAKE) -C src clean
 
+.PHONY: distclean
+distclean: clean
+
 dist/$(dist_name).tar.gz:
 	make clean
 	mkdir -p dist
--- a/scripts/HHPaths.pm
+++ b/scripts/HHPaths.pm
@@ -14,7 +14,7 @@
 use Exporter;
 our $VERSION = "version 2.0.12 (Feb 2012)";
 our @ISA     = qw(Exporter);
-our @EXPORT  = qw($VERSION $hhlib $hhdata $hhbin $hhscripts $execdir $datadir $ncbidir $dummydb $pdbdir $dsspdir $dssp $cs_lib $context_lib);
+our @EXPORT  = qw($VERSION $hhlib $hhshare $hhdata $hhbdata $hhbin $hhscripts $execdir $datadir $ncbidir $dummydb $pdbdir $dsspdir $dssp $cs_lib $context_lib);
 
 ##############################################################################################
 # PLEASE COMPLETE THE PATHS ... TO PSIPRED AND OLD-STYLE BLAST (NOT BLAST+) (NEEDED FOR PSIPRED) 
@@ -38,11 +38,13 @@
 # The lines below probably do not need to be changed
 
 # Setting paths for hh-suite perl scripts
-our $hhlib    = $ENV{"HHLIB"};     # main hh-suite directory
-our $hhdata   = $hhlib."/data";    # path to data directory for hhblits, example files
+our $hhlib    = $ENV{"HHLIB"} || "/usr/lib/hhsuite";     # main hh-suite directory
+our $hhshare  = $ENV{"HHLIB"} || "/usr/share/hhsuite";   # main hh-suite directory
+our $hhdata   = $hhshare."/data";  # path to arch indep data directory for hhblits, example files
+our $hhbdata  = $hhlib."/data";    # path to arch dep data directory for hhblits, example files
 our $hhbin    = $hhlib."/bin";     # path to cstranslate (path to hhsearch, hhblits etc. should be in $PATH)
-our $hhscripts= $hhlib."/scripts"; # path to hh perl scripts (addss.pl, reformat.pl, hhblitsdb.pl etc.)
-our $dummydb  = $hhdata."/do_not_delete"; # Name of dummy blast db for PSIPRED (single sequence formatted with NCBI formatdb)
+our $hhscripts= $hhshare."/scripts"; # path to hh perl scripts (addss.pl, reformat.pl, hhblitsdb.pl etc.)
+our $dummydb  = $hhbdata."/do_not_delete"; # Name of dummy blast db for PSIPRED (single sequence formatted with NCBI formatdb)
 
 # HHblits data files
 our $cs_lib = "$hhdata/cs219.lib";
--- a/src/hhdecl.C
+++ b/src/hhdecl.C
@@ -279,7 +279,7 @@
   if(getenv("HHLIB"))
     strcpy(hhlib, getenv("HHLIB"));
   else
-    strcpy(hhlib, "/usr/lib/hh");
+    strcpy(hhlib, "/usr/lib/hhsuite");
 
   strcat(strcpy(hhdata, hhlib), "/data");
   strcat(strcpy(clusterfile, hhdata), "/context_data.lib");
@@ -291,7 +291,7 @@
   /* we did not find HHLIB, if called with full path or in dist dir, we can try relative to program path */
   if(program_path != NULL)
   {
-    strcat(strcpy(hhlib, program_path), "../lib/hh");
+    strcat(strcpy(hhlib, program_path), "../lib/hhsuite");
     strcat(strcpy(hhdata, hhlib), "/data");
     strcat(strcpy(clusterfile, hhdata), "/context_data.lib");
     strcat(strcpy(cs_library, hhdata), "/cs219.lib");
--- a/src/hhblits.C
+++ b/src/hhblits.C
@@ -295,8 +295,8 @@
   printf(" -M [0,100]     use FASTA: columns with fewer than X%% gaps are match states   \n");
   if (all) { 
   printf("Directory paths \n");
-  printf(" -contxt <file> context file for computing context-specific pseudocounts (default=%s)\n",par.clusterfile);
-  printf(" -cslib  <file> column state file for fast database prefiltering (default=%s)\n",par.cs_library);
+  printf(" -contxt <file> context file for computing context-specific pseudocounts (default=/usr/lib/hhsuite/data/context_data.lib)\n");
+  printf(" -cslib  <file> column state file for fast database prefiltering (default=/usr/lib/hhsuite/data/cs219.lib)\n");
   printf(" -psipred      <dir>  directory with PSIPRED executables (default=%s)  \n",par.psipred);
   printf(" -psipred_data <dir>  directory with PSIPRED data (default=%s) \n",par.psipred_data);
   printf("\n");
@@ -408,7 +408,12 @@
   printf("An extended list of options can be obtained by using '-help all' as parameter    \n");
   }
   printf("\n");
-  printf("Example: %s -i query.fas -oa3m query.a3m -n 2  \n",program_name);
+  printf("Examples:\n");
+  printf("%s -i query.fas -o query.hhr -d <database-basepath>\n",program_name);
+  printf("\n");
+  printf("%s -i query.fas -o query.hhr -oa3m query.a3m -n 2 -d <database-basepath>\n",program_name);
+  printf("\n");
+  printf("Download databases from ftp://toolkit.genzentrum.lmu.de/HH-suite/databases/hhblits/.\n");
   cout<<endl;
 }
 
--- a/src/hhsearch.C
+++ b/src/hhsearch.C
@@ -326,7 +326,7 @@
   printf(" -pcc  [0,3]    extinction exponent for tau(Neff)  (def=%-.1f)     \n",par.pcc);
   printf(" -pcw  [0,3]    weight of pos-specificity for pcs  (def=%-.1f)      \n",par.pcw);
   // HHsearch option should be the same as HHblits option!!
-  printf(" -contxt <file> context file for computing context-specific pseudocounts (default=%s)\n",par.clusterfile);
+  printf(" -contxt <file> context file for computing context-specific pseudocounts (default=/usr/lib/hhsuite/data/context_data.lib)\n");
   printf(" -csw  [0,inf]  weight of central position in cs pseudocount mode (def=%.1f)\n", par.csw);
   printf(" -csb  [0,1]    weight decay parameter for positions in cs pc mode (def=%.1f)\n", par.csb);
 }
--- a/src/Makefile
+++ b/src/Makefile
@@ -14,13 +14,13 @@
 
 ifdef ICC
   CXX = env LANG=C icc
-  CXXFLAGS = -fast -Wall -fno-strict-aliasing -finline-functions -funroll-loops -fp-model fast=2 -fast-transcendentals -wd981 -wd383 -wd2259 -wd1572 -D HH_SSE3 -I$(CS_DIR) -I$(FFINDEX_DIR)
+  CXXFLAGS = -fast -Wall -fno-strict-aliasing -finline-functions -funroll-loops -fp-model fast=2 -fast-transcendentals -wd981 -wd383 -wd2259 -wd1572 -D HH_SSE3 -I$(CS_DIR)
   HHSEARCH_LIBS = -lpthread -lrt
   HHBLITS_LIBS = -lpthread -lrt -openmp
   OBJECT_LIBS = -openmp
 else # ifndef ICC
   CXX = g++
-  CXXFLAGS = -O3 -Wall -Wno-deprecated -Wno-char-subscripts -fno-strict-aliasing -I$(CS_DIR) $(BITS_FLAG) -I$(FFINDEX_DIR)
+  CXXFLAGS = -O3 -Wall -Wno-deprecated -Wno-char-subscripts -fno-strict-aliasing -I$(CS_DIR) $(BITS_FLAG)
   HHSEARCH_LIBS = -lpthread
   HHBLITS_LIBS = -lpthread -fopenmp
   HHALIGN_LIBS = 
@@ -92,7 +92,7 @@
 	  $(CPP_VALGRIND) hhsearch.C -o hhsearch_valgrind $(CS_OBJECTS) $(HHSEARCH_LIBS)
 
 hhblits: hhblits.C $(SOURCES) $(HEADERS) $(CS_OBJECTS)
-	 $(CPP) hhblits.C -o hhblits $(CS_OBJECTS) $(HHBLITS_LIBS) $(FFINDEX_DIR)/libffindex.a
+	 $(CPP) hhblits.C -o hhblits $(CS_OBJECTS) $(HHBLITS_LIBS) -lffindex
 
 hhblits_static: hhblits.C $(SOURCES) $(HEADERS)$(CS_OBJECTS)
 	 $(CPP) -static hhblits.C -o hhblits $(CS_OBJECTS) $(HHBLITS_LIBS) $(FFINDEX_DIR)/libffindex.a
--- a/scripts/addss.pl
+++ b/scripts/addss.pl
@@ -28,7 +28,7 @@
 
 #     We are very grateful for bug reports! Please contact us at soeding@genzentrum.lmu.de
 
-use lib $ENV{"HHLIB"}."/scripts";
+use lib ( $ENV{"HHLIB"} || '/usr/share/hhsuite' )."/scripts";
 use HHPaths;   # config file with path variables for nr, blast, psipred, pdb, dssp etc.
 use Align;     # Needleman-Wunsch and Smith-Waterman alignment functions
 use File::Temp qw/ tempfile tempdir /;
--- a/scripts/hhblitsdb.pl
+++ b/scripts/hhblitsdb.pl
@@ -28,7 +28,7 @@
 
 #     We are very grateful for bug reports! Please contact us at soeding@genzentrum.lmu.de
 
-use lib $ENV{"HHLIB"}."/scripts";
+use lib ( $ENV{"HHLIB"} || '/usr/share/hhsuite' )."/scripts";
 use HHPaths;   # config file with path variables for nr, blast, psipred, pdb, dssp etc.
 use strict;
 
--- a/scripts/hhmakemodel.pl
+++ b/scripts/hhmakemodel.pl
@@ -28,7 +28,7 @@
 
 #     We are very grateful for bug reports! Please contact us at soeding@genzentrum.lmu.de
 
-use lib $ENV{"HHLIB"}."/scripts";
+use lib ( $ENV{"HHLIB"} || '/usr/share/hhsuite' )."/scripts";
 use HHPaths;   # config file with path variables for nr, blast, psipred, pdb, dssp etc.
 use strict;
 use Align;
--- /dev/null
+++ b/data/Makefile
@@ -0,0 +1,11 @@
+#!/usr/bin/make -f
+
+DUMMYDB:=do_not_delete.phr do_not_delete.pin do_not_delete.psq
+
+all: $(DUMMYDB)
+
+%.phr %.pin %.psq : %
+	formatdb -i '$<' && rm -f formatdb.log
+
+clean:
+	rm -f $(DUMMYDB) formatdb.log
--- a/scripts/create_profile_from_hhm.pl
+++ b/scripts/create_profile_from_hhm.pl
@@ -27,7 +27,7 @@
 
 #     We are very grateful for bug reports! Please contact us at soeding@genzentrum.lmu.de
 
-use lib $ENV{"HHLIB"}."/scripts";
+use lib ( $ENV{"HHLIB"} || '/usr/share/hhsuite' )."/scripts";
 use HHPaths;   # config file with path variables for nr, blast, psipred, pdb, dssp etc.
 use strict;
 
--- a/scripts/create_profile_from_hmmer.pl
+++ b/scripts/create_profile_from_hmmer.pl
@@ -27,7 +27,7 @@
 
 #     We are very grateful for bug reports! Please contact us at soeding@genzentrum.lmu.de
 
-use lib $ENV{"HHLIB"}."/scripts";
+use lib ( $ENV{"HHLIB"} || '/usr/share/hhsuite' )."/scripts";
 use HHPaths;   # config file with path variables for nr, blast, psipred, pdb, dssp etc.
 use strict;
 
--- a/scripts/multithread.pl
+++ b/scripts/multithread.pl
@@ -29,7 +29,7 @@
 
 #     We are very grateful for bug reports! Please contact us at soeding@genzentrum.lmu.de
 
-use lib $ENV{"HHLIB"}."/scripts";
+use lib ( $ENV{"HHLIB"} || '/usr/share/hhsuite' )."/scripts";
 use HHPaths;   # config file with path variables for nr, blast, psipred, pdb, dssp etc.
 use strict;
 use POSIX;
--- a/scripts/reformat.pl
+++ b/scripts/reformat.pl
@@ -27,7 +27,7 @@
 
 #     We are very grateful for bug reports! Please contact us at soeding@genzentrum.lmu.de
 
-use lib $ENV{"HHLIB"}."/scripts";
+use lib ( $ENV{"HHLIB"} || '/usr/share/hhsuite' )."/scripts";
 use HHPaths;   # config file with path variables for nr, blast, psipred, pdb, dssp etc.
 use strict;
 use warnings;
