本文以U-boot的配置过程为背景,本文所介绍的方法不局限于解读U-boot
的Makefile,同样适用于linux
和busybox
等开源软件。
U-boot配置的执行命令是
make -C $BOOTLDR_PATH ARCH=arm CROSS_COMPILE=$CROSS_COMPILER_KERNEL_PREFIX s3c2440_config \
--debug=basic > make_boot_config.log
执行完后make_boot_config.log
的内容是
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-redhat-linux-gnu
正在读入 makefiles...
make[1]: Entering directory `/disk2/boot'
make[1]: Leaving directory `/disk2/boot'
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-redhat-linux-gnu
正在读入 makefiles...
Updating goal targets....
文件“s3c2440_config”不存在。
文件“unconfig”不存在。
必须重新创建目标“unconfig”。
make[1]: Entering directory `/disk2/boot'
重新创建目标文件“unconfig”成功。
必须重新创建目标“s3c2440_config”。
Configuring for s3c2440 board...
重新创建目标文件“s3c2440_config”成功。
make[1]: Leaving directory `/disk2/boot'
可以看到,下面这些内容重复出现,并且也不是我们跟踪Makefile想要了解的信息。
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-redhat-linux-gnu
正在读入 makefiles...
Updating goal targets....
利用sed
来处理一下这个文件,新建文件make_info_del.sed
/GNU Make 3.81/,/PARTICULAR PURPOSE./d
/This program built for x86_64-redhat-linux-gnu/d
/Updating goal targets..../d
/makefiles...$/d
执行命令
cat make_boot_config.log | sed -f make_info_del.sed > make_boot_config.log.1
生成文件的内容是
make[1]: Entering directory `/disk2/boot'
make[1]: Leaving directory `/disk2/boot'
文件“s3c2440_config”不存在。
文件“unconfig”不存在。
必须重新创建目标“unconfig”。
make[1]: Entering directory `/disk2/boot'
重新创建目标文件“unconfig”成功。
必须重新创建目标“s3c2440_config”。
Configuring for s3c2440 board...
重新创建目标文件“s3c2440_config”成功。
make[1]: Leaving directory `/disk2/boot'
这个时候我们就可以很方便的理清u-boot配置时Makefile
中目标的依赖关系,s3c2440_config
依赖unconfig
,上面U-boot配置的依赖关系很简单,不太过瘾,稍后我们来利用这种方法说明一下U-boot编译过程中的依赖关系,传送门uboot 2013.04版编译过程及原理说明。