# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

__doc__ = """
Configuration for building net.lib / libnet.a.
"""

Import('env')

env = env.Clone()

env.ApplySConscript([
    '$BZIP2_DIR/using_bzip2.scons',
    '$CHROME_SRC_DIR/build/using_googleurl.scons',
    '$CHROME_SRC_DIR/build/using_v8.scons',
    '$GRIT_DIR/build/using_generated_resources.scons',
    '$GTEST_DIR/../using_gtest.scons',
    '$ICU38_DIR/using_icu38.scons',
    '$MODP_B64_DIR/using_modp_b64.scons',
    '$SDCH_DIR/using_sdch.scons',
    '$ZLIB_DIR/using_zlib.scons',
])

input_files = ChromeFileList([
  MSVSFilter('base', [
    'base/address_list.cc',
    'base/address_list.h',
    'base/auth.h',
    'base/base64.cc',
    'base/base64.h',
    'base/bzip2_filter.cc',
    'base/bzip2_filter.h',
    'base/cert_status_flags.cc',
    'base/cert_status_flags.h',
    'base/cert_verifier.cc',
    'base/cert_verifier.h',
    'base/cert_verify_result.h',
    'base/client_socket.cc',
    'base/client_socket.h',
    'base/client_socket_factory.cc',
    'base/client_socket_factory.h',
    'base/client_socket_handle.cc',
    'base/client_socket_handle.h',
    'base/client_socket_pool.cc',
    'base/client_socket_pool.h',
    'base/completion_callback.h',
    'base/connection_type_histograms.cc',
    'base/connection_type_histograms.h',
    'base/cookie_monster.cc',
    'base/cookie_monster.h',
    'base/cookie_policy.cc',
    'base/cookie_policy.h',
    'base/data_url.cc',
    'base/data_url.h',
    'base/directory_lister.cc',
    'base/directory_lister.h',
    'base/dns_resolution_observer.cc',
    'base/dns_resolution_observer.h',
    'base/effective_tld_names.cc',
    'base/escape.cc',
    'base/escape.h',
    'base/ev_root_ca_metadata.cc',
    'base/ev_root_ca_metadata.h',
    'base/file_stream.h',
    'base/file_stream_win.cc',
    'base/filter.cc',
    'base/filter.h',
    'base/gzip_filter.cc',
    'base/gzip_filter.h',
    'base/gzip_header.cc',
    'base/gzip_header.h',
    'base/host_resolver.cc',
    'base/host_resolver.h',
    'base/io_buffer.cc',
    'base/io_buffer.h',
    'base/listen_socket.cc',
    'base/listen_socket.h',
    'base/load_flags.h',
    'base/mime_sniffer.cc',
    'base/mime_sniffer.h',
    'base/mime_util.cc',
    'base/mime_util.h',
    'base/net_error_list.h',
    'base/net_errors.cc',
    'base/net_errors.h',
    'base/net_module.cc',
    'base/net_module.h',
    'base/net_resources.h',
    'base/net_util.cc',
    'base/net_util.h',
    'base/net_util_win.cc',
    'base/platform_mime_util.h',
    'base/platform_mime_util_win.cc',
    'build/precompiled_net.cc',
    'build/precompiled_net.h',
    'base/registry_controlled_domain.cc',
    'base/registry_controlled_domain.h',
    'base/scoped_cert_chain_context.h',
    'base/sdch_filter.cc',
    'base/sdch_filter.h',
    'base/sdch_manager.cc',
    'base/sdch_manager.h',
    'base/socket.h',
    'base/ssl_client_socket.h',
    'base/ssl_client_socket_win.cc',
    'base/ssl_client_socket_win.h',
    'base/ssl_config_service.cc',
    'base/ssl_config_service.h',
    'base/ssl_info.h',
    'base/ssl_test_util.cc',
    'base/tcp_client_socket.h',
    'base/tcp_client_socket_win.cc',
    'base/telnet_server.cc',
    'base/telnet_server.h',
    'base/upload_data.cc',
    'base/upload_data.h',
    'base/upload_data_stream.cc',
    'base/upload_data_stream.h',
    'base/wininet_util.cc',
    'base/wininet_util.h',
    'base/winsock_init.cc',
    'base/winsock_init.h',
    'base/x509_certificate.cc',
    'base/x509_certificate.h',
    'base/x509_certificate_win.cc',
  ]),
  MSVSFilter('url_request', [
    'url_request/mime_sniffer_proxy.cc',
    'url_request/mime_sniffer_proxy.h',
    'url_request/url_request.cc',
    'url_request/url_request.h',
    'url_request/url_request_about_job.cc',
    'url_request/url_request_about_job.h',
    'url_request/url_request_context.h',
    'url_request/url_request_error_job.cc',
    'url_request/url_request_error_job.h',
    'url_request/url_request_file_dir_job.cc',
    'url_request/url_request_file_dir_job.h',
    'url_request/url_request_file_job.cc',
    'url_request/url_request_file_job.h',
    'url_request/url_request_filter.cc',
    'url_request/url_request_filter.h',
    'url_request/url_request_ftp_job.cc',
    'url_request/url_request_ftp_job.h',
    'url_request/url_request_http_job.cc',
    'url_request/url_request_http_job.h',
    'url_request/url_request_inet_job.cc',
    'url_request/url_request_inet_job.h',
    'url_request/url_request_job.cc',
    'url_request/url_request_job.h',
    'url_request/url_request_job_manager.cc',
    'url_request/url_request_job_manager.h',
    'url_request/url_request_job_metrics.cc',
    'url_request/url_request_job_metrics.h',
    'url_request/url_request_job_tracker.cc',
    'url_request/url_request_job_tracker.h',
    'url_request/url_request_simple_job.cc',
    'url_request/url_request_simple_job.h',
    'url_request/url_request_status.h',
    'url_request/url_request_test_job.cc',
    'url_request/url_request_test_job.h',
    'url_request/url_request_view_cache_job.cc',
    'url_request/url_request_view_cache_job.h',
  ]),
  MSVSFilter('http', [
    'http/des.cc',
    'http/des.h',
    'http/http_atom_list.h',
    'http/http_auth.cc',
    'http/http_auth.h',
    'http/http_auth_cache.cc',
    'http/http_auth_cache.h',
    'http/http_auth_handler.h',
    'http/http_auth_handler.cc',
    'http/http_auth_handler_basic.cc',
    'http/http_auth_handler_basic.h',
    'http/http_auth_handler_digest.cc',
    'http/http_auth_handler_digest.h',
    'http/http_auth_handler_ntlm.cc',
    'http/http_auth_handler_ntlm.h',
    'http/http_cache.cc',
    'http/http_cache.h',
    'http/http_chunked_decoder.cc',
    'http/http_chunked_decoder.h',
    'http/http_network_layer.cc',
    'http/http_network_layer.h',
    'http/http_network_session.h',
    'http/http_network_transaction.cc',
    'http/http_network_transaction.h',
    'http/http_request_info.h',
    'http/http_response_headers.cc',
    'http/http_response_headers.h',
    'http/http_response_info.cc',
    'http/http_response_info.h',
    'http/http_transaction.h',
    'http/http_transaction_factory.h',
    'http/http_util.cc',
    'http/http_util.h',
    'http/http_vary_data.cc',
    'http/http_vary_data.h',
    'http/md4.cc',
    'http/md4.h',
  ]),
  MSVSFilter('disk_cache', [
    'disk_cache/addr.cc',
    'disk_cache/addr.h',
    'disk_cache/backend_impl.cc',
    'disk_cache/backend_impl.h',
    'disk_cache/block_files.cc',
    'disk_cache/block_files.h',
    'disk_cache/cache_util.h',
    'disk_cache/cache_util_win.cc',
    'disk_cache/disk_cache.h',
    'disk_cache/disk_format.h',
    'disk_cache/entry_impl.cc',
    'disk_cache/entry_impl.h',
    'disk_cache/errors.h',
    'disk_cache/eviction.cc',
    'disk_cache/eviction.h',
    'disk_cache/file.h',
    'disk_cache/file_block.h',
    'disk_cache/file_lock.cc',
    'disk_cache/file_lock.h',
    'disk_cache/file_win.cc',
    'disk_cache/hash.cc',
    'disk_cache/hash.h',
    'disk_cache/mapped_file.h',
    'disk_cache/mapped_file_win.cc',
    'disk_cache/mem_backend_impl.cc',
    'disk_cache/mem_backend_impl.h',
    'disk_cache/mem_entry_impl.cc',
    'disk_cache/mem_entry_impl.h',
    'disk_cache/mem_rankings.cc',
    'disk_cache/mem_rankings.h',
    'disk_cache/rankings.cc',
    'disk_cache/rankings.h',
    'disk_cache/stats.cc',
    'disk_cache/stats.h',
    'disk_cache/stats_histogram.cc',
    'disk_cache/stats_histogram.h',
    'disk_cache/storage_block-inl.h',
    'disk_cache/storage_block.h',
    'disk_cache/trace.cc',
    'disk_cache/trace.h',
  ]),
  MSVSFilter('proxy', [
    'proxy/proxy_config.cc',
    'proxy/proxy_config.h',
    'proxy/proxy_config_service.h',
    'proxy/proxy_config_service_fixed.h',
    'proxy/proxy_config_service_win.cc',
    'proxy/proxy_config_service_win.h',
    'proxy/proxy_info.cc',
    'proxy/proxy_info.h',
    'proxy/proxy_list.cc',
    'proxy/proxy_list.h',
    'proxy/proxy_resolver.h',
    'proxy/proxy_resolver_script.h',
    'proxy/proxy_resolver_v8.cc',
    'proxy/proxy_resolver_winhttp.cc',
    'proxy/proxy_resolver_winhttp.h',
    'proxy/proxy_retry_info.h',
    'proxy/proxy_script_fetcher.cc',
    'proxy/proxy_script_fetcher.h',
    'proxy/proxy_server.cc',
    'proxy/proxy_server.h',
    'proxy/proxy_service.cc',
    'proxy/proxy_service.h',
  ]),
  MSVSFilter('ftp', [
    'ftp/ftp_auth_cache.cc',
    'ftp/ftp_auth_cache.h',
    'ftp/ftp_network_layer.cc',
    'ftp/ftp_network_layer.h',
    'ftp/ftp_network_session.h',
    'ftp/ftp_network_transaction.cc',
    'ftp/ftp_network_transaction.h',
    'ftp/ftp_request_info.h',
    'ftp/ftp_response_info.h',
    'ftp/ftp_transaction.h',
    'ftp/ftp_transaction_factory.h',
  ]),
])

