# SPDX-FileCopyrightText: 2020 Luke Granger-Brown <depot@lukegb.com>
#
# SPDX-License-Identifier: Apache-2.0

{ pkgs, ... }:
pkgs.stdenv.mkDerivation rec {
  pname = "sheepshaver";
  version = "29bb3d5a5a99db494049f64c678f38301ef63432";

  src = pkgs.fetchFromGitHub {
    owner = "cebix";
    repo = "macemu";
    rev = version;
    sha256 = "sha256:1rqyyyhm7w73wg29l5l1xwqljzkhd6s7smdhq3zncrkkx2rxc7fc";
  };
  unpackPhase = ''
    cp -R $src/ writable/
    chmod -R u+w writable/
    make -C writable/SheepShaver links
  '';
  sourceRoot = "writable/SheepShaver/src/Unix";

  nativeBuildInputs = with pkgs; [
    autoconf automake file perl pkg-config
  ];

  buildInputs = with pkgs; [
    gtk2 SDL xorg.libX11 xorg.libSM libslirp
  ];

  configureFlags = [
    "--enable-sdl-audio"
  ];
  CPPFLAGS = "-DSTDC_HEADERS";

  preConfigure = ''
    NO_CONFIGURE=1 ./autogen.sh
  '';
}