Population nucleosynthesis in single and binary stars. I. Model