This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push: new 918505e13d8 build/export: Fix missing gnu-elf.ld copy and toolchain script. 918505e13d8 is described below commit 918505e13d886f0e37e055a58303ae10b68758e6 Author: trns1997 <trns1...@gmail.com> AuthorDate: Thu Sep 4 21:27:48 2025 +0200 build/export: Fix missing gnu-elf.ld copy and toolchain script. Fix missing `gnu-elf.ld` file copy during export generation and update `toolchain.cmake` script to ensure proper toolchain detection and configuration. * Prevents build failures when exporting projects. * Improves reproducibility of generated exports. Signed-off-by: trns1997 <trns1...@gmail.com> --- tools/mkexport.sh | 130 +++++++++++++++++++++++++++---------------- tools/toolchain.cmake.export | 7 +-- 2 files changed, 84 insertions(+), 53 deletions(-) diff --git a/tools/mkexport.sh b/tools/mkexport.sh index 9d8c42d9c62..cdb695ac7f5 100755 --- a/tools/mkexport.sh +++ b/tools/mkexport.sh @@ -19,6 +19,8 @@ # under the License. # +set -e # Exit on error + # Get the input parameter list USAGE="USAGE: $0 [-d] [-z] [-u] [-t <top-dir> [-x <lib-ext>] [-a <apps-dir>] [-m <make-exe>] -l \"lib1 [lib2 [lib3 ...]]\"" @@ -185,9 +187,10 @@ cp "${TOPDIR}/tools/incdir.c" "${EXPORTDIR}/tools/." # Copy the board specific linker if found, or use the default when not. APPLD=gnu-elf.ld + if [ -f "${BOARDDIR}/scripts/${APPLD}" ]; then cp -f "${BOARDDIR}/scripts/${APPLD}" "${EXPORTDIR}/scripts/." -else +elif [ -f "${TOPDIR}/libs/libc/elf/${APPLD}" ]; then cp -f "${TOPDIR}/libs/libc/elf/${APPLD}" "${EXPORTDIR}/scripts/." fi @@ -364,70 +367,101 @@ cp -LR -p "${TOPDIR}/include" "${EXPORTDIR}/." || \ ${MAKE} -C ${ARCHDIR} export_startup TOPDIR=${TOPDIR} EXPORT_DIR="${EXPORTDIR}" # Copy architecture-specific header files into the arch export sub-directory. -# This is tricky because each architecture does things in a little different -# way. -# -# First copy any header files in the architecture src/ sub-directory (some -# architectures keep all of the header files there, some a few, and others -# none - -cp -f "${ARCHDIR}"/*.h "${EXPORTDIR}"/arch/. 2>/dev/null - -# Then look a list of possible places where other architecture-specific -# header files might be found. If those places exist (as directories or -# as symbolic links to directories, then copy the header files from -# those directories into the EXPORTDIR +# Some architectures keep all headers in src/, some only a few, and others none. + +if [ -d "${ARCHDIR}" ]; then + # Expand the glob safely + set -- "${ARCHDIR}"/*.h + if [ -e "$1" ]; then + echo "MK: Copying architecture headers from ${ARCHDIR} to ${EXPORTDIR}/arch" + if ! cp -f "$@" "${EXPORTDIR}/arch/"; then + echo "MK: Error: Failed to copy headers from ${ARCHDIR}" >&2 + exit 1 + fi + else + echo "MK: Notice: No header files found in ${ARCHDIR}" >&2 + fi +else + echo "MK: Warning: Architecture directory ${ARCHDIR} does not exist" >&2 +fi if [ "X${USRONLY}" != "Xy" ]; then ARCH_HDRDIRS="arm armv7-m avr avr32 board common chip mips32" + for hdir in $ARCH_HDRDIRS; do + srcdir="${ARCHDIR}/${hdir}" + dstdir="${EXPORTDIR}/arch/${hdir}" # Does the directory (or symbolic link) exist? + if [ -d "$srcdir" ] || [ -h "$srcdir" ]; then + mkdir -p "$dstdir" || { + echo "MK: Error: mkdir $dstdir failed" >&2 + exit 1 + } + + # Copy headers if they exist + set -- "$srcdir"/*.h + if [ -e "$1" ]; then + echo "MK: Copying headers from $srcdir to $dstdir" + if ! cp -f "$@" "$dstdir/"; then + echo "MK: Error: Failed to copy headers from $srcdir" >&2 + exit 1 + fi + else + echo "MK: Notice: No header files found in $srcdir" >&2 + fi - if [ -d "${ARCHDIR}/${hdir}" -o -h "${ARCHDIR}/${hdir}" ]; then - - # Yes.. create a export sub-directory of the same name - - mkdir "${EXPORTDIR}/arch/${hdir}" || \ - { echo "MK: 'mkdir ${EXPORTDIR}/arch/${hdir}' failed"; exit 1; } - - # Then copy the header files (only) into the new directory - - cp -f "${ARCHDIR}"/${hdir}/*.h "${EXPORTDIR}"/arch/${hdir}/. 2>/dev/null - - # Most architectures have low directory called "hardware" that - # holds the header files - - if [ -d "${ARCHDIR}/${hdir}/hardware" ]; then - - # Yes.. create a export sub-directory of the same name - - mkdir "${EXPORTDIR}/arch/${hdir}/hardware" || \ - { echo "MK: 'mkdir ${EXPORTDIR}/arch/${hdir}/hardware' failed"; exit 1; } - - # Then copy the header files (only) into the new directory - - cp -f "${ARCHDIR}"/${hdir}/hardware/*.h "${EXPORTDIR}"/arch/${hdir}/hardware/. 2>/dev/null + # Handle hardware subdir if it exists + if [ -d "$srcdir/hardware" ]; then + mkdir -p "$dstdir/hardware" || { + echo "MK: Error: mkdir $dstdir/hardware failed" >&2 + exit 1 + } + + set -- "$srcdir/hardware"/*.h + if [ -e "$1" ]; then + echo "MK: Copying headers from $srcdir/hardware to $dstdir/hardware" + if ! cp -f "$@" "$dstdir/hardware/"; then + echo "MK: Error: Failed to copy headers from $srcdir/hardware" >&2 + exit 1 + fi + else + echo "MK: Notice: No hardware headers in $srcdir/hardware" >&2 + fi fi fi done - # Copy OS internal header files as well. They are used by some architecture- - # specific header files. - - mkdir "${EXPORTDIR}/arch/os" || \ - { echo "MK: 'mkdir ${EXPORTDIR}/arch/os' failed"; exit 1; } + # Copy OS internal header files + mkdir -p "${EXPORTDIR}/arch/os" || { + echo "MK: Error: mkdir ${EXPORTDIR}/arch/os failed" >&2 + exit 1 + } OSDIRS="clock environ errno group init irq mqueue paging pthread sched semaphore signal task timer wdog" for dir in ${OSDIRS}; do - mkdir "${EXPORTDIR}/arch/os/${dir}" || \ - { echo "MK: 'mkdir ${EXPORTDIR}/arch/os/${dir}' failed"; exit 1; } - cp -f "${TOPDIR}"/sched/${dir}/*.h "${EXPORTDIR}"/arch/os/${dir}/. 2>/dev/null - done + srcdir="${TOPDIR}/sched/${dir}" + dstdir="${EXPORTDIR}/arch/os/${dir}" - # Add the board library to the list of libraries + mkdir -p "$dstdir" || { + echo "MK: Error: mkdir $dstdir failed" >&2 + exit 1 + } + + set -- "$srcdir"/*.h + if [ -e "$1" ]; then + echo "MK: Copying OS headers from $srcdir to $dstdir" + if ! cp -f "$@" "$dstdir/"; then + echo "MK: Error: Failed to copy headers from $srcdir" >&2 + exit 1 + fi + else + echo "MK: Notice: No headers in $srcdir" >&2 + fi + done + # Add the board library if present if [ -f "${ARCHDIR}/board/libboard${LIBEXT}" ]; then LIBLIST="${LIBLIST} ${ARCHSUBDIR}/board/libboard${LIBEXT}" fi diff --git a/tools/toolchain.cmake.export b/tools/toolchain.cmake.export index 1e9bc7ca5a4..a5542b5dd4a 100644 --- a/tools/toolchain.cmake.export +++ b/tools/toolchain.cmake.export @@ -19,20 +19,17 @@ set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${NUTTX_PATH}/include/${NUTTX_CXX} ${NUTTX_PATH}/include ${NUTTX_PATH}/arch/chip) -file(GLOB STARTUP_OBJS ${NUTTX_PATH}/startup/*) - add_compile_options(-nostdlib) add_compile_options(-ffunction-sections -fdata-sections) # same entry used for all build modes in crt0.c and arch/.../xxx_start.c - set(ENTRY_NAME "__start") set(CMAKE_C_LINK_EXECUTABLE - "<CMAKE_LINKER> ${LDFLAGS} --entry=${ENTRY_NAME} -T${LINKER_SCRIPT} <OBJECTS> ${STARTUP_OBJS} -o <TARGET> <LINK_LIBRARIES> -L${NUTTX_PATH}/libs --start-group ${LDLIBS} ${EXTRA_LIBS} --end-group" + "<CMAKE_LINKER> ${LDFLAGS} --entry=${ENTRY_NAME} -T${LINKER_SCRIPT} <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -L${NUTTX_PATH}/libs --start-group ${LDLIBS} ${EXTRA_LIBS} --end-group" ) set(CMAKE_CXX_LINK_EXECUTABLE - "<CMAKE_LINKER> ${LDFLAGS} --entry=${ENTRY_NAME} -T${LINKER_SCRIPT} <OBJECTS> ${STARTUP_OBJS} -o <TARGET> <LINK_LIBRARIES> -L${NUTTX_PATH}/libs --start-group ${LDLIBS} ${EXTRA_LIBS} --end-group" + "<CMAKE_LINKER> ${LDFLAGS} --entry=${ENTRY_NAME} -T${LINKER_SCRIPT} <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -L${NUTTX_PATH}/libs --start-group ${LDLIBS} ${EXTRA_LIBS} --end-group" ) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)