Statistical mechanics of static granular packings under gravity