Fix race condition on mkdir in codegen

This is done by moving mkdir from codegen into the Makefile.