From dd481a03fc4982202af15a850ea18696171ebe5f Mon Sep 17 00:00:00 2001 From: Ryan Leavengood Date: Wed, 13 Dec 2006 08:04:23 +0000 Subject: [PATCH] Added a few new rules that do some search and replacing using sed. AFAIK all our build platforms should have sed support (it is built into Jambase at least.) I use these rules to do some code generation in my soon to be committed MarkAs Tracker add-ons. This works pretty nifty if I do say so myself. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19481 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- build/jam/MiscRules | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/build/jam/MiscRules b/build/jam/MiscRules index 7b3d53242e..ce6a89e75f 100644 --- a/build/jam/MiscRules +++ b/build/jam/MiscRules @@ -76,3 +76,44 @@ rule MakeLocateDebug } } +rule SearchAndReplace +{ + # SearchAndReplace : : : + # A code generator that searches and replaces text in a source file to + # produce another. + # : The file (a source file) being created by this + # search and replace code generation. + # : The file being used to generate . + # : The string to search for in . + # : The string to replace with in the new file. + # + # For example usage see the MarkAs Tracker add-on code. + # + local _new_file = [ FGristSourceFiles $(1) ] ; + Depends all : $(_new_file) ; + Depends $(_new_file) : $(2) ; + MakeLocate $(_new_file) : $(LOCATE_SOURCE) ; + SEARCH on $(_new_file) = $(LOCATE_SOURCE) ; + Sed $(_new_file) : $(2) -e s/$(3)/$(4)/g ; + Clean clean : $(_new_file) ; +} + +rule Sed +{ + # Sed : + # : The file (a source file) being created by this + # sed run. + # : The parameters to sed in a list. The first item is + # the source file being searched through, the rest + # are standard sed parameters. + + # We don't care about the parameters to sed + NoCare $(2[2-]) ; + NotFile $(2[2-]) ; +} + +actions Sed +{ + $(SED) $(2[2-]) $(2[1]) > $(1) +} +