if env.Bit('posix'):
  # Remove files that still need to be ported from the input_files list.
  # TODO(port): delete files from this list as they get ported.
  input_files.Remove(
      'base/ssl_config_service.cc',
      'url_request/url_request_ftp_job.cc',
  )

if not env.Bit('windows'):
  # Remove windows-specific files on non-Windows platforms.
  # TODO(sgk):
  # Remove the windows-specific files from the input_files list above
  # and turn this back in to an add-on-Windows list (like we used to)
  # once we're comfortable re-ordering the files in the generated
  # .vcproj file(s).
  input_files.Remove(
      'base/file_stream_win.cc',
      'base/net_util_win.cc',
      'base/platform_mime_util_win.cc',
      'base/ssl_client_socket_win.cc',
      'base/tcp_client_socket_win.cc',
      'base/wininet_util.cc',
      'base/winsock_init.cc',
      'base/x509_certificate_win.cc',
      'build/precompiled_net.cc',
      'disk_cache/cache_util_win.cc',
      'disk_cache/file_win.cc',
      'disk_cache/mapped_file_win.cc',
      'proxy/proxy_config_service_win.cc',
      'proxy/proxy_resolver_winhttp.cc',
      'url_request/url_request_inet_job.cc',
  )

if env.Bit('mac'):
  input_files.Extend([
      'base/platform_mime_util_mac.cc',
      'base/ssl_client_socket_mac.cc',
      'base/x509_certificate_mac.cc',
      'proxy/proxy_resolver_mac.cc',
  ])

