# Maintainer: Tobias Powalowski <tpowa@archlinux.org>
# Contributor: Surain Mallawa Arachchi <mas@crc32.net>

pkgname=linux-atm
pkgver=2.5.2
pkgrel=9
pkgdesc="Drivers and tools to support ATM networking under Linux."
arch=('x86_64' 'aarch64')
depends=('glibc')
optdepends=('flex: for atmsigd')
url="http://linux-atm.sourceforge.net/"
license=(GPL-2.0-only)
source=(https://downloads.sourceforge.net/sourceforge/${pkgname}/${pkgname}-${pkgver}.tar.gz
        linux-atm-man-pages.patch
        linux-atm-remove-define-hacks.patch
        linux-atm-linux-5.2-SIOCGSTAMP.patch
	linux-atm-2.5.2-linux-headers-5.19.patch
	linux-atm-2.5.2-headers.patch
        linux-atm-string-formatting.patch
	linux-atm-use_socklen_t.patch)
options=(!makeflags)
b2sums=('329aad437a1e6a17fd7d7d2b81c976a76c684aaf127006ed3af1e998a0f52df056747cc84fc13c933dc15c07246f1f00e4ff101ac98ef1dd1bea102830a83625'
        'eb7dca42e6729a3f6ba15ee353d6054e9487ff04791fe03dbd5c29c8e3edf7d4909d450ee7ac99e20c78568977bc6e2300078c1e353dfe14fe9eabc58a54775b'
        'bcc3d953dbf03902733414bc03a432f6ae25383874358ba37a21586e986a5c26a11a3b54a80be7403a77d3b1ae46a2eab8ba644a1f2dd4b97374fcf7adcdaf9a'
        '26fb42c7c49a56cdb238d22ab65096e7db684550f0f27c208262a2b2b73f790aa3bf4cea65bab176317c444deaf58a4a717e8a83cdb5d2f59474aa6cec814a23'
        '8187606a2dee1345e23a1083b8718a0d0a650f0f9d032a81a8bb42b988b7eefd821bb54b6681dbcd49bc4633fc59e2c7afd78d31e3610d0ded3e839c6997da26'
        '1a1280f70c9232ddc39b664e1a533258c6bf7a05017f471544d442b69a9f9b73775d914b1433359adbcc571218207ec7413e2a64e67432489a8b417251b32e3d'
        '726b221428457374e97f77425f56df488f93ad4a3a0aab229a19113d3d06419621de994d713eab872ff86de0c44ef47043aaab0728c06b5734c2d68887eeafd3'
        '0f514916bc2115f8ad5995f993b79aebb2cf1e464723eb6ea13e9434b7d2a61ec75b4239e04a3311aeebc6d3a2573fdd69635edf22bc9cd149042023f92001db')

prepare() {
  cd "${pkgname}-${pkgver}"
  patch -Np1 -i ../linux-atm-man-pages.patch
  patch -Np1 -i ../linux-atm-remove-define-hacks.patch
  patch -Np1 -i ../linux-atm-linux-5.2-SIOCGSTAMP.patch
  patch -Np1 -i ../linux-atm-string-formatting.patch
  # gentoo patches
  patch -Np1 -i ../linux-atm-2.5.2-linux-headers-5.19.patch
  patch -Np1 -i ../linux-atm-2.5.2-headers.patch
  # fedora patch
  patch -Np1 -i ../linux-atm-use_socklen_t.patch

  # install firmware in /usr/lib
  sed -i "s#/lib/firmware#/usr/lib/firmware#" src/extra/Makefile.in
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  ./configure --build=$CHOST --prefix=/usr --sbindir=/usr/bin --sysconfdir=/etc
  make
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make DESTDIR="${pkgdir}" install
}
