refactor tools/build.c