diff --git a/README.md b/README.md index 9834823862..336d35b60c 100644 --- a/README.md +++ b/README.md @@ -97,13 +97,13 @@ More information is [available on the wiki](https://github.com/hioa-cs/IncludeOS ### Writing your first service -1. Copy the [./seed](./seed) directory to a convenient location like `~/your_service`. Then, just start implementing the `Service::start` function in the `Service` class, located in [your_service/service.cpp](./seed/service.cpp) (Very simple example provided). This function will be called once the OS is up and running. -2. Update the [CMakeLists.txt](./seed/CMakeLists.txt) to specify the name of your project, enable any needed drivers or plugins, etc. +1. Copy the [./seed/service](./seed/service) directory to a convenient location like `~/your_service`. Then, just start implementing the `Service::start` function in the `Service` class, located in [your_service/service.cpp](./seed/service/service.cpp) (Very simple example provided). This function will be called once the OS is up and running. +2. Update the [CMakeLists.txt](./seed/service/CMakeLists.txt) to specify the name of your project, enable any needed drivers or plugins, etc. **Example:** ``` - $ cp -r seed ~/my_service + $ cp -r seed/service ~/my_service $ cd ~/my_service $ emacs service.cpp ... add your code diff --git a/etc/library.cmake b/etc/library.cmake index 2452a87354..d22ea8b582 100644 --- a/etc/library.cmake +++ b/etc/library.cmake @@ -1,7 +1,12 @@ # -# +# CMakeList for IncludeOS library # +# IncludeOS install location +if (NOT DEFINED ENV{INCLUDEOS_PREFIX}) + set(ENV{INCLUDEOS_PREFIX} /usr/local) +endif() + # test compiler if(CMAKE_COMPILER_IS_GNUCC) # currently gcc is not supported due to problems cross-compiling a unikernel @@ -12,14 +17,10 @@ endif(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_ASM_NASM_OBJECT_FORMAT "elf") enable_language(ASM_NASM) -# stackrealign is needed to guarantee 16-byte stack alignment for SSE -# the compiler seems to be really dumb in this regard, creating a misaligned stack left and right -set(CAPABS "-mstackrealign -msse3 -fstack-protector-strong") - # Various global defines # * OS_TERMINATE_ON_CONTRACT_VIOLATION provides classic assert-like output from Expects / Ensures # * _GNU_SOURCE enables POSIX-extensions in newlib, such as strnlen. ("everything newlib has", ref. cdefs.h) -set(CAPABS "${CAPABS} -DOS_TERMINATE_ON_CONTRACT_VIOLATION -D_GNU_SOURCE -DSERVICE=\"\\\"${BINARY}\\\"\" -DSERVICE_NAME=\"\\\"${SERVICE_NAME}\\\"\"") +set(CAPABS "-msse3 -fstack-protector-strong -DOS_TERMINATE_ON_CONTRACT_VIOLATION -D_GNU_SOURCE") set(WARNS "-Wall -Wextra") #-pedantic # configure options @@ -32,23 +33,24 @@ if (minimal) set(OPTIMIZE "-Os") endif() if (debug) - set(CAPABS "${CAPABS} -g" + set(CAPABS "${CAPABS} -g") endif() # these kinda work with llvm set(CMAKE_CXX_FLAGS "-MMD -target i686-elf ${CAPABS} ${OPTIMIZE} ${WARNS} -c -m32 -std=c++14 -D_LIBCPP_HAS_NO_THREADS=1") set(CMAKE_C_FLAGS "-MMD -target i686-elf ${CAPABS} ${OPTIMIZE} ${WARNS} -c -m32") - # includes include_directories(${LOCAL_INCLUDES}) -include_directories(${INCLUDEOS_ROOT}/include/libcxx) -include_directories(${INCLUDEOS_ROOT}/include/api/sys) -include_directories(${INCLUDEOS_ROOT}/include/newlib) -include_directories(${INCLUDEOS_ROOT}/include/api/posix) -include_directories(${INCLUDEOS_ROOT}/include/api) -include_directories(${INCLUDEOS_ROOT}/include/gsl) - -# output <- input -add_library(library STATIC ${SOURCES}) -set_target_properties(library PROPERTIES OUTPUT_NAME ${LIBRARY_NAME}) +include_directories($ENV{INCLUDEOS_PREFIX}/includeos/include/libcxx) +include_directories($ENV{INCLUDEOS_PREFIX}/includeos/api/sys) +include_directories($ENV{INCLUDEOS_PREFIX}/includeos/include/newlib) +include_directories($ENV{INCLUDEOS_PREFIX}/includeos/api/posix) +include_directories($ENV{INCLUDEOS_PREFIX}/includeos/api) +include_directories($ENV{INCLUDEOS_PREFIX}/includeos/include) +include_directories($ENV{INCLUDEOS_PREFIX}/include) + +add_library(${LIBRARY_NAME} STATIC ${SOURCES}) + +#install(TARGETS ${LIBRARY_NAME} DESTINATION includeos/lib) +#install(DIRECTORY ${LIBRARY_HEADERS} DESTINATION includeos/include) diff --git a/seed/.gitignore b/seed/.gitignore deleted file mode 100644 index c6079b4532..0000000000 --- a/seed/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.o -*.d -*.img -_elf_symbols.bin diff --git a/seed/debug/service.gdb b/seed/debug/service.gdb deleted file mode 100644 index f5acb4ff3c..0000000000 --- a/seed/debug/service.gdb +++ /dev/null @@ -1,5 +0,0 @@ -file service -break _start -break OS::start -set non-stop off -target remote localhost:1234 \ No newline at end of file diff --git a/seed/library/.gitignore b/seed/library/.gitignore new file mode 100644 index 0000000000..d2e6ee39e8 --- /dev/null +++ b/seed/library/.gitignore @@ -0,0 +1,2 @@ +build/* +lib/ diff --git a/seed/library/CMakeLists.txt b/seed/library/CMakeLists.txt new file mode 100644 index 0000000000..4cd6ffde4f --- /dev/null +++ b/seed/library/CMakeLists.txt @@ -0,0 +1,44 @@ +cmake_minimum_required(VERSION 2.8.9) + +# IncludeOS install location +if (NOT DEFINED ENV{INCLUDEOS_PREFIX}) + set(ENV{INCLUDEOS_PREFIX} /usr/local) +endif() + +# Use toolchain (if needed) +set(CMAKE_TOOLCHAIN_FILE $ENV{INCLUDEOS_PREFIX}/includeos/i686-elf-toolchain.cmake) + +# Name of your project +project (libseed) + +# Name of your IncludeOS library +set(LIBRARY_NAME "seed") # => libseed.a + +# Source files to be built into your IncludeOS library +set(SOURCES + # seed.cpp # ...add more here + ) + +# Necessary includes to build your library +set(LOCAL_INCLUDES + # "include" + ) + +# include library build script +include($ENV{INCLUDEOS_PREFIX}/includeos/library.cmake) + + +# INSTALLATION (OPTIONAL): + +# If CMAKE_INSTALL_PREFIX is not set, install to source directory +if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}") # $ENV{INCLUDEOS_PREFIX}/includeos +endif() + +# Where to install library +install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) + +# Where to install library headers +# NOTE: There is a difference between installing a list of files and a directory +# set(LIBRARY_HEADERS "include/seed") +# install(DIRECTORY ${LIBRARY_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include) diff --git a/seed/cmake_build.sh b/seed/library/cmake_build.sh similarity index 100% rename from seed/cmake_build.sh rename to seed/library/cmake_build.sh diff --git a/seed/run.sh b/seed/run.sh deleted file mode 100755 index 8b5ad911d8..0000000000 --- a/seed/run.sh +++ /dev/null @@ -1,8 +0,0 @@ -#! /bin/bash -set - -INCLUDEOS_PREFIX=${INCLUDEOS_PREFIX-/usr/local} -sudo $INCLUDEOS_PREFIX/includeos/scripts/create_bridge.sh - -FILE=$1 -shift -source $INCLUDEOS_PREFIX/includeos/scripts/run.sh $FILE ${*} diff --git a/seed/service/.gitignore b/seed/service/.gitignore new file mode 100644 index 0000000000..a007feab07 --- /dev/null +++ b/seed/service/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/seed/CMakeLists.txt b/seed/service/CMakeLists.txt similarity index 100% rename from seed/CMakeLists.txt rename to seed/service/CMakeLists.txt diff --git a/seed/service/cmake_build.sh b/seed/service/cmake_build.sh new file mode 100755 index 0000000000..9fdd05a8a0 --- /dev/null +++ b/seed/service/cmake_build.sh @@ -0,0 +1,7 @@ +#!/bin/bash +INSTALL=`pwd` +mkdir -p build +pushd build +cmake .. -DCMAKE_INSTALL_PREFIX:PATH=$INSTALL +make install +popd diff --git a/seed/docker_run.sh b/seed/service/docker_run.sh similarity index 100% rename from seed/docker_run.sh rename to seed/service/docker_run.sh diff --git a/seed/service.cpp b/seed/service/service.cpp similarity index 100% rename from seed/service.cpp rename to seed/service/service.cpp