#!/usr/bin/env python import sys import importlib import os import shutil import platform # Nuclex SCons libraries sys.path.append('../../BuildSystem/scons') nuclex = importlib.import_module('nuclex') archive = importlib.import_module('archive') # ----------------------------------------------------------------------------------------------- # universal_tbb_target_name = 'tbb' environment = nuclex.create_cplusplus_environment() #environment['ENV'] = os.environ #environment['CXX'] = 'clang++' # ----------------------------------------------------------------------------------------------- # # Step 0: preparatory work # Fetch the list of headers used when compiling tbb_headers_file = environment.File('tbb-headers') tbb_header_files = archive.split_lines(tbb_headers_file.get_text_contents()) # Fetch the list of sources to compile tbb tbb_sources_file = environment.File('tbb-sources') tbb_source_files = archive.split_lines(tbb_sources_file.get_text_contents()) # ----------------------------------------------------------------------------------------------- # # Step 1: Download the current release # Fetch the available download URLs from a file download_url_file = environment.File('tbb-download-urls') download_urls = archive.split_lines(download_url_file.get_text_contents()) # Determine the target filename for the download (below 'downloads' folder) archive_filename = os.path.basename(download_urls[0]) archive_file = environment.File(os.path.join('downloads', archive_filename)) # Tell SCons how to "produce" the downloaded archive (by calling wget) if not archive_file.exists(): download_archive = environment.Command( source = download_url_file, #action = 'wget ' + download_urls[0] + ' --output-document=$TARGET', action = archive.download_url_in_urlfile, target = archive_file ) # ----------------------------------------------------------------------------------------------- # # Step 2: Extract the release into the build directory def extract_compressed_tarball(target, source, env): """Extracts the distribution .tar.gz archive and applies a patch that ensures the same headers will work on Windows and average Linux distributions. @param target Output files, not used by the function but passed along so SCons can look at them and knows its dependency tree @param source Source files, expected to be an array containing the .tar.gz path and the unified diff path @param env SCons build environment""" print(str(source[0])) build_directory = env.Dir('build') print(str(build_directory)) archive.extract_compressed_tarball(str(source[0]), str(build_directory), 1) # SCons is too stupid to be told to copy the frigging file AFTER # extraction, so we'll work around the sucker: shutil.copyfile( 'version_string.ver', 'build/src/version_string.ver' ) # Tell SCons how to "produce" the sources & headers (by calling tar) extract_archive = environment.Command( source = archive_file, #action = 'tar --extract --gzip --strip-components=1 --file=$SOURCE --directory=build', action = extract_compressed_tarball, target = tbb_source_files + tbb_header_files ) # ----------------------------------------------------------------------------------------------- # # Step 3: Compile the TBB library tbb_environment = environment.Clone() del tbb_environment['SOURCE_DIRECTORY'] # We define the sources ourselves del tbb_environment['HEADER_DIRECTORY']; # Yep, build environment is still stupid. Include private headers by relative path, guys! tbb_environment.add_include_directory('build/src') tbb_environment.add_include_directory('build/src/rml/include') tbb_environment.add_include_directory('build/include') tbb_environment.add_include_directory('build/src/tbbmalloc') # Whether TBB will throws exceptions. This is checked in the headers as well, so # library users will have to set this constant too match the build settings. tbb_environment.add_preprocessor_constant('TBB_USE_EXCEPTIONS') # ITT is Instrumentation & Tracing Technology. # Enabling it will generate some TBB instrumentation marks to be picked up by # a supporting profile (read: Intel VTune) to provide enhanced profiling data. tbb_environment.add_preprocessor_constant('DO_ITT_NOTIFY') # Select the OS threading API that will be used by TBB. This is not used in any public # header, so users of the library do not have to care (except perhaps -lpthread on Linux # to link the pthread library) if platform.system() == 'Windows': tbb_environment.add_preprocessor_constant('USE_WINTHREAD') else: tbb_environment.add_preprocessor_constant('USE_PTHREAD') # Only for building. Old, no longer wanted stuff is included for backwards # compatibility. This prevents the library build from spamming deprecation messages. tbb_environment.add_preprocessor_constant('TBB_SUPPRESS_DEPRECATED_MESSAGES', '1') # Controlled internally. Do not set. #tbb_environment.add_preprocessor_constant('__TBB_USE_OPTIONAL_RTTI', 1) # Should only be set when building the TBB library. # Never set this when you're just using the library. tbb_environment.add_preprocessor_constant('__TBB_BUILD', '1') # Same for the tbbmalloc library. #tbb_environment.add_preprocessor_constant('__TBBMALLOC_BUILD', '1') # Directory containing the TBB source files that need to be compiled tbb_environment.add_source_directory( 'build', tbb_source_files, scons_issue_2908_workaround_needed = True ) # Compilation step compile_tbb_library = tbb_environment.build_library( universal_tbb_target_name, static = True ) # ----------------------------------------------------------------------------------------------- # # Step 4: Put the header in the main package directory for header in tbb_header_files: if header.startswith('build/include/'): install_path = os.path.join('Include', header[14:]) environment.InstallAs(install_path, header) # ----------------------------------------------------------------------------------------------- #