日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android config.mk,android编译分析之10—config.mk

發(fā)布時間:2023/12/2 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android config.mk,android编译分析之10—config.mk 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

config.mk可以說是android編譯系統(tǒng)中關于配置環(huán)境的一個總的makefile,定義了編譯環(huán)境的方方面面。執(zhí)行完config.mk就完成了android編譯系統(tǒng)的所有準備工作,即準備好了所有的編譯需要的全局變量,下一步直接執(zhí)行make,即可產生鏡像文件。

首先,定義了一些變量和目錄,

# Only use ANDROID_BUILD_SHELL to wrap around bash.

# DO NOT use other shells such as zsh.

ifdef ANDROID_BUILD_SHELL

SHELL := $(ANDROID_BUILD_SHELL)

else

# Use bash, not whatever shell somebody has installed as /bin/sh

# This is repeated from main.mk, since envsetup.sh runs this file

# directly.

SHELL := /bin/bash

endif

# Utility variables.

empty :=

space := $(empty) $(empty)

comma := ,

# Note that make will eat the newline just before endef.

define newline

endef

# Unfortunately you can't simply define backslash as \ or \\.

backslash := \a

backslash := $(patsubst %a,%,$(backslash))

# Tell python not to spam the source tree with .pyc files. This

# only has an effect on python 2.6 and above.

export PYTHONDONTWRITEBYTECODE := 1

# Standard source directories.

SRC_DOCS:= $(TOPDIR)docs

# TODO: Enforce some kind of layering; only add include paths

# when a module links against a particular library.

# TODO: See if we can remove most of these from the global list.

SRC_HEADERS := \

$(TOPDIR)system/core/include \

$(TOPDIR)system/media/audio/include \

$(TOPDIR)hardware/libhardware/include \

$(TOPDIR)hardware/libhardware_legacy/include \

$(TOPDIR)hardware/ril/include \

$(TOPDIR)libnativehelper/include \

$(TOPDIR)frameworks/native/include \

$(TOPDIR)frameworks/native/opengl/include \

$(TOPDIR)frameworks/av/include \

$(TOPDIR)frameworks/base/include

SRC_HOST_HEADERS:=$(TOPDIR)tools/include

SRC_LIBRARIES:= $(TOPDIR)libs

SRC_SERVERS:= $(TOPDIR)servers

SRC_TARGET_DIR := $(TOPDIR)build/target

SRC_API_DIR := $(TOPDIR)prebuilts/sdk/api

SRC_SYSTEM_API_DIR := $(TOPDIR)prebuilts/sdk/system-api

# Some specific paths to tools

SRC_DROIDDOC_DIR := $(TOPDIR)build/tools/droiddoc

然后調用pathmap.mk,包含一些hard code的路徑,

# Various mappings to avoid hard-coding paths all over the place

include $(BUILD_SYSTEM)/pathmap.mk

下面的這些變量在我們寫Android.mk時經常會用到,一般都是通過include調用,其實都是一些makefile文件,

# ###############################################################

# Build system internal files

# ###############################################################

BUILD_COMBOS:= $(BUILD_SYSTEM)/combo

CLEAR_VARS:= $(BUILD_SYSTEM)/clear_vars.mk

BUILD_HOST_STATIC_LIBRARY:= $(BUILD_SYSTEM)/host_static_library.mk

BUILD_HOST_SHARED_LIBRARY:= $(BUILD_SYSTEM)/host_shared_library.mk

BUILD_STATIC_LIBRARY:= $(BUILD_SYSTEM)/static_library.mk

BUILD_SHARED_LIBRARY:= $(BUILD_SYSTEM)/shared_library.mk

BUILD_EXECUTABLE:= $(BUILD_SYSTEM)/executable.mk

BUILD_HOST_EXECUTABLE:= $(BUILD_SYSTEM)/host_executable.mk

BUILD_PACKAGE:= $(BUILD_SYSTEM)/package.mk

