Makefile中自定義函數的調用


自己學習腳印,不喜勿噴,謝謝 ~

Makefile中函數定義:

external/genext2fs/Config.mk

# $(1): src directory
# $(2): output file
# $(3): label (if any)
# $(4): if true, add journal
define build-userimage-ext2-target
@mkdir -p $(dir $(2)) //不顯示命令本身,只顯示執行結果
$(hide) num_blocks=`du -sk $(1) | tail -n1 | awk '{print $$1;}'`;\ // tail -n1 的意思是讀取最后一行的輸出
if [ $$num_blocks -lt 20480 ]; then extra_blocks=3072; \
else extra_blocks=20480; fi ; \
num_blocks=`expr $$num_blocks + $$extra_blocks` ; \ // expr 是四則運算的命令
num_inodes=`find $(1) | wc -l` ; num_inodes=`expr $$num_inodes + 500`; \
if [ -n "$(filter system.img userdata.img,$(notdir $(2)))" ]; then android_image="-a"; else android_image="-U"; fi; \
$(MKEXT2IMG) $$android_image -d $(1) -b $$num_blocks -N $$num_inodes -m 0 $(2)
$(if $(strip $(3)),\
$(hide) $(TUNE2FS) -L $(strip $(3)) $(2))
$(if $(strip $(4)),\
$(hide) $(TUNE2FS) -j $(2))
$(TUNE2FS) -C 1 $(2)
$(E2FSCK) -fy $(2) ; [ $$? -lt 4 ]
endef

函數調用:

include external/genext2fs/Config.mk

ifeq ($(TARGET_SYSTEMIMAGES_USE_EXT3),true)
## generate an ext3 image
# $(1): output file
define build-radioimage-target
@echo "Target radio fs image: $(1)"
$(call build-userimage-ext2-target,$(1),$(2),radio,journal)
endef

else # TARGET_SYSTEMIMAGES_USE_EXT3 != true
$(error Radio does not support yaffs!)

endif

第一行需要將函數定義的makefile include進來,讓其可以調用到其中的方法。

在具體調用的方法使用call,函數后面可以跟參數,該參數對應函數原型中的$(1),$(2)等等




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM