First-principles model potentials for lattice-dynamical studies: general methodology and example of application to ferroic perovskite oxides