BLD: Improved makefile to build self tests and correctly build shared libraries without incorrect dependencies