1{
2 # Deps
3 lib,
4 stdenv,
5 makeWrapper,
6 retroarch-bare,
7 unstableGitUpdater,
8 zlib,
9}:
10
11lib.extendMkDerivation {
12 constructDrv = stdenv.mkDerivation;
13
14 excludeDrvArgNames = [
15 "core"
16 "extraBuildInputs"
17 "extraNativeBuildInputs"
18 "libretroCore"
19 "normalizeCore"
20 ];
21
22 extendDrvArgs =
23 finalAttrs:
24 {
25 core,
26 enableParallelBuilding ? true,
27 extraBuildInputs ? [ ],
28 extraNativeBuildInputs ? [ ],
29 makeFlags ? [ ],
30 makefile ? "Makefile.libretro",
31 meta ? { },
32 passthru ? { },
33 strictDeps ? true,
34 ## Location of resulting RetroArch core on $out
35 libretroCore ? "/lib/retroarch/cores",
36 ## The core filename is derived from the core name
37 ## Setting `normalizeCore` to `true` will convert `-` to `_` on the core filename
38 normalizeCore ? true,
39 ...
40 }:
41 let
42 d2u = if normalizeCore then (lib.replaceStrings [ "-" ] [ "_" ]) else (x: x);
43 coreDir = placeholder "out" + libretroCore;
44 coreFilename = "${d2u core}_libretro${stdenv.hostPlatform.extensions.sharedLibrary}";
45 mainProgram = "retroarch-${core}";
46 in
47 {
48 pname = "libretro-${core}";
49
50 buildInputs = [ zlib ] ++ extraBuildInputs;
51 nativeBuildInputs = [ makeWrapper ] ++ extraNativeBuildInputs;
52
53 inherit enableParallelBuilding makefile strictDeps;
54
55 makeFlags = [
56 "platform=${
57 {
58 linux = "unix";
59 darwin = "osx";
60 windows = "win";
61 }
62 .${stdenv.hostPlatform.parsed.kernel.name} or stdenv.hostPlatform.parsed.kernel.name
63 }"
64 "ARCH=${
65 {
66 armv7l = "arm";
67 armv6l = "arm";
68 aarch64 = "arm64";
69 i686 = "x86";
70 }
71 .${stdenv.hostPlatform.parsed.cpu.name} or stdenv.hostPlatform.parsed.cpu.name
72 }"
73 ]
74 ++ makeFlags;
75
76 installPhase = ''
77 runHook preInstall
78
79 install -Dt ${coreDir} ${coreFilename}
80 makeWrapper ${retroarch-bare}/bin/retroarch $out/bin/${mainProgram} \
81 --add-flags "-L ${coreDir}/${coreFilename}"
82
83 runHook postInstall
84 '';
85
86 passthru = {
87 inherit core libretroCore;
88 # libretro repos sometimes has a fake tag like "Current", ignore
89 # it by setting hardcodeZeroVersion
90 updateScript = unstableGitUpdater { hardcodeZeroVersion = true; };
91 }
92 // passthru;
93
94 meta = {
95 inherit mainProgram;
96 inherit (retroarch-bare.meta) platforms;
97 teams = [ lib.teams.libretro ];
98 }
99 // meta;
100 };
101}