# -*- Python -*-

#
# Copyright 2014 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

cc_library(
    name = "libprotobuf-lite",
    srcs = [
        "extension_set.cc",
        "generated_message_util.cc",
        "io/coded_stream.cc",
        "io/zero_copy_stream.cc",
        "io/zero_copy_stream_impl_lite.cc",
        "message_lite.cc",
        "repeated_field.cc",
        "stubs/atomicops_internals_x86_gcc.cc",
        "stubs/atomicops_internals_x86_msvc.cc",
        "stubs/common.cc",
        "stubs/once.cc",
        "stubs/stringprintf.cc",
        "wire_format_lite.cc",
    ],
    hdrs = [
        "io/coded_stream_inl.h",
        "stubs/hash.h",
        "stubs/stringprintf.h",
    ],
    includes = [
        "../..",
    ],
    deps = [
        "//:config",
    ],
)

cc_library(
    name = "libprotobuf",
    srcs = [
        "compiler/importer.cc",
        "compiler/parser.cc",
        "descriptor.cc",
        "descriptor.pb.cc",
        "descriptor_database.cc",
        "dynamic_message.cc",
        "extension_set_heavy.cc",
        "generated_message_reflection.cc",
        "io/gzip_stream.cc",
        "io/printer.cc",
        "io/tokenizer.cc",
        "io/zero_copy_stream_impl.cc",
        "message.cc",
        "reflection_ops.cc",
        "service.cc",
        "stubs/structurally_valid.cc",
        "stubs/strutil.cc",
        "stubs/substitute.cc",
        "text_format.cc",
        "unknown_field_set.cc",
        "wire_format.cc",
    ],
    hdrs = [
        "stubs/strutil.h",
        "stubs/substitute.h",
    ],
    deps = [":libprotobuf-lite"],
)

cc_library(
    name = "libprotoc",
    srcs = [
        "compiler/code_generator.cc",
        "compiler/command_line_interface.cc",
        "compiler/cpp/cpp_enum.cc",
        "compiler/cpp/cpp_enum_field.cc",
        "compiler/cpp/cpp_extension.cc",
        "compiler/cpp/cpp_field.cc",
        "compiler/cpp/cpp_file.cc",
        "compiler/cpp/cpp_generator.cc",
        "compiler/cpp/cpp_helpers.cc",
        "compiler/cpp/cpp_message.cc",
        "compiler/cpp/cpp_message_field.cc",
        "compiler/cpp/cpp_primitive_field.cc",
        "compiler/cpp/cpp_service.cc",
        "compiler/cpp/cpp_string_field.cc",
        "compiler/java/java_doc_comment.cc",
        "compiler/java/java_enum.cc",
        "compiler/java/java_enum_field.cc",
        "compiler/java/java_extension.cc",
        "compiler/java/java_field.cc",
        "compiler/java/java_file.cc",
        "compiler/java/java_generator.cc",
        "compiler/java/java_helpers.cc",
        "compiler/java/java_message.cc",
        "compiler/java/java_message_field.cc",
        "compiler/java/java_primitive_field.cc",
        "compiler/java/java_service.cc",
        "compiler/java/java_string_field.cc",
        "compiler/plugin.cc",
        "compiler/plugin.pb.cc",
        "compiler/python/python_generator.cc",
        "compiler/subprocess.cc",
        "compiler/zip_writer.cc",
    ],
    hdrs = [
        "compiler/cpp/cpp_enum.h",
        "compiler/cpp/cpp_enum_field.h",
        "compiler/cpp/cpp_extension.h",
        "compiler/cpp/cpp_field.h",
        "compiler/cpp/cpp_file.h",
        "compiler/cpp/cpp_helpers.h",
        "compiler/cpp/cpp_message.h",
        "compiler/cpp/cpp_message_field.h",
        "compiler/cpp/cpp_options.h",
        "compiler/cpp/cpp_primitive_field.h",
        "compiler/cpp/cpp_service.h",
        "compiler/cpp/cpp_string_field.h",
        "compiler/java/java_doc_comment.h",
        "compiler/java/java_enum.h",
        "compiler/java/java_enum_field.h",
        "compiler/java/java_extension.h",
        "compiler/java/java_field.h",
        "compiler/java/java_file.h",
        "compiler/java/java_helpers.h",
        "compiler/java/java_message.h",
        "compiler/java/java_message_field.h",
        "compiler/java/java_primitive_field.h",
        "compiler/java/java_service.h",
        "compiler/java/java_string_field.h",
        "compiler/subprocess.h",
        "compiler/zip_writer.h",
    ],
    linkopts = ["-lm"],
    deps = [":libprotobuf"],
)

cc_binary(
    name = "protoc",
    srcs = ["compiler/main.cc"],
    deps = [":libprotoc"],
)

# This rule is necessary for Protobuf v3.0
genrule(
    name = "pbconfig_h",
    srcs = [
        "//:config.h",
        "//:config.h.include",
    ],
    outs = ["stubs/pbconfig.h"],
    cmd = "(echo \"// Note: Google Protobuf internal only. Do NOT include.\" && " +
          "(cat $(location //:config.h) | grep -f $(location //:config.h.include) | " +
          "sed 's,#define , #define GOOGLE_PROTOBUF_,')) > $@",
)
