blob: 09fe83ced5256e02fb334ec932c141ecb7b1617e [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`/..
brians343bc112013-02-10 01:53:46 +000023
Brian Silvermanf10de2a2013-11-16 19:56:11 -080024OUTDIR=${AOS}/../output/${PLATFORM}
25BUILD_NINJA=${OUTDIR}/build.ninja
brians343bc112013-02-10 01:53:46 +000026
brians343bc112013-02-10 01:53:46 +000027${AOS}/build/download_externals.sh
Brian Silvermanf10de2a2013-11-16 19:56:11 -080028. $(dirname $0)/tools_config
brians343bc112013-02-10 01:53:46 +000029
30# The exciting quoting is so that it ends up with -DWHATEVER='"'`a command`'"'.
31# The '"' at either end is so that it creates a string constant when expanded
32# in the C/C++ code.
33COMMONFLAGS='-DLOG_SOURCENAME='"'\"'"'`basename $in`'"'\"' "
brians343bc112013-02-10 01:53:46 +000034
35if [[ "${ACTION}" != "clean" && ( ! -d ${OUTDIR} || -n \
36 "`find ${AOS}/.. -newer ${BUILD_NINJA} \( -name '*.gyp' -or -name '*.gypi' \)`" ) ]]; then
Brian Silvermanf10de2a2013-11-16 19:56:11 -080037 # This is a gyp "file" that we pipe into gyp so that it will put the output
38 # in a directory named what we want where we want it.
39 GYP_INCLUDE=$(cat <<END
40{
41 'target_defaults': {
42 'configurations': {
43 '${PLATFORM}': {}
44 }
45 }
46}
47END
48)
49 echo "${GYP_INCLUDE}" | ${GYP} \
50 --check --depth=${AOS}/.. --no-circular-check -f ninja \
51 -I${AOS}/build/aos.gypi -I/dev/stdin -Goutput_dir=output \
52 -DOS=${PLATFORM} -DWIND_BASE=${WIND_BASE} -DDEBUG=${DEBUG} \
53 ${GYP_MAIN}
brians343bc112013-02-10 01:53:46 +000054 # 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 Silvermanf10de2a2013-11-16 19:56:11 -080072 ${NINJA} -C ${OUTDIR} ${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 Silvermanf10de2a2013-11-16 19:56:11 -080076 ${OUTDIR}/outputs/* \
Brian Silverman31c99c82013-09-29 16:51:17 -070077 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` / \
Brian Silvermanf10de2a2013-11-16 19:56:11 -080081 ${OUTDIR}/lib/FRC_UserProgram.out
Brian Silvermandff55a22013-04-28 18:11:00 -070082 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
Brian Silvermanf10de2a2013-11-16 19:56:11 -080088 ${OUTDIR}/../out_atom/outputs/netconsole <<"END"
Brian Silvermandff55a22013-04-28 18:11:00 -070089unld "FRC_UserProgram.out"
90ld < FRC_UserProgram.out
91END
92 fi
93 if [[ ${ACTION} == tests ]]; then
Brian Silverman596ad952014-01-01 17:19:21 -080094 find ${OUTDIR}/tests -executable -exec ${AOS}/build/run_test.sh {} \;
Brian Silvermandff55a22013-04-28 18:11:00 -070095 fi
brians343bc112013-02-10 01:53:46 +000096fi