# $Id: Portfile 119542 2014-04-29 22:12:57Z ryandesign@macports.org $

PortSystem 1.0

name            netpbm
version         10.66.02
svn.revision    2191
revision        1
categories      graphics
license         {BSD GPL-2 IJG Permissive}
maintainers     ryandesign openmaintainer
description     Image manipulation
long_description \
    A whole bunch of utilities for primitive manipulation \
    of graphic images.  Wide array of converters from one \
    graphics format to another.  E.g. from g3 fax format to \
    jpeg.  Many basic graphics editing tools such as \
    magnifying and cropping.

homepage        http://netpbm.sourceforge.net/
platforms       darwin freebsd linux

# Parallel building is not reliable in netpbm 10.64.01.
# See http://trac.macports.org/ticket/17516#comment:7 .
# If you're thinking about enabling parallel build in the Portfile,
# please make sure to test it on OS X 10.4 as well!  Thanks!
use_parallel_build  no

depends_build   path:bin/perl:perl5

depends_lib     port:jasper \
                port:jbigkit \
                port:jpeg \
                port:libpng \
                port:libxml2 \
                port:tiff \
                port:xorg-libX11 \
                port:zlib

fetch.type      svn
svn.url         https://svn.code.sf.net/p/netpbm/code/advanced/
worksrcdir      advanced

patchfiles      patch-pm_config.in.h.diff \
                patch-lib-Makefile.diff \
                patch-converter-other-giftopnm.c-strcaseeq.diff \
                patch-converter-other-jpeg2000.diff

post-patch {
    reinplace "s|@@PREFIX@@|${prefix}|g" ${worksrcpath}/pm_config.in.h
}

variant universal {}

configure.cflags-append -fno-common

set jasperlib -ljasper
set ldreloc NONE
set ldshlib {-shared -Wl,-soname,$(SONAME)}
set linker_can_do_explicit_library N
set netpbmlibtype unixshared
set netpbmlibsuffix so
set want_sse N

configure {
    # The netpbm configure script is interactive, and appends its results to
    # the config.mk file; doc/INSTALL recommends packagers do that manually.
    copy -force ${worksrcpath}/config.mk.in ${worksrcpath}/config.mk
    set configmk [open ${worksrcpath}/config.mk a]
    puts ${configmk} "
CC = ${configure.cc}
CFLAGS = ${configure.cflags} ${configure.cppflags} [get_canonical_archflags cc]
CFLAGS_CONFIG = \$(CFLAGS)
JASPERHDR_DIR = ${prefix}/include
JASPERLIB = ${jasperlib}
JPEGLIB = -ljpeg
LDFLAGS = ${configure.ldflags} [get_canonical_archflags ld]
LDRELOC = ${ldreloc}
LDSHLIB = ${ldshlib}
LINKER_CAN_DO_EXPLICIT_LIBRARY = ${linker_can_do_explicit_library}
NETPBMLIBTYPE = ${netpbmlibtype}
NETPBMLIBSUFFIX = ${netpbmlibsuffix}
PNGLIB = -lpng
TIFFLIB = -ltiff
WANT_SSE = ${want_sse}
ZLIB = -lz
"
    close ${configmk}
}

platform darwin {
    set ldshlib "\$(LDFLAGS) -dynamiclib -install_name ${prefix}/lib/libnetpbm.\$(MAJ).dylib -compatibility_version \$(MAJ) -current_version \$(MAJ).\$(MIN).\$(NETPBM_POINT_RELEASE)"
    set netpbmlibtype dylib
    set netpbmlibsuffix dylib
}

platform linux {
    set ldreloc {ld --reloc}
    set linker_can_do_explicit_library Y
}

platform freebsd {
    depends_build-append port:libtool

    patchfiles-append patch-libopt.c.diff

    set jasperlib ${prefix}/lib/libjasper.la
    set ldshlib "${prefix}/lib/glibtool --mode=link gcc"
}

build.args    "messages=yes"
build.target  ""
build.type    gnu

destroot.target   package
destroot.destdir  pkgdir=${destroot}${prefix}

pre-destroot {
    delete ${destroot}${prefix}
}

post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/netpbm
    eval move ${destroot}${prefix}/bin/doc.url [glob ${destroot}${prefix}/misc/*] ${destroot}${prefix}/share/netpbm
    move ${destroot}${prefix}/man ${destroot}${prefix}/share/
     move ${destroot}${prefix}/link/libnetpbm.a ${destroot}${prefix}/lib

    eval delete [glob -type f -directory ${destroot}${prefix} *]

    foreach old_library {pbm pgm pnm ppm} {
        ln -s libnetpbm.dylib ${destroot}${prefix}/lib/lib${old_library}.dylib
    }
}

# work around bug in Apple's gcc build 4061
platform darwin 8 {
    pre-configure {
        set fl [open "| ${configure.cc} --version"]
        set data [read $fl]
        close $fl
        if {[regexp "build 4061" ${data}]} {
            ui_msg "On Mac OS X ${macosx_version}, ${name} ${version} does not work with gcc version \"${data}\"."
            return -code error "incompatible gcc version"
        }
    }
}

livecheck.type  regex
livecheck.url   https://sourceforge.net/p/netpbm/code/HEAD/log/?path=/advanced/version.mk&limit=1
livecheck.regex {(\d+(\.\d+)+)}
