Makefile: fix JAVA_HOME detection

Use readlink and sed to detect JAVA_HOME and also fix CXXFLAGS.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>