Makefiles to work on the source tree

Just added a few conditions and variables to make it work on the source tree.