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的主要任务是把一张图片从服务器下载到内存中.下载数据并不难,如何对下载这一系列的任务进行设计 ...
随机推荐
- window redis php(必须版本>=5.4) 安装
1.下载redis的win版客户端 下载地址: http://code.google.com/p/servicestack/wiki/RedisWindowsDownload 2.选择32bit,64 ...
- 当我们有多个类 继承同一个父类 这时候使用多态时候 可以使用该父类的类型做引用 不需要将object做引用
当我们有多个类 继承同一个父类 这时候使用多态时候 可以使用该父类的类型做引用 不需要将object做引用
- 关于在springmvc下使用@RequestBody报http status 415的错误解决办法
网上有很多原因,进行整理后主要有以下几类 springmvc添加配置.注解: pom.xml添加jackson包引用: Ajax请求时没有设置Content-Type为application/json ...
- SPA页面性能优化
1. 快速启动 —— 极大提升加载速度(important) 快速启动应用,并行发起 Bundle 加载&拉取初始数据.相信大家已经发现了,SPA 初始化时候,不得不等待 bundle 返回并 ...
- [BZOJ4553][HEOI2016]序列 CDQ分治
4553: [Tjoi2016&Heoi2016]序列 Time Limit: 20 Sec Memory Limit: 128 MB Description 佳媛姐姐过生日的时候,她的小伙 ...
- 【BZOJ5418】【NOI2018】屠龙勇士(数论,exgcd)
[NOI2018]屠龙勇士(数论,exgcd) 题面 洛谷 题解 考场上半个小时就会做了,一个小时就写完了.. 然后发现没过样例,结果大力调发现中间值爆\(longlong\)了,然后就没管了.. 然 ...
- arp 投毒实验
1.查看kali2.0和kali2.0.0的IP地址,如图1和图2,其中192.168.1.133作为攻击者,192.168.1.109作为PC访问FTP服务器192.168.1.234 图1 图2 ...
- windows2016上如何通过攻击ETERNALBLUE获得meterpreter反弹
windows2016上如何通过攻击ETERNALBLUE获得meterpreter反弹 译:by backlion 0x00前言 当微软发布MS17-010漏洞的补丁时,该漏洞影响的范围是从Win ...
- 函数式编程(1)-高阶变成(1)-map/reduce
map/reduce Python内建了map()和reduce()函数. 如果你读过Google的那篇大名鼎鼎的论文“MapReduce: Simplified Data Processing on ...
- 解题:NOIP 2018 赛道修建
题面 几乎把我送退役的一道题,留在这里做个纪念. 考场看出来是原题结果为了求稳强行花了一个小时写了80pts暴力,然后挂了55pts(真·暴力写挂),结果今天花了不到半个小时连想带写一遍95pts(T ...