Perturbative heavy quark fragmentation function throughO(αs2): Gluon initiated contribution