diff --git a/.gitignore b/.gitignore index ffbc6474c5..a210bae212 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,12 @@ subconverter.exe cmake-build-debug .idea base/cache -build \ No newline at end of file +build +build_root/ +deps_install/ +venv/ +subconverter_macos/ +scripts/yaml-cpp/ +scripts/quickjspp/ +scripts/libcron/ +scripts/toml11/ diff --git a/scripts/build.macos.release.sh b/scripts/build.macos.release.sh index 96ef522033..c26cf05a51 100644 --- a/scripts/build.macos.release.sh +++ b/scripts/build.macos.release.sh @@ -1,66 +1,106 @@ #!/bin/bash -set -xe - -brew reinstall rapidjson zlib pcre2 pkgconfig - -#git clone https://github.com/curl/curl --depth=1 --branch curl-7_88_1 -#cd curl -#./buildconf > /dev/null -#./configure --with-ssl=/usr/local/opt/openssl@1.1 --without-mbedtls --disable-ldap --disable-ldaps --disable-rtsp --without-libidn2 > /dev/null -#cmake -DCMAKE_USE_SECTRANSP=ON -DHTTP_ONLY=ON -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_USE_LIBSSH2=OFF . > /dev/null -#make -j8 > /dev/null -#cd .. - -git clone https://github.com/jbeder/yaml-cpp --depth=1 -cd yaml-cpp -cmake -DCMAKE_BUILD_TYPE=Release -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF . > /dev/null -make -j6 > /dev/null -sudo make install > /dev/null -cd .. +set -e -git clone https://github.com/ftk/quickjspp --depth=1 -cd quickjspp -cmake -DCMAKE_BUILD_TYPE=Release . -make quickjs -j6 > /dev/null -sudo install -d /usr/local/lib/quickjs/ -sudo install -m644 quickjs/libquickjs.a /usr/local/lib/quickjs/ -sudo install -d /usr/local/include/quickjs/ -sudo install -m644 quickjs/quickjs.h quickjs/quickjs-libc.h /usr/local/include/quickjs/ -sudo install -m644 quickjspp.hpp /usr/local/include/ -cd .. +# --- Configuration --- +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +ROOT_DIR="$( dirname "$SCRIPT_DIR" )" +DEPS_SRC_DIR="$SCRIPT_DIR" +INSTALL_DIR="$ROOT_DIR/deps_install" +CPU_CORES=$(sysctl -n hw.ncpu || echo 4) +BREW_PREFIX=$(brew --prefix) + +cd "$ROOT_DIR" + +echo "Using Brew Prefix: $BREW_PREFIX" +echo "Using CPU Cores: $CPU_CORES" +echo "Install Directory: $INSTALL_DIR" + +# 1. Base Dependencies +echo "Checking base dependencies..." +brew install rapidjson zlib pcre2 pkgconfig curl openssl@3 + +# 2. Helper Functions +function setup_repo() { + local url=$1 + local dir=$2 + local ref=$3 + echo "--- Setting up $dir ($ref) ---" + cd "$DEPS_SRC_DIR" + if [ ! -d "$dir" ]; then + git clone "$url" "$dir" + fi + cd "$dir" + git fetch origin --tags + git reset --hard "$ref" +} + +# 3. Build Dependencies +mkdir -p "$INSTALL_DIR" -git clone https://github.com/PerMalmberg/libcron --depth=1 -cd libcron +setup_repo "https://github.com/jbeder/yaml-cpp" "yaml-cpp" "master" +cmake -B build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release \ + -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF \ + -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" +cmake --build build -j "$CPU_CORES" +cmake --install build + +setup_repo "https://github.com/ftk/quickjspp" "quickjspp" "master" +cmake -B build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release +cmake --build build --target quickjs -j "$CPU_CORES" +mkdir -p "$INSTALL_DIR/lib/quickjs" "$INSTALL_DIR/include/quickjs" +cp build/quickjs/libquickjs.a "$INSTALL_DIR/lib/quickjs/" +cp quickjs/quickjs.h quickjs/quickjs-libc.h "$INSTALL_DIR/include/quickjs/" +cp quickjspp.hpp "$INSTALL_DIR/include/" + +setup_repo "https://github.com/PerMalmberg/libcron" "libcron" "master" git submodule update --init -cmake -DCMAKE_BUILD_TYPE=Release . -make libcron -j6 -sudo install -m644 libcron/out/Release/liblibcron.a /usr/local/lib/ -sudo install -d /usr/local/include/libcron/ -sudo install -m644 libcron/include/libcron/* /usr/local/include/libcron/ -sudo install -d /usr/local/include/date/ -sudo install -m644 libcron/externals/date/include/date/* /usr/local/include/date/ -cd .. +cmake -B build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release +cmake --build build --target libcron -j "$CPU_CORES" +mkdir -p "$INSTALL_DIR/include/libcron" "$INSTALL_DIR/include/date" +cp libcron/out/Release/liblibcron.a "$INSTALL_DIR/lib/" +cp -R libcron/include/libcron/* "$INSTALL_DIR/include/libcron/" +cp -R libcron/externals/date/include/date/* "$INSTALL_DIR/include/date/" -git clone https://github.com/ToruNiina/toml11 --branch="v4.3.0" --depth=1 -cd toml11 -cmake -DCMAKE_CXX_STANDARD=11 . -sudo make install -j6 > /dev/null -cd .. +setup_repo "https://github.com/ToruNiina/toml11" "toml11" "main" +cmake -B build -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=11 -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" +cmake --build build -j "$CPU_CORES" +cmake --install build + +# 4. Main Program Build +cd "$ROOT_DIR" +echo "--- Building subconverter ---" +rm -rf build_root +cmake -B build_root -G "Unix Makefiles" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_PREFIX_PATH="$INSTALL_DIR" \ + -DZLIB_ROOT="$BREW_PREFIX/opt/zlib" \ + -DPCRE2_ROOT="$BREW_PREFIX/opt/pcre2" +cmake --build build_root -j "$CPU_CORES" + +# 5. Final Linking +echo "--- Final Linking ---" +rm -rf subconverter +LDFLAGS="-Xlinker -unexported_symbol -Xlinker \"*\" -framework CoreFoundation -framework Security" +LIBS="$(find "$INSTALL_DIR" -name "*.a") $BREW_PREFIX/opt/zlib/lib/libz.a $BREW_PREFIX/opt/pcre2/lib/libpcre2-8.a -lcurl" +OBJECTS="$(find build_root/CMakeFiles/subconverter.dir/src/ -name "*.o")" -cmake -DCMAKE_BUILD_TYPE=Release . -make -j6 -rm subconverter -# shellcheck disable=SC2046 -c++ -Xlinker -unexported_symbol -Xlinker "*" -o base/subconverter -framework CoreFoundation -framework Security $(find CMakeFiles/subconverter.dir/src/ -name "*.o") "$(brew --prefix zlib)/lib/libz.a" "$(brew --prefix pcre2)/lib/libpcre2-8.a" $(find . -name "*.a") -lcurl -O3 +c++ $LDFLAGS -o base/subconverter $OBJECTS $LIBS -O3 -python -m ensurepip -sudo python -m pip install gitpython -python scripts/update_rules.py -c scripts/rules_config.conf +# 6. Update Rules +echo "--- Updating Rules ---" +python3 -m venv venv +source venv/bin/activate +pip install gitpython +python $SCRIPT_DIR/update_rules.py -c $SCRIPT_DIR/rules_config.conf +deactivate +# 7. Cleanup and Packaging +echo "--- Finishing ---" cd base chmod +rx subconverter chmod +r ./* cd .. -mv base subconverter -set +xe +if [ -d "subconverter" ]; then rm -rf subconverter; fi +cp -R base subconverter +echo "Build complete! Output is in subconverter/"