<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build_cookbook(build_config, templatepack_path, cookbooks_home, force=False):
 """Build a cookbook from a fastfood.json file. Can build on an existing cookbook, otherwise this will create a new cookbook for you based on your templatepack. """

    with open(build_config) as cfg:
        cfg = json.load(cfg)

    cookbook_name = cfg['name']
    template_pack = pack.TemplatePack(templatepack_path)

    written_files = []
    cookbook = create_new_cookbook(cookbook_name, cookbooks_home)

    for stencil_definition in cfg['stencils']:

        selected_stencil_set_name = stencil_definition.get('stencil_set')
        stencil_set = template_pack.load_stencil_set(selected_stencil_set_name)

        selected_stencil_name = _determine_selected_stencil(
            stencil_set,
            stencil_definition
        )

        stencil = stencil_set.get_stencil(selected_stencil_name,
                                          **stencil_definition)

        updated_cookbook = process_stencil(
            cookbook,
            cookbook_name,  # in case no metadata.rb yet
            template_pack,
            force,
            stencil_set,
            stencil,
            written_files
        )

    return written_files, updated_cookbook