Fix $(@RD) behaviour when TOP_BUILD_DIR is used

Hi again!

When using `TOP_BUILD_DIR` and specifying directory-specific configurations, these configurations aren't properly used (e.g. `INCLUDES_$(d)`). This is because the `$(@RD)` variable used doesn't properly convert build directories to real directories when `TOP_BUILD_DIR` is used.

Two helper functions are provided to convert back and forth between source and output directories, and a few variables are redefined in terms of those helpers. A minimal test project is provided that doesn't work before this change.

Thanks,
Alex.