diff --git a/lib/build.sh b/lib/build.sh index 5d85847..3a98484 100644 --- a/lib/build.sh +++ b/lib/build.sh @@ -101,16 +101,19 @@ set_compile_opts() { # architecture/cpu compile flags # arm prefers -mcpu over -march # https://community.arm.com/arm-community-blogs/b/tools-software-ides-blog/posts/compiler-flags-across-architectures-march-mtune-and-mcpu - arch_flags="" - test_arch="$(uname -m)" - if [[ ${test_arch} == "x86_64" ]]; then - arch_flags="-march=${CPU}" - elif [[ ${test_arch} == "aarch64" || - ${test_arch} == "arm64" ]]; then - arch_flags="-mcpu=${CPU}" + # and can fail static builds with -fpic + # warning: too many GOT entries for -fpic, please recompile with -fPIC + local arch_flags=() + if [[ ${HOSTTYPE} == "x86_64" ]]; then + arch_flags+=("-march=${CPU}") + elif [[ ${HOSTTYPE} == "aarch64" ]]; then + arch_flags+=( + "-mcpu=${CPU}" + "-fPIC" + ) fi - C_FLAGS+=("${arch_flags}") + C_FLAGS+=("${arch_flags[@]}") CXX_FLAGS=("${C_FLAGS[@]}") CPP_FLAGS=("${C_FLAGS[@]}") RUSTFLAGS+=("-C target-cpu=${CPU}") @@ -158,6 +161,17 @@ set_compile_opts() { get_build_conf() { local getBuild="${1}" + local libcVer='X.X' + if test "${getBuild}" == 'libc' && has_cmd ldd; then + local srcTest="${TMP_DIR}/libc-ver" + echo '#include +#include +#include +int main() { puts(gnu_get_libc_version()); return 0; }' >"${srcTest}.c" + gcc "${srcTest}.c" -o "${srcTest}" + libcVer="$("${srcTest}")" + fi + # name version file-extension url dep1,dep2 # shellcheck disable=SC2016 local BUILDS_CONF=' @@ -172,6 +186,9 @@ libvmaf 3.0.0 tar.gz https://github.com/Netflix/vmaf/archive/refs/t libopus 1.5.2 tar.gz https://github.com/xiph/opus/releases/download/v${ver}/opus-${ver}.${ext} libdav1d 1.5.1 tar.xz http://downloads.videolan.org/videolan/dav1d/${ver}/dav1d-${ver}.${ext} ' + BUILDS_CONF+="libc ${libcVer} tar.xz" + BUILDS_CONF+=' https://ftpmirror.gnu.org/glibc/glibc-${ver}.${ext}' + local supported_builds=() unset ver ext url deps extracted_dir while read -r line; do @@ -423,8 +440,14 @@ build_libaom() { ### MESON ### build_libdav1d() { + local enableAsm='true' + # arm64 will fail the build at 0 optimization + if [[ "${HOSTTYPE}:${OPT_LVL}" == "aarch64:0" ]]; then + enableAsm="false" + fi meson \ setup . build.user \ + -Denable_asm=${enableAsm} \ "${MESON_FLAGS[@]}" || return 1 ccache ninja -vC build.user || return 1 ${SUDO_MODIFY} ninja -vC build.user install || return 1 @@ -471,6 +494,46 @@ build_libopus() { ${SUDO_MODIFY} make -j"${JOBS}" install || return 1 return 0 } +# special function mainly for arm64 builds +# since most distros do not compile libc +# with -fPIC for some reason +build_libc() ( + # only for arm64 + test "${HOSTTYPE}" != "aarch64" && exit 0 + # only for static builds + test "${STATIC}" == 'false' && exit 0 + # only for glibc + has_cmd ldd || exit 0 + # only build once + test -f "${LIBDIR}/libc.a" && exit 0 + + rm -rf build + mkdir build + cd build || exit 1 + + # manually set flags since these are + # not intended to be user-controlled + unset CFLAGS CXXFLAGS + export CFLAGS='-fPIC -O3 -U_FORTIFY_SOURCE' + export CXXFLAGS="${CFLAGS}" + libc_prefix="${PWD}/local-install" + libc_libdir="${libc_prefix}/lib" + ./../configure \ + --prefix="${libc_prefix}" \ + --libdir="${libc_libdir}" \ + --disable-werror || exit 1 + make -j"${JOBS}" all || exit 1 + + # install only the -fPIC static libraries + for picLib in ./**_pic.a; do + echo_warn "${picLib}" + done + # exit 1 + # cd "${libc_libdir}" || exit 1 + # cp ./*.a "${LIBDIR}" || exit 1 + + exit 0 +) add_project_versioning_to_ffmpeg() { local optFile optFile="$(command ls ./**/ffmpeg_opt.c)" diff --git a/lib/compile_opts.sh b/lib/compile_opts.sh index 5379116..fdf38af 100644 --- a/lib/compile_opts.sh +++ b/lib/compile_opts.sh @@ -3,7 +3,7 @@ # variables used externally # shellcheck disable=SC2034 -# complete clean before building +# clean build directories before building CLEAN=true # enable link time optimization LTO=false @@ -11,7 +11,7 @@ LTO=false OPT_LVL=0 # static or shared build STATIC=true -# CPU type (x86_v{1,2,3}...) +# CPU type (amd64/v{1,2,3}...) CPU=native # architecture type ARCH=native diff --git a/lib/docker.sh b/lib/docker.sh index 38f9e90..c112ac5 100644 --- a/lib/docker.sh +++ b/lib/docker.sh @@ -120,17 +120,19 @@ docker_build_image() { printf "RUN ${pkg_install} %s\n" "${req_pkgs[@]}" echo 'RUN pipx install virtualenv' echo 'RUN pipx ensurepath' - echo 'RUN curl https://sh.rustup.rs -sSf | bash -s -- -y' - echo 'ENV PATH="~/.cargo/bin:$PATH"' - echo 'RUN rustup default stable && rustup update stable' - echo 'RUN cargo install cargo-c' + echo 'ENV CARGO_HOME="/root/.cargo"' + echo 'ENV RUSTUP_HOME="/root/.rustup"' + echo 'ENV PATH="/root/.cargo/bin:$PATH"' + local cargoInst='' + cargoInst+='curl https://sh.rustup.rs -sSf | bash -s -- -y' + cargoInst+='&& rustup update stable' + cargoInst+='&& cargo install cargo-c' + cargoInst+='&& rm -rf "${CARGO_HOME}"/registry "${CARGO_HOME}"/git' + echo "RUN ${cargoInst}" # since any user may run this image, # open up root tools to everyone - echo 'RUN chmod 777 -R /root/' - echo 'ENV PATH="/root/.cargo/bin:$PATH"' echo 'ENV PATH="/root/.local/bin:$PATH"' - echo 'ENV RUSTUP_HOME="/root/.rustup"' - echo 'ENV CARGO_HOME="/root/.rustup"' + echo 'RUN chmod 777 -R /root/' echo "WORKDIR ${DOCKER_WORKDIR}" } >"${dockerfile}" diff --git a/lib/install_deps.sh b/lib/install_deps.sh index 6bb2d22..b2043bf 100644 --- a/lib/install_deps.sh +++ b/lib/install_deps.sh @@ -43,7 +43,9 @@ print_req_pkgs() { local common_pkgs=( autoconf automake cmake libtool texinfo nasm yasm python3 wget - meson doxygen jq ccache gawk git + meson doxygen jq ccache gawk + git gnuplot bison rsync ragel + zip unzip gperf itstool ) # shellcheck disable=SC2034 local brew_pkgs=( @@ -62,7 +64,7 @@ print_req_pkgs() { libvorbis-dev libxcb1-dev pipx libxcb-shm0-dev libxcb-xfixes0-dev zlib1g-dev libssl-dev ninja-build - gobjc++ mawk libnuma-dev + gobjc++ mawk libnuma-dev libc6-dev mediainfo mkvtoolnix libgtest-dev ) # shellcheck disable=SC2034 @@ -74,12 +76,13 @@ print_req_pkgs() { local dnf_pkgs=( "${common_linux_pkgs[@]}" openssl-devel pipx ninja-build fontconfig-devel wget2 - cpuinfo-devel glibc-static libstdc++-static + cpuinfo-devel glibc-static glibc-devel + libstdc++-static libstdc++-devel ) local req_pkgs_env_name="${pkg_mgr/-/_}_pkgs" declare -n req_pkgs="${req_pkgs_env_name}" - local sorted_req_pkgs=($(printf '%s\n' "${req_pkgs[@]}" | sort)) + local sorted_req_pkgs=($(printf '%s\n' "${req_pkgs[@]}" | sort -u)) echo "${sorted_req_pkgs[@]}" }