File indexing completed on 2024-05-12 04:22:31

0001 #!/usr/bin/env zsh
0002 #
0003 #  SPDX-License-Identifier: GPL-3.0-or-later
0004 #
0005 
0006 # creates a universal tar build from build-x86_64 and build-arm64
0007 # First argument is <root_dir> where build dirs reside.
0008 
0009 consolidate_universal_binaries () {
0010     # echo "dirs ${DIR_X86} :: ${DIR_UNI}"
0011     for f in "${@}"; do
0012         # Only try to consolidate Mach-O and static libs
0013         if [[ -n $(file "${f}" | grep "Mach-O") || "${f:(-2)}" = ".a" ]]; then
0014             # echo "${BUILDROOT}/${DEPBUILD_X86_64_DIR}/${f##*test-i/}"
0015             LIPO_OUTPUT=$(lipo -info "${f}" | grep Non-fat 2> /dev/null)
0016             if [[ -n ${LIPO_OUTPUT} ]]; then
0017                 if [[ -f "${DIR_X86}/${f##*${DIR_UNI}/}" ]]; then
0018                     echo "creating universal binary -- ${f##*${DIR_UNI}/}"
0019                     lipo -create "${f}" "${DIR_X86}/${f##*${DIR_UNI}/}" -output "${f}"
0020                 fi
0021             fi
0022             # log "ignoring ${f}"
0023         fi
0024     done
0025 }
0026 
0027 consolidate_build_dirs() {
0028     DIR_X86=${1}
0029     local DIR_ARM=${2}
0030     local DIR_UNI=${3}
0031 
0032     rsync -aq ${DIR_ARM}/ ${DIR_UNI}
0033     consolidate_universal_binaries $(find "${DIR_UNI}" -type f)
0034 }
0035 
0036 if [[ ${#@} < 1 ]]; then
0037     echo "script needs root_dir of builds to consolidate as input"
0038     exit
0039 fi
0040 
0041 root_dir=${1}
0042 
0043 if [[ ! -d ${root_dir} ]]; then
0044     echo "provided path is not a directory"
0045     echo "path: ${root_dir}"
0046 fi
0047 
0048 dir_x86="${root_dir}/build-x86_64"
0049 dir_arm="${root_dir}/build-arm64"
0050 dir_uni="${root_dir}/build_uni"
0051 
0052 
0053 if [[ -d "${dir_x86}" && -d "${dir_arm}" ]]; then
0054     consolidate_build_dirs "${dir_x86}" "${dir_arm}" "${dir_uni}"
0055 else
0056     if [[ -d "${dir_x86}" ]]; then
0057         rsync -aq "${dir_x86}/" "${dir_uni}"
0058     else
0059         rsync -aq "${dir_arm}/" "${dir_uni}"
0060     fi
0061 fi
0062 
0063 # from https://www.gnu.org/software/automake/manual/html_node/DESTDIR.html
0064 build_tar=package_build_fat.tar.gz
0065 
0066 cd "${dir_uni}"
0067 find . '(' -type f -o -type l ')' -print > ../files.lst
0068 tar zcvf "${build_tar}" --files-from "../files.lst"
0069 mv ${build_tar} ../
0070 
0071 echo "consolidate end"