Android source目录添加编译工程脚本(含ccache)

将此脚本置于android 工程源码根目录,即可用此脚本起build,且取名为compile.sh

#!/bin/bash

#

# Copyright (c) 2012, The Linux Foundation. All rights reserved.

#

# Redistribution and use in source and binary forms, with or without

# modification, are permitted provided that the following conditions are

# met:

# * Redistributions of source code must retain the above copyright

# notice, this list of conditions and the following disclaimer.

# * Redistributions in binary form must reproduce the above

# copyright notice, this list of conditions and the following

# disclaimer in the documentation and/or other materials provided

# with the distribution.

# * Neither the name of The Linux Foundation nor the names of its

# contributors may be used to endorse or promote products derived

# from this software without specific prior written permission.

#

# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED

# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF

# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT

# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS

# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR

# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF

# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR

# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,

# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE

# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN

# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#

set -o errexit

usage() {

cat <<USAGE

Usage:

bash $0 <TARGET_PRODUCT> [OPTIONS]

Description:

Builds Android tree for given TARGET_PRODUCT

OPTIONS:

-c, --clean_build

Clean build - build from scratch by removing entire out dir

-d, --debug

Enable debugging - captures all commands while doing the build

-h, --help

Display this help message

-i, --image

Specify image to be build/re-build (bootimg/sysimg/usrimg)

-j, --jobs

Specifies the number of jobs to run simultaneously (Default: 8)

-k, --kernel_defconf

Specify defconf file to be used for compiling Kernel

-l, --log_file

Log file to store build logs (Default: <TARGET_PRODUCT>.log)

-m, --module

Module to be build

-p, --project

Project to be build

-s, --setup_ccache

Set CCACHE for faster incremental builds (true/false - Default: true)

-u, --update-api

Update APIs

-v, --build_variant

Build variant (Default: userdebug)

USAGE

}

clean_build() {

echo -e "\nINFO: Removing entire out dir. . .\n"

make clobber

}

build_android() {

echo -e "\nINFO: Build Android tree for $TARGET\n"

make [email protected] | tee $LOG_FILE.log

}

build_bootimg() {

echo -e "\nINFO: Build bootimage for $TARGET\n"

make bootimage [email protected] | tee $LOG_FILE.log

}

build_sysimg() {

echo -e "\nINFO: Build systemimage for $TARGET\n"

make systemimage [email protected] | tee $LOG_FILE.log

}

build_usrimg() {

echo -e "\nINFO: Build userdataimage for $TARGET\n"

make userdataimage [email protected] | tee $LOG_FILE.log

}

build_module() {

echo -e "\nINFO: Build $MODULE for $TARGET\n"

make $MODULE [email protected] | tee $LOG_FILE.log

}

build_project() {

echo -e "\nINFO: Build $PROJECT for $TARGET\n"

mmm $PROJECT | tee $LOG_FILE.log

}

update_api() {

echo -e "\nINFO: Updating APIs\n"

make update-api | tee $LOG_FILE.log

}

setup_ccache() {

export CCACHE_DIR=../.ccache

export USE_CCACHE=1

}

delete_ccache() {

prebuilts/misc/linux-x86/ccache/ccache -C

rm -rf $CCACHE_DIR

}

create_ccache() {

echo -e "\nINFO: Setting CCACHE with 10 GB\n"

setup_ccache

delete_ccache

prebuilts/misc/linux-x86/ccache/ccache -M 10G

}

# Set defaults

VARIANT="userdebug"

JOBS=8

CCACHE="true"

# Setup getopt.

long_opts="clean_build,debug,help,image:,jobs:,kernel_defconf:,log_file:,module:,"

long_opts+="project:,setup_ccache:,update-api,build_variant:"

getopt_cmd=$(getopt -o cdhi:j:k:l:m:p:s:uv: --long "$long_opts" \

-n $(basename $0) -- "[email protected]") || \

{ echo -e "\nERROR: Getopt failed. Extra args\n"; usage; exit 1;}

