Home | History | Annotate | Download | only in tools
      1 #!/bin/bash
      2 #
      3 # Copyright (C) 2009 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 #
     17 
     18 # This script takes a Linux SDK, cleans it and injects the necessary Windows
     19 # binaries needed by the SDK. The script has 2 parts:
     20 # - development/tools/build/path_windows_sdk.sh to process the
     21 #   platform-dependent folders and files.
     22 # - sdk/build/patch_windows_sdk.sh to process folder and files which
     23 #   depend on the sdk.git repo. This file is invoked by the makefile
     24 #   at development/build/tools/windows_sdk.mk.
     25 #
     26 # Input arguments:
     27 # -q = Optional arg to make this silent. Must be given first.
     28 # $1 = Temporary SDK directory, that is the Linux SDK being patched into
     29 #      a Windows one.
     30 # $2 = The out/host/windows directory, which contains the new Windows
     31 #      binaries to use.
     32 # $3 = An optional replacement for $TOPDIR (inherited from the Android
     33 #      build system), which is the top directory where Android is located.
     34 
     35 set -e # any error stops the build
     36 
     37 # Verbose by default. Use -q to make more silent.
     38 V=""
     39 Q=""
     40 if [[ "$1" == "-q" ]]; then
     41     Q="$1"
     42     shift
     43 else
     44   echo "Win SDK: $0 $*"
     45   set -x # show bash commands; no need for V=-v
     46 fi
     47 
     48 TEMP_SDK_DIR=$1
     49 WIN_OUT_DIR=$2
     50 TOPDIR=${TOPDIR:-$3}
     51 
     52 # The unix2dos is provided by the APT package "tofrodos". However
     53 # as for ubuntu lucid, the package renamed the command to "todos".
     54 UNIX2DOS=$(which unix2dos || true)
     55 if [[ ! -x $UNIX2DOS ]]; then
     56   UNIX2DOS=$(which todos || true)
     57 fi
     58 
     59 PLATFORMS=( $TEMP_SDK_DIR/platforms/* )
     60 if [[ ${#PLATFORMS[@]} != 1 ]]; then
     61     echo "Error: Too many platforms found in $TEMP_SDK_DIR"
     62     echo "Expected one. Instead, found: ${PLATFORMS[@]}"
     63     exit 1
     64 fi
     65 
     66 # Package USB Driver
     67 if [[ -n "$USB_DRIVER_HOOK" ]]; then
     68     $USB_DRIVER_HOOK $V $TEMP_SDK_DIR $TOPDIR
     69 fi
     70 
     71 
     72 # Invoke atree to copy the files
     73 # TODO: pass down OUT_HOST_EXECUTABLE to get the right bin/atree directory
     74 ${TOPDIR}out/host/linux-x86/bin/atree -f ${TOPDIR}development/build/sdk-windows-x86.atree \
     75       -I $WIN_OUT_DIR/host/windows-x86 \
     76       -I ${TOPDIR:-.} \
     77       -o $TEMP_SDK_DIR
     78 
     79 # Fix EOL chars to make window users happy - fix all files at the top level
     80 # as well as all batch files including those in platform-tools/
     81 if [[ -x $UNIX2DOS ]]; then
     82   find $TEMP_SDK_DIR -maxdepth 1 -name "*.[ht]*" -type f -print0 | xargs -0 $UNIX2DOS
     83   find $TEMP_SDK_DIR -maxdepth 3 -name "*.bat"   -type f -print0 | xargs -0 $UNIX2DOS
     84 fi
     85 
     86 # Just to make it easier on the build servers, we want fastboot and adb
     87 # (and its DLLs) next to the new SDK.
     88 for i in fastboot.exe adb.exe AdbWinApi.dll AdbWinUsbApi.dll; do
     89     cp -f $V $WIN_OUT_DIR/host/windows-x86/bin/$i $TEMP_SDK_DIR/../$i
     90 done
     91 
     92