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. 查询出menupath字段中 出现 “- "(横杆)大于3次的 记录

  2. Linux下编译程序时,经常会遇到“undefined reference to XXX” 报错,

    Linux下编译程序时,经常会遇到“undefined reference to XXX” 报错, 这里总结一些可能的原因和解决方案,给需要的朋友: 说道undefined reference err ...

  3. Centos7安装完毕后联网-设置ip地址(VMware虚拟机)

    VMware虚拟机中安装了Centos7,为了让Centos能够访问外网及设置固定的ip地址以方便本地通过SSH访问Centos,做以下几步.本文来自osfipin note. 1.确认虚拟机网络链接 ...

  4. OEM SLP Key

    OEM SLP Key Windows Server 2012 R2 Datacenter ===================== 2N9T6-Y284D-T68G9-QGV6X-FRFTD -- ...

  5. 洛谷 P1278 单词游戏 【状压dp】

    题目描述 Io和Ao在玩一个单词游戏. 他们轮流说出一个仅包含元音字母的单词,并且后一个单词的第一个字母必须与前一个单词的最后一个字母一致. 游戏可以从任何一个单词开始. 任何单词禁止说两遍,游戏中只 ...

  6. python基础(4)

    条件判断和循环 条件判断 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,用if语句实现: age = 20 if ag ...

  7. 【51nod1965】奇怪的式子

    Portal --> 51nod1965 Solution 怎么说呢..这题..做的有点痛苦.. 首先看这个式子长得..比较奇怪,指数里面那个加号有点烦人,而且这个函数不是一个积性函数也有点烦人 ...

  8. 框架----Django框架(进阶篇)

    一.Model 到目前为止,当我们的程序涉及到数据库相关操作时,我们一般都会这么搞: 创建数据库,设计表结构和字段 使用 MySQLdb 来连接数据库,并编写数据访问层代码 业务逻辑层去调用数据访问层 ...

  9. R-FCN:基于区域的全卷积网络来检测物体

    http://blog.csdn.net/shadow_guo/article/details/51767036 原文标题为“R-FCN: Object Detection via Region-ba ...

  10. vs下给生成的程序(exe)加入默认的申请管理员权限

    在vs下编程时,经常会用到一些特殊的权限,尤其是管理员权限,下面是在win7下笔者亲测通过的. 下面要分两种情况: 第一种情况就是在vs2003或者以下的编译器中运行 1.准备一个manifest文件 ...