之后在当前目录下执行help 可以发现它给出的信息和此前见过linux 下面help 的信息不一样了:
lai@lai-ThinkPad-X61:~/af-t34$ helpInvoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory.
- mmm: Builds all of the modules in the supplied directories.
- cgrep: Greps on all local C/C++ files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file.
Look at the source to view more functions. The complete list is:
add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant cproj croot findmakefile gdbclient get_abs_build_var getbugreports get_build_var getprebuilt gettop godir help isviewserverstarted jgrep lunch m mm mmm pid printconfig print_lunch_menu resgrep runhat runtest setpaths set_sequence_number set_stuff_for_environment settitle smoketest startviewserver stopviewserver systemstack tapas tracedmdump
关于source
source 命令会把对应脚本中的内容读取到当前的bash 解释器中,在当前的执行环境中执行;其中定义的 function 以及通过 export 声明的变量等在 source 执行结束之后依然存在于当前的bash 环境中。比如我们常用的 source .bashrc 或者 source .profile 等目的是为了引用刚刚改动过的环境变量。
m 的解释
function m()
{
T=$(gettop)
if [ "$T" ]; then
make -C $T $@
else
echo "Couldn't locate the top of the tree. Try setting TOP."
fi
}
~/Android/an403/external/webkit/Source/WebKit/android/jni/test$ gettop
/home/mypc/Android/an403
$@ 返回调用这个脚本时传入的参数
比如我们执行 m showcommands -d经过 function m 的翻译后就执行
make -C /home/yajun/Android/an403 showcommands -d
当然如果 当前的目录不在源码树里面,gettop 就返回空,这样 m 的结果就时
- ~$ m
- Couldn't locate the top of the tree. Try setting TOP.
下面主要讲解mm
{
# If we're sitting in the root of the build tree, just do a
# normal make.
if [ -f build/core/envsetup.mk -a -f Makefile ]; then
make $@
else
# Find the closest Android.mk file.
T=$(gettop)
local M=$(findmakefile)
# Remove the path to top as the makefilepath needs to be relative
local M=`echo $M|sed 's:'$T'/::'`
if [ ! "$T" ]; then
echo "Couldn't locate the top of the tree. Try setting TOP."
elif [ ! "$M" ]; then
echo "Couldn't locate a makefile from the current directory."
else
ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
fi
fi
}
从它的注释可以看出,当你在某个目录下执行 mm 的时候,
function findmakefile()
{
TOPFILE=build/core/envsetup.mk
# We redirect cd to /dev/null in case it's aliased to
# a command that prints something as a side-effect
# (like pushd)
local HERE=$PWD
T=
while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
T=$PWD
if [ -f "$T/Android.mk" ]; then
echo $T/Android.mk
cd $HERE > /dev/null
return
fi
cd .. > /dev/null
done
cd $HERE > /dev/null
}
以我在 /home/yajun/Android/an403/external/webkit/Source/WebKit/android/benchmark/ 下执行 mm 为例
ONE_SHOT_MAKEFILE=external/webkit/Source/WebKit/android/benchmark/Android.mk make -C /home/yajun/Android/an403 all_modules
# We've probably been invoked by the "mm" shell function
# with a subdirectory's makefile.
include $(ONE_SHOT_MAKEFILE)
# Change CUSTOM_MODULES to include only modules that were
# defined by this makefile; this will install all of those
# modules as a side-effect. Do this after including ONE_SHOT_MAKEFILE
# so that the modules will be installed in the same place they
# would have been with a normal make.
CUSTOM_MODULES := $(sort $(call get-tagged-modules,$(ALL_MODULE_TAGS)))
FULL_BUILD :=
# Stub out the notice targets, which probably aren't defined
# when using ONE_SHOT_MAKEFILE.
NOTICE-HOST-%: ;
NOTICE-TARGET-%: ;
else # ONE_SHOT_MAKEFILE
把其中的变量读取进来:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
main.cpp
# Pull the webkit definitions from the base webkit makefile.
LOCAL_SHARED_LIBRARIES := libwebcore $(WEBKIT_SHARED_LIBRARIES)
LOCAL_LDLIBS := $(WEBKIT_LDLIBS)
LOCAL_MODULE := webcore_test
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
LOCAL_MODULE:=
LOCAL_MODULE_PATH:=
LOCAL_MODULE_STEM:=
LOCAL_DONT_CHECK_MODULE:=
LOCAL_CHECKED_MODULE:=
LOCAL_BUILT_MODULE:=
在最后一句会 include $(BUILD_EXECUTABLE) 它的定义在:build/core/config.mk:60:BUILD_EXECUTABLE:= $(BUILD_SYSTEM)/executable.mk
ifeq ($(strip $(LOCAL_MODULE_CLASS)),)
LOCAL_MODULE_CLASS := EXECUTABLES
endif
ifeq ($(strip $(LOCAL_MODULE_SUFFIX)),)
LOCAL_MODULE_SUFFIX := $(TARGET_EXECUTABLE_SUFFIX)
endif
include $(BUILD_SYSTEM)/dynamic_binary.mk
ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
$(linked_module): $(TARGET_CRTBEGIN_STATIC_O) $(all_objects) $(all_libraries) $(TARGET_CRTEND_O)
$(transform-o-to-static-executable)
else
$(linked_module): $(TARGET_CRTBEGIN_DYNAMIC_O) $(all_objects) $(all_libraries) $(TARGET_CRTEND_O)
$(transform-o-to-executable)
endif
到这里相信写过 Makefile 的朋友顿时觉得熟悉了吧,只是这里的 target, dependencies, executable commands 都被变量代替了:
$(linked_module): $(TARGET_CRTBEGIN_DYNAMIC_O) $(all_objects) $(all_libraries) $(TARGET_CRTEND_O)
$(transform-o-to-executable)
如果想进一步了解这里做了什么事情,我们需要知道上面的变量都是什么值,最方便的做法是把他们打印出来。
include $(BUILD_SYSTEM)/dynamic_binary.mk
$(warning "-------------------------------------------")
$(warning "linked_modle=$(linked_module)")
$(warning "TARGET_CRTBEGIN_DYNAMIC_O=$(TARGET_CRTBEGIN_DYNAMIC_O)")
$(warning "all_objects=$(all_objects)")
$(warning "all_libraries=$(all_libraries)")
$(warning "TARGET_CRTEND_O=$(TARGET_CRTEND_O)")
$(warning "transform-o-to-executable=$(transform-o-to-executable)")
$(warning "--------------------------------------------")
ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
可以然后就可以看出来这里做要 build 出来的是什么东西啦:
build/core/executable.mk:16: "-------------------------------------------"
build/core/executable.mk:17: "linked_modle=out/target/product/generic/obj/EXECUTABLES/webcore_test_intermediates/LINKED/webcore_test"
build/core/executable.mk:18: "TARGET_CRTBEGIN_DYNAMIC_O=out/target/product/generic/obj/lib/crtbegin_dynamic.o"
build/core/executable.mk:19: "all_objects= out/target/product/generic/obj/EXECUTABLES/webcore_test_intermediates/main.o "
build/core/executable.mk:20: "all_libraries=out/target/product/generic/obj/lib/libwebcore.so out/target/product/generic/obj/lib/libc.so out/target/product/generic/obj/lib/libstdc++.so out/target/product/generic/obj/lib/libm.so "
build/core/executable.mk:21: "TARGET_CRTEND_O=out/target/product/generic/obj/lib/crtend_android.o"
build/core/executable.mk:22: "transform-o-to-executable=@mkdir -p
@echo "target Executable: ()"
-nostdlib -Bdynamic -Wl,-T,build/core/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc -o -Lout/target/product/generic/obj/lib -Wl,-rpath-link=out/target/product/generic/obj/lib out/target/product/generic/obj/lib/crtbegin_dynamic.o -Wl,-z,noexecstack -Wl,--icf=safe -Wl,--fix-cortex-a8 prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/bin/../lib/gcc/arm-linux-androideabi/4.4.3/armv7-a/libgcc.a out/target/product/generic/obj/lib/crtend_android.o"
build/core/executable.mk:23: "--------------------------------------------"