Thermodynamics of Inhomogeneous Systems