From 1c2eaae8b3a52b099c613cd0e64baa84b69d51b5 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Sun, 27 Sep 2009 18:35:38 +0300 Subject: [PATCH] Created container.h and added more comprehensive hello world Added a per-container container.h that inclues useful definitions. Hello world now is in a separate file not to modify main too often. hello world now prints container name and id. --- conts/test/hello.c | 13 +++++++++++++ conts/test/main.c | 5 ++++- scripts/bare/bare_generator.py | 14 ++++++++++++++ scripts/bare/files/container.h.in | 13 +++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 conts/test/hello.c create mode 100644 scripts/bare/files/container.h.in diff --git a/conts/test/hello.c b/conts/test/hello.c new file mode 100644 index 0000000..054adc9 --- /dev/null +++ b/conts/test/hello.c @@ -0,0 +1,13 @@ +/* + * Autogenerated hello world print function + */ + +#include +#include + +int print_hello_world(void) +{ + printf("%s: Hello world from %s!\n", __CONTAINER__, __CONTAINER_NAME__); + return 0; +} + diff --git a/conts/test/main.c b/conts/test/main.c index 6de1dce..d2d8ed6 100644 --- a/conts/test/main.c +++ b/conts/test/main.c @@ -5,9 +5,12 @@ #include #include +extern int print_hello_world(void); + int main(void) { - printf("Hello World!\n"); + print_hello_world(); + return 0; } diff --git a/scripts/bare/bare_generator.py b/scripts/bare/bare_generator.py index a19b708..df4112e 100755 --- a/scripts/bare/bare_generator.py +++ b/scripts/bare/bare_generator.py @@ -32,12 +32,15 @@ class BareContGenerator: self.build_readme_in = join(SCRIPTROOT, 'files/build.readme.in') self.build_desc_in = join(SCRIPTROOT, 'files/container.desc.in') self.linker_lds_in = join(SCRIPTROOT, 'files/linker.lds.in') + self.container_h_in = join(SCRIPTROOT, 'files/container.h.in') self.build_script_name = 'SConstruct' self.build_readme_name = 'build.readme' self.build_desc_name = '.container' self.linker_lds_name = 'linker.lds' + self.container_h_name = 'container.h' + self.container_h_out = None self.build_script_out = None self.build_readme_out = None self.build_desc_out = None @@ -89,15 +92,24 @@ class BareContGenerator: self.main_configurator_name, \ self.main_configurator_name)) + def copy_bare_container_h(self, config, cont): + with open(self.container_h_in) as fin: + str = fin.read() + with open(self.container_h_out, 'w+') as fout: + # Make any manipulations here + fout.write(str % (cont.name, cont.id, cont.id)) + def create_bare_sources(self, config, cont): self.create_bare_srctree(config, cont) self.copy_bare_build_readme(config, cont) self.copy_bare_build_desc(config, cont) self.generate_linker_script(config, cont) + self.copy_bare_container_h(config, cont) def update_configuration(self, config, cont): self.copy_bare_build_desc(config, cont) self.generate_linker_script(config, cont) + self.copy_bare_container_h(config, cont) def check_create_bare_sources(self, config): for cont in config.containers: @@ -108,6 +120,8 @@ class BareContGenerator: self.build_desc_out = join(self.CONT_SRC_DIR, self.build_desc_name) self.linker_lds_out = join(join(self.CONT_SRC_DIR, 'include'), \ self.linker_lds_name) + self.container_h_out = join(join(self.CONT_SRC_DIR, 'include'), \ + self.container_h_name) if not os.path.exists(join(self.BARE_SRC_BASEDIR, cont.dirname)): self.create_bare_sources(config, cont) diff --git a/scripts/bare/files/container.h.in b/scripts/bare/files/container.h.in new file mode 100644 index 0000000..5015fd6 --- /dev/null +++ b/scripts/bare/files/container.h.in @@ -0,0 +1,13 @@ +/* + * Autogenerated definitions for this container. + */ +#ifndef __CONTAINER_H__ +#define __CONTAINER_H__ + + +#define __CONTAINER_NAME__ "%s" +#define __CONTAINER_ID__ %d +#define __CONTAINER__ "cont%d" + + +#endif /* __CONTAINER_H__ */