The Thermodynamics of Evaporation and Condensation in Porous Media