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解读的更多相关文章

  1. TinyOS和Deluge的安装模拟(二)

    TinyOS的安装 TinyOS的安装是一件麻烦的事情,它不像其他的开发环境那样配置简单.要想成功安装好TinyOS,需要选择好PC操作系统,TinyOS安装文件的版本,工具链的版本…….总之,安装过 ...

  2. TinyOS编程思想和Nesc基础语法

    TinyOS操作系统由nesc语言写成,从程序员角度看,它的基本作用就是提供了一组API接口以及一些编程规则. 具体来说,基于nesc语言的TinyOS编程行为具有以下特点: a.兼容C语言:使用ne ...

  3. 实验六 CC2530平台上P2P通信的TinyOS编程

    实验六 CC2530平台上P2P通信的TinyOS编程 实验目的: 加深和巩固学生对于TinyOS编程方法的理解和掌握 让学生初步的掌握射频通信TinyOS编程方法 学生通过本实验应理解TinyOS中 ...

  4. 实验五 CC2530平台上ADC组件的TinyOS编程

    实验五 CC2530平台上ADC组件的TinyOS编程 实验目的: 加深和巩固学生对于TinyOS编程方法的理解和掌握 让学生初步掌握传感器的ADC组件应用方法 学生通过本实验能够初步的了解和掌握CC ...

  5. 实验四 CC2530平台上UART组件的TinyOS编程

    实验四 CC2530平台上UART组件的TinyOS编程 实验目的: 加深和巩固学生对于TinyOS编程方法的理解和掌握 让学生初步掌握CC2530的UART.及其TinyOS编程方法 学生通过本实验 ...

  6. 第二次实验:CC2530平台上GPIO组件的TinyOS编程

    实验二 CC2530平台上GPIO组件的TinyOS编程 实验目的: 加深和巩固学生对于TinyOS编程方法的理解和掌握 让学生理解和掌握CC2530的GPIO及外部中断,及其TinyOS编程方法 学 ...

  7. Tinyos 第三版Make系统

    1.make系统安装 cd tools ./Bootstrap ./configure make sudo make install 2.make系统结构 3.第三版Makerules文件部分解析 # ...

  8. TinyOS在ubuntu 14.04下安装教程

    1:打开/etc/apt/sources.list 文件,在文件最底部添加安装源: deb http://tinyos.stanford.edu/tinyos/dists/ubuntu lucid m ...

  9. SDWebImage源码解读之SDWebImageDownloaderOperation

    第七篇 前言 本篇文章主要讲解下载操作的相关知识,SDWebImageDownloaderOperation的主要任务是把一张图片从服务器下载到内存中.下载数据并不难,如何对下载这一系列的任务进行设计 ...

随机推荐

  1. pixi.js tools

    pixi群 881784250 Awesome pixi.js tools A list of useful libs/resources/tools for renowned html5 rende ...

  2. 数据库引擎InnoDB和MyISAM区别

    MyISAM是MySQL的默认数据库引擎(5.5版之前),由早期的ISAM(Indexed Sequential Access Method:有索引的顺序访问方法)所改良.虽然性能极佳,但却有一个缺点 ...

  3. 第209天:jQuery运动框架封装(二)

    运动框架 一.函数------单物体运动框架封装 1.基于时间的运动原理 动画时间进程 动画距离进程 图解: 物体从0移动到400 当物体移动到200的时候 走了50% 同样的,物体总共运行需要4秒 ...

  4. Angel Beats,AFOer Beats?

    意识模糊的时候适合写一些奇怪的东西? NOI退役之后我尝试了很多方法调节心态.(比如做OI题,出OI题,学文化课,读书,吃饭,睡觉,水群,看番,推galgame). 然而看啥都是退役的画风.比如说推W ...

  5. 【uoj#225】[UR #15]奥林匹克五子棋 构造

    题目描述 两个人在 $n\times m$ 的棋盘上下 $k$ 子棋,问:是否存在一种平局的情况?如果存在则输出一种可能的最终情况. 输入 第一行三个正整数 $n,m,k$ ,意义如前所述. 输出 如 ...

  6. [五]SpringBoot 之 连接数据库(JPA-Hibernate)

    在具体介绍之前,先了解下什么是JPA JPA全称JavaPersistence API.JPA通过JDK5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. http: ...

  7. P2764 最小路径覆盖问题(网络流24题之一)

    题目描述 «问题描述: 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖.P 中路径可以从V 的任何一个顶点开 ...

  8. BZOJ2216 [Poi2011]Lightning Conductor 【决策单调性dp】

    题目链接 BZOJ2216 题解 学过高中数学都应知道,我们要求\(p\)的极值,参变分离为 \[h_j + sqrt{|i - j|} - h_i \le p\] 实际上就是求\(h_j + sqr ...

  9. javascript中的位运算,

    罗浮宫群里又有讨论位运算符号|了,做过一段时间php,数据库保存布尔值数据经常用到,比如100110 就表明了六个属性的是与否,极大减少了数据量..] ECMAScript 中位运算跟其他语言一样的. ...

  10. omnet++4.0安装使用

    http://my.oschina.net/u/2269841/blog/423659 本文主要借鉴该文章在此对作者表示由衷的感谢http://blog.csdn.net/xiaobei4929/ar ...