An analytical theory for optimal controls on Riemannian manifolds