Various build improvements

Fixed Makefile to build all targets without conflicts.

Fixed tests where they assumed presence of /dev/tty.

Added building shared library.

Added install targets for all libraries, headers and executables.