c1545db09a2e69527f3ce8e93eb71a030b7c0ad8
1 #!/bin/sh
2 #
3 # Command-line build of an Energia MT sketch
4 #
5 # Usage: ebuild [-e energia_root] [-t target] sketch-dir build-dir [ppopts...]
6 #
7 # where,
8 # -e energia_root - installation directory of Energia MT. If not
9 # specified, uses the directory containing the directory
10 # containing this script; i.e., `dirname $0`/..
11 # Note: a complete installation of Energia is required
12 # in order to build an executable.
13 # -t target - target; e.g., cc3200emt:RedBearLab_CC3200. If not
14 # specified, uses cc3200emt:CC3200_LAUNCHXL
15 # sketch_dir - directory containing the sketch to build
16 # build_dir - output directory for the build of the sketch
17 # ppopts - Energia MT preprocessor (ino2cpp) options; e.g.,
18 # -Dsketchbook.path=...
19 # -Dbuild.drvlib={true|false}
20 #
21 # Note: A complete installation of Energia is REQUIRED in order for the build
22 # to work. Energia contains numerous makefiles, all of which are
23 # required to complete the build.
24 #
25 # Examples
26 # 1. Build a sketch for the cc3200emt:CC3200_LAUNCHXL
27 #
28 # ebuild.ksh mysketch mybuild
29 #
30 # 2. Using example from a contributed library installed in, say,
31 # $ZUMOCC3200, build in the local directory ./foo
32 #
33 # ebuild.ksh -t cc3200emt:RedBearLab_CC3200 \
34 # $ZUMOCC3200/examples/AssistedDrive ./foo \
35 # -Dsketchbook.path=../$ZUMOCC3200
36 #
38 pname="$0"
39 mydir="`dirname $pname`"
41 # someday this will be inside Energia
42 INO2CPP="$mydir"
43 ENERGIA="`cd $mydir/..; /bin/pwd`"
45 usage="usage: $0 [-e energia_root] [-t target] sketch-dir build-dir [ino2cpp_options ...]"
47 ## parse command line options
48 target="cc3200emt:CC3200_LAUNCHXL"
49 while getopts e:t: c ; do
50 case $c in
51 e ) ENERGIA="$OPTARG" ;;
52 t ) target="$OPTARG" ;;
53 \?) echo "$usage"
54 exit 1;;
55 esac
56 done
57 shift `expr $OPTIND - 1`
59 ## validate command line options
60 if [ $# -lt 2 ]; then
61 echo $usage
62 exit 1
63 fi
65 sketch=$1
66 build=$2
67 shift 2
69 ## locate a java command
70 JAVA=java
71 for j in "$ENERGIA/java/bin/java" "`which java 2> /dev/null`" "$JAVA_HOME/bin/java"; do
72 if [ -x "$j" -o -x "$j.exe" ]; then
73 JAVA="$j"
74 break
75 fi
76 done
78 ## locate a make command
79 MAKE=make
80 for m in $ENERGIA/tools/common/bin/make "`which make 2> /dev/null`"; do
81 if [ -x "$m" -o -x "$m.exe" ]; then
82 MAKE="$m"
83 break
84 fi
85 done
87 ## check that ENERGIA is in fact an Energia installation
88 if [ ! -r "$ENERGIA/hardware/common/Makefile" ]; then
89 echo "$pname: error: '$ENERGIA/hardware/common/Makefile' does not exist; '$ENERGIA' doesn't seem to be an installation of Energia." 2>&1
90 exit 1
91 fi
93 ## run the Energia Wiring preprocessor
94 echo processing $sketch [$target] ...
95 $JAVA -jar $INO2CPP/ino2cpp.jar -o $build -T $INO2CPP/templates/Variables.mk.template -r $ENERGIA $* $sketch $target
96 if [ "$?" != "0" ]; then
97 echo "$pname: error: Energia ino2cpp preprocessor failed." 2>&1
98 exit 1
99 fi
101 ## compile!
102 $MAKE -C $build -f "$ENERGIA/hardware/common/Makefile"