BUILD_PHONY_PACKAGE:= $(BUILD_SYSTEM)/phony_package.mk

BUILD_HOST_PREBUILT:= $(BUILD_SYSTEM)/host_prebuilt.mk

BUILD_PREBUILT:= $(BUILD_SYSTEM)/prebuilt.mk

BUILD_MULTI_PREBUILT:= $(BUILD_SYSTEM)/multi_prebuilt.mk

BUILD_JAVA_LIBRARY:= $(BUILD_SYSTEM)/java_library.mk

BUILD_STATIC_JAVA_LIBRARY:= $(BUILD_SYSTEM)/static_java_library.mk

BUILD_HOST_JAVA_LIBRARY:= $(BUILD_SYSTEM)/host_java_library.mk

BUILD_DROIDDOC:= $(BUILD_SYSTEM)/droiddoc.mk

BUILD_COPY_HEADERS := $(BUILD_SYSTEM)/copy_headers.mk

BUILD_NATIVE_TEST := $(BUILD_SYSTEM)/native_test.mk

BUILD_NATIVE_BENCHMARK := $(BUILD_SYSTEM)/native_benchmark.mk

BUILD_HOST_NATIVE_TEST := $(BUILD_SYSTEM)/host_native_test.mk

BUILD_SHARED_TEST_LIBRARY := $(BUILD_SYSTEM)/shared_test_lib.mk

BUILD_HOST_SHARED_TEST_LIBRARY := $(BUILD_SYSTEM)/host_shared_test_lib.mk

BUILD_STATIC_TEST_LIBRARY := $(BUILD_SYSTEM)/static_test_lib.mk

BUILD_HOST_STATIC_TEST_LIBRARY := $(BUILD_SYSTEM)/host_static_test_lib.mk

BUILD_NOTICE_FILE := $(BUILD_SYSTEM)/notice_files.mk

BUILD_HOST_DALVIK_JAVA_LIBRARY := $(BUILD_SYSTEM)/host_dalvik_java_library.mk

BUILD_HOST_DALVIK_STATIC_JAVA_LIBRARY := $(BUILD_SYSTEM)/host_dalvik_static_java_library.mk

如果make的目標中包含showcommands,則會打印完整的命令。

# The 'showcommands' goal says to show the full command

# lines being executed, instead of a short message about

# the kind of operation being done.

SHOW_COMMANDS:= $(filter showcommands,$(MAKECMDGOALS))

定義了一些全局變量,cflags,常用文件后綴等,

# ###############################################################

# Set common values

# ###############################################################

# These can be changed to modify both host and device modules.

COMMON_GLOBAL_CFLAGS:= -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith

COMMON_RELEASE_CFLAGS:= -DNDEBUG -UDEBUG

COMMON_GLOBAL_CPPFLAGS:= $(COMMON_GLOBAL_CFLAGS) -Wsign-promo -std=gnu++11

COMMON_RELEASE_CPPFLAGS:= $(COMMON_RELEASE_CFLAGS)

GLOBAL_CFLAGS_NO_OVERRIDE := \

-Werror=int-to-pointer-cast \

-Werror=pointer-to-int-cast \

GLOBAL_CPPFLAGS_NO_OVERRIDE :=

# Set the extensions used for various packages

COMMON_PACKAGE_SUFFIX := .zip

COMMON_JAVA_PACKAGE_SUFFIX := .jar

COMMON_ANDROID_PACKAGE_SUFFIX := .apk

# list of flags to turn specific warnings in to errors

TARGET_ERROR_FLAGS := -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point

ifdef TMPDIR

JAVA_TMPDIR_ARG := -Djava.io.tmpdir=$(TMPDIR)

else

JAVA_TMPDIR_ARG :=

endif

buildspec.mk還沒研究咋用,-include可以看出不是強制必須存在的,

# ---------------------------------------------------------------

# Try to include buildspec.mk, which will try to set stuff up.

