Don't include -Wl,... in hash since it doesn't affect compilation

As suggested by Mutsumi Ishikawa.
Fix bug in dirname

This avoids a crash when running "ccache -s" with CCACHE_DIR="".
Bail out on empty CCACHE_DIR