if env.Bit('linux'):
  input_files.Extend([
      'base/nss_memio.c',
      # TODO(tc): gnome-vfs? xdgmime? /etc/mime.types?
      'base/platform_mime_util_linux.cc',
      'base/ssl_client_socket_nss.cc',
      'base/x509_certificate_nss.cc',
  ])

if env.Bit('posix'):
  input_files.Extend([
      'base/file_stream_posix.cc',
      'base/net_util_posix.cc',
      'base/tcp_client_socket_libevent.cc',
      'disk_cache/cache_util_posix.cc',
      'disk_cache/file_posix.cc',
      'disk_cache/mapped_file_posix.cc',
  ])

if env.Bit('windows'):
  # TODO(bradnelson): This step generates file precompiled_net.pch.ib_tag
  #                   possibly only on incredibuild, scons doesn't know this.
  env_p = env.Clone()
  # TODO(sgk):  for now, add the same _LIB flag that Hammer adds to
  #             the other .obj files
  env_p.Append(CCFLAGS='/Ylnet',
               CPPDEFINES=['_LIB'])
  pch, obj = env_p.PCH('precompiled_net.pch', 'build/precompiled_net.cc')
  env['PCH'] = pch
  env['PCHSTOP'] = 'precompiled_net.h'
  env.Append(CCPCHFLAGS = ['/FIprecompiled_net.h'])
  input_files.Replace('build/precompiled_net.cc', obj)