eval set -- "$getopt_cmd"

while true; do

case "$1" in

-c|--clean_build) CLEAN_BUILD="true";;

-d|--debug) DEBUG="true";;

-h|--help) usage; exit 0;;

-i|--image) IMAGE="$2"; shift;;

-j|--jobs) JOBS="$2"; shift;;

-k|--kernel_defconf) DEFCONFIG="$2"; shift;;

-l|--log_file) LOG_FILE="$2"; shift;;

-m|--module) MODULE="$2"; shift;;

-p|--project) PROJECT="$2"; shift;;

-u|--update-api) UPDATE_API="true";;

-s|--setup_ccache) CCACHE="$2"; shift;;

-v|--build_variant) VARIANT="$2"; shift;;

--) shift; break;;

esac

shift

done

# Mandatory argument

if [ $# -eq 0 ]; then

echo -e "\nERROR: Missing mandatory argument: TARGET_PRODUCT\n"

usage

exit 1

fi

if [ $# -gt 1 ]; then

echo -e "\nERROR: Extra inputs. Need TARGET_PRODUCT only\n"

usage

exit 1

fi

TARGET="$1"; shift

if [ -z $LOG_FILE ]; then

LOG_FILE=$TARGET

fi

CMD="-j $JOBS"

if [ "$DEBUG" = "true" ]; then

CMD+=" showcommands"

fi

if [ -n "$DEFCONFIG" ]; then

CMD+=" KERNEL_DEFCONFIG=$DEFCONFIG"

fi

if [ "$CCACHE" = "true" ]; then

setup_ccache

fi

source build/envsetup.sh

lunch $TARGET-$VARIANT

if [ "$CLEAN_BUILD" = "true" ]; then

clean_build

if [ "$CCACHE" = "true" ]; then

create_ccache

fi

fi

if [ "$UPDATE_API" = "true" ]; then

update_api

fi

if [ -n "$MODULE" ]; then

build_module "$CMD"

fi

if [ -n "$PROJECT" ]; then

build_project

fi

if [ -n "$IMAGE" ]; then

build_$IMAGE "$CMD"

fi

build_android "$CMD"

脚本说明:

1,比如产品名称为mifi,则最简单的编译命令即为:./compile.sh s2,则此时会根据脚本默认的配置去编译,开启8个jobs起build,默认为userdebug版本。

2,版本类型控制,可通过-v选项控制,后跟user,userdebug,eng。

3,此脚本默认配置使用ccache,何谓ccache,compile cache简称ccache,顾名思义,编译高速缓存。启动ccache编译工程可以省去编译过程中的重复工作环节,例如,某一.c文件会include很多头文件,而头文件里可能还会include很多头文件,如此编译不同的文件可能这些预编译的头文件可能会被重复load多次,从而耗费大量时间,这时候ccache的作用便发挥出来,编译系统会从ccache的缓存解析数据中获取解析后的头文件数据,直接载入编译。

4,本条作为3基础之上的附加说明,此脚本只是开启了android编译系统的ccache,而kernel部分则需要如下操作方可开启:

kernel/Makefile文件中的

S  = $(CROSS_COMPILE)as

LD  = $(CROSS_COMPILE)ld.bfd

CC  = $(CROSS_COMPILE)gcc

CPP  = $(CC) -E

之后添加:

ifneq ($(USE_CCACHE),)

export CCACHE_COMPILERCHECK := content

export CCACHE_SLOPPINESS := time_macros,include_file_mtime,file_macro

export CCACHE_BASEDIR := /

ccache := $(strip $(wildcard $(PWD)/../prebuilts/misc/linux-x86/ccache/ccache))

ifdef ccache

ifneq ($(ccache),$(firstword $(CC)))

CC := $(ccache) $(CC)

endif

ccache =

endif

endif

如此,kernel部分的编译效率亦大增也。

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-15 03:47:12

Android source目录添加编译工程脚本(含ccache)的相关文章

Android Studio设置自动编译工程

在Eclipse使用习惯了自动编译的兄弟们,刚迁移到Android Studio,肯定也很怀念这功能,自动编译意味着每次运行都能缩短很多时间. Android Studio里面其实也是有自动编译功能的,不过个人觉得还是不如Eclipse好使.具体设置看下图: 把图中的checkbox的勾点上即可. Android Studio设置自动编译工程,布布扣,bubuko.com

source Insight 添加python 工程

1. 下载python的识别文件 Python.CLF 2.设置     原文地址:https://www.cnblogs.com/jlmgary/p/8946667.html

【转】Ubuntu10.04上编译Android源码(Build Android source in Ubuntu10.04 Platform)

原文网址:http://blog.csdn.net/chenyafei617/article/details/6570928 一.Introduction 今天我们就来谈谈如何在Ubuntu平台上面编译android源码,我的是ubuntu10.04版本,在进行编译流程讲解之前我想讲一下 make .make snod .make kernel的作用,m.mm.mmm它们的作用以及区别. - make:                 编译源码,生成相应的系统镜像文件.             

整合Xilinx PetaLinux工程编译和Open Source U- Boot/Linux编译

整合PetaLinux工程编译和Open Source U- Boot/Linux编译 作者: 付汉杰 1. 测试环境 2. PetaLinux介绍 3. PetaLinux的安装 4. 提高PetaLinux/Yocto的编译速度 4.1. 下载SState cache 4.2. 设置SState cache 4.3. 利用离线下载文件 4.4. 重用下载文件 4.5. 离线编译 5. Open Source Linux和UBoot 5.1. 保留Linux和UBoot源代码 5.2. 取得L

Android Studio 在命令行编译工程

在Android  sdk 目录下的samples/android-21/ 文件夹下,任找一个工程,如果在命令行直接编译 可能会报这种错误: gradle buile.gradle FAILURE: Build failed with an exception. * What went wrong: Task 'build.gradle' not found in root project 'BorderlessButtons'. * Try: Run gradle tasks to get a

使用本脚本可以自动批量完成中间节点环境的部署工作,包括:Nginx编译安装、添加程序管理脚本、设置开机启动、反向代理配置、证书分发、添加iptables规则等

使用本脚本可以自动批量完成中间节点环境的部署工作,包括:Nginx编译安装.添加程序管理脚本.设置开机启动.反向代理配置.证书分发.添加iptables规则等.脚本支持自定义nginx安装版本.设置编译模块.配置监听端口等. 1. Nginx Role规则说明 本脚本用于中间节点(Nginx反向代理)环境的自动化配置,主要内容包括: 安装基础依赖环境: 创建nginx启动用户(支持自定义用户): 下载nginx安装文件(可自定义nginx版本): 解压安装文件: 执行编译安装(可自定义编译参数和

Android Studio下添加assets目录

在Android Studio中添加assets目录,目录的位置在 XXX\src\main\assets XXX代表你的项目的路径,assets放在src\main目录下. 这个位置可以通过XXX.iml  XXX代表自己的项目名,其中有设置assets的目录,设置如下 <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />

在Android Studio中添加assets目录

在Android Studio中添加assets目录,目录的位置在 XXX\src\main\assets XXX代表你的项目的路径,assets放在src\main目录下. 这个位置可以通过XXX.iml  XXX代表自己的项目名,其中有设置assets的目录,设置如下 <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" /> 结果如图所示: 参考:http://blo

配置android source 在ubuntu中编译环境

在Ubuntu中可以配置 android source 编译环境,推荐使用最新的64位的Ubuntu  LTS(Long Time Support); 1.安装JDK. AOSP主分支代码需要java7,在Ubuntu上可以使用 OpenJDK. 安装java7的命令: $ sudo apt-get update $ sudo apt-get install openjdk-7-jdk 如果系统中已安装有java环境,可以将其进行更新: $ sudo update-alternatives --