##
##  dolt.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 information
%define       V_dolt_base  1.59.9
%define       V_dolt_snap  20250913

#   package information
Name:         dolt
Summary:      SQL/Git Database Server
URL:          https://github.com/dolthub/dolt/
Vendor:       Dolt Community
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Database
License:      Apache
Version:      %{V_dolt_base}.%{V_dolt_snap}
Release:      20250913

#   list of sources
Source0:      http://download.openpkg.org/components/versioned/dolt/dolt-%{V_dolt_snap}.tar.xz

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, go
PreReq:       OpenPKG, openpkg >= 20160101

%description
    Dolt is a SQL database that you can fork, clone, branch, merge, push
    and pull just like a Git repository. Connect to Dolt just like any
    MySQL database to run queries or update the data using SQL commands.
    Use the command line interface to import CSV files, commit your
    changes, push them to a remote, or merge your teammate's changes.
    All the commands you know for Git work exactly the same for Dolt.
    Git versions files, Dolt versions tables. It's like Git and MySQL
    had a baby.

%track
    prog dolt = {
        version   = %{V_dolt_base}
        url       = https://github.com/dolthub/dolt/releases
        regex     = tree/v(\d+\.\d+\.\d+)
    }

%prep
    %setup -q -n dolt
    (   cd pkg/mod/github.com/dolthub/go-mysql-server@*/internal/sockstate
        sed -e 's;linux;freebsd;g' <netstat_linux.go >netstat_freebsd.go
        sed -i -e 's;darwin;freebsd;g' netstat_unix.go
    ) || exit $?

%build
    #   build program
    (   export GOPATH=`pwd`
        cd $GOPATH/src/github.com/dolthub/dolt/go
        go build -v -o bin/dolt ./cmd/dolt/
    ) || exit $?

%install
    #   create directory hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin

    #   install program
    %{l_shtool} install -c -s -m 755 \
        src/github.com/dolthub/dolt/go/bin/dolt \
        $RPM_BUILD_ROOT%{l_prefix}/bin/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

