Skip to content

Commit

Permalink
feat(appgen): Add native app template
Browse files Browse the repository at this point in the history
Closes: #235
Approved by: jmcadden
  • Loading branch information
jimcadden authored and BetsyRT committed Jan 25, 2018
1 parent 2b4d2ee commit 91b1301
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 14 deletions.
29 changes: 15 additions & 14 deletions contrib/appgen/appgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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"
File renamed without changes.
20 changes: 20 additions & 0 deletions contrib/appgen/template/native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
68 changes: 68 additions & 0 deletions contrib/appgen/template/native/Makefile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions contrib/appgen/template/native/src/title.cc
Original file line number Diff line number Diff line change
@@ -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 <ebbrt/Debug.h>

void AppMain() { ebbrt::kprintf_force("{{ CAP_TITLE }} BACKEND UP.\n"); }

0 comments on commit 91b1301

Please sign in to comment.