2024-04-21 15:54:59 +00:00
|
|
|
{ stdenv
|
|
|
|
, lib
|
|
|
|
, buildDotnetModule
|
2024-06-05 15:53:02 +00:00
|
|
|
, dotnetCorePackages
|
2024-04-21 15:54:59 +00:00
|
|
|
, callPackage
|
|
|
|
, fetchFromGitHub
|
2023-08-04 22:07:22 +00:00
|
|
|
, ffmpeg
|
2024-04-21 15:54:59 +00:00
|
|
|
, glfw
|
|
|
|
, libogg
|
|
|
|
, libvorbis
|
2022-06-16 17:23:12 +00:00
|
|
|
, makeWrapper
|
|
|
|
, openal
|
2024-04-21 15:54:59 +00:00
|
|
|
, portaudio
|
|
|
|
, rtmidi
|
2022-06-16 17:23:12 +00:00
|
|
|
}:
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
let
|
|
|
|
csprojName = if stdenv.hostPlatform.isLinux then
|
|
|
|
"FamiStudio.Linux"
|
|
|
|
else if stdenv.hostPlatform.isDarwin then
|
|
|
|
"FamiStudio.Mac"
|
|
|
|
else throw "Don't know how to build FamiStudio for ${stdenv.hostPlatform.system}";
|
|
|
|
in
|
|
|
|
buildDotnetModule rec {
|
2022-06-16 17:23:12 +00:00
|
|
|
pname = "famistudio";
|
2024-06-05 15:53:02 +00:00
|
|
|
version = "4.2.0";
|
2022-06-16 17:23:12 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "BleuBleu";
|
|
|
|
repo = "FamiStudio";
|
|
|
|
rev = "refs/tags/${version}";
|
2024-06-05 15:53:02 +00:00
|
|
|
hash = "sha256-ydEWLL05B86672j3MVo/90tgDHg8FJ2EZaesqrBZy4A=";
|
2022-06-16 17:23:12 +00:00
|
|
|
};
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
postPatch = let
|
|
|
|
libname = library: "${library}${stdenv.hostPlatform.extensions.sharedLibrary}";
|
|
|
|
buildNativeWrapper = args: callPackage ./build-native-wrapper.nix (args // {
|
|
|
|
inherit version src;
|
|
|
|
sourceRoot = "${src.name}/ThirdParty/${args.depname}";
|
|
|
|
});
|
|
|
|
nativeWrapperToReplaceFormat = args: let
|
|
|
|
libPrefix = lib.optionalString stdenv.hostPlatform.isLinux "lib";
|
|
|
|
in {
|
|
|
|
package = buildNativeWrapper args;
|
|
|
|
expectedName = "${libPrefix}${args.depname}";
|
|
|
|
ourName = "${libPrefix}${args.depname}";
|
|
|
|
};
|
|
|
|
librariesToReplace = [
|
|
|
|
# Unmodified native libraries that we can fully substitute
|
|
|
|
{ package = glfw; expectedName = "libglfw"; ourName = "libglfw"; }
|
|
|
|
{ package = rtmidi; expectedName = "librtmidi"; ourName = "librtmidi"; }
|
|
|
|
] ++ lib.optionals stdenv.hostPlatform.isLinux [
|
|
|
|
{ package = openal; expectedName = "libopenal32"; ourName = "libopenal"; }
|
|
|
|
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
|
|
|
|
{ package = portaudio; expectedName = "libportaudio.2"; ourName = "libportaudio.2"; }
|
|
|
|
] ++ [
|
|
|
|
# Native libraries, with extra code for the C# wrapping
|
|
|
|
(nativeWrapperToReplaceFormat { depname = "GifDec"; })
|
|
|
|
(nativeWrapperToReplaceFormat { depname = "NesSndEmu"; })
|
|
|
|
(nativeWrapperToReplaceFormat { depname = "NotSoFatso"; extraPostPatch = ''
|
|
|
|
# C++17 does not allow register storage class specifier
|
|
|
|
substituteInPlace build.sh \
|
|
|
|
--replace-fail "$CXX" "$CXX -std=c++14"
|
|
|
|
''; })
|
|
|
|
(nativeWrapperToReplaceFormat { depname = "ShineMp3"; })
|
|
|
|
(nativeWrapperToReplaceFormat { depname = "Stb"; })
|
|
|
|
(nativeWrapperToReplaceFormat { depname = "Vorbis"; buildInputs = [ libogg libvorbis ]; })
|
|
|
|
];
|
|
|
|
libraryReplaceArgs = lib.strings.concatMapStringsSep " "
|
|
|
|
(library: "--replace-fail '${libname library.expectedName}' '${lib.getLib library.package}/lib/${libname library.ourName}'")
|
|
|
|
librariesToReplace;
|
|
|
|
in ''
|
|
|
|
# Don't use any prebuilt libraries
|
|
|
|
rm FamiStudio/*.{dll,dylib,so*}
|
2023-08-04 22:07:22 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
# Replace copying of vendored prebuilt native libraries with copying of our native libraries
|
|
|
|
substituteInPlace ${projectFile} ${libraryReplaceArgs}
|
2022-06-16 17:23:12 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
# Un-hardcode target platform if set
|
|
|
|
sed -i -e '/PlatformTarget/d' ${projectFile}
|
2022-06-16 17:23:12 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
# Don't require a special name to be preserved, our OpenAL isn't 32-bit
|
|
|
|
substituteInPlace FamiStudio/Source/AudioStreams/OpenALStream.cs \
|
|
|
|
--replace-fail 'libopenal32' 'libopenal'
|
|
|
|
'';
|
2022-06-16 17:23:12 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
projectFile = "FamiStudio/${csprojName}.csproj";
|
|
|
|
nugetDeps = ./deps.nix;
|
2024-06-05 15:53:02 +00:00
|
|
|
dotnet-sdk = dotnetCorePackages.sdk_7_0;
|
|
|
|
dotnet-runtime = dotnetCorePackages.runtime_7_0;
|
2022-06-16 17:23:12 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
executables = [ "FamiStudio" ];
|
2022-06-16 17:23:12 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
postInstall = ''
|
|
|
|
mkdir -p $out/share/famistudio
|
|
|
|
for datdir in Setup/Demo\ {Instruments,Songs}; do
|
|
|
|
cp -R "$datdir" $out/share/famistudio/
|
|
|
|
done
|
|
|
|
'';
|
2022-06-16 17:23:12 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
postFixup = ''
|
|
|
|
# FFMpeg looked up from PATH
|
|
|
|
wrapProgram $out/bin/FamiStudio \
|
|
|
|
--prefix PATH : ${lib.makeBinPath [ ffmpeg ]}
|
2022-06-16 17:23:12 +00:00
|
|
|
'';
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
passthru.updateScript = ./update.sh;
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
meta = with lib; {
|
|
|
|
homepage = "https://famistudio.org/";
|
|
|
|
description = "NES Music Editor";
|
|
|
|
longDescription = ''
|
|
|
|
FamiStudio is very simple music editor for the Nintendo Entertainment System
|
|
|
|
or Famicom. It is targeted at both chiptune artists and NES homebrewers.
|
|
|
|
'';
|
|
|
|
license = licenses.mit;
|
|
|
|
maintainers = with maintainers; [ OPNA2608 ];
|
2024-04-21 15:54:59 +00:00
|
|
|
platforms = platforms.unix;
|
|
|
|
mainProgram = "FamiStudio";
|
2022-06-16 17:23:12 +00:00
|
|
|
};
|
|
|
|
}
|