lib = env.ChromeLibrary('net', input_files)

p = env.ChromeMSVSProject('$NET_DIR/build/net.vcproj',
                          dest='$CHROME_SRC_DIR/net/build/net.vcproj',
                          guid='{326E9795-E760-410A-B69A-3F79DB3F5243}',
                          keyword='Win32Proj',
                          dependencies = [
                              '$NET_DIR/build/net_resources.vcproj',
                              '$NET_DIR/build/tld_cleanup.vcproj',
                          ],
                          # TODO: restore when we can derive all info,
                          # on all platforms, from the windows build targets.
                          #buildtargets=[lib[0]],
                          files=input_files,
                          ConfigurationType='4')

p.AddToolFile('build/convert_tld_data.rules')

p.AddConfig('Debug|Win32',
            InheritedPropertySheets=[
                '$(SolutionDir)../build/debug.vsprops',
                './net.vsprops',
            ],
            tools=[
                'VCPreBuildEventTool',
                'VCCustomBuildTool',
                'Convert TLD Data File',
                'VCXMLDataGeneratorTool',
                'VCWebServiceProxyGeneratorTool',
                'VCMIDLTool',
                MSVSTool('VCCLCompilerTool',
                         PrecompiledHeaderThrough='precompiled_net.h',
                         ForcedIncludeFiles='precompiled_net.h',
                         UsePrecompiledHeader='2'),
                'VCManagedResourceCompilerTool',
                'VCResourceCompilerTool',
                'VCPreLinkEventTool',
                'VCLibrarianTool',
                'VCALinkTool',
                'VCXDCMakeTool',
                'VCBscMakeTool',
                'VCFxCopTool',
                'VCPostBuildEventTool',
            ])

p.AddConfig('Release|Win32',
            InheritedPropertySheets=[
                '$(SolutionDir)../build/release.vsprops',
                './net.vsprops',
            ],
            tools=[
                'VCPreBuildEventTool',
                'VCCustomBuildTool',
                'Convert TLD Data File',
                'VCXMLDataGeneratorTool',
                'VCWebServiceProxyGeneratorTool',
                'VCMIDLTool',
                'VCCLCompilerTool',
                'VCManagedResourceCompilerTool',
                'VCResourceCompilerTool',
                'VCPreLinkEventTool',
                'VCLibrarianTool',
                'VCALinkTool',
                'VCXDCMakeTool',
                'VCBscMakeTool',
                'VCFxCopTool',
                'VCPostBuildEventTool',
            ])

# TODO(sgk):  remove when we can derive this information
p.AddFileConfig('build/precompiled_net.cc',
                'Debug|Win32',
                tools=[
                    MSVSTool('VCCLCompilerTool',
                             UsePrecompiledHeader='1'),
                ])

# TODO(sgk):  remove when we can derive this information
p.AddFileConfig('build/precompiled_net.cc',
                'Release|Win32',
                ExcludedFromBuild='true',
                tools=[
                    'VCCLCompilerTool',
                ])