about summary refs log tree commit diff
path: root/pkgs/applications/virtualization/qemu/binfmt-p-wrapper.nix
blob: fada14569299b6c957ae0d8b567f10dd2eed4750 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# binfmt preserve-argv[0] wrapper
#
# More details in binfmt-p-wrapper.c
#
# The wrapper has to be static so LD_* environment variables
# cannot affect the execution of the wrapper itself.

{ lib, stdenv, pkgsStatic, enableDebug ? false }:

name: emulator:

pkgsStatic.stdenv.mkDerivation {
  inherit name;

  src = ./binfmt-p-wrapper.c;

  dontUnpack = true;
  dontInstall = true;

  buildPhase = ''
    runHook preBuild

    mkdir -p $out/bin
    $CC -o $out/bin/${name} -static -std=c99 -O2 \
        -DTARGET_QEMU=\"${emulator}\" \
        ${lib.optionalString enableDebug "-DDEBUG"} \
        $src

    runHook postBuild
  '';
}