anchor.diff:    # ToDo: probably not all .la files are completely fixed, but it shouldn't matter
     postInstall = with stdenv.lib; ''
       mv -t "$drivers/lib/" \
  -  '' + optionalString enableExtraFeatures ''
  -      `#$out/lib/libXvMC*` \
  -      $out/lib/gbm $out/lib/libgbm* \
  -  '' + ''
  -      $out/lib/gallium-pipe \
  +      $out/lib/libXvMC* \
         $out/lib/libdricore* \
         $out/lib/libgallium* \
         $out/lib/vdpau \
  +      $out/lib/{bellagio,d3d} \
         $out/lib/libxatracker*
  +
  +    mv -t "$drivers/lib/dri/" \
  +      "$out"/lib/dri/*
  +    rmdir "$out/lib/dri"
   
       mkdir -p {$osmesa,$drivers}/lib/pkgconfig
       mv -t $osmesa/lib/ \
  
positive.code:   - libOSMesa is in $osmesa (~4 MB)
  */
  
  let
    version = "10.5.3";
    # this is the default search path for DRI drivers
    driverLink = "/run/opengl-driver" + stdenv.lib.optionalString stdenv.isi686 "-32";
    clang = if llvmPackages ? clang-unwrapped then llvmPackages.clang-unwrapped else llvmPackages.clang;
  in
  with { inherit (stdenv.lib) optional optionals optionalString; };
  
  stdenv.mkDerivation {
    name = "mesa-noglu-${version}";
  
negative.code: 
    '' + /* now fix references in .la files */ ''
      sed "/^libdir=/s,$out,$drivers," -i \
        $drivers/lib/libXvMC*.la \
        $drivers/lib/vdpau/*.la \
        $drivers/lib/libdricore*.la
  
      sed "s,$out\(/lib/libdricore[0-9\.]*.la\),$drivers\1,g" \
        -i $drivers/lib/*.la $drivers/lib/*/*.la
  
      sed "/^libdir=/s,$out,$osmesa," -i \
        $osmesa/lib/libOSMesa*.la
  
    '' + /* set the default search path for DRI drivers; used e.g. by X server */ ''
      substituteInPlace "$out/lib/pkgconfig/dri.pc" --replace '$(drivers)' "${driverLink}"
    '' + /* move vdpau drivers to $drivers/lib, so they are found */ ''
      mv "$drivers"/lib/vdpau/* "$drivers"/lib/ && rmdir "$drivers"/lib/vdpau
    '';
    #ToDo: @vcunat isn't sure if drirc will be found when in $out/etc/, but it doesn't seem important ATM */
  
    postFixup =
      # add RPATH so the drivers can find the moved libgallium and libdricore9
      # moved here to avoid problems with stripping patchelfed files
    ''
      for lib in $drivers/lib/*.so* $drivers/lib/*/*.so*; do
        if [[ ! -L "$lib" ]]; then
          patchelf --set-rpath "$(patchelf --print-rpath $lib):$drivers/lib" "$lib"
        fi
      done
    '';
    # ToDo + /* check $out doesn't depend on llvm */ ''
    # builder failures are ignored for some reason
    #   grep -qv '${llvmPackages.llvm}' -R "$out"
  
    passthru = { inherit libdrm version driverLink; };
  
    meta = with stdenv.lib; {
      description = "An open source implementation of OpenGL";
      homepage = http://www.mesa3d.org/;
      license = licenses.mit; # X11 variant, in most files
      platforms = platforms.mesaPlatforms;
      maintainers = with maintainers; [ eduarrrd simons vcunat ];
    };
  }
  