Variational principle for the Finslerian extension of general relativity