A systematic density functional approach to the mean field theory of smectics