Skip to content

Instantly share code, notes, and snippets.

@vmrob
Last active September 22, 2015 02:55
Show Gist options
  • Save vmrob/6e0e91e89ef9cff329a0 to your computer and use it in GitHub Desktop.
Save vmrob/6e0e91e89ef9cff329a0 to your computer and use it in GitHub Desktop.
needy b2
#################
# Needy toolset
#################
import type ;
import feature ;
import toolset ;
import generators ;
type.register NEEDSFILE : json ;
generators.register-standard satisfy_static : NEEDSFILE : STATIC_LIB ;
# Feature types
feature.feature needylib : : free ;
feature.feature needycmd : : free path ;
feature.feature libdir : : free path ;
feature.feature builddir : : free path ;
# Flags for the satisfy_static rule
toolset.flags $(__name__).satisfy_static NEEDY_LIB <needylib> ;
toolset.flags $(__name__).satisfy_static COMMAND <needycmd> ;
toolset.flags $(__name__).satisfy_static LIB_DIR <libdir> ;
toolset.flags $(__name__).satisfy_static BUILD_DIR <builddir> ;
rule satisfy_static ( target : extra-sources * : requirements * : default-build * : usage-requirements * )
{
# Specify some default values
local libdir = [ on $(target) return $(LIB_DIR) ] ;
local needylib = [ on $(target) return $(NEEDY_LIB) ] ;
local needycmd = [ on $(target) return $(COMMAND) ] ;
libdir = $(libdir:E=.) ;
needylib = $(needylib:E=target) ;
needycmd = $(needycmd:E=needy) ;
local needy_build_dir = [ SHELL "cd $(libdir) && $(needycmd) builddir $(needylib)" ] ;
local builddir = [ on $(target) return $(BUILD_DIR:E=$(needy_build_dir)) ] ;
# Apply potentially new values to the target
NEEDY_LIB on $(target) = $(needylib) ;
LIB_DIR on $(target) = $(libdir) ;
COMMAND on $(target) = $(needycmd) ;
BUILD_DIR on $(target) = $(builddir) ;
}
actions satisfy_static bind COMMAND NEEDY_LIB
{
cd `dirname $(>)`
$(COMMAND) satisfy $(NEEDY_LIB)
}
# Flags for the needylib rule
toolset.flags $(__name__).needylib NEEDY_LIB <needylib> ;
toolset.flags $(__name__).needylib COMMAND <needycmd> ;
toolset.flags $(__name__).needylib LIB_DIR <libdir> ;
toolset.flags $(__name__).needylib BUILD_DIR <builddir> ;
rule needylib ( target : requirements * : usage-requirements * )
{
local libdir = [ MATCH <libdir>(.*) : $(requirements) ] ;
local needylib = [ MATCH <needylib>(.*) : $(requirements) ] ;
local needycmd = [ MATCH <needycmd>(.*) : $(requirements) ] ;
libdir = $(libdir:E=.) ;
needylib = $(needylib:E=target) ;
needycmd = $(needycmd:E=needy) ;
local builddir = [ SHELL "cd $(libdir) && $(needycmd) builddir $(needylib)" ] ;
local static_lib_file = "$(builddir)/lib/lib$(target).a" ;
make $(static_lib_file) : $(libdir)/needs.json : @$(__name__).satisfy_static : $(requirements) : $(usage-requirements) ;
lib $(target)
: # no extra sources (built by needy)
: <file>$(static_lib_file) $(requirements)
: # no default build (built by needy)
: <include>$(builddir)/include $(usage-requirements)
;
}
#############
# Usage #
#############
# import needy ;
#
# path-constant LIBSDIR : libs ;
# path-constant NEEDYCMD : needy/scripts/needy ;
#
# needy.needylib boost_system : <needylib>boost <needycmd>$(NEEDYCMD) <libdir>$(LIBSDIR) ;
# needy.needylib boost_thread : <needylib>boost <needycmd>$(NEEDYCMD) <libdir>$(LIBSDIR) ;
# needy.needylib boost_coroutine : <needylib>boost <needycmd>$(NEEDYCMD) <libdir>$(LIBSDIR) ;
# needy.needylib boost_context : <needylib>boost <needycmd>$(NEEDYCMD) <libdir>$(LIBSDIR) ;
# needy.needylib boost_filesystem : <needylib>boost <needycmd>$(NEEDYCMD) <libdir>$(LIBSDIR) ;
# needy.needylib ssl : <needylib>openssl <needycmd>$(NEEDYCMD) <libdir>$(LIBSDIR) ;
# needy.needylib crypto : <needylib>openssl <needycmd>$(NEEDYCMD) <libdir>$(LIBSDIR) ;
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment