Variational method for liquids moving on a substrate