summaryrefslogtreecommitdiffstats
path: root/src/boost/tools/build/example/customization
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/tools/build/example/customization')
-rw-r--r--src/boost/tools/build/example/customization/class.verbatim7
-rw-r--r--src/boost/tools/build/example/customization/codegen.cpp36
-rw-r--r--src/boost/tools/build/example/customization/inline_file.py44
-rw-r--r--src/boost/tools/build/example/customization/jamroot.jam9
-rw-r--r--src/boost/tools/build/example/customization/readme.txt11
-rw-r--r--src/boost/tools/build/example/customization/t1.verbatim2
-rw-r--r--src/boost/tools/build/example/customization/t2.verbatim0
-rw-r--r--src/boost/tools/build/example/customization/usage.verbatim5
-rw-r--r--src/boost/tools/build/example/customization/verbatim.jam61
-rw-r--r--src/boost/tools/build/example/customization/verbatim.py47
10 files changed, 222 insertions, 0 deletions
diff --git a/src/boost/tools/build/example/customization/class.verbatim b/src/boost/tools/build/example/customization/class.verbatim
new file mode 100644
index 000000000..5c0d7b803
--- /dev/null
+++ b/src/boost/tools/build/example/customization/class.verbatim
@@ -0,0 +1,7 @@
+class_template
+
+class %class_name% {
+public:
+ %class_name%() {}
+ ~%class_name%() {}
+}; \ No newline at end of file
diff --git a/src/boost/tools/build/example/customization/codegen.cpp b/src/boost/tools/build/example/customization/codegen.cpp
new file mode 100644
index 000000000..2c632e2d1
--- /dev/null
+++ b/src/boost/tools/build/example/customization/codegen.cpp
@@ -0,0 +1,36 @@
+// (C) Copyright Vladimir Prus, 2003
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE.txt or copy at
+// https://www.bfgroup.xyz/b2/LICENSE.txt)
+
+// Please see 'usage.verbatim' file for usage notes.
+
+#include <iostream>
+#include <string>
+#include <cstring>
+using std::cout;
+using std::string;
+using std::strlen;
+
+extern const char class_template[];
+extern const char usage[];
+
+int main(int ac, char* av[])
+{
+ if (av[1]) {
+
+ string class_name = av[1];
+ string s = class_template;
+
+ string::size_type n;
+ while((n = s.find("%class_name%")) != string::npos) {
+ s.replace(n, strlen("%class_name%"), class_name);
+ }
+ std::cout << "Output is:\n";
+ std::cout << s << "\n";
+ return 0;
+ } else {
+ std::cout << usage << "\n";
+ return 1;
+ }
+}
diff --git a/src/boost/tools/build/example/customization/inline_file.py b/src/boost/tools/build/example/customization/inline_file.py
new file mode 100644
index 000000000..77cd8cb29
--- /dev/null
+++ b/src/boost/tools/build/example/customization/inline_file.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+
+# Copyright 2003 Vladimir Prus
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
+
+import sys
+from string import strip
+
+def quote_line(line):
+
+ result = ""
+
+ for i in line:
+ if (i == '\\'):
+ result = result + '\\\\'
+ elif (i == '\"'):
+ result = result + '\\\"'
+ elif (i != '\r' and i != '\n'):
+ result = result + i;
+
+ return '\"' + result + '\\n\"'
+
+def quote_file(file):
+ result = ""
+
+ for i in file.readlines():
+ result = result + quote_line(i) + "\n"
+
+ return result
+
+if len(sys.argv) < 3:
+ print "Usage: inline_file.py output_c_file file_to_include"
+else:
+ output_c_file = sys.argv[1]
+ out_file = open(output_c_file, "w");
+
+ file_to_include = sys.argv[2]
+
+ in_file = open(file_to_include, "r");
+ variable_name = strip(in_file.readline())
+ out_file.write("extern const char %s[] = {\n%s};\n\n" % (variable_name, quote_file(in_file)))
+ in_file.close()
+ out_file.close()
diff --git a/src/boost/tools/build/example/customization/jamroot.jam b/src/boost/tools/build/example/customization/jamroot.jam
new file mode 100644
index 000000000..3568213c7
--- /dev/null
+++ b/src/boost/tools/build/example/customization/jamroot.jam
@@ -0,0 +1,9 @@
+# Copyright 2003 Vladimir Prus
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
+
+import verbatim ;
+
+exe codegen : codegen.cpp class.verbatim usage.verbatim
+ t1.verbatim ;
+
diff --git a/src/boost/tools/build/example/customization/readme.txt b/src/boost/tools/build/example/customization/readme.txt
new file mode 100644
index 000000000..6a799277a
--- /dev/null
+++ b/src/boost/tools/build/example/customization/readme.txt
@@ -0,0 +1,11 @@
+Copyright 2003 Vladimir Prus
+Distributed under the Boost Software License, Version 1.0.
+(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+
+
+This example show how to add a new target type and a new tool support to
+B2. Please refer to extender manual for a complete description of this
+example.
+
+Note that this example requires Python. If cygwin Python on Windows is to be
+used, please go to "verbatim.jam" and follow instructions there.
diff --git a/src/boost/tools/build/example/customization/t1.verbatim b/src/boost/tools/build/example/customization/t1.verbatim
new file mode 100644
index 000000000..144540f29
--- /dev/null
+++ b/src/boost/tools/build/example/customization/t1.verbatim
@@ -0,0 +1,2 @@
+t1
+//###include "t2.verbatim" \ No newline at end of file
diff --git a/src/boost/tools/build/example/customization/t2.verbatim b/src/boost/tools/build/example/customization/t2.verbatim
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/boost/tools/build/example/customization/t2.verbatim
diff --git a/src/boost/tools/build/example/customization/usage.verbatim b/src/boost/tools/build/example/customization/usage.verbatim
new file mode 100644
index 000000000..0fc4b4a37
--- /dev/null
+++ b/src/boost/tools/build/example/customization/usage.verbatim
@@ -0,0 +1,5 @@
+usage
+Usage: codegen class_name
+
+This program takes a template of C++ code and replaces of all occurrences of
+%class_name% with the passed 'class_name' parameter. \ No newline at end of file
diff --git a/src/boost/tools/build/example/customization/verbatim.jam b/src/boost/tools/build/example/customization/verbatim.jam
new file mode 100644
index 000000000..c529845df
--- /dev/null
+++ b/src/boost/tools/build/example/customization/verbatim.jam
@@ -0,0 +1,61 @@
+# Copyright 2003, 2004 Vladimir Prus
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
+
+# This file shows some of the primary customization mechanisms in B2 V2
+# and should serve as a basic for your own customization.
+# Each part has a comment describing its purpose, and you can pick the parts
+# which are relevant to your case, remove everything else, and then change names
+# and actions to taste.
+
+import os ;
+
+# Declare a new target type. This allows B2 to do something sensible
+# when targets with the .verbatim extension are found in sources.
+import type ;
+type.register VERBATIM : verbatim ;
+
+# Declare a dependency scanner for the new target type. The
+# 'inline-file.py' script does not handle includes, so this is
+# only for illustraction.
+import scanner ;
+# First, define a new class, derived from 'common-scanner',
+# that class has all the interesting logic, and we only need
+# to override the 'pattern' method which return regular
+# expression to use when scanning.
+class verbatim-scanner : common-scanner
+{
+ rule pattern ( )
+ {
+ return "//###include[ ]*\"([^\"]*)\"" ;
+ }
+}
+
+# Register the scanner class. The 'include' is
+# the property which specifies the search path
+# for includes.
+scanner.register verbatim-scanner : include ;
+# Assign the scanner class to the target type.
+# Now, all .verbatim sources will be scanned.
+# To test this, build the project, touch the
+# t2.verbatim file and build again.
+type.set-scanner VERBATIM : verbatim-scanner ;
+
+import generators ;
+generators.register-standard verbatim.inline-file : VERBATIM : CPP ;
+
+# Note: To use Cygwin Python on Windows change the following line
+# to "python inline_file.py $(<) $(>)"
+# Also, make sure that "python" in in PATH.
+actions inline-file
+{
+ "./inline_file.py" $(<) $(>)
+}
+
+if [ os.name ] = VMS
+{
+ actions inline-file
+ {
+ python inline_file.py $(<:W) $(>:W)
+ }
+}
diff --git a/src/boost/tools/build/example/customization/verbatim.py b/src/boost/tools/build/example/customization/verbatim.py
new file mode 100644
index 000000000..996577054
--- /dev/null
+++ b/src/boost/tools/build/example/customization/verbatim.py
@@ -0,0 +1,47 @@
+# Copyright 2010 Vladimir Prus
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
+
+# This file is only used with Python port of Boost.Build
+
+# This file shows some of the primary customization mechanisms in Boost.Build V2
+# and should serve as a basic for your own customization.
+# Each part has a comment describing its purpose, and you can pick the parts
+# which are relevant to your case, remove everything else, and then change names
+# and actions to taste.
+
+# Declare a new target type. This allows Boost.Build to do something sensible
+# when targets with the .verbatim extension are found in sources.
+import b2.build.type as type
+type.register("VERBATIM", ["verbatim"])
+
+# Declare a dependency scanner for the new target type. The
+# 'inline-file.py' script does not handle includes, so this is
+# only for illustraction.
+import b2.build.scanner as scanner;
+# First, define a new class, derived from 'common-scanner',
+# that class has all the interesting logic, and we only need
+# to override the 'pattern' method which return regular
+# expression to use when scanning.
+class VerbatimScanner(scanner.CommonScanner):
+
+ def pattern(self):
+ return "//###include[ ]*\"([^\"]*)\""
+
+scanner.register(VerbatimScanner, ["include"])
+type.set_scanner("VERBATIM", VerbatimScanner)
+
+import b2.build.generators as generators
+
+generators.register_standard("verbatim.inline-file",
+ ["VERBATIM"], ["CPP"])
+
+from b2.manager import get_manager
+
+get_manager().engine().register_action("verbatim.inline-file",
+"""
+./inline_file.py $(<) $(>)
+""")
+
+
+