require 'package'

class Musl_expat < Package
  description 'James Clark\'s Expat XML parser library in C.'
  homepage 'https://sourceforge.net/projects/expat/'
  @_ver = '2.4.8'
  version @_ver
  license 'MIT'
  compatibility 'all'
  source_url 'https://prdownloads.sourceforge.net/project/expat/expat/2.4.8/expat-2.4.8.tar.xz'
  source_sha256 'f79b8f904b749e3e0d20afeadecf8249c55b2e32d4ebb089ae378df479dcaf25'

  binary_url({
    aarch64: 'https://gitlab.com/api/v4/projects/26210301/packages/generic/musl_expat/2.4.8_armv7l/musl_expat-2.4.8-chromeos-armv7l.tar.zst',
     armv7l: 'https://gitlab.com/api/v4/projects/26210301/packages/generic/musl_expat/2.4.8_armv7l/musl_expat-2.4.8-chromeos-armv7l.tar.zst',
       i686: 'https://gitlab.com/api/v4/projects/26210301/packages/generic/musl_expat/2.4.8_i686/musl_expat-2.4.8-chromeos-i686.tar.zst',
     x86_64: 'https://gitlab.com/api/v4/projects/26210301/packages/generic/musl_expat/2.4.8_x86_64/musl_expat-2.4.8-chromeos-x86_64.tar.zst'
  })
  binary_sha256({
    aarch64: 'da829889bc002774679a8ac8373a662b75469cd4e1e0efcf003165e3b1083e19',
     armv7l: 'da829889bc002774679a8ac8373a662b75469cd4e1e0efcf003165e3b1083e19',
       i686: 'e737950ec7ed54a5fa04d923e4f42710c063d1d8dd580a4f887d6b40e28a596d',
     x86_64: '06bfcf25868d41925874458068e56155028d027be365db5989079a92bb3570b2'
  })

  depends_on 'musl_native_toolchain' => :build

  is_musl
  patchelf
  is_static

  def self.patch
    system 'filefix'
  end

  def self.build
    system "#{MUSL_ENV_OPTIONS} ./configure --prefix=#{CREW_MUSL_PREFIX} \
        --enable-static \
        --with-pic"
    system 'make'
  end

  def self.install
    system 'make', "DESTDIR=#{CREW_DEST_DIR}", 'install'
  end
end
