Add INTERMEDIATE_DIR variable, remove slash after _DIR variables

The INTERMEDIATE_DIR allows user to simply specify an directory where target files should be placed.

Removing slashes allows to build inplace in library, or to have INTERMEDIATE_DIR empty.