Add RTL support (@xsoh)

I rebased @xsoh's PR #520 to fix the build problems.