Skip to content
Snippets Groups Projects
Forked from pub / frama-c
12160 commits behind the upstream repository.
default.nix 11.67 KiB
# paramaterised derivation with dependencies injected (callPackage style)
{ pkgs, stdenv, src ? ../., opam2nix, ocaml_version ? "ocaml-ng.ocamlPackages_4_08.ocaml", plugins ? { } }:

let mk_buildInputs = { opamPackages ? [], nixPackages ? [] } :
    [ pkgs.gnugrep pkgs.gnused  pkgs.autoconf pkgs.gnumake pkgs.gcc pkgs.ncurses pkgs.time pkgs.python3 pkgs.perl pkgs.file pkgs.which pkgs.dos2unix] ++ nixPackages ++ opam2nix.build {
           specs = opam2nix.toSpecs ([ "ocamlfind" "zarith" "ocamlgraph" "yojson" "zmq"
                "ppx_deriving" "ppx_deriving_yojson"
                { name = "coq"; constraint = "=8.12.0";  }
                { name = "alt-ergo" ; constraint = "=2.2.0"; }
                { name = "why3" ; constraint = "=1.3.3"; }
                { name = "why3-coq" ; constraint = "=1.3.3"; }
                { name = "menhir"; constraint = "=20200624"; }
                { name = "dune"; constraint = "=2.7.1"; }
                ] ++ opamPackages
              );
           ocamlAttr = ocaml_version;
        };

    # Extends the call to stdenv.mkDerivation with parameters common for all
    # frama-c derivations
    mk_deriv = args:
        stdenv.mkDerivation ({
            # Disable Nix's GCC hardening
            hardeningDisable = [ "all" ];
        } // args);
in

rec {
  inherit src mk_buildInputs;
  buildInputs = mk_buildInputs {};
  installed = main.out;
  main = mk_deriv {
        name = "frama-c";
        inherit src buildInputs;
        outputs = [ "out" "build_dir" ];
        postPatch = ''
               patchShebangs .
        '';
        configurePhase = ''
               unset CC
               autoconf
               ./configure --prefix=$out
        '';
        buildPhase = ''
                make -j 4
        '';
        installPhase = ''
               make install
               mkdir -p $build_dir
               tar -cf $build_dir/dir.tar .
               pwd > $build_dir/old_pwd
        '';
        setupHook = pkgs.writeText "setupHook.sh" ''
          addFramaCPath () {
            if test -d "$1/lib/frama-c/plugins"; then
              export FRAMAC_PLUGIN="''${FRAMAC_PLUGIN:-}''${FRAMAC_PLUGIN:+:}$1/lib/frama-c/plugins"
              export OCAMLPATH="''${OCAMLPATH:-}''${OCAMLPATH:+:}$1/lib/frama-c/plugins"
            fi

            if test -d "$1/lib/frama-c"; then
              export OCAMLPATH="''${OCAMLPATH:-}''${OCAMLPATH:+:}$1/lib/frama-c"
            fi

            if test -d "$1/share/frama-c/"; then
              export FRAMAC_EXTRA_SHARE="''${FRAMAC_EXTRA_SHARE:-}''${FRAMAC_EXTRA_SHARE:+:}$1/share/frama-c"
            fi

          }

          addEnvHooks "$targetOffset" addFramaCPath