# -*- 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               codeberg 1.0
PortGroup               conflicts_build 1.0
PortGroup               makefile 1.0

name                    cdrtools
codeberg.setup          schilytools schilytools 2024-03-21
version                 3.02-${codeberg.version}
revision                0
categories              sysutils audio
conflicts               dvdrtools
maintainers             {hotmail.com:amtor @RobK88} \
                        openmaintainer
license                 CDDL-1 LGPL-2.1 GPL-2+ GPL-2

description             ISO 9660 filesystem and CD creation tools
long_description        The cdrtools software includes programs to create \
                        and/or extract ISO 9660 filesystems, verify their \
                        integrity, and write them to a disc.\nAlso included \
                        is a CD audio disc ripper.

checksums               rmd160  e937719c3a68efac9f6aacfaaaed4cb1775805e5 \
                        sha256  4d66bf35a5bc2927248fac82266b56514fde07c1acda66f25b9c42ccff560a02 \
                        size    5892015
                        
post-patch {
                        reinplace -locale C "s|-noclobber| |g" \
                        ${worksrcpath}/cdrecord/Makefile.dfl

                        reinplace -locale C "s|/opt/schily|${prefix}|g" \
                        ${worksrcpath}/btcflash/btcflash.1 \
                        ${worksrcpath}/cdda2wav/cdda2wav.1 \
                        ${worksrcpath}/cdrecord/cdrecord.1 \
                        ${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}/mkisofs/diag/isoinfo.8 \
                        ${worksrcpath}/patch/tests/random/cmptest.sh \
                        ${worksrcpath}/patch/tests/random/gentest.sh \
                        ${worksrcpath}/readcd/readcd.1 \
                        ${worksrcpath}/rmt/rmt.1 \
                        ${worksrcpath}/rscsi/default-rscsi.sample \
                        ${worksrcpath}/rscsi/rscsi.1 \
                        ${worksrcpath}/scgskeleton/scgskeleton.1 \
                        ${worksrcpath}/sformat/datio.c \
                        ${worksrcpath}/smake/job.c \
                        ${worksrcpath}/smake/make.c \
                        ${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 ppc64 to i386 if so desired
            platform powerpc {
                build.args-append   COPTX="-arch ppc -arch ppc64" \
                                    C++OPTX="-arch ppc -arch ppc64" \
                                    LDOPTX="-arch ppc -arch ppc64"
            }
#       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 \
                        port:pulseaudio

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 {
                        set keepPrograms  [ list    ${destroot}${prefix}/bin/btcflash \
                                                    ${destroot}${prefix}/bin/cdda2mp3 \
                                                    ${destroot}${prefix}/bin/cdda2ogg \
                                                    ${destroot}${prefix}/bin/cdda2wav \
                                                    ${destroot}${prefix}/bin/cdrecord \
                                                    ${destroot}${prefix}/bin/devdump \
                                                    ${destroot}${prefix}/bin/isodebug \
                                                    ${destroot}${prefix}/bin/isodump \
                                                    ${destroot}${prefix}/bin/isoinfo \
                                                    ${destroot}${prefix}/bin/isovfy \
                                                    ${destroot}${prefix}/bin/mkhybrid \
                                                    ${destroot}${prefix}/bin/mkisofs \
                                                    ${destroot}${prefix}/bin/readcd \
                                                    ${destroot}${prefix}/bin/scgcheck \
                                                    ${destroot}${prefix}/bin/scgskeleton ]

                        set allPrograms [ glob ${destroot}${prefix}/bin/* ]
                        foreach f $allPrograms {
                            if { [ lsearch $keepPrograms $f ] == -1 } {
                                delete $f
                            }
                        }

                        set keepPrograms  [ list ${destroot}${prefix}/sbin/rscsi ]
                        set allPrograms [ glob ${destroot}${prefix}/sbin/* ]
                        foreach f $allPrograms {
                            if { [ lsearch $keepPrograms $f ] == -1 } {
                                delete $f
                            }
                        }

                        set keepDocs [ list ${destroot}${prefix}/share/doc/cdda2wav \
                                            ${destroot}${prefix}/share/doc/cdrecord \
                                            ${destroot}${prefix}/share/doc/libparanoia \
                                            ${destroot}${prefix}/share/doc/mkisofs \
                                            ${destroot}${prefix}/share/doc/rscsi \
                                            ${destroot}${prefix}/share/doc/mkisofs ]
                        set allDocs [ glob -type d ${destroot}${prefix}/share/doc/* ]
                        foreach f $allDocs {
                            if { [ lsearch $keepDocs $f ] == -1 } {
                                delete $f
                            }
                        }

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

                        set keepMan1Pages [ list \
                                            ${destroot}${prefix}/share/man/man1/btcflash.1 \
                                            ${destroot}${prefix}/share/man/man1/cdda2mp3.1 \
                                            ${destroot}${prefix}/share/man/man1/cdda2ogg.1 \
                                            ${destroot}${prefix}/share/man/man1/cdda2wav.1 \
                                            ${destroot}${prefix}/share/man/man1/cdrecord.1 \
                                            ${destroot}${prefix}/share/man/man1/readcd.1 \
                                            ${destroot}${prefix}/share/man/man1/rscsi.1 \
                                            ${destroot}${prefix}/share/man/man1/scgcheck.1 \
                                            ${destroot}${prefix}/share/man/man1/scgskeleton.1 ]
                        set allMan1Pages [ glob ${destroot}${prefix}/share/man/man1/* ]
                        foreach f $allMan1Pages {
                            if { [ lsearch $keepMan1Pages $f ] == -1 } {
                                delete $f
                            }
                        }

                        delete  ${destroot}${prefix}/share/man/help \
                                ${destroot}${prefix}/share/man/man3 \
                                ${destroot}${prefix}/share/man/man5 \
                                ${destroot}${prefix}/share/man/man8/sformat.8

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

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