blob: c1cf166a61940d29748a07d25ae7bdd543239a5e [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#!/bin/bash -e
2#set -x
3
4# This file should be called to build the code.
5# Usage: build.sh platform main_file.gyp debug [action]
6
7PLATFORM=$1
8GYP_MAIN=$2
9DEBUG=$3
10ACTION=$4
11
12export WIND_BASE=${WIND_BASE:-"/usr/local/powerpc-wrs-vxworks/wind_base"}
13
14[ ${PLATFORM} == "crio" -o ${PLATFORM} == "atom" ] || ( echo Platform "(${PLATFORM})" must be '"crio" or "atom"'. ; exit 1 )
15[ ${DEBUG} == "yes" -o ${DEBUG} == "no" ] || ( echo Debug "(${DEBUG})" must be '"yes" or "no"'. ; exit 1 )
16
17AOS=`dirname $0`/..
18NINJA_DIR=${AOS}/externals/ninja
19NINJA=${NINJA_DIR}/ninja
20# From chromium@154360:trunk/src/DEPS.
21GYP_REVISION=1488
22GYP_DIR=${AOS}/externals/gyp-${GYP_REVISION}
23GYP=${GYP_DIR}/gyp
24
25OUTDIR=${AOS}/../out_${PLATFORM}
26BUILD_NINJA=${OUTDIR}/Default/build.ninja
27
28[ -d ${NINJA_DIR} ] || git clone --branch release https://github.com/martine/ninja.git ${NINJA_DIR}
29[ -x ${NINJA} ] || ${NINJA_DIR}/bootstrap.py
30[ -d ${GYP_DIR} ] || ( svn co http://gyp.googlecode.com/svn/trunk -r ${GYP_REVISION} ${GYP_DIR} && patch -p1 -d ${GYP_DIR} < ${AOS}/externals/gyp.patch )
31${AOS}/build/download_externals.sh
32
33# The exciting quoting is so that it ends up with -DWHATEVER='"'`a command`'"'.
34# The '"' at either end is so that it creates a string constant when expanded
35# in the C/C++ code.
36COMMONFLAGS='-DLOG_SOURCENAME='"'\"'"'`basename $in`'"'\"' "
37if [ ${PLATFORM} == crio ]; then
38 COMMONFLAGS+='-DAOS_INITNAME=aos_init_function_`readlink -f $out | sed \"s/[\/.]/_/g\"` '
39fi
40
41if [[ "${ACTION}" != "clean" && ( ! -d ${OUTDIR} || -n \
42 "`find ${AOS}/.. -newer ${BUILD_NINJA} \( -name '*.gyp' -or -name '*.gypi' \)`" ) ]]; then
43 ${GYP} \
44 --check --depth=${AOS}/.. --no-circular-check -f ninja \
45 -I${AOS}/build/aos.gypi -Goutput_dir=out_${PLATFORM} \
46 -DOS=${PLATFORM} -DWIND_BASE=${WIND_BASE} -DDEBUG=${DEBUG} \
47 ${GYP_MAIN}
48 # Have to substitute "command = $compiler" so that it doesn't try to
49 # substitute them in the linker commands, where it doesn't work.
50 sed -i "s:command = \$cc:\\0 ${COMMONFLAGS}:g ; \
51 s:command = \$cxx:\\0 ${COMMONFLAGS}:g" \
52 ${BUILD_NINJA}
53 if [ ${PLATFORM} == crio ]; then
54 sed -i 's/nm -gD/nm/g' ${BUILD_NINJA}
55 fi
56fi
57
58if [ "${ACTION}" == "clean" ]; then
59 rm -r ${OUTDIR}
60else
Brian Silvermandff55a22013-04-28 18:11:00 -070061 if [ "${ACTION}" != "deploy" -a "${ACTION}" != "tests" -a "${ACTION}" != "redeploy" ]; then
62 GYP_ACTION=${ACTION}
63 else
64 GYP_ACTION=
65 fi
brians343bc112013-02-10 01:53:46 +000066 ${NINJA} -C ${OUTDIR}/Default ${GYP_ACTION}
Brian Silvermandff55a22013-04-28 18:11:00 -070067 if [[ ${ACTION} == deploy || ${ACTION} == redeploy ]]; then
68 [ ${PLATFORM} == atom ] && \
69 rsync --progress -c -r --rsync-path=/home/driver/bin/rsync \
70 ${OUTDIR}/Default/outputs/* \
71 driver@`${AOS}/build/get_ip fitpc`:/home/driver/robot_code/bin
72 [ ${PLATFORM} == crio ] && \
73 ncftpput `${AOS}/build/get_ip robot` / \
74 ${OUTDIR}/Default/lib/FRC_UserProgram.out
75 fi
76 if [[ ${ACTION} == redeploy ]]; then
77 if [[ ${PLATFORM} != crio ]]; then
78 echo "Platform ${PLATFORM} does not support redeploy." 1>&2
79 exit 1
80 fi
81 ${OUTDIR}/../out_atom/Default/outputs/netconsole <<"END"
82unld "FRC_UserProgram.out"
83ld < FRC_UserProgram.out
84END
85 fi
86 if [[ ${ACTION} == tests ]]; then
87 find ${OUTDIR}/Default/tests -executable -exec {} \;
88 fi
brians343bc112013-02-10 01:53:46 +000089fi