about summary refs log tree commit diff
path: root/pkgs/tools/games/alice-tools/default.nix
blob: 07d96cbd03fa0c5a018ebe5117c306668c9c7a01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{ stdenv
, lib
, gitUpdater
, testers
, fetchFromGitHub
, meson
, ninja
, pkg-config
, bison
, flex
, libiconv
, libpng
, libjpeg
, libwebp
, zlib
, withGUI ? true
, qtbase ? null
, wrapQtAppsHook ? null
}:

assert withGUI -> qtbase != null && wrapQtAppsHook != null;

stdenv.mkDerivation (finalAttrs: {
  pname = "alice-tools" + lib.optionalString withGUI "-qt${lib.versions.major qtbase.version}";
  version = "0.13.0";

  src = fetchFromGitHub {
    owner = "nunuhara";
    repo = "alice-tools";
    rev = finalAttrs.version;
    fetchSubmodules = true;
    hash = "sha256-DazWnBeI5XShkIx41GFZLP3BbE0O8T9uflvKIZUXCHo=";
  };

  postPatch = lib.optionalString (withGUI && lib.versionAtLeast qtbase.version "6.0") ''
    # Use Meson's Qt6 module
    substituteInPlace src/meson.build \
      --replace qt5 qt6

    # For some reason Meson uses QMake instead of pkg-config detection method for Qt6 on Darwin, which gives wrong search paths for tools
    export PATH=${qtbase.dev}/libexec:$PATH
  '';

  mesonFlags = lib.optionals (withGUI && lib.versionAtLeast qtbase.version "6.0") [
    # Qt6 requires at least C++17, project uses compiler's default, default too old on Darwin & aarch64-linux
    "-Dcpp_std=c++17"
  ];

  nativeBuildInputs = [
    meson
    ninja
    pkg-config
    bison
    flex
  ] ++ lib.optionals withGUI [
    wrapQtAppsHook
  ];

  buildInputs = [
    libiconv
    libpng
    libjpeg
    libwebp
    zlib
  ] ++ lib.optionals withGUI [
    qtbase
  ];

  dontWrapQtApps = true;

  # Default install step only installs a static library of a build dependency
  installPhase = ''
    runHook preInstall

    install -Dm755 src/alice $out/bin/alice
  '' + lib.optionalString withGUI ''
    install -Dm755 src/galice $out/bin/galice
    wrapQtApp $out/bin/galice
  '' + ''

    runHook postInstall
  '';

  passthru = {
    updateScript = gitUpdater { };
    tests.version = testers.testVersion {
      package = finalAttrs.finalPackage;
      command = lib.optionalString withGUI "env QT_QPA_PLATFORM=minimal " + "${lib.getExe finalAttrs.finalPackage} --version";
    };
  };

  meta = with lib; {
    description = "Tools for extracting/editing files from AliceSoft games";
    homepage = "https://github.com/nunuhara/alice-tools";
    license = licenses.gpl2Plus;
    platforms = platforms.all;
    maintainers = with maintainers; [ OPNA2608 ];
    mainProgram = if withGUI then "galice" else "alice";
  };
})