#!/usr/bin/env python import sys import importlib import os import shutil import platform # Nuclex SCons libraries sys.path.append('../../References/scripts/scons') nuclex = importlib.import_module('nuclex') archive = importlib.import_module('archive') # ----------------------------------------------------------------------------------------------- # universal_sdl_target_name = 'sdl' environment = nuclex.create_cplusplus_environment() # ----------------------------------------------------------------------------------------------- # # Step 0: preparatory work # Fetch the list of headers used when compiling sdl_headers_file = environment.File('sdl-headers') sdl_header_files = archive.split_lines(sdl_headers_file.get_text_contents()) # Fetch the list of sources to compile sdl sdl_sources_file = environment.File('sdl-sources') sdl_source_files = archive.split_lines(sdl_sources_file.get_text_contents()) if platform.system() == 'Windows': sdl_source_files.append('build/src/thread/windows/SDL_sysmutex.c') sdl_source_files.append('build/src/joystick/windows/SDL_sysjoystick.c') sdl_source_files.append('build/src/timer/windows/SDL_systimer.c') sdl_source_files.append('build/src/thread/windows/SDL_syssem.c') sdl_source_files.append('build/src/loadso/windows/SDL_sysloadso.c') sdl_source_files.append('build/src/filesystem/windows/SDL_sysfilesystem.c') sdl_source_files.append('build/src/thread/windows/SDL_systhread.c') sdl_source_files.append('build/src/power/windows/SDL_syspower.c') sdl_source_files.append('build/src/thread/windows/SDL_systls.c') else: sdl_source_files.append('build/src/thread/pthread/SDL_sysmutex.c') sdl_source_files.append('build/src/joystick/linux/SDL_sysjoystick.c') sdl_source_files.append('build/src/timer/unix/SDL_systimer.c') sdl_source_files.append('build/src/thread/pthread/SDL_syssem.c') sdl_source_files.append('build/src/loadso/dlopen/SDL_sysloadso.c') sdl_source_files.append('build/src/filesystem/unix/SDL_sysfilesystem.c') sdl_source_files.append('build/src/thread/pthread/SDL_systhread.c') sdl_source_files.append('build/src/power/linux/SDL_syspower.c') sdl_source_files.append('build/src/thread/pthread/SDL_systls.c') sdl_source_files.append('build/src/audio/dsp/SDL_dspaudio.c') sdl_source_files.append('build/src/audio/alsa/SDL_alsa_audio.c') sdl_source_files.append('build/src/thread/pthread/SDL_systhread.c') sdl_source_files.append('build/src/video/wayland/SDL_waylandvideo.c') #sdl_source_files.append('build/src/video/kmsdrm/SDL_kmsdrmvideo.c') sdl_source_files.append('build/src/core/linux/SDL_udev.c') sdl_source_files.append('build/src/thread/SDL_thread.c') sdl_source_files.append('build/src/timer/SDL_timer.c') sdl_source_files.append('build/src/video/x11/SDL_x11messagebox.c') sdl_source_files.append('build/src/joystick/steam/SDL_steamcontroller.c') # ----------------------------------------------------------------------------------------------- # # Step 1: Download the current release # Fetch the available download URLs from a file download_url_file = environment.File('sdl-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 it already exists, we're satisfied with it (under the assumption, that nobody # would create a different release of the sources under the same file name) 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""" archive.extract_compressed_tarball(str(source[0]), 'build', 1) # SCons is too stupid to be told to copy the frigging file AFTER # extraction, so we'll work around the sucker: shutil.copyfile( 'SDL_config_linux.h', 'build/include/SDL_config_linux.h' ) archive.apply_patch(str(source[1])) sdl_header_files.append('build/include/SDL_config_linux.h') # Tell SCons how to "produce" the sources & headers (by calling tar) extract_archive = environment.Command( source = [ archive_file, 'linux.patch' ], #action = 'tar --extract --gzip --strip-components=1 --file=$SOURCE --directory=build', action = extract_compressed_tarball, target = sdl_source_files + sdl_header_files ) # ----------------------------------------------------------------------------------------------- # # Step 3: Compile the sdl library sdl_environment = environment.Clone() del sdl_environment['SOURCE_DIRECTORY'] # We define the sources ourselves sdl_environment['HEADER_DIRECTORY'] = 'build/include' #sdl_environment.add_include_directory('build/src/sdl') sdl_environment.add_source_directory( 'build', sdl_source_files, scons_issue_2908_workaround_needed = True ) sdl_environment.add_preprocessor_constant('X_HAVE_UTF8_STRING') #sdl_environment.add_project('../zlib') compile_sdl_library = sdl_environment.build_library( universal_sdl_target_name, static = True ) # ----------------------------------------------------------------------------------------------- # # Step 4: Put the headers in the main package directory for header in sdl_header_files: if header.startswith('build/include/'): install_path = os.path.join('Include/SDL2', header[14:]) environment.InstallAs(install_path, header) # ----------------------------------------------------------------------------------------------- #