summary refs log tree commit diff
path: root/pkgs/applications/science/math/calc/default.nix
blob: 86ec445d9b3e41230b62936ddb4e056624d7dc91 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{ lib
, stdenv
, fetchurl
, makeWrapper
, ncurses
, readline
, unixtools
, enableReadline ? true
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "calc";
  version = "2.15.0.1";

  src = fetchurl {
    urls = [
      "https://github.com/lcn2/calc/releases/download/v${finalAttrs.version}/calc-${finalAttrs.version}.tar.bz2"
      "http://www.isthe.com/chongo/src/calc/calc-${finalAttrs.version}.tar.bz2"
    ];
    hash = "sha256-u/mt9y4805IWYDdEHz94dPb4V+d4YVrrhzz8v3B+q24=";
  };

  postPatch = ''
    substituteInPlace Makefile.target \
      --replace '-install_name ''${LIBDIR}/libcalc''${LIB_EXT_VERSION}' '-install_name ''${T}''${LIBDIR}/libcalc''${LIB_EXT_VERSION}' \
      --replace '-install_name ''${LIBDIR}/libcustcalc''${LIB_EXT_VERSION}' '-install_name ''${T}''${LIBDIR}/libcustcalc''${LIB_EXT_VERSION}'
  '';

  nativeBuildInputs = [
    makeWrapper
    unixtools.col
  ];

  buildInputs = lib.optionals enableReadline [
    ncurses
    readline
  ];

  makeFlags = [
    "T=$(out)"
    "INCDIR="
    "BINDIR=/bin"
    "LIBDIR=/lib"
    "CALC_SHAREDIR=/share/calc"
    "CALC_INCDIR=/include"
    "MANDIR=/share/man/man1"

    # Handle LDFLAGS defaults in calc
    "DEFAULT_LIB_INSTALL_PATH=$(out)/lib"
  ]
  ++ lib.optionals enableReadline [
    "READLINE_LIB=-lreadline"
    "USE_READLINE=-DUSE_READLINE"
  ];

  meta = {
    homepage = "http://www.isthe.com/chongo/tech/comp/calc/";
    description = "C-style arbitrary precision calculator";
    changelog = "https://github.com/lcn2/calc/blob/v${finalAttrs.version}/CHANGES";
    # The licensing situation depends on readline (see section 3 of the LGPL)
    # If linked against readline then GPLv2 otherwise LGPLv2.1
    license = if enableReadline
              then lib.licenses.gpl2Only
              else lib.licenses.lgpl21Only;
    maintainers = with lib.maintainers; [ matthewbauer ];
    platforms = lib.platforms.all;
  };
})