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