From 5b5f66674b1f6dc6615bfe3908d247b395b0d8d8 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Wed, 12 Jun 2019 13:03:57 +0200 Subject: [PATCH] Adjustments for NixOS --- .../base-linux/lib/import/import-lx_hybrid.mk | 16 +++++ .../lib/import/import-syscall-linux.mk | 3 + repos/base/etc/tools.conf | 10 +-- repos/base/mk/lib.mk | 2 +- tool/builddir/build.mk | 4 +- tool/depot/extract | 2 +- tool/dev-shell.nix | 37 ++++++++++ tool/run/depot.inc | 6 +- tool/run/grub2.inc | 4 +- tool/toolchain.nix | 68 +++++++++++++++++++ 10 files changed, 138 insertions(+), 14 deletions(-) create mode 100644 tool/dev-shell.nix create mode 100644 tool/toolchain.nix diff --git a/repos/base-linux/lib/import/import-lx_hybrid.mk b/repos/base-linux/lib/import/import-lx_hybrid.mk index cfb3a0790..4a3af6936 100644 --- a/repos/base-linux/lib/import/import-lx_hybrid.mk +++ b/repos/base-linux/lib/import/import-lx_hybrid.mk @@ -22,6 +22,14 @@ HOST_INC_DIR += $(shell echo "int main() {return 0;}" |\ sed '/^\#include <\.\.\.> search starts here:/,/^End of search list/!d' |\ grep "include-fixed") +# +# Nix include paths +# +ifneq ($(nativeBuildInputs),) +HOST_INC_DIR += $(shell find $(nativeBuildInputs) -name include) +endif + + # # Add search paths for normal libraries # @@ -49,6 +57,14 @@ HOST_SO_SEARCH_DIRS := $(sort $(dir $(shell $(LDCONFIG) -p | sed "s/^.* \//\//" LINK_ARG_PREFIX := -Wl, CXX_LINK_OPT += $(addprefix $(LINK_ARG_PREFIX)-rpath-link $(LINK_ARG_PREFIX),$(HOST_SO_SEARCH_DIRS)) +# +# Nix library paths +# +ifneq ($(nativeBuildInputs),) +HOST_SO_SEARCH_DIRS += $(shell find $(nativeBuildInputs) -name lib) +endif + + # # Make exceptions work # diff --git a/repos/base-linux/lib/import/import-syscall-linux.mk b/repos/base-linux/lib/import/import-syscall-linux.mk index f093c2d67..31b9fa8c9 100644 --- a/repos/base-linux/lib/import/import-syscall-linux.mk +++ b/repos/base-linux/lib/import/import-syscall-linux.mk @@ -11,6 +11,9 @@ HOST_INC_DIR += /usr/include/$(shell gcc -dumpmachine) HOST_INC_DIR += /usr/include/i386-linux-gnu HOST_INC_DIR += /usr/include/x86_64-linux-gnu +# NixOS +HOST_INC_DIR += $(foreach NP,$(NIX_PROFILES),$(NP)/include) + # # Some header files installed on GNU/Linux test for the GNU compiler. For # example, 'stdio.h' might complain with the following error otherwise: diff --git a/repos/base/etc/tools.conf b/repos/base/etc/tools.conf index af61840a2..ea13a7ec7 100644 --- a/repos/base/etc/tools.conf +++ b/repos/base/etc/tools.conf @@ -19,19 +19,19 @@ # package build tool. # ifeq ($(filter-out $(SPECS),x86_32),) -CROSS_DEV_PREFIX ?= /opt/genode/toolchain-19.05/bin/genode-x86- +CROSS_DEV_PREFIX ?= genode-x86- endif ifeq ($(filter-out $(SPECS),x86_64),) -CROSS_DEV_PREFIX ?= /opt/genode/toolchain-19.05/bin/genode-x86- +CROSS_DEV_PREFIX ?= genode-x86- endif ifeq ($(filter-out $(SPECS),arm),) -CROSS_DEV_PREFIX ?= /opt/genode/toolchain-19.05/bin/genode-arm- +CROSS_DEV_PREFIX ?= genode-arm- endif ifeq ($(filter-out $(SPECS),riscv),) -CROSS_DEV_PREFIX ?= /opt/genode/toolchain-19.05/bin/genode-riscv- +CROSS_DEV_PREFIX ?= genode-riscv- endif ifeq ($(filter-out $(SPECS),arm_64),) -CROSS_DEV_PREFIX ?= /opt/genode/toolchain-19.05/bin/genode-aarch64- +CROSS_DEV_PREFIX ?= genode-aarch64- endif # diff --git a/repos/base/mk/lib.mk b/repos/base/mk/lib.mk index 41fe8b327..066ad63e6 100644 --- a/repos/base/mk/lib.mk +++ b/repos/base/mk/lib.mk @@ -260,7 +260,7 @@ $(ABI_SO): $(LIB).symbols.o --end-group --no-whole-archive $(LIB_CHECKED): $(LIB_SO) - $(VERBOSE)$(BASE_DIR)/../../tool/check_abi $(LIB_SO) $(SYMBOLS) + $(VERBOSE)tclsh $(BASE_DIR)/../../tool/check_abi $(LIB_SO) $(SYMBOLS) $(LIB_SO).stripped: $(LIB_SO) $(VERBOSE)$(STRIP) -o $@ $< diff --git a/tool/builddir/build.mk b/tool/builddir/build.mk index 091c297bb..e620da76b 100644 --- a/tool/builddir/build.mk +++ b/tool/builddir/build.mk @@ -291,7 +291,7 @@ gen_deps_and_build_targets: $(INSTALL_DIR) $(DEBUG_DIR) $(LIB_DEP_FILE) echo " @echo \" \$$(sort \$$(MISSING_PORTS))\""; \ echo " @echo \"\""; \ echo " @echo \"You can prepare respectively update them as follows:\""; \ - echo " @echo \" $(GENODE_DIR)/tool/ports/prepare_port \$$(sort \$$(MISSING_PORTS))\""; \ + echo " @echo \"make -f $(GENODE_DIR)/tool/ports/prepare_port \$$(sort \$$(MISSING_PORTS))\""; \ echo " @echo \"\""; \ echo " @false"; \ echo "else"; \ @@ -321,7 +321,7 @@ RUN_SCRIPT = $(call select_from_repositories,run/$*.run) run/%: $(call select_from_repositories,run/%.run) $(RUN_ENV) $(VERBOSE)test -f "$(RUN_SCRIPT)" || (echo "Error: No run script for $*"; exit -1) - $(VERBOSE)$(GENODE_DIR)/tool/run/run --genode-dir $(GENODE_DIR) \ + $(VERBOSE)expect $(GENODE_DIR)/tool/run/run --genode-dir $(GENODE_DIR) \ --name $* \ --specs "$(SPECS)" \ --board "$(BOARD)" \ diff --git a/tool/depot/extract b/tool/depot/extract index 08204a609..80a974695 100755 --- a/tool/depot/extract +++ b/tool/depot/extract @@ -159,7 +159,7 @@ handle_missing_ports = $(if $1,$(VERBOSE)( \ echo -e " $(1)"; \ echo -e ""; \ echo -e "You can prepare respectively update them as follows:"; \ - echo -e " $(GENODE_DIR)/tool/ports/prepare_port $(1)"; \ + echo -e "make -f $(GENODE_DIR)/tool/ports/prepare_port $(1)"; \ echo -e ""; \ false),) diff --git a/tool/dev-shell.nix b/tool/dev-shell.nix new file mode 100644 index 000000000..f60cd0cae --- /dev/null +++ b/tool/dev-shell.nix @@ -0,0 +1,37 @@ +{ pkgs ? import {} }: with pkgs; + +stdenv.mkDerivation { + name = "genode-dev-env"; + buildInputs = + [ (import ./toolchain.nix { inherit pkgs; }) + git + ccache + gnumake which findutils + + expect libxml2 syslinux qemu xorriso + + # libc + flex bison + + # virtualbox + yasm libxslt iasl + + # qt5 + gperf + + # ncurses + mawk + + # fb_sdl + pkgconfig + SDL.dev + alsaLib.dev + ]; + + shellHook = + '' + export PROMPT_DIRTRIM=2 + export PS1="\[\033[1;30m\]Genode-dev [\[\033[1;37m\]\w\[\033[1;30m\]] $\[\033[0m\] " + export PS2="\[\033[1;30m\]>\[\033[0m\] " + ''; +} diff --git a/tool/run/depot.inc b/tool/run/depot.inc index eb9fbe814..d73bf4b5b 100644 --- a/tool/run/depot.inc +++ b/tool/run/depot.inc @@ -204,7 +204,7 @@ proc _depot_auto_update { archives } { # remove duplicates set archives_to_create [lsort -unique $archives_to_create] - set cmd "[genode_dir]/tool/depot/create $archives_to_create " + set cmd "make -f [genode_dir]/tool/depot/create $archives_to_create " append cmd "CROSS_DEV_PREFIX=[cross_dev_prefix] " append cmd "DEPOT_DIR=[depot_dir] " append cmd "UPDATE_VERSIONS=1 FORCE=1 REBUILD= " @@ -444,12 +444,12 @@ proc check_for_missing_depot_archives { } { if {[llength $local_user_archives]} { append create_args " CROSS_DEV_PREFIX=[cross_dev_prefix]" puts stderr "You may create the following archives locally:\n" - puts stderr " [genode_dir]/tool/depot/create $local_user_archives$create_args\n" + puts stderr "make -f [genode_dir]/tool/depot/create $local_user_archives$create_args\n" } if {[llength $foreign_archives]} { puts stderr "You may try to download the following archives:\n" - puts stderr " [genode_dir]/tool/depot/download $foreign_archives\n" + puts stderr "make -f [genode_dir]/tool/depot/download $foreign_archives\n" } exit 1 diff --git a/tool/run/grub2.inc b/tool/run/grub2.inc index 787bf2a53..b045d2c2b 100644 --- a/tool/run/grub2.inc +++ b/tool/run/grub2.inc @@ -3,7 +3,7 @@ # proc get_grub2_dir { } { set ::env(MAKEFLAGS) s - set grub2_path [exec [genode_dir]/tool/ports/current grub2] + set grub2_path [exec make -f [genode_dir]/tool/ports/current grub2] if {![file exists $grub2_path]} { puts "" @@ -11,7 +11,7 @@ proc get_grub2_dir { } { puts " grub2" puts "" puts "You can prepare respectively update it as follows:" - puts " [genode_dir]/tool/ports/prepare_port grub2" + puts "make -f [genode_dir]/tool/ports/prepare_port grub2" puts "" exit 1 } diff --git a/tool/toolchain.nix b/tool/toolchain.nix new file mode 100644 index 000000000..2aa0b8d90 --- /dev/null +++ b/tool/toolchain.nix @@ -0,0 +1,68 @@ +{ pkgs ? import {} }: with pkgs; + +let + genodeVersion = "19.05"; + glibcVersion = (builtins.parseDrvName stdenv.glibc.name).version; + +in +stdenv.mkDerivation rec { + name = "genode-toolchain-${genodeVersion}"; + version = genodeVersion; + + src = + if stdenv.isx86_64 then + fetchurl { + url = "https://downloads.sourceforge.net/project/genode/genode-toolchain/${genodeVersion}/genode-toolchain-${genodeVersion}-x86_64.tar.xz"; + sha256 = "036czy21zk7fvz1y1p67q3d5hgg8rb8grwabgrvzgdsqcv2ls6l9"; + } + else abort "no toolchain for ${stdenv.system}"; + + buildInputs = [ patchelf ]; + + dontPatchELF = true; + + # installPhase is disabled for now + phases = "unpackPhase fixupPhase"; + + unpackPhase = '' + mkdir -p $out + + echo "unpacking $src..." + tar xf $src --strip-components=5 -C $out + ''; + + installPhase = '' + cd $out/bin + for platform in arm x86 ; do + dest="$"$platform"/bin" + eval dest=$"$dest" + + mkdir -p $dest + + for b in genode-$platform-* ; do + eval ln -s $b $dest/$\{b#genode-$platform-\} + done + + done + cd - + ''; + + fixupPhase = '' + interp=${stdenv.glibc.out}/lib/ld-${glibcVersion}.so + if [ ! -f "$interp" ] ; then + echo new interpreter $interp does not exist, + echo cannot patch binaries + exit 1 + fi + + for f in $(find $out); do + if [ -f "$f" ] && patchelf "$f" 2> /dev/null; then + patchelf --set-interpreter $interp \ + --set-rpath $out/lib:${stdenv.glibc.out}/lib:${zlib.out}/lib \ + "$f" || true + fi + done + ''; + + passthru = { libc = stdenv.glibc; }; +}