1{ stdenv, lib, fetchFromRepoOrCz, perl, texinfo }:
2with lib;
3
4stdenv.mkDerivation rec {
5 pname = "tcc";
6 version = "0.9.27";
7 upstreamVersion = "release_${concatStringsSep "_" (builtins.splitVersion version)}";
8
9 src = fetchFromRepoOrCz {
10 repo = "tinycc";
11 rev = upstreamVersion;
12 sha256 = "12mm1lqywz0akr2yb2axjfbw8lwv57nh395vzsk534riz03ml977";
13 };
14
15 nativeBuildInputs = [ perl texinfo ];
16
17 hardeningDisable = [ "fortify" ];
18
19 enableParallelBuilding = true;
20
21 postPatch = ''
22 substituteInPlace "texi2pod.pl" \
23 --replace "/usr/bin/perl" "${perl}/bin/perl"
24 '';
25
26 preConfigure = ''
27 echo ${version} > VERSION
28
29 configureFlagsArray+=("--cc=cc")
30 configureFlagsArray+=("--elfinterp=$(< $NIX_CC/nix-support/dynamic-linker)")
31 configureFlagsArray+=("--crtprefix=${getLib stdenv.cc.libc}/lib")
32 configureFlagsArray+=("--sysincludepaths=${getDev stdenv.cc.libc}/include:{B}/include")
33 configureFlagsArray+=("--libpaths=${getLib stdenv.cc.libc}/lib")
34 '';
35
36 postFixup = ''
37 cat >libtcc.pc <<EOF
38 Name: libtcc
39 Description: Tiny C compiler backend
40 Version: ${version}
41 Libs: -L$out/lib -Wl,--rpath $out/lib -ltcc -ldl
42 Cflags: -I$out/include
43 EOF
44 install -Dt $out/lib/pkgconfig libtcc.pc -m 444
45 '';
46
47 doCheck = true;
48 checkTarget = "test";
49
50 meta = {
51 description = "Small, fast, and embeddable C compiler and interpreter";
52
53 longDescription = ''
54 TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike
55 other C compilers, it is meant to be self-sufficient: you do not
56 need an external assembler or linker because TCC does that for
57 you.
58
59 TCC compiles so fast that even for big projects Makefiles may not
60 be necessary.
61
62 TCC not only supports ANSI C, but also most of the new ISO C99
63 standard and many GNU C extensions.
64
65 TCC can also be used to make C scripts, i.e. pieces of C source
66 that you run as a Perl or Python script. Compilation is so fast
67 that your script will be as fast as if it was an executable.
68
69 TCC can also automatically generate memory and bound checks while
70 allowing all C pointers operations. TCC can do these checks even
71 if non patched libraries are used.
72
73 With libtcc, you can use TCC as a backend for dynamic code
74 generation.
75 '';
76
77 homepage = "http://www.tinycc.org/";
78 license = licenses.mit;
79
80 platforms = [ "x86_64-linux" ];
81 maintainers = [ maintainers.joachifm ];
82 };
83}