NuttX_编译系统分析
2016-03-20 00:04
225 查看
Nuttx 内存寻址模式有3种
伪目标有:
context
clean_context
check_context
export
subdir_clean
subdir_distclean
clean
distclean
apps_clean
apps_distclean
引用某大神的一个图:
/article/8682621.html
install 相应的lib 到/lib目录下
Config.mk
discover.py
mkconfig.c, cfgdefine.c, and cfgdefine.h
cmdconfig.c
kconfig2html.c
mkconfigvars.sh
mkexport.sh and Makefile.export
mkfsdata.pl
mkversion.c, cfgdefine.c, and cfgdefine.h
mksyscall.c, cvsparser.c, and cvsparser.h
mksymtab.c, cvsparser.c, and cvsparser.h
mkctags.sh
nxstyle.c
pic32mx
bdf-convert.c
Makefile.host
mkromfsimg.sh
mkdeps.c cnvwindeps.c mkwindeps.sh mknulldeps.sh
define.sh / define.bat
link.sh / link.bat
unlink.sh / unlink.bat
incdir.sh / incdir.bat
copydir.sh / copydir.bat
mkimage.sh
indent.sh
refresh.sh
testbuild.sh
zipme.sh
NO | EN | CN |
---|---|---|
1 | Flat embedded build | 平面内存构建模式 |
2 | Protected build with MPU | 保护内存构建模式 |
3 | Kernel build with MMU | 内核内存构建模式 |
1. 目录结构
| +~~~~~~~~~~~~~+ | | nuttx app $(TOPDIR) = nuttx $(TOPDIR)/ +---.config +---.version +---Makefile +---Makefile.unix +---Makefile.win(略) +---Directories.mk +---LibTargets.mk +---FlatLibs.mk +---KernelLibs.mk (略) +---ProtectedLibs.mk(略) +---/arch/arm/src/armv7-m/Toolchain.defs +---/tools +---configure.sh +---Config.mk +---/tools +---/tools +---/tools +---/tools
2. Makefile 文件包含关系
+--.config | | +-tools/Config.mk | | | | +--.config | | | | +-Make.defs--+--tools/Config.mk | | | | | +--arch/arm/src/armv7-m/Toolchain.defs | | Makefile-+--Makefile.unix--+--Directories.mk | | | | +--FlatLibs.mk (Flat embedded build) | | | | +------------+--ProtectedLibs.mk(Protected build with MPU))(略) | | | | | +--KernelLibs.mk (Kernel build with MMU)(略) | | | +--LibTargets.mk +--Makefile.win-(略)
3. Makefile 目标
默认的目标为:all: $(BIN)伪目标有:
context
clean_context
check_context
export
subdir_clean
subdir_distclean
clean
distclean
apps_clean
apps_distclean
引用某大神的一个图:
/article/8682621.html
` |<--pass1dep-|<----------------------------------------+ |<--pass1deps-| |<--tools/mkdeps$(HOSTEXEEXT) | | | | | | +--+ |<--$(USERLIBS) | | | | | | |<--pass2dep-|<---------------------------------------| |<---pass2deps-| |<--tools/mkdeps$(HOSTEXEEXT) | | | | | | | | | |<--$(NUTTXLIBS) <--+ | | | | | | | | | +-----------------------------------+ | | | | | | | | | |<--lib/libsched$(LIBEXT)<--sched/libsched$(LIBEXT)<--------| | | | |<--lib/libc$(LIBEXT)<--libc/libc$(LIBEXT)<-----------------| | | | |<--lib/libmm$(LIBEXT)<--mm/libmm$(LIBEXT)<-----------------| all<--$(BIN)-| | | |<--lib/libarch$(LIBEXT)<--$(ARCH_SRC)/libarch$(LIBEXT)<----| | | | |<--lib/libcxx$(LIBEXT)<--libxx/libcxx$(LIBEXT)<------------| | | | |<--lib/libapps$(LIBEXT)<--$(APPDIR)/libapps$(LIBEXT)<------| | | | |<--lib/libnet$(LIBEXT)<--net/libnet$(LIBEXT)<--------------| | | | |<--lib/libfs$(LIBEXT)<--fs/libfs$(LIBEXT)<-----------------| | | | |<--lib/libdrivers$(LIBEXT)<--drivers/libdrivers$(LIBEXT)<--| | | | |<--lib/libbinfmt$(LIBEXT)<--binfmt/libbinfmt$(LIBEXT)<-----| | | | | | | +---------+ | | | | | | +--------+ | | | | | | |<--pass1<--+ | | | | | |<--pass2<------+ | | +---------------------------------------------------------------------------+ | | |<--check_context | | | |<--include/nuttx/config.h-|<--$(TOPDIR)/.config | | |<--tools/mkconfig$(HOSTEXEEXT) | | | |<--include/nuttx/version.h-|<--$(TOPDIR)/.version | | |<--tools/mkversion$(HOSTEXEEXT) | | |<--context-|<--include/math.h<--include/nuttx/math.h |<--include/float.h<--include/nuttx/float.h |<--include/stdarg.h<--include/nuttx/stdarg.h | | |<--include/arch<-Make.defs | | | |<--include/arch/board-|<--include/arch<--Make.defs | | |<--Make.defs | | |<--dirlinks-|<--include/arch/chip-|<--include/arch<--Make.defs | |<--Make.defs | |<--$(ARCH_SRC)/board<--Make.defs |<--$(ARCH_SRC)/chip<--Make.defs |<--include/apps<--Make.defs
4. Directories.mk
- NUTTX_ADDONS - USER_ADDONS - NONFSDIRS - FSDIRS - CONTEXTDIRS - USERDIRS - OTHERDIRS - CLEANDIRS - KERNDEPDIRS - USERDEPDIRS
5. FlatLibs.mk ProtectedLibs.mk(略) KernelLibs.mk(略)
导出make3个目标(都依赖context) - NUTTXLIBS - - USERLIBS - - EXPORTLIBS-
- NUTTXLIBS +--/lib/libsched.a ---------> 调度器相关 | +--/lib/libconfigs.a | +--/lib/libc.a | +--/lib/libmm.a | +--/lib/libarch.a | +--/lib/libapps.a | +--/lib/libcxx.a ----------> c++相关(略) | +--/lib/libnet.a ----------> network相关(略) | +--/lib/libcrypto.a -------> 加密相关(略) | +--/lib/libfs.a | +--/lib/libdrivers.a | +--/lib/libbinfmt.a | +--/lib/libgraphics.a ---+ | |-> 图像相关(略) +--/lib/libnx.a ---+ | +--/lib/libaudio.a --------> 音频相关(略) | +--/lib/libstubs.a (CONFIG_LIB_SYSCALL = y) - USERLIBS +--/lib/libproxies.a (CONFIG_LIB_SYSCALL = y) - EXPORTLIBS +-- $(NUTTXLIBS)
6. LibTargets.mk
make -c 到对应目录中编译相应的libinstall 相应的lib 到/lib目录下
ps:在Makefile里会用到install,其他地方会用cp 1) 如果目标文件存在, cp会先清空文件后往里写入新文件, 而install则会先删除掉原先的文件然后写入新文件 2) install命令会恰当地处理文件权限的问题。 比如说,install -c会把目标文件的权限设置为rwxr-xr-x
7. tools目录
configure.sh (configure.c, cfgparser.c, and cfgparser.h)Config.mk
discover.py
mkconfig.c, cfgdefine.c, and cfgdefine.h
cmdconfig.c
kconfig2html.c
mkconfigvars.sh
mkexport.sh and Makefile.export
mkfsdata.pl
mkversion.c, cfgdefine.c, and cfgdefine.h
mksyscall.c, cvsparser.c, and cvsparser.h
mksymtab.c, cvsparser.c, and cvsparser.h
mkctags.sh
nxstyle.c
pic32mx
bdf-convert.c
Makefile.host
mkromfsimg.sh
mkdeps.c cnvwindeps.c mkwindeps.sh mknulldeps.sh
define.sh / define.bat
link.sh / link.bat
unlink.sh / unlink.bat
incdir.sh / incdir.bat
copydir.sh / copydir.bat
mkimage.sh
indent.sh
refresh.sh
testbuild.sh
zipme.sh
7.1 configure.sh
使用方式: cd ${TOPDIR}/tools ./configure.sh <board-name>/<config-dir> 这是一个配置脚本, 做了以下几个事情: - Copy configs/<board-name>/<config-dir>/Make.def to ${TOPDIR}/Make.defs - Copy configs/<board-name>/<config-dir>/setenv.sh to ${TOPDIR}/setenv.sh - Copy configs/<board-name>/<config-dir>/defconfig to ${TOPDIR}/.config
7.2 Config.mk
通用makefile 函数接口定义,需要顶层Make.defs 包含该Confilg.mk和顶层的.config文件-include $(TOPDIR)/.config include $(TOPDIR)/tools/Config.mk
7.2.1. CONFIG_ARCH, CONFIG_ARCH_CHIP, CONFIG_ARCH_BOARD - 宏的重新定义
CONFIG_ARCH := $(patsubst "%",%,$(strip $(CONFIG_ARCH))) CONFIG_ARCH_CHIP := $(patsubst "%",%,$(strip $(CONFIG_ARCH_CHIP))) CONFIG_ARCH_BOARD := $(patsubst "%",%,$(strip $(CONFIG_ARCH_BOARD)))
7.2.2. OBJEXT LIBEXT - obj和lib扩展名的定义
OBJEXT ?= .o LIBEXT ?= .a
7.2.4. DELIM - 分割符
ifeq ($(CONFIG_WINDOWS_NATIVE),y) DELIM = $(strip \) else DELIM = $(strip /) endif
7.2.4. INCDIR
使用方式: - CFFLAGS += ${shell $(INCDIR) [options] "compiler" "dir1" "dir2" "dir2" ...} ifeq ($(CONFIG_WINDOWS_NATIVE),y) INCDIR = "$(TOPDIR)\tools\incdir.bat" else INCDIR = "$(TOPDIR)/tools/incdir.sh" endif
7.2.5. PREPROCESS - 预处理
使用方式: - $(call PREPROCESS, in-file, out-file) #CPP - The command to invoke the C pre-processor #CPPFLAGS - Options to pass to the C pre-processor define PREPROCESS @echo "CPP: $1->$2" $(Q) $(CPP) $(CPPFLAGS) $1 -o $2 endef
7.2.6. COMPILE/COMPILEXX - 编译
使用方式: - $(call COMPILE, in-file, out-file) - $(call COMPILEXX, in-file, out-file) #CC - The command to invoke the C compiler #CFLAGS - Options to pass to the C compiler #CXX - The command to invoke the C++ compiler #CXXFLAGS - Options to pass to the C++ compiler define COMPILE @echo "CC: $1" $(Q) $(CC) -c $(CFLAGS) $1 -o $2 endef define COMPILEXX @echo "CXX: $1" $(Q) $(CXX) -c $(CXXFLAGS) $1 -o $2 endef
7.2.7. ASSEMBLE - 汇编
使用方式: - $(call ASSEMBLE, in-file, out-file) #CC - By default, the C compiler is used to compile assembly language files #AFLAGS - Options to pass to the C+compiler define ASSEMBLE @echo "AS: $1" $(Q) $(CC) -c $(AFLAGS) $1 -o $2 endef
7.2.8. ARCHIVE - 打包生成lib
使用方式: - $(call ARCHIVE, archive-file, "file1 file2 file3 ...") #AR - The command to invoke the archiver (includes any options) ifeq ($(CONFIG_WINDOWS_NATIVE),y) define ARCHIVE @echo AR: $2 $(Q) $(AR) $1 $(2) endef else define ARCHIVE @echo "AR: $2" $(Q) $(AR) $1 $(2) || { echo "$(AR) $1 FAILED!" ; exit 1 ; } endef endif
7.2.9. PRELINK - 链接
使用方式: - $(call PRELINK, prelink-file, "file1 file2 file3 ...") #LD - The command to invoke the linker (includes any options) #OBJCOPY - The command to invoke the object cop (includes any options) ifeq ($(CONFIG_WINDOWS_NATIVE),y) define PRELINK @echo PRELINK: $1 $(Q) $(LD) -Ur -o $1 $2 && $(OBJCOPY) --localize-hidden $1 endef else define PRELINK @echo "PRELINK: $1" $(Q) $(LD) -Ur -o $1 $2 && $(OBJCOPY) --localize-hidden $1 endef endif
7.2.10. MOVEOBJ - 空
使用方式 - 无 define MOVEOBJ endef
7.2.11. DELFILE - 删除一个文件
使用方式: - $(call DELFILE file") ifeq ($(CONFIG_WINDOWS_NATIVE),y) define DELFILE $(Q) if exist $1 (del /f /q $1) endef else define DELFILE $(Q) rm -f $1 endef endif
7.2.12. DELDIR - 删除一个目录
使用方式: - $(call DELDIR dir") ifeq ($(CONFIG_WINDOWS_NATIVE),y) define DELDIR $(Q) if exist $1 (rmdir /q /s $1) endef else define DELDIR $(Q) rm -rf $1 endef endif
7.2.13. MOVEFILE - 移动一个文件
使用方式: - $(call MOVEFILE target src") ifeq ($(CONFIG_WINDOWS_NATIVE),y) define MOVEFILE $(Q) if exist $1 (move /Y $1 $2) endef else define MOVEFILE $(Q) mv -f $1 $2 endef endif
7.2.14. CLEAN - 清除默认目标 .o .a .swp .*
使用方式: - $(call CLEAN") ifeq ($(CONFIG_WINDOWS_NATIVE),y) define CLEAN $(Q) if exist *$(OBJEXT) (del /f /q *$(OBJEXT)) $(Q) if exist *$(LIBEXT) (del /f /q *$(LIBEXT)) $(Q) if exist *~ (del /f /q *~) $(Q) if exist (del /f /q .*.swp) endef else define CLEAN $(Q) rm -f *$(OBJEXT) *$(LIBEXT) *~ .* .swp endef endif
相关文章推荐
- prel 多行注释
- android学习笔记——回调机制
- 大家一起和snailren学java-(一)对象导论
- 7-11-最短路径算法-图-第7章-《数据结构》课本源码-严蔚敏吴伟民版
- 在ubuntu中配置SSH(解决connect to host localhost port 22: Connection refused问题)
- html页面优化
- VirtualBox在Linux下安装增强功能时出错
- iOS伪拷贝, 浅拷贝, 深拷贝
- 【原】Spark Standalone如何通过start-all.sh启动集群
- 【HTML5】新增的主体结构元素
- python 字符串转浮点数
- 个人感想
- Java并发编程之阻塞队列详解
- awk 九九乘法表 shell实现代码
- Python中列表、字典、元组数据结构的简单学习笔记
- 两个命令把 Vim 打造成 Python IDE的方法
- 总结Python编程中函数的使用要点
- 深入解析Python中函数的参数与作用域
- 举例讲解Python中的迭代器、生成器与列表解析用法
- 老司机传授Ubuntu下Apache+PHP+MySQL环境搭建攻略