From 918281b01f295bff6e5291bca2602fea0ba19a77 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Sun, 26 Aug 2018 22:11:04 +0200 Subject: [PATCH] Genode SDK Makefile for generating a Genode SDK. Fix #2948 --- tool/create_sdk | 201 +++++++++++++++++++++++++++++++++++ tool/sdk/genode-base.pc.in | 15 +++ tool/sdk/genode-lib.pc.in | 11 ++ tool/sdk/genode-libc.pc.in | 11 ++ tool/sdk/genode-posix.pc.in | 10 ++ tool/sdk/genode-prg.pc | 11 ++ tool/sdk/genode-prg.pc.in | 11 ++ tool/sdk/genode-stdcxx.pc.in | 11 ++ tool/sdk/genode-vfs.pc.in | 9 ++ 9 files changed, 290 insertions(+) create mode 100755 tool/create_sdk create mode 100644 tool/sdk/genode-base.pc.in create mode 100644 tool/sdk/genode-lib.pc.in create mode 100644 tool/sdk/genode-libc.pc.in create mode 100644 tool/sdk/genode-posix.pc.in create mode 100644 tool/sdk/genode-prg.pc create mode 100644 tool/sdk/genode-prg.pc.in create mode 100644 tool/sdk/genode-stdcxx.pc.in create mode 100644 tool/sdk/genode-vfs.pc.in diff --git a/tool/create_sdk b/tool/create_sdk new file mode 100755 index 0000000000..603ecd77a1 --- /dev/null +++ b/tool/create_sdk @@ -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 [SDK_DIR= DEPOT_USER=$(DEFAULT_DEPOT_USER)]" + @echo + @echo " can be:" + @$(foreach PLAT,$(PLATFORMS), \ + echo " '$(PLAT)'";) + @echo + @echo " The definition of SDK_DIR is optional. If specified," + @echo " is the location of the directory to create." + @echo " If not specified, the directory will be created at" + @echo " $(DEFAULT_SDK_DIR_PREFIX)--$(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) diff --git a/tool/sdk/genode-base.pc.in b/tool/sdk/genode-base.pc.in new file mode 100644 index 0000000000..9a19f9981f --- /dev/null +++ b/tool/sdk/genode-base.pc.in @@ -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 diff --git a/tool/sdk/genode-lib.pc.in b/tool/sdk/genode-lib.pc.in new file mode 100644 index 0000000000..88101b4217 --- /dev/null +++ b/tool/sdk/genode-lib.pc.in @@ -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 diff --git a/tool/sdk/genode-libc.pc.in b/tool/sdk/genode-libc.pc.in new file mode 100644 index 0000000000..cd92710cee --- /dev/null +++ b/tool/sdk/genode-libc.pc.in @@ -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 diff --git a/tool/sdk/genode-posix.pc.in b/tool/sdk/genode-posix.pc.in new file mode 100644 index 0000000000..40f7dbcf08 --- /dev/null +++ b/tool/sdk/genode-posix.pc.in @@ -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 diff --git a/tool/sdk/genode-prg.pc b/tool/sdk/genode-prg.pc new file mode 100644 index 0000000000..725e81c499 --- /dev/null +++ b/tool/sdk/genode-prg.pc @@ -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 diff --git a/tool/sdk/genode-prg.pc.in b/tool/sdk/genode-prg.pc.in new file mode 100644 index 0000000000..725e81c499 --- /dev/null +++ b/tool/sdk/genode-prg.pc.in @@ -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 diff --git a/tool/sdk/genode-stdcxx.pc.in b/tool/sdk/genode-stdcxx.pc.in new file mode 100644 index 0000000000..9e2c85c62e --- /dev/null +++ b/tool/sdk/genode-stdcxx.pc.in @@ -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 diff --git a/tool/sdk/genode-vfs.pc.in b/tool/sdk/genode-vfs.pc.in new file mode 100644 index 0000000000..c29f7caf62 --- /dev/null +++ b/tool/sdk/genode-vfs.pc.in @@ -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