From 91b13012711b238502053dfdca71dc1178a9243f Mon Sep 17 00:00:00 2001 From: Jim Cadden Date: Tue, 23 Jan 2018 16:24:46 -0500 Subject: [PATCH] feat(appgen): Add native app template Closes: #235 Approved by: jmcadden --- contrib/appgen/appgen.py | 29 ++++---- .../{helloworld => default}/CMakeLists.txt | 0 .../template/{helloworld => default}/Makefile | 0 .../cmake/FindCapnp.cmake | 0 .../cmake/FindTBB.cmake | 0 .../src/StaticEbbIds.h | 0 .../src/hosted/Printer.cc | 0 .../src/hosted/Printer.h | 0 .../src/hosted/title.cc | 0 .../src/native/Printer.cc | 0 .../src/native/Printer.h | 0 .../src/native/title.cc | 0 contrib/appgen/template/native/CMakeLists.txt | 20 ++++++ contrib/appgen/template/native/Makefile | 68 +++++++++++++++++++ contrib/appgen/template/native/src/title.cc | 8 +++ 15 files changed, 111 insertions(+), 14 deletions(-) rename contrib/appgen/template/{helloworld => default}/CMakeLists.txt (100%) rename contrib/appgen/template/{helloworld => default}/Makefile (100%) rename contrib/appgen/template/{helloworld => default}/cmake/FindCapnp.cmake (100%) rename contrib/appgen/template/{helloworld => default}/cmake/FindTBB.cmake (100%) rename contrib/appgen/template/{helloworld => default}/src/StaticEbbIds.h (100%) rename contrib/appgen/template/{helloworld => default}/src/hosted/Printer.cc (100%) rename contrib/appgen/template/{helloworld => default}/src/hosted/Printer.h (100%) rename contrib/appgen/template/{helloworld => default}/src/hosted/title.cc (100%) rename contrib/appgen/template/{helloworld => default}/src/native/Printer.cc (100%) rename contrib/appgen/template/{helloworld => default}/src/native/Printer.h (100%) rename contrib/appgen/template/{helloworld => default}/src/native/title.cc (100%) create mode 100644 contrib/appgen/template/native/CMakeLists.txt create mode 100644 contrib/appgen/template/native/Makefile create mode 100644 contrib/appgen/template/native/src/title.cc diff --git a/contrib/appgen/appgen.py b/contrib/appgen/appgen.py index 7d68e8ec..c0ce7f9b 100755 --- a/contrib/appgen/appgen.py +++ b/contrib/appgen/appgen.py @@ -2,24 +2,25 @@ from jinja2 import Environment, FileSystemLoader import os import sys +import argparse -print "Generate files new EbbRT application in the currect working \ -directory." -var = raw_input("Enter a name for the application \ -(one word, no spaces):\n> ").lower() +parser = argparse.ArgumentParser(description='Generate EbbRT application', + prog=sys.argv[0], usage='%(prog)s [options]') +parser.add_argument('-n', metavar="NAME", default="app", help='new application name') +parser.add_argument('-t', default="default", choices=['default', 'native'], help='application template') +args = parser.parse_args() -# Capture our current directory -THIS_DIR = os.path.dirname(os.path.abspath(__file__)) -CONTEXT = { "title" : var, "CAP_TITLE": var.upper() } -target_path = os.path.join(os.getcwd(), var) -source_path = os.path.join(THIS_DIR, "template/helloworld") +template = args.t +appname = args.n + +# Capture the script (source) directory +source_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "template/"+template) +target_path = os.getcwd() +CONTEXT = { "title" : appname, "CAP_TITLE": appname.upper() } def apply_template(source, target): if not os.path.exists(target): os.makedirs(target) - else: - print "Error, target directory already exists: "+target - sys.exit() print "Building new application: "+target #print "Using template: "+source for path,sd,files in os.walk(source): @@ -34,7 +35,7 @@ def apply_template(source, target): relative_path = os.path.join(relative_root, name) full_source_path = os.path.join(path, name) if name == "title.cc": - full_target_path = os.path.join(target_root, var+".cc") + full_target_path = os.path.join(target_root, appname+".cc") else: full_target_path = os.path.join(target_root, name) print "writing "+full_target_path @@ -49,4 +50,4 @@ def render_template(fs, filename, context): if __name__ == '__main__': apply_template(source_path, target_path) - print "Build finished." + print "New EbbRT application ("+appname+") generated in current working directory" diff --git a/contrib/appgen/template/helloworld/CMakeLists.txt b/contrib/appgen/template/default/CMakeLists.txt similarity index 100% rename from contrib/appgen/template/helloworld/CMakeLists.txt rename to contrib/appgen/template/default/CMakeLists.txt diff --git a/contrib/appgen/template/helloworld/Makefile b/contrib/appgen/template/default/Makefile similarity index 100% rename from contrib/appgen/template/helloworld/Makefile rename to contrib/appgen/template/default/Makefile diff --git a/contrib/appgen/template/helloworld/cmake/FindCapnp.cmake b/contrib/appgen/template/default/cmake/FindCapnp.cmake similarity index 100% rename from contrib/appgen/template/helloworld/cmake/FindCapnp.cmake rename to contrib/appgen/template/default/cmake/FindCapnp.cmake diff --git a/contrib/appgen/template/helloworld/cmake/FindTBB.cmake b/contrib/appgen/template/default/cmake/FindTBB.cmake similarity index 100% rename from contrib/appgen/template/helloworld/cmake/FindTBB.cmake rename to contrib/appgen/template/default/cmake/FindTBB.cmake diff --git a/contrib/appgen/template/helloworld/src/StaticEbbIds.h b/contrib/appgen/template/default/src/StaticEbbIds.h similarity index 100% rename from contrib/appgen/template/helloworld/src/StaticEbbIds.h rename to contrib/appgen/template/default/src/StaticEbbIds.h diff --git a/contrib/appgen/template/helloworld/src/hosted/Printer.cc b/contrib/appgen/template/default/src/hosted/Printer.cc similarity index 100% rename from contrib/appgen/template/helloworld/src/hosted/Printer.cc rename to contrib/appgen/template/default/src/hosted/Printer.cc diff --git a/contrib/appgen/template/helloworld/src/hosted/Printer.h b/contrib/appgen/template/default/src/hosted/Printer.h similarity index 100% rename from contrib/appgen/template/helloworld/src/hosted/Printer.h rename to contrib/appgen/template/default/src/hosted/Printer.h diff --git a/contrib/appgen/template/helloworld/src/hosted/title.cc b/contrib/appgen/template/default/src/hosted/title.cc similarity index 100% rename from contrib/appgen/template/helloworld/src/hosted/title.cc rename to contrib/appgen/template/default/src/hosted/title.cc diff --git a/contrib/appgen/template/helloworld/src/native/Printer.cc b/contrib/appgen/template/default/src/native/Printer.cc similarity index 100% rename from contrib/appgen/template/helloworld/src/native/Printer.cc rename to contrib/appgen/template/default/src/native/Printer.cc diff --git a/contrib/appgen/template/helloworld/src/native/Printer.h b/contrib/appgen/template/default/src/native/Printer.h similarity index 100% rename from contrib/appgen/template/helloworld/src/native/Printer.h rename to contrib/appgen/template/default/src/native/Printer.h diff --git a/contrib/appgen/template/helloworld/src/native/title.cc b/contrib/appgen/template/default/src/native/title.cc similarity index 100% rename from contrib/appgen/template/helloworld/src/native/title.cc rename to contrib/appgen/template/default/src/native/title.cc diff --git a/contrib/appgen/template/native/CMakeLists.txt b/contrib/appgen/template/native/CMakeLists.txt new file mode 100644 index 00000000..95ee4e81 --- /dev/null +++ b/contrib/appgen/template/native/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 2.6 FATAL_ERROR) +project("{{ title }}-ebbrt" C CXX) + +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") +set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") +set(CMAKE_CXX_FLAGS_RELEASE "-O4 -flto -DNDEBUG") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g3") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14 -Wall -Werror") +set(BAREMETAL_SOURCES src/{{ title }}.cc) + +if( ${CMAKE_SYSTEM_NAME} STREQUAL "EbbRT") + add_executable({{ title }}.elf ${BAREMETAL_SOURCES}) + add_custom_command(TARGET {{ title }}.elf POST_BUILD + COMMAND objcopy -O elf32-i386 {{ title }}.elf {{ title }}.elf32 ) + +# Hosted =========================================================== +elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" ) + message(FATAL_ERROR "System name unsupported: ${CMAKE_SYSTEM_NAME}") +endif() diff --git a/contrib/appgen/template/native/Makefile b/contrib/appgen/template/native/Makefile new file mode 100644 index 00000000..69cf831f --- /dev/null +++ b/contrib/appgen/template/native/Makefile @@ -0,0 +1,68 @@ +MYDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) + +CD ?= cd +CMAKE ?= cmake +CP ?= cp +ECHO ?= echo +MAKE ?= make +MKDIR ?= mkdir + +EBBRTSYSROOT ?= $(abspath $(EBBRT_SYSROOT)) +CMAKE_TOOLCHAIN_FILE ?= $(EBBRTSYSROOT)/usr/misc/ebbrt.cmake +BAREMETAL_PREFIX_PATH= $(EBBRTSYSROOT)/usr/ + +BUILD_PATH ?= $(MYDIR) +DEBUG_PATH ?= $(BUILD_PATH)/Debug +RELEASE_PATH ?= $(BUILD_PATH)/Release +BAREMETAL_DEBUG_DIR ?= $(DEBUG_PATH) +BAREMETAL_RELEASE_DIR ?= $(RELEASE_PATH) + +all: Debug Release +native: native-debug native-release +Debug: native-debug +Release: native-release + +# ENVIRONMENT VARIABLES +check-ebbrt-sysroot: +ifndef EBBRT_SYSROOT + $(error EBBRT_SYSROOT is undefined) +endif + +$(BUILD_PATH): + $(MKDIR) $@ + +$(DEBUG_PATH): | $(BUILD_PATH) + $(MKDIR) $@ + +$(RELEASE_PATH): | $(BUILD_PATH) + $(MKDIR) $@ + +ifneq ($(DEBUG_PATH), $(BAREMETAL_DEBUG_DIR)) +$(BAREMETAL_DEBUG_DIR): | $(DEBUG_PATH) + $(MKDIR) $@ +endif + +ifneq ($(RELEASE_PATH), $(BAREMETAL_RELEASE_DIR)) +$(BAREMETAL_RELEASE_DIR): | $(RELEASE_PATH) + $(MKDIR) $@ +endif + +native-debug: | check-ebbrt-sysroot $(BAREMETAL_DEBUG_DIR) + $(CD) $(BAREMETAL_DEBUG_DIR) && \ + EBBRT_SYSROOT=$(EBBRTSYSROOT) $(CMAKE) -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_PREFIX_PATH=$(BAREMETAL_PREFIX_PATH) \ + -DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN_FILE) $(MYDIR) && $(MAKE) + +native-release: | check-ebbrt-sysroot $(BAREMETAL_RELEASE_DIR) + $(CD) $(BAREMETAL_RELEASE_DIR) && \ + EBBRT_SYSROOT=$(EBBRTSYSROOT) $(CMAKE) -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_PREFIX_PATH=$(BAREMETAL_PREFIX_PATH) \ + -DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN_FILE) $(MYDIR) && \ + $(MAKE) + + +clean: + $(MAKE) clean -C $(BAREMETAL_DEBUG_DIR) && \ + $(MAKE) clean -C $(BAREMETAL_RELEASE_DIR) + +.PHONY: Debug Release all clean native native-debug native-release diff --git a/contrib/appgen/template/native/src/title.cc b/contrib/appgen/template/native/src/title.cc new file mode 100644 index 00000000..76178f5f --- /dev/null +++ b/contrib/appgen/template/native/src/title.cc @@ -0,0 +1,8 @@ +// Copyright Boston University SESA Group 2013 - 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include + +void AppMain() { ebbrt::kprintf_force("{{ CAP_TITLE }} BACKEND UP.\n"); }