Tinyos Makerules解读
Makerules 文件解读 位于/opt/tinyos-2.1.2/support/make
#-*-Makefile-*- vim:syntax=make
#$Id: Makerules,v 1.6 2008/09/26 20:13:58 klueska Exp $ # @author Cory Sharp <cssharp@eecs.berkeley.edu> ### --- This makefile requires GNU Make version 3.80 or newer. ### ---
### --- Prepare variables
### --- # Get TOSDIR from ncc if it isn't set already.
ifndef TOSDIR
TOSDIR := $(shell ncc -print-tosdir)
endif
15-17行为tos文件夹路径设置函数
# Mung MAKERULES for Cygwin; see the warning below for more details.
ifneq ($(findstring \,$(MAKERULES)),)
MAKERULES := $(subst \,/,$(MAKERULES))
define BACKSLASH_WARNING
warning, MAKERULES contains backslashes. The environment variable MAKERULES contains backslashes \'s. This can
cause shell scripts including ones in this make system to fail in
strange ways. I've changed those to forward slashes for you for this
build. However, you are strongly encouraged to respecify MAKERULES as
either a standard unix-style path or as a mixed-style path where the
backslashes are replaced with forward slashes /'s. endef
$(warning $(BACKSLASH_WARNING))
endif
这段代码作用是在cygwin下,文件路径格式修改。将路径中的'\'替换为'/'。
# Deduce TINYOS_MAKE_PATH, the path to this file, if it's not defined already.
ifndef TINYOS_MAKE_PATH
ifdef MAKERULES
TINYOS_MAKE_PATH := $(dir $(MAKERULES))
TINYOS_MAKE_PATH := $(TINYOS_MAKE_PATH:%/=%)
else
TINYOS_MAKE_PATH := $(TOSDIR)/../support/make
endif
endif
4-5行是windows下make路径设置,7行是linux下make路径。
# Use a default Makelocal if it's not defined already.
TINYOS_MAKELOCAL ?= $(TINYOS_MAKE_PATH)/Makelocal # Use a default Makedefaults if it's not defined already.
TINYOS_MAKEDEFAULTS ?= $(TINYOS_MAKE_PATH)/Makedefaults # Allow users to specify additional directories to find TOSMake files.
TOSMAKE_PATH += $(TINYOS_MAKE_PATH) # Save makecmdgoals (a read only var) to goals so that we can modify it.
GOALS += $(MAKECMDGOALS)
11行中变量MAKECMDGOALS是make指令后的目标参数。
### ---
### --- Define make functions.
### --- (Lord, this is ugly. I want a real scripting language so bad.)
### ---
### --- The functions a user will generally be interested in are
### --- TOSMake_include(file)
### --- TOSMake_include_platform(dir)
### --- # names(words)
# Produce option names, like junk from /path/to/junk.target.
names = $(sort $(basename $(notdir $(1))))
12行目的是先获取文件名,然后获取文件名前缀,最后按字母排序输出。
# TOSMake_find(file_or_dir)
# Search for file_or_dir within TOSMAKE_PATH. For the special case of
# initializing TOSMAKE_PATH itself, this function does not search
# TOSMAKE_PATH if file_or_dir begins with +.
sh_search = for a in $(TOSMAKE_PATH); do [ -e "$$a/$$n" ] && echo "$$a/$$n" && break; done
TOSMake_find = $(if $(filter +%,$(1)),$(:+%=%),$(shell n="$(1)"; $(sh_search)))
TOSMAKE_find是搜索到的文件名。其中路径带有“+”符号的为获取TOSMAKE_PATH目录下的指定文件,函数定义在118行,在149行执行文件包含。
不带“+”符号返回的为make子目录中的文件,函数定义在106行,然后在指定的target文件中执行文件包含。
# TOSMake_makelist(dir,extension)
# Get a list of files with the given extension from a directory which MUST
# be a subdir under TOSMAKE_PATH.
TOSMake_makelist = $(wildcard $(call TOSMake_find,$(1))/*.$(2))
此段代码是获取make文件列表,带入参数是 “$(1))/*.$(2)”,其中$(1)是文件路径参数,$(2)是文件后缀名参数。
# TOSMake_include(file)
# Include a makefile which MUST be in a dir or subdir under TOSMAKE_PATH.
TOSMake_include = $(eval include $(call TOSMake_find,$(1)))
执行包含在TOSMAKE_PATH目录下的文件$(1)。
# TOSMake_extra_targets(name)
# Create a default make targets for a TOSMake extra full with its possible
# options afterward.
define TOSMake_extra_targets
$(subst :,%,$(1)): FORCE
@:
endef
当传入make目标无效时调用此函数,执行空操作。
第五行的FORCE是定义的为目标,常用在没有命令和依赖的规则。(如果一个规则只有目标,没有依赖,也没有命令,而且该规则的目标也不存在,则make认为只要该规则运行,其目标就已被更新。这意味着所有以这种规则的目标为依赖的规则,它们的命令将总被执行。)
# TOSMake_include_dir(dir)
# Pull in .extras and .targets from a directory which MUST be a subdir
# under TOSMAKE_PATH. Create default extra rules as necessary, etc.
TOSMake_include_dir = $(eval $(call TOSMake_include_dir_define,$()))
define TOSMake_include_dir_define
$(eval NEW_EXTRAS := $(call TOSMake_makelist,$(),extra))
$(eval NEW_TARGETS := $(call TOSMake_makelist,$(),target))
$(eval VALID_EXTRAS += $(NEW_EXTRAS))
$(eval VALID_TARGETS += $(NEW_TARGETS))
$(eval EXTRAS = $(filter $(call names,$(VALID_EXTRAS)),$(GOALS)))
$(eval TARGETS = $(filter $(call names,$(VALID_TARGETS)),$(GOALS)))
$(eval OTHERS = $(filter-out $(EXTRAS) $(TARGETS),$(GOALS)))
$(foreach file,$(NEW_EXTRAS) $(NEW_TARGETS),$(if $(filter $(call names,$(file)),$(GOALS)),$(eval include $(file))))
endef
这段代码目的是查找有效的EXTRA和TARGET,并包含这些有效文件。参数$(1)是文件查找路径。
TOSMake_accum_dir = $(eval $(call TOSMake_accum_dir_define,$()))
define TOSMake_accum_dir_define
$(eval NEW_EXTRAS := $(call TOSMake_makelist,$(1),extra))
$(eval NEW_TARGETS := $(call TOSMake_makelist,$(1),target))
$(eval VALID_EXTRAS += $(NEW_EXTRAS))
$(eval VALID_TARGETS += $(NEW_TARGETS))
$(eval TARGETS = $(filter $(call names,$(VALID_TARGETS)),$(GOALS)))
endef
此代码上方的类似,不同的地方是查找的路径不同,本代码并不执行文件包含操作。
# TOSMake_include_platform(dir)
# Pull in a directory as a new TOSMake platform, which MUST be a subdir of
# TOSMAKE_PATH. A platform directory must also have a .rules file, which
# is automatically evaluated.
TOSMake_include_platform=$(eval $(call TOSMake_include_platform_define,$(1)))
define TOSMake_include_platform_define
$(call TOSMake_include_dir,$(1))
$(call TOSMake_include,$(1)/$(1).rules)
endef
执行包含target目标指定的文件。例如telosb.target中参数$(1)是msp。
# Makelocal comes first to allow overriding Makedefaults.
-include $(TINYOS_MAKELOCAL)
-include $(TINYOS_MAKEDEFAULTS) PLATFORMDIR ?= $(TOSDIR)/platforms/$(PLATFORM)
第五行中的$(PLATFORM)在目标对应的target文件中被定义,如telosb平台在telosb.target中。
# Mark TOSMAKE_PATH with a + so that they're not searched for by TOSMake_find.
$(foreach incdir,$(addprefix +,$(TOSMAKE_PATH)),$(call TOSMake_accum_dir,$(incdir))) $(foreach file,$(VALID_EXTRAS),$(if $(filter $(call names,$(file)),$(GOALS)),$(eval include $(file))))
$(foreach file,$(VALID_TARGETS),$(if $(filter $(call names,$(file)),$(GOALS)),$(eval include $(file)))) # Make default rules for each extra with full argument
$(foreach goal,$(MAKECMDGOALS),$(if $(filter-out $(TARGETS) help,$(goal)),$(eval $(call TOSMake_extra_targets,$(goal)))))
此段代码都是文件包含操作,调用了上面的函数生成。
第2行搜索的make目录下的对应的target和extra文件,和其他目录的文件以“+”区分。
4,5行包含有行2搜索到的有效目标文件。
若目标无效,行8则会调用“TOSMake_extra_targets”函数执行空操作。
### ---
### --- Define USAGE, print help if necessary or requested, etc.
### --- # USAGE is printed out when help is requested. Files other than this should
# add text to HELP, not USAGE.
define USAGE Usage: make <target> <extras>
make <target> help Valid targets: $(call names,$(VALID_TARGETS))
Valid extras: $(call names,$(VALID_EXTRAS))
$(HELP) endef
此段代码定义的是语法规则显示函数,其中参数$(HELP)在TINYOS_MAKEDEFAULTS中定义。
# If no target or an invalid target is specified, print usage.
ifeq ($(TARGETS),)
ifeq ($(GOALS),)
$(error $(USAGE)Please specify a valid target)
else
$(error $(USAGE)ERROR, "$(GOALS)" does not specify a valid target)
endif
endif
代码2,3行判断目标是否有效,若无效或不存在则会生成对应的错误信息。
# If the user specifically had help on the command line, don't build any
# targets, instead display help information and exit with a nice error.
ifeq ($(filter help,$(GOALS)),help)
define USAGE Usage: make $(TARGETS) <extras> Valid targets: $(call names,$(VALID_TARGETS))
Valid extras: $(call names,$(VALID_EXTRAS))
$(HELP) endef
$(error $(USAGE)Thank you)
endif
此段代码判断目标是否为help,若成立则输出内部定义的USAGE函数。
$(COMPONENT).nc:
@echo "ERROR: You need to create a top level file called $(COMPONENT).nc, or modify your local Makefile to point to the real name of your top level component."
@false .PHONY: FORCE
第1-3行语法规则有待研究。。。。
第五行定义了FORCE伪目标。
完整Makerules如下:
#-*-Makefile-*- vim:syntax=make
#$Id: Makerules,v 1.6 // :: klueska Exp $ # @author Cory Sharp <cssharp@eecs.berkeley.edu> ### --- This makefile requires GNU Make version 3.80 or newer. ### ---
### --- Prepare variables
### --- # Get TOSDIR from ncc if it isn't set already.
ifndef TOSDIR
TOSDIR := $(shell ncc -print-tosdir)
endif # Mung MAKERULES for Cygwin; see the warning below for more details.
ifneq ($(findstring \,$(MAKERULES)),)
MAKERULES := $(subst \,/,$(MAKERULES))
define BACKSLASH_WARNING
warning, MAKERULES contains backslashes. The environment variable MAKERULES contains backslashes \'s. This can
cause shell scripts including ones in this make system to fail in
strange ways. I've changed those to forward slashes for you for this
build. However, you are strongly encouraged to respecify MAKERULES as
either a standard unix-style path or as a mixed-style path where the
backslashes are replaced with forward slashes /'s. endef
$(warning $(BACKSLASH_WARNING))
endif # Deduce TINYOS_MAKE_PATH, the path to this file, if it's not defined already.
ifndef TINYOS_MAKE_PATH
ifdef MAKERULES
TINYOS_MAKE_PATH := $(dir $(MAKERULES))
TINYOS_MAKE_PATH := $(TINYOS_MAKE_PATH:%/=%)
else
TINYOS_MAKE_PATH := $(TOSDIR)/../support/make
endif
endif # Use a default Makelocal if it's not defined already.
TINYOS_MAKELOCAL ?= $(TINYOS_MAKE_PATH)/Makelocal # Use a default Makedefaults if it's not defined already.
TINYOS_MAKEDEFAULTS ?= $(TINYOS_MAKE_PATH)/Makedefaults # Allow users to specify additional directories to find TOSMake files.
TOSMAKE_PATH += $(TINYOS_MAKE_PATH) # Save makecmdgoals (a read only var) to goals so that we can modify it.
GOALS += $(MAKECMDGOALS) # Extract user options from goals of the form opt,arg, transform to opt=arg,
# and evaluate. Then, reduce GOALS to have the args removed.
OptRE := [,.]
GoalOpts := $(shell perl -e 'print join " ", map {s{^(.*?)$(OptRE)}{\U$$1=};$$_} grep /$(OptRE)/, split /\s+/, "$(GOALS)";')
GOALS := $(shell perl -e '$$_="$(GOALS)"; s{$(OptRE)\S*}{}g; print;')
$(foreach opt,$(GoalOpts),$(eval $(opt))) ### ---
### --- Define make functions.
### --- (Lord, this is ugly. I want a real scripting language so bad.)
### ---
### --- The functions a user will generally be interested in are
### --- TOSMake_include(file)
### --- TOSMake_include_platform(dir)
### --- # names(words)
# Produce option names, like junk from /path/to/junk.target.
names = $(sort $(basename $(notdir $()))) # TOSMake_find(file_or_dir)
# Search for file_or_dir within TOSMAKE_PATH. For the special case of
# initializing TOSMAKE_PATH itself, this function does not search
# TOSMAKE_PATH if file_or_dir begins with +.
sh_search = for a in $(TOSMAKE_PATH); do [ -e "$$a/$$n" ] && echo "$$a/$$n" && break; done
TOSMake_find = $(if $(filter +%,$()),$(:+%=%),$(shell n="$(1)"; $(sh_search))) # TOSMake_makelist(dir,extension)
# Get a list of files with the given extension from a directory which MUST
# be a subdir under TOSMAKE_PATH.
TOSMake_makelist = $(wildcard $(call TOSMake_find,$())/*.$(2)) # TOSMake_include(file)
# Include a makefile which MUST be in a dir or subdir under TOSMAKE_PATH.
TOSMake_include = $(eval include $(call TOSMake_find,$(1))) # TOSMake_extra_targets(name)
# Create a default make targets for a TOSMake extra full with its possible
# options afterward.
define TOSMake_extra_targets
$(subst :,%,$(1)): FORCE
@:
endef # TOSMake_include_dir(dir)
# Pull in .extras and .targets from a directory which MUST be a subdir
# under TOSMAKE_PATH. Create default extra rules as necessary, etc.
TOSMake_include_dir = $(eval $(call TOSMake_include_dir_define,$(1)))
define TOSMake_include_dir_define
$(eval NEW_EXTRAS := $(call TOSMake_makelist,$(1),extra))
$(eval NEW_TARGETS := $(call TOSMake_makelist,$(1),target))
$(eval VALID_EXTRAS += $(NEW_EXTRAS))
$(eval VALID_TARGETS += $(NEW_TARGETS))
$(eval EXTRAS = $(filter $(call names,$(VALID_EXTRAS)),$(GOALS)))
$(eval TARGETS = $(filter $(call names,$(VALID_TARGETS)),$(GOALS)))
$(eval OTHERS = $(filter-out $(EXTRAS) $(TARGETS),$(GOALS)))
$(foreach file,$(NEW_EXTRAS) $(NEW_TARGETS),$(if $(filter $(call names,$(file)),$(GOALS)),$(eval include $(file))))
endef TOSMake_accum_dir = $(eval $(call TOSMake_accum_dir_define,$(1)))
define TOSMake_accum_dir_define
$(eval NEW_EXTRAS := $(call TOSMake_makelist,$(1),extra))
$(eval NEW_TARGETS := $(call TOSMake_makelist,$(1),target))
$(eval VALID_EXTRAS += $(NEW_EXTRAS))
$(eval VALID_TARGETS += $(NEW_TARGETS))
$(eval TARGETS = $(filter $(call names,$(VALID_TARGETS)),$(GOALS)))
endef # TOSMake_include_platform(dir)
# Pull in a directory as a new TOSMake platform, which MUST be a subdir of
# TOSMAKE_PATH. A platform directory must also have a .rules file, which
# is automatically evaluated.
TOSMake_include_platform=$(eval $(call TOSMake_include_platform_define,$(1)))
define TOSMake_include_platform_define
$(call TOSMake_include_dir,$(1))
$(call TOSMake_include,$(1)/$(1).rules)
endef ### ---
### --- Include Makelocal and Makedefaults
### --- # Makelocal comes first to allow overriding Makedefaults.
-include $(TINYOS_MAKELOCAL)
-include $(TINYOS_MAKEDEFAULTS) PLATFORMDIR ?= $(TOSDIR)/platforms/$(PLATFORM) # Mark TOSMAKE_PATH with a + so that they're not searched for by TOSMake_find.
$(foreach incdir,$(addprefix +,$(TOSMAKE_PATH)),$(call TOSMake_accum_dir,$(incdir))) $(foreach file,$(VALID_EXTRAS),$(if $(filter $(call names,$(file)),$(GOALS)),$(eval include $(file))))
$(foreach file,$(VALID_TARGETS),$(if $(filter $(call names,$(file)),$(GOALS)),$(eval include $(file)))) # Make default rules for each extra with full argument
$(foreach goal,$(MAKECMDGOALS),$(if $(filter-out $(TARGETS) help,$(goal)),$(eval $(call TOSMake_extra_targets,$(goal))))) ### ---
### --- Define USAGE, print help if necessary or requested, etc.
### --- # USAGE is printed out when help is requested. Files other than this should
# add text to HELP, not USAGE.
define USAGE Usage: make <target> <extras>
make <target> help Valid targets: $(call names,$(VALID_TARGETS))
Valid extras: $(call names,$(VALID_EXTRAS))
$(HELP) endef # If no target or an invalid target is specified, print usage.
ifeq ($(TARGETS),)
ifeq ($(GOALS),)
$(error $(USAGE)Please specify a valid target)
else
$(error $(USAGE)ERROR, "$(GOALS)" does not specify a valid target)
endif
endif # If the user specifically had help on the command line, don't build any
# targets, instead display help information and exit with a nice error.
ifeq ($(filter help,$(GOALS)),help)
define USAGE Usage: make $(TARGETS) <extras> Valid targets: $(call names,$(VALID_TARGETS))
Valid extras: $(call names,$(VALID_EXTRAS))
$(HELP) endef
$(error $(USAGE)Thank you)
endif $(COMPONENT).nc:
@echo "ERROR: You need to create a top level file called $(COMPONENT).nc, or modify your local Makefile to point to the real name of your top level component."
@false .PHONY: FORCE
Tinyos Makerules解读的更多相关文章
- TinyOS和Deluge的安装模拟(二)
TinyOS的安装 TinyOS的安装是一件麻烦的事情,它不像其他的开发环境那样配置简单.要想成功安装好TinyOS,需要选择好PC操作系统,TinyOS安装文件的版本,工具链的版本…….总之,安装过 ...
- TinyOS编程思想和Nesc基础语法
TinyOS操作系统由nesc语言写成,从程序员角度看,它的基本作用就是提供了一组API接口以及一些编程规则. 具体来说,基于nesc语言的TinyOS编程行为具有以下特点: a.兼容C语言:使用ne ...
- 实验六 CC2530平台上P2P通信的TinyOS编程
实验六 CC2530平台上P2P通信的TinyOS编程 实验目的: 加深和巩固学生对于TinyOS编程方法的理解和掌握 让学生初步的掌握射频通信TinyOS编程方法 学生通过本实验应理解TinyOS中 ...
- 实验五 CC2530平台上ADC组件的TinyOS编程
实验五 CC2530平台上ADC组件的TinyOS编程 实验目的: 加深和巩固学生对于TinyOS编程方法的理解和掌握 让学生初步掌握传感器的ADC组件应用方法 学生通过本实验能够初步的了解和掌握CC ...
- 实验四 CC2530平台上UART组件的TinyOS编程
实验四 CC2530平台上UART组件的TinyOS编程 实验目的: 加深和巩固学生对于TinyOS编程方法的理解和掌握 让学生初步掌握CC2530的UART.及其TinyOS编程方法 学生通过本实验 ...
- 第二次实验:CC2530平台上GPIO组件的TinyOS编程
实验二 CC2530平台上GPIO组件的TinyOS编程 实验目的: 加深和巩固学生对于TinyOS编程方法的理解和掌握 让学生理解和掌握CC2530的GPIO及外部中断,及其TinyOS编程方法 学 ...
- Tinyos 第三版Make系统
1.make系统安装 cd tools ./Bootstrap ./configure make sudo make install 2.make系统结构 3.第三版Makerules文件部分解析 # ...
- TinyOS在ubuntu 14.04下安装教程
1:打开/etc/apt/sources.list 文件,在文件最底部添加安装源: deb http://tinyos.stanford.edu/tinyos/dists/ubuntu lucid m ...
- SDWebImage源码解读之SDWebImageDownloaderOperation
第七篇 前言 本篇文章主要讲解下载操作的相关知识,SDWebImageDownloaderOperation的主要任务是把一张图片从服务器下载到内存中.下载数据并不难,如何对下载这一系列的任务进行设计 ...
随机推荐
- opencv 矩阵类数据的运算
参考:http://blog.sina.com.cn/s/blog_7908e1290101i97z.htmlhttp://blog.sina.com.cn/s/blog_afe2af380101bq ...
- 【Linux学习笔记】Linux C中内联汇编的语法格式及使用方法(Inline Assembly in Linux C)
http://blog.csdn.net/slvher/article/details/8864996 https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm. ...
- Mybatis 类属性和字段映射小小分析
在上一篇 [Mybatis 点点滴滴]博客中,写到了 Mybatis 能够将类属性和表字段自动对应起来,在 parameterType属性值直接填写 POJO 类的名称即可(首字母不区分大小写),在 ...
- js控制iframe高度自动撑开
<iframe src="index.html" width="100%" name="" id="myiframe&quo ...
- HDU4647_Another Graph Game
有趣的博弈题. 关键在于把比边权的平分到两边的点权上面,然后点权排序,每次从大的开始拿就可以了. #include <iostream> #include <cstdio> # ...
- dom变成jquery对象 先获取dom对象 然后通过$()转换成jquery对象
dom变成jquery对象 先获取dom对象 然后通过$()转换成jquery对象
- 常州day1p4
给定一棵 n 个点的树,树上每个节点代表一个小写字母,询问一个字符串 S 是否在树上出现过? 字符串 S 出现过即表示存在两个点 u,v,u 到 v 的最短路径上依次连接所有点上的字母恰好是 S N ...
- HDU.1495 非常可乐 (BFS)
题意分析 大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为.因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶可乐,而且一定要喝的和seeyou一样多 ...
- 电子商务(电销)平台中用户模块(User)数据库设计明细
以下是自己在电子商务系统设计中的订单模块的数据库设计经验总结,而今发表出来一起分享,如有不当,欢迎跟帖讨论~ 用户基础表(user_base)|-- 自动编号 (user_id)|-- 用户名 (us ...
- vector 和数组 之间的转化
1.数组转vector float arrHeight[] = { 1.68,1.72,1.83,2.05,2.35,1.78,2.1,1.96 }; vector<float> vec ...