It has never been revealed in detail how he was made. The Mark I was constructed by Professor Marius at some time before the events of "The Invisible Enemy" & given to the Doctor & Leela at the end of that story. Marks II - IV were constructed by the Doctor. Some details of his components were revealed in "A Girl's Best Friend", the pilot (& only) episode of the proposed series K9 and Company. For further information, see K9.