on master help sign in
unity8/build.sh
82 lines 2.1 kB history raw
1#!/bin/sh
3#
4# Copyright (C) 2017 Canonical Ltd
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License version 3 as
8# published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
19SETUP=false
20CLEAN=false
21NUM_JOBS=$(( `grep -c ^processor /proc/cpuinfo` + 1 ))
22CODE_DIR=$( dirname `readlink -f $0` )
24usage() {
25 echo "usage: build [OPTIONS] [BUILD_TYPE]\n" >&2
26 echo "Script to build the shell. If BUILD_TYPE is not specified, it defaults to \"debug\".\n" >&2
27 echo "OPTIONS:" >&2
28 echo " -c, --clean Clean the build tree before building" >&2
29 echo >&2
30 exit 1
33ARGS=`getopt -n$0 -u -a --longoptions="setup,clean,help" -o "sch" -- "$@"`
34[ $? -ne 0 ] && usage
35eval set -- "$ARGS"
37while [ $# -gt 0 ]
38do
39 case "$1" in
40 -c|--clean) CLEAN=true;;
41 -h|--help) usage;;
42 --) shift;break;;
43 esac
44 shift
45done
47[ $# -gt 1 ] && usage
49BUILD_TYPE="debug"
50[ $# -eq 1 ] && BUILD_TYPE="$1"
52mk_build_deps() {
53 if [ ! -f control -o $CODE_DIR/debian/control -nt control ]; then
54 sed 's/\:native//g' $CODE_DIR/debian/control > control
55 mk-build-deps --install --root-cmd sudo control
56 fi
59if [ -f "/usr/bin/ccache" ] ; then
60 if [ "x$CC" = "x" ]; then
61 export CC='ccache gcc'
62 fi
63 if [ "x$CXX" = "x" ] ; then
64 export CXX='ccache g++'
65 fi
66fi
68if [ -f "/usr/bin/ninja" ] ; then
69 GENERATOR="-G Ninja"
70 # Ninja does not need -j, it parallelizes automatically.
71 BUILD_COMMAND="ninja"
72else
73 GENERATOR=
74 BUILD_COMMAND="make -j$NUM_JOBS"
75fi
77if $CLEAN; then rm -rf builddir; fi
78mkdir -p builddir
79cd builddir
80mk_build_deps
81cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CODE_DIR ${GENERATOR} || exit 6
82${BUILD_COMMAND} || exit 7