2022-10-07 17:52:10 +01:00
|
|
|
{ stdenv
|
|
|
|
, fetchFromGitHub
|
|
|
|
, callPackage
|
|
|
|
, gnat
|
|
|
|
, zlib
|
|
|
|
, llvm
|
|
|
|
, lib
|
2024-06-21 18:22:16 +01:00
|
|
|
, gcc-unwrapped
|
|
|
|
, texinfo
|
|
|
|
, gmp
|
|
|
|
, mpfr
|
|
|
|
, libmpc
|
|
|
|
, gnutar
|
|
|
|
, glibc
|
|
|
|
, makeWrapper
|
2022-10-07 17:52:10 +01:00
|
|
|
, backend ? "mcode"
|
|
|
|
}:
|
2019-06-02 22:40:01 +01:00
|
|
|
|
2024-06-21 18:22:16 +01:00
|
|
|
assert backend == "mcode" || backend == "llvm" || backend == "gcc";
|
2019-06-02 22:40:01 +01:00
|
|
|
|
2023-09-23 09:41:15 +01:00
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
2019-06-02 22:40:01 +01:00
|
|
|
pname = "ghdl-${backend}";
|
2024-04-15 01:55:36 +01:00
|
|
|
version = "4.1.0";
|
2019-06-02 22:40:01 +01:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
2021-01-15 05:52:23 +00:00
|
|
|
owner = "ghdl";
|
|
|
|
repo = "ghdl";
|
2023-09-23 09:41:15 +01:00
|
|
|
rev = "v${finalAttrs.version}";
|
2024-04-15 01:55:36 +01:00
|
|
|
hash = "sha256-tPSHer3qdtEZoPh9BsEyuTOrXgyENFUyJqnUS3UYAvM=";
|
2019-06-02 22:40:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
LIBRARY_PATH = "${stdenv.cc.libc}/lib";
|
|
|
|
|
2022-10-07 17:52:10 +01:00
|
|
|
nativeBuildInputs = [
|
|
|
|
gnat
|
2024-06-21 18:22:16 +01:00
|
|
|
] ++ lib.optionals (backend == "gcc") [
|
|
|
|
texinfo
|
|
|
|
makeWrapper
|
2022-10-07 17:52:10 +01:00
|
|
|
];
|
|
|
|
buildInputs = [
|
|
|
|
zlib
|
2022-10-06 17:38:53 +01:00
|
|
|
] ++ lib.optionals (backend == "llvm") [
|
2022-10-07 17:52:10 +01:00
|
|
|
llvm
|
2024-06-21 18:22:16 +01:00
|
|
|
] ++ lib.optionals (backend == "gcc") [
|
|
|
|
gmp
|
|
|
|
mpfr
|
|
|
|
libmpc
|
2022-10-07 17:52:10 +01:00
|
|
|
];
|
|
|
|
propagatedBuildInputs = [
|
2024-06-21 18:22:16 +01:00
|
|
|
] ++ lib.optionals (backend == "llvm" || backend == "gcc") [
|
2022-10-07 17:52:10 +01:00
|
|
|
zlib
|
|
|
|
];
|
2019-06-02 22:40:01 +01:00
|
|
|
|
|
|
|
preConfigure = ''
|
|
|
|
# If llvm 7.0 works, 7.x releases should work too.
|
2021-02-10 09:04:28 +00:00
|
|
|
sed -i 's/check_version 7.0/check_version 7/g' configure
|
2024-06-21 18:22:16 +01:00
|
|
|
'' + lib.optionalString (backend == "gcc") ''
|
|
|
|
${gnutar}/bin/tar -xf ${gcc-unwrapped.src}
|
2019-06-02 22:40:01 +01:00
|
|
|
'';
|
|
|
|
|
2022-10-07 17:52:10 +01:00
|
|
|
configureFlags = [
|
|
|
|
# See https://github.com/ghdl/ghdl/pull/2058
|
|
|
|
"--disable-werror"
|
|
|
|
"--enable-synth"
|
|
|
|
] ++ lib.optionals (backend == "llvm") [
|
|
|
|
"--with-llvm-config=${llvm.dev}/bin/llvm-config"
|
2024-06-21 18:22:16 +01:00
|
|
|
] ++ lib.optionals (backend == "gcc") [
|
|
|
|
"--with-gcc=gcc-${gcc-unwrapped.version}"
|
|
|
|
];
|
|
|
|
|
|
|
|
buildPhase = lib.optionalString (backend == "gcc") ''
|
|
|
|
make copy-sources
|
|
|
|
mkdir gcc-objs
|
|
|
|
cd gcc-objs
|
|
|
|
../gcc-${gcc-unwrapped.version}/configure \
|
|
|
|
--with-native-system-header-dir=/include \
|
|
|
|
--with-build-sysroot=${lib.getDev glibc} \
|
|
|
|
--prefix=$out \
|
|
|
|
--enable-languages=c,vhdl \
|
|
|
|
--disable-bootstrap \
|
|
|
|
--disable-lto \
|
|
|
|
--disable-multilib \
|
|
|
|
--disable-libssp \
|
|
|
|
--disable-libgomp \
|
|
|
|
--disable-libquadmath
|
|
|
|
make -j $NIX_BUILD_CORES
|
|
|
|
make install
|
|
|
|
cd ../
|
|
|
|
make -j $NIX_BUILD_CORES ghdllib
|
|
|
|
'';
|
|
|
|
|
|
|
|
postFixup = lib.optionalString (backend == "gcc") ''
|
|
|
|
wrapProgram $out/bin/ghdl \
|
|
|
|
--set LIBRARY_PATH ${lib.makeLibraryPath [
|
|
|
|
glibc
|
|
|
|
]}
|
|
|
|
'';
|
|
|
|
|
|
|
|
hardeningDisable = [
|
|
|
|
] ++ lib.optionals (backend == "gcc") [
|
|
|
|
# GCC compilation fails with format errors
|
|
|
|
"format"
|
2022-10-07 17:52:10 +01:00
|
|
|
];
|
2019-06-02 22:40:01 +01:00
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2020-10-22 00:04:26 +01:00
|
|
|
passthru = {
|
2024-06-21 18:22:16 +01:00
|
|
|
# run with:
|
2020-10-22 00:04:26 +01:00
|
|
|
# nix-build -A ghdl-mcode.passthru.tests
|
|
|
|
# nix-build -A ghdl-llvm.passthru.tests
|
2024-06-21 18:22:16 +01:00
|
|
|
# nix-build -A ghdl-gcc.passthru.tests
|
2020-10-22 00:04:26 +01:00
|
|
|
tests = {
|
|
|
|
simple = callPackage ./test-simple.nix { inherit backend; };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-09-23 09:37:51 +01:00
|
|
|
meta = {
|
2019-06-02 22:40:01 +01:00
|
|
|
homepage = "https://github.com/ghdl/ghdl";
|
|
|
|
description = "VHDL 2008/93/87 simulator";
|
2023-09-23 09:37:51 +01:00
|
|
|
license = lib.licenses.gpl2Plus;
|
|
|
|
mainProgram = "ghdl";
|
2024-05-09 06:06:14 +01:00
|
|
|
maintainers = with lib.maintainers; [ lucus16 thoughtpolice ];
|
2024-09-03 12:51:19 +01:00
|
|
|
platforms =
|
|
|
|
lib.platforms.linux
|
|
|
|
++ lib.optionals (backend == "mcode" || backend == "llvm") [ "x86_64-darwin" ];
|
2019-06-02 22:40:01 +01:00
|
|
|
};
|
2023-09-23 09:41:15 +01:00
|
|
|
})
|