# This file is part of MXE. See LICENSE.md for licensing information.

PKG             := netpbm
$(PKG)_WEBSITE  := https://netpbm.sourceforge.io/
$(PKG)_DESCR    := Netpbm
$(PKG)_IGNORE   :=
$(PKG)_VERSION  := 10.35.96
$(PKG)_CHECKSUM := e652f3642e930156afaffb4c28e135efe026b41cd64be20e245b0c8124819eee
$(PKG)_SUBDIR   := $(PKG)-$($(PKG)_VERSION)
$(PKG)_FILE     := $(PKG)-$($(PKG)_VERSION).tgz
$(PKG)_URL      := https://$(SOURCEFORGE_MIRROR)/project/netpbm/super_stable/$($(PKG)_VERSION)/$($(PKG)_FILE)
$(PKG)_DEPS     := cc

define $(PKG)_UPDATE
    $(WGET) -q -O- 'https://sourceforge.net/projects/netpbm/files/super_stable/' | \
    $(SED) -n 's,.*netpbm-\([0-9][^>]*\)\.tgz.*,\1,p' | \
    head -1
endef

# The Netpbm package has its own weird build system...
# Parallel builds don't work, so we use -j1 explicitly.

define $(PKG)_BUILD
    # Create a suitable configuration
    cp '$(1)/Makefile.config.in' '$(1)/Makefile.config'
    echo 'DEFAULT_TARGET=nonmerge'          >> '$(1)/Makefile.config'
    echo 'CC=$(TARGET)-gcc'                 >> '$(1)/Makefile.config'
    echo 'LD=$(TARGET)-gcc'                 >> '$(1)/Makefile.config'
    echo 'LINKERISCOMPILER=Y'               >> '$(1)/Makefile.config'
    echo 'LINKER_CAN_DO_EXPLICIT_LIBRARY=Y' >> '$(1)/Makefile.config'
    echo 'AR=$(TARGET)-ar'                  >> '$(1)/Makefile.config'
    echo 'RANLIB=$(TARGET)-ranlib'          >> '$(1)/Makefile.config'
    echo 'OMIT_NETWORK=y'                   >> '$(1)/Makefile.config'
    echo 'DONT_HAVE_PROCESS_MGMT=Y'         >> '$(1)/Makefile.config'
    echo 'NETPBMLIBTYPE=unixstatic'         >> '$(1)/Makefile.config'
    echo 'NETPBMLIBSUFFIX=a'                >> '$(1)/Makefile.config'
    # Build only the library
    $(MAKE) -C '$(1)' -j1 PROG_SUBDIRS=
    # Package everything into a package directory. Use '-i' to ignore
    # failures that happen because we did not build all the tools.
    $(MAKE) -C '$(1)' -j1 -i package pkgdir='$(1)/mxe-pkgdir'
    # Install only the library from that package directory
    $(INSTALL) -d '$(PREFIX)/$(TARGET)/include'
    $(INSTALL) -m644 '$(1)/mxe-pkgdir/include/'* '$(PREFIX)/$(TARGET)/include'
    $(INSTALL) -d '$(PREFIX)/$(TARGET)/lib'
    $(INSTALL) -m644 '$(1)/mxe-pkgdir/link/libnetpbm.a' '$(PREFIX)/$(TARGET)/lib/'
endef

$(PKG)_BUILD_SHARED =
