  We develop the analytical theory that describes simultaneous transmission of
several photons through a waveguide coupled to a $\Lambda$-type atom. We show
that after transmission of a short few-photon pulse, the final state of the
atom and all the photons is a genuine multipartite entangled state belonging to
the W class. The parameters of the input pulse are optimized to maximize the
efficiency of three- and four-partite W-state production.
