2022-06-26 10:26:21 +00:00
{ stdenv
, lib
2024-01-13 08:15:51 +00:00
, fetchzip
2023-07-15 17:15:38 +00:00
, meson
, ninja
2022-06-26 10:26:21 +00:00
, flex
, bison
, pkg-config
, which
, pythonSupport ? false
, python ? null
, swig
, libyaml
2020-04-24 23:36:52 +00:00
} :
2023-07-15 17:15:38 +00:00
stdenv . mkDerivation ( finalAttrs : {
2020-04-24 23:36:52 +00:00
pname = " d t c " ;
2024-10-04 16:56:33 +00:00
version = " 1 . 7 . 1 " ;
2020-04-24 23:36:52 +00:00
2024-01-13 08:15:51 +00:00
src = fetchzip {
url = " h t t p s : / / g i t . k e r n e l . o r g / p u b / s c m / u t i l s / d t c / d t c . g i t / s n a p s h o t / d t c - v ${ finalAttrs . version } . t a r . g z " ;
2024-10-04 16:56:33 +00:00
hash = " s h a 2 5 6 - Z l 2 b O G D J I e / b h M F N s y 9 6 9 J Y C Y q t X T O z g b + b b O l K q O c o = " ;
2020-04-24 23:36:52 +00:00
} ;
2023-07-15 17:15:38 +00:00
env . SETUPTOOLS_SCM_PRETEND_VERSION = finalAttrs . version ;
nativeBuildInputs = [
meson
ninja
flex
bison
pkg-config
which
] ++ lib . optionals pythonSupport [
python
python . pkgs . setuptools-scm
swig
] ;
2022-06-26 10:26:21 +00:00
2021-04-12 18:23:04 +00:00
buildInputs = [ libyaml ] ;
2020-04-24 23:36:52 +00:00
postPatch = ''
2023-07-15 17:15:38 +00:00
patchShebangs setup . py
2020-04-24 23:36:52 +00:00
'' ;
2023-07-15 17:15:38 +00:00
# Required for installation of Python library and is innocuous otherwise.
env . DESTDIR = " / " ;
2020-04-24 23:36:52 +00:00
2023-07-15 17:15:38 +00:00
mesonAutoFeatures = " a u t o " ;
mesonFlags = [
( lib . mesonBool " s t a t i c - b u i l d " stdenv . hostPlatform . isStatic )
( lib . mesonBool " t e s t s " finalAttrs . finalPackage . doCheck )
] ;
doCheck =
# Checks are broken on aarch64 darwin
# https://github.com/NixOS/nixpkgs/pull/118700#issuecomment-885892436
2024-09-26 11:04:55 +00:00
! stdenv . hostPlatform . isDarwin &&
2024-09-19 14:19:46 +00:00
# Checks are broken when building statically on x86_64 linux with musl
# One of the test tries to build a shared library and this causes the linker:
# x86_64-unknown-linux-musl-ld: /nix/store/h9gcvnp90mpniyx2v0d0p3s06hkx1v2p-x86_64-unknown-linux-musl-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-musl/13.3.0/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a shared object
# x86_64-unknown-linux-musl-ld: failed to set dynamic section sizes: bad value
! stdenv . hostPlatform . isStatic &&
2022-09-14 18:05:37 +00:00
2023-07-15 17:15:38 +00:00
# we must explicitly disable this here so that mesonFlags receives
# `-Dtests=disabled`; without it meson will attempt to run
# hostPlatform binaries during the configurePhase.
( with stdenv ; buildPlatform . canExecute hostPlatform ) ;
2021-04-12 18:23:04 +00:00
2020-04-24 23:36:52 +00:00
meta = with lib ; {
description = " D e v i c e T r e e C o m p i l e r " ;
2022-06-16 17:23:12 +00:00
homepage = " h t t p s : / / g i t . k e r n e l . o r g / p u b / s c m / u t i l s / d t c / d t c . g i t " ;
2021-04-12 18:23:04 +00:00
license = licenses . gpl2Plus ; # dtc itself is GPLv2, libfdt is dual GPL/BSD
2020-04-24 23:36:52 +00:00
maintainers = [ maintainers . dezgeg ] ;
platforms = platforms . unix ;
2024-04-21 15:54:59 +00:00
mainProgram = " d t c " ;
2020-04-24 23:36:52 +00:00
} ;
2023-07-15 17:15:38 +00:00
} )