diff --git a/.gitignore b/.gitignore
index f20a6c9fb8bf35dcff9c3e602e85e53f28aeafa4..ef0b3ad13daea73d7b335f64d9aac81676508d28 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,10 +1,11 @@
 build/aclocal.m4
 build/autom4te.cache
-build/aux/*
+build/build_aux/*
 build/config.*
 build/configure
 build/configure~
 build/cluster/*
+build/error.log
 build/libtool
 build/Makefile
 build/Makefile.in
@@ -15,5 +16,5 @@ build/libnptm/*
 containers/singularity/*.sif
 doc/build/*
 src/*/.deps
-src/*/objects/*
-src/*/dynobjects/*
+src/*/.dirstamp
+src/*/*.o
\ No newline at end of file
diff --git a/build/Makefile.am b/build/Makefile.am
index de0719e43d884037d7fb6b5a7e4102fb8964901b..319ff058a0ad3edba10686763a02729ac9fb26c8 100644
--- a/build/Makefile.am
+++ b/build/Makefile.am
@@ -1,16 +1,17 @@
 AUTOMAKE_OPTIONS=subdir-objects
-lib_LTLIBRARIES=libnptm.la
-libnptm_la_SOURCES=../src/libnptm/algebraic.cpp ../src/libnptm/clu_subs.cpp ../src/libnptm/Commons.cpp ../src/libnptm/Configuration.cpp ../src/libnptm/file_io.cpp ../src/libnptm/lapack_calls.cpp ../src/libnptm/logging.cpp ../src/libnptm/magma_calls.cpp ../src/libnptm/Parsers.cpp ../src/libnptm/sph_subs.cpp ../src/libnptm/tfrfme.cpp ../src/libnptm/TransitionMatrix.cpp ../src/libnptm/tra_subs.cpp ../src/libnptm/types.cpp
-bin_PROGRAMS=edfb_clu clu np_cluster edfb_sph sph np_sphere frfme lffft np_trapping
-edfb_clu_SOURCES=../src/cluster/edfb_clu.f
-clu_SOURCES=../src/cluster/clu.f
-np_cluster_SOURCES=../src/cluster/np_cluster.cpp ../src/cluster/cluster.cpp
-edfb_sph_SOURCES=../src/sphere/edfb_sph.f
-sph_SOURCES=../src/sphere/sph.f
-np_sphere_SOURCES=../src/sphere/np_sphere.cpp ../src/sphere/sphere.cpp
-frfme_SOURCES=../src/trapping/frfme.f
-lffft_SOURCES=../src/trapping/lffft.f
-np_trapping_SOURCES=../src/trapping/np_trapping.cpp ../src/trapping/cfrfme.cpp ../src/trapping/clffft.cpp
-check_PROGRAMS=test_TEDF test_TTMS
-test_TEDF_SOURCES=../src/testing/test_TEDF.cpp
-test_TTMS_SOURCES=../src/testing/test_TTMS.cpp
+LDADD=libnptm/libnptm.la -L/usr/lib64 $(HDF5_LDFLAGS)
+lib_LTLIBRARIES=libnptm/libnptm.la
+libnptm_libnptm_la_SOURCES=../src/libnptm/algebraic.cpp ../src/libnptm/clu_subs.cpp ../src/libnptm/Commons.cpp ../src/libnptm/Configuration.cpp ../src/libnptm/file_io.cpp ../src/libnptm/lapack_calls.cpp ../src/libnptm/logging.cpp ../src/libnptm/magma_calls.cpp ../src/libnptm/Parsers.cpp ../src/libnptm/sph_subs.cpp ../src/libnptm/tfrfme.cpp ../src/libnptm/TransitionMatrix.cpp ../src/libnptm/tra_subs.cpp ../src/libnptm/types.cpp
+bin_PROGRAMS=cluster/edfb_clu cluster/clu cluster/np_cluster sphere/edfb_sph sphere/sph sphere/np_sphere trapping/frfme trapping/lffft trapping/np_trapping
+cluster_edfb_clu_SOURCES=../src/cluster/edfb_clu.f
+cluster_clu_SOURCES=../src/cluster/clu.f
+cluster_np_cluster_SOURCES=../src/cluster/np_cluster.cpp ../src/cluster/cluster.cpp
+sphere_edfb_sph_SOURCES=../src/sphere/edfb_sph.f
+sphere_sph_SOURCES=../src/sphere/sph.f
+sphere_np_sphere_SOURCES=../src/sphere/np_sphere.cpp ../src/sphere/sphere.cpp
+trapping_frfme_SOURCES=../src/trapping/frfme.f
+trapping_lffft_SOURCES=../src/trapping/lffft.f
+trapping_np_trapping_SOURCES=../src/trapping/np_trapping.cpp ../src/trapping/cfrfme.cpp ../src/trapping/clffft.cpp
+check_PROGRAMS=testing/test_TEDF testing/test_TTMS
+testing_test_TEDF_SOURCES=../src/testing/test_TEDF.cpp
+testing_test_TTMS_SOURCES=../src/testing/test_TTMS.cpp
diff --git a/build/build_aux/.gitkeep b/build/build_aux/.gitkeep
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/build/configure.ac b/build/configure.ac
index 14554b1513045008accadbebb1cde55ba23689d7..4fdbb734add25007bdcb8098c920eed3b8c95cc4 100644
--- a/build/configure.ac
+++ b/build/configure.ac
@@ -1,5 +1,22 @@
 # CAPABILITY TESTING MACROS
-
+m4_define(
+	[M4_HDF5_LIB],
+	[cat > nptm_test_hdf5.cpp <<EOF
+#include <hdf5.h>
+int main(int argc, char **argv) {
+  hid_t file_id = 0;
+  herr_t status = H5Iis_valid(file_id);
+  return (int)status;
+}
+EOF
+	$CXX -o nptm_test_hdf5 nptm_test_hdf5.cpp -I$HDF5_INCLUDE -L$HDF5_LIB -lhdf5 > /dev/null 2>>error.log
+	export TEST_HDF5_LIB=$?
+	rm nptm_test_hdf5.cpp
+	if test "x$TEST_HDF5_LIB" = "x0"; then
+	  rm nptm_test_hdf5
+	fi]
+)
+  
 # END CAPABILITY TESTING MACROS
 
 # autoconf setup initialization
@@ -9,7 +26,7 @@ AC_INIT([np_tmcode], [8.04], [giovanni.lamura@inaf.it])
 AC_CONFIG_SRCDIR([../src/libnptm/TransitionMatrix.cpp])
 
 # Auxiliary build folder
-AC_CONFIG_AUX_DIR([aux])
+AC_CONFIG_AUX_DIR([build_aux])
 
 # automake initialization
 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
@@ -23,14 +40,19 @@ AC_PROG_CXX([mpicxx g++ clang])
 LT_INIT
 
 # Environment setup
-FFLAGS="-std=legacy -O3"
-CXXFLAGS="-O3 -ggdb -Wno-format-contains-nul"
-SUBDIRS="cluster libnptm sphere testing trapping"
 AS_IF(
 	[test "x$HDF5_INCLUDE" = "x"],
 	[export HDF5_INCLUDE=/usr/include/hdf5/serial],
 	[AC_MSG_NOTICE(["HDF5_INCLUDE=$HDF5_INCLUDE"])]
 )
+AS_IF(
+	[test "x$HDF5_LIB" = "x"],
+	[export HDF5_LIB=/usr/lib/x86_64-linux-gnu/hdf5/serial],
+	[AC_MSG_NOTICE(["HDF5_LIB=$HDF5_LIB"])]
+)
+FFLAGS="-std=legacy -O3"
+CXXFLAGS="-O3 -ggdb -Wno-format-contains-nul -I $HDF5_INCLUDE"
+SUBDIRS="cluster libnptm sphere testing trapping"
 
 # Check for required headers
 AC_CHECK_HEADER(
@@ -39,6 +61,15 @@ AC_CHECK_HEADER(
 	AC_MSG_ERROR(["Could not find HDF5 headers!]),
 	)
 
+# Check for required libraries
+M4_HDF5_LIB
+AS_IF(
+	[test "x$TEST_HDF5_LIB" = "x0"],
+	[export HDF5_LDFLAGS="-L${HDF5_LIB} -lhdf5"],
+	[AC_MSG_ERROR(["HDF5 library not found!"])]
+)
+AC_SUBST([HDF5_LDFLAGS])
+
 # Send output to Makefiles
 AC_CONFIG_FILES([Makefile])