eclipse-register-toolchain 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/sh
  2. # This script registers the toolchain of a Buildroot project into the
  3. # Eclipse plugin. To do so, it adds a new line for the Buildroot
  4. # toolchain into the $HOME/.buildroot-eclipse.toolchains file, which
  5. # the Eclipse Buildroot plugin reads to discover automatically the
  6. # available Buildroot toolchains on the system.
  7. #
  8. # This script should typically not be called manually. Instead, one
  9. # should enable the BR2_ECLIPSE_REGISTER configuration option, which
  10. # will lead Buildroot to automatically call this script with the
  11. # appropriate arguments.
  12. #
  13. # Usage:
  14. # eclipse-register-toolchain project-directory toolchain-prefix architecture
  15. #
  16. # project-directory is the absolute path to the Buildroot project
  17. # output directory (which contains the host/, target/, build/,
  18. # images/, etc. subdirectories). It should be an absolute and
  19. # canonical path.
  20. #
  21. # toolchain-prefix is the prefix of the cross-compilation tools, i.e
  22. # 'arm-linux-' if the cross-compiler executable is 'arm-linux-gcc'.
  23. #
  24. # architecture is the lower-cased name of the architecture targetted
  25. # by the Buildroot project.
  26. if test $# -ne 3; then
  27. echo "Invalid number of arguments."
  28. echo "Usage: $0 project-directory toolchain-prefix architecture"
  29. exit 1
  30. fi
  31. project_directory=$1
  32. toolchain_prefix=$2
  33. architecture=$3
  34. if test ! -d ${project_directory} ; then
  35. echo "Non-existing project directory ${project_directory}"
  36. exit 1
  37. fi
  38. if test ! -d ${project_directory}/host ; then
  39. echo "Your project directory does not look like a Buildroot output"
  40. exit 1
  41. fi
  42. if test ! -e ${project_directory}/host/bin/${toolchain_prefix}gcc ; then
  43. echo "Cannot find the cross-compiler in the project directory"
  44. exit 1
  45. fi
  46. TOOLCHAIN_ECLIPSE_FILE=${HOME}/.buildroot-eclipse.toolchains
  47. # First, we remove all lines from the ${TOOLCHAIN_ECLISPE_FILE} that
  48. # correspond to toolchains that no longer exist.
  49. if test -f ${TOOLCHAIN_ECLIPSE_FILE} ; then
  50. mv ${TOOLCHAIN_ECLIPSE_FILE} ${TOOLCHAIN_ECLIPSE_FILE}.tmp
  51. cat ${TOOLCHAIN_ECLIPSE_FILE}.tmp | while read toolchain ; do
  52. path=$(echo ${toolchain} | cut -f1 -d ':')
  53. # Filter lines corresponding to still existing projects
  54. echo "Testing ${path} ..."
  55. if ! test -d ${path} ; then
  56. continue
  57. fi
  58. # .. and the current project
  59. if test ${path} = ${project_directory} ; then
  60. continue
  61. fi
  62. echo ${toolchain} >> ${TOOLCHAIN_ECLIPSE_FILE}
  63. done
  64. rm ${TOOLCHAIN_ECLIPSE_FILE}.tmp
  65. fi
  66. # Add the toolchain
  67. echo "${project_directory}:${toolchain_prefix}:${architecture}" >> ${TOOLCHAIN_ECLIPSE_FILE}