# If this file doesn't exist, the environment variables will

# be used, and if that doesn't work, then the default is an

# arm build

ifndef ANDROID_BUILDSPEC

ANDROID_BUILDSPEC := $(TOPDIR)buildspec.mk

endif

-include $(ANDROID_BUILDSPEC)

include了envsetup.mk,前面已經介紹,設置了很多編譯相關的變量。

# ---------------------------------------------------------------

# Define most of the global variables. These are the ones that

# are specific to the user's build configuration.

include $(BUILD_SYSTEM)/envsetup.mk

在調用findleaves.py時設置的選項,

# Pruned directory options used when using findleaves.py

# See envsetup.mk for a description of SCAN_EXCLUDE_DIRS

FIND_LEAVES_EXCLUDES := $(addprefix --prune=, $(OUT_DIR) $(SCAN_EXCLUDE_DIRS) .repo .git)

由于config.mk太長,后面不一一列出來了,找重點的分析,中間主要都是些host和target 編譯鏈相關的變量,還有一些編譯需要用的應用程序,例如aapt,aidl等等。

其中調用select.mk主要是為了設置host和target編譯鏈相關的變量。

#下面調用select.mk設置host端,即編譯機的編譯鏈,gcc ar等

combo_target := HOST_

combo_2nd_arch_prefix :=

include $(BUILD_SYSTEM)/combo/select.mk

# Load the 2nd host arch if it's needed.

ifdef HOST_2ND_ARCH

combo_target := HOST_

# 2ND_

combo_2nd_arch_prefix := $(HOST_2ND_ARCH_VAR_PREFIX)

include $(BUILD_SYSTEM)/combo/select.mk

endif

# on windows, the tools have .exe at the end, and we depend on the

# host config stuff being done first

# 下面調用select.mk設置target端,即目標機的編譯鏈,gcc ar等

combo_target := TARGET_

combo_2nd_arch_prefix :=

include $(BUILD_SYSTEM)/combo/select.mk

# Load the 2nd target arch if it's needed.

ifdef TARGET_2ND_ARCH

combo_target := TARGET_

combo_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)

include $(BUILD_SYSTEM)/combo/select.mk

endif

然后include了ccache,為了加快再次編譯速度,關于ccache后續(xù)再研究。

include $(BUILD_SYSTEM)/ccache.mk

接著include了javac.mk,用來設置java編譯器,

include $(BUILD_SYSTEM)/combo/javac.mk

同時在android6.0以上默認使用jack進行編譯,在javac.mk中,如果ANDROID_COMPILE_WITH_JACK默認沒設置,就設置為true。

ifndef ANDROID_COMPILE_WITH_JACK

# Defines if compilation with jack is enabled by default.

ANDROID_COMPILE_WITH_JACK := true

endif

接著包含了clang相關的makefile,關于clang后續(xù)再研究。

include $(BUILD_SYSTEM)/clang/config.mk

注:Clang是LLVM的前端,可以用來編譯C,C++,ObjectiveC等語言。傳統(tǒng)的編譯器通常分為三個部分,前端(frontEnd),優(yōu)化器(Optimizer)和后端(backEnd)。在編譯過程中,前端主要負責詞法和語法分析,將源代碼轉化為抽象語法樹;優(yōu)化器則是在前端的基礎上,對得到的中間代碼進行優(yōu)化,使代碼更加高效;后端則是將已經優(yōu)化的中間代碼轉化為針對各自平臺的機器代碼。Clang則是以LLVM為后端的一款高效易用,并且與IDE結合很好的編譯前端。

最后include了dumpvar.mk,就是專為打印變量值的makefile,前面已經分析過。

include $(BUILD_SYSTEM)/dumpvar.mk

envsetup.sh中的一些函數,例如check_product,最終就是make config.mk,而make的目標為dumpvar-*。

總結

以上是生活随笔為你收集整理的android config.mk,android编译分析之10—config.mk的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。