{
    "targets": [
        {
            "target_name": "protobuf",
            "type": "static_library",
            "include_dirs": [
                "2.6.1/protobuf-2.6.1/src",
                "2.6.1/protobuf-2.6.1" # for config.h
            ],
            "sources": [
                "2.6.1/protobuf-2.6.1/src/google/protobuf/*.cc",
                "2.6.1/protobuf-2.6.1/src/google/protobuf/io/*.cc",
                "2.6.1/protobuf-2.6.1/src/google/protobuf/stubs/*.cc"
            ],
            "sources!": [
                "2.6.1/protobuf-2.6.1/src/google/protobuf/*unittest.cc",
                "2.6.1/protobuf-2.6.1/src/google/protobuf/io/*unittest.cc",
                "2.6.1/protobuf-2.6.1/src/google/protobuf/stubs/*unittest.cc",
                "2.6.1/protobuf-2.6.1/src/google/protobuf/test_util.cc",
                "2.6.1/protobuf-2.6.1/src/google/protobuf/test_util_lite.cc"
            ],
            "direct_dependent_settings": {
                "include_dirs": [
                    "2.6.1/protobuf-2.6.1/src"
                ]
            }
        },
        
        # this is the compiler for *.proto files
        {
            "target_name": "protoc",
            "type": "executable",
            "include_dirs": [
                "2.6.1/protobuf-2.6.1" # for config.h
            ],
            "sources": [
                "2.6.1/protobuf-2.6.1/src/google/protobuf/compiler/*.cc",
                "2.6.1/protobuf-2.6.1/src/google/protobuf/compiler/cpp/*.cc",
                "2.6.1/protobuf-2.6.1/src/google/protobuf/compiler/python/*.cc",
                "2.6.1/protobuf-2.6.1/src/google/protobuf/compiler/java/*.cc"
            ],
            "sources!": [
                "2.6.1/protobuf-2.6.1/src/google/protobuf/compiler/*unittest.cc",
                "2.6.1/protobuf-2.6.1/src/google/protobuf/compiler/mock_code_generator.cc",
                "2.6.1/protobuf-2.6.1/src/google/protobuf/compiler/test_plugin.cc",
                "2.6.1/protobuf-2.6.1/src/google/protobuf/compiler/cpp/*unittest.cc",
                "2.6.1/protobuf-2.6.1/src/google/protobuf/compiler/python/*unittest.cc",
                "2.6.1/protobuf-2.6.1/src/google/protobuf/compiler/java/*unittest.cc"
            ],
            "dependencies": [
                "protobuf"
            ]
        },
        
        # this is the library that builds the addressbook.pb.* which is
        # being generated by protoc. This library is used by both example apps.
        # Instead we could have each example app compile addressbook.pb.cc.
        {
            "target_name": "protobuf-example-addressbook",
            "type": "static_library",
            "include_dirs": [
                # I wish we wouldn't need this funky root include dir, but
                # see my comments on the protoc action below.
                "./"
            ],
            "direct_dependent_settings": {
                "include_dirs": [ "./" ]
            },
            "sources": [
                # this file could also be generated manually via
                #   >cd examples
                #   >protoc *.proto --cpp_out=.
                "2.6.1/protobuf-2.6.1/examples/addressbook.pb.cc"
            ],
            "actions": [
                {
                    # See https://code.google.com/p/gyp/wiki/GypLanguageSpecification
                    # for actions: they are typically used for running code
                    # generation tools that provide input for subsequent 
                    # compilation steps. This action here runs the just built 
                    # protoc to generate *.pb.cc+h from *.proto file.
                    # See also http://src.chromium.org/chrome/trunk/src/build/protoc.gypi
                    # for how to create a rule for protoc.
                    "action_name": "protoc",
                    "inputs": [
                        # technically the protoc sources are (indirect) inputs 
                        # too, I don't bother listing these here: inter-target
                        # deps should take care of this (except when the compiler
                        # sources themselves are modified).
                        "2.6.1/protobuf-2.6.1/examples/addressbook.proto"
                    ],
                    "outputs": [
                        "2.6.1/protobuf-2.6.1/examples/addressbook.pb.cc"
                    ],
                    # the cwd for the action is the *.gyp's parent dir.cc
                    # to print the cmd line prefix the action list with 'echo'.
                    # WARNING: a big drawback of this action here is that the 
                    # generated *.pb.cc will contain an #include directive with
                    # relative path 2.6.1/protobuf-2.6.1/examples/*.pb.h.
                    # Means whichever target compiles this *.cc needs the root
                    # dir in its -I list. Potential fixes:
                    #   a) invoke a python wrapper that changes the cwd before
                    #      calling protoc
                    #   b) add a --basedir option or some such to protoc
                    #   c) change gyp to allow specifying a cwd on gyp actions
                    "action": [ "<(PRODUCT_DIR)/protoc", "<@(_inputs)", "--cpp_out=." ],
                    "message": "invoking protoc"
                }
            ],
            "dependencies": [ 
                "protobuf", 
                # to ensure that protoc was built before we build the example:
                "protoc" 
            ]
        },

        {
            "target_name": "protobuf-example-add_person",
            "type": "executable",
            "test": {
                "args": ["my_addressbook.pb"],
                # this example app is interactive, so feed canned text
                # into stdin
                "stdin": "123\nkjell\n\n4125556666\n"
            },
            "include_dirs": [
                "2.6.1/protobuf-2.6.1/examples"
            ],
            "sources": [
                "2.6.1/protobuf-2.6.1/examples/add_person.cc"
            ],
            "dependencies": [ "protobuf", "protobuf-example-addressbook" ]
        },

        {
            "target_name": "protobuf-example-list_people",
            "type": "executable",
            # To run this manually:
            #   >out/release/protobuf-example-add_person my_addressbook.pb
            #   >out/release/protobuf-example-list_people my_addressbook.pb
            # So the list_people example reads the file written by add_person.
            "test": {
                "args": [ "my_addressbook.pb" ]
            },
            "include_dirs": [
                "2.6.1/protobuf-2.6.1/examples"
            ],
            "sources": [
                "2.6.1/protobuf-2.6.1/examples/list_people.cc"
            ],
            "dependencies": [ 
                "protobuf", 
                "protobuf-example-addressbook",
                # this dep only ensures that my_addressbook.pb was written
                # by the add_person example
                "protobuf-example-add_person"
            ]
        }

        
        # To build these tests we need a more convenient rule to turn
        # *.proto into *.pb.?
#        {
#            "target_name": "protobuf-test",
#            "type": "executable",
#            "test": {},
#            "include_dirs": [
#                #"2.6.1/protobuf-2.6.1" # for config.h
#            ],
#            "sources": [
#                "2.6.1/protobuf-2.6.1/src/google/protobuf/*unittest.cc",
#                "2.6.1/protobuf-2.6.1/src/google/protobuf/io/*unittest.cc",
#                "2.6.1/protobuf-2.6.1/src/google/protobuf/stubs/*unittest.cc",
#                "2.6.1/protobuf-2.6.1/src/google/protobuf/test_util.cc"
#            ],
#            "dependencies": [
#                "protobuf",
#                "../googletest/googletest.gyp:*"
#            ]
#        }
    ]
}
