import configure ; import feature ; import print ; import property ; import regex ; import sequence ; feature.feature config-define : : free ; local rule format-define ( macro-def ) { local args = [ regex.match "([^=]*)=(.*)" : $(macro-def) ] ; return "#define $(args[1]) $(args[2])" ; } rule create-config-header ( target : : properties * ) { local macros = [ property.select : $(properties) ] ; local include-guard = [ MD5 $(macros:J=) ] ; print.output $(target) ; print.text "#ifndef $(include-guard)" "#define $(include-guard)" [ sequence.transform format-define : $(macros:G=) ] "#endif" : overwrite ; } rule check-config-macro ( target name macro ) { return [ configure.check-target-builds $(target) $(name) : $(macro)=1 : $(macro)=0 ] ; } rule config-header ( target : requirements * ) { return [ make $(target) : : @create-config-header : $(requirements) ] ; } compile test.cpp ; explicit test ; config-header config.h : [ check-config-macro test "has test.h" HAS_TEST_H ] ;