# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem              1.0
PortGroup               makefile 1.0
PortGroup               conflicts_build 1.0
PortGroup               codeberg 1.0

name                    star
codeberg.setup          schilytools schilytools 2024-03-21
version                 1.7.0-${codeberg.version}
revision                0
categories              archivers
maintainers             {hotmail.com:amtor @RobK88} \
                        openmaintainer
license                 CDDL

description             The Schily fully POSIX compliant implementations of the cpio, tar \
                        and pax archivers including various utilities.
long_description        The ${name} port provides fully POSIX compliant implementations of \
                        the cpio, tar and pax archivers including various utilities. \
                        In particular, the ${name} port provides the Schily star, suntar,  \
                        ustar, gnutar (renamed sgnutar), scpio and spax archivers. \
                        \n \
                        \nThe Schily star archiver provides many advantages over GNU tar or \
                        BSD tar including a built in 'find', fast fifo, \
                        selectable cli, accurate sparse files, pattern matcher, sophiticated \
                        'diff', no name length limitations, the handling of ctimes, atimes \
                        and mtimes for files, the prevention of the clobbering of more recent \
                        files during extraction, automatic byte swap (when needed), automatic \
                        format detect, automatic compression detect, support for ACLs and \
                        file flags, support for all inode metadata, sophticated error \
                        control, 'ed' like pattern subsitutions, fast built in -copy mode \
                        and true incremental dump and restore features. \
                        \n \
                        \nExcept for the Schily cpio (or scpio) archiver, all the Schily \
                        archivers are fully compliant with the POSIX 1003.1-2001 standard! \
                        \n \
                        \nThe Schily cpio (or scpio) archiver is fully compliant with the \
                        previous POSIX 1003.1-1988 standard.  (The cpio archiver \
                        was dropped from the POSIX 1003.1-2001 standard). \
                        \n \
                        \nPLEASE NOTE:  Unlike the pax archiver provided by macOS, \
                        Schily's pax (or spax) archiver is fully compliant with the POSIX \
                        1003.1-2001 standard!  In other words, unlike the pax \
                        archiver provided by macOS, the Schily pax (or spax) archiver will \
                        actually create and read archives in the POSIX 1003.1-2001 pax \
                        archive format! \
                        \n \
                        \nAlso included is the Schily tartest utility used to test whether a \
                        tar archive is POSIX compliant and the star_sym utility which \
                        reads a inode database file from a previous incremental restore via \
                        the star archiver and prints the database in a human readable format. \
                        \n \
                        \nOmitted from the port are the mt, smt and rmt binaries to control \
                        magnetic tape drives.

checksums               rmd160  e937719c3a68efac9f6aacfaaaed4cb1775805e5 \
                        sha256  4d66bf35a5bc2927248fac82266b56514fde07c1acda66f25b9c42ccff560a02 \
                        size    5892015

post-patch {
                        reinplace -locale C "s|gnutar|sgnutar|g" \
                        ${worksrcpath}/star/gnutar.1

                        reinplace -locale C "s|-noclobber| |g" \
                        ${worksrcpath}/cdrecord/Makefile.dfl

                        reinplace -locale C "s|/opt/schily|${prefix}|g" \
                        ${worksrcpath}/DEFAULTS/Defaults.darwin \
                        ${worksrcpath}/DEFAULTS/Defaults.mac-os10 \
                        ${worksrcpath}/DEFAULTS_ENG/Defaults.darwin \
                        ${worksrcpath}/DEFAULTS_ENG/Defaults.mac-os10 \
                        ${worksrcpath}/libfind/find.c \
                        ${worksrcpath}/libfind/find_main.c \
                        ${worksrcpath}/librscg/scsi-remote.c \
                        ${worksrcpath}/patch/tests/random/cmptest.sh \
                        ${worksrcpath}/patch/tests/random/gentest.sh \
                        ${worksrcpath}/sformat/datio.c \
                        ${worksrcpath}/smake/job.c \
                        ${worksrcpath}/smake/make.c \
                        ${worksrcpath}/star/star.1 \
                        ${worksrcpath}/sunpro/Make/bin/make/common/misc.cc \
                        ${worksrcpath}/sunpro/Make/bin/make/common/read2.cc \
                        ${worksrcpath}/TEMPLATES/Defaults.gcc \
                        ${worksrcpath}/TEMPLATES/Defaults.clang \
                        ${worksrcpath}/TEMPLATES/Defaults.xcc \
                        ${worksrcpath}/ved/ved.h
}

