Generation of functional derivatives in Kohn-Sham density-functional theory