at 23.05-pre 114 lines 3.2 kB view raw
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 "-ldl" 42 ]; 43 variables = rec { 44 prefix = "${placeholder "out"}"; 45 includedir = "${prefix}/include"; 46 libdir = "${prefix}/lib"; 47 }; 48 description = "Tiny C compiler backend"; 49 }) 50 ]; 51 52 postPatch = '' 53 patchShebangs texi2pod.pl 54 ''; 55 56 configureFlags = [ 57 "--cc=$CC" 58 "--ar=$AR" 59 "--crtprefix=${lib.getLib stdenv.cc.libc}/lib" 60 "--sysincludepaths=${lib.getDev stdenv.cc.libc}/include:{B}/include" 61 "--libpaths=${lib.getLib stdenv.cc.libc}/lib" 62 # build cross compilers 63 "--enable-cross" 64 ] ++ lib.optionals stdenv.hostPlatform.isMusl [ 65 "--config-musl" 66 ]; 67 68 preConfigure = '' 69 ${ 70 if stdenv.isDarwin && ! isCleanVer version 71 then "echo 'not overwriting VERSION since it would upset ld'" 72 else "echo ${version} > VERSION" 73 } 74 configureFlagsArray+=("--elfinterp=$(< $NIX_CC/nix-support/dynamic-linker)") 75 ''; 76 77 outputs = [ "out" "info" "man" ]; 78 79 doCheck = true; 80 checkTarget = "test"; 81 82 meta = with lib; { 83 homepage = "https://repo.or.cz/tinycc.git"; 84 description = "Small, fast, and embeddable C compiler and interpreter"; 85 longDescription = '' 86 TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other C 87 compilers, it is meant to be self-sufficient: you do not need an external 88 assembler or linker because TCC does that for you. 89 90 TCC compiles so fast that even for big projects Makefiles may not be 91 necessary. 92 93 TCC not only supports ANSI C, but also most of the new ISO C99 standard 94 and many GNU C extensions. 95 96 TCC can also be used to make C scripts, i.e. pieces of C source that you 97 run as a Perl or Python script. Compilation is so fast that your script 98 will be as fast as if it was an executable. 99 100 TCC can also automatically generate memory and bound checks while allowing 101 all C pointers operations. TCC can do these checks even if non patched 102 libraries are used. 103 104 With libtcc, you can use TCC as a backend for dynamic code generation. 105 ''; 106 license = licenses.lgpl21Only; 107 maintainers = with maintainers; [ joachifm AndersonTorres ]; 108 platforms = platforms.unix; 109 broken = stdenv.isDarwin; 110 }; 111} 112# TODO: more multiple outputs 113# TODO: self-compilation 114# TODO: provide expression for stable release