distributable:
  url: https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v{{version.marketing}}/util-linux-{{version.raw}}.tar.xz
  strip-components: 1

versions:
  github: util-linux/util-linux/tags

provides:
  darwin:
    - bin/cal
    - bin/col
    - bin/colcrt
    - bin/colrm
    - bin/column
    - bin/flock
    - bin/getopt
    - bin/hardlink
    - bin/hexdump
    - bin/isosize
    - bin/logger
    - bin/look
    - bin/mcookie
    - bin/mesg
    - bin/namei
    - bin/rename
    - bin/renice
    - bin/rev
    - bin/scriptreplay
    - bin/setsid
    - bin/uuidgen
    - bin/uuidparse
    - bin/wall
    - bin/whereis
  linux:
    - bin/cal
    - bin/chmem
    - bin/choom
    - bin/chrt
    - bin/col
    - bin/colcrt
    - bin/colrm
    - bin/column
    - bin/dmesg
    - bin/eject
    - bin/fallocate
    - bin/fincore
    - bin/findmnt
    - bin/flock
    - bin/getopt
    - bin/hardlink
    - bin/hexdump
    - bin/ionice
    - bin/ipcmk
    - bin/ipcrm
    - bin/ipcs
    - bin/isosize
    - bin/kill
    - bin/last
    - bin/lastb
    - bin/linux32
    - bin/linux64
    - bin/logger
    - bin/look
    - bin/lsblk
    - bin/lscpu
    - bin/lsfd
    - bin/lsipc
    - bin/lsirq
    - bin/lslocks
    - bin/lslogins
    - bin/lsmem
    - bin/lsns
    - bin/mcookie
    - bin/mesg
    - bin/mount
    - bin/mountpoint
    - bin/namei
    - bin/nsenter
    - bin/prlimit
    - bin/rename
    - bin/renice
    - bin/rev
    - bin/script
    - bin/scriptlive
    - bin/scriptreplay
    - bin/setarch
    - bin/setsid
    - bin/taskset
    - bin/uclampset
    - bin/umount
    - bin/uname26
    - bin/unshare
    - bin/utmpdump
    - bin/uuidgen
    - bin/uuidparse
    - bin/wall
    - bin/wdctl
    - bin/whereis

dependencies:
  gnu.org/gettext: ^0

build:
  dependencies:
    gnu.org/bison: '*'
    freedesktop.org/pkg-config: '*'
    gnu.org/patch: '*'
    crates.io/semverator: '*'
  script:
    # thanks to MacPorts
    - |
      if test darwin = {{hw.platform}} && \
        semverator satisfies '<2.39' {{version}}; then
        patch -p0 <props/macports.patch
      fi

    # FIXME: waitpid (new in 2.39) fails to build
    - sed -i.bak 's/build_waitpid=yes ;;/build_waitpid=no ;;/g' configure
    - rm configure.bak

    - ./configure $ARGS

    - make --jobs {{hw.concurrency}} install

    - |
      cd "{{prefix}}/include"
      for x in $HEADERS; do
        mv "$x/$x.h" .
        ln -s "../$x.h" "$x/"
      done
  env:
    ARGS:
      - --prefix={{prefix}}
      - --disable-makeinstall-chown
      - --disable-makeinstall-setuid
    HEADERS:
      - blkid
      - libfdisk
      - libsmartcols
      - uuid
    linux:
      HEADERS:
      - libmount

test:
  dependencies:
    stedolan.github.io/jq: '*'
  script:
    test "$(echo 5 6 7 | column -tJN first,second,third | jq .table[0].second)" = '"6"'
