all-makefiles-under vs all-subdir-makefiles vs first-makefiles-under

参考:all-makefiles-under v.s. first-makefiles-under

definitions.mk - OpenGrok cross reference for /build/make/core/definitions.mk (aospxref.com)

先来看一下这三者的定义:

###########################################################
## Retrieve a list of all makefiles immediately below some directory
###########################################################

#找出指定目录的二级目录的所有Android.mk
define all-makefiles-under
$(wildcard $(1)/*/Android.mk)
endef

###########################################################
## Look under a directory for makefiles that don't have parent
## makefiles.
###########################################################
# $(1): directory to search under
# Ignores $(1)/Android.mk
define first-makefiles-under
$(shell build/make/tools/findleaves.py $(FIND_LEAVES_EXCLUDES) \
        --mindepth=2 $(addprefix --dir=,$(1)) Android.mk)
endef

###########################################################
## Retrieve a list of all makefiles immediately below your directory
## Must be called before including any other makefile!!
###########################################################
#找出当前目录的二级目录的所有Android.mk
define all-subdir-makefiles
$(call all-makefiles-under,$(call my-dir))
endef

The builtin wildcard is quite efficient. So we should use $(call all-makefiles-under, $(LOCAL_PATH)) as you can.

first-makefiles-under calls the script build/tools/findleaves.py to find Android.mks in the given directory.

If it finds an Android.mk in a directory, it just stops searching the subdirs.

It’s not efficient, especially in case you have deep complex directory structure that does not have Android.mk in the top dirs.

We should use it as little as possible.

If your Android.mk’s only purpose is to include all first-level sub-directory Android.mks, use:

include $(call all-subdir-makefiles)

If you want to include Android.mks in a specific set of first-level sub-directories:

include $(call all-named-subdir-makefiles, )

注意:

1、上面的函数都不包括指定目录的Android.mk。

2、Both all-subdir-makefiles and all-named-subdir-makefiles use $(my-dir), which uses makefile’s builtin MAKEFILE_LIST to get the current include chain of makefiles.

So they must be the called before any “include” statement in your makefile.

位置错误会报错:error: my-dir must be called before including any other makefile…

原因分析:

Android AOSP Android.mk - $(call all-subdir-makefiles) Path problems | Sebastian Weisgerber

Problems using NDK build system and subdirectories

即:

This is due to a limitation of the GNU Make command language: All variables are global**, and the implementation of $(call my-dir)** can only give you the name of the last included Makefile (even if you already exited the Makefile). There is no way to implement something that works properly with GNU Make.

测试结果:

假设app目录结构如下

app->app1->Android.mk
   ->app2->Android.mk
   ->app3->app4->Android.mk
         ->app5->Android.mk
   ->app6->Android.mk
   		->app7->Android.mk
         ->app8->Android.mk
   ->Android.mk

在app目录分别调用以上函数,结果如下:

#all-makefiles-under
app->app1->Android.mk
   ->app2->Android.mk
   ->app6->Android.mk
#all-subdir-makefiles
app->app1->Android.mk
   ->app2->Android.mk
   ->app6->Android.mk
#first-makefiles-under
app->app1->Android.mk
   ->app2->Android.mk
   ->app3->app4->Android.mk
         ->app5->Android.mk
   ->app6->Android.mk

Android.mk中call all-subdir-makefiles和call all-makefiles-under,$(LOCAL_PATH)的区别_jackyu613的专栏 Embedded Linux Android-CSDN博客

call all-subdir-makefiles和call all-makefiles-under - 简书

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值