autogen: set prefix for configure, remove libdir

'libdir' uses the value of 'prefix', so it shouldn't be hardcoded.
build: define the install dir variables in Makefile.am

According to the autoconf manual, AC_DEFINE and friends should not be
used to define values that are dependent on $prefix, so that users can
successfully override this value when they run configure.

Instead, the recommended solution is to add -D options to CPPFLAGS in
Makefile.am. Even though not every path we are configuring uses $prefix,
it's better to define them in one place for consistency.