1#!/bin/bash
2#
3# Copyright (C) 2015 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17if [ ! -d art ]; then
18  echo "Script needs to be run at the root of the android tree"
19  exit 1
20fi
21
22# Logic for setting out_dir from build/make/core/envsetup.mk:
23if [[ -z $OUT_DIR ]]; then
24  if [[ -z $OUT_DIR_COMMON_BASE ]]; then
25    out_dir=out
26  else
27    out_dir=${OUT_DIR_COMMON_BASE}/${PWD##*/}
28  fi
29else
30  out_dir=${OUT_DIR}
31fi
32
33java_libraries_dir=${out_dir}/target/common/obj/JAVA_LIBRARIES
34common_targets="vogar core-tests apache-harmony-jdwp-tests-hostdex jsr166-tests mockito-target ${out_dir}/host/linux-x86/bin/jack"
35mode="target"
36j_arg="-j$(nproc)"
37showcommands=
38make_command=
39
40while true; do
41  if [[ "$1" == "--host" ]]; then
42    mode="host"
43    shift
44  elif [[ "$1" == "--target" ]]; then
45    mode="target"
46    shift
47  elif [[ "$1" == -j* ]]; then
48    j_arg=$1
49    shift
50  elif [[ "$1" == "--showcommands" ]]; then
51    showcommands="showcommands"
52    shift
53  elif [[ "$1" == "" ]]; then
54    break
55  else
56    echo "Unknown options $@"
57    exit 1
58  fi
59done
60
61if [[ $mode == "host" ]]; then
62  make_command="make $j_arg $showcommands build-art-host-tests $common_targets"
63  make_command+=" ${out_dir}/host/linux-x86/lib/libjavacoretests.so "
64  make_command+=" ${out_dir}/host/linux-x86/lib64/libjavacoretests.so"
65elif [[ $mode == "target" ]]; then
66  make_command="make $j_arg $showcommands build-art-target-tests $common_targets"
67  make_command+=" libjavacrypto libjavacoretests libnetd_client linker toybox toolbox sh"
68  make_command+=" ${out_dir}/host/linux-x86/bin/adb libstdc++ "
69  make_command+=" ${out_dir}/target/product/${TARGET_PRODUCT}/system/etc/public.libraries.txt"
70fi
71
72echo "Executing $make_command"
73$make_command
74