1{ stdenv, fetchgit, cmake, pkgconfig, gtk3, cf-private, Cocoa }:
2
3let
4 shortName = "libui";
5 version = "3.1a";
6 backend = if stdenv.isDarwin then "darwin" else "unix";
7in
8
9stdenv.mkDerivation rec {
10 name = "${shortName}-${version}";
11 src = fetchgit {
12 url = "https://github.com/andlabs/libui.git";
13 rev = "6ebdc96b93273c3cedf81159e7843025caa83058";
14 sha256 = "1lpbfa298c61aarlzgp7vghrmxg1274pzxh1j9isv8x758gk6mfn";
15 };
16
17 nativeBuildInputs = [ cmake pkgconfig ];
18 buildInputs = stdenv.lib.optional stdenv.isLinux gtk3
19 ++ stdenv.lib.optionals stdenv.isDarwin [ Cocoa cf-private /* For NSDefaultRunLoopMode */ ];
20
21 preConfigure = stdenv.lib.optionalString stdenv.isDarwin ''
22 sed -i 's/set(CMAKE_OSX_DEPLOYMENT_TARGET "10.8")//' ./CMakeLists.txt
23 '';
24
25 installPhase = ''
26 mkdir -p $out/{include,lib}
27 mkdir -p $out/lib/pkgconfig
28 '' + stdenv.lib.optionalString stdenv.isLinux ''
29 mv ./out/${shortName}.so.0 $out/lib/
30 ln -s $out/lib/${shortName}.so.0 $out/lib/${shortName}.so
31 '' + stdenv.lib.optionalString stdenv.isDarwin ''
32 mv ./out/${shortName}.A.dylib $out/lib/
33 ln -s $out/lib/${shortName}.A.dylib $out/lib/${shortName}.dylib
34 '' + ''
35 cp $src/ui.h $out/include
36 cp $src/ui_${backend}.h $out/include
37
38 cp ${./libui.pc} $out/lib/pkgconfig/${shortName}.pc
39 substituteInPlace $out/lib/pkgconfig/${shortName}.pc \
40 --subst-var-by out $out \
41 --subst-var-by version "${version}"
42 '';
43 postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
44 install_name_tool -id $out/lib/${shortName}.A.dylib $out/lib/${shortName}.A.dylib
45 '';
46
47 meta = with stdenv.lib; {
48 homepage = https://github.com/andlabs/libui;
49 description = "Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.";
50 license = licenses.mit;
51 platforms = platforms.unix;
52 };
53}