File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -143,6 +143,54 @@ mkdir -p "${BUILD_DIR}"
143143TARGET_ARCH=$( dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null || echo " amd64" )
144144echo " Target architecture: ${TARGET_ARCH} "
145145
146+ find_cross_compiler () {
147+ local prefix=" $1 "
148+ local compiler=" "
149+
150+ # First try the base name (might be a symlink to latest)
151+ if command -v " ${prefix} gcc" & > /dev/null; then
152+ compiler=" $( command -v " ${prefix} gcc" ) "
153+ else
154+ # Find all versioned compilers and pick the latest
155+ local candidates=($( ls /usr/bin/${prefix} gcc-* 2> /dev/null | sort -V) )
156+ if [ ${# candidates[@]} -gt 0 ]; then
157+ compiler=" ${candidates[-1]} "
158+ fi
159+ fi
160+
161+ if [ -n " $compiler " ]; then
162+ echo " $compiler "
163+ return 0
164+ else
165+ return 1
166+ fi
167+ }
168+
169+ setup_cross_compilation () {
170+ if [ " $TARGET_ARCH " != " amd64" ]; then
171+ echo " Setting up cross-compilation for ${TARGET_ARCH} ..."
172+
173+ case $TARGET_ARCH in
174+ arm64)
175+ local c_compiler=$( find_cross_compiler " aarch64-linux-gnu-" )
176+ if [ $? -eq 0 ]; then
177+ CMAKE_ARGS+=(-DCMAKE_C_COMPILER=" $c_compiler " )
178+ CMAKE_ARGS+=(-DCMAKE_CXX_COMPILER=" ${c_compiler/ gcc/ g++} " )
179+ fi
180+ ;;
181+ armhf)
182+ local c_compiler=$( find_cross_compiler " arm-linux-gnueabihf-" )
183+ if [ $? -eq 0 ]; then
184+ CMAKE_ARGS+=(-DCMAKE_C_COMPILER=" $c_compiler " )
185+ CMAKE_ARGS+=(-DCMAKE_CXX_COMPILER=" ${c_compiler/ gcc/ g++} " )
186+ fi
187+ ;;
188+ esac
189+ fi
190+ }
191+
192+ setup_cross_compilation
193+
146194# Compute distro-specific release suffix
147195if [ -f " ${SOURCE_DIR} /scripts/distro_release.sh" ]; then
148196 DISTRO_DEB_RELEASE=$( bash " ${SOURCE_DIR} /scripts/distro_release.sh" )
You can’t perform that action at this time.
0 commit comments