blob: 0fe13ab0258da2611438616086d19b853a3022b4 [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 Silverman14fd0fb2014-01-14 21:42:01 -080020[ "${PLATFORM}" == "crio" -o "${PLATFORM}" == "linux" ] || ( echo Platform "(${PLATFORM})" must be '"crio" or "linux"'. ; exit 1 )
Brian Silvermana67ecc72013-09-28 13:53:53 -070021[ "${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': {
Daniel Petti4b25ad82013-11-19 11:33:23 -080044 '${OUT_NAME}': {}
Brian Silvermanf10de2a2013-11-16 19:56:11 -080045 }
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 Silverman14fd0fb2014-01-14 21:42:01 -080068 if [ "${ACTION}" != "deploy" -a "${ACTION}" != "tests" ]; 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 Silverman14fd0fb2014-01-14 21:42:01 -080074 if [[ ${ACTION} == deploy ]]; then
75 [[ ${PLATFORM} == linux ]] && \
Brian Silverman6b894d72013-08-28 16:21:30 -070076 rsync --progress -c -r \
Brian Silvermanf10de2a2013-11-16 19:56:11 -080077 ${OUTDIR}/outputs/* \
Brian Silverman14fd0fb2014-01-14 21:42:01 -080078 driver@`${AOS}/build/get_ip prime`:/home/driver/robot_code/bin
79 ssh driver@`${AOS}/build/get_ip prime` "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
Brian Silvermandff55a22013-04-28 18:11:00 -070084 if [[ ${ACTION} == tests ]]; then
Brian Silvermanf10de2a2013-11-16 19:56:11 -080085 find ${OUTDIR}/tests -executable -exec {} \;
Brian Silvermandff55a22013-04-28 18:11:00 -070086 fi
brians343bc112013-02-10 01:53:46 +000087fi