From bd2f45718156186cb0529a473a64496cd08e7ac2 Mon Sep 17 00:00:00 2001 From: Levon Gevorgyan Date: Fri, 27 Mar 2026 09:24:21 -0500 Subject: [PATCH] fixup libjxl build --- lib/0-utils.sh | 12 ++++++++++-- lib/build.sh | 33 ++++++++++++++++++++------------- lib/compile_opts.sh | 5 ++++- lib/install_deps.sh | 8 -------- lib/package.sh | 4 +--- main.sh | 4 ++-- 6 files changed, 37 insertions(+), 29 deletions(-) diff --git a/lib/0-utils.sh b/lib/0-utils.sh index 3888562..c454968 100644 --- a/lib/0-utils.sh +++ b/lib/0-utils.sh @@ -301,6 +301,14 @@ print_os() { echo "${FB_OS}" } +set_sudo() { + if is_windows || test "$(id -u)" -eq 0; then + SUDO='' + else + SUDO='sudo ' + fi +} + is_positive_integer() { local input="$1" if [[ ${input} != ?(-)+([[:digit:]]) || ${input} -lt 0 ]]; then @@ -431,7 +439,7 @@ have_required_version() { recreate_dir() { local dirs=("$@") for dir in "${dirs[@]}"; do - test -d "${dir}" && rm -rf "${dir}" + test -d "${dir}" && ${SUDO_MODIFY} rm -rf "${dir}" mkdir -p "${dir}" || return 1 done } @@ -439,7 +447,7 @@ recreate_dir() { ensure_dir() { local dirs=("$@") for dir in "${dirs[@]}"; do - test -d "${dir}" || mkdir -p "${dir}" || return 1 + test -d "${dir}" || ${SUDO_MODIFY} mkdir -p "${dir}" || return 1 done } diff --git a/lib/build.sh b/lib/build.sh index 46a7896..64500eb 100644 --- a/lib/build.sh +++ b/lib/build.sh @@ -31,6 +31,9 @@ set_compile_opts() { BUILD_TYPE NO_BUILD_TYPE SHARED + BINDIR + LIBDIR + INCDIR ) unset "${BUILD_ENV_NAMES[@]}" export "${EXPORTED_ENV_NAMES[@]}" @@ -39,6 +42,10 @@ set_compile_opts() { JOBS="$(nproc)" # local vs system prefix test "${PREFIX}" == 'local' && PREFIX="${LOCAL_PREFIX}" + # relevant prefix directories + BINDIR="${PREFIX}/bin" + LIBDIR="${PREFIX}/lib" + INCDIR="${PREFIX}/include" # check if we need to handle PREFIX with sudo local testfile='' @@ -53,14 +60,11 @@ set_compile_opts() { SUDO_MODIFY='' else SUDO_MODIFY="${SUDO}" - echo_warn "using ${SUDO}to install" - ${SUDO_MODIFY} mkdir -p "${PREFIX}/bin/" || return 1 + echo_warn "using ${SUDO}to modify PREFIX" fi test -f "${testfile}" && ${SUDO_MODIFY} rm "${testfile}" - test -d "${PREFIX}" || { ${SUDO_MODIFY} mkdir -p "${PREFIX}" || return 1; } + ensure_dir "${BINDIR}" || return 1 - # set library/pkgconfig directory - LIBDIR="${PREFIX}/lib" LDFLAGS_ARR=("-L${LIBDIR}") # android has different library location/names @@ -182,7 +186,7 @@ fi' >"${compilerDir}/which" # add prefix include # TODO use cygpath for windows - CPPFLAGS_ARR+=("-I${PREFIX}/include") + CPPFLAGS_ARR+=("-I${INCDIR}") # if PGO is enabled, first build run will be to generate # second run will be to use generated profdata @@ -684,11 +688,11 @@ build() { # skip packaging on PGO generate run if [[ ${PGO} == 'ON' && ${PGO_RUN} == 'generate' ]]; then - PATH="${PREFIX}/bin:${PATH}" gen_profdata + PATH="${BINDIR}:${PATH}" gen_profdata return $? fi - local ffmpegBin="${PREFIX}/bin/ffmpeg" + local ffmpegBin="${BINDIR}/ffmpeg" # run ffmpeg to show completion "${ffmpegBin}" -version || return 1 @@ -698,8 +702,8 @@ build() { if [[ ${ffmpeg} != "${ffmpegBin}" ]]; then echo echo_warn "ffmpeg in path (${ffmpeg}) is not the built one (${ffmpegBin})" - echo_info "consider adding ${PREFIX}/bin to \$PATH" - echo "echo 'export PATH=\"${PREFIX}/bin:\$PATH\"' >> ~/.bashrc" + echo_info "consider adding ${BINDIR} to \$PATH" + echo "echo 'export PATH=\"${BINDIR}:\$PATH\"' >> ~/.bashrc" fi package || return 1 @@ -1072,6 +1076,9 @@ build_libssh() { } build_libjxl() { + # jxl headers interfere with this build + recreate_dir "${INCDIR}/jxl" || return 1 + meta_cmake_build \ -DJPEGXL_FORCE_SYSTEM_BROTLI=ON \ -DJPEGXL_BUNDLE_LIBPNG=OFF || return 1 @@ -1084,7 +1091,7 @@ build_libjxl() { if [[ ${STATIC} == ON ]]; then libs+=(libjxl_extras_codec) else - libs+=(libjxl_jni) + is_darwin || libs+=(libjxl_jni) fi sanitize_sysroot_libs "${libs[@]}" || return 1 } @@ -1321,7 +1328,7 @@ build_libcrypto() { cryptoFlags+=( enable-{brotli,zlib,zstd} - --with-{brotli,zlib,zstd}-include="${PREFIX}/include" + --with-{brotli,zlib,zstd}-include="${INCDIR}" --with-{brotli,zlib,zstd}-lib="${LIBDIR}" ) @@ -1405,7 +1412,7 @@ build_ffmpeg() { meta_configure_build \ "${ffmpegFlags[@]}" || return 1 LTO="${ltoBackup}" - ${SUDO_MODIFY} cp ff*_g "${PREFIX}/bin" + ${SUDO_MODIFY} cp ff*_g "${BINDIR}" sanitize_sysroot_libs \ libavcodec libavdevice libavfilter libswscale \ libavformat libavutil libswresample || return 1 diff --git a/lib/compile_opts.sh b/lib/compile_opts.sh index f4ddebf..337e636 100644 --- a/lib/compile_opts.sh +++ b/lib/compile_opts.sh @@ -7,7 +7,7 @@ unset FB_COMP_OPTS_DESC declare -Ag FB_COMP_OPTS_DESC -# default compile options +# default build options FB_COMP_OPTS_DESC['CLEAN']='clean build directories before building' DEFAULT_CLEAN=ON @@ -29,6 +29,9 @@ DEFAULT_ARCH=native FB_COMP_OPTS_DESC['PREFIX']='prefix to install to, default is local install in ./gitignore/sysroot' DEFAULT_PREFIX='local' +FB_COMP_OPTS_DESC['PACKAGE']='package ffmpeg binaries to tarball in ./gitignore/package' +DEFAULT_PACKAGE=OFF + FB_COMP_OPTS_DESC['ENABLE']='configure what ffmpeg enables' DEFAULT_ENABLE="\ libaom \ diff --git a/lib/install_deps.sh b/lib/install_deps.sh index 0641779..e454e26 100644 --- a/lib/install_deps.sh +++ b/lib/install_deps.sh @@ -2,14 +2,6 @@ # shellcheck disable=SC2120 determine_pkg_mgr() { - # sudo used externally - # shellcheck disable=SC2034 - if is_windows || test "$(id -u)" -eq 0; then - SUDO='' - else - SUDO='sudo ' - fi - # pkg-mgr update-cmd upgrade-cmd install-cmd check-cmd # shellcheck disable=SC2016 local PKG_MGR_MAP=' diff --git a/lib/package.sh b/lib/package.sh index cb65d44..a6f780c 100644 --- a/lib/package.sh +++ b/lib/package.sh @@ -1,9 +1,7 @@ #!/usr/bin/env bash check_for_package_cfg() { - local requiredCfg='ON:ON:ON:3' - local currentCfg="${STATIC}:${LTO}:${PGO}:${OPT}" - if [[ ${currentCfg} == "${requiredCfg}" ]]; then + if [[ ${PACKAGE} == 'ON' ]]; then return 0 else return 1 diff --git a/main.sh b/main.sh index d233b98..d42c95c 100755 --- a/main.sh +++ b/main.sh @@ -89,7 +89,7 @@ $cmd "$@"' >"${ENTRY_SCRIPT}" gen_links || return 1 # allow calling entry.sh with arguments as execution -entry() { "$@" ; } +entry() { "$@"; } set_completions() { for funcName in "${FB_FUNC_NAMES[@]}"; do @@ -97,7 +97,7 @@ set_completions() { done } -determine_pkg_mgr || return 1 +set_sudo || return 1 check_compile_opts_override || return 1 # set local prefix since some functions need it