proc port_conflict_check {p_port_name p_conflict_ver_min p_conflict_ver_max} {
    ui_info "Checking for conflict against port: ${p_port_name}"

    if { ![catch {set port_conflict_ver_info [lindex [registry_active ${p_port_name}] 0]}] } {
        set port_conflict_ver [lindex ${port_conflict_ver_info} 1]_[lindex ${port_conflict_ver_info} 2]
        ui_info "${p_port_name} active version: ${port_conflict_ver}"

        if { [vercmp ${port_conflict_ver} ${p_conflict_ver_min}] >= 0
            && [vercmp ${port_conflict_ver} ${p_conflict_ver_max}] <= 0 } {

            ui_info "${p_port_name} conflicts; declare build conflict"
            conflicts_build-append \
                ${p_port_name}
        }
    }
}

port_conflict_check     cdrtools 0.0 3.01_1

compiler.blacklist-append \
                        llvm-gcc-4.2 macports-llvm-gcc-4.2 {clang < 300}

configure.ldflags-append -lintl

pre-build {
    if { $universal_possible && [variant_isset universal] } {
#       Big Sur and Later
        if { ${os.platform} eq "darwin" && ${os.major} >= 20 } {
            platform i386 {
                build.args-append   COPTX="-arch x86_64 -arch arm64" \
                                    C++OPTX="-arch x86_64 -arch arm64" \
                                    LDOPTX="-arch x86_64 -arch arm64"
            }
            platform arm {
                build.args-append   COPTX="-arch x86_64 -arch arm64" \
                                    C++OPTX="-arch x86_64 -arch arm64" \
                                    LDOPTX="-arch x86_64 -arch arm64"
            }
#       Lion to Catalina
        } elseif { ${os.platform} eq "darwin" && ${os.major} >=11 } {
            platform i386 {
                build.args-append   COPTX="-arch x86_64 -arch i386" \
                                    C++OPTX="-arch x86_64 -arch i386" \
                                    LDOPTX="-arch x86_64 -arch i386"
            }
#       Snow Leopard
        } elseif { ${os.platform} eq "darwin" && ${os.major} ==10 } {
            platform i386 {
                build.args-append   COPTX="-arch x86_64 -arch i386" \
                                    C++OPTX="-arch x86_64 -arch i386" \
                                    LDOPTX="-arch x86_64 -arch i386"
            }
#           Note: Snow Leopard can only run 32bit ppc apps via Rosetta
            platform powerpc {
                build.args-append   COPTX="-arch ppc -arch i386" \
                                    C++OPTX="-arch ppc -arch i386" \
                                    LDOPTX="-arch ppc -arch i386"
            }
#       Tiger and Leopard
        } elseif { ${os.platform} eq "darwin" && ${os.major} >= 8 } {
#           Note: One could change ppc to ppc64 if so desired
            platform i386 {
                build.args-append   COPTX="-arch ppc -arch i386" \
                                    C++OPTX="-arch ppc -arch i386" \
                                    LDOPTX="-arch ppc -arch i386"
            }
#           Note: One could change ppc to ppc64 if so desired
            platform powerpc {
                build.args-append   COPTX="-arch ppc -arch i386" \
                                    C++OPTX="-arch ppc -arch i386" \
                                    LDOPTX="-arch ppc -arch i386"
            }
#       Panther and earlier
        } else {
            platform powerpc {
                build.args-append   COPTX="-arch ppc -arch ppc64" \
                                    C++OPTX="-arch ppc -arch ppc64" \
                                    LDOPTX="-arch ppc -arch ppc64"
            }
        }
    }
}

depends_build-append    port:smake \
                        port:gettext \
                        port:bison

depends_lib-append      port:gettext-runtime \
                        port:libiconv

build.cmd               smake

