Theory of second-harmonic generation in an inhomogeneous hot plasma