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的主要任务是把一张图片从服务器下载到内存中.下载数据并不难,如何对下载这一系列的任务进行设计 ...
随机推荐
- WebUploader 设置单个文件上传
1.导入控件样式文件 <link rel="stylesheet" type="text/css" href="__PUBLIC__/stati ...
- wx import require的理解
服务器端的Node.js遵循CommonJS规范.核心思想是允许模块通过require 方法来同步加载所要依赖的其他模块,然后通过 exports或module.exports来导出需要暴露的接口. ...
- Spring注解原理
一.注解的基本概念和原理及其简单实用 注解(Annotation)提供了一种安全的类似注释的机制,为我们在代码中添加信息提供了一种形式化得方法,使我们可以在稍后某个时刻方便的使用这些数据(通过解析注解 ...
- 3294 [SCOI2016]背单词
题目描述 Lweb 面对如山的英语单词,陷入了深深的沉思,”我怎么样才能快点学完,然后去玩三国杀呢?“.这时候睿智的凤老师从远处飘来,他送给了 Lweb 一本计划册和一大缸泡椒,他的计划册是长这样的: ...
- TortoiseSVN 和 VisualSVN Server 使用教程
TortoiseSVN 和 VisualSVN Server 使用教程 来源 https://blog.csdn.net/xgf415/article/details/75196360 目录: SVN ...
- # HNOI2012 ~ HNOI2018 题解
HNOI2012 题解 [HNOI2012]永无乡 Tag:线段树合并.启发式合并 联通块合并问题. 属于\(easy\)题,直接线段树合并 或 启发式合并即可. [HNOI2012]排队 Tag:组 ...
- HPP注入详解
###HPP参数污染的定义 HTTP Parameter Pollution简称HPP,所以有的人也称之为“HPP参数污染”,HPP是一种注入型的漏洞,攻击者通过在HTTP请求中插入特定的参数来发 ...
- echars画折线图的一种数据处理方式
echars画折线图的一种数据处理方式 <!DOCTYPE html> <html> <head> <meta charset="utf-8&quo ...
- vim切换显示器乱行问题解决
http://note.youdao.com/noteshare?id=ccdad950ca154a6b1597cbe2ede07b81
- (4.1)LingPipe在Eclipse中的运行
酒店评论情感分析系统(四)——LingPipe在Eclipse中的运行 本来打算在做这个项目的时候,使用基于语义的文本倾向性分析方法,即先通过对评论文本进行中文分析,去停用词,然后在倾向性语义模式库的 ...