Statistical mechanics of the self-gravitating gas: I. Thermodynamic limit and phase diagrams