platform abstraction

This commit is contained in:
Wolfgang Thaller 2021-11-23 23:46:52 +01:00
parent 8349ce162a
commit 1559630536

View File

@ -43,6 +43,9 @@
}; };
bfdEmulation = "m68k"; bfdEmulation = "m68k";
isStatic = true; isStatic = true;
retro68GccConfig = ["--with-arch=m68k" "--with-cpu=m68000"];
retro68 = true;
}; };
powerpc = { powerpc = {
system = "powerpc-macos"; system = "powerpc-macos";
@ -60,6 +63,10 @@
execFormat = { name = "unknown"; }; execFormat = { name = "unknown"; };
}; };
}; };
retro68BinutilsConfig = ["--disable-plugins"];
retro68GccConfig = ["--disable-lto"];
retro68 = true;
}; };
carbon = { carbon = {
system = "powerpc-carbon"; system = "powerpc-carbon";
@ -78,27 +85,34 @@
}; };
}; };
}; };
retro68BinutilsConfig = ["--disable-plugins"];
retro68GccConfig = ["--disable-lto"];
retro68 = true;
}; };
in { in {
# A Nixpkgs overlay. # A Nixpkgs overlay.
overlay = pkgs: prev: overlay = pkgs: prev:
let filterSrc = pkgs.nix-gitignore.gitignoreSource [ ]; let filterSrc = pkgs.nix-gitignore.gitignoreSource [ ];
in { in {
retro68_binutils_m68k = with pkgs; retro68_binutils = with pkgs;
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
name = "retro68_binutils_m68k"; name = "retro68_binutils";
src = filterSrc (self + /binutils); src = filterSrc (self + /binutils);
configureFlags = [ "--target=m68k-apple-macos" "--disable-doc" ]; configureFlags = [ "--target=${stdenv.targetPlatform.config}" "--disable-doc" ]
++ stdenv.targetPlatform.retro68BinutilsConfig or [];
enableParallelBuilding = true; enableParallelBuilding = true;
}; };
retro68_binutils_m68k_with_tools = with pkgs; retro68_binutils_with_tools = with pkgs; if stdenv.targetPlatform.system == "m68k-macos"
then
symlinkJoin { symlinkJoin {
name = "retro68_buinutils_m68k_with_tools"; name = "retro68_binutils_with_tools";
paths = [ retro68_binutils_m68k buildPackages.retro68_tools ]; paths = [ retro68_binutils buildPackages.retro68_tools ];
# Move the real linker aside and install symlinks to Elf2Mac # Move the real linker aside and install symlinks to Elf2Mac
postBuild = '' postBuild = ''
@ -107,18 +121,19 @@
ln -s $out/bin/Elf2Mac $out/bin/m68k-apple-macos-ld ln -s $out/bin/Elf2Mac $out/bin/m68k-apple-macos-ld
ln -s $out/bin/Elf2Mac $out/m68k-apple-macos/bin/ld ln -s $out/bin/Elf2Mac $out/m68k-apple-macos/bin/ld
''; '';
}; }
else binutils1;
binutils = if pkgs.stdenv.targetPlatform.system == "m68k-macos" then binutils = if pkgs.stdenv.targetPlatform ? retro68 then
pkgs.wrapBintoolsWith { pkgs.wrapBintoolsWith {
bintools = pkgs.retro68_binutils_m68k_with_tools; bintools = pkgs.retro68_binutils_with_tools;
} }
else else
prev.binutils; prev.binutils;
gcc = if pkgs.stdenv.targetPlatform.system == "m68k-macos" then gcc = if pkgs.stdenv.targetPlatform ? retro68 then
pkgs.wrapCCWith { pkgs.wrapCCWith {
cc = pkgs.retro68_gcc_m68k; cc = pkgs.retro68_gcc;
extraBuildCommands = '' extraBuildCommands = ''
echo "" > $out/nix-support/add-hardening.sh echo "" > $out/nix-support/add-hardening.sh
''; '';
@ -130,30 +145,28 @@
libcCrossChooser = name: libcCrossChooser = name:
if name == "retro68" then null else prev.libcCrossChooser name; if name == "retro68" then null else prev.libcCrossChooser name;
retro68_gcc_m68k = with pkgs; retro68_gcc = with pkgs;
stdenv.mkDerivation { stdenv.mkDerivation rec {
name = "retro68_gcc_m68k"; name = "retro68_gcc";
src = filterSrc (self + /gcc); src = filterSrc (self + /gcc);
buildInputs = buildInputs =
[ retro68_binutils_m68k_with_tools gmp mpfr libmpc ]; [ retro68_binutils_with_tools gmp mpfr libmpc ];
configureFlags = [ configureFlags = [
"--target=m68k-apple-macos" "--target=${stdenv.targetPlatform.config}"
"--enable-languages=c,c++" "--enable-languages=c,c++"
"--with-arch=m68k"
"--with-cpu=m68000"
"--disable-libssp" "--disable-libssp"
"MAKEINFO=missing" "MAKEINFO=missing"
]; ]++ stdenv.targetPlatform.retro68GccConfig or [];
hardeningDisable = [ "format" ]; hardeningDisable = [ "format" ];
enableParallelBuilding = true; enableParallelBuilding = true;
# nix does in-source builds by default, and something breaks # nix does in-source builds by default, and something breaks
buildCommand = '' buildCommand = ''
mkdir -p $out/m68k-apple-macos/bin mkdir -p $out/${stdenv.targetPlatform.config}/bin
ln -s ${retro68_binutils_m68k_with_tools}/m68k-apple-macos/bin/* $out/m68k-apple-macos/bin/ ln -s ${retro68_binutils_with_tools}/${stdenv.targetPlatform.config}/bin/* $out/${stdenv.targetPlatform.config}/bin/
export target_configargs="--disable-nls --enable-libstdcxx-dual-abi=no --disable-libstdcxx-verbose" export target_configargs="--disable-nls --enable-libstdcxx-dual-abi=no --disable-libstdcxx-verbose"
$src/configure "--target=m68k-apple-macos" "--enable-languages=c,c++" "--with-arch=m68k" "--with-cpu=m68000" "--disable-libssp" "MAKEINFO=missing" --prefix=$out $src/configure ${builtins.toString configureFlags} --prefix=$out
make -j$NIX_BUILD_CORES make -j$NIX_BUILD_CORES
make install make install
''; '';