lol
1{ stdenv
2, lib
3, fetchzip
4, fetchpatch
5, meson
6, ninja
7, flex
8, bison
9, pkg-config
10, which
11, pythonSupport ? false
12, python ? null
13, swig
14, libyaml
15}:
16
17stdenv.mkDerivation (finalAttrs: {
18 pname = "dtc";
19 version = "1.7.0";
20
21 src = fetchzip {
22 url = "https://git.kernel.org/pub/scm/utils/dtc/dtc.git/snapshot/dtc-v${finalAttrs.version}.tar.gz";
23 sha256 = "sha256-FMh3VvlY3fUK8fbd0M+aCmlUrmG9YegiOOQ7MOByffc=";
24 };
25
26 patches = [
27 # meson: Fix cell overflow tests when running from meson
28 (fetchpatch {
29 url = "https://github.com/dgibson/dtc/commit/32174a66efa4ad19fc6a2a6422e4af2ae4f055cb.patch";
30 sha256 = "sha256-C7OzwY0zq+2CV3SB5unI7Ill2M3deF7FXeQE3B/Kx2s=";
31 })
32
33 # Use #ifdef NO_VALGRIND
34 (fetchpatch {
35 url = "https://github.com/dgibson/dtc/commit/41821821101ad8a9f83746b96b163e5bcbdbe804.patch";
36 sha256 = "sha256-7QEFDtap2DWbUGqtyT/RgJZJFldKB8oSubKiCtLZ0w4=";
37 })
38
39 # dtc: Fix linker options so it also works in Darwin
40 (fetchpatch {
41 url = "https://github.com/dgibson/dtc/commit/3acde70714df3623e112cf3ec99fc9b5524220b8.patch";
42 sha256 = "sha256-uLXL0Sjcn+bnMuF+A6PjUW1Rq6uNg1dQl58zbeYpP/U=";
43 })
44
45 # meson: allow disabling tests
46 (fetchpatch {
47 url = "https://github.com/dgibson/dtc/commit/35f26d2921b68d97fefbd5a2b6e821a2f02ff65d.patch";
48 sha256 = "sha256-cO4f/jJX/pQL7kk4jpKUhsCVESW2ZuWaTr7z3BuvVkw=";
49 })
50
51 (fetchpatch {
52 name = "static.patch";
53 url = "https://git.kernel.org/pub/scm/utils/dtc/dtc.git/patch/?id=3fbfdd08afd2a7a25b27433f6f5678c0fe694721";
54 hash = "sha256-skK8m1s4xkK6x9AqzxiEK+1uMEmS27dBI1CdEXNFTfU=";
55 })
56 ];
57
58 env.SETUPTOOLS_SCM_PRETEND_VERSION = finalAttrs.version;
59
60 nativeBuildInputs = [
61 meson
62 ninja
63 flex
64 bison
65 pkg-config
66 which
67 ] ++ lib.optionals pythonSupport [
68 python
69 python.pkgs.setuptools-scm
70 swig
71 ];
72
73 buildInputs = [ libyaml ];
74
75 postPatch = ''
76 patchShebangs setup.py
77
78 # meson.build: bump version to 1.7.0
79 substituteInPlace libfdt/meson.build \
80 --replace "version: '1.6.0'," "version: '${finalAttrs.version}',"
81 substituteInPlace meson.build \
82 --replace "version: '1.6.0'," "version: '${finalAttrs.version}',"
83 '';
84
85 # Required for installation of Python library and is innocuous otherwise.
86 env.DESTDIR = "/";
87
88 mesonAutoFeatures = "auto";
89 mesonFlags = [
90 (lib.mesonBool "static-build" stdenv.hostPlatform.isStatic)
91 (lib.mesonBool "tests" finalAttrs.finalPackage.doCheck)
92 ];
93
94 doCheck =
95 # Checks are broken on aarch64 darwin
96 # https://github.com/NixOS/nixpkgs/pull/118700#issuecomment-885892436
97 !stdenv.isDarwin &&
98
99 # we must explicitly disable this here so that mesonFlags receives
100 # `-Dtests=disabled`; without it meson will attempt to run
101 # hostPlatform binaries during the configurePhase.
102 (with stdenv; buildPlatform.canExecute hostPlatform);
103
104 meta = with lib; {
105 description = "Device Tree Compiler";
106 homepage = "https://git.kernel.org/pub/scm/utils/dtc/dtc.git";
107 license = licenses.gpl2Plus; # dtc itself is GPLv2, libfdt is dual GPL/BSD
108 maintainers = [ maintainers.dezgeg ];
109 platforms = platforms.unix;
110 mainProgram = "dtc";
111 };
112})