#
# Must specify INS_BASE and INS_RBASE in both the build and destroot phases
#
build.args-append       INS_BASE="${destroot}${prefix}" \
                        INS_RBASE="${destroot}${prefix}" \
                        DEFOSINCDIRS="${prefix}/include" \
                        CC_OPT=${configure.optflags}

destroot.destdir        INS_BASE="${destroot}${prefix}" \
                        INS_RBASE="${destroot}${prefix}" \
                        MANDIR=man \
                        DEFINSUSR=${install.user} \
                        DEFINSGRP=${install.group}

#
# smake does not support parallel building
# i.e. smake does not support the -j flag
#
use_parallel_build      no

post-destroot {
                        move    ${destroot}${prefix}/bin/gnutar \
                                ${destroot}${prefix}/bin/sgnutar

                        set keepPrograms    [ list  ${destroot}${prefix}/bin/scpio \
                                                    ${destroot}${prefix}/bin/sgnutar \
                                                    ${destroot}${prefix}/bin/spax \
                                                    ${destroot}${prefix}/bin/star \
                                                    ${destroot}${prefix}/bin/star_sym \
                                                    ${destroot}${prefix}/bin/suntar \
                                                    ${destroot}${prefix}/bin/tartest \
                                                    ${destroot}${prefix}/bin/ustar ]
                        set allPrograms [ glob ${destroot}${prefix}/bin/* ]
                        foreach f $allPrograms {
                            if { [ lsearch $keepPrograms $f ] == -1 } {
                                delete $f
                            }
                        }

                        delete ${destroot}${prefix}/sbin

                        set keepDocs [ list ${destroot}${prefix}/share/doc/star  ]
                        set allDocs [ glob -type d ${destroot}${prefix}/share/doc/* ]
                        foreach f $allDocs {
                            if { [ lsearch $keepDocs $f ] == -1 } {
                                delete $f
                            }
                        }

                        move    ${destroot}${prefix}/share/man/man1/gnutar.1 \
                                ${destroot}${prefix}/share/man/man1/sgnutar.1

                        set keepMan1Pages [ list \
                                            ${destroot}${prefix}/share/man/man1/scpio.1 \
                                            ${destroot}${prefix}/share/man/man1/sgnutar.1 \
                                            ${destroot}${prefix}/share/man/man1/spax.1 \
                                            ${destroot}${prefix}/share/man/man1/star.1 \
                                            ${destroot}${prefix}/share/man/man1/star_sym.1 \
                                            ${destroot}${prefix}/share/man/man1/suntar.1 \
                                            ${destroot}${prefix}/share/man/man1/tartest.1 \
                                            ${destroot}${prefix}/share/man/man1/ustar.1 ]
                        set allMan1Pages [ glob ${destroot}${prefix}/share/man/man1/* ]
                        foreach f $allMan1Pages {
                            if { [ lsearch $keepMan1Pages $f ] == -1 } {
                                delete $f
                            }
                        }

                        foreach f { man5/changeset.5 man5/sccschangeset.5 \
                                    man5/sccsfile.5 man5/streamarchive.5 \
                                    man5/makefiles.5 man5/makerules.5} {
                                        delete ${destroot}${prefix}/share/man/$f
                        }

                        delete  ${destroot}${prefix}/share/man/help \
                                ${destroot}${prefix}/share/man/man3 \
                                ${destroot}${prefix}/share/man/man8

                        delete  ${destroot}${prefix}/etc/sformat.dat \
                                ${destroot}${prefix}/etc/termcap \
                                ${destroot}${prefix}/etc/default/cdrecord \
                                ${destroot}${prefix}/etc/default/rscsi \
                                ${destroot}${prefix}/etc/default/rmt

                        delete  ${destroot}${prefix}/share/lib \
                                ${destroot}${prefix}/lib \
                                ${destroot}${prefix}/include

                        delete  ${destroot}${prefix}/ccs ${destroot}${prefix}/xpg4
}

notes "
    The gnutar binary provided in the star port has been prefixed with the character 's'
    (i.e. sgnutar) to distinguish it from the official gnutar binary.
    The correspondng man page has also been renamed and updated accordingly.
"
