您现在的位置是:首页 >技术教程 >OpenWrt 编译分析(22.03)网站首页技术教程
OpenWrt 编译分析(22.03)
1. 单独编译内核模块
make target/linux/compile
make package/kernel/linux/compile
make package/install
make target/install
2. package相关
2.1. package编译路径
includepackage.mk
PKG_BUILD_DIR ?= ( B U I L D D I R ) / (BUILD_DIR)/ (BUILDDIR)/(if ( B U I L D V A R I A N T ) , (BUILD_VARIANT), (BUILDVARIANT),(PKG_NAME)- ( B U I L D V A R I A N T ) / ) (BUILD_VARIANT)/) (BUILDVARIANT)/)(PKG_NAME)$(if ( P K G V E R S I O N ) , − (PKG_VERSION),- (PKGVERSION),−(PKG_VERSION))
如果定义了PKG_BUILD_DIR,那就用PKG_BUILD_DIR;否则就是
(
B
U
I
L
D
D
I
R
)
/
(BUILD_DIR)/
(BUILDDIR)/(if
(
B
U
I
L
D
V
A
R
I
A
N
T
)
,
(BUILD_VARIANT),
(BUILDVARIANT),(PKG_NAME)-
(
B
U
I
L
D
V
A
R
I
A
N
T
)
/
)
(BUILD_VARIANT)/)
(BUILDVARIANT)/)(PKG_NAME)$(if
(
P
K
G
V
E
R
S
I
O
N
)
,
−
(PKG_VERSION),-
(PKGVERSION),−(PKG_VERSION))
以dnsmasq为例
Makefile中定义了VARIANT:=nodhcpv6
include/package-dumpinfo.mk,将Build-Variant: nodhcpv6写入tmp/.packageinfo
scriptsmetadata.pm,将tmp/.packageinfo中的Build-Variant: nodhcpv6写入KaTeX parse error: Undefined control sequence: package at position 23: …ariant} scripts̲p̲a̲c̲k̲a̲g̲e̲-metadata.pl,将(curdir)/network/services/dnsmasq/variants += $(if KaTeX parse error: Undefined control sequence: subdir at position 62: …gedeps include̲s̲u̲b̲d̲i̲r̲.mk,通过(call log_make,
(
1
)
/
(1)/
(1)/(bd),
(
t
a
r
g
e
t
)
,
,
(target),,
(target),,(filter-out __default,$(variant)))传递到package.mk
2.2 package为什么能看到BOARD变量
因为./rules.mk中有如下定义:
BOARD:=$(call qstrip,$(CONFIG_TARGET_BOARD))
3. includedownload.mk
下载过程的入口为package.mk中的"$(call Download,default)",代码如下,其中default是Download函数的参数。
define Build/DefaultTargets
$(if
(
U
S
E
S
O
U
R
C
E
D
I
R
)
(USE_SOURCE_DIR)
(USESOURCEDIR)(USE_GIT_TREE)
(
U
S
E
G
I
T
S
R
C
C
H
E
C
K
O
U
T
)
,
,
(USE_GIT_SRC_CHECKOUT),,
(USEGITSRCCHECKOUT),,(if $(strip
(
P
K
G
S
O
U
R
C
E
U
R
L
)
)
,
(PKG_SOURCE_URL)),
(PKGSOURCEURL)),(call Download,default)))
$(if
(
D
U
M
P
)
,
,
(DUMP),,
(DUMP),,(Build/CoreTargets))
define Build/DefaultTargets
endef
endef
Download通过"$(eval
(
D
o
w
n
l
o
a
d
/
(Download/
(Download/(1)))“调用Download/default函数,定义下载的URL,文件名等变量。
为了避免dl下的文件重复下载,可以将Download函数做如下修改(增加了ifeq (”$(wildcard
(
D
L
D
I
R
)
/
(DL_DIR)/
(DLDIR)/(FILE))“,”“)):
define Download
$(eval $(Download/Defaults))
$(eval
(
D
o
w
n
l
o
a
d
/
(Download/
(Download/(1)))
ifeq (”$(wildcard
(
D
L
D
I
R
)
/
(DL_DIR)/
(DLDIR)/(FILE))“,”")
$(foreach FIELD,URL FILE
(
V
a
l
i
d
a
t
e
/
(Validate/
(Validate/(call dl_method,
(
U
R
L
)
,
(URL),
(URL),(PROTO))),
ifeq (
(
(
((FIELD)),)
$
(
e
r
r
o
r
D
o
w
n
l
o
a
d
/
(error Download/
(errorDownload/(1) is missing the $(FIELD) field.)
endif
)
$(foreach dep,$(DOWNLOAD_RDEP),
$(dep): $(DL_DIR)/$(FILE)
)
download: $(DL_DIR)/$(FILE)
$(DL_DIR)/$(FILE):
mkdir -p $(DL_DIR)
$(call locked,
$(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),
$(call DownloadMethod/$(call dl_method,$(URL),$(PROTO)),check,$(if $(filter default,$(1)),PKG_,Download/$(1):)),
$(DownloadMethod/unknown)
),
$(FILE))
endif
endef