博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Tinyos Makerules解读
阅读量:6702 次
发布时间:2019-06-25

本文共 15862 字,大约阅读时间需要 52 分钟。

Makerules 文件解读 位于/opt/tinyos-2.1.2/support/make

1 #-*-Makefile-*- vim:syntax=make 2 #$Id: Makerules,v 1.6 2008/09/26 20:13:58 klueska Exp $ 3  4 # @author Cory Sharp 
5 6 ### --- This makefile requires GNU Make version 3.80 or newer. 7 8 9 ### ---10 ### --- Prepare variables11 ### ---12 13 14 # Get TOSDIR from ncc if it isn't set already.15 ifndef TOSDIR16 TOSDIR := $(shell ncc -print-tosdir)17 endif

15-17行为tos文件夹路径设置函数

 

1 #  Mung MAKERULES for Cygwin; see the warning below for more details. 2 ifneq ($(findstring \,$(MAKERULES)),) 3 MAKERULES := $(subst \,/,$(MAKERULES)) 4 define BACKSLASH_WARNING 5 warning, MAKERULES contains backslashes. 6  7     The environment variable MAKERULES contains backslashes \'s.  This can 8     cause shell scripts including ones in this make system to fail in 9     strange ways.  I've changed those to forward slashes for you for this10     build.  However, you are strongly encouraged to respecify MAKERULES as11     either a standard unix-style path or as a mixed-style path where the12     backslashes are replaced with forward slashes /'s.13 14 endef15 $(warning $(BACKSLASH_WARNING))16 endif

这段代码作用是在cygwin下,文件路径格式修改。将路径中的'\'替换为'/'。

 

1 #  Deduce TINYOS_MAKE_PATH, the path to this file, if it's not defined already.2 ifndef TINYOS_MAKE_PATH3   ifdef MAKERULES4     TINYOS_MAKE_PATH := $(dir $(MAKERULES))5     TINYOS_MAKE_PATH := $(TINYOS_MAKE_PATH:%/=%)6   else7     TINYOS_MAKE_PATH := $(TOSDIR)/../support/make8   endif9 endif

4-5行是windows下make路径设置,7行是linux下make路径。

 

1 #  Use a default Makelocal if it's not defined already. 2 TINYOS_MAKELOCAL ?= $(TINYOS_MAKE_PATH)/Makelocal 3  4 #  Use a default Makedefaults if it's not defined already. 5 TINYOS_MAKEDEFAULTS ?= $(TINYOS_MAKE_PATH)/Makedefaults 6  7 #  Allow users to specify additional directories to find TOSMake files. 8 TOSMAKE_PATH += $(TINYOS_MAKE_PATH) 9 10 #  Save makecmdgoals (a read only var) to goals so that we can modify it.11 GOALS += $(MAKECMDGOALS)

11行中变量MAKECMDGOALS是make指令后的目标参数。

 

1 ### --- 2 ### --- Define make functions. 3 ### --- (Lord, this is ugly. I want a real scripting language so bad.) 4 ### --- 5 ### --- The functions a user will generally be interested in are 6 ### ---   TOSMake_include(file) 7 ### ---   TOSMake_include_platform(dir) 8 ### --- 9 10 #  names(words)11 #    Produce option names, like junk from /path/to/junk.target.12 names = $(sort $(basename $(notdir $(1))))

12行目的是先获取文件名,然后获取文件名前缀,最后按字母排序输出。

 

1 #  TOSMake_find(file_or_dir)2 #    Search for file_or_dir within TOSMAKE_PATH.  For the special case of3 #    initializing TOSMAKE_PATH itself, this function does not search 4 #    TOSMAKE_PATH if file_or_dir begins with +.5 sh_search = for a in $(TOSMAKE_PATH); do [ -e "$$a/$$n" ] && echo "$$a/$$n" && break; done6 TOSMake_find = $(if $(filter +%,$(1)),$(1:+%=%),$(shell n="$(1)"; $(sh_search)))

TOSMAKE_find是搜索到的文件名。其中路径带有“+”符号的为获取TOSMAKE_PATH目录下的指定文件,函数定义在118行,在149行执行文件包含。

不带“+”符号返回的为make子目录中的文件,函数定义在106行,然后在指定的target文件中执行文件包含。

 

