def subdir(dir): """Process a make.py in a subdirectory.""" # avoid reflexivity if curdir == dir: io.DEF.print_warning("reflexive subdir ignored in %s" % curdir) return # look for existence of make.py dpath = (curenv.path / dir).norm() path = dpath / "make.py" if not path.can_read(): common.script_error("no 'make.py' in %s" % path) # push new environment name = (curenv.name + "_" + str(dir)).replace(".", "_") push_env(env.ScriptEnv(name, dpath, curenv, {})) # load make.py mod = imp.load_source(name, str(path)) curenv.map = mod.__dict__ # pop new environment pop_env() return mod
def gen(dir, rext, dep): """Generate recipes to build res. A generation string is found between file src and res. Each intermediate file has for name the kernel of res (generated files will be put in the res directory). Returns the list of files to build (last file having rext as extension).""" dir = common.Path(dir) dep = common.Path(dep) # prepare the kernel b = dep.get_base() dext = dep.get_ext() n = b.get_file() kern = dir / n # initialize lookup process if not ext_db.has_key(dext): common.script_error("don't know how to build '%s' from '%s'" % (rext, dep)) #raise Common.MaatError("DEBUG:") ext = ext_db[dext] prev = dep # end when dep is found ress = [] while ext.ext != rext: gen = ext.gens[rext] next = kern + gen.res.ext gen.gen(next, prev) ress.append(next) prev = next ext = gen.res # return result return ress
def phony(goal, deps, *actions): """Build a goal with the following dependencies that does not match a real file.""" path = common.Path(env.cur.path) / goal file = get_file(str(path)) if file.recipe: common.script_error("a goal named '%s' already exist!" % goal) else: file.set_phony() return ActionRecipe(goal, deps, *actions).ress[0]
def dist_name(): """Build the name of the directory to build a distribution.""" DIST = env.top.DIST if not DIST: PROJECT = env.top.PROJECT if not PROJECT: common.script_error("no project name defined!") DIST = PROJECT VERSION = env.top.VERSION if VERSION: DIST = DIST + "-" + VERSION else: DIST = DIST + "-" + env.top.TODAY DIST = DIST + "-" + env.top.PLATFORM return DIST
def data(data, discard=False): """Install data: performs just a copy for a plain file, performs a recursive copy for a directory. If discard is given, it contains files to discard from the installation. Discard may a string (a file system regular expression), a list of paths or a function that must takes as parameter a path and return true (keep) or false (discard).""" # check if the path can be computed data = recipe.get_file(data) if not data.INSTALL_TO and not data.PROJECT: common.script_error( "to install data, one of PROJECT or INSTALL_TO is required!") # build the rule data = recipe.get_file(data) target = file(data.path.make("install-data-")) action = InstallData(data, common.filter(discard)) recipe.phony([target], [data], action) std.INSTALL.append(target)
def lib(name, sources, CFLAGS=None, CXXFLAGS=None, PREFIX=LIB_PREFIX, SUFFIX=LIB_SUFFIX, type="static", DYN_PREFIX=DLIB_PREFIX, DYN_SUFFIX=DLIB_SUFFIX, LDFLAGS=None, LIBS=None, RPATH=None, INSTALL_TO="", DYN_INSTALL_TO=""): """Called to build a static library.""" global need_lib need_lib = True todo = [] # check type if type not in ["static", "dynamic", "both"]: common.script_error( "library type must be one of static (default), dynamic or both.") # build objects sources = [file(s) for s in sources] objs = make_objects(env.cur.path, sources, CFLAGS, CXXFLAGS, type in ["dynamic", "both"]) # build static library if type in ["static", "both"]: lib = file(PREFIX + name + SUFFIX) recipe.ActionRecipe([lib], objs, action.Invoke(link_lib([lib], objs))) todo.append(lib) std.ALL.append(lib) std.DISTCLEAN.append(lib) config.register(CONFIG_AR) if INSTALL_TO != None: lib.INSTALL_TO = INSTALL_TO install.lib(lib) # build dynamic library if type in ["dynamic", "both"]: lib = file(DYN_PREFIX + name + DYN_SUFFIX) recipe.ActionRecipe([lib], objs, Linker(lib, objs, is_cxx(sources))) lib.ADDED_LDFLAGS = "-shared" if LDFLAGS: lib.LDFLAGS = LDFLAGS if lib.BUILD_MODE != "": f = lib["LDFLAGS_%s" % lib.BUILD_MODE] if f != None: lib.ADDED_LDFLAGS = "%s %s" % (lib.ADDED_LDFLAGS, f) if LIBS: post_inits.append(LibSolver(prog, LIBS)) if RPATH: prog.RPATH = RPATH todo.append(lib) std.ALL.append(lib) std.DISTCLEAN.append(lib) if is_cxx(sources): config.register(CONFIG_CXX) else: config.register(CONFIG_CC) if DYN_INSTALL_TO != None: lib.DYN_INSTALL_TO = DYN_INSTALL_TO install.dlib(lib) # build main goal lib = file(name) r = recipe.meta(lib, todo) recipe.add_alias(lib, name) lib.PROVIDE_PATH = lib.path.parent() lib.PROVIDE_LIB = name