1{ stdenv
2, fetchFromGitHub
3, fetchpatch
4, callPackage
5, gnat
6, zlib
7, llvm
8, lib
9, backend ? "mcode"
10}:
11
12assert backend == "mcode" || backend == "llvm";
13
14stdenv.mkDerivation rec {
15 pname = "ghdl-${backend}";
16 version = "2.0.0";
17
18 src = fetchFromGitHub {
19 owner = "ghdl";
20 repo = "ghdl";
21 rev = "v${version}";
22 sha256 = "sha256-B/G3FGRzYy4Y9VNNB8yM3FohiIjPJhYSVbqsTN3cL5k=";
23 };
24
25 patches = [
26 # https://github.com/ghdl/ghdl/issues/2056
27 (fetchpatch {
28 name = "fix-build-gcc-12.patch";
29 url = "https://github.com/ghdl/ghdl/commit/f8b87697e8b893b6293ebbfc34670c32bfb49397.patch";
30 hash = "sha256-tVbMm8veFkNPs6WFBHvaic5Jkp1niyg0LfFufa+hT/E=";
31 })
32 ];
33
34 LIBRARY_PATH = "${stdenv.cc.libc}/lib";
35
36 nativeBuildInputs = [
37 gnat
38 ];
39 buildInputs = [
40 zlib
41 ] ++ lib.optionals (backend == "llvm") [
42 llvm
43 ];
44 propagatedBuildInputs = [
45 ] ++ lib.optionals (backend == "llvm") [
46 zlib
47 ];
48
49 preConfigure = ''
50 # If llvm 7.0 works, 7.x releases should work too.
51 sed -i 's/check_version 7.0/check_version 7/g' configure
52 '';
53
54 configureFlags = [
55 # See https://github.com/ghdl/ghdl/pull/2058
56 "--disable-werror"
57 "--enable-synth"
58 ] ++ lib.optionals (backend == "llvm") [
59 "--with-llvm-config=${llvm.dev}/bin/llvm-config"
60 ];
61
62 hardeningDisable = [ "format" ];
63
64 enableParallelBuilding = true;
65
66 passthru = {
67 # run with either of
68 # nix-build -A ghdl-mcode.passthru.tests
69 # nix-build -A ghdl-llvm.passthru.tests
70 tests = {
71 simple = callPackage ./test-simple.nix { inherit backend; };
72 };
73 };
74
75 meta = with lib; {
76 homepage = "https://github.com/ghdl/ghdl";
77 description = "VHDL 2008/93/87 simulator";
78 maintainers = with maintainers; [ lucus16 thoughtpolice ];
79 platforms = platforms.linux;
80 license = licenses.gpl2;
81 };
82}