blob: 9ec745a7e19d95968aaa185f7c400a9b51846045 [file] [log] [blame]
Brian Silvermana67ecc72013-09-28 13:53:53 -07001#!/bin/bash
brians343bc112013-02-10 01:53:46 +00002#set -x
3
Brian Silvermana67ecc72013-09-28 13:53:53 -07004set -e
5
brians343bc112013-02-10 01:53:46 +00006# This file should be called to build the code.
Brian Silvermana67ecc72013-09-28 13:53:53 -07007# Usage: build.sh platform main_file.gyp debug [action]...
brians343bc112013-02-10 01:53:46 +00008
9PLATFORM=$1
10GYP_MAIN=$2
11DEBUG=$3
12ACTION=$4
13
Brian Silvermana67ecc72013-09-28 13:53:53 -070014shift 3
15shift || true # We might not have a 4th argument if ACTION is empty.
16
brians343bc112013-02-10 01:53:46 +000017export WIND_BASE=${WIND_BASE:-"/usr/local/powerpc-wrs-vxworks/wind_base"}
18
Brian Silvermana67ecc72013-09-28 13:53:53 -070019[ "${PLATFORM}" == "crio" -o "${PLATFORM}" == "atom" ] || ( echo Platform "(${PLATFORM})" must be '"crio" or "atom"'. ; exit 1 )
20[ "${DEBUG}" == "yes" -o "${DEBUG}" == "no" ] || ( echo Debug "(${DEBUG})" must be '"yes" or "no"'. ; exit 1 )
brians343bc112013-02-10 01:53:46 +000021
22AOS=`dirname $0`/..
Brian Silvermana67ecc72013-09-28 13:53:53 -070023NINJA_RELEASE=v1.4.0
24NINJA_DIR=${AOS}/externals/ninja-${NINJA_RELEASE}
brians343bc112013-02-10 01:53:46 +000025NINJA=${NINJA_DIR}/ninja
26# From chromium@154360:trunk/src/DEPS.
Brian Silvermana67ecc72013-09-28 13:53:53 -070027GYP_REVISION=1738
brians343bc112013-02-10 01:53:46 +000028GYP_DIR=${AOS}/externals/gyp-${GYP_REVISION}
29GYP=${GYP_DIR}/gyp
30
31OUTDIR=${AOS}/../out_${PLATFORM}
32BUILD_NINJA=${OUTDIR}/Default/build.ninja
33
Brian Silvermana67ecc72013-09-28 13:53:53 -070034[ -d ${NINJA_DIR} ] || git clone --branch ${NINJA_RELEASE} https://github.com/martine/ninja.git ${NINJA_DIR}
brians343bc112013-02-10 01:53:46 +000035[ -x ${NINJA} ] || ${NINJA_DIR}/bootstrap.py
36[ -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 )
37${AOS}/build/download_externals.sh
38
39# The exciting quoting is so that it ends up with -DWHATEVER='"'`a command`'"'.
40# The '"' at either end is so that it creates a string constant when expanded
41# in the C/C++ code.
42COMMONFLAGS='-DLOG_SOURCENAME='"'\"'"'`basename $in`'"'\"' "
43if [ ${PLATFORM} == crio ]; then
44 COMMONFLAGS+='-DAOS_INITNAME=aos_init_function_`readlink -f $out | sed \"s/[\/.]/_/g\"` '
45fi
46
47if [[ "${ACTION}" != "clean" && ( ! -d ${OUTDIR} || -n \
48 "`find ${AOS}/.. -newer ${BUILD_NINJA} \( -name '*.gyp' -or -name '*.gypi' \)`" ) ]]; then
49 ${GYP} \
50 --check --depth=${AOS}/.. --no-circular-check -f ninja \
51 -I${AOS}/build/aos.gypi -Goutput_dir=out_${PLATFORM} \
52 -DOS=${PLATFORM} -DWIND_BASE=${WIND_BASE} -DDEBUG=${DEBUG} \
53 ${GYP_MAIN}
54 # Have to substitute "command = $compiler" so that it doesn't try to
55 # substitute them in the linker commands, where it doesn't work.
56 sed -i "s:command = \$cc:\\0 ${COMMONFLAGS}:g ; \
57 s:command = \$cxx:\\0 ${COMMONFLAGS}:g" \
58 ${BUILD_NINJA}
59 if [ ${PLATFORM} == crio ]; then
60 sed -i 's/nm -gD/nm/g' ${BUILD_NINJA}
61 fi
62fi
63
64if [ "${ACTION}" == "clean" ]; then
Brian Silvermana67ecc72013-09-28 13:53:53 -070065 rm -r ${OUTDIR} || true
brians343bc112013-02-10 01:53:46 +000066else
Brian Silvermandff55a22013-04-28 18:11:00 -070067 if [ "${ACTION}" != "deploy" -a "${ACTION}" != "tests" -a "${ACTION}" != "redeploy" ]; then
Brian Silvermana67ecc72013-09-28 13:53:53 -070068 NINJA_ACTION=${ACTION}
Brian Silvermandff55a22013-04-28 18:11:00 -070069 else
Brian Silvermana67ecc72013-09-28 13:53:53 -070070 NINJA_ACTION=
Brian Silvermandff55a22013-04-28 18:11:00 -070071 fi
Brian Silvermana67ecc72013-09-28 13:53:53 -070072 ${NINJA} -C ${OUTDIR}/Default ${NINJA_ACTION} "$@"
Brian Silvermandff55a22013-04-28 18:11:00 -070073 if [[ ${ACTION} == deploy || ${ACTION} == redeploy ]]; then
74 [ ${PLATFORM} == atom ] && \
Brian Silverman6b894d72013-08-28 16:21:30 -070075 rsync --progress -c -r \
Brian Silverman31c99c82013-09-29 16:51:17 -070076 ${OUTDIR}/Default/outputs/* \
77 driver@`${AOS}/build/get_ip fitpc`:/home/driver/robot_code/bin
78 ssh driver@`${AOS}/build/get_ip fitpc` "sync; sync; sync"
Brian Silvermandff55a22013-04-28 18:11:00 -070079 [ ${PLATFORM} == crio ] && \
80 ncftpput `${AOS}/build/get_ip robot` / \
81 ${OUTDIR}/Default/lib/FRC_UserProgram.out
82 fi
83 if [[ ${ACTION} == redeploy ]]; then
84 if [[ ${PLATFORM} != crio ]]; then
85 echo "Platform ${PLATFORM} does not support redeploy." 1>&2
86 exit 1
87 fi
88 ${OUTDIR}/../out_atom/Default/outputs/netconsole <<"END"
89unld "FRC_UserProgram.out"
90ld < FRC_UserProgram.out
91END
92 fi
93 if [[ ${ACTION} == tests ]]; then
94 find ${OUTDIR}/Default/tests -executable -exec {} \;
95 fi
brians343bc112013-02-10 01:53:46 +000096fi