当前位置:网站首页>Top level makefile analysis of u-boot (1)
Top level makefile analysis of u-boot (1)
2022-07-18 04:39:00 【Cheap sword】
top floor Makefile almost 3200, Next, analyze this file in detail .
u-boot Version and environment variables
VERSION = 1
PATCHLEVEL = 3
SUBLEVEL = 4
EXTRAVERSION =
U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
VERSION_FILE = $(obj)include/version_autogenerated.h
HOSTARCH := $(shell uname -m | \ sed -e s/i.86/i386/ \ -e s/sun4u/sparc64/ \ -e s/arm.*/arm/ \ -e s/sa110/arm/ \ -e s/powerpc/ppc/ \ -e s/ppc64/ppc/ \ -e s/macppc/ppc/)
HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \ sed -e 's/\(cygwin\).*/cygwin/')
#$(error HOSTARCH = $(HOSTARCH) HOSTOS = $(HOSTOS) "WAITING for value!")
export HOSTARCH HOSTOS
# Deal with colliding definitions from tcsh etc.
VENDOR=
- The first three variables are combined into one
U_BOOT_VERSIONVariable , To form the u-boot Version number of , This version number is finally stored ininclude/version_autogenerated.hIn file . After opening, the content is#define U_BOOT_VERSION "U-Boot 1.3.4" - sed Of
sed s/i.86/i386/Is a kind of substitution grammar , It means thati.86Replace withi386, for exampleecho "33i.86" | sed s/i.86/i386/The output of is33i386,sed in -e It means that multiple substitutions can be carried out at the same time . uname -mIs to show Linux The architecture of , For example, the command result of the current virtual machine isx86_64, It can be seen from the value that there is noi.86,sun4u,…,macppc, thereforeHOSTARCHThe value of is equal touname -mOutput result of .uname -sIs to display the kernel name , So here it shows "Linux",tr '[:upper:]' '[:lower:]'The result of the command is to set all letters to lowercase . At lastHOSTOSThe value of islinux.- To verify whether the judgment is correct , Can open
exportComments on the previous line . intend Makefile Stop after this sentence ( take error Switch to info After that, it will not stop ), And output the values of these two variables . - Cancel the above comments and run
make, The result isMakefile:43: *** HOSTARCH = x86_64 HOSTOS = linux "WAITING for value!". stop it ., Therefore, our analysis is correct . - And then
HOSTARCHandHOSTOSexport (export) For environment variables , In order to make the son shell Use . - Definition
VENDORThe variable is empty
Silent compilation
# Allow for silent builds
ifeq (,$(findstring s,$(MAKEFLAGS)))
XECHO = echo
else
XECHO = :
endif
When we use make -s Command compilation u-boot No information will be output , As Silent compilation .
Set a separate compile output folder
#########################################################################
#
# U-boot build supports producing a object files to the separate external
# directory. Two use cases are supported:
#
# 1) Add O= to the make command line
# 'make O=/tmp/build all'
#
# 2) Set environement variable BUILD_DIR to point to the desired location
# 'export BUILD_DIR=/tmp/build'
# 'make'
#
# The second approach can also be used with a MAKEALL script
# 'export BUILD_DIR=/tmp/build'
# './MAKEALL'
#
# Command line 'O=' setting overrides BUILD_DIR environent variable.
#
# When none of the above methods is used the local build is performed and
# the object files are placed in the source directory.
#
ifdef O
ifeq ("$(origin O)", "command line")
BUILD_DIR := $(O)
endif
endif
ifneq ($(BUILD_DIR),)
saved-output := $(BUILD_DIR)
# Attempt to create a output directory.
$(shell [ -d ${
BUILD_DIR} ] || mkdir -p ${
BUILD_DIR})
# Verify if it was successful.
BUILD_DIR := $(shell cd $(BUILD_DIR) && /bin/pwd)
$(if $(BUILD_DIR),,$(error output directory "$(saved-output)" does not exist))
endif # ifneq ($(BUILD_DIR),)
It can be seen from the initial comments ,u-boot It supports the storage of source code directories and compiled directories separately , But the manufacturer seems to give up this function when porting , No matter how I tried, I failed , So I won't talk about it here , Just for completeness .
Several important variables
OBJTREE := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))
SRCTREE := $(CURDIR)
TOPDIR := $(SRCTREE)
LNDIR := $(OBJTREE)
export TOPDIR SRCTREE OBJTREE
MKCONFIG := $(SRCTREE)/mkconfig
export MKCONFIG
#$(info OBJTREE = $(OBJTREE))
#$(info SRCTREE = $(SRCTREE))
#$(error )
ifneq ($(OBJTREE),$(SRCTREE))
REMOTE_BUILD := 1
export REMOTE_BUILD
endif
# $(obj) and (src) are defined in config.mk but here in main Makefile
# we also need them before config.mk is included which is the case for
# some targets like unconfig, clean, clobber, distclean, etc.
ifneq ($(OBJTREE),$(SRCTREE))
obj := $(OBJTREE)/
src := $(SRCTREE)/
else
obj :=
src :=
endif
export obj src
- The above code will generate the compiled file storage root directory (
OBJTREE) Source code root directory in the future (SRCTREE). Because we didn't set up different directories , So the values of both are the same , After uncommenting, you will see the running result . - Set up
MKCONFIGVariable , Define mkconfig file - because
OBJTREEValue andSRCTREESame value , beobj,srcAndREMOTE_BUILDAll three variables are empty .
Makefile The analysis is stuck
ifeq ($(obj)include/config.mk,$(wildcard $(obj)include/config.mk))
- stay u-boot The top-level directory uses the command
make distcleanDelete all generated files . - And then use make Will find the newspaper
System not configured - see READMEerror . This is because there is no such config.mk The document created . - In our uboot Environment construction and compilation In the article ,make Only before
make x210_sd_configcommand , therefore config.mk The file is generated after this command . - Next, we analyze the generation process of the file .
边栏推荐
猜你喜欢
随机推荐
如何通过特殊数据类型索引实现内存数据库加速
[SQL injection] Stack Injection
Browser compatibility testing system, method and process
云计算SLA思考
VirtualBox:设置共享文件夹
Pythia:Facebook最新开源的视觉、语言多任务学习框架
718. 最长重复子数组
PAT 甲级 A1004 Counting Leaves
Send your code into space and develop "the greatest work" with Huawei cloud
Pat class a a1053 path of equal weight (tree traversal)
为什么阿里巴巴规定禁止超过三张表 join?
洛谷P4113 [HEOI2012]采花 题解
动圈式扬声器过载过程
常见保持请求幂等的方式
笔记本电脑能连接WiFi但浏览器无法打开网页的解决办法
Audio and video SDP add bit rate
一次莫名其妙的故障……
Write it down once Net analysis of memory leakage in web system of a power plant
面试官:抽象工厂模式是什么?
一种嵌入式中应用层与硬件层分层管理方法









