Genode SDK

Makefile for generating a Genode SDK.

Fix #2948
This commit is contained in:
Emery Hemingway 2018-08-26 22:11:04 +02:00 committed by Christian Helmuth
parent 447329eaee
commit 918281b01f
9 changed files with 290 additions and 0 deletions

201
tool/create_sdk Executable file
View File

@ -0,0 +1,201 @@
#!/usr/bin/make --file
#
# \brief Create Genode software development kit
# \author Emery Hemingway
# \date 2018-08-26
#
MAKEOVERRIDES =
PLATFORM = $(MAKECMDGOALS)
PLATFORMS = x86_32 x86_64
VERBOSE ?= @
GENODE_DIR := $(realpath $(dir $(MAKEFILE_LIST))/..)
VERSION := $(strip $(shell cat $(GENODE_DIR)/VERSION))
DEFAULT_SDK_DIR_PREFIX := $(GENODE_DIR)/build/sdk
DEFAULT_DEPOT_USER = genodelabs
sdk_usage:
@echo
@echo "Tool for preparing a Genode SDK"
@echo
@echo "usage:"
@echo
@echo " create_sdk <platform> [SDK_DIR=<sdk-dir> DEPOT_USER=$(DEFAULT_DEPOT_USER)]"
@echo
@echo " <platform> can be:"
@$(foreach PLAT,$(PLATFORMS), \
echo " '$(PLAT)'";)
@echo
@echo " The definition of SDK_DIR is optional. If specified,"
@echo " <sdk-dir> is the location of the directory to create."
@echo " If not specified, the directory will be created at"
@echo " $(DEFAULT_SDK_DIR_PREFIX)-<platform>-$(VERSION)."
@echo
#
# Define default location of the build directory if not explicitly specified
#
SDK_DIR ?= $(DEFAULT_SDK_DIR_PREFIX)-$(PLATFORM)-$(VERSION)
DEPOT_USER ?= $(DEFAULT_DEPOT_USER)
TOOLCHAIN_DIR ?= /usr/local/genode-gcc
#
# Sanity checks
#
ifneq ($(PLATFORM),)
#
# Check if platform is unknown
#
ifeq ($(filter $(PLATFORM),$(PLATFORMS)),)
$(error Bad platform argument '$(PLATFORM)')
endif
#
# Check if build directory exists already
#
ifneq ($(wildcard $(SDK_DIR)),)
$(error SDK directory '$(SDK_DIR)' already exists)
endif
endif
#
# SPECS definitions
#
SPECS(x86_32) := x86 x86_32 32bit
SPECS(x86_64) := x86 x86_64 64bit
ifneq (${SPECS(${PLATFORM})},)
GENODE_API_PKG_NAMES = \
base so os \
audio_in_session \
audio_out_session \
block_session \
file_system_session \
framebuffer_session \
gpio_session \
gpu_session \
input_session \
nic_session \
nitpicker_session \
platform_session \
regulator_session \
report_session \
rtc_session \
terminal_session \
timer_session \
uart_session \
usb_session \
vfs \
CONTRIB_API_PKG_NAMES = \
libc \
stdcxx \
SDK_BIN_PKG_NAME = \
base-linux \
vfs \
libc \
posix \
stdcxx \
include $(GENODE_DIR)/tool/depot/mk/front_end.inc
depot_api_pkg = $(DEPOT_DIR)/$(DEPOT_USER)/api/$(1)/$(call recipe_version,api/$(1))
GENODE_API_PKGS := $(foreach PKG,$(GENODE_API_PKG_NAMES),$(call depot_api_pkg,$(PKG)))
CONTRIB_API_PKGS := $(foreach PKG,$(CONTRIB_API_PKG_NAMES),$(call depot_api_pkg,$(PKG)))
BIN_PKGS := $(foreach X, $(SDK_BIN_PKG_NAME), \
$(X)/$(call recipe_version,src/$(X)))
DEPOT_BIN_PKGS := $(foreach X, $(BIN_PKGS), \
$(DEPOT_DIR)/$(DEPOT_USER)/bin/$(PLATFORM)/$(X))
USER_SRC_NAME_VERSIONS := $(foreach X, $(BIN_PKGS), \
$(DEPOT_USER)/src/$(X))
LINK_SCRIPTS = genode_dyn.dl genode_dyn.ld genode_rel.ld
SDK_LINK_SCRIPTS := $(addprefix $(SDK_DIR)/ld/,$(LINK_SCRIPTS))
PKGCONFIG_INS := $(wildcard $(GENODE_DIR)/tool/sdk/*.pc.in)
SDK_PKGCONFIGS := $(patsubst %.pc.in,$(SDK_DIR)/pkgconfig/%.pc,$(notdir $(PKGCONFIG_INS)))
$(SDK_DIR)/pkgconfig/%.pc: $(GENODE_DIR)/tool/sdk/%.pc.in
$(VERBOSE)mkdir -p $(dir $@)
$(VERBOSE)sed \
-e 's|!SDK_DIR!|$(SDK_DIR)|' \
-e 's|!TOOLCHAIN_DIR!|$(TOOLCHAIN_DIR)|' \
-e 's|!VERSION!|$(VERSION)|' \
< $< > $@
message: \
$(SDK_DIR) \
$(SDK_DIR)/archives \
$(SDK_DIR)/include \
$(SDK_DIR)/lib \
$(SDK_DIR)/lib/ldso-startup.lib.a \
$(SDK_LINK_SCRIPTS) \
$(SDK_PKGCONFIGS) \
$(SDK_DIR)/archives:
$(VERBOSE)for pkg in $(USER_SRC_NAME_VERSIONS); do echo $$pkg >> $@; done
# Rule to create all depot packages first
$(SDK_DIR): $(GENODE_API_PKGS) $(CONTRIB_API_PKGS) $(DEPOT_BIN_PKGS)
$(VERBOSE)mkdir --parents $@
$(SDK_LINK_SCRIPTS): $(addprefix $(GENODE_DIR)/repos/base/src/ld/,$(LINK_SCRIPTS))
$(VERBOSE)mkdir --parents $(dir $@)
$(VERBOSE)cp $^ $(dir $@)
api_pkg_includes = \
$(filter-out $(1)/include/spec,$(wildcard $(1)/include/*)) \
$(foreach SPEC,${SPECS(${PLATFORM})},$(wildcard $(1)/include/spec/$(SPEC)/*)) \
cp_includes = \
mkdir $(SDK_DIR)/include/$(1); \
cp --recursive $(call api_pkg_includes,$(call depot_api_pkg,$(1))) $(SDK_DIR)/include/$(1);
GENODE_INCLUDES := $(foreach PKG,$(GENODE_API_PKGS),$(call api_pkg_includes,$(PKG)))
$(SDK_DIR)/include: $(SDK_DIR) $(GENODE_API_PKGS) $(CONTRIB_API_PKGS)
$(VERBOSE)mkdir --parents $@
$(VERBOSE)mkdir --parents $@/genode
$(VERBOSE)cp --no-clobber --recursive $(GENODE_INCLUDES) $@/genode
$(VERBOSE)$(foreach PKG,$(CONTRIB_API_PKG_NAMES),$(call cp_includes,$(PKG)))
$(SDK_DIR)/lib: $(SDK_DIR) $(DEPOT_BIN_PKGS)
$(VERBOSE)mkdir --parents $@
$(VERBOSE)cp --no-clobber \
$(foreach PKG,$(DEPOT_BIN_PKGS),$(wildcard $(PKG)/*.lib.*)) $@
$(SDK_DIR)/lib/startup.o: $(GENODE_DIR)/repos/base/src/lib/ldso/startup/startup.cc $(SDK_DIR)/lib
$(VERBOSE)$(CXX) -c $< -o $@
$(SDK_DIR)/lib/ldso-startup.lib.a: $(SDK_DIR)/lib/startup.o
$(VERBOSE)$(AR) -rcs $@ $<
.INTERMEDIATE: $(SDK_DIR)/lib/startup.o
$(DEPOT_DIR)/%:
$(VERBOSE)make --file $(GENODE_DIR)/tool/depot/create $*
endif
$(PLATFORM): message
message:
@echo "Successfully created SDK directory at $(SDK_DIR)."
.PHONY: $(PLATFORM)

View File

@ -0,0 +1,15 @@
prefix=!SDK_DIR!
lddir=${prefix}/ld
libdir=${prefix}/lib
toolchaindir=!TOOLCHAIN_DIR!
cc=${toolchaindir}/bin/genode-x86-gcc
cxx=${toolchaindir}/bin/genode-x86-g++
ld=${toolchaindir}/bin/genode-x86-ld
ar=${toolchaindir}/bin/genode-x86-ar
ranlib=${toolchaindir}/bin/genode-x86-ranlib
Name: genode-base
Description: Genode base compiler definitions
URL: https://genode.org/
Version: !VERSION!
Cflags: -nostdinc -fPIC -I${prefix}/include/genode -I${toolchaindir}/lib/gcc/x86_64-pc-elf/6.3.0/include

11
tool/sdk/genode-lib.pc.in Normal file
View File

@ -0,0 +1,11 @@
prefix=!SDK_DIR!
lddir=${prefix}/ld
libdir=${prefix}/lib
toolchaindir=!TOOLCHAIN_DIR!
Name: genode-lib
Description: Flags for linking Genode libraries
URL: https://genode.org/
Version: !VERSION!
Requires: genode-base
Libs: -shared --eh-frame-hdr -melf_x86_64 -gc-sections -z max-page-size=0x1000 -T ${lddir}/genode_rel.ld --entry=0x0 ${libdir}/ldso-startup.lib.a ${toolchaindir}/lib/gcc/x86_64-pc-elf/6.3.0/64/libgcc.a

View File

@ -0,0 +1,11 @@
prefix=!SDK_DIR!
includedir=${prefix}/include/libc
libdir=${prefix}/lib
Name: genode-libc
Description: Genode C runtime library
URL: https://genode.org/
Version: !VERSION!
Requires: genode-base genode-vfs
Cflags: -D__FreeBSD__=8 -D__ISO_C_VISIBLE=1999 -fno-builtin-sin -fno-builtin-cos -fno-builtin-sinf -fno-builtin-cosf -I${includedir} -I${includedir}/libc -I${includedir}/libc/libc -I${includedir}/libc-genode
Libs: ${libdir}/libc.lib.so ${libdir}/libm.lib.so

View File

@ -0,0 +1,10 @@
prefix=!SDK_DIR!
includedir=${prefix}/include/libc
libdir=${prefix}/lib
Name: genode-posix
Description: Genode POSIX entrypoint library
URL: https://genode.org/
Version: !VERSION!
Requires: genode-libc
Libs: ${libdir}/posix.lib.so

11
tool/sdk/genode-prg.pc Normal file
View File

@ -0,0 +1,11 @@
prefix=!SDK_DIR!
lddir=${prefix}/ld
libdir=${prefix}/lib
toolchaindir=!TOOLCHAIN_DIR!
ld=${toolchaindir}/bin/genode-x86-ld
Name: genode-prg
Description: Flags for dynamically-linked Genode programs
URL: https://genode.org/
Version: !VERSION!
Libs: -melf_x86_64 -gc-sections -z max-page-size=0x1000 --dynamic-list=${lddir}/genode_dyn.dl -nostdlib -Ttext=0x01000000 --dynamic-linker=ld.lib.so --eh-frame-hdr -rpath-link=. -T ${lddir}/genode_dyn.ld ${libdir}/ld.lib.so ${toolchaindir}/lib/gcc/x86_64-pc-elf/6.3.0/64/libgcc.a

11
tool/sdk/genode-prg.pc.in Normal file
View File

@ -0,0 +1,11 @@
prefix=!SDK_DIR!
lddir=${prefix}/ld
libdir=${prefix}/lib
toolchaindir=!TOOLCHAIN_DIR!
ld=${toolchaindir}/bin/genode-x86-ld
Name: genode-prg
Description: Flags for dynamically-linked Genode programs
URL: https://genode.org/
Version: !VERSION!
Libs: -melf_x86_64 -gc-sections -z max-page-size=0x1000 --dynamic-list=${lddir}/genode_dyn.dl -nostdlib -Ttext=0x01000000 --dynamic-linker=ld.lib.so --eh-frame-hdr -rpath-link=. -T ${lddir}/genode_dyn.ld ${libdir}/ld.lib.so ${toolchaindir}/lib/gcc/x86_64-pc-elf/6.3.0/64/libgcc.a

View File

@ -0,0 +1,11 @@
prefix=!SDK_DIR!
includedir=${prefix}/include/stdcxx/stdcxx
libdir=${prefix}/lib
Name: genode-stdcxx
Description: Genode Standard C++ library
URL: https://genode.org/
Version: !VERSION!
Requires: genode-libc
Cflags: -D_GLIBCXX_HAVE_MBSTATE_T -D_GLIBCXX_ATOMIC_BUILTINS_4 -I${includedir} -I${includedir}/std -I${includedir}/c_global
Libs: ${libdir}/stdcxx.lib.so

View File

@ -0,0 +1,9 @@
prefix=!SDK_DIR!
libdir=${prefix}/lib
Name: genode-vfs
Description: Genode Virtual File-System library
URL: https://genode.org/
Version: !VERSION!
Requires: genode-base
Libs: ${libdir}/vfs.lib.so