summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-09-27 19:18:32 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-09-27 19:18:32 +0200
commitcede34ad1ac6730f5f2c88b4dd655f90589ae803 (patch)
tree37a35f45833fc4ffb71f643c07d8828b9b329e01 /examples
parentc2b7e8a5a7bc98bcf5e03b32eefaa664442c26fe (diff)
Add a hello world example
Diffstat (limited to 'examples')
-rw-r--r--examples/hello/driver.cxx41
-rw-r--r--examples/hello/hello.cli8
-rw-r--r--examples/hello/makefile63
-rw-r--r--examples/makefile18
4 files changed, 130 insertions, 0 deletions
diff --git a/examples/hello/driver.cxx b/examples/hello/driver.cxx
new file mode 100644
index 0000000..c211601
--- /dev/null
+++ b/examples/hello/driver.cxx
@@ -0,0 +1,41 @@
+// file : examples/hello/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <iostream>
+
+#include "hello.hxx"
+
+using namespace std;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ int end; // End of options.
+ options o (argc, argv, end);
+
+ if (o.help ())
+ {
+ cerr << "hello v. 1.0.0" << endl;
+ return 0;
+ }
+
+ for (int i = end; i < argc; i++)
+ {
+ cout << o.greeting () << ", " << argv[i];
+
+ for (unsigned int j = 0; j < o.exclamations (); j++)
+ cout << '!';
+
+ cout << endl;
+ }
+ }
+ catch (const cli::exception& e)
+ {
+ cerr << e << endl;
+ return 1;
+ }
+}
diff --git a/examples/hello/hello.cli b/examples/hello/hello.cli
new file mode 100644
index 0000000..9907510
--- /dev/null
+++ b/examples/hello/hello.cli
@@ -0,0 +1,8 @@
+include <string>;
+
+class options
+{
+ bool --help;
+ std::string --greeting = "Hello";
+ unsigned int --exclamations = 1;
+};
diff --git a/examples/hello/makefile b/examples/hello/makefile
new file mode 100644
index 0000000..a162d0d
--- /dev/null
+++ b/examples/hello/makefile
@@ -0,0 +1,63 @@
+# file : examples/hello/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2009 Code Synthesis Tools CC
+# license : MIT; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
+
+cli := hello.cli
+cxx := driver.cxx
+
+obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(cli:.cli=.o))
+dep := $(obj:.o=.o.d)
+
+driver := $(out_base)/driver
+clean := $(out_base)/.clean
+
+# Build.
+#
+$(driver): $(obj)
+
+$(obj) $(dep): cpp_options := -I$(out_base)
+
+genf := $(cli:.cli=.hxx) $(cli:.cli=.ixx) $(cli:.cli=.cxx)
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): cli := $(out_root)/cli/cli
+$(gen): $(out_root)/cli/cli
+
+$(call include-dep,$(dep))
+
+# Convenience alias for default target.
+#
+$(out_base)/: $(driver)
+
+# Clean.
+#
+$(clean): $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(obj)) \
+ $(addsuffix .cxx.clean,$(dep)) \
+ $(addprefix $(out_base)/,$(cli:.cli=.cxx.cli.clean))
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(gen): | $(out_base)/.gitignore
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver $(genf)
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+# How to.
+#
+$(call include,$(bld_root)/cxx/o-e.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(scf_root)/cli/cli-cxx.make)
+
+# Dependencies.
+#
+$(call import,$(src_root)/cli/makefile)
diff --git a/examples/makefile b/examples/makefile
new file mode 100644
index 0000000..31a72b7
--- /dev/null
+++ b/examples/makefile
@@ -0,0 +1,18 @@
+# file : examples/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2009 Code Synthesis Tools CC
+# license : MIT; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make
+
+examples := hello
+
+default := $(out_base)/
+clean := $(out_base)/.clean
+
+.PHONY: $(default) $(clean)
+
+$(default): $(addprefix $(out_base)/,$(addsuffix /,$(examples)))
+$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(examples)))
+
+$(foreach e,$(examples),$(call import,$(src_base)/$e/makefile))