6f919985c09a14dca416860c04a7b544ad11aa73
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / support / scripts / eclipse-register-toolchain
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
28 if test $# -ne 3; then
29     echo "Invalid number of arguments."
30     echo "Usage: $0 project-directory toolchain-prefix architecture"
31     exit 1
32 fi
33
34 project_directory=$1
35 toolchain_prefix=$2
36 architecture=$3
37
38 if test ! -d ${project_directory} ; then
39     echo "Non-existing project directory ${project_directory}"
40     exit 1
41 fi
42
43 if test ! -d ${project_directory}/host ; then
44     echo "Your project directory does not look like a Buildroot output"
45     exit 1
46 fi
47
48 if test ! -e ${project_directory}/host/usr/bin/${toolchain_prefix}gcc ; then
49     echo "Cannot find the cross-compiler in the project directory"
50     exit 1
51 fi
52
53 TOOLCHAIN_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.
57 if 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
73 fi
74
75 # Add the toolchain
76 echo "${project_directory}:${toolchain_prefix}:${architecture}" >> ${TOOLCHAIN_ECLIPSE_FILE}