Formation of the circumstellar shell around SN 1987A