#
# flexbv board viewer
#
{
  stdenv,
  libGL,
  SDL2,
  makeWrapper,
  buildFHSEnv,
  libz,
  fontconfig
}:
let

	#
	# The FlexBV provided binaries are static and self-unpacking, with a hardcoded next-stage
	# dynamic loader path; and the format is an atypical variant of UPX.
	#
	# We'll create an inner package, and wrap it in an FHSEnv so we don't have to deal
	# with patching the interpreter.
	#
  flexbv = stdenv.mkDerivation {
  	pname = "flexbv-unwrapped";
  	version = "5.0345";

  	src = ../proprietary/flexbv5/FlexBV-5.0436-linux-3N5871753H701314U.tgz;

  	dontBuild = true;
  	dontConfigure = true;

  	nativeBuildInputs = [
  		makeWrapper
  	];

  	buildInputs = [
  		libGL
  		SDL2.out
  		libz.out
  		fontconfig.lib
  	];

  	# Set up the env with our binaries.
    installPhase = ''
    	mkdir -p $out/bin
    	cp * $out/bin
    '';
  };

in buildFHSEnv {
	name = "flexbv";
	targetPkgs = (pkgs: flexbv.buildInputs ++ [ flexbv ]);
	runScript = ''
	  flexbv "$@"
  '';
}
