From 5bfade3b6dad911f1976ac0f6fcd18046798d9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Roff=C3=A9?= Date: Sun, 30 Jan 2022 10:59:18 +0100 Subject: [PATCH 1/5] Revert "RendererGl: Make shaders compatible with Nouveau drivers on Linux" This reverts commit 5025f3d71c21159c2c6bd17eda5d875d52f73996. --- app/renderer_gl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/renderer_gl.cpp b/app/renderer_gl.cpp index 7c47566..6c0123c 100644 --- a/app/renderer_gl.cpp +++ b/app/renderer_gl.cpp @@ -15,9 +15,9 @@ namespace { // clang-format off const char *vertexShader = - "#version 130\n" - "in vec3 aPos;" - "in vec2 aTexCoord;" + "#version 330 core\n" + "layout (location = 0) in vec3 aPos;" + "layout (location = 1) in vec2 aTexCoord;" "uniform mat4 scaleMatrix;" "out vec2 TexCoord;" @@ -29,7 +29,7 @@ const char *vertexShader = "}"; const char *fragmentShader = - "#version 130\n" + "#version 330 core\n" "out vec4 FragColor;" "in vec3 ourColor;" From ae0893a6f4f93cff917fe81d55ae3c0687cb17b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Roff=C3=A9?= Date: Sun, 30 Jan 2022 10:44:46 +0100 Subject: [PATCH 2/5] Some cleanup --- core/src/snesimpl.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/src/snesimpl.h b/core/src/snesimpl.h index b675d6a..c938751 100644 --- a/core/src/snesimpl.h +++ b/core/src/snesimpl.h @@ -46,12 +46,9 @@ class SnesImpl int renderSingleFrame(bool renderPpu = true) final; void setController1(const Controller& controller) final; - ; void saveState(const std::string& path) final; - ; void loadState(const std::string& path) final; - ; // Scheduler methods void resumeTask(SchedulerTask* task, int cycles); From 25c11258e4d421f8989e454eacfa631aa57b0eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Roff=C3=A9?= Date: Sat, 21 Aug 2021 13:19:06 +0200 Subject: [PATCH 3/5] build: Fix build with clang 13 --- app/CMakeLists.txt | 1 - app/frontend_sdl2/controller_sdl2.cpp | 2 +- app/recorder/recorder.h | 2 +- app/recorder/videorecorder.h | 1 - core/include/msfce/core/log.h | 5 +++++ core/src/controllerports.cpp | 2 +- core/src/membus.cpp | 3 +-- core/src/membus.h | 1 - core/src/ppu.h | 2 +- core/src/snesimpl.cpp | 2 +- core/src/snesimpl.h | 2 +- tests/CMakeLists.txt | 4 ++++ 12 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index e4fb982..516221d 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -93,7 +93,6 @@ target_link_libraries(msfce ${PKG_SWSCALE_LIBRARIES} ${PKG_SWRESAMPLE_LIBRARIES} - -lstdc++fs -lpthread ) diff --git a/app/frontend_sdl2/controller_sdl2.cpp b/app/frontend_sdl2/controller_sdl2.cpp index 1bbb24a..759ad67 100644 --- a/app/frontend_sdl2/controller_sdl2.cpp +++ b/app/frontend_sdl2/controller_sdl2.cpp @@ -10,7 +10,7 @@ namespace { struct SnesControllerMapping { const char* name; - off64_t offset; + off_t offset; }; // clang-format off diff --git a/app/recorder/recorder.h b/app/recorder/recorder.h index 3a6518f..abf1930 100644 --- a/app/recorder/recorder.h +++ b/app/recorder/recorder.h @@ -15,7 +15,7 @@ namespace msfce::recorder { struct Frame; -struct FrameRecorder; +class FrameRecorder; class Recorder : public msfce::core::Renderer { public: diff --git a/app/recorder/videorecorder.h b/app/recorder/videorecorder.h index fb0c147..eb96146 100644 --- a/app/recorder/videorecorder.h +++ b/app/recorder/videorecorder.h @@ -58,7 +58,6 @@ class VideoRecorder : public FrameRecorderBackend { AVStream* m_AudioStream = nullptr; AVAudioFifo* m_AudioFifo = nullptr; SwrContext* m_AudioSwrCtx = nullptr; - int m_AudioFrameIdx = 0; int m_AudioInSamples = 0; int m_AudioOutSamples = 0; int m_AudioSnesFrameSize = 0; diff --git a/core/include/msfce/core/log.h b/core/include/msfce/core/log.h index f35f180..dbdba49 100644 --- a/core/include/msfce/core/log.h +++ b/core/include/msfce/core/log.h @@ -41,7 +41,12 @@ enum LogLevel : uint32_t { typedef void ( *log_cb_t)(uint32_t prio, const char* tag, const char* fmt, va_list ap); +#if defined(__GNUC__) && !defined(__clang__) void __log(uint32_t prio, const char* tag, const char* fmt, ...) __attribute__((format(gnu_printf, 3, 4))); +#else +void __log(uint32_t prio, const char* tag, const char* fmt, ...) + __attribute__((format(printf, 3, 4))); +#endif void logSetLevel(uint32_t prio); diff --git a/core/src/controllerports.cpp b/core/src/controllerports.cpp index 47f1bb1..691f4a0 100644 --- a/core/src/controllerports.cpp +++ b/core/src/controllerports.cpp @@ -9,7 +9,7 @@ namespace { struct RegisterMapping { - off64_t offset; + off_t offset; int bit; }; diff --git a/core/src/membus.cpp b/core/src/membus.cpp index 04eb6d8..5d00844 100644 --- a/core/src/membus.cpp +++ b/core/src/membus.cpp @@ -16,8 +16,7 @@ constexpr uint32_t kComponentAccessRW = kComponentAccessR | kComponentAccessW; namespace msfce::core { -Membus::Membus(AddressingType addrType, bool fastRom) - : m_AddrType(addrType), m_FastRom(fastRom) +Membus::Membus(AddressingType addrType, bool fastRom) : m_FastRom(fastRom) { if (addrType == AddressingType::lowrom) { initLowRom(); diff --git a/core/src/membus.h b/core/src/membus.h index 5371995..a14e84b 100644 --- a/core/src/membus.h +++ b/core/src/membus.h @@ -94,7 +94,6 @@ class Membus { void internalWriteU8(uint32_t addr, uint8_t value); private: - AddressingType m_AddrType; bool m_FastRom = false; Bank m_Banks[0x100]; diff --git a/core/src/ppu.h b/core/src/ppu.h index b404b49..b9f95b9 100644 --- a/core/src/ppu.h +++ b/core/src/ppu.h @@ -143,7 +143,7 @@ class Ppu int tileHeightPixel; int tileBpp; - int tileSize = tileBpp * 8; + int tileSize; TilemapMapper tilemapMapper; diff --git a/core/src/snesimpl.cpp b/core/src/snesimpl.cpp index 0da2882..4fc4e21 100644 --- a/core/src/snesimpl.cpp +++ b/core/src/snesimpl.cpp @@ -126,7 +126,7 @@ int SnesImpl::plugCartidge(const char* path) return ret; } - LOGI(TAG, "Rom size: %lu bytes", fStat.st_size); + LOGI(TAG, "Rom size: %jd bytes", static_cast(fStat.st_size)); // Read file content std::vector rom(fStat.st_size); diff --git a/core/src/snesimpl.h b/core/src/snesimpl.h index c938751..aa368a4 100644 --- a/core/src/snesimpl.h +++ b/core/src/snesimpl.h @@ -51,7 +51,7 @@ class SnesImpl void loadState(const std::string& path) final; // Scheduler methods - void resumeTask(SchedulerTask* task, int cycles); + void resumeTask(SchedulerTask* task, int cycles) final; // MemComponent methods uint8_t readU8(uint32_t addr) override; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5d53466..ce98aa4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,6 +4,10 @@ add_executable(msfce_tests tests.cpp ) +set_target_properties(msfce_tests PROPERTIES + CXX_STANDARD 17 +) + target_include_directories(msfce_tests PRIVATE ${CMAKE_SOURCE_DIR}/core/src From 2b892595399060940160fad4ee97407bfc50a5a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Roff=C3=A9?= Date: Sun, 30 Jan 2022 11:13:48 +0100 Subject: [PATCH 4/5] Rework mingw64 layout --- .github/workflows/build.yml | 10 +++++----- .gitignore | 3 ++- README.md | 11 +++-------- {mingw64 => extras}/.gitignore | 0 mingw64/build_deps.sh => extras/build-mingw64.sh | 8 ++++---- {mingw64 => extras}/glm/glm.pc.in | 0 .../mingw64-meson-toolchain.ini | 0 .../toolchain.cmake => extras/mingw64-toolchain.cmake | 0 .../opus/0001-configure-Disable-FORTIFY_SOURCE.patch | 0 9 files changed, 14 insertions(+), 18 deletions(-) rename {mingw64 => extras}/.gitignore (100%) rename mingw64/build_deps.sh => extras/build-mingw64.sh (96%) rename {mingw64 => extras}/glm/glm.pc.in (100%) rename mingw64/meson-toolchain.ini => extras/mingw64-meson-toolchain.ini (100%) rename mingw64/toolchain.cmake => extras/mingw64-toolchain.cmake (100%) rename {mingw64 => extras}/opus/0001-configure-Disable-FORTIFY_SOURCE.patch (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f2f355..a10728b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -63,16 +63,16 @@ jobs: env: cache-name: cache-build-dependencies with: - path: mingw64/x86_64-w64-mingw32 - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('mingw64/build_deps.sh') }} + path: extras/x86_64-w64-mingw32 + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('extras/build-mingw64.sh') }} - name: Build dependencies - run: (test -d mingw64/x86_64-w64-mingw32 && echo Build dependencies found, skip rebuild) || ./mingw64/build_deps.sh + run: (test -d extras/x86_64-w64-mingw32 && echo Build dependencies found, skip rebuild) || ./extras/build-mingw64.sh - name: Run cmake run: | - export PKG_CONFIG_LIBDIR=$(pwd)/mingw64/x86_64-w64-mingw32/lib/pkgconfig + export PKG_CONFIG_LIBDIR=$(pwd)/extras/x86_64-w64-mingw32/lib/pkgconfig mkdir build cd build - cmake -DCMAKE_TOOLCHAIN_FILE=../mingw64/toolchain.cmake -DCMAKE_BUILD_TYPE=Release .. + cmake -DCMAKE_TOOLCHAIN_FILE=../extras/mingw64-toolchain.cmake -DCMAKE_BUILD_TYPE=Release .. - name: Build run: | cd build diff --git a/.gitignore b/.gitignore index 378eac2..8074a76 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -build +build* +extras/x86_64-w64-mingw32 \ No newline at end of file diff --git a/README.md b/README.md index 81a6a71..12135fc 100644 --- a/README.md +++ b/README.md @@ -152,18 +152,13 @@ sudo apt install mingw-w64 cmake pkg-config wget unzip \ meson ninja-build nasm ``` -Build dependencies -``` -export PKG_CONFIG_LIBDIR=$(pwd)/mingw64/x86_64-w64-mingw32/lib/pkgconfig -./mingw64/build_deps.sh -``` - Build ``` -export PKG_CONFIG_LIBDIR=$(pwd)/mingw64/x86_64-w64-mingw32/lib/pkgconfig +./extras/build-mingw64.sh +export PKG_CONFIG_LIBDIR=$(pwd)/extras/x86_64-w64-mingw32/lib/pkgconfig mkdir build cd build -cmake -DCMAKE_TOOLCHAIN_FILE=../mingw64/toolchain.cmake -DCMAKE_BUILD_TYPE=Release .. +cmake -DCMAKE_TOOLCHAIN_FILE=../extras/mingw64-toolchain.cmake -DCMAKE_BUILD_TYPE=Release .. make ``` diff --git a/mingw64/.gitignore b/extras/.gitignore similarity index 100% rename from mingw64/.gitignore rename to extras/.gitignore diff --git a/mingw64/build_deps.sh b/extras/build-mingw64.sh similarity index 96% rename from mingw64/build_deps.sh rename to extras/build-mingw64.sh index 0885f23..09c1c84 100755 --- a/mingw64/build_deps.sh +++ b/extras/build-mingw64.sh @@ -10,7 +10,7 @@ NJOBS=$(grep -c ^processor /proc/cpuinfo) # Intermediate directories SRC_DIR="$BASE_DIR/src" -WORK_DIR="$BASE_DIR/work" +WORK_DIR="$BASE_DIR/work/$CROSS_PREFIX" # Install folder + pkg-config configuration ROOTFS_DIR="$BASE_DIR/$CROSS_PREFIX" @@ -26,7 +26,7 @@ test_sha256() { local expected_hash=$2 local real_hash=$(sha256sum $local_path | awk '{print $1}') - + if [[ $real_hash == $expected_hash ]]; then return 0 else @@ -56,7 +56,7 @@ download_tarball() { rm $local_path fi - # Get and check file integrity + # Get and check file integrity wget $uri -O $local_path test_sha256 $local_path $tarball_hash if [[ $? -eq 0 ]]; then @@ -238,7 +238,7 @@ build_epoxy() { cd "$work_dir/$archive_root" mkdir build cd build - meson .. --cross-file $BASE_DIR/meson-toolchain.ini --default-library=static --buildtype=release --prefix=$ROOTFS_DIR + meson .. --cross-file $BASE_DIR/mingw64-meson-toolchain.ini --default-library=static --buildtype=release --prefix=$ROOTFS_DIR ninja ninja install diff --git a/mingw64/glm/glm.pc.in b/extras/glm/glm.pc.in similarity index 100% rename from mingw64/glm/glm.pc.in rename to extras/glm/glm.pc.in diff --git a/mingw64/meson-toolchain.ini b/extras/mingw64-meson-toolchain.ini similarity index 100% rename from mingw64/meson-toolchain.ini rename to extras/mingw64-meson-toolchain.ini diff --git a/mingw64/toolchain.cmake b/extras/mingw64-toolchain.cmake similarity index 100% rename from mingw64/toolchain.cmake rename to extras/mingw64-toolchain.cmake diff --git a/mingw64/opus/0001-configure-Disable-FORTIFY_SOURCE.patch b/extras/opus/0001-configure-Disable-FORTIFY_SOURCE.patch similarity index 100% rename from mingw64/opus/0001-configure-Disable-FORTIFY_SOURCE.patch rename to extras/opus/0001-configure-Disable-FORTIFY_SOURCE.patch From b8e58157a75ae90f72e7e72737ec002914f96033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Roff=C3=A9?= Date: Sun, 30 Jan 2022 10:46:08 +0100 Subject: [PATCH 5/5] Add support of macOS --- .github/workflows/build.yml | 64 +++++ .gitignore | 4 +- README.md | 31 +++ app/frontend_sdl2/frontend_sdl2.cpp | 5 + extras/build-macos.sh | 352 +++++++++++++++++++++++++ extras/macos-meson-arm64-toolchain.ini | 9 + 6 files changed, 464 insertions(+), 1 deletion(-) create mode 100755 extras/build-macos.sh create mode 100644 extras/macos-meson-arm64-toolchain.ini diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a10728b..f551eb8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -84,3 +84,67 @@ jobs: path: | build/msfce.exe build/*.dll + build-macos-x86-64: + needs: clang-format + runs-on: macos-11 + steps: + - uses: actions/checkout@v1 + - uses: n1hility/cancel-previous-runs@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Fetch submodules + run: git submodule update --init --recursive + - name: Install required system packages + run: | + brew install coreutils wget cmake pkg-config nasm meson ninja + - name: Cache build dependencies + uses: actions/cache@v2 + env: + cache-name: cache-build-dependencies + with: + path: extras/apple-darwin-x86_64 + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('extras/build-macos.sh') }} + - name: Build dependencies + run: (test -d extras/apple-darwin-x86_64 && echo Build dependencies found, skip rebuild) || ./extras/build-macos.sh + - name: Run cmake + run: | + export PKG_CONFIG_LIBDIR=$(pwd)/extras/apple-darwin-x86_64/lib/pkgconfig + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Release .. + - name: Build + run: | + cd build + make -j2 + build-macos-arm64: + needs: clang-format + runs-on: macos-11 + steps: + - uses: actions/checkout@v1 + - uses: n1hility/cancel-previous-runs@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Fetch submodules + run: git submodule update --init --recursive + - name: Install required system packages + run: | + brew install coreutils wget cmake pkg-config nasm meson ninja + - name: Cache build dependencies + uses: actions/cache@v2 + env: + cache-name: cache-build-dependencies + with: + path: extras/apple-darwin-arm64 + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('extras/build-macos.sh') }} + - name: Build dependencies + run: (test -d extras/apple-darwin-arm64 && echo Build dependencies found, skip rebuild) || ./extras/build-macos.sh -a arm64 + - name: Run cmake + run: | + export PKG_CONFIG_LIBDIR=$(pwd)/extras/apple-darwin-arm64/lib/pkgconfig + mkdir build + cd build + cmake -DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_BUILD_TYPE=Release .. + - name: Build + run: | + cd build + make -j2 diff --git a/.gitignore b/.gitignore index 8074a76..c7b1fd3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ build* -extras/x86_64-w64-mingw32 \ No newline at end of file +extras/apple-darwin-arm64 +extras/apple-darwin-x86_64 +extras/x86_64-w64-mingw32 diff --git a/README.md b/README.md index 12135fc..6eae9c3 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,37 @@ cmake -DCMAKE_TOOLCHAIN_FILE=../extras/mingw64-toolchain.cmake -DCMAKE_BUILD_TYP make ``` +### macOS + +Both Mac Intel and Mac M1 targets are supported, but build has only been tested on Mac Intel. + +Install required packages +``` +brew install coreutils wget cmake pkg-config nasm meson ninja +``` + +#### Build for Mac Intel + +Build for Intel +``` +./extras/build-macos.sh +export PKG_CONFIG_LIBDIR=$(pwd)/extras/apple-darwin-x86_64/lib/pkgconfig +mkdir build-x86_64 +cd build-x86_64 +cmake -DCMAKE_BUILD_TYPE=Release .. +make +``` + +#### Build for M1 +``` +./extras/build-macos.sh -a arm64 +export PKG_CONFIG_LIBDIR=$(pwd)/extras/apple-darwin-arm64/lib/pkgconfig +mkdir build-arm64 +cd build-arm64 +cmake -DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_BUILD_TYPE=Release .. +make +``` + ## Ressources * [65C816 Opcodes by Bruce Clark](http://6502.org/tutorials/65c816opcodes.html) diff --git a/app/frontend_sdl2/frontend_sdl2.cpp b/app/frontend_sdl2/frontend_sdl2.cpp index 6523c41..1ca523b 100644 --- a/app/frontend_sdl2/frontend_sdl2.cpp +++ b/app/frontend_sdl2/frontend_sdl2.cpp @@ -57,6 +57,11 @@ int FrontendSdl2::init(const std::shared_ptr& snes) assert(m_Window); // Init OpenGl context + SDL_GL_SetAttribute( + SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); + m_GlContext = SDL_GL_CreateContext(m_Window); assert(m_GlContext); diff --git a/extras/build-macos.sh b/extras/build-macos.sh new file mode 100755 index 0000000..60cd056 --- /dev/null +++ b/extras/build-macos.sh @@ -0,0 +1,352 @@ +#!/bin/bash + +set -e + +BASE_DIR=$(realpath $(dirname $0)) +NJOBS=$(getconf NPROCESSORS_ONLN) + +panic() { + echo $1 + exit 1 +} + +test_sha256() { + local local_path=$1 + local expected_hash=$2 + + local real_hash=$(sha256sum $local_path | awk '{print $1}') + + if [[ $real_hash == $expected_hash ]]; then + return 0 + else + return 1 + fi +} + +download_tarball() { + local uri=$1 + local tarball_hash=$2 + + local filename=$(basename $uri) + local local_path="$SRC_DIR/$filename" + + echo "Downloading $local_path" + + # Check if file exists and is valid + if [[ -f $local_path ]]; then + test_sha256 $local_path $tarball_hash + + if [[ $? -eq 0 ]]; then + echo "File already exists and is valid" + return 0 + fi + + echo "File found, but invalid" + rm $local_path + fi + + # Get and check file integrity + wget $uri -O $local_path + test_sha256 $local_path $tarball_hash + if [[ $? -eq 0 ]]; then + return 0 + fi + + return 1 +} + +set_buildenv() { + if [[ $HOST_ARCH == "arm64" ]]; then + export CLANG_HOST="arm-apple-darwin" + else + export CLANG_HOST="x86_64-apple-darwin" + fi + + export CFLAGS="-mmacosx-version-min=$MINIMAL_OSX_VERSION -arch $HOST_ARCH -isysroot $SDKROOT" + export CXXFLAGS=$CFLAGS + export LDFLAGS=$CFLAGS +} + +clear_buildenv() { + unset CFLAGS + unset CXXFLAGS + unset LDFLAGS + unset CLANG_HOST +} + +build_zlib() { + local init_cwd=$(pwd) + + local uri="https://zlib.net/zlib-1.2.11.tar.gz" + local archive_root='zlib-1.2.11' + local sha256="c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1" + local work_dir="$WORK_DIR/zlib" + + # Get sources + download_tarball $uri $sha256 || panic "Fail to get zlib sources" + mkdir -p $work_dir + tar xf "$SRC_DIR/$(basename $uri)" -C $work_dir + + # Build + cd "$work_dir/$archive_root" + set_buildenv + + CC="clang $CFLAGS" ./configure --prefix=$ROOTFS_DIR --static + make -j$NJOBS + make install + + clear_buildenv + cd $init_cwd +} + +build_x264() { + local init_cwd=$(pwd) + + local uri="https://code.videolan.org/videolan/x264/-/archive/5db6aa6cab1b146e07b60cc1736a01f21da01154/x264-5db6aa6cab1b146e07b60cc1736a01f21da01154.zip" + local archive_root='x264-5db6aa6cab1b146e07b60cc1736a01f21da01154' + local sha256="6896825756ebe2c2657580d7636ed5fd6a41fea8e7722ba866fac7be6780d02f" + local work_dir="$WORK_DIR/x264" + + # Get sources + download_tarball $uri $sha256 || panic "Fail to get x264 sources" + mkdir -p $work_dir + unzip "$SRC_DIR/$(basename $uri)" -d $work_dir + + # Build + cd "$work_dir/$archive_root" + set_buildenv + + ./configure --host=$HOST_ARCH-apple-darwin --disable-cli --enable-static --prefix=$ROOTFS_DIR + make -j$NJOBS + make install + + clear_buildenv + cd $init_cwd +} + +build_opus() { + local init_cwd=$(pwd) + + local uri="https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz" + local archive_root='opus-1.3.1' + local sha256="65b58e1e25b2a114157014736a3d9dfeaad8d41be1c8179866f144a2fb44ff9d" + local work_dir="$WORK_DIR/opus" + + # Get sources + download_tarball $uri $sha256 || panic "Fail to get opus sources" + mkdir -p $work_dir + tar xf "$SRC_DIR/$(basename $uri)" -C $work_dir + + # Build + cd "$work_dir/$archive_root" + set_buildenv + + ./configure --host=$CLANG_HOST --prefix=$ROOTFS_DIR \ + --disable-extra-programs --disable-shared + + make -j$NJOBS + make install + + clear_buildenv + cd $init_cwd +} + +build_ffmpeg() { + local init_cwd=$(pwd) + + local uri="http://ffmpeg.org/releases/ffmpeg-4.4.tar.xz" + local archive_root='ffmpeg-4.4' + local sha256="06b10a183ce5371f915c6bb15b7b1fffbe046e8275099c96affc29e17645d909" + local work_dir="$WORK_DIR/ffmpeg" + + # Get sources + download_tarball $uri $sha256 || panic "Fail to get ffmpeg sources" + mkdir -p $work_dir + tar xf "$SRC_DIR/$(basename $uri)" -C $work_dir + + OPTIONS="" + if [[ $HOST_ARCH != $BUILD_ARCH ]]; then + OPTIONS="$OPTIONS --enable-cross-compile" + fi + + # Build + cd "$work_dir/$archive_root" + + # Use --extra-cflags and --extra-ldflags because ffmpeg doesn't use CFLAGS when + # building .S files + set_buildenv + FFMPEG_CFLAGS="$CFLAGS" + FFMPEG_LDFLAGS="$LDFLAGS" + clear_buildenv + + ./configure \ + --arch=$HOST_ARCH --prefix=$ROOTFS_DIR \ + $OPTIONS --extra-cflags="$FFMPEG_CFLAGS" --extra-ldflags="$FFMPEG_LDFLAGS" \ + --enable-gpl --enable-shared --disable-static \ + --disable-programs --disable-everything --disable-bsfs \ + --enable-swscale \ + --enable-libx264 --enable-encoder=libx264 \ + --enable-libopus --enable-encoder=libopus \ + --enable-encoder=png \ + --enable-muxer=matroska \ + --enable-muxer=mp4 \ + --enable-protocol=file + + make -j$NJOBS + make install + + cd $init_cwd +} + +build_sdl2() { + local init_cwd=$(pwd) + + local uri="https://www.libsdl.org/release/SDL2-2.0.14.tar.gz" + local archive_root='SDL2-2.0.14' + local sha256="d8215b571a581be1332d2106f8036fcb03d12a70bae01e20f424976d275432bc" + local work_dir="$WORK_DIR/sdl2" + + # Get sources + download_tarball $uri $sha256 || panic "Fail to get SDL2 sources" + mkdir -p $work_dir + tar xf "$SRC_DIR/$(basename $uri)" -C $work_dir + + # Build + cd "$work_dir/$archive_root" + set_buildenv + + ./configure --host=$CLANG_HOST --prefix=$ROOTFS_DIR \ + --disable-video-x11 + + make -j$NJOBS + make install + + clear_buildenv + cd $init_cwd +} + +build_glm() { + local init_cwd=$(pwd) + + local uri="https://github.com/g-truc/glm/releases/download/0.9.9.8/glm-0.9.9.8.zip" + local archive_root='glm' + local sha256="37e2a3d62ea3322e43593c34bae29f57e3e251ea89f4067506c94043769ade4c" + local work_dir="$WORK_DIR/glm" + + # Get sources + download_tarball $uri $sha256 || panic "Fail to get glm sources" + mkdir -p $work_dir + unzip "$SRC_DIR/$(basename $uri)" -d $work_dir + + # Install headers + cd "$work_dir/$archive_root" + mkdir -p $ROOTFS_DIR/include $ROOTFS_DIR/lib/pkgconfig + cp -a glm "$ROOTFS_DIR/include" + cp "$BASE_DIR/glm/glm.pc.in" "$ROOTFS_DIR/lib/pkgconfig/glm.pc" + + # Patch .pc file + sed -i.bu 's|@prefix@|'$ROOTFS_DIR'|g' "$ROOTFS_DIR/lib/pkgconfig/glm.pc" + + cd $init_cwd +} + +build_epoxy() { + local init_cwd=$(pwd) + + local uri="https://github.com/anholt/libepoxy/releases/download/1.5.5/libepoxy-1.5.5.tar.xz" + local archive_root='libepoxy-1.5.5' + local sha256="261663db21bcc1cc232b07ea683252ee6992982276536924271535875f5b0556" + local work_dir="$WORK_DIR/epoxy" + + # Get sources + download_tarball $uri $sha256 || panic "Fail to get epoxy sources" + mkdir -p $work_dir + tar xf "$SRC_DIR/$(basename $uri)" -C $work_dir + + # Build + cd "$work_dir/$archive_root" + set_buildenv + + CROSS_FILE="" + if [[ $HOST_ARCH != $BUILD_ARCH ]]; then + CROSS_FILE="--cross-file $BASE_DIR/macos-meson-arm64-toolchain.ini" + fi + + mkdir build + cd build + meson .. $CROSS_FILE --default-library=static --buildtype=release --prefix=$ROOTFS_DIR + + ninja + ninja install + + clear_buildenv + cd $init_cwd +} + +usage() { + cat << EOF +usage: $0 [options] + +OPTIONS: + -h Show some help + -a Use the specified arch +EOF +} + +# Build configuration +BUILD_ARCH=$(uname -m | cut -d. -f1) +HOST_ARCH="x86_64" + +# Parse parameters +while getopts "ha:" OPTION +do + case $OPTION in + h) + usage + exit 1 + ;; + a) + HOST_ARCH=$OPTARG + ;; + *) + usage + exit 1 + ;; + esac +done +shift $(($OPTIND - 1)) + +if [ "x$1" != "x" ]; then + usage + exit 1 +fi + +HOST_TRIPLET="apple-darwin-$HOST_ARCH" +SDKROOT=$(xcrun --show-sdk-path) + +if [[ $HOST_ARCH == "arm64" ]]; then + MINIMAL_OSX_VERSION="11.0" +else + MINIMAL_OSX_VERSION="10.10" +fi + +# Intermediate directories +SRC_DIR="$BASE_DIR/src" +WORK_DIR="$BASE_DIR/work/$HOST_TRIPLET" + +# Install folder + pkg-config configuration +ROOTFS_DIR="$BASE_DIR/$HOST_TRIPLET" +export PKG_CONFIG_LIBDIR=$ROOTFS_DIR/lib/pkgconfig + +# Create folders +mkdir -p $SRC_DIR $WORK_DIR +mkdir -p $ROOTFS_DIR + +# Build libs +build_zlib +build_x264 +build_opus +build_ffmpeg +build_sdl2 +build_glm +build_epoxy diff --git a/extras/macos-meson-arm64-toolchain.ini b/extras/macos-meson-arm64-toolchain.ini new file mode 100644 index 0000000..ec72857 --- /dev/null +++ b/extras/macos-meson-arm64-toolchain.ini @@ -0,0 +1,9 @@ +[binaries] +c = 'clang' +cpp = 'clang++' + +[host_machine] +system = 'darwin' +cpu_family = 'aarch64' +cpu = 'aarch64' +endian = 'little'