##
##  minicom.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_dist   2.7.1
%define       V_subdir 4215

#   package information
Name:         minicom
Summary:      Serial Line Terminal Program
URL:          http://alioth.debian.org/projects/minicom/
Vendor:       Jukka Lahtinen
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Communication
License:      BSD
Version:      %{V_dist}
Release:      20171202

#   list of sources
Source0:      http://alioth.debian.org/frs/download.php/file/%{V_subdir}/minicom-%{V_dist}.tar.gz
Patch0:       minicom.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, lrzsz, make
PreReq:       OpenPKG, openpkg >= 20160101, lrzsz
BuildPreReq:  ncurses, libiconv
PreReq:       ncurses, libiconv

%description
    Minicom is a menu driven communication program for serial line
    communications. It emulates ANSI and VT102 terminals, has a dialing
    directory and automatic ZMODEM download support.

%track
    prog minicom = {
        version   = %{V_dist}
        url       = http://alioth.debian.org/project/showfiles.php?group_id=30018&release_id=96
        regex     = minicom-(\d+\.\d+)\.tar\.gz
    }
    prog minicom:subdir = {
        version   = %{V_subdir}
        url       = http://alioth.debian.org/project/showfiles.php?group_id=30018&release_id=96
        regex     = /(\d+)/minicom-\d+\.\d+\.tar\.gz
    }

%prep
    %setup -q
    %patch -p0

%build
    #   determine default serial device
    device="/dev/modem"
    lockdir="/var/lock"
    case "%{l_platform -t}" in
        *-freebsd* ) device=/dev/cuaa0;    lockdir=/var/spool/lock  ;;
        *-linux*   ) device=/dev/ttyS0;    lockdir=/var/lock        ;;
        *-sunos*   ) device=/dev/cua/a;    lockdir=/var/spool/locks ;;
        *-darwin*  ) device=/dev/cu.modem; lockdir=/var/tmp         ;;
    esac

    #   configure sources
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags ncurses .}" \
    LDFLAGS="%{l_ldflags}" \
    LIBS="-liconv" \
    ./configure \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --sysconfdir=%{l_prefix}/etc/minicom \
        --enable-lock-dir=$lockdir \
        --enable-dfl-port=$device \
        --enable-dfl-baud=9600 \
        --disable-nls

    #   build programs
    %{l_make} %{l_mflags -O}

%install

    #   pre-create installation area
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/minicom

    #   install programs
    %{l_make} %{l_mflags} install \
        prefix=$RPM_BUILD_ROOT%{l_prefix} \
        exec_prefix=$RPM_BUILD_ROOT%{l_prefix} \
        mandir=$RPM_BUILD_ROOT%{l_prefix}/man

    #   add configuration files
    echo "root" >$RPM_BUILD_ROOT%{l_prefix}/etc/minicom/minicom.users
    ( echo "pu baudrate  9600"
      echo "pu bits      8"
      echo "pu parity    N"
      echo "pu stopbits  1"
      echo "pu minit     ^M"
      echo "pu mreset    ^M"
      echo "pu mhangup   ^M"
    ) >minirc.dfl
    %{l_shtool} install -c -m 644 \
        minirc.dfl $RPM_BUILD_ROOT%{l_prefix}/etc/minicom/

    #   strip binaries
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true

    #   determine installation files
    attr_cfg="644,uucp,%{l_mgrp}"
    attr_dev="4755,uucp,%{l_mgrp}"
    case "%{l_platform -t}" in
        *-freebsd* )
            attr_cfg="644,uucp,%{l_mgrp}"
            attr_dev="6755,uucp,dialer"
            ;;
        *-linux* )
            attr_cfg="644,%{l_musr},%{l_mgrp}"
            attr_dev="2755,%{l_musr},`ls -l /dev/ttyS0 | awk '{print $4;}'`"
            ;;
        *-sunos* )
            attr_cfg="644,uucp,%{l_mgrp}"
            attr_dev="4755,uucp,%{l_mgrp}"
            ;;
        *-darwin* )
            attr_cfg="644,%{l_musr},%{l_mgrp}"
            attr_dev="2755,%{l_musr},wheel"
            ;;
    esac
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        "%config %{l_prefix}/etc/minicom/*" \
        "%config %attr($attr_cfg) %{l_prefix}/etc/minicom/minirc.dfl" \
        "%attr($attr_dev) %{l_prefix}/bin/minicom"

%files -f files

%clean

