Makefiles improvements and cleanup

This should resolve #138 (please reopen or comment on it if it's not the
case). Special thanks to Takkun for helping to reproduce the issue.

Signed-off-by: Haru <haru@dotalux.com>
Fixed a race condition leading to a crash on server shutdown on linux

Fixes bugreport:7699, thanks to bgamez23 (bugreport), Ind (testing,
brainstorming)
http://hercules.ws/board/tracker/issue-7699-map-crashed-on-the-latest-version/

Signed-off-by: Haru <haru@dotalux.com>