def generate(env):
    """Add Builders, Scanners and construction variables
    for protoc to the build Environment."""
    try:
        bldr = env['BUILDERS']['Protoc']
    except KeyError:
        action = SCons.Action.Action('$PROTOCOM', '$PROTOCOMSTR')
        bldr = SCons.Builder.Builder(action=action,
                                     emitter=protoc_emitter,
                                     src_suffix='$PROTOCSRCSUFFIX')
        env['BUILDERS']['Protoc'] = bldr

    # pylint: disable=bad-whitespace
    env['PROTOC']          = env.Detect(_PROTOCS) or 'protoc'
    env['PROTOCFLAGS']     = SCons.Util.CLVar('')
    env['PROTOCSRCSUFFIX'] = _PROTOSUFFIX
    # Default proto search path is same dir
    env['PROTOPATH']       = ['.']
    # Default CPP output in same dir
    env['PROTOCPPOUT']     = '.'
    # No default Python output
    env['PROTOPYOUT']      = ''
    proto_cmd     = ['$PROTOC']
    proto_cmd.append('${["--proto_path=%s"%(x) for x in PROTOPATH]}')
    proto_cmd.append('$PROTOCFLAGS')
    proto_cmd.append('${PROTOCPPOUT and "--cpp_out=%s"%(PROTOCPPOUT) or ""}')
    proto_cmd.append('${PROTOPYOUT and "--python_out=%s"%(PROTOPYOUT) or ""}')
    proto_cmd.append('${SOURCES}')
    env['PROTOCOM'] = ' '.join(proto_cmd)

    # Add the proto scanner (if it wasn't added already)
    env.AppendUnique(SCANNERS=SCons.Scanner.Scanner(function=protoc_scanner,
                                                    skeys=[_PROTOSUFFIX]))