1{ lib
2, copyPkgconfigItems
3, fetchFromRepoOrCz
4, makePkgconfigItem
5, perl
6, stdenv
7, texinfo
8, which
9}:
10
11stdenv.mkDerivation (finalAttrs: {
12 pname = "tcc";
13 version = "0.9.27-unstable-2022-07-15";
14
15 src = fetchFromRepoOrCz {
16 repo = "tinycc";
17 rev = "af1abf1f45d45b34f0b02437f559f4dfdba7d23c";
18 hash = "sha256-jY0P2GErmo//YBaz6u4/jj/voOE3C2JaIDRmo0orXN8=";
19 };
20
21 outputs = [ "out" "info" "man" ];
22
23 nativeBuildInputs = [
24 copyPkgconfigItems
25 perl
26 texinfo
27 which
28 ];
29
30 strictDeps = true;
31
32 pkgconfigItems = let
33 libtcc-pcitem = {
34 name = "libtcc";
35 inherit (finalAttrs) version;
36 cflags = [ "-I${libtcc-pcitem.variables.includedir}" ];
37 libs = [
38 "-L${libtcc-pcitem.variables.libdir}"
39 "-Wl,--rpath ${libtcc-pcitem.variables.libdir}"
40 "-ltcc"
41 ];
42 variables = {
43 prefix = "${placeholder "out"}";
44 includedir = "${placeholder "dev"}/include";
45 libdir = "${placeholder "lib"}/lib";
46 };
47 description = "Tiny C compiler backend";
48 };
49 in [
50 (makePkgconfigItem libtcc-pcitem)
51 ];
52
53 postPatch = ''
54 patchShebangs texi2pod.pl
55 '';
56
57 configureFlags = [
58 "--cc=$CC"
59 "--ar=$AR"
60 "--crtprefix=${lib.getLib stdenv.cc.libc}/lib"
61 "--sysincludepaths=${lib.getDev stdenv.cc.libc}/include:{B}/include"
62 "--libpaths=${lib.getLib stdenv.cc.libc}/lib"
63 # build cross compilers
64 "--enable-cross"
65 ] ++ lib.optionals stdenv.hostPlatform.isMusl [
66 "--config-musl"
67 ];
68
69 preConfigure = let
70 # To avoid "malformed 32-bit x.y.z" error on mac when using clang
71 versionIsClean = version:
72 builtins.match "^[0-9]\\.+[0-9]+\\.[0-9]+" version != null;
73 in ''
74 ${
75 if stdenv.isDarwin && ! versionIsClean finalAttrs.version
76 then "echo 'not overwriting VERSION since it would upset ld'"
77 else "echo ${finalAttrs.version} > VERSION"
78 }
79 configureFlagsArray+=("--elfinterp=$(< $NIX_CC/nix-support/dynamic-linker)")
80 '';
81
82 # Test segfault for static build
83 doCheck = !stdenv.hostPlatform.isStatic;
84
85 checkTarget = "test";
86 # https://www.mail-archive.com/tinycc-devel@nongnu.org/msg10142.html
87 preCheck = lib.optionalString (stdenv.isDarwin && stdenv.isx86_64) ''
88 rm tests/tests2/{108,114}*
89 '';
90
91 meta = {
92 homepage = "https://repo.or.cz/tinycc.git";
93 description = "Small, fast, and embeddable C compiler and interpreter";
94 longDescription = ''
95 TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other C
96 compilers, it is meant to be self-sufficient: you do not need an external
97 assembler or linker because TCC does that for you.
98
99 TCC compiles so fast that even for big projects Makefiles may not be
100 necessary.
101
102 TCC not only supports ANSI C, but also most of the new ISO C99 standard
103 and many GNU C extensions.
104
105 TCC can also be used to make C scripts, i.e. pieces of C source that you
106 run as a Perl or Python script. Compilation is so fast that your script
107 will be as fast as if it was an executable.
108
109 TCC can also automatically generate memory and bound checks while allowing
110 all C pointers operations. TCC can do these checks even if non patched
111 libraries are used.
112
113 With libtcc, you can use TCC as a backend for dynamic code generation.
114 '';
115 license = with lib.licenses; [ lgpl21Only ];
116 mainProgram = "tcc";
117 maintainers = with lib.maintainers; [ joachifm AndersonTorres ];
118 platforms = lib.platforms.unix;
119 # https://www.mail-archive.com/tinycc-devel@nongnu.org/msg10199.html
120 broken = stdenv.isDarwin && stdenv.isAarch64;
121 };
122})
123# TODO: more multiple outputs
124# TODO: self-compilation