Inclusive Makefile

本文介绍了一种名为 Inclusive 的 Make 构建方法,该方法改进了 Recursive Make 的局限性,通过 Makefile、Python 和 Perl 实现了一个灵活且易于扩展的构建系统。

以前项目中,我都用Recursive Make去构建编译环境。这种方式感觉直观,而且单一,仅仅用Makefile就可以完成,但是不足之处是,扩展起来麻烦,数据定义和规则耦合在一起,并且每执行一次子Make都要step到那个目录。耗时。最近发现在北电的项目中,使用了一种叫做Inclusive的Make。完全摒弃了Recursive的缺点。尤其是在定义和规则相分离上优势明显,并且扩展起来很方便。项目中通过Makefile+Perl+shell共同构建起了load build系统。我理解了他的思想后,写了一个demo.为了简化,我采用了Python+Makefile的组合。一共包含三个部分:
1.控制部分(build.xml)
2.模板部分
3.实例数据部分

控制部分主要的责任就是,利用模板将每个实例部分用实例数据实例化一个make对象,并执行它。

如果我们要添加模块,只需要在新模块目录下添加一份用来实例化对象的数据文件Build.mk就行了。

build.py / build.xml

from xml.etree.ElementTree import ElementTree
import os
import sys
from optparse import OptionParser
class InitConfiguration:
def __init__(self):
  self.dir = ""
  self.modules = []
def initialize(self , file):
  if os.path.exists(file):
   print "parsing:" , file
  else:
   print "can not find the file:" , file
   sys.exit(-1)
  
  xmlTree = ElementTree().parse(file)
  
  for node in xmlTree.getchildren():
   if node.tag == "topdir":
    self.dir = node.text
   if node.tag == "module":
    self.modules.append(node.text)
  
  
def invoke(self):
  cmd = "make MODULE=/'"
  for arg in self.modules:
   cmd = "make MODULE="
   cmd += arg
   cmd += " TOPDIR="
   cmd += self.dir
   print cmd
   os.system(cmd)
def clean(self):
                cmd = "make MODULE=/'"
                for arg in self.modules:
                        cmd = "make MODULE="
                        cmd += arg
                        cmd += " TOPDIR="
                        cmd += self.dir
   cmd += " clean_objs"
                        print cmd
                        os.system(cmd)
  
  os.system("make clean_libs clean_bins")
def main():
        init = InitConfiguration()
        init.initialize("../config/Build.xml")
usage = "%prog options"
optionParser = OptionParser(usage)
optionParser.add_option('--opt', dest='opt' , help='')
(options , args) = optionParser.parse_args()
if options.opt == "clean":
  init.clean()
  return

init.initialize("../config/Build.xml")
init.invoke()
return
if __name__ == "__main__":
main()  
------------------------------------------------------------------
<build>
<topdir>../../src/lteoff/domain/oam</topdir>
<module>pm</module>
<module>fm</module>
<module>sm</module>
<module>util</module>
</build>


模板Makefile:

MODULEDIR = $(patsubst %,$(TOPDIR)/%,$(MODULE))
INSTALL = /usr/bin/install
CC = g++
AR = $(CC)
ARFLAGS = -shared
RM = rm -rf
CXXFLAGS = -O3 -g -Wall
LDFLAGS = -lpthread
CPPFLAGS = -I./
LIBPATH = -L./
LINK = $(CC) -o ../../bin/$@ $^
ARCLIB = $(AR) $(ARFLAGS) -o ../../lib/lib$@.so $^ $(LDFLAGS) $(LIBPATH)
include $(patsubst %,%/Build.mk,$(MODULEDIR))
ifneq (,$(ARCHIVE))
        ifneq (,$(PROGRAM))
                DEPEND += $(ARCHIVE) $(PROGRAM)
        else
                DEPEND += $(ARCHIVE)
        endif
else
        ifneq (,$(PROGRAM))
                DEPEND += $(PROGRAM)
endif
endif
APP_VAR = $($(PROGRAM)_SRC)
ARC_VAR = $($(ARCHIVE)_SRC)
APP_OBJS = $(patsubst %.cpp,%.o,$(APP_VAR))
ARC_OBJS = $(patsubst %.cpp,%.o,$(ARC_VAR))
%.o: %.cpp
@(echo compiling $@)
$(CC) -c $< -o $@ $(CPPFLAGS) $(CXXFLAGS)
all: $(DEPEND)
@(echo done)
$(ARCHIVE): $(ARC_OBJS)
@(echo creating archive $(LIB))
$(ARCLIB)

