Merge pull request #146 from autc04/nix
Support for the `nix` package manager.
This commit is contained in:
commit
aef75b358f
|
@ -6,6 +6,9 @@ indent_style = space
|
|||
tab_width = 4
|
||||
charset = utf-8
|
||||
|
||||
[*.nix]
|
||||
tab_width = 2
|
||||
|
||||
[InterfacesAndLibraries/**/*]
|
||||
indent_style = tab
|
||||
|
||||
|
|
|
@ -5,4 +5,5 @@ CMakeLists.txt.user
|
|||
InterfacesAndLibraries
|
||||
.DS_Store
|
||||
.vscode
|
||||
result
|
||||
/result
|
||||
/result-*
|
||||
|
|
|
@ -41,13 +41,12 @@ using std::string;
|
|||
using std::vector;
|
||||
using std::ofstream;
|
||||
|
||||
string argvZero;
|
||||
string realLdPath;
|
||||
|
||||
void RealLD(vector<string> args)
|
||||
{
|
||||
vector<const char*> argv;
|
||||
string realLD = argvZero + ".real";
|
||||
argv.push_back(realLD.c_str());
|
||||
argv.push_back(realLdPath.c_str());
|
||||
for(string& s : args)
|
||||
argv.push_back(s.c_str());
|
||||
argv.push_back(NULL);
|
||||
|
@ -90,134 +89,132 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
vector<string> args;
|
||||
std::copy(argv + 1, argv+argc, std::back_inserter(args));
|
||||
argvZero = argv[0];
|
||||
realLdPath = string(argv[0]) + ".real";
|
||||
|
||||
if(boost::algorithm::ends_with(argv[0], "ld"))
|
||||
if (char *path = getenv("RETRO68_REAL_LD"))
|
||||
realLdPath = path;
|
||||
|
||||
string outputFile = "a.out";
|
||||
string entryPoint = "_start";
|
||||
bool elf2mac = false;
|
||||
bool flatoutput = false;
|
||||
bool segments = true;
|
||||
bool stripMacsbug = false;
|
||||
bool saveLdScript = false;
|
||||
|
||||
SegmentMap segmentMap;
|
||||
|
||||
vector<string> args2;
|
||||
for(auto p = args.begin(), e = args.end(); p != e; ++p)
|
||||
{
|
||||
string outputFile = "a.out";
|
||||
string entryPoint = "_start";
|
||||
bool elf2mac = false;
|
||||
bool flatoutput = false;
|
||||
bool segments = true;
|
||||
bool stripMacsbug = false;
|
||||
bool saveLdScript = false;
|
||||
|
||||
SegmentMap segmentMap;
|
||||
|
||||
vector<string> args2;
|
||||
for(auto p = args.begin(), e = args.end(); p != e; ++p)
|
||||
if(*p == "--elf2mac-real-ld")
|
||||
{
|
||||
if(*p == "-o")
|
||||
{
|
||||
++p;
|
||||
if(p == e)
|
||||
errx(EXIT_FAILURE, "-o missing argument");
|
||||
outputFile = *p;
|
||||
}
|
||||
else if(boost::algorithm::starts_with(*p, "-o"))
|
||||
{
|
||||
outputFile = (*p).substr(2);
|
||||
}
|
||||
else if(*p == "-elf2mac" || *p == "--elf2mac")
|
||||
{
|
||||
elf2mac = true;
|
||||
}
|
||||
else if(*p == "-e")
|
||||
{
|
||||
++p;
|
||||
if(p == e)
|
||||
errx(EXIT_FAILURE, "-e missing argument");
|
||||
entryPoint = *p;
|
||||
}
|
||||
else if(boost::algorithm::starts_with(*p, "-e"))
|
||||
{
|
||||
entryPoint = (*p).substr(2);
|
||||
}
|
||||
else if(*p == "--mac-flat")
|
||||
{
|
||||
elf2mac = true;
|
||||
flatoutput = true;
|
||||
segments = false;
|
||||
}
|
||||
else if(*p == "--mac-single")
|
||||
{
|
||||
elf2mac = true;
|
||||
flatoutput = false;
|
||||
segments = false;
|
||||
}
|
||||
else if(*p == "--mac-segments")
|
||||
{
|
||||
elf2mac = true;
|
||||
if(flatoutput)
|
||||
errx(EXIT_FAILURE, "--mac-segments can't be used with --mac-flat");
|
||||
++p;
|
||||
if(p == e)
|
||||
errx(EXIT_FAILURE, "--mac-segments missing argument");
|
||||
segmentMap = SegmentMap(*p);
|
||||
}
|
||||
else if(*p == "--mac-strip-macsbug")
|
||||
{
|
||||
stripMacsbug = true;
|
||||
}
|
||||
else if(*p == "--mac-keep-ldscript")
|
||||
{
|
||||
saveLdScript = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
args2.push_back(*p);
|
||||
}
|
||||
++p;
|
||||
if(p == e)
|
||||
errx(EXIT_FAILURE, "--elf2mac-real-ld missing argument");
|
||||
realLdPath = *p;
|
||||
}
|
||||
|
||||
if(elf2mac)
|
||||
else if(*p == "-o")
|
||||
{
|
||||
char tmpfile[] = "/tmp/ldscriptXXXXXX";
|
||||
int fd = mkstemp(tmpfile);
|
||||
if(fd < 0)
|
||||
errx(EXIT_FAILURE, "can't create temp file");
|
||||
|
||||
{
|
||||
ofstream out(tmpfile);
|
||||
if(segments)
|
||||
{
|
||||
segmentMap.CreateLdScript(out, entryPoint, stripMacsbug);
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateFlatLdScript(out, entryPoint, stripMacsbug);
|
||||
}
|
||||
}
|
||||
|
||||
args2.push_back("-o");
|
||||
args2.push_back(outputFile + ".gdb");
|
||||
args2.push_back("-T");
|
||||
args2.push_back(tmpfile);
|
||||
RealLD(args2);
|
||||
if(saveLdScript)
|
||||
std::cerr << "Ld Script at: " << tmpfile << std::endl;
|
||||
else
|
||||
unlink(tmpfile);
|
||||
Object theObject(outputFile + ".gdb");
|
||||
++p;
|
||||
if(p == e)
|
||||
errx(EXIT_FAILURE, "-o missing argument");
|
||||
outputFile = *p;
|
||||
}
|
||||
else if(boost::algorithm::starts_with(*p, "-o"))
|
||||
{
|
||||
outputFile = (*p).substr(2);
|
||||
}
|
||||
else if(*p == "-elf2mac" || *p == "--elf2mac")
|
||||
{
|
||||
elf2mac = true;
|
||||
}
|
||||
else if(*p == "-e")
|
||||
{
|
||||
++p;
|
||||
if(p == e)
|
||||
errx(EXIT_FAILURE, "-e missing argument");
|
||||
entryPoint = *p;
|
||||
}
|
||||
else if(boost::algorithm::starts_with(*p, "-e"))
|
||||
{
|
||||
entryPoint = (*p).substr(2);
|
||||
}
|
||||
else if(*p == "--mac-flat")
|
||||
{
|
||||
elf2mac = true;
|
||||
flatoutput = true;
|
||||
segments = false;
|
||||
}
|
||||
else if(*p == "--mac-single")
|
||||
{
|
||||
elf2mac = true;
|
||||
flatoutput = false;
|
||||
segments = false;
|
||||
}
|
||||
else if(*p == "--mac-segments")
|
||||
{
|
||||
elf2mac = true;
|
||||
if(flatoutput)
|
||||
theObject.FlatCode(outputFile);
|
||||
else if(segments)
|
||||
theObject.MultiSegmentApp(outputFile, segmentMap);
|
||||
else
|
||||
theObject.SingleSegmentApp(outputFile);
|
||||
errx(EXIT_FAILURE, "--mac-segments can't be used with --mac-flat");
|
||||
++p;
|
||||
if(p == e)
|
||||
errx(EXIT_FAILURE, "--mac-segments missing argument");
|
||||
segmentMap = SegmentMap(*p);
|
||||
}
|
||||
else if(*p == "--mac-strip-macsbug")
|
||||
{
|
||||
stripMacsbug = true;
|
||||
}
|
||||
else if(*p == "--mac-keep-ldscript")
|
||||
{
|
||||
saveLdScript = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RealLD(args);
|
||||
args2.push_back(*p);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(elf2mac)
|
||||
{
|
||||
char tmpfile[] = "/tmp/ldscriptXXXXXX";
|
||||
int fd = mkstemp(tmpfile);
|
||||
if(fd < 0)
|
||||
errx(EXIT_FAILURE, "can't create temp file");
|
||||
|
||||
{
|
||||
ofstream out(tmpfile);
|
||||
if(segments)
|
||||
{
|
||||
segmentMap.CreateLdScript(out, entryPoint, stripMacsbug);
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateFlatLdScript(out, entryPoint, stripMacsbug);
|
||||
}
|
||||
}
|
||||
|
||||
args2.push_back("-o");
|
||||
args2.push_back(outputFile + ".gdb");
|
||||
args2.push_back("-T");
|
||||
args2.push_back(tmpfile);
|
||||
RealLD(args2);
|
||||
if(saveLdScript)
|
||||
std::cerr << "Ld Script at: " << tmpfile << std::endl;
|
||||
else
|
||||
unlink(tmpfile);
|
||||
Object theObject(outputFile + ".gdb");
|
||||
if(flatoutput)
|
||||
theObject.FlatCode(outputFile);
|
||||
else if(segments)
|
||||
theObject.MultiSegmentApp(outputFile, segmentMap);
|
||||
else
|
||||
theObject.SingleSegmentApp(outputFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(argc != 2)
|
||||
errx(EXIT_FAILURE, "usage : %s file-name ", argv[0]);
|
||||
Object theObject(argv[1]);
|
||||
SegmentMap segmentMap;
|
||||
theObject.MultiSegmentApp("out.bin", segmentMap);
|
||||
RealLD(args);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#define ResType MacResType
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#undef ResType
|
||||
|
||||
#if TARGET_CPU_PPC
|
||||
#ifdef __powerpc
|
||||
#include "Classic.h"
|
||||
#include "Launcher.h"
|
||||
|
||||
#define ResType MacResType
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#undef ResType
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
|
|
|
@ -9,10 +9,7 @@
|
|||
#include "Launcher.h"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
# define ResType MacResType
|
||||
# include <ApplicationServices/ApplicationServices.h>
|
||||
# undef ResType
|
||||
# if TARGET_CPU_PPC
|
||||
# ifdef __powerpc
|
||||
# include "Classic.h"
|
||||
# endif
|
||||
# include "Carbon.h"
|
||||
|
|
45
README.md
45
README.md
|
@ -22,6 +22,8 @@ after cloning. To get the latest changes, use
|
|||
git submodule update
|
||||
|
||||
|
||||
Note: There is now experimental support for the [Nix Package Manager](www.nixos.org). If you're a nix user, skip ahead to the [Using Retro68 with Nix](#using-retro68-with-nix) section.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Linux, Mac OS X or Windows (via Cygwin)
|
||||
|
@ -143,6 +145,49 @@ The `build-host`, `build-target`, `build-target-ppc` and `build-target-carbon`
|
|||
directories are CMake build directories generated from the top-level `CMakeLists.txt`,
|
||||
so you can also `cd` to one of these and run `make` separately if you've made changes.
|
||||
|
||||
Using Retro68 with Nix
|
||||
----------------------
|
||||
|
||||
If you are not using the [Nix Package Manager](www.nixos.org), please skip this section. But maybe you should be using it ;-).
|
||||
|
||||
Nix is a package manager that runs on Linux and macOS, and NixOS is a Linux distribution based on it.
|
||||
|
||||
If you've got `nix` installed, after downloading Retro68, you can run
|
||||
|
||||
nix-shell
|
||||
|
||||
from the Retro68 directory to get a shell with the compiler tools targeting
|
||||
68K Macs available in the path, and `CC` and other environment variables already
|
||||
set up for you. You can then `cd` to one of the example directories or to your
|
||||
own project and use `cmake` to build it.
|
||||
|
||||
You can use the `nix-shell` command to invoke various useful shell environments:
|
||||
|
||||
| Command | What |
|
||||
|-------------------------------------|----------------------------------------------|
|
||||
| `nix-shell` | 68K development environment |
|
||||
| `nix-shell -A m68k` | 68K development environment |
|
||||
| `nix-shell -A ppc` | PowerPC development environment |
|
||||
| `nix-shell -A retro68.monolithic` | Shell for running `build-toolchain.bash` |
|
||||
|
||||
You can also use the `nix-build` command to build packages. As always with `nix`,
|
||||
the result will be somewhere in a subdirectory of `/nix/store`, with a symlink
|
||||
named `result` placed in your Retro68 directory.
|
||||
|
||||
| Command | What |
|
||||
|-------------------------------------|----------------------------------------------|
|
||||
| `nix-build -A m68k.retro68.samples` | Sample programs for 68K |
|
||||
| `nix-build -A ppc.retro68.samples` | Sample programs for PowerPC |
|
||||
| `nix-build -A retro68.monolithic` | Result of `build-toolchain.bash --no-carbon` |
|
||||
| `nix-build -A m68k.zlib` | zlib library, cross-compiled for 68K Macs |
|
||||
| `nix-build -A m68k.`*packagename* | cross-compile *packagename* to 68K |
|
||||
| `nix-build -A ppc.`*packagename* | cross-compile *packagename* to PowerPC |
|
||||
|
||||
You can attempt to cross-compile *any* package from the `nixpkgs` collection. Unless the
|
||||
package contains a very portable library, the command will of course fail. Please don't
|
||||
report bugs, please report successes instead!
|
||||
|
||||
|
||||
Sample programs
|
||||
---------------
|
||||
|
||||
|
|
12
Rez/Rez.cc
12
Rez/Rez.cc
|
@ -136,6 +136,18 @@ int main(int argc, const char *argv[])
|
|||
for(std::string path : options["include"].as<std::vector<std::string>>())
|
||||
lexer.addIncludePath(path);
|
||||
|
||||
if(const char *path = getenv("REZ_INCLUDE_PATH"))
|
||||
{
|
||||
while(const char* end = strchr(path, ':'))
|
||||
{
|
||||
if(end != path)
|
||||
lexer.addIncludePath(std::string(path, end));
|
||||
path = end + 1;
|
||||
}
|
||||
if(*path)
|
||||
lexer.addIncludePath(path);
|
||||
}
|
||||
|
||||
if(world.verboseFlag)
|
||||
{
|
||||
std::cerr << "Compiling " << fn << "...\n";
|
||||
|
|
|
@ -34,11 +34,14 @@
|
|||
*/
|
||||
|
||||
#include <MacTypes.h>
|
||||
#include <Retro68Runtime.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdlib.h>
|
||||
#include <MixedMode.h>
|
||||
|
||||
#if !TARGET_CPU_PPC
|
||||
#include <Retro68Runtime.h>
|
||||
#endif
|
||||
|
||||
#pragma pack (push, 2)
|
||||
|
||||
struct MPWFile;
|
||||
|
|
|
@ -23,11 +23,15 @@ function(add_application name)
|
|||
set(files)
|
||||
set(rsrc_files)
|
||||
set(rez_files)
|
||||
|
||||
set(rez_include_options ${REZ_INCLUDE_PATH})
|
||||
list(TRANSFORM rez_include_options PREPEND -I)
|
||||
|
||||
foreach(f ${ARGS_FILES})
|
||||
if(${f} MATCHES "\\.r$")
|
||||
add_custom_command(
|
||||
OUTPUT ${f}.rsrc.bin
|
||||
COMMAND ${REZ} ${REZ_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${f} -I ${REZ_INCLUDE_PATH} -o ${f}.rsrc.bin
|
||||
COMMAND ${REZ} ${REZ_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${f} ${rez_include_options} -o ${f}.rsrc.bin
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${f})
|
||||
list(APPEND rsrc_files "${CMAKE_CURRENT_BINARY_DIR}/${f}.rsrc.bin")
|
||||
list(APPEND rez_files "${f}")
|
||||
|
|
449
default.nix
449
default.nix
|
@ -1,27 +1,432 @@
|
|||
{ system ? builtins.currentSystem, pkgs ? import <nixpkgs> { inherit system; }
|
||||
, ... }:
|
||||
|
||||
pkgs.callPackage ({
|
||||
stdenv, cmake, ninja, bison, flex,ruby, boost, gmp, mpfr, libmpc, zlib,
|
||||
lib, bash }:
|
||||
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;
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "retro68";
|
||||
nativeBuildInputs = [ cmake bison ruby flex ];
|
||||
buildInputs = [
|
||||
boost
|
||||
gmp
|
||||
mpfr
|
||||
libmpc
|
||||
zlib
|
||||
bash
|
||||
];
|
||||
src = if lib.inNixShell then null else pkgs.nix-gitignore.gitignoreSource [ ] ./.;
|
||||
|
||||
builder = ./nix/builder.sh;
|
||||
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"; };
|
||||
};
|
||||
};
|
||||
|
||||
hardeningDisable = ["all"];
|
||||
}
|
||||
|
||||
|
||||
) { }
|
||||
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;
|
||||
};
|
||||
|
||||
# A Nixpkgs overlay.
|
||||
overlay = pkgs: prev:
|
||||
{
|
||||
retro68 = {
|
||||
platforms = retroPlatforms;
|
||||
|
||||
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
|
||||
"");
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
};
|
||||
} // 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
|
||||
];
|
||||
};
|
||||
|
||||
# no separate libc package for now
|
||||
libcCrossChooser = name:
|
||||
if name == "retro68" then null else prev.libcCrossChooser name;
|
||||
|
||||
};
|
||||
|
||||
pkgs = import <nixpkgs> {
|
||||
inherit system;
|
||||
overlays = [ overlay ];
|
||||
};
|
||||
|
||||
crossPkgs = pkgs.lib.mapAttrs (name: plat:
|
||||
import <nixpkgs> {
|
||||
inherit system;
|
||||
overlays = [ overlay ];
|
||||
crossSystem = plat;
|
||||
config = { allowUnsupportedSystem = true; };
|
||||
}) retroPlatforms;
|
||||
|
||||
shell = pkgs.lib.mapAttrs (name: cross:
|
||||
cross.mkShell {
|
||||
nativeBuildInputs = with pkgs; [
|
||||
retro68.hfsutils
|
||||
retro68.tools
|
||||
cmake
|
||||
gnumake
|
||||
];
|
||||
buildInputs = [ cross.retro68.console ];
|
||||
} // cross) crossPkgs;
|
||||
|
||||
in shell.m68k // shell // {
|
||||
inherit overlay;
|
||||
inherit (pkgs) retro68;
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
source $stdenv/setup
|
||||
|
||||
bash $src/build-toolchain.bash --prefix=$out
|
Loading…
Reference in New Issue