Home | History | Annotate | Download | only in makefile
      1 #!/bin/bash -e
      2 # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
      3 #
      4 # Licensed under the Apache License, Version 2.0 (the "License");
      5 # you may not use this file except in compliance with the License.
      6 # You may obtain a copy of the License at
      7 #
      8 #     http://www.apache.org/licenses/LICENSE-2.0
      9 #
     10 # Unless required by applicable law or agreed to in writing, software
     11 # distributed under the License is distributed on an "AS IS" BASIS,
     12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 # See the License for the specific language governing permissions and
     14 # limitations under the License.
     15 # ==============================================================================
     16 # Utility functions for scripts to build tensorflow by Makefile
     17 
     18 get_cpu_count() {
     19   case "${OSTYPE}" in
     20     linux*)
     21       grep processor /proc/cpuinfo | wc -l ;;
     22     darwin*)
     23       sysctl hw.ncpu | awk '{print $2}' ;;
     24     cygwin*)
     25       grep processor /proc/cpuinfo | wc -l ;;
     26     *)
     27       echo "1"
     28       exit 1 ;;
     29   esac
     30   exit 0
     31 }
     32 
     33 get_job_count() {
     34   echo $(($(get_cpu_count)))
     35 }
     36 
     37 make_host_protoc() {
     38   if [[ ! $1 ]]; then
     39     echo "needs 1 argument (HOST_GENDIR)"
     40     exit 1
     41   fi
     42   HOST_GENDIR="$1"
     43   ./autogen.sh
     44   if [ $? -ne 0 ]
     45   then
     46     echo "./autogen.sh command failed."
     47     exit 1
     48   fi
     49   rm -rf "${HOST_GENDIR}"
     50   mkdir -p "${HOST_GENDIR}"
     51   ./configure --disable-shared --prefix="${HOST_GENDIR}"
     52   make clean
     53   make -j"$(get_job_count)"
     54   if [ $? -ne 0 ]; then
     55     echo "make failed"
     56     exit 1
     57   fi
     58   make install
     59 }
     60 
     61 download_and_push() {
     62   URL="$1"
     63   LOCAL_DEST="$2"
     64   ANDROID_DEST="$3"
     65   SKIP_DOWNLOAD_IF_EXIST="$4"
     66   if [[ "${SKIP_DOWNLOAD_IF_EXIST}" == "true" ]]; then
     67     ANDROID_DEST_FILE_PATH="${ANDROID_DEST}/$(basename "${LOCAL_DEST}")"
     68     if adb shell test -f "${ANDROID_DEST_FILE_PATH}"; then
     69         echo "${ANDROID_DEST_FILE_PATH} already existins, skip download" 1>&2
     70       return 0
     71     fi
     72   fi
     73 
     74   curl -Ls "${URL}" -o "${LOCAL_DEST}"
     75 
     76   if [[ ! -z "${ANDROID_DEST}" ]]; then
     77     adb shell mkdir -p "${ANDROID_DEST}"
     78     adb push "${LOCAL_DEST}" "${ANDROID_DEST}"
     79   fi
     80 }
     81