diff --git a/pkgs/by-name/gf/gforth/package.nix b/pkgs/by-name/gf/gforth/package.nix index 4ff19e15c911..bed387a3214a 100644 --- a/pkgs/by-name/gf/gforth/package.nix +++ b/pkgs/by-name/gf/gforth/package.nix @@ -2,7 +2,7 @@ lib, stdenv, fetchFromGitHub, - callPackage, + buildPackages, autoreconfHook, gitUpdater, texinfo, @@ -11,8 +11,8 @@ }: let - swig = callPackage ./swig.nix { }; - bootForth = callPackage ./boot-forth.nix { }; + swig = buildPackages.callPackage ./swig.nix { }; + bootForth = buildPackages.callPackage ./boot-forth.nix { }; lispDir = "${placeholder "out"}/share/emacs/site-lisp"; in stdenv.mkDerivation (finalAttrs: { @@ -32,9 +32,14 @@ stdenv.mkDerivation (finalAttrs: { writableTmpDirAsHomeHook autoreconfHook texinfo - bootForth swig - ]; + ] + ++ ( + if (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) then + [ buildPackages.gforth ] + else + [ bootForth ] + ); buildInputs = [ libffi @@ -47,12 +52,41 @@ stdenv.mkDerivation (finalAttrs: { ] ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) [ "--build=x86_64-apple-darwin" + ] + ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ + # Tries to run ./engine/gforth-ll + "--without-check" + # Use build-platform CC for helper programs that must run during build + "HOSTCC=${buildPackages.stdenv.cc}/bin/cc" + # Tell gforth's libcc where to find the cross compiler + "CROSS_PREFIX=${stdenv.hostPlatform.config}-" + ]; + + env = lib.optionalAttrs (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) { + # Tell gforth's libcc to prefix compiler commands with the cross-compilation target + CROSS_PREFIX = "${stdenv.hostPlatform.config}-"; + }; + + makeFlags = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ + "DITCENGINE=${buildPackages.gforth}/bin/gforth-ditc" + "GFORTH=${buildPackages.gforth}/bin/gforth" + "ENGINE=${buildPackages.gforth}/bin/gforth" # for ./preforth ]; preConfigure = '' mkdir -p ${lispDir} ''; + postConfigure = lib.optionalString (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' + # Put the project-local (cross-aware) libtool first in PATH + mkdir -p .cross-bin + ln -sf "$PWD/libtool" .cross-bin/libtool + ln -sf "$PWD/libtool" ".cross-bin/${stdenv.hostPlatform.config}-libtool" + export PATH="$PWD/.cross-bin:$PATH" + # Remove 'check' from the default 'all' target (can't run cross binaries) + sed -i 's/^\(all:.*\) check/\1/' Makefile + ''; + passthru.updateScript = gitUpdater { }; meta = {