about summary refs log tree commit diff
path: root/nixpkgs/pkgs/desktops/lomiri/development/geonames/default.nix
blob: ce77bca6bc41ca1ee5f5e4b4384690b7af51eeb1 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
{ stdenv
, lib
, fetchFromGitLab
, gitUpdater
, testers
, buildPackages
, cmake
, docbook-xsl-nons
, docbook_xml_dtd_45
, gettext
, glib
, glibcLocales
, withExamples ? true
, gtk3
# Uses gtkdoc-scan* tools, which produces a binary linked against lib for hostPlatform and executes it to generate docs
, withDocumentation ? stdenv.buildPlatform.canExecute stdenv.hostPlatform
, gtk-doc
, pkg-config
, validatePkgConfig
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "geonames";
  version = "0.3.1";

  src = fetchFromGitLab {
    owner = "ubports";
    repo = "development/core/geonames";
    rev = finalAttrs.version;
    hash = "sha256-AhRnUoku17kVY0UciHQXFDa6eCH6HQ4ZGIOobCaGTKQ=";
  };

  outputs = [
    "out"
    "dev"
  ] ++ lib.optionals withExamples [
    "bin"
  ] ++ lib.optionals withDocumentation [
    "devdoc"
  ];

  postPatch = ''
    patchShebangs src/generate-locales.sh tests/setup-test-env.sh
  '';

  strictDeps = true;

  nativeBuildInputs = [
    cmake
    gettext
    glib # glib-compile-resources
    pkg-config
    validatePkgConfig
  ] ++ lib.optionals withDocumentation [
    docbook-xsl-nons
    docbook_xml_dtd_45
    gtk-doc
  ];

  buildInputs = [
    glib
  ] ++ lib.optionals withExamples [
    gtk3
  ];

  # Tests need to be able to check locale
  LC_ALL = lib.optionalString finalAttrs.finalPackage.doCheck "en_US.UTF-8";
  nativeCheckInputs = [
    glibcLocales
  ];

  makeFlags = [
    # gtkdoc-scan runs ld, can't find qsort & strncpy symbols
    "LD=${stdenv.cc.targetPrefix}cc"
  ];

  cmakeFlags = [
    (lib.cmakeBool "WANT_DOC" withDocumentation)
    (lib.cmakeBool "WANT_DEMO" withExamples)
    (lib.cmakeBool "WANT_TESTS" finalAttrs.finalPackage.doCheck)
    # Keeps finding & using glib-compile-resources from buildInputs otherwise
    (lib.cmakeFeature "CMAKE_PROGRAM_PATH" (lib.makeBinPath [ buildPackages.glib.dev ]))
  ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
    # only for cross without native execute support because the canExecute "emulator" call has a format that I can't get CMake to accept
    (lib.cmakeFeature "CMAKE_CROSSCOMPILING_EMULATOR" (stdenv.hostPlatform.emulator buildPackages))
  ];

  preInstall = lib.optionalString withDocumentation ''
    # gtkdoc-mkhtml generates images without write permissions, errors out during install
    chmod +w doc/reference/html/*
  '';

  doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;

  passthru = {
    tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
    updateScript = gitUpdater { };
  };

  meta = with lib; {
    description = "Parse and query the geonames database dump";
    mainProgram = "geonames-demo";
    homepage = "https://gitlab.com/ubports/development/core/geonames";
    changelog = "https://gitlab.com/ubports/development/core/geonames/-/blob/${finalAttrs.version}/ChangeLog";
    license = licenses.gpl3Only;
    maintainers = teams.lomiri.members;
    platforms = platforms.all;
    # Cross requires hostPlatform emulation during build
    # https://gitlab.com/ubports/development/core/geonames/-/issues/1
    broken = stdenv.buildPlatform != stdenv.hostPlatform && !stdenv.hostPlatform.emulatorAvailable buildPackages;
    pkgConfigModules = [
      "geonames"
    ];
  };
})