distributable:
  url: https://download.qemu.org/qemu-{{version}}.tar.xz
  strip-components: 1

versions:
  gitlab: qemu-project/qemu/tags

provides:
  - bin/qemu-img
  - bin/qemu-edid
  - bin/qemu-io
  - bin/qemu-nbd
  - bin/qemu-storage-daemon
  - bin/qemu-system-aarch64
  - bin/qemu-system-alpha
  - bin/qemu-system-arm
  - bin/qemu-system-avr
  - bin/qemu-system-cris
  - bin/qemu-system-hppa
  - bin/qemu-system-i386
  - bin/qemu-system-loongarch64
  - bin/qemu-system-m68k
  - bin/qemu-system-microblaze
  - bin/qemu-system-microblazeel
  - bin/qemu-system-mips
  - bin/qemu-system-mips64
  - bin/qemu-system-mips64el
  - bin/qemu-system-mipsel
  - bin/qemu-system-nios2
  - bin/qemu-system-or1k
  - bin/qemu-system-ppc
  - bin/qemu-system-ppc64
  - bin/qemu-system-riscv32
  - bin/qemu-system-riscv64
  - bin/qemu-system-rx
  - bin/qemu-system-s390x
  - bin/qemu-system-sh4
  - bin/qemu-system-sh4eb
  - bin/qemu-system-sparc
  - bin/qemu-system-sparc64
  - bin/qemu-system-tricore
  - bin/qemu-system-x86_64
  - bin/qemu-system-xtensa
  - bin/qemu-system-xtensaeb

dependencies:
  gnome.org/glib: 2
  capstone-engine.org: ^4
  pixman.org: ^0
  gnutls.org: ^3
  freedesktop.org/slirp: ^4
  virtualsquare.org/vde: ^2
  facebook.com/zstd: ^1
  invisible-island.net/ncurses: ^6
  libssh.org: ^0
  libpng.org: ^1

build:
  dependencies:
    gnu.org/bison: '*'
    github.com/westes/flex: '*'
    python.org: ~3.11
    ninja-build.org: '*'
    mesonbuild.com: '*'
  script:
    # TODO: linux virtfs <8 requires attr and libcap-ng
    - run: ARGS="$ARGS --enable-virtfs"
      if: '>=8'

    # https://gitlab.com/qemu-project/qemu/-/issues/1853
    - run: sed -i -e"s/-isystem', /-isystem' + /g" meson.build
      if: '>=8.1.4'

    - ./configure $ARGS
    - make --jobs {{ hw.concurrency }} install

    # Without this, `codesign` complains about resource forks in the binary
    - if: darwin
      run:
        - xattr -cr {{prefix}}/bin/*
  env:
    ARGS:
      - --prefix="{{prefix}}"
      - --disable-bsd-user
      - --disable-guest-agent
      - --enable-slirp
      - --enable-capstone
      - --enable-curses
      - --enable-libssh
      - --enable-vde
      - --enable-zstd
      - --extra-cflags=-DNCURSES_WIDECHAR=1
      - --disable-sdl
      - --disable-docs
    darwin:
      ARGS:
        - --enable-virtfs

test:
  dependencies:
    curl.se: '*'
    info-zip.org/unzip: '*'
  script: |
    qemu-system-aarch64 --version | grep "QEMU emulator version {{version}}"
    qemu-system-alpha --version | grep "QEMU emulator version {{version}}" 
    qemu-system-arm --version | grep "QEMU emulator version {{version}}"
    qemu-system-cris --version | grep "QEMU emulator version {{version}}"
    qemu-system-hppa --version | grep "QEMU emulator version {{version}}"
    qemu-system-i386 --version | grep "QEMU emulator version {{version}}"
    qemu-system-m68k --version | grep "QEMU emulator version {{version}}"
    qemu-system-microblaze --version | grep "QEMU emulator version {{version}}"
    qemu-system-microblazeel --version | grep "QEMU emulator version {{version}}"
    qemu-system-mips --version | grep "QEMU emulator version {{version}}"
    qemu-system-mips64 --version | grep "QEMU emulator version {{version}}"
    qemu-system-mips64el --version | grep "QEMU emulator version {{version}}"
    qemu-system-mipsel --version | grep "QEMU emulator version {{version}}"
    qemu-system-nios2 --version | grep "QEMU emulator version {{version}}"
    qemu-system-or1k --version | grep "QEMU emulator version {{version}}"
    qemu-system-ppc --version | grep "QEMU emulator version {{version}}"
    qemu-system-ppc64 --version | grep "QEMU emulator version {{version}}"
    qemu-system-riscv32 --version | grep "QEMU emulator version {{version}}"
    qemu-system-riscv64 --version | grep "QEMU emulator version {{version}}"
    qemu-system-rx --version | grep "QEMU emulator version {{version}}"
    qemu-system-s390x --version | grep "QEMU emulator version {{version}}"
    qemu-system-sh4 --version | grep "QEMU emulator version {{version}}"
    qemu-system-sh4eb --version | grep "QEMU emulator version {{version}}"
    qemu-system-sparc --version | grep "QEMU emulator version {{version}}"
    qemu-system-sparc64 --version | grep "QEMU emulator version {{version}}"
    qemu-system-tricore --version | grep "QEMU emulator version {{version}}"
    qemu-system-x86_64 --version | grep "QEMU emulator version {{version}}"
    qemu-system-xtensa --version | grep "QEMU emulator version {{version}}"
    qemu-system-xtensaeb --version | grep "QEMU emulator version {{version}}"

    curl -O "https://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/official/FD12FLOPPY.zip"
    unzip FD12FLOPPY.zip
    qemu-img info FLOPPY.img | grep "file format: raw"
