From cede34ad1ac6730f5f2c88b4dd655f90589ae803 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 27 Sep 2009 19:18:32 +0200 Subject: Add a hello world example --- examples/hello/driver.cxx | 41 ++++++++++++++++++++++++++++++ examples/hello/hello.cli | 8 ++++++ examples/hello/makefile | 63 +++++++++++++++++++++++++++++++++++++++++++++++ examples/makefile | 18 ++++++++++++++ 4 files changed, 130 insertions(+) create mode 100644 examples/hello/driver.cxx create mode 100644 examples/hello/hello.cli create mode 100644 examples/hello/makefile create mode 100644 examples/makefile (limited to 'examples') 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 +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include + +#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 ; + +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 +# 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 +# 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)) -- cgit v1.1