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