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