blob: c7a4bc426317ef77eb6973c10084b17d5aaee24c [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
Daniel Pettied2ee752013-09-27 04:26:13 +000012OUT_NAME=$4
13ACTION=$5
brians343bc112013-02-10 01:53:46 +000014
Daniel Petti8378ebf2013-10-29 01:45:33 +000015shift 4
Daniel Pettib046c532013-10-29 03:40:40 +000016shift || true # We might not have a 5th argument if ACTION is empty.
Brian Silvermana67ecc72013-09-28 13:53:53 -070017
brians343bc112013-02-10 01:53:46 +000018export WIND_BASE=${WIND_BASE:-"/usr/local/powerpc-wrs-vxworks/wind_base"}
19
Brian Silvermana67ecc72013-09-28 13:53:53 -070020[ "${PLATFORM}" == "crio" -o "${PLATFORM}" == "atom" ] || ( echo Platform "(${PLATFORM})" must be '"crio" or "atom"'. ; exit 1 )
21[ "${DEBUG}" == "yes" -o "${DEBUG}" == "no" ] || ( echo Debug "(${DEBUG})" must be '"yes" or "no"'. ; exit 1 )
brians343bc112013-02-10 01:53:46 +000022
23AOS=`dirname $0`/..
brians343bc112013-02-10 01:53:46 +000024
Daniel Pettie16297b2013-11-18 14:03:32 -080025OUTDIR=${AOS}/../output/${OUT_NAME}
Brian Silvermanf10de2a2013-11-16 19:56:11 -080026BUILD_NINJA=${OUTDIR}/build.ninja
brians343bc112013-02-10 01:53:46 +000027
brians343bc112013-02-10 01:53:46 +000028${AOS}/build/download_externals.sh
Brian Silvermanf10de2a2013-11-16 19:56:11 -080029. $(dirname $0)/tools_config
brians343bc112013-02-10 01:53:46 +000030
31# The exciting quoting is so that it ends up with -DWHATEVER='"'`a command`'"'.
32# The '"' at either end is so that it creates a string constant when expanded
33# in the C/C++ code.
34COMMONFLAGS='-DLOG_SOURCENAME='"'\"'"'`basename $in`'"'\"' "
brians343bc112013-02-10 01:53:46 +000035
36if [[ "${ACTION}" != "clean" && ( ! -d ${OUTDIR} || -n \
37 "`find ${AOS}/.. -newer ${BUILD_NINJA} \( -name '*.gyp' -or -name '*.gypi' \)`" ) ]]; then
Brian Silvermanf10de2a2013-11-16 19:56:11 -080038 # This is a gyp "file" that we pipe into gyp so that it will put the output
39 # in a directory named what we want where we want it.
40 GYP_INCLUDE=$(cat <<END
41{
42 'target_defaults': {
43 'configurations': {
44 '${PLATFORM}': {}
45 }
46 }
47}
48END
49)
50 echo "${GYP_INCLUDE}" | ${GYP} \
51 --check --depth=${AOS}/.. --no-circular-check -f ninja \
52 -I${AOS}/build/aos.gypi -I/dev/stdin -Goutput_dir=output \
53 -DOS=${PLATFORM} -DWIND_BASE=${WIND_BASE} -DDEBUG=${DEBUG} \
54 ${GYP_MAIN}
brians343bc112013-02-10 01:53:46 +000055 # Have to substitute "command = $compiler" so that it doesn't try to
56 # substitute them in the linker commands, where it doesn't work.
57 sed -i "s:command = \$cc:\\0 ${COMMONFLAGS}:g ; \
58 s:command = \$cxx:\\0 ${COMMONFLAGS}:g" \
59 ${BUILD_NINJA}
60 if [ ${PLATFORM} == crio ]; then
61 sed -i 's/nm -gD/nm/g' ${BUILD_NINJA}
62 fi
63fi
64
65if [ "${ACTION}" == "clean" ]; then
Brian Silvermana67ecc72013-09-28 13:53:53 -070066 rm -r ${OUTDIR} || true
brians343bc112013-02-10 01:53:46 +000067else
Brian Silvermandff55a22013-04-28 18:11:00 -070068 if [ "${ACTION}" != "deploy" -a "${ACTION}" != "tests" -a "${ACTION}" != "redeploy" ]; then
Brian Silvermana67ecc72013-09-28 13:53:53 -070069 NINJA_ACTION=${ACTION}
Brian Silvermandff55a22013-04-28 18:11:00 -070070 else
Brian Silvermana67ecc72013-09-28 13:53:53 -070071 NINJA_ACTION=
Brian Silvermandff55a22013-04-28 18:11:00 -070072 fi
Brian Silvermanf10de2a2013-11-16 19:56:11 -080073 ${NINJA} -C ${OUTDIR} ${NINJA_ACTION} "$@"
Brian Silvermandff55a22013-04-28 18:11:00 -070074 if [[ ${ACTION} == deploy || ${ACTION} == redeploy ]]; then
Daniel Pettib046c532013-10-29 03:40:40 +000075 [[ ${PLATFORM} =~ .*atom ]] && \
Brian Silverman6b894d72013-08-28 16:21:30 -070076 rsync --progress -c -r \
Brian Silvermanf10de2a2013-11-16 19:56:11 -080077 ${OUTDIR}/outputs/* \
Brian Silverman31c99c82013-09-29 16:51:17 -070078 driver@`${AOS}/build/get_ip fitpc`:/home/driver/robot_code/bin
79 ssh driver@`${AOS}/build/get_ip fitpc` "sync; sync; sync"
Brian Silvermandff55a22013-04-28 18:11:00 -070080 [ ${PLATFORM} == crio ] && \
81 ncftpput `${AOS}/build/get_ip robot` / \
Brian Silvermanf10de2a2013-11-16 19:56:11 -080082 ${OUTDIR}/lib/FRC_UserProgram.out
Brian Silvermandff55a22013-04-28 18:11:00 -070083 fi
84 if [[ ${ACTION} == redeploy ]]; then
85 if [[ ${PLATFORM} != crio ]]; then
86 echo "Platform ${PLATFORM} does not support redeploy." 1>&2
87 exit 1
88 fi
Brian Silvermanf10de2a2013-11-16 19:56:11 -080089 ${OUTDIR}/../out_atom/outputs/netconsole <<"END"
Brian Silvermandff55a22013-04-28 18:11:00 -070090unld "FRC_UserProgram.out"
91ld < FRC_UserProgram.out
92END
93 fi
94 if [[ ${ACTION} == tests ]]; then
Brian Silvermanf10de2a2013-11-16 19:56:11 -080095 find ${OUTDIR}/tests -executable -exec {} \;
Brian Silvermandff55a22013-04-28 18:11:00 -070096 fi
brians343bc112013-02-10 01:53:46 +000097fi