mirror of
https://github.com/autc04/Retro68.git
synced 2024-06-15 22:29:38 +00:00
commit
086eb7450d
|
@ -77,11 +77,13 @@ jobs:
|
|||
EOF
|
||||
displayName: Build inside nixos/nix docker
|
||||
- script: |
|
||||
mkdir CompiledSamples
|
||||
cd CompiledSamples
|
||||
docker cp -L nix:result - | tar x --strip-components 1
|
||||
displayName: Copy result out of docker
|
||||
|
||||
- publish: Applications
|
||||
artifact: 68K Applications
|
||||
- publish: CompiledSamples
|
||||
artifact: 68K Samples
|
||||
|
||||
|
||||
- job: nix_ppc
|
||||
|
@ -99,7 +101,9 @@ jobs:
|
|||
EOF
|
||||
displayName: Build inside nixos/nix docker
|
||||
- script: |
|
||||
mkdir CompiledSamples
|
||||
cd CompiledSamples
|
||||
docker cp -L nix:result - | tar x --strip-components 1
|
||||
displayName: Copy result out of docker
|
||||
- publish: Applications
|
||||
artifact: PowerPC Applications
|
||||
- publish: CompiledSamples
|
||||
artifact: PowerPC Samples
|
||||
|
|
482
default.nix
482
default.nix
|
@ -1,483 +1,39 @@
|
|||
{ system ? builtins.currentSystem, pkgs ? import <nixpkgs> { inherit system; }
|
||||
, ... }:
|
||||
let sources = import ./nix/sources.nix;
|
||||
in { system ? builtins.currentSystem, nixpkgs ? sources.nixpkgs, ... }:
|
||||
|
||||
let
|
||||
retroPlatforms = {
|
||||
m68k = {
|
||||
system = "m68k-macos";
|
||||
config = "m68k-apple-macos";
|
||||
libc = "retro68";
|
||||
parsed = {
|
||||
cpu = {
|
||||
name = "m68k";
|
||||
bits = 32;
|
||||
significantByte = { name = "bigEndian"; };
|
||||
family = "m68k";
|
||||
};
|
||||
kernel = {
|
||||
name = "macos";
|
||||
execFormat = { name = "unknown"; };
|
||||
};
|
||||
};
|
||||
bfdEmulation = "m68k";
|
||||
isStatic = true;
|
||||
retroPlatforms = import nix/platforms.nix;
|
||||
|
||||
retro68GccConfig = [ "--with-arch=m68k" "--with-cpu=m68000" ];
|
||||
retro68 = true;
|
||||
cmakeSystemName = "Retro68";
|
||||
};
|
||||
powerpc = {
|
||||
system = "powerpc-macos";
|
||||
config = "powerpc-apple-macos";
|
||||
libc = "retro68";
|
||||
parsed = {
|
||||
cpu = {
|
||||
name = "powerpc";
|
||||
bits = 32;
|
||||
significantByte = { name = "bigEndian"; };
|
||||
family = "power";
|
||||
};
|
||||
kernel = {
|
||||
name = "macos";
|
||||
execFormat = { name = "unknown"; };
|
||||
};
|
||||
};
|
||||
lib = ((import <nixpkgs>) { }).lib;
|
||||
|
||||
isStatic = true;
|
||||
retro68BinutilsConfig = [ "--disable-plugins" ];
|
||||
retro68GccConfig = [ "--disable-lto" ];
|
||||
retro68 = true;
|
||||
cmakeSystemName = "RetroPPC";
|
||||
};
|
||||
carbon = {
|
||||
system = "powerpc-carbon";
|
||||
config = "powerpc-apple-carbon";
|
||||
libc = "retro68";
|
||||
parsed = {
|
||||
cpu = {
|
||||
name = "powerpc";
|
||||
bits = 32;
|
||||
significantByte = { name = "bigEndian"; };
|
||||
family = "power";
|
||||
};
|
||||
kernel = {
|
||||
name = "carbon";
|
||||
execFormat = { name = "unknown"; };
|
||||
};
|
||||
};
|
||||
isStatic = true;
|
||||
retro68BinutilsConfig = [ "--disable-plugins" ];
|
||||
retro68GccConfig = [ "--disable-lto" ];
|
||||
retro68 = true;
|
||||
cmakeSystemName = "RetroCarbon";
|
||||
};
|
||||
|
||||
isStatic = true;
|
||||
retro68BinutilsConfig = [ "--disable-plugins" ];
|
||||
retro68GccConfig = [ "--disable-lto" ];
|
||||
retro68 = true;
|
||||
};
|
||||
multiversal_src = if builtins.pathExists ./multiversal/make-multiverse.rb then
|
||||
./multiversal
|
||||
else
|
||||
sources.multiversal;
|
||||
|
||||
# A Nixpkgs overlay.
|
||||
overlay = pkgs: prev:
|
||||
{
|
||||
retro68 = {
|
||||
platforms = retroPlatforms;
|
||||
overlay = lib.composeManyExtensions [
|
||||
((import nix/overlay.nix) { inherit multiversal_src; })
|
||||
(import nix/universal.nix)
|
||||
(import nix/samples.nix)
|
||||
];
|
||||
|
||||
monolithic = with pkgs;
|
||||
stdenv.mkDerivation {
|
||||
name = "retro68.monolithic";
|
||||
src = ./.;
|
||||
nativeBuildInputs = [ cmake bison flex ruby ninja bash ];
|
||||
buildInputs = [ boost gmp mpfr libmpc zlib ]
|
||||
++ lib.optional hostPlatform.isDarwin
|
||||
darwin.apple_sdk.frameworks.ApplicationServices;
|
||||
buildCommand = ''
|
||||
bash $src/build-toolchain.bash --ninja --prefix=$out --no-carbon
|
||||
'';
|
||||
hardeningDisable = [ "format" ];
|
||||
};
|
||||
|
||||
# ----------- Native Tools -------------
|
||||
# hfsutils -- Utilities for manipulating HFS volumes & disk images.
|
||||
hfsutils = with pkgs;
|
||||
stdenv.mkDerivation {
|
||||
name = "retro68.hfsutils";
|
||||
srcs = ./hfsutils;
|
||||
|
||||
preConfigure = ''
|
||||
mkdir -p $out/bin
|
||||
mkdir -p $out/lib
|
||||
mkdir -p $out/include
|
||||
mkdir -p $out/share/man/man1
|
||||
'';
|
||||
configureFlags = [ "--mandir=$(out)/share/man" "--enable-devlibs" ];
|
||||
};
|
||||
|
||||
# tools -- native tools that are part of Retro68
|
||||
tools = with pkgs;
|
||||
stdenv.mkDerivation {
|
||||
name = "retro68.tools";
|
||||
src = nix-gitignore.gitignoreSource [
|
||||
"/*"
|
||||
"!/CMakeLists.txt"
|
||||
"!/libelf" # should perhaps use nixpkg's libelf instead?
|
||||
"!/cmake"
|
||||
"!/LaunchAPPL"
|
||||
"!/libretro"
|
||||
"!/PEFTools"
|
||||
"!/ResourceFiles"
|
||||
"!/Rez"
|
||||
"!/Elf2Mac"
|
||||
"!/ConvertObj"
|
||||
"!/ConvertDiskImage"
|
||||
] ./.;
|
||||
|
||||
nativeBuildInputs = [ cmake bison flex ];
|
||||
buildInputs = [ boost zlib retro68.hfsutils ]
|
||||
++ lib.optional hostPlatform.isDarwin
|
||||
darwin.apple_sdk.frameworks.ApplicationServices;
|
||||
};
|
||||
|
||||
} // prev.lib.optionalAttrs (prev.targetPlatform ? retro68) {
|
||||
|
||||
# ----------- Binutils & GCC -------------
|
||||
|
||||
# binutils_unwrapped -- binutils, without any wrappers
|
||||
binutils_unwrapped = with pkgs;
|
||||
stdenv.mkDerivation rec {
|
||||
name = "retro68.binutils_unwrapped";
|
||||
src = ./binutils;
|
||||
|
||||
configureFlags =
|
||||
[ "--target=${stdenv.targetPlatform.config}" "--disable-doc" ]
|
||||
++ stdenv.targetPlatform.retro68BinutilsConfig or [ ];
|
||||
enableParallelBuilding = true;
|
||||
|
||||
postInstall = let
|
||||
ld = "$out/bin/${stdenv.targetPlatform.config}-ld";
|
||||
ld_real = "$out/bin/${stdenv.targetPlatform.config}-ld.real";
|
||||
|
||||
in ''
|
||||
mv ${ld} ${ld_real}
|
||||
|
||||
echo "#!${stdenv.shell}" > ${ld}
|
||||
echo "exec \$'' + ''
|
||||
{RETRO68_LD_WRAPPER_${stdenv.targetPlatform.cmakeSystemName}-${ld_real}} \"\$@\"" >> ${ld}
|
||||
chmod +x ${ld}
|
||||
|
||||
rm $out/${stdenv.targetPlatform.config}/bin/ld
|
||||
ln -s ${ld} $out/${stdenv.targetPlatform.config}/bin/ld
|
||||
'';
|
||||
};
|
||||
|
||||
# gcc -- gcc, without any wrappers
|
||||
gcc_unwrapped = with pkgs;
|
||||
stdenv.mkDerivation rec {
|
||||
name = "retro68.gcc_unwrapped";
|
||||
src = ./gcc;
|
||||
buildInputs = [ retro68.binutils_unwrapped gmp mpfr libmpc ];
|
||||
configureFlags = [
|
||||
"--target=${stdenv.targetPlatform.config}"
|
||||
"--enable-languages=c,c++"
|
||||
"--disable-libssp"
|
||||
"MAKEINFO=missing"
|
||||
] ++ stdenv.targetPlatform.retro68GccConfig or [ ];
|
||||
hardeningDisable = [ "format" ];
|
||||
enableParallelBuilding = true;
|
||||
|
||||
# nix does in-source builds by default, and something breaks
|
||||
buildCommand = ''
|
||||
mkdir -p $out/${stdenv.targetPlatform.config}/bin
|
||||
ln -s ${retro68.binutils_unwrapped}/${stdenv.targetPlatform.config}/bin/* $out/${stdenv.targetPlatform.config}/bin/
|
||||
|
||||
export target_configargs="--disable-nls --enable-libstdcxx-dual-abi=no --disable-libstdcxx-verbose"
|
||||
$src/configure ${builtins.toString configureFlags} --prefix=$out
|
||||
make -j$NIX_BUILD_CORES
|
||||
make install
|
||||
'';
|
||||
};
|
||||
|
||||
} // prev.lib.optionalAttrs (prev.hostPlatform ? retro68) {
|
||||
|
||||
setup_hook = let
|
||||
systemName = pkgs.targetPlatform.cmakeSystemName;
|
||||
toolchain = pkgs.writeTextFile {
|
||||
name = "retro68.cmake-toolchain";
|
||||
text = ''
|
||||
set(CMAKE_SYSTEM_NAME ${systemName})
|
||||
set(CMAKE_SYSTEM_VERSION 1)
|
||||
set(CMAKE_CROSSCOMPILING TRUE)
|
||||
|
||||
set(REZ "${pkgs.buildPackages.retro68.tools}/bin/Rez" )
|
||||
set(REZ_TEMPLATES_PATH ${pkgs.retro68.libretro}/RIncludes)
|
||||
|
||||
set(MAKE_PEF "${pkgs.buildPackages.retro68.tools}/bin/MakePEF" )
|
||||
|
||||
include(${./cmake/add_application.cmake})
|
||||
'';
|
||||
};
|
||||
hook = pkgs.writeTextFile {
|
||||
name = "retro68.setup_hook";
|
||||
text = ''
|
||||
export CMAKE_TOOLCHAIN_FILE=${toolchain}
|
||||
|
||||
retro68_addRIncludes() {
|
||||
case $depHostOffset in
|
||||
-1) local role='BUILD_' ;;
|
||||
0) local role="" ;;
|
||||
1) local role='TARGET_' ;;
|
||||
*) echo "retro68_addRIncludes: Error: Cannot be used with $depHostOffset-offset deps" >2;
|
||||
return 1 ;;
|
||||
esac
|
||||
|
||||
if [[ -d "$1/RIncludes" ]]; then
|
||||
export REZ_INCLUDE_PATH+=":$1/RIncludes"
|
||||
fi
|
||||
}
|
||||
|
||||
addEnvHooks "$targetOffset" retro68_addRIncludes
|
||||
|
||||
'' + (pkgs.lib.optionalString (systemName == "Retro68") ''
|
||||
export RETRO68_LD_WRAPPER_Retro68="${pkgs.buildPackages.retro68.tools}/bin/Elf2Mac"
|
||||
export RETRO68_REAL_LD="${pkgs.buildPackages.retro68.binutils_unwrapped}/bin/m68k-apple-macos-ld.real"
|
||||
'');
|
||||
};
|
||||
in pkgs.makeSetupHook { } hook;
|
||||
|
||||
# ----------- Retro68 core libraries -------------
|
||||
|
||||
# multiversal -- multiversal interfaces
|
||||
multiversal = with pkgs;
|
||||
(stdenv.override {
|
||||
cc = stdenv.cc.override { extraPackages = [ ]; };
|
||||
}).mkDerivation {
|
||||
name = "retro68.multiversal";
|
||||
src = ./multiversal;
|
||||
nativeBuildInputs = [ buildPackages.ruby ];
|
||||
buildCommand = ''
|
||||
echo $src
|
||||
build=`pwd`
|
||||
(cd $src && ruby make-multiverse.rb -G CIncludes -o "$build")
|
||||
mkdir $out
|
||||
cp -r CIncludes $out/include
|
||||
cp -r RIncludes $out/
|
||||
'' + (if stdenv.targetPlatform.system == "m68k-macos" then ''
|
||||
cp -r lib68k $out/lib
|
||||
'' else
|
||||
"");
|
||||
};
|
||||
|
||||
mpw_35_gm = with pkgs;
|
||||
fetchurl {
|
||||
url = "https://web.archive.org/web/20210309154524/https://staticky.com/mirrors/ftp.apple.com/developer/Tool_Chest/Core_Mac_OS_Tools/MPW_etc./MPW-GM_Images/MPW-GM.img.bin";
|
||||
sha256 = "0wm8dwmm0cpp8px27in564ih27sn5vbydz3jqpzwh04qpfazmfwr";
|
||||
};
|
||||
|
||||
universal = with pkgs;
|
||||
stdenvNoCC.mkDerivation {
|
||||
name = "retro68.universal";
|
||||
src = retro68.mpw_35_gm;
|
||||
nativeBuildInputs = with buildPackages.retro68; [tools hfsutils binutils_unwrapped];
|
||||
|
||||
|
||||
buildCommand = ''
|
||||
ConvertDiskImage $src decoded.dsk
|
||||
export HOME=.
|
||||
hmount decoded.dsk
|
||||
mkdir -p CIncludes RIncludes lib68
|
||||
hcopy -t 'MPW-GM:MPW-GM:Interfaces&Libraries:Interfaces:CIncludes:*.h' CIncludes/
|
||||
hcopy -t 'MPW-GM:MPW-GM:Interfaces&Libraries:Interfaces:RIncludes:*.r' RIncludes/
|
||||
mkdir -p $out/include $out/RIncludes
|
||||
bash ${./prepare-headers.sh} CIncludes $out/include
|
||||
bash ${./prepare-rincludes.sh} RIncludes $out/RIncludes
|
||||
|
||||
hcopy -r 'MPW-GM:MPW-GM:Interfaces&Libraries:Libraries:Libraries:*.o' lib68
|
||||
|
||||
. ${./interfaces-and-libraries.sh}
|
||||
M68KLIBRARIES=lib68
|
||||
setup68KLibraries $out/
|
||||
mv $out/lib68k $out/lib
|
||||
'';
|
||||
};
|
||||
|
||||
import_libraries = with pkgs;
|
||||
if stdenvNoCC.targetPlatform != retroPlatforms.m68k then
|
||||
stdenvNoCC.mkDerivation {
|
||||
name = "retro68.import_libraries";
|
||||
src = ./ImportLibraries;
|
||||
buildCommand = ''
|
||||
mkdir -p $out/lib
|
||||
cp $src/*.a $out/lib/
|
||||
'';
|
||||
}
|
||||
else
|
||||
null;
|
||||
|
||||
libretro = with pkgs;
|
||||
let
|
||||
systemName = pkgs.targetPlatform.cmakeSystemName;
|
||||
toolchain = pkgs.writeTextFile {
|
||||
name = "retro68-cmake-toolchain-bootstrap";
|
||||
text = ''
|
||||
set(CMAKE_SYSTEM_NAME ${systemName})
|
||||
set(CMAKE_SYSTEM_VERSION 1)
|
||||
set(CMAKE_CROSSCOMPILING TRUE)
|
||||
'';
|
||||
};
|
||||
in (pkgs.stdenv.override {
|
||||
cc = stdenv.cc.override { extraPackages = [ ]; };
|
||||
}).mkDerivation {
|
||||
name = "libretro";
|
||||
src = ./libretro;
|
||||
|
||||
nativeBuildInputs = [ buildPackages.cmake ];
|
||||
buildInputs = [ retro68.multiversal ];
|
||||
|
||||
buildCommand = ''
|
||||
echo "Build command."
|
||||
cmake $src \
|
||||
-DCMAKE_INSTALL_PREFIX=$out \
|
||||
-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_TOOLCHAIN_FILE=${toolchain}
|
||||
cmake --build .
|
||||
cmake --build . --target install
|
||||
'';
|
||||
};
|
||||
|
||||
console = with pkgs;
|
||||
stdenv.mkDerivation {
|
||||
name = "retro68.console";
|
||||
src = ./Console;
|
||||
|
||||
nativeBuildInputs = [ buildPackages.cmake ];
|
||||
};
|
||||
|
||||
samples = with pkgs;
|
||||
let
|
||||
individualSamples = lib.mapAttrs (key: path:
|
||||
stdenv.mkDerivation {
|
||||
name = "retro68.samples." + key;
|
||||
src = path;
|
||||
nativeBuildInputs = [ buildPackages.ninja buildPackages.cmake ];
|
||||
buildInputs = [ retro68.console ];
|
||||
buildCommand = ''
|
||||
mkdir build
|
||||
cd build
|
||||
cmake $src -G Ninja
|
||||
ninja
|
||||
mkdir -p $out/Applications
|
||||
mkdir -p $out/Applications/.finf
|
||||
mkdir -p $out/Applications/.rsrc
|
||||
|
||||
cp *.APPL $out/Applications
|
||||
cp .finf/*.APPL $out/Applications/.finf
|
||||
cp .rsrc/*.APPL $out/Applications/.rsrc
|
||||
for f in *.APPL; do
|
||||
cp $'' + ''
|
||||
{f%.APPL}.bin $out/Applications
|
||||
done
|
||||
'';
|
||||
}) ({
|
||||
dialog = ./Samples/Dialog;
|
||||
helloworld = ./Samples/HelloWorld;
|
||||
mpwtool = ./Samples/MPWTool;
|
||||
raytracer = ./Samples/Raytracer;
|
||||
#systemextension = ./Samples/SystemExtension;
|
||||
wdef = ./Samples/WDEF;
|
||||
} // lib.optionalAttrs
|
||||
(targetPlatform.cmakeSystemName != "Retro68") {
|
||||
sharedlibrary = ./Samples/SharedLibrary;
|
||||
} // lib.optionalAttrs
|
||||
(targetPlatform.cmakeSystemName == "Retro68") {
|
||||
launcher = ./Samples/Launcher;
|
||||
});
|
||||
in runCommand "retro68.samples" { } ''
|
||||
mkdir -p $out/Applications
|
||||
mkdir -p $out/Applications/.rsrc
|
||||
mkdir -p $out/Applications/.finf
|
||||
|
||||
${lib.concatMapStrings (x: ''
|
||||
cp -r ${lib.escapeShellArg x}/Applications $out/
|
||||
'') (builtins.attrValues individualSamples)}
|
||||
'' // individualSamples;
|
||||
|
||||
launchapplserver = with pkgs; stdenvUniversal.mkDerivation {
|
||||
name = "retro68.launchapplserver";
|
||||
src = ./LaunchAPPL;
|
||||
nativeBuildInputs = [ buildPackages.ninja buildPackages.cmake ];
|
||||
installPhase = ''
|
||||
mkdir $out
|
||||
mkdir -p $out/Applications
|
||||
mkdir -p $out/Applications/.finf
|
||||
mkdir -p $out/Applications/.rsrc
|
||||
|
||||
cp Server/LaunchAPPLServer.APPL $out/Applications
|
||||
cp Server/.finf/LaunchAPPLServer.APPL $out/Applications/.finf
|
||||
cp Server/.rsrc/LaunchAPPLServer.APPL $out/Applications/.rsrc
|
||||
cp Server/LaunchAPPLServer.bin $out/Applications
|
||||
'';
|
||||
};
|
||||
};
|
||||
} // prev.lib.optionalAttrs (prev.targetPlatform ? retro68) {
|
||||
|
||||
# ----------- Binutils & GCC wrapped for nixpkgs -------------
|
||||
|
||||
# binutils -- binutils with the wrappers provided by nixpkgs
|
||||
binutils =
|
||||
pkgs.wrapBintoolsWith { bintools = pkgs.retro68.binutils_unwrapped; };
|
||||
|
||||
# gcc -- gcc with the wrappers provided by nixpkgs
|
||||
gcc = pkgs.wrapCCWith {
|
||||
cc = pkgs.retro68.gcc_unwrapped;
|
||||
|
||||
# don't allow nix to add options for hardening
|
||||
extraBuildCommands = ''
|
||||
echo "" > $out/nix-support/add-hardening.sh
|
||||
'';
|
||||
|
||||
extraPackages = with pkgs.targetPackages.retro68; [
|
||||
multiversal
|
||||
import_libraries
|
||||
libretro
|
||||
setup_hook
|
||||
];
|
||||
};
|
||||
|
||||
stdenvUniversal = pkgs.stdenv.override {
|
||||
cc = pkgs.stdenv.cc.override {
|
||||
extraPackages = with pkgs.retro68; [
|
||||
universal
|
||||
import_libraries
|
||||
libretro
|
||||
setup_hook
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
# no separate libc package for now
|
||||
libcCrossChooser = name:
|
||||
if name == "retro68" then null else prev.libcCrossChooser name;
|
||||
|
||||
};
|
||||
|
||||
pkgs = import <nixpkgs> {
|
||||
overlaidPkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ overlay ];
|
||||
};
|
||||
|
||||
crossPkgs = pkgs.lib.mapAttrs (name: plat:
|
||||
import <nixpkgs> {
|
||||
crossPkgs = lib.mapAttrs (name: plat:
|
||||
import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ overlay ];
|
||||
crossSystem = plat;
|
||||
config = { allowUnsupportedSystem = true; };
|
||||
}) retroPlatforms;
|
||||
|
||||
shell = pkgs.lib.mapAttrs (name: cross:
|
||||
shell = lib.mapAttrs (name: cross:
|
||||
cross.mkShell {
|
||||
nativeBuildInputs = with pkgs; [
|
||||
nativeBuildInputs = with overlaidPkgs; [
|
||||
retro68.hfsutils
|
||||
retro68.tools
|
||||
cmake
|
||||
|
@ -488,5 +44,5 @@ let
|
|||
|
||||
in shell.m68k // shell // {
|
||||
inherit overlay;
|
||||
inherit (pkgs) retro68;
|
||||
inherit (overlaidPkgs) retro68;
|
||||
}
|
||||
|
|
280
nix/overlay.nix
Normal file
280
nix/overlay.nix
Normal file
|
@ -0,0 +1,280 @@
|
|||
{ multiversal_src }:
|
||||
pkgs: prevPkgs:
|
||||
{
|
||||
retro68 = pkgs.lib.makeScope pkgs.newScope (self:
|
||||
{
|
||||
platforms = import ./platforms.nix;
|
||||
|
||||
monolithic = with pkgs;
|
||||
stdenv.mkDerivation {
|
||||
name = "retro68.monolithic";
|
||||
src = ../.;
|
||||
nativeBuildInputs = [ cmake bison flex ruby ninja bash ];
|
||||
buildInputs = [ boost gmp mpfr libmpc zlib ]
|
||||
++ lib.optional hostPlatform.isDarwin
|
||||
darwin.apple_sdk.frameworks.ApplicationServices;
|
||||
buildCommand = ''
|
||||
bash $src/build-toolchain.bash --ninja --prefix=$out --no-carbon
|
||||
'';
|
||||
hardeningDisable = [ "format" ];
|
||||
};
|
||||
|
||||
# ----------- Native Tools -------------
|
||||
# hfsutils -- Utilities for manipulating HFS volumes & disk images.
|
||||
hfsutils = with pkgs;
|
||||
stdenv.mkDerivation {
|
||||
name = "retro68.hfsutils";
|
||||
srcs = ../hfsutils;
|
||||
|
||||
preConfigure = ''
|
||||
mkdir -p $out/bin
|
||||
mkdir -p $out/lib
|
||||
mkdir -p $out/include
|
||||
mkdir -p $out/share/man/man1
|
||||
'';
|
||||
configureFlags = [ "--mandir=$(out)/share/man" "--enable-devlibs" ];
|
||||
};
|
||||
|
||||
# tools -- native tools that are part of Retro68
|
||||
tools = with pkgs;
|
||||
stdenv.mkDerivation {
|
||||
name = "retro68.tools";
|
||||
src = nix-gitignore.gitignoreSource [
|
||||
"/*"
|
||||
"!/CMakeLists.txt"
|
||||
"!/libelf" # should perhaps use nixpkg's libelf instead?
|
||||
"!/cmake"
|
||||
"!/LaunchAPPL"
|
||||
"!/libretro"
|
||||
"!/PEFTools"
|
||||
"!/ResourceFiles"
|
||||
"!/Rez"
|
||||
"!/Elf2Mac"
|
||||
"!/ConvertObj"
|
||||
"!/ConvertDiskImage"
|
||||
] ./..;
|
||||
|
||||
nativeBuildInputs = [ cmake bison flex ];
|
||||
buildInputs = [ boost zlib retro68.hfsutils ]
|
||||
++ lib.optional hostPlatform.isDarwin
|
||||
darwin.apple_sdk.frameworks.ApplicationServices;
|
||||
};
|
||||
|
||||
} // prevPkgs.lib.optionalAttrs (prevPkgs.targetPlatform ? retro68) {
|
||||
|
||||
# ----------- Binutils & GCC -------------
|
||||
|
||||
# binutils_unwrapped -- binutils, without any wrappers
|
||||
binutils_unwrapped = with pkgs;
|
||||
stdenv.mkDerivation rec {
|
||||
name = "retro68.binutils_unwrapped";
|
||||
src = ../binutils;
|
||||
|
||||
configureFlags =
|
||||
[ "--target=${stdenv.targetPlatform.config}" "--disable-doc" ]
|
||||
++ stdenv.targetPlatform.retro68BinutilsConfig or [ ];
|
||||
enableParallelBuilding = true;
|
||||
|
||||
postInstall = let
|
||||
ld = "$out/bin/${stdenv.targetPlatform.config}-ld";
|
||||
ld_real = "$out/bin/${stdenv.targetPlatform.config}-ld.real";
|
||||
|
||||
in ''
|
||||
mv ${ld} ${ld_real}
|
||||
|
||||
echo "#!${stdenv.shell}" > ${ld}
|
||||
echo "exec \$'' + ''
|
||||
{RETRO68_LD_WRAPPER_${stdenv.targetPlatform.cmakeSystemName}-${ld_real}} \"\$@\"" >> ${ld}
|
||||
chmod +x ${ld}
|
||||
|
||||
rm $out/${stdenv.targetPlatform.config}/bin/ld
|
||||
ln -s ${ld} $out/${stdenv.targetPlatform.config}/bin/ld
|
||||
'';
|
||||
};
|
||||
|
||||
# gcc -- gcc, without any wrappers
|
||||
gcc_unwrapped = with pkgs;
|
||||
stdenv.mkDerivation rec {
|
||||
name = "retro68.gcc_unwrapped";
|
||||
src = ../gcc;
|
||||
buildInputs = [ retro68.binutils_unwrapped gmp mpfr libmpc ];
|
||||
configureFlags = [
|
||||
"--target=${stdenv.targetPlatform.config}"
|
||||
"--enable-languages=c,c++"
|
||||
"--disable-libssp"
|
||||
"MAKEINFO=missing"
|
||||
] ++ stdenv.targetPlatform.retro68GccConfig or [ ];
|
||||
hardeningDisable = [ "format" ];
|
||||
enableParallelBuilding = true;
|
||||
|
||||
# nix does in-source builds by default, and something breaks
|
||||
buildCommand = ''
|
||||
mkdir -p $out/${stdenv.targetPlatform.config}/bin
|
||||
ln -s ${retro68.binutils_unwrapped}/${stdenv.targetPlatform.config}/bin/* $out/${stdenv.targetPlatform.config}/bin/
|
||||
|
||||
export target_configargs="--disable-nls --enable-libstdcxx-dual-abi=no --disable-libstdcxx-verbose"
|
||||
$src/configure ${builtins.toString configureFlags} --prefix=$out
|
||||
make -j$NIX_BUILD_CORES
|
||||
make install
|
||||
'';
|
||||
};
|
||||
|
||||
} // prevPkgs.lib.optionalAttrs (prevPkgs.hostPlatform ? retro68) {
|
||||
|
||||
setup_hook = let
|
||||
systemName = pkgs.targetPlatform.cmakeSystemName;
|
||||
toolchain = pkgs.writeTextFile {
|
||||
name = "retro68.cmake-toolchain";
|
||||
text = ''
|
||||
set(CMAKE_SYSTEM_NAME ${systemName})
|
||||
set(CMAKE_SYSTEM_VERSION 1)
|
||||
set(CMAKE_CROSSCOMPILING TRUE)
|
||||
|
||||
set(REZ "${pkgs.buildPackages.retro68.tools}/bin/Rez" )
|
||||
set(REZ_TEMPLATES_PATH ${pkgs.retro68.libretro}/RIncludes)
|
||||
|
||||
set(MAKE_PEF "${pkgs.buildPackages.retro68.tools}/bin/MakePEF" )
|
||||
|
||||
include(${../cmake/add_application.cmake})
|
||||
'' + (pkgs.lib.optionalString (systemName == "RetroCarbon") ''
|
||||
set(CMAKE_EXE_LINKER_FLAGS_INIT "-carbon")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-carbon")
|
||||
add_definitions( -DTARGET_API_MAC_CARBON=1 )
|
||||
'');
|
||||
};
|
||||
hook = pkgs.writeTextFile {
|
||||
name = "retro68.setup_hook";
|
||||
text = ''
|
||||
export CMAKE_TOOLCHAIN_FILE=${toolchain}
|
||||
|
||||
retro68_addRIncludes() {
|
||||
case $depHostOffset in
|
||||
-1) local role='BUILD_' ;;
|
||||
0) local role="" ;;
|
||||
1) local role='TARGET_' ;;
|
||||
*) echo "retro68_addRIncludes: Error: Cannot be used with $depHostOffset-offset deps" >2;
|
||||
return 1 ;;
|
||||
esac
|
||||
|
||||
if [[ -d "$1/RIncludes" ]]; then
|
||||
export REZ_INCLUDE_PATH+=":$1/RIncludes"
|
||||
fi
|
||||
}
|
||||
|
||||
addEnvHooks "$targetOffset" retro68_addRIncludes
|
||||
|
||||
'' + (pkgs.lib.optionalString (systemName == "Retro68") ''
|
||||
export RETRO68_LD_WRAPPER_Retro68="${pkgs.buildPackages.retro68.tools}/bin/Elf2Mac"
|
||||
export RETRO68_REAL_LD="${pkgs.buildPackages.retro68.binutils_unwrapped}/bin/m68k-apple-macos-ld.real"
|
||||
'');
|
||||
};
|
||||
in pkgs.makeSetupHook { } hook;
|
||||
|
||||
# ----------- Retro68 core libraries -------------
|
||||
|
||||
# multiversal -- multiversal interfaces
|
||||
multiversal = with pkgs;
|
||||
(stdenv.override {
|
||||
cc = stdenv.cc.override { extraPackages = [ ]; };
|
||||
}).mkDerivation {
|
||||
name = "retro68.multiversal";
|
||||
src = multiversal_src;
|
||||
nativeBuildInputs = [ buildPackages.ruby ];
|
||||
buildCommand = ''
|
||||
echo $src
|
||||
build=`pwd`
|
||||
(cd $src && ruby make-multiverse.rb -G CIncludes -o "$build")
|
||||
mkdir $out
|
||||
cp -r CIncludes $out/include
|
||||
cp -r RIncludes $out/
|
||||
'' + (if stdenv.targetPlatform.system == "m68k-macos" then ''
|
||||
cp -r lib68k $out/lib
|
||||
'' else
|
||||
"");
|
||||
};
|
||||
|
||||
|
||||
import_libraries = with pkgs;
|
||||
if stdenvNoCC.targetPlatform.system != "m68k-macos" then
|
||||
stdenvNoCC.mkDerivation {
|
||||
name = "retro68.import_libraries";
|
||||
src = ../ImportLibraries;
|
||||
buildCommand = ''
|
||||
mkdir -p $out/lib
|
||||
cp $src/*.a $out/lib/
|
||||
'';
|
||||
}
|
||||
else
|
||||
null;
|
||||
|
||||
libretro = with pkgs;
|
||||
let
|
||||
systemName = pkgs.targetPlatform.cmakeSystemName;
|
||||
toolchain = pkgs.writeTextFile {
|
||||
name = "retro68-cmake-toolchain-bootstrap";
|
||||
text = ''
|
||||
set(CMAKE_SYSTEM_NAME ${systemName})
|
||||
set(CMAKE_SYSTEM_VERSION 1)
|
||||
set(CMAKE_CROSSCOMPILING TRUE)
|
||||
'';
|
||||
};
|
||||
in (pkgs.stdenv.override {
|
||||
cc = stdenv.cc.override { extraPackages = [ ]; };
|
||||
}).mkDerivation {
|
||||
name = "libretro";
|
||||
src = ../libretro;
|
||||
|
||||
nativeBuildInputs = [ buildPackages.cmake ];
|
||||
buildInputs = [ retro68.multiversal ];
|
||||
|
||||
buildCommand = ''
|
||||
echo "Build command."
|
||||
cmake $src \
|
||||
-DCMAKE_INSTALL_PREFIX=$out \
|
||||
-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_TOOLCHAIN_FILE=${toolchain}
|
||||
cmake --build .
|
||||
cmake --build . --target install
|
||||
'';
|
||||
};
|
||||
|
||||
console = with pkgs;
|
||||
stdenv.mkDerivation {
|
||||
name = "retro68.console";
|
||||
src = ../Console;
|
||||
|
||||
nativeBuildInputs = [ buildPackages.cmake ];
|
||||
};
|
||||
|
||||
});
|
||||
} // prevPkgs.lib.optionalAttrs (prevPkgs.targetPlatform ? retro68) {
|
||||
|
||||
# ----------- Binutils & GCC wrapped for nixpkgs -------------
|
||||
|
||||
# binutils -- binutils with the wrappers provided by nixpkgs
|
||||
binutils =
|
||||
pkgs.wrapBintoolsWith { bintools = pkgs.retro68.binutils_unwrapped; };
|
||||
|
||||
# gcc -- gcc with the wrappers provided by nixpkgs
|
||||
gcc = pkgs.wrapCCWith {
|
||||
cc = pkgs.retro68.gcc_unwrapped;
|
||||
|
||||
# don't allow nix to add options for hardening
|
||||
extraBuildCommands = ''
|
||||
echo "" > $out/nix-support/add-hardening.sh
|
||||
'';
|
||||
|
||||
extraPackages = with pkgs.targetPackages.retro68; [
|
||||
multiversal
|
||||
import_libraries
|
||||
libretro
|
||||
setup_hook
|
||||
];
|
||||
};
|
||||
|
||||
# no separate libc package for now
|
||||
libcCrossChooser = name:
|
||||
if name == "retro68" then null else prevPkgs.libcCrossChooser name;
|
||||
|
||||
}
|
75
nix/platforms.nix
Normal file
75
nix/platforms.nix
Normal file
|
@ -0,0 +1,75 @@
|
|||
{
|
||||
m68k = {
|
||||
system = "m68k-macos";
|
||||
config = "m68k-apple-macos";
|
||||
libc = "retro68";
|
||||
parsed = {
|
||||
cpu = {
|
||||
name = "m68k";
|
||||
bits = 32;
|
||||
significantByte = { name = "bigEndian"; };
|
||||
family = "m68k";
|
||||
};
|
||||
kernel = {
|
||||
name = "macos";
|
||||
execFormat = { name = "unknown"; };
|
||||
};
|
||||
};
|
||||
bfdEmulation = "m68k";
|
||||
isStatic = true;
|
||||
|
||||
retro68GccConfig = [ "--with-arch=m68k" "--with-cpu=m68000" ];
|
||||
retro68 = true;
|
||||
cmakeSystemName = "Retro68";
|
||||
};
|
||||
powerpc = {
|
||||
system = "powerpc-macos";
|
||||
config = "powerpc-apple-macos";
|
||||
libc = "retro68";
|
||||
parsed = {
|
||||
cpu = {
|
||||
name = "powerpc";
|
||||
bits = 32;
|
||||
significantByte = { name = "bigEndian"; };
|
||||
family = "power";
|
||||
};
|
||||
kernel = {
|
||||
name = "macos";
|
||||
execFormat = { name = "unknown"; };
|
||||
};
|
||||
};
|
||||
|
||||
isStatic = true;
|
||||
retro68BinutilsConfig = [ "--disable-plugins" ];
|
||||
retro68GccConfig = [ "--disable-lto" ];
|
||||
retro68 = true;
|
||||
cmakeSystemName = "RetroPPC";
|
||||
};
|
||||
carbon = {
|
||||
system = "powerpc-carbon";
|
||||
config = "powerpc-apple-macos";
|
||||
libc = "retro68";
|
||||
parsed = {
|
||||
cpu = {
|
||||
name = "powerpc";
|
||||
bits = 32;
|
||||
significantByte = { name = "bigEndian"; };
|
||||
family = "power";
|
||||
};
|
||||
kernel = {
|
||||
name = "carbon";
|
||||
execFormat = { name = "unknown"; };
|
||||
};
|
||||
};
|
||||
isStatic = true;
|
||||
retro68BinutilsConfig = [ "--disable-plugins" ];
|
||||
retro68GccConfig = [ "--disable-lto" ];
|
||||
retro68 = true;
|
||||
cmakeSystemName = "RetroCarbon";
|
||||
};
|
||||
|
||||
isStatic = true;
|
||||
retro68BinutilsConfig = [ "--disable-plugins" ];
|
||||
retro68GccConfig = [ "--disable-lto" ];
|
||||
retro68 = true;
|
||||
}
|
47
nix/samples.nix
Normal file
47
nix/samples.nix
Normal file
|
@ -0,0 +1,47 @@
|
|||
pkgs: prevPkgs: {
|
||||
retro68 = prevPkgs.retro68.overrideScope' (self: prevRetro: {
|
||||
samples = with pkgs;
|
||||
let
|
||||
individualSamples = lib.mapAttrs (key: path:
|
||||
stdenv.mkDerivation {
|
||||
name = "retro68.samples." + key;
|
||||
src = path;
|
||||
nativeBuildInputs = [ buildPackages.ninja buildPackages.cmake ];
|
||||
buildInputs = [ retro68.console ];
|
||||
installPhase = ''
|
||||
mkdir $out
|
||||
cp *.bin $out/
|
||||
'';
|
||||
}) ({
|
||||
dialog = ../Samples/Dialog;
|
||||
helloworld = ../Samples/HelloWorld;
|
||||
raytracer = ../Samples/Raytracer;
|
||||
} // lib.optionalAttrs (targetPlatform.cmakeSystemName != "RetroCarbon") {
|
||||
mpwtool = ../Samples/MPWTool;
|
||||
wdef = ../Samples/WDEF;
|
||||
} // lib.optionalAttrs (targetPlatform.cmakeSystemName != "Retro68") {
|
||||
sharedlibrary = ../Samples/SharedLibrary;
|
||||
} // lib.optionalAttrs (targetPlatform.cmakeSystemName == "Retro68") {
|
||||
systemextension = ../Samples/SystemExtension;
|
||||
launcher = ../Samples/Launcher;
|
||||
});
|
||||
in runCommand "retro68.samples" { } ''
|
||||
mkdir -p $out/
|
||||
|
||||
${lib.concatMapStrings (x: ''
|
||||
cp -r ${lib.escapeShellArg x}/*.bin $out/
|
||||
'') (builtins.attrValues individualSamples)}
|
||||
'' // individualSamples;
|
||||
|
||||
launchapplserver = with pkgs;
|
||||
stdenvUniversal.mkDerivation {
|
||||
name = "retro68.launchapplserver";
|
||||
src = ../LaunchAPPL;
|
||||
nativeBuildInputs = [ buildPackages.ninja buildPackages.cmake ];
|
||||
installPhase = ''
|
||||
mkdir $out
|
||||
cp *.bin $out/
|
||||
'';
|
||||
};
|
||||
});
|
||||
}
|
38
nix/sources.json
Normal file
38
nix/sources.json
Normal file
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"multiversal": {
|
||||
"branch": "master",
|
||||
"description": "Multiversal Interfaces for Classic MacOS",
|
||||
"homepage": null,
|
||||
"owner": "autc04",
|
||||
"repo": "multiversal",
|
||||
"rev": "ce33b1bada9b0acb14021c21ac916927c757d525",
|
||||
"sha256": "1fsyjad4kwsqgr2mlx9dfl7z8z42cf2sgw1arqmci47zhaj8is1f",
|
||||
"type": "tarball",
|
||||
"url": "https://github.com/autc04/multiversal/archive/ce33b1bada9b0acb14021c21ac916927c757d525.tar.gz",
|
||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||
},
|
||||
"niv": {
|
||||
"branch": "master",
|
||||
"description": "Easy dependency management for Nix projects",
|
||||
"homepage": "https://github.com/nmattia/niv",
|
||||
"owner": "nmattia",
|
||||
"repo": "niv",
|
||||
"rev": "5830a4dd348d77e39a0f3c4c762ff2663b602d4c",
|
||||
"sha256": "1d3lsrqvci4qz2hwjrcnd8h5vfkg8aypq3sjd4g3izbc8frwz5sm",
|
||||
"type": "tarball",
|
||||
"url": "https://github.com/nmattia/niv/archive/5830a4dd348d77e39a0f3c4c762ff2663b602d4c.tar.gz",
|
||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||
},
|
||||
"nixpkgs": {
|
||||
"branch": "release-21.11",
|
||||
"description": "Nix Packages collection",
|
||||
"homepage": "",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "d1e59cfc49961e121583abe32e2f3db1550fbcff",
|
||||
"sha256": "03ldf1dlxqf3g8qh9x5vp6vd9zvvr481fyjds111imll69y60wpm",
|
||||
"type": "tarball",
|
||||
"url": "https://github.com/NixOS/nixpkgs/archive/d1e59cfc49961e121583abe32e2f3db1550fbcff.tar.gz",
|
||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||
}
|
||||
}
|
174
nix/sources.nix
Normal file
174
nix/sources.nix
Normal file
|
@ -0,0 +1,174 @@
|
|||
# This file has been generated by Niv.
|
||||
|
||||
let
|
||||
|
||||
#
|
||||
# The fetchers. fetch_<type> fetches specs of type <type>.
|
||||
#
|
||||
|
||||
fetch_file = pkgs: name: spec:
|
||||
let
|
||||
name' = sanitizeName name + "-src";
|
||||
in
|
||||
if spec.builtin or true then
|
||||
builtins_fetchurl { inherit (spec) url sha256; name = name'; }
|
||||
else
|
||||
pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
|
||||
|
||||
fetch_tarball = pkgs: name: spec:
|
||||
let
|
||||
name' = sanitizeName name + "-src";
|
||||
in
|
||||
if spec.builtin or true then
|
||||
builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
|
||||
else
|
||||
pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
|
||||
|
||||
fetch_git = name: spec:
|
||||
let
|
||||
ref =
|
||||
if spec ? ref then spec.ref else
|
||||
if spec ? branch then "refs/heads/${spec.branch}" else
|
||||
if spec ? tag then "refs/tags/${spec.tag}" else
|
||||
abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
|
||||
in
|
||||
builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; };
|
||||
|
||||
fetch_local = spec: spec.path;
|
||||
|
||||
fetch_builtin-tarball = name: throw
|
||||
''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
|
||||
$ niv modify ${name} -a type=tarball -a builtin=true'';
|
||||
|
||||
fetch_builtin-url = name: throw
|
||||
''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
|
||||
$ niv modify ${name} -a type=file -a builtin=true'';
|
||||
|
||||
#
|
||||
# Various helpers
|
||||
#
|
||||
|
||||
# https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695
|
||||
sanitizeName = name:
|
||||
(
|
||||
concatMapStrings (s: if builtins.isList s then "-" else s)
|
||||
(
|
||||
builtins.split "[^[:alnum:]+._?=-]+"
|
||||
((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name)
|
||||
)
|
||||
);
|
||||
|
||||
# The set of packages used when specs are fetched using non-builtins.
|
||||
mkPkgs = sources: system:
|
||||
let
|
||||
sourcesNixpkgs =
|
||||
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; };
|
||||
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
|
||||
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
|
||||
in
|
||||
if builtins.hasAttr "nixpkgs" sources
|
||||
then sourcesNixpkgs
|
||||
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
|
||||
import <nixpkgs> {}
|
||||
else
|
||||
abort
|
||||
''
|
||||
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
|
||||
add a package called "nixpkgs" to your sources.json.
|
||||
'';
|
||||
|
||||
# The actual fetching function.
|
||||
fetch = pkgs: name: spec:
|
||||
|
||||
if ! builtins.hasAttr "type" spec then
|
||||
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
|
||||
else if spec.type == "file" then fetch_file pkgs name spec
|
||||
else if spec.type == "tarball" then fetch_tarball pkgs name spec
|
||||
else if spec.type == "git" then fetch_git name spec
|
||||
else if spec.type == "local" then fetch_local spec
|
||||
else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
|
||||
else if spec.type == "builtin-url" then fetch_builtin-url name
|
||||
else
|
||||
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
|
||||
|
||||
# If the environment variable NIV_OVERRIDE_${name} is set, then use
|
||||
# the path directly as opposed to the fetched source.
|
||||
replace = name: drv:
|
||||
let
|
||||
saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
|
||||
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
|
||||
in
|
||||
if ersatz == "" then drv else
|
||||
# this turns the string into an actual Nix path (for both absolute and
|
||||
# relative paths)
|
||||
if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
|
||||
|
||||
# Ports of functions for older nix versions
|
||||
|
||||
# a Nix version of mapAttrs if the built-in doesn't exist
|
||||
mapAttrs = builtins.mapAttrs or (
|
||||
f: set: with builtins;
|
||||
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
|
||||
);
|
||||
|
||||
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
|
||||
range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);
|
||||
|
||||
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
|
||||
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
|
||||
|
||||
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
|
||||
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
|
||||
concatMapStrings = f: list: concatStrings (map f list);
|
||||
concatStrings = builtins.concatStringsSep "";
|
||||
|
||||
# https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
|
||||
optionalAttrs = cond: as: if cond then as else {};
|
||||
|
||||
# fetchTarball version that is compatible between all the versions of Nix
|
||||
builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
|
||||
let
|
||||
inherit (builtins) lessThan nixVersion fetchTarball;
|
||||
in
|
||||
if lessThan nixVersion "1.12" then
|
||||
fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
|
||||
else
|
||||
fetchTarball attrs;
|
||||
|
||||
# fetchurl version that is compatible between all the versions of Nix
|
||||
builtins_fetchurl = { url, name ? null, sha256 }@attrs:
|
||||
let
|
||||
inherit (builtins) lessThan nixVersion fetchurl;
|
||||
in
|
||||
if lessThan nixVersion "1.12" then
|
||||
fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
|
||||
else
|
||||
fetchurl attrs;
|
||||
|
||||
# Create the final "sources" from the config
|
||||
mkSources = config:
|
||||
mapAttrs (
|
||||
name: spec:
|
||||
if builtins.hasAttr "outPath" spec
|
||||
then abort
|
||||
"The values in sources.json should not have an 'outPath' attribute"
|
||||
else
|
||||
spec // { outPath = replace name (fetch config.pkgs name spec); }
|
||||
) config.sources;
|
||||
|
||||
# The "config" used by the fetchers
|
||||
mkConfig =
|
||||
{ sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
|
||||
, sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
|
||||
, system ? builtins.currentSystem
|
||||
, pkgs ? mkPkgs sources system
|
||||
}: rec {
|
||||
# The sources, i.e. the attribute set of spec name to spec
|
||||
inherit sources;
|
||||
|
||||
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
|
||||
inherit pkgs;
|
||||
};
|
||||
|
||||
in
|
||||
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
|
58
nix/universal.nix
Normal file
58
nix/universal.nix
Normal file
|
@ -0,0 +1,58 @@
|
|||
pkgs: prevPkgs:
|
||||
{
|
||||
retro68 = if !(prevPkgs.hostPlatform ? retro68) then
|
||||
prevPkgs.retro68
|
||||
else
|
||||
prevPkgs.retro68.overrideScope' (self: prevRetro: {
|
||||
|
||||
mpw_35_gm = with pkgs;
|
||||
fetchurl {
|
||||
url =
|
||||
"https://web.archive.org/web/20210309154524/https://staticky.com/mirrors/ftp.apple.com/developer/Tool_Chest/Core_Mac_OS_Tools/MPW_etc./MPW-GM_Images/MPW-GM.img.bin";
|
||||
sha256 = "0wm8dwmm0cpp8px27in564ih27sn5vbydz3jqpzwh04qpfazmfwr";
|
||||
};
|
||||
|
||||
universal = with pkgs;
|
||||
stdenvNoCC.mkDerivation {
|
||||
name = "retro68.universal";
|
||||
src = retro68.mpw_35_gm;
|
||||
nativeBuildInputs = with buildPackages.retro68; [
|
||||
tools
|
||||
hfsutils
|
||||
binutils_unwrapped
|
||||
];
|
||||
|
||||
buildCommand = ''
|
||||
ConvertDiskImage $src decoded.dsk
|
||||
export HOME=.
|
||||
hmount decoded.dsk
|
||||
mkdir -p CIncludes RIncludes lib68
|
||||
hcopy -t 'MPW-GM:MPW-GM:Interfaces&Libraries:Interfaces:CIncludes:*.h' CIncludes/
|
||||
hcopy -t 'MPW-GM:MPW-GM:Interfaces&Libraries:Interfaces:RIncludes:*.r' RIncludes/
|
||||
mkdir -p $out/include $out/RIncludes
|
||||
bash ${../prepare-headers.sh} CIncludes $out/include
|
||||
bash ${../prepare-rincludes.sh} RIncludes $out/RIncludes
|
||||
|
||||
hcopy -r 'MPW-GM:MPW-GM:Interfaces&Libraries:Libraries:Libraries:*.o' lib68
|
||||
|
||||
. ${../interfaces-and-libraries.sh}
|
||||
M68KLIBRARIES=lib68
|
||||
setup68KLibraries $out/
|
||||
mv $out/lib68k $out/lib
|
||||
'';
|
||||
};
|
||||
});
|
||||
} // prevPkgs.lib.optionalAttrs (prevPkgs.targetPlatform ? retro68) {
|
||||
|
||||
stdenvUniversal = pkgs.stdenv.override {
|
||||
cc = pkgs.stdenv.cc.override {
|
||||
extraPackages = with pkgs.retro68; [
|
||||
universal
|
||||
import_libraries
|
||||
libretro
|
||||
setup_hook
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user