1 #  TOSMake_makelist(dir,extension)2 #    Get a list of files with the given extension from a directory which MUST3 #    be a subdir under TOSMAKE_PATH.4 TOSMake_makelist = $(wildcard $(call TOSMake_find,$(1))/*.$(2))

此段代码是获取make文件列表,带入参数是 “$(1))/*.$(2)”,其中$(1)是文件路径参数,$(2)是文件后缀名参数。

 

1 #  TOSMake_include(file)2 #    Include a makefile which MUST be in a dir or subdir under TOSMAKE_PATH.3 TOSMake_include = $(eval include $(call TOSMake_find,$(1)))

执行包含在TOSMAKE_PATH目录下的文件$(1)。

 

1 #  TOSMake_extra_targets(name)2 #    Create a default make targets for a TOSMake extra full with its possible3 #    options afterward.4 define TOSMake_extra_targets5 $(subst :,%,$(1)): FORCE6     @:7 endef

当传入make目标无效时调用此函数,执行空操作。

第五行的FORCE是定义的为目标,常用在没有命令和依赖的规则。(如果一个规则只有目标,没有依赖,也没有命令,而且该规则的目标也不存在,则make认为只要该规则运行,其目标就已被更新。这意味着所有以这种规则的目标为依赖的规则,它们的命令将总被执行。)

 

1 #  TOSMake_include_dir(dir) 2 #    Pull in .extras and .targets from a directory which MUST be a subdir 3 #    under TOSMAKE_PATH.  Create default extra rules as necessary, etc. 4 TOSMake_include_dir = $(eval $(call TOSMake_include_dir_define,$(1))) 5 define TOSMake_include_dir_define 6 $(eval NEW_EXTRAS := $(call TOSMake_makelist,$(1),extra)) 7 $(eval NEW_TARGETS := $(call TOSMake_makelist,$(1),target)) 8 $(eval VALID_EXTRAS += $(NEW_EXTRAS)) 9 $(eval VALID_TARGETS += $(NEW_TARGETS))10 $(eval EXTRAS = $(filter $(call names,$(VALID_EXTRAS)),$(GOALS)))11 $(eval TARGETS = $(filter $(call names,$(VALID_TARGETS)),$(GOALS)))12 $(eval OTHERS = $(filter-out $(EXTRAS) $(TARGETS),$(GOALS)))13 $(foreach file,$(NEW_EXTRAS) $(NEW_TARGETS),$(if $(filter $(call names,$(file)),$(GOALS)),$(eval include $(file))))14 endef

这段代码目的是查找有效的EXTRA和TARGET,并包含这些有效文件。参数$(1)是文件查找路径。

 

1 TOSMake_accum_dir = $(eval $(call TOSMake_accum_dir_define,$(1)))2 define TOSMake_accum_dir_define3 $(eval NEW_EXTRAS := $(call TOSMake_makelist,$(1),extra))4 $(eval NEW_TARGETS := $(call TOSMake_makelist,$(1),target))5 $(eval VALID_EXTRAS += $(NEW_EXTRAS))6 $(eval VALID_TARGETS += $(NEW_TARGETS))7 $(eval TARGETS = $(filter $(call names,$(VALID_TARGETS)),$(GOALS)))8 endef

此代码上方的类似,不同的地方是查找的路径不同,本代码并不执行文件包含操作。

 

1 #  TOSMake_include_platform(dir)2 #    Pull in a directory as a new TOSMake platform, which MUST be a subdir of3 #    TOSMAKE_PATH.  A platform directory must also have a .rules file, which4 #    is automatically evaluated.5 TOSMake_include_platform=$(eval $(call TOSMake_include_platform_define,$(1)))6 define TOSMake_include_platform_define7 $(call TOSMake_include_dir,$(1))8 $(call TOSMake_include,$(1)/$(1).rules)9 endef

执行包含target目标指定的文件。例如telosb.target中参数$(1)是msp。

 

1 #  Makelocal comes first to allow overriding Makedefaults.2 -include $(TINYOS_MAKELOCAL)3 -include $(TINYOS_MAKEDEFAULTS)4 5 PLATFORMDIR ?= $(TOSDIR)/platforms/$(PLATFORM)

第五行中的$(PLATFORM)在目标对应的target文件中被定义,如telosb平台在telosb.target中。

 

1 #  Mark TOSMAKE_PATH with a + so that they're not searched for by TOSMake_find.2 $(foreach incdir,$(addprefix +,$(TOSMAKE_PATH)),$(call TOSMake_accum_dir,$(incdir)))3 4 $(foreach file,$(VALID_EXTRAS),$(if $(filter $(call names,$(file)),$(GOALS)),$(eval include $(file))))5 $(foreach file,$(VALID_TARGETS),$(if $(filter $(call names,$(file)),$(GOALS)),$(eval include $(file))))6 7 #  Make default rules for each extra with full argument8 $(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”函数执行空操作。

 

1 ### --- 2 ### --- Define USAGE, print help if necessary or requested, etc. 3 ### --- 4  5 #  USAGE is printed out when help is requested.  Files other than this should 6 #  add text to HELP, not USAGE. 7 define USAGE 8  9 10 Usage:  make 
11 make
help12 13 Valid targets: $(call names,$(VALID_TARGETS))14 Valid extras: $(call names,$(VALID_EXTRAS))15 $(HELP)16 17 endef

此段代码定义的是语法规则显示函数,其中参数$(HELP)在TINYOS_MAKEDEFAULTS中定义。

 

1 #  If no target or an invalid target is specified, print usage.2 ifeq ($(TARGETS),)3   ifeq ($(GOALS),)4     $(error $(USAGE)Please specify a valid target)5   else6     $(error $(USAGE)ERROR, "$(GOALS)" does not specify a valid target)7   endif8 endif

代码2,3行判断目标是否有效,若无效或不存在则会生成对应的错误信息。

 

1 #  If the user specifically had help on the command line, don't build any 2 #  targets, instead display help information and exit with a nice error. 3 ifeq ($(filter help,$(GOALS)),help) 4 define USAGE 5  6  7 Usage:  make $(TARGETS) 
8 9 Valid targets: $(call names,$(VALID_TARGETS))10 Valid extras: $(call names,$(VALID_EXTRAS))11 $(HELP)12 13 endef14 $(error $(USAGE)Thank you)15 endif

此段代码判断目标是否为help,若成立则输出内部定义的USAGE函数。

 

1 $(COMPONENT).nc:2     @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."3     @false4 5 .PHONY: FORCE

第1-3行语法规则有待研究。。。。

第五行定义了FORCE伪目标。

 

完整Makerules如下:

1 #-*-Makefile-*- vim:syntax=make  2 #$Id: Makerules,v 1.6 2008/09/26 20:13:58 klueska Exp $  3   4 # @author Cory Sharp 
5 6 ### --- This makefile requires GNU Make version 3.80 or newer. 7 8 9 ### --- 10 ### --- Prepare variables 11 ### --- 12 13 14 # Get TOSDIR from ncc if it isn't set already. 15 ifndef TOSDIR 16 TOSDIR := $(shell ncc -print-tosdir) 17 endif 18 19 # Mung MAKERULES for Cygwin; see the warning below for more details. 20 ifneq ($(findstring \,$(MAKERULES)),) 21 MAKERULES := $(subst \,/,$(MAKERULES)) 22 define BACKSLASH_WARNING 23 warning, MAKERULES contains backslashes. 24 25 The environment variable MAKERULES contains backslashes \'s. This can 26 cause shell scripts including ones in this make system to fail in 27 strange ways. I've changed those to forward slashes for you for this 28 build. However, you are strongly encouraged to respecify MAKERULES as 29 either a standard unix-style path or as a mixed-style path where the 30 backslashes are replaced with forward slashes /'s. 31 32 endef 33 $(warning $(BACKSLASH_WARNING)) 34 endif 35 36 # Deduce TINYOS_MAKE_PATH, the path to this file, if it's not defined already. 37 ifndef TINYOS_MAKE_PATH 38 ifdef MAKERULES 39 TINYOS_MAKE_PATH := $(dir $(MAKERULES)) 40 TINYOS_MAKE_PATH := $(TINYOS_MAKE_PATH:%/=%) 41 else 42 TINYOS_MAKE_PATH := $(TOSDIR)/../support/make 43 endif 44 endif 45 46 # Use a default Makelocal if it's not defined already. 47 TINYOS_MAKELOCAL ?= $(TINYOS_MAKE_PATH)/Makelocal 48 49 # Use a default Makedefaults if it's not defined already. 50 TINYOS_MAKEDEFAULTS ?= $(TINYOS_MAKE_PATH)/Makedefaults 51 52 # Allow users to specify additional directories to find TOSMake files. 53 TOSMAKE_PATH += $(TINYOS_MAKE_PATH) 54 55 # Save makecmdgoals (a read only var) to goals so that we can modify it. 56 GOALS += $(MAKECMDGOALS) 57 58 # Extract user options from goals of the form opt,arg, transform to opt=arg, 59 # and evaluate. Then, reduce GOALS to have the args removed. 60 OptRE := [,.] 61 GoalOpts := $(shell perl -e 'print join " ", map {s{^(.*?)$(OptRE)}{\U$$1=};$$_} grep /$(OptRE)/, split /\s+/, "$(GOALS)";') 62 GOALS := $(shell perl -e '$$_="$(GOALS)"; s{$(OptRE)\S*}{}g; print;') 63 $(foreach opt,$(GoalOpts),$(eval $(opt))) 64 65 66 ### --- 67 ### --- Define make functions. 68 ### --- (Lord, this is ugly. I want a real scripting language so bad.) 69 ### --- 70 ### --- The functions a user will generally be interested in are 71 ### --- TOSMake_include(file) 72 ### --- TOSMake_include_platform(dir) 73 ### --- 74 75 # names(words) 76 # Produce option names, like junk from /path/to/junk.target. 77 names = $(sort $(basename $(notdir $(1)))) 78 79 # TOSMake_find(file_or_dir) 80 # Search for file_or_dir within TOSMAKE_PATH. For the special case of 81 # initializing TOSMAKE_PATH itself, this function does not search 82 # TOSMAKE_PATH if file_or_dir begins with +. 83 sh_search = for a in $(TOSMAKE_PATH); do [ -e "$$a/$$n" ] && echo "$$a/$$n" && break; done 84 TOSMake_find = $(if $(filter +%,$(1)),$(1:+%=%),$(shell n="$(1)"; $(sh_search))) 85 86 # TOSMake_makelist(dir,extension) 87 # Get a list of files with the given extension from a directory which MUST 88 # be a subdir under TOSMAKE_PATH. 89 TOSMake_makelist = $(wildcard $(call TOSMake_find,$(1))/*.$(2)) 90 91 # TOSMake_include(file) 92 # Include a makefile which MUST be in a dir or subdir under TOSMAKE_PATH. 93 TOSMake_include = $(eval include $(call TOSMake_find,$(1))) 94 95 # TOSMake_extra_targets(name) 96 # Create a default make targets for a TOSMake extra full with its possible 97 # options afterward. 98 define TOSMake_extra_targets 99 $(subst :,%,$(1)): FORCE100 @:101 endef102 103 # TOSMake_include_dir(dir)104 # Pull in .extras and .targets from a directory which MUST be a subdir105 # under TOSMAKE_PATH. Create default extra rules as necessary, etc.106 TOSMake_include_dir = $(eval $(call TOSMake_include_dir_define,$(1)))107 define TOSMake_include_dir_define108 $(eval NEW_EXTRAS := $(call TOSMake_makelist,$(1),extra))109 $(eval NEW_TARGETS := $(call TOSMake_makelist,$(1),target))110 $(eval VALID_EXTRAS += $(NEW_EXTRAS))111 $(eval VALID_TARGETS += $(NEW_TARGETS))112 $(eval EXTRAS = $(filter $(call names,$(VALID_EXTRAS)),$(GOALS)))113 $(eval TARGETS = $(filter $(call names,$(VALID_TARGETS)),$(GOALS)))114 $(eval OTHERS = $(filter-out $(EXTRAS) $(TARGETS),$(GOALS)))115 $(foreach file,$(NEW_EXTRAS) $(NEW_TARGETS),$(if $(filter $(call names,$(file)),$(GOALS)),$(eval include $(file))))116 endef117 118 TOSMake_accum_dir = $(eval $(call TOSMake_accum_dir_define,$(1)))119 define TOSMake_accum_dir_define120 $(eval NEW_EXTRAS := $(call TOSMake_makelist,$(1),extra))121 $(eval NEW_TARGETS := $(call TOSMake_makelist,$(1),target))122 $(eval VALID_EXTRAS += $(NEW_EXTRAS))123 $(eval VALID_TARGETS += $(NEW_TARGETS))124 $(eval TARGETS = $(filter $(call names,$(VALID_TARGETS)),$(GOALS)))125 endef126 127 # TOSMake_include_platform(dir)128 # Pull in a directory as a new TOSMake platform, which MUST be a subdir of129 # TOSMAKE_PATH. A platform directory must also have a .rules file, which130 # is automatically evaluated.131 TOSMake_include_platform=$(eval $(call TOSMake_include_platform_define,$(1)))132 define TOSMake_include_platform_define133 $(call TOSMake_include_dir,$(1))134 $(call TOSMake_include,$(1)/$(1).rules)135 endef136 137 138 ### ---139 ### --- Include Makelocal and Makedefaults140 ### ---141 142 # Makelocal comes first to allow overriding Makedefaults.143 -include $(TINYOS_MAKELOCAL)144 -include $(TINYOS_MAKEDEFAULTS)145 146 PLATFORMDIR ?= $(TOSDIR)/platforms/$(PLATFORM)147 148 # Mark TOSMAKE_PATH with a + so that they're not searched for by TOSMake_find.149 $(foreach incdir,$(addprefix +,$(TOSMAKE_PATH)),$(call TOSMake_accum_dir,$(incdir)))150 151 $(foreach file,$(VALID_EXTRAS),$(if $(filter $(call names,$(file)),$(GOALS)),$(eval include $(file))))152 $(foreach file,$(VALID_TARGETS),$(if $(filter $(call names,$(file)),$(GOALS)),$(eval include $(file))))153 154 # Make default rules for each extra with full argument155 $(foreach goal,$(MAKECMDGOALS),$(if $(filter-out $(TARGETS) help,$(goal)),$(eval $(call TOSMake_extra_targets,$(goal)))))156 157 158 ### ---159 ### --- Define USAGE, print help if necessary or requested, etc.160 ### ---161 162 # USAGE is printed out when help is requested. Files other than this should163 # add text to HELP, not USAGE.164 define USAGE165 166 167 Usage: make
168 make
help169 170 Valid targets: $(call names,$(VALID_TARGETS))171 Valid extras: $(call names,$(VALID_EXTRAS))172 $(HELP)173 174 endef175 176 # If no target or an invalid target is specified, print usage.177 ifeq ($(TARGETS),)178 ifeq ($(GOALS),)179 $(error $(USAGE)Please specify a valid target)180 else181 $(error $(USAGE)ERROR, "$(GOALS)" does not specify a valid target)182 endif183 endif184 185 # If the user specifically had help on the command line, don't build any186 # targets, instead display help information and exit with a nice error.187 ifeq ($(filter help,$(GOALS)),help)188 define USAGE189 190 191 Usage: make $(TARGETS)
192 193 Valid targets: $(call names,$(VALID_TARGETS))194 Valid extras: $(call names,$(VALID_EXTRAS))195 $(HELP)196 197 endef198 $(error $(USAGE)Thank you)199 endif200 201 $(COMPONENT).nc:202 @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."203 @false204 205 .PHONY: FORCE
View Code

 

转载于:https://www.cnblogs.com/wlzy/p/5932058.html

你可能感兴趣的文章
Windows Azure HandBook (8) Azure性能测试(1)
查看>>
优化事务处理
查看>>
iphone:Core Data:Where does a Managed Object Context Come From?
查看>>
.NET WinForm下StatusStrip控件如何设置分隔线及部分子控件右对齐
查看>>
spark groupByKey 也是可以filter的
查看>>
sqlmap使用笔记
查看>>
集合类接口IEnumerable,IEnumerator,ICollection,IList,IDictionary理解
查看>>
tkinter的GUI设计:界面与逻辑分离(二)-- 菜单栏
查看>>
Visual Studio DSL 入门 8---创建状态机元数据模型
查看>>
如何讓 iOS UIWebView 連線時傳送自訂 Cookie 的方法[转]
查看>>
LiDAR Textbook & Automated Road Network Extraction
查看>>
java并行体系结构
查看>>
探索ASP.NET MVC5系列之~~~5.缓存篇(页面缓存+二级缓存)
查看>>
ArcGIS Javascript API 1.2 Released
查看>>
命令行构建Unity项目
查看>>
C# ArrayList(数组列表)
查看>>
新近碰到的病毒(TR.Spy.Babonock.A)
查看>>
Eliminate Witches!
查看>>
ToString格式化
查看>>
HDU 4819 Mosaic D区段树
查看>>