理解 Android 的 ONE_SHOT_MAKEFILE

http://blog.csdn.net/span76/article/details/21104175

使用 mmm 编译的时候 Android 执行的 ONE_SHOT make, 其如何实现?

mmm 的源代码在 build/envsetup.sh 中

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. function mmm()  
  2.     641 {  
  3.     642     T=$(gettop)  
  4.     643     if [ "$T" ]; then  
  5.     644         local MAKEFILE=  
  6.     645         local MODULES=  
  7.     646         local ARGS=  
  8.     647         local DIR TO_CHOP  
  9.     648         local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')  
  10.     649         local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')  
  11.     650         for DIR in $DIRS ; do  
  12.     651             MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`  
  13.     652             if [ "$MODULES" = "" ]; then  
  14.     653                 MODULES=all_modules  
  15.     654             fi  
  16.     655             DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`  
  17.     656             if [ -f $DIR/Android.mk ]; then  
  18.     657                 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`  
  19.     658                 TO_CHOP=`expr $TO_CHOP + 1`  
  20.     659                 START=`PWD= /bin/pwd`  
  21.     660                 MFILE=`echo $START | cut -c${TO_CHOP}-`  
  22.     661                 if [ "$MFILE" = "" ] ; then  
  23.     662                     MFILE=$DIR/Android.mk  
  24.     663                 else  
  25.     664                     MFILE=$MFILE/$DIR/Android.mk  
  26.     665                 fi  
  27.     666                 MAKEFILE="$MAKEFILE $MFILE"  
  28.     667             else  
  29.     668                 if [ "$DIR" = snod ]; then  
  30.     669                     ARGS="$ARGS snod"  
  31.     670                 elif [ "$DIR" = showcommands ]; then  
  32.     671                     ARGS="$ARGS showcommands"  
  33.     672                 elif [ "$DIR" = dist ]; then  
  34.     673                     ARGS="$ARGS dist"  
  35.     674                 elif [ "$DIR" = incrementaljavac ]; then  
  36.     675                     ARGS="$ARGS incrementaljavac"  
  37.     676                 else  
  38.     677                     echo "No Android.mk in $DIR."  
  39.     678                     return 1  
  40.     679                 fi  
  41.     680             fi  
  42.     681         done  
  43.     682         ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS $MODULES $ARGS  
  44.     683     else  
  45.     684         echo "Couldn't locate the top of the tree.  Try setting TOP."  
  46.     685     fi  
  47.     686 }  
但运行下面的命令

mmm sdk/emulator/opengl/tests/translator_tests/GLES_V2

最终生成命令行

ONE_SHOT_MAKEFILE= sdk/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk make -C /home/payne/njb all_modules

注意

ONE_SHOT_MAKEFILE=sdk/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk   是参数

make -C /home/payne/njb all_modules 才是命令

就是说带着 ONE_SHOT_MAKEFILE 的参数去执行 make 命令, 而make的target 是 all_modules

在 build/core/main.mk#467

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. ifneq ($(ONE_SHOT_MAKEFILE),)  
  2. # We've probably been invoked by the "mm" shell function  
  3. # with a subdirectory's makefile.  
  4. include $(ONE_SHOT_MAKEFILE)  
  5. # Change CUSTOM_MODULES to include only modules that were  
  6. # defined by this makefile; this will install all of those  
  7. # modules as a side-effect.  Do this after including ONE_SHOT_MAKEFILE  
  8. # so that the modules will be installed in the same place they  
  9. # would have been with a normal make.  
  10. CUSTOM_MODULES := $(sort $(call get-tagged-modules,$(ALL_MODULE_TAGS)))  
  11. FULL_BUILD :=  
  12. # Stub out the notice targets, which probably aren't defined  
  13. # when using ONE_SHOT_MAKEFILE.  
  14. NOTICE-HOST-%: ;  
  15. NOTICE-TARGET-%: ;  

当环境变量 ONE_SHOT_MAKEFILE不是空的时候, 就被 include 进来了,此 mk 的 LOCAL_MODULE 也将会让  all_modules 去依赖(加入到变量ALL_MODULES中),这样 make all_modules 的时候,就会先编译依赖的 LOCAL_MODULE了; 当然不相关的 module不会加入到 ALL_MODULES

build/core/main.mk#813

    813 .PHONY: all_modules
    814 all_modules: $(ALL_MODULES)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值