1{ lib, stdenv, fetchurl, unzip, flex, tk, ncurses, readline }:
2
3stdenv.mkDerivation {
4 pname = "lc3tools";
5 version = "0.12";
6
7 src = fetchurl {
8 url = "https://highered.mheducation.com/sites/dl/free/0072467509/104652/lc3tools_v12.zip";
9 hash = "sha256-PTM0ole8pHiJmUaahjPwcBQY8/hVVgQhADZ4bSABt3I=";
10 };
11
12 patches = [
13 # the original configure looks for things in the FHS path
14 # I have modified it to take environment vars
15 ./0001-mangle-configure.patch
16
17 # lc3sim looks for the LC3 OS in $out/share/lc3tools instead of $out
18 ./0002-lc3os-path.patch
19
20 # lc3sim-tk looks for lc3sim in $out/bin instead of $out
21 ./0003-lc3sim-tk-path.patch
22
23 # use `cc` instead of `gcc`; on macOS the latter is not present
24 ./0004-configure-use-cc.patch
25 ];
26
27 nativeBuildInputs = [ unzip ];
28 buildInputs = [ flex tk ncurses readline ];
29
30 # lumetta published this a while ago but handrolled his configure
31 # jank in the original packaging makes this necessary:
32 LIBS = "${flex}/lib:${ncurses}/lib:${readline}/lib";
33 INCLUDES = "${flex}/include:${ncurses}/include:${readline}/include";
34
35 # it doesn't take `--prefix`
36 prefixKey = "--installdir ";
37
38 postInstall = ''
39 mkdir -p $out/{bin,share/lc3tools}
40
41 mv -t $out/share/lc3tools $out/{COPYING,NO_WARRANTY,README} $out/lc3os*
42 mv -t $out/bin $out/lc3*
43 '';
44
45 meta = with lib; {
46 longDescription = ''
47 The LC-3 tools package contains the lc3as assembler, the lc3sim simulator,
48 and lc3sim-tk, a Tcl/Tk-based GUI frontend to the simulator.
49 '';
50 description = "Toolchain and emulator for the LC-3 architecture";
51 homepage = "https://highered.mheducation.com/sites/0072467509/student_view0/lc-3_simulator.html";
52 license = licenses.gpl2;
53 maintainers = with maintainers; [ anna328p ];
54 mainProgram = "lc3sim-tk";
55 platforms = with lib.platforms; unix ++ windows;
56 };
57}