$(PROGRAM): $(APP_OBJS)
@(echo creating executing file $(BIN))
$(LINK)
.PHONY: clean_objs clean_libs clean_bins
clean_objs:
$(RM) $(MODULEDIR)/*.o
clean_libs:
$(RM) ../../lib/*
clean_bins:
$(RM) ../../bin/*

最后是数据Makefile,在每个字模块目录下面都有一个Build.mk,里面存放了为模板Makefile实例化的数据
Build.mk

PROGRAM = fmApp
fmApp_SRC = $(TOPDIR)/fm/fmApp.cpp

ARCHIVE = fm
fm_SRC = $(TOPDIR)/fm/fm.cpp

有个网站好像是用来查看权限配置的,To find where setResourceMonitors is defined: defs:setResourceMonitors To find files that use sprintf in usr/src/cmd/cmd-inet/usr.sbin/: refs:sprintf path:usr/src/cmd/cmd-inet/usr.sbin To find assignments to variable foo: "foo =" To find Makefiles where the pstack binary is being built: pstack path:Makefile to search for phrase "Bill Joy": "Bill Joy" To find perl files that do not use /usr/bin/perl but something else: -"/usr/bin/perl" +"/bin/perl" To find all strings beginning with foo use the wildcard: foo* To find all files which have . c in their name (dot is a token!): ". c" To find all files which start with "ma" and then have only alphabet characters do: path:/ma[a-zA-Z]*/ To find all main methods in all files analyzed by C analyzer (so .c, .h, ...) do: main type:c More info: A Query is a series of clauses. A clause may be prefixed by: a plus "+" or a minus "-" sign, indicating that the clause is required or prohibited respectively; or a term followed by a colon ":", indicating the field to be searched. This enables one to construct queries which search multiple fields. A clause may be either: a term, indicating all the documents that contain this term; or a phrase - group of words surrounded by double quotes " ", e.g. "hello dolly" a nested query, enclosed in parentheses "(" ")" (also called query/field grouping) . Note that this may be used with a +/- prefix to require any of a set of terms. boolean operators which allow terms to be combined through logic operators. Supported are AND(&&), "+", OR(||), NOT(!) and "-" (Note: they must be ALL CAPS). Regular Expression, Wildcard, Fuzzy, Proximity and Range Searches: to perform a regular expression search use the "/" enclosure, e.g. /[mb]an/ - will search for man or for ban; NOTE: path field search escapes "/" by default, so it only supports regexps when the search string starts and ends with "/". More info can be found on Lucene regexp page. to perform a single character wildcard search use the "?" symbol, e.g. te?t to perform a multiple character wildcard search use the "*" symbol, e.g. test* or te*t you can use a * or ? symbol as the first character of a search (unless not enabled using indexer option -a). to do a fuzzy search (find words similar in spelling, based on the Levenshtein Distance, or Edit Distance algorithm) use the tilde, "~", e.g. rcs~ to do a proximity search use the tilde, "~", symbol at the end of a Phrase. For example to search for a "opengrok" and "help" within 10 words of each other enter: "opengrok help"~10 range queries allow one to match documents whose field(s) values are between the lower and upper bound specified by the Range Query. Range Queries can be inclusive or exclusive of the upper and lower bounds. Sorting is done lexicographically. Inclusive queries are denoted by square brackets [ ] , exclusive by curly brackets { }. For example: title:{Aida TO Carmen} - will find all documents between Aida to Carmen, exclusive of Aida and Carmen. Escaping special characters: Opengrok supports escaping special characters that are part of the query syntax. Current special characters are: + - && || ! ( ) { } [ ] ^ " ~ * ? : \ / To escape these character use the \ before the character. For example to search for (1+1):2 use the query: \(1\+1\)\:2 NOTE on analyzers: Indexed words are made up of Alpha-Numeric and Underscore characters. One letter words are usually not indexed as symbols! Most other characters (including single and double quotes) are treated as "spaces/whitespace" (so even if you escape them, they will not be found, since most analyzers ignore them). The exceptions are: @ $ % ^ & = ? . : which are mostly indexed as separate words. Because some of them are part of the query syntax, they must be escaped with a reverse slash as noted above. So searching for \+1 or \+ 1 will both find +1 and + 1. Valid FIELDs are full Search through all text tokens (words,strings,identifiers,numbers) in index. defs Only finds symbol definitions (where e.g. a variable (function, ...) is defined). refs Only finds symbols (e.g. methods, classes, functions, variables). path path of the source file (no need to use dividers, or if, then use "/" - Windows users, "\" is an escape key in Lucene query syntax! Please don't use "\", or replace it with "/"). Also note that if you want just exact path, enclose it in "", e.g. "src/mypath", otherwise dividers will be removed and you get more hits. type Type of analyzer used to scope down to certain file types (e.g. just C sources). Current mappings: [ada=Ada, asm=Asm, bzip2=Bzip(2), c=C, clojure=Clojure, csharp=C#, cxx=C++, eiffel=Eiffel, elf=ELF, erlang=Erlang, file=Image file, fortran=Fortran, golang=Golang, gzip=GZIP, haskell=Haskell, hcl=HCL, jar=Jar, java=Java, javaclass=Java class, javascript=JavaScript, json=Json, kotlin=Kotlin, lisp=Lisp, lua=Lua, mandoc=Manual pages, pascal=Pascal, perl=Perl, php=PHP, plain=Plain Text, plsql=PL/SQL, powershell=PowerShell script, python=Python, r=R, ruby=Ruby, rust=Rust, scala=Scala, sh=Shell script, sql=SQL, swift=Swift, tar=Tar, tcl=Tcl, terraform=Terraform, troff=Troff, typescript=TypeScript, uuencode=UUEncoded, vb=Visual Basic, verilog=Verilog, xml=XML, yaml=Yaml, zip=Zip] The term (phrases) can be boosted (making it more relevant) using a caret ^ , e.g. help^4 opengrok - will make term help boosted Opengrok search is powered by Lucene, for more detail on query syntax refer to Lucene docs. Intelligence Window这是用例,我该怎么来查找这个权限
11-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值