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