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