code:
# Build recipe for meson.
#
# Copyright (c) 2018-2021-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=meson
version=0.61.0
release=1

# Define a category for the output of the package name
pkgcategory=devel

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=https://github.com/mesonbuild/meson/releases/download/${version}/$tarname

description="
A high performance build system.

Meson is a cross-platform build system designed to be both as fast
and as user friendly as possible.  It supports many languages and
compilers, including GCC, Clang and Visual Studio.  Its build
definitions are written in a simple non-turing complete DSL.
"

homepage=https://www.mesonbuild.com
license="Apache License v2.0"

# Source documentation
docs="COPYING PKG-INFO README.md"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    python3 setup.py install \
     --prefix=/usr \
     --root="$destdir"

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/devel/meson/recipe


code:
# Build recipe for nasm.
#
# Copyright (C) 2018, MMPG <mmpg@vp.pl>
# Copyright (c) 2018, 2021 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=nasm
version=2.15
release=1

# Define a category for the output of the package name
pkgcategory=devel

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=https://www.nasm.us/pub/nasm/releasebuilds/$version/$tarname

description="
A free portable assembler.

Designed for the Intel 80x86 microprocessor series, using primarily the
traditional Intel instruction mnemonics and syntax.
"

homepage=https://nasm.us
license=BSD

docs="AUTHORS CHANGES ChangeLog LICENSE README.md"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --mandir=$mandir \
     --docdir=$docsdir \
     --disable-pdf-compression \
     --enable-sections \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install install_rdf

    # Compress manpages
    lzip -9 "${destdir}/${mandir}/"man1/*.1

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

repo_name: dustdfg/dragora

path: recipes/devel/nasm/recipe

license: mit


code:
# Build recipe for ninja.
#
# Copyright (c) 2018-2019, 2021 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=ninja
version=1.10.2
release=1

# Define a category for the output of the package name
pkgcategory=devel

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=https://github.com/ninja-build/ninja/archive/v${version}/$tarname

description="
A small build system with a focus on speed.

Ninja is a small build system with a focus on speed.  It differs from
other build systems in two major respects: it is designed to have its
input files generated by a higher-level build system, and it is
designed to run builds as fast as possible.
"

homepage=https://ninja-build.org
license="Apache License v2.0"

# Source documentation
docs="COPYING doc/manual.asciidoc"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    python3 configure.py --bootstrap

    # Run tests
    #./ninja ninja_test
    #./ninja_test --gtest_filter=-SubprocessTest.SetWithLots

    mkdir -p "${destdir}/usr/bin"
    cp -p ninja "${destdir}/usr/bin/"
    chmod 755 "${destdir}/usr/bin/ninja"

    strip --strip-unneeded "${destdir}/usr/bin/ninja"

    # Add completions

    mkdir -p "${destdir}/usr/share/bash-completion/completions/ninja" \
             "${destdir}/usr/share/zsh/site-functions/_ninja"

    cp -p misc/bash-completion \
     "${destdir}/usr/share/bash-completion/completions/ninja"

    cp -p misc/zsh-completion \
     "${destdir}/usr/share/zsh/site-functions/_ninja"

    pylib=$( python3 -c 'import sysconfig; print(sysconfig.get_path("platlib"))' )
    mkdir -p "${destdir}/${pylib}"
    cp -p misc/ninja_syntax.py "${destdir}/${pylib}"

    chmod 644 \
     "${destdir}/usr/share/bash-completion/completions/ninja/bash-completion" \
     "${destdir}/usr/share/zsh/site-functions/_ninja/zsh-completion" \
     "${destdir}/${pylib}/ninja_syntax.py"

    unset -v pylib

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/devel/ninja/recipe


code:
# Build recipe for pkgconf.
#
# Copyright (c) 2016-2021 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=pkgconf
version=1.8.0
release=1

# Define a category for the output of the package name
pkgcategory=devel

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=https://distfiles.dereferenced.org/pkgconf/$tarname

description="
Package compiler and linker metadata toolkit.

pkgconf is a program which helps to configure compiler and linker flags
for development frameworks.  It is similar to pkg-config from
freedesktop.org.

libpkgconf is a library which provides access to most of pkgconf's
functionality, to allow other tooling such as compilers and IDEs
to discover and use frameworks configured by pkgconf.
"

homepage=https://git.dereferenced.org/pkgconf/pkgconf
license=Custom

# Source documentation
docs="AUTHORS COPYING NEWS README*"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --docdir=$docsdir \
     --enable-static=yes \
     --enable-shared=yes \
     --with-pkg-config-dir="/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig" \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    #make -j${jobs} check;	# It needs "kyua" ...
    make -j${jobs} DESTDIR="$destdir" install-strip

    # Create symlink-compatibility for those
    # programs looking for `pkg-config'
    ln -s pkgconf "${destdir}/usr/bin/pkg-config"

    # Include profile file
    mkdir -p "${destdir}/etc/profile.d"
    cp -p "${worktree}/archive/pkgconf/etc/profile.d/pkgconf.sh" \
           "${destdir}/etc/profile.d/"
    chmod 644 "${destdir}/etc/profile.d/pkgconf.sh"

    # To handle config file(s)
    touch "${destdir}/etc/profile.d/.graft-config"

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/devel/pkgconf/recipe


code:
# Build recipe for re2c.
#
# Copyright (c) 2018-2019, 2021 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=re2c
version=2.2
release=1

# Define a category for the output of the package name
pkgcategory=devel

tarname=${program}-${version}.tar.lz

# Remote source(s)
fetch=https://github.com/skvadrik/re2c/releases/download/${version}/$tarname

description="
A fast lexer generator for C and C++.

re2c is a free and open-source lexer generator for C and C++.  Its main
goal is generating fast lexers: at least as fast as their reasonably
optimized hand-coded counterparts.  Instead of using traditional
table-driven approach, re2c encodes the generated finite state automata
directly in the form of conditional jumps and comparisons.
"

homepage=https://www.re2c.org
license="Public domain"

# Source documentation
docs="CHANGELOG NO_WARRANTY README.md"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" CXXFLAGS="$QICXXFLAGS" \
     LDFLAGS="$QILDFLAGS -static" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --docdir=$docsdir \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1 bootstrap
    make -j${jobs} DESTDIR="$destdir" install

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}


code:
# Build recipe for rpcsvc-proto.
#
# Copyright (C) 2020-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=rpcsvc-proto
version=1.4.3
release=1

# Define a category for the output of the package name
pkgcategory=devel

tarname=${program}-${version}.tar.xz

# Remote source(s)
fetch=https://github.com/thkukuk/rpcsvc-proto/releases/download/v${version}/$tarname

description="
rpcsvc protocol definitions from Glibc.

This package contains rpcsvc proto.x files from Glibc, which are missing
in libtirpc.  Additional it contains rpcgen, which is needed to create
header files and sources from protocol files.
"

homepage=https://github.com/thkukuk/rpcsvc-proto/
license=BSD

docs="AUTHORS COPYING ChangeLog NEWS README THANKS"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" \
    CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --docdir=$docsdir \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install-strip

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/devel/rpcsvc-proto/recipe


code:
# Build recipe for strace.
#
# Copyright (c) 2018-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=strace
version=5.16
release=1

# Define a category for the output of the package name
pkgcategory=devel

tarname=${program}-${version}.tar.xz

# Remote source(s)
fetch=https://strace.io/files/${version}/$tarname

description="
System call tracer tool.

Strace is a tool to trace system calls and signals.
"

homepage=https://strace.io
license="BSD-3 clause"

# Source documentation
docs="AUTHORS COPYING CREDITS ChangeLog NEWS README*"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" \
    LDFLAGS="$QILDFLAGS -static" \
     $configure_args \
     --mandir=$mandir \
     --enable-mpers=no \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/devel/strace/recipe


code:
# Build recipe for tcl.
#
# Copyright (c) 2018, 2020-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=tcl
version=8.6.12
series_version="${version%.*}"
release=2

# Define a category for the output of the package name
pkgcategory=devel

tarname=${program}${version}-src.tar.gz

# Remote source(s)
fetch=https://prdownloads.sourceforge.net/tcl/$tarname

homepage=https://www.tcl.tk

description="
Tool command language.

Tcl (Tool Command Language) is a very powerful but easy to learn
dynamic programming language, suitable for a very wide range of uses,
including web and desktop applications, networking, administration,
testing and many more.  Open source and business-friendly, Tcl is a
mature yet evolving language that is truly cross platform, easily
deployed and highly extensible.

For more information, visit:
$homepage
"

license=Custom

# Source documentation
docs="ChangeLog README.md changes license.terms"
docsdir="${docdir}/${program}-${version}"

# Custom source directory
srcdir=${program}${version}

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    WD="$(pwd)"

    # Determine whether to use 64 bit support
    case $arch in
    amd64 | x32 )
        bit_flags=--enable-64bit
        ;;
    esac

    cd unix

    ./configure CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" \
    LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --enable-shared \
     --enable-threads \
     --enable-man-symlinks \
     --without-tzdata \
     --build="$(gcc -dumpmachine)" \
     $bit_flags

    unset -v bit_flags
    make -j${jobs} V=1

    # Current versions provided on this release
    itcl_version=4.2.2
    tdbc_version=1.1.3

    # Fix header and library paths
    sed -e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" \
        -e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib${libSuffix}@" \
        -i tclConfig.sh

    sed -e "s#${WD}/unix/pkgs/itcl${itcl_version}#/usr/lib${libSuffix}/itcl${itcl_version}#"      \
        -e "s#${WD}/pkgs/itcl${itcl_version}/generic#/usr/include#"                               \
        -e "s#${WD}/pkgs/itcl${itcl_version}#/usr/include#"                                       \
        -i pkgs/itcl${itcl_version}/itclConfig.sh

    sed -e "s#${WD}/unix/pkgs/tdbc${tdbc_version}#/usr/lib${libSuffix}/tdbc${tdbc_version}#"      \
        -e "s#${WD}/pkgs/tdbc${tdbc_version}/generic#/usr/include#"                               \
        -e "s#${WD}/pkgs/tdbc${tdbc_version}/library#/usr/lib${libSuffix}/tcl${series_version}#"  \
        -e "s#${WD}/pkgs/tdbc${tdbc_version}#/usr/include#"                                       \
        -i pkgs/tdbc${tdbc_version}/tdbcConfig.sh

    unset -v WD tdbc_version itcl_version

    make -j${jobs} DESTDIR="$destdir" install
    make -j${jobs} INSTALL_ROOT="$destdir" install-private-headers

    # Make symlink(s) for compatibility
    ln -s tclsh${series_version} "${destdir}/usr/bin/tclsh"
    ln -s libtcl${series_version}.so "${destdir}/usr/lib${libSuffix}/libtcl.so"
    ln -s libtclstub${series_version}.a "${destdir}/usr/lib${libSuffix}/libtclstub.a"

    unset -v series_version

    cd ..

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip --force -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/devel/tcl/recipe


code:
# Build recipe for texinfo.
#
# Copyright (c) 2016-2019, 2021 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=texinfo
version=6.8
release=2

# Define a category for the output of the package name
pkgcategory=devel

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch="
  https://ftpmirror.gnu.org/texinfo/$tarname
  https://ftp.gnu.org/gnu/texinfo/$tarname
"

description="
The GNU documentation system.

Texinfo is a documentation system that uses a single source
file to produce both online information and printed output.

It is primarily designed for writing software manuals.
"

homepage=https://www.gnu.org/software/texinfo
license=GPLv3+

# Source documentation
docs="AUTHORS COPYING ChangeLog NEWS README* TODO"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    # https://lists.gnu.org/archive/html/bug-texinfo/2021-09/msg00011.html
    patch -Np1 -i "${worktree}/patches/texinfo/headings-single.patch"

    ./configure CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" \
    LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docsdir \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install-strip
    make DESTDIR="$destdir" TEXMF="/usr/share/texmf" install-tex

    # Include a cron job

    mkdir -p "${destdir}/etc/cron.daily/"
    cp -p "${worktree}/archive/texinfo/etc/cron.daily/texinfo" \
          "${destdir}/etc/cron.daily/"
    chmod 0755 "${destdir}/etc/cron.daily/texinfo"

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/devel/texinfo/recipe


code:
# Build recipe for tk (Tcl/Tk).
#
# Copyright (c) 2018-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=tk
version=8.6.12
series_version=8.6
release=1

# Define a category for the output of the package name
pkgcategory=devel

tarname=${program}${version}-src.tar.gz

# Remote source(s)
fetch=https://prdownloads.sourceforge.net/tcl/$tarname

homepage=https://www.tcl.tk

description="
The TCL GUI ToolKit.

The tk package contains the TCL GUI ToolKit.

For more information, visit:
$homepage
"

license=Custom

# Source documentation
docs="ChangeLog README.md changes license.terms"
docsdir="${docdir}/${program}-${version}"

# Custom source directory
#srcdir="${program}${version%.*}"
srcdir="${program}${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    # Determine whether to use 64 bit support
    case $arch in
    amd64 | x32 )
        bit_flags=--enable-64bit
        ;;
    esac

    cd unix

    ./configure CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" \
    LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --enable-shared \
     --enable-threads \
     --enable-man-symlinks \
     --without-tzdata \
     --build="$(gcc -dumpmachine)" \
     $bit_flags

    unset -v bit_flags
    make -j${jobs} V=1

    # Thanks to "Beyond of Linux From Scratch"
    sed -e "s@^\(TK_SRC_DIR='\).*@\1/usr/include'@" \
        -e "/TK_B/s@='\(-L\)\?.*unix@='\1/usr/lib${libSuffix}@" \
        -i tkConfig.sh

    make -j${jobs} DESTDIR="$destdir" install
    make -j${jobs} INSTALL_ROOT="$destdir" install-private-headers

    # Make symlink(s) for compatibility
    ln -s wish${series_version} "${destdir}/usr/bin/wish"
    ln -s libtk${series_version}.so "${destdir}/usr/lib${libSuffix}/libtk.so"
    ln -s libtkstub${series_version}.a "${destdir}/usr/lib${libSuffix}/libtkstub.a"

    unset -v series_version

    cd ..

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/devel/tk/recipe


code:
# Build recipe for vala.
#
# Copyright (C) 2018-2019, 2021-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=vala
version=0.54.6
release=1

# Define a category for the output of the package name
pkgcategory=devel

tarname=${program}-${version}.tar.xz

# Remote source(s)
fetch="https://download.gnome.org/sources/vala/${version%.*}/$tarname"

description="
Compiler using the GObject type system.

Vala is a programming language using modern high level abstractions
without imposing additional runtime requirements and without using a
different ABI compared to applications and libraries written in C.

Vala uses the GObject type system and has additional code generation
routines that make targeting the GNOME stack simple.  Vala has many
other uses where native binaries are required.
"

homepage=https://wiki.gnome.org/Projects/Vala
license=LGPLv2.1

docs="AUTHORS COPYING ChangeLog NEWS README THANKS"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    # Note: --enable-valadoc requires Graphviz

    ./configure CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" \
    LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docsdir \
     --disable-valadoc \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} V=1 DESTDIR="$destdir" install-strip

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/devel/vala/recipe


code:
# Build recipe for valgrind.
#
# Copyright (c) 2017 Mateus P. Rodrigues <mprodrigues@dragora.org>.
# Copyright (c) 2017-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=valgrind
version=3.18.1
release=1

# Define a category for the output of the package name
pkgcategory=devel

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=ftp://sourceware.org/pub/valgrind/$tarname

description="
Generic framework for creating dynamic analysis tools.

Valgrind is an instrumentation framework for building dynamic analysis tools.
There are Valgrind tools that can automatically detect many memory management
and threading bugs, and profile your programs in detail. You can also use
Valgrind to build new tools.
"

homepage=https://valgrind.org/
license="GPLv2"

# Source documentation
docs="AUTHORS COPYING* FAQ.txt NEWS* README*"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    # Set installation for documentation directory
    patch -p0 < "${worktree}/patches/valgrind/valgrind-docdir.patch"

    # Set specific options for the architecture
    case $arch in
    i?86)
        arch_options="--enable-only32bit --build=$(gcc -dumpmachine)"
        ;;
    amd64 | x32 )
        arch_options="--enable-only64bit --build=$(gcc -dumpmachine)"
        ;;
    esac

    # We do not try to strip any debugging symbol as
    # suggested in README_PACKAGERS

    # Copy definition in order to build Valgrind (Thanks to "Alpine Linux")
    cp -p "${worktree}/archive/valgrind/musl.supp" .

    ./configure CPPFLAGS="-D_FORTIFY_SOURCE=0" \
     CFLAGS="-no-pie -fno-PIE -fPIC" \
     CXXFLAGS="-no-pie -fno-PIE -fPIC" \
     LDFLAGS="" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docsdir \
     --enable-tls \
     --enable-inner \
     --disable-ubsan \
     $arch_options

    unset -v arch_options

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install

    # Remove installed Valgrind's documentation for reduce the package size
    rm -rf "${destdir}/$docsdir"

    # Strip ELF executables excluding shared objects (as suggested)
    find "$destdir" -type f | xargs file | awk '/ELF/ && /executable/' | \
     cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/devel/valgrind/recipe


code:
# Build recipe for aspell.
#
# Copyright (c) 2018-2019, 2021 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=aspell
version=0.60.8
release=1

# Define a category for the output of the package name
pkgcategory=dict

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=ftp://ftp.gnu.org/gnu/aspell/$tarname

description="
A spell checker.

GNU Aspell is a Free and Open Source spell checker designed to
eventually replace Ispell.  It can either be used as a library or as an
independent spell checker.  Its main feature is that it does a superior
job of suggesting possible replacements for a misspelled word than just
about any other spell checker out there for the English language.

Unlike Ispell, Aspell can also easily check documents in UTF-8 without
having to use a special dictionary.  Aspell will also do its best to
respect the current locale setting.  Other advantages over Ispell
include support for using multiple dictionaries at once and
intelligently handling personal dictionaries when more than one Aspell
process is open at once.
"

homepage=https://www.aspell.net
license=LGPLv2.1

# Source documentation
docs="COPYING README TODO"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure \
    CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" CXXFLAGS="$QICXXFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docsdir \
     --enable-pkgdatadir=/usr/lib${libSuffix}/aspell \
     --enable-pkglibdir=/usr/lib${libSuffix}/aspell \
     --enable-dict-dir=/usr/lib${libSuffix}/aspell \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install-strip

    # Compress info documents deleting index file for the package
    rm -f "${destdir}/${infodir}/dir"
    lzip -9 "${destdir}/${infodir}"/*

    # Compress and link man pages (if needed)
    (
        cd "${destdir}/$mandir"
        find . -type f -exec lzip -9 {} +
        find . -type l | while read -r file
        do
            ln -sf "$(readlink -- "$file").lz" "${file}.lz"
            rm -- "$file"
        done
    )

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/dict/aspell/recipe


code:
# Build recipe for aspell6-en.
#
# Copyright (c) 2018-2019, 2021 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=aspell6-en
version=2020.12.07-0
release=1

# Define a category for the output of the package name
pkgcategory=dict

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=ftp://ftp.gnu.org/gnu/aspell/dict/en/$tarname

description="
A dictionary for GNU Aspell in English.

This is the English dictionary for Aspell.  It requires Aspell
version 0.60 or later.

This word list is considered both complete and accurate.
"

homepage=https://wordlist.aspell.net
license=Custom

# Source documentation
docs="Copyright README doc/ChangeLog doc/extra.txt"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"
    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure
    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}


code:
# Build recipe for docbook-xml.
#
# Copyright (c) 2019 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=docbook-xml
version=4.5
release=1

# Define a category for the output of the package name
pkgcategory=docbook

tarname=${program}-${version}.zip

# Remote source(s)
fetch="
  https://docbook.org/xml/${version}/$tarname
  https://docbook.org/xml/4.4/${program}-4.4.zip
  https://docbook.org/xml/4.3/${program}-4.3.zip
  https://docbook.org/xml/4.2/${program}-4.2.zip
  https://docbook.org/xml/4.1.2/docbkx412.zip
"

description="
The DocBook XML DTD.

The DocBook XML DTD package contains document type definitions
for verification of XML data files against the DocBook rule set.

These are useful for structuring books and software documentation
to a standard allowing you to utilize transformations already
written for that standard.
"

homepage=https://www.docbook.org
license=Custom

# Source documentation
docs="ChangeLog README"
docsdir="${docdir}/${program}-${version}"

build()
{
    # Unzip the sources in an own directory
    for _version in $version 4.4 4.3 4.2 4.1.2
    do
        mkdir -p "${srcdir}/${_version}" \
                 "${destdir}/usr/share/xml/docbook/xml-dtd-${_version}"

        if test $_version = 4.1.2
        then
            cd "${srcdir}/${_version}"
            unpack "${tardir}/docbkx412.zip"
        else
            cd "${srcdir}/${_version}"
            unpack "${tardir}/docbook-xml-${_version}.zip"
        fi

        # Set sane permissions
        chmod -R u+w,go-w,a+rX-s .

        # Populate package
        cp -R -p -f docbook.cat *.dtd ent/ *.mod \
         "${destdir}/usr/share/xml/docbook/xml-dtd-${_version}"
    done
    unset -v _version

    # Switch back to the current 'version'
    cd "${TMPDIR}/${srcdir}/${version}"

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"

    # Create config directory
    mkdir -p "${destdir}/etc/xml"

    # Insert post-install script manually

    mkdir -p "${destdir}/var/lib/qi"
    cat << EOF > "${destdir}/var/lib/qi/${full_pkgname}.sh"

# XML docbook
if test ! -e etc/xml/docbook
then
    echo "Creating etc/xml/docbook (version: $version) ..."
    xmlcatalog --noout --create etc/xml/docbook
fi

echo ""
echo "Updating etc/xml/docbook ..."

xmlcatalog --noout --add "public" \\
 "-//OASIS//DTD DocBook XML V4.5//EN" \\
 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" \\
 etc/xml/docbook

xmlcatalog --noout --add "public" \\
 "-//OASIS//DTD DocBook XML CALS Table Model V4.5//EN" \\
 "file:///usr/share/xml/docbook/xml-dtd-4.5/calstblx.dtd" \\
 etc/xml/docbook

xmlcatalog --noout --add "public" \\
 "-//OASIS//DTD XML Exchange Table Model 19990315//EN" \\
 "file:///usr/share/xml/docbook/xml-dtd-4.5/soextblx.dtd" \\
 etc/xml/docbook

xmlcatalog --noout --add "public" \\
 "-//OASIS//ELEMENTS DocBook XML Information Pool V4.5//EN" \\
 "file:///usr/share/xml/docbook/xml-dtd-4.5/dbpoolx.mod" \\
 etc/xml/docbook

xmlcatalog --noout --add "public" \\
 "-//OASIS//ELEMENTS DocBook XML Document Hierarchy V4.5//EN" \\
 "file:///usr/share/xml/docbook/xml-dtd-4.5/dbhierx.mod" \\
 etc/xml/docbook

xmlcatalog --noout --add "public" \\
 "-//OASIS//ELEMENTS DocBook XML HTML Tables V4.5//EN" \\
 "file:///usr/share/xml/docbook/xml-dtd-4.5/htmltblx.mod" \\
 etc/xml/docbook

xmlcatalog --noout --add "public" \\
 "-//OASIS//ENTITIES DocBook XML Notations V4.5//EN" \\
 "file:///usr/share/xml/docbook/xml-dtd-4.5/dbnotnx.mod" \\
 etc/xml/docbook

xmlcatalog --noout --add "public" \\
 "-//OASIS//ENTITIES DocBook XML Character Entities V4.5//EN" \\
 "file:///usr/share/xml/docbook/xml-dtd-4.5/dbcentx.mod" \\
 etc/xml/docbook

xmlcatalog --noout --add "public" \\
 "-//OASIS//ENTITIES DocBook XML Additional General Entities V4.5//EN" \\
 "file:///usr/share/xml/docbook/xml-dtd-4.5/dbgenent.mod" \\
 etc/xml/docbook

xmlcatalog --noout --add "rewriteSystem" \\
 "http://www.oasis-open.org/docbook/xml/4.5" \\
 "file:///usr/share/xml/docbook/xml-dtd-4.5" \\
 etc/xml/docbook

xmlcatalog --noout --add "rewriteURI" \\
 "http://www.oasis-open.org/docbook/xml/4.5" \\
 "file:///usr/share/xml/docbook/xml-dtd-4.5" \\
 etc/xml/docbook

# XML catalog
if test ! -e etc/xml/catalog
then
    echo "Creating etc/xml/catalog (version: $version) ..."
    xmlcatalog --noout --create etc/xml/catalog
fi

echo ""
echo "Updating etc/xml/catalog ..."

xmlcatalog --noout --add "delegatePublic" \\
 "-//OASIS//ENTITIES DocBook XML" \\
 "file:///etc/xml/docbook" \\
 etc/xml/catalog

xmlcatalog --noout --add "delegatePublic" \\
 "-//OASIS//DTD DocBook XML" \\
 "file:///etc/xml/docbook" \\
 etc/xml/catalog

xmlcatalog --noout --add "delegateSystem" \\
 "http://www.oasis-open.org/docbook/" \\
 "file:///etc/xml/docbook" \\
 etc/xml/catalog

xmlcatalog --noout --add "delegateURI" \\
 "http://www.oasis-open.org/docbook/" \\
 "file:///etc/xml/docbook" \\
 etc/xml/catalog

echo ""
printf "%s" "Adding identifiers from previous version:"

for DTDVERSION in 4.4 4.3 4.2 4.1.2
do
    printf "%s" " v\${DTDVERSION}"

    # etc/xml/docbook

    xmlcatalog --noout --add "public" \\
     "-//OASIS//DTD DocBook XML V\${DTDVERSION}//EN" \\
     "http://www.oasis-open.org/docbook/xml/\${DTDVERSION}/docbookx.dtd" \\
     etc/xml/docbook

    xmlcatalog --noout --add "rewriteSystem" \\
     "http://www.oasis-open.org/docbook/xml/\${DTDVERSION}" \\
     "file:///usr/share/xml/docbook/xml-dtd-4.5" \\
     etc/xml/docbook

    xmlcatalog --noout --add "rewriteURI" \\
     "http://www.oasis-open.org/docbook/xml/\${DTDVERSION}" \\
     "file:///usr/share/xml/docbook/xml-dtd-4.5" \\
     etc/xml/docbook

    # etc/xml/catalog

    xmlcatalog --noout --add "delegateSystem" \\
     "http://www.oasis-open.org/docbook/xml/\${DTDVERSION}/" \\
     "file:///etc/xml/docbook" \\
     etc/xml/catalog

    xmlcatalog --noout --add "delegateURI" \\
     "http://www.oasis-open.org/docbook/xml/\${DTDVERSION}/" \\
     "file:///etc/xml/docbook" \\
     etc/xml/catalog
done

EOF
}

path: recipes/docbook/docbook-xml/recipe


code:
# Build recipe for docbook-xsl.
#
# Copyright (c) 2019 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=docbook-xsl-nons
pkgname=docbook-xsl
version=1.79.2
release=1

# Define a category for the output of the package name
pkgcategory=docbook

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=https://github.com/docbook/xslt10-stylesheets/releases/download/release/${version}/$tarname

description="
The DocBook XSL Stylesheets.

The DocBook XSL Stylesheets package contains XSL stylesheets.
These are useful for performing transformations on XML DocBook files.
"

homepage=https://www.docbook.org
license=Custom

# Source documentation
docs="AUTHORS BUGS COPYING NEWS README RELEASE-NOTES.txt TODO VERSION"
docsdir="${docdir}/${pkgname}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Apply a patch from "Beyond Linux From Scratch"
    patch -Np1 -i "${worktree}/patches/docbook-xsl/docbook-xsl-nons-1.79.2-stack_fix-1.patch"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    mkdir -p "${destdir}/usr/share/xml/docbook/xsl-stylesheets-nons-${version}"
    cp -R VERSION assembly common eclipse epub epub3 extensions fo        \
         highlighting html htmlhelp images javahelp lib manpages params   \
         profiling roundtrip slides template tests tools webhelp website  \
         xhtml xhtml-1_1 xhtml5                                           \
     "${destdir}/usr/share/xml/docbook/xsl-stylesheets-nons-${version}"
    (
        cd "${destdir}/usr/share/xml/docbook/xsl-stylesheets-nons-${version}"
        ln -s VERSION VERSION.xsl
    )

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"

    # Create config directory
    mkdir -p "${destdir}/etc/xml"

    # Insert post-install script manually

    mkdir -p "${destdir}/var/lib/qi"
    cat << EOF > "${destdir}/var/lib/qi/${full_pkgname}.sh"

# XML catalog
if test ! -e etc/xml/catalog
then
    echo "Creating etc/xml/catalog (from docbook-xsl-${version}) ..."
    xmlcatalog --noout --create etc/xml/catalog
fi

echo "Adding XML (XSL) definitions to etc/xml/catalog ..."
xmlcatalog --noout --add "rewriteSystem" \\
 "http://cdn.docbook.org/release/xsl-nons/${version}" \\
 "file://usr/share/xml/docbook/xsl-stylesheets-nons-${version}" \\
 etc/xml/catalog

xmlcatalog --noout --add "rewriteURI" \\
 "http://cdn.docbook.org/release/xsl-nons/${version}" \\
 "file://usr/share/xml/docbook/xsl-stylesheets-nons-${version}" \\
 etc/xml/catalog

xmlcatalog --noout --add "rewriteSystem" \\
 "http://cdn.docbook.org/release/xsl-nons/current" \\
 "file://usr/share/xml/docbook/xsl-stylesheets-nons-${version}" \\
 etc/xml/catalog

xmlcatalog --noout --add "rewriteURI" \\
 "http://cdn.docbook.org/release/xsl-nons/current" \\
 "file://usr/share/xml/docbook/xsl-stylesheets-nons-${version}" \\
 etc/xml/catalog

# Sourceforge URIs
xmlcatalog --noout --add "rewriteSystem" \\
 "http://docbook.sourceforge.net/release/xsl/current" \\
 "/usr/share/xml/docbook/xsl-stylesheets-nons-${version}" \\
 etc/xml/catalog

xmlcatalog --noout --add "rewriteURI" \\
 "http://docbook.sourceforge.net/release/xsl/current" \\
 "/usr/share/xml/docbook/xsl-stylesheets-nons-${version}" \\
 etc/xml/catalog

EOF
}

path: recipes/docbook/docbook-xsl/recipe


code:
# Build recipe for itstool.
#
# Copyright (c) 2019, 2021-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=itstool
version=2.0.7
arch=noarch
release=1

# Define a category for the output of the package name
pkgcategory=docbook

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=http://files.itstool.org/itstool/$tarname

description="
Convert between XML and PO using ITS.

Itstool extracts messages from XML files and outputs PO template
files, then merges translations from MO files to create translated
XML files.  It determines what to translate and how to chunk it
into messages using the W3C Internationalization Tag Set (ITS).
"

homepage=https://itstool.org
license=GPLv3+

# Source documentation
docs="AUTHORS COPYING* ChangeLog NEWS README"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure PYTHON="/usr/bin/python3" \
     $configure_args \
     --mandir=$mandir \
     --docdir=$docsdir \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/docbook/itstool/recipe


code:
# Build recipe for openjade.
#
# Copyright (c) 2019, 2021 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=openjade
version=1.3.2
release=2

# Define a category for the output of the package name
pkgcategory=docbook

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=https://downloads.sourceforge.net/project/openjade/openjade/${version}/$tarname

description="
An implementation of DSSSL, a language to format SGML or XML documents.

OpenJade contains backends for various formats (RTF, HTML, TeX, MIF,
SGML2SGML, and FOT).
"

homepage=https://openjade.sourceforge.net
license=MIT

# Source documentation
docs="COPYING ChangeLog NEWS README VERSION"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    # Update using patches from Gentoo
    patch -Np1 -i "${worktree}/patches/openjade/openjade-1.3.2-deplibs.patch"
    patch -Np1 -i "${worktree}/patches/openjade/openjade-1.3.2-ldflags.patch"
    patch -Np1 -i "${worktree}/patches/openjade/openjade-1.3.2-respect-ldflags.patch"
    patch -Np1 -i "${worktree}/patches/openjade/openjade-1.3.2-msggen.pl.patch"
    patch -Np1 -i "${worktree}/patches/openjade/openjade-1.3.2-libosp-la.patch"
    patch -Np1 -i "${worktree}/patches/openjade/openjade-1.3.2-gcc46.patch"
    patch -Np1 -i "${worktree}/patches/openjade/openjade-1.3.2-no-undefined.patch"
    patch -Np1 -i "${worktree}/patches/openjade/openjade-1.3.2-wchar_t-uint.patch"
    patch -Np1 -i "${worktree}/patches/openjade/openjade-1.3.2-chmod.patch"

    # Update for hosts based on musl
    cp -f "${worktree}/archive/common/config.guess" config/config.guess
    cp -f "${worktree}/archive/common/config.sub" config/config.sub

    ./configure CXXFLAGS="$QICXXFLAGS -fno-lifetime-dse" \
    LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --datadir=/usr/share/sgml/openjade-${version} \
     --enable-default-catalog=/etc/sgml/catalog \
     --enable-default-search-path=/usr/share/sgml \
     --enable-splibdir=/usr/lib${libSuffix} \
     --enable-http \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    mkdir -p "${destdir}/etc/sgml"
    make -j${jobs} DESTDIR="$destdir" install install-man

    # Remove libtool .la files
    rm -f "${destdir}/usr/lib${libSuffix}"/*.la

    # Create Jade equivalents

    ln -sf openjade        "${destdir}/usr/bin/jade"
    ln -sf openjade.1      "${destdir}${mandir}/man1/jade.1"

    # Catalogs

    cp -p dsssl/catalog "${destdir}/usr/share/sgml/openjade-${version}"
    for file in dsssl/*.dtd dsssl/*.dsl dsssl/*.sgm
    do
        cp -p "$file" "${destdir}/usr/share/sgml/openjade-${version}/${file##*/}"
    done
    unset -v file
    chmod 644 "${destdir}/usr/share/sgml/openjade-${version}"/*

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"

    # Insert post-install script manually

    mkdir -p "${destdir}/var/lib/qi"
    cat << EOF > "${destdir}/var/lib/qi/${full_pkgname}.sh"

echo ""
echo "Updating etc/sgml/catalog ..."

install-catalog --add etc/sgml/openjade-${version}.cat \\
 /usr/share/sgml/openjade-${version}/catalog

install-catalog --add etc/sgml/sgml-docbook.cat \\
 /etc/sgml/openjade-${version}.cat

EOF
}

path: recipes/docbook/openjade/recipe


code:
# Build recipe for opensp.
#
# Copyright (c) 2019, 2021 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=OpenSP
pkgname=opensp
version=1.5.2
release=2

# Define a category for the output of the package name
pkgcategory=docbook

tarname=${program}-${version}.tar.gz

# Remote source(s)
fetch=https://downloads.sourceforge.net/openjade/$tarname

description="
The opensp package contains a C++ library for using SGML/XML files.

This is useful for validating, parsing and manipulating
SGML and XML documents.
"

homepage=https://openjade.sourceforge.net
license=MIT

# Source documentation
docs="AUTHORS BUGS COPYING ChangeLog NEWS README"
docsdir="${docdir}/${pkgname}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Update for hosts based on musl
    cp -f "${worktree}/archive/common/config.guess" config.guess
    cp -f "${worktree}/archive/common/config.sub" config.sub

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    # Disable warnings while running openjade
    # (Thanks to Beyond of Linux From Scratch)

    sed -i 's/32,/253,/' lib/Syntax.cxx
    sed -i 's/LITLEN          240 /LITLEN          8092/' \
     unicode/gensyntax.pl unicode/unicode.syn

    ./configure CXXFLAGS="$QICXXFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --enable-static=no \
     --enable-shared=yes \
     --enable-default-catalog=/etc/sgml/catalog \
     --enable-default-search-path=/usr/share/sgml \
     --enable-http \
     --enable-xml-messages \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1 \
     pkgdatadir=/usr/share/sgml/OpenSP-${version} docdir=$docsdir

    make -j${jobs} \
     pkgdatadir=/usr/share/sgml/OpenSP-${version} docdir=$docsdir \
     DESTDIR="$destdir" install

    # Make symlinks for compatiblity (e.g OpenJade).
    # (Thanks to Beyond of Linux From Scratch)

    ln -sf onsgmls    "${destdir}"/usr/bin/nsgmls
    ln -sf osgmlnorm  "${destdir}"/usr/bin/sgmlnorm
    ln -sf ospam      "${destdir}"/usr/bin/spam
    ln -sf ospcat     "${destdir}"/usr/bin/spcat
    ln -sf ospent     "${destdir}"/usr/bin/spent
    ln -sf osx        "${destdir}"/usr/bin/sx
    ln -sf osx        "${destdir}"/usr/bin/sgml2xml

    # Make symlinks for manpages
    for file in nsgmls sgmlnorm spam spcat spent sx
    do
        ln -sf o${file}.1 "${destdir}/${mandir}/man1/${file}.1"
    done
    unset -v file

    ln -sf osx.1 "${destdir}/${mandir}/man1/sgml2xml.1"

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/docbook/opensp/recipe


code:
# Update SGML catalogs

mkdir -p -m 0755 usr/share/sgml/sgml-iso-entities-8879.1986/

install-catalog --add etc/sgml/sgml-ent.cat \
 /usr/share/sgml/sgml-iso-entities-8879.1986/catalog && \
install-catalog --add etc/sgml/sgml-docbook.cat \
 /etc/sgml/sgml-ent.cat


code:
# Build recipe for sgml-common.
#
# Copyright (c) 2019, 2021 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=sgml-common
version=0.6.3
arch=noarch
release=3

# Define a category for the output of the package name
pkgcategory=docbook

tarname=${program}-${version}.tgz

# Remote source(s)
fetch=https://sourceware.org/ftp/docbook-tools/new-trials/SOURCES/$tarname

description="
The SGML common package contains install-catalog.

This is useful for creating and maintaining centralized SGML catalogs.
"

homepage=https://www.docbook.org/xml/
license=GPLv3+

# Source documentation
docs="AUTHORS COPYING ChangeLog NEWS README"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Apply patches and updates from Fedora
    patch -Np1 -i "${worktree}/patches/sgml-common/sgml-common-quotes.patch"
    patch -Np1 -i "${worktree}/patches/sgml-common/sgml-common-umask.patch"
    patch -Np1 -i "${worktree}/patches/sgml-common/sgml-common-xmldir.patch"

    # Apply patch from Beyond Linux From Scratch
    patch -Np1 -i "${worktree}/patches/sgml-common/sgml-common-0.6.3-manpage-1.patch"

    # Replace bogus links with files (Adapted from "Fedora")
    automakedir="$(ls -1 -d /usr/share/automake-* | head -n 1)"
    for file in COPYING INSTALL install-sh missing mkinstalldirs
    do
        rm -- $file
        cp -L -p "${automakedir}"/$file .
    done
    unset -v automakedir file

    autoreconf -vif

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docsdir \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1 docdir=$docsdir
    make -j${jobs} docdir=$docsdir DESTDIR="$destdir" install

    touch "${destdir}/etc/sgml/.graft-config"

    mkdir -p "${destdir}/usr/share/sgml/sgml-iso-entities-8879.1986"

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/docbook/sgml-common/recipe


code:
# Build recipe for xmlto.
#
# Copyright (c) 2019 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=xmlto
version=0.0.28
release=1

# Define a category for the output of the package name
pkgcategory=docbook

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=https://releases.pagure.org/xmlto/$tarname

description="
The xmlto package is a front-end to a XSL toolchain.

It chooses an appropriate stylesheet for the conversion you want and
applies it using an external XSLT processor.  It also performs any
necessary post-processing.
"

homepage=https://pagure.io/xmlto/
license=GPLv2+

# Source documentation
docs="AUTHORS COPYING ChangeLog FAQ NEWS README THANKS"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS -static" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --docdir=$docsdir \
     --with-webbrowser=lynx \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install-strip

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/docbook/xmlto/recipe


code:
# Build recipe for gnupg (version 2).
#
# Copyright (c) 2018-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=gnupg
pkgname=gnupg2
version=2.2.33
release=1

# Define a category for the output of the package name
pkgcategory=gnupg

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=https://www.gnupg.org/ftp/gcrypt/gnupg/$tarname

description="
The GnuPG version 2.

GnuPG 2.0 is the new modularized version of GnuPG supporting
OpenPGP and S/MIME.
"

homepage=https://www.gnupg.org
license="GPLv2+, GPLv3+, LGPLv2+, LGPLv3+ | CC0 1.0 Universal"

# Source documentation
docs="AUTHORS COPYING* ChangeLog NEWS README* THANKS TODO VERSION"
docsdir="${docdir}/${pkgname}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    # Make sure to build the gpg-zip program (thanks to BLFS!)
    sed -e '/noinst_SCRIPTS = gpg-zip/c sbin_SCRIPTS += gpg-zip' \
        -i tools/Makefile.in

    ./configure CPPFLAGS="$QICPPFLAGS" \
    CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docsdir \
     --enable-symcryptrun \
     --enable-g13 \
     --enable-sqlite \
     --disable-gpg-is-gpg2 \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install-strip

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}


code:
# Build recipe for gpgme.
#
# Copyright (c) 2018-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=gpgme
version=1.16.0
release=1

# Define a category for the output of the package name
pkgcategory=gnupg

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=https://www.gnupg.org/ftp/gcrypt/gpgme/$tarname

description="
GnuPG made easy.

GPGME (GnuPG Made Easy) is a C language library that allows to add
support for cryptography to a program.
"

homepage=https://www.gnupg.org
license="GPLv2+, LGPLv2.1"

# Source documentation
docs="AUTHORS COPYING* ChangeLog NEWS README THANKS TODO VERSION"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" \
    CFLAGS="$QICFLAGS" CXXFLAGS="$QICXXFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docsdir \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install-strip

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/gnupg/gpgme/recipe


code:
# Build recipe for libassuan.
#
# Copyright (c) 2018-2019, 2021-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=libassuan
version=2.5.5
release=1

# Define a category for the output of the package name
pkgcategory=gnupg

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=https://www.gnupg.org/ftp/gcrypt/libassuan/$tarname

description="
IPC library used by GnuPG.

libassuan is the IPC library used by some GnuPG related software.
"

homepage=https://www.gnupg.org
license="GPLv3+, LGPLv2.1"

# Source documentation
docs="AUTHORS COPYING* ChangeLog NEWS README* THANKS TODO VERSION"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" \
    CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docsdir \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install-strip

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/gnupg/libassuan/recipe


code:
# Build recipe for libgcrypt.
#
# Copyright (c) 2018-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=libgcrypt
version=1.9.4
release=1

# Define a category for the output of the package name
pkgcategory=gnupg

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=https://www.gnupg.org/ftp/gcrypt/libgcrypt/$tarname

description="
Basic cryptographic library.

The libgcrypt package contains a general purpose crypto library
based on the code used in GnuPG.
"

homepage=https://www.gnupg.org
license="GPLv2+, LGPLv2.1"

# Source documentation
docs="AUTHORS COPYING* ChangeLog NEWS README* THANKS TODO VERSION"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" \
    CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docsdir \
     --disable-padlock-support \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install-strip

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/gnupg/libgcrypt/recipe


code:
# Build recipe for libgpg-error.
#
# Copyright (c) 2018-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=libgpg-error
version=1.43
release=1

# Define a category for the output of the package name
pkgcategory=gnupg

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=https://www.gnupg.org/ftp/gcrypt/libgpg-error/$tarname

description="
Small library with error codes.

The libgpg-error package contains a library that defines common error
values for all GnuPG components.
"

homepage=https://www.gnupg.org
license="GPLv2+, LGPLv2.1"

# Source documentation
docs="AUTHORS COPYING* ChangeLog NEWS README THANKS VERSION"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" \
    CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docsdir \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install-strip

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/gnupg/libgpg-error/recipe


code:
# Build recipe for libksba.
#
# Copyright (c) 2018, 2020-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=libksba
version=1.6.0
release=1

# Define a category for the output of the package name
pkgcategory=gnupg

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=https://www.gnupg.org/ftp/gcrypt/libksba/$tarname

description="
CMS and X.509 access library.

The libksba package contains a library used to make X.509 certificates
as well as making the Cryptographic Message Syntax easily accessible by
other applications.
"

homepage=https://www.gnupg.org
license="GPLv2+, GPLv3+, LGPLv3+"

# Source documentation
docs="AUTHORS COPYING* ChangeLog NEWS README* THANKS TODO"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" \
    CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docsdir \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install-strip

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/gnupg/libksba/recipe


code:
# Build recipe for pinentry.
#
# Copyright (c) 2020, 2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=pinentry
version=1.2.0
release=1

# Define a category for the output of the package name
pkgcategory=gnupg

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=https://www.gnupg.org/ftp/gcrypt/pinentry/$tarname

description="
Collection of PIN or passphrase entry dialogs (terminal).

This is a collection of PIN or passphrase entry dialogs which
utilize the Assuan protocol as specified in the Libassuan manual.
"

homepage=https://www.gnupg.org
license=GPLv2+

# Source documentation
docs="AUTHORS COPYING* ChangeLog NEWS README* THANKS TODO VERSION"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    ./configure CPPFLAGS="$QICPPFLAGS" \
    CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --infodir=$infodir \
     --mandir=$mandir \
     --docdir=$docsdir \
     --enable-pinentry-tty \
     --enable-fallback-curses \
     --build="$(gcc -dumpmachine)"

    make -j${jobs} V=1
    make -j${jobs} DESTDIR="$destdir" install-strip

    # Compress info documents deleting index file for the package
    if test -d "${destdir}/$infodir"
    then
        rm -f "${destdir}/${infodir}/dir"
        lzip -9 "${destdir}/${infodir}"/*
    fi

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 {} +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

path: recipes/gnupg/pinentry/recipe


code:
# Build recipe for kernel/generic (build-tree).
#
# Copyright (c) 2017-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

# The version and release numbers are set from 'kernel/generic'
if test -z "$kernel_generic_version" || test -z "$kernel_generic_release"
then
    printf '%s\n' "" \
    "Variables coming from 'kernel/generic' to set the version and" \
    "release numbers of this recipe are empty.  This will be ignored." \
    "" 1>&2
    opt_skiprecipe=opt_skiprecipe;	# Tells to Qi to ignore this recipe.
fi

program=linux
version=$kernel_generic_version
release=$kernel_generic_release

# Define a category for the output of the package name
pkgcategory=kernel

# Use a custom package name
pkgname=linux-libre-buildtree

description="
The Linux-libre build tree directory (${arch}).

This is the directory tree as generated for Dragora from the 'kernel/generic'
recipe.  Necessary for later installations of modules as well as drivers that
require it.
"

license="GPLv2 only"

build()
{
    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    # Move (build) kernel-tree into package

    mkdir -p "${destdir}/usr/src/${srcdir}"
    mv -f ./* "${destdir}/usr/src/${srcdir}"

    # Unset variables exported from "kernel/generic"
    unset -v keep_srcdir kernel_generic_version kernel_generic_release
}

path: recipes/kernel/buildtree-generic/recipe


code:
# Build recipe for linux-libre-firmware.
#
# Copyright (c) 2017-2018, 2021-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=linux-libre-firmware
version=1.4
release=2

# Define a category for the output of the package name
pkgcategory=kernel

tarname=${program}-${version}.tar.lz

# Remote source(s)
fetch=https://jxself.org/firmware/$tarname

description="
The GNU Linux-libre firmware.

This is the release of free firmware for use with the linux-libre kernel.

For more information, please read:
https://jxself.org/free-firmware.shtml
"

homepage=https://jxself.org/firmware
license=Custom

# Source documentation
docs="GPL-2 GPL-3 MPL-2 README WHENCE"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    # Prepare package to copy the firmwares (data)

    mkdir -p "${destdir}/lib/firmware"
    cp -R -p bin/* "${destdir}/lib/firmware/"
    chown -R root:root "${destdir}/lib/firmware/"

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cd src && cp -p $docs "${destdir}/$docsdir"
}

path: recipes/kernel/firmware/recipe


code:
# Build instructions for GNU Linux-libre (amd64, generic).
#
# Copyright (c) 2017-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=linux-libre
version=5.16.20
release=2

# Define a category for the output of the package name
pkgcategory=kernel

tarname=${program}-${version}-gnu.tar.lz

# Remote source(s)
fetch=https://linux-libre.fsfla.org/pub/linux-libre/releases/${version}-gnu/$tarname

homepage=https://www.gnu.org/software/linux-libre

description="
The GNU Linux-libre kernel (image and modules for ${arch}).

GNU Linux-libre is a project to maintain and publish 100% Free distributions of
Linux, suitable for use in Free System Distributions, removing software that is
included without source code, with obfuscated or obscured source code, under
non-Free Software licenses, that do not permit you to change the software so
that it does what you wish, and that induces or requires you to install
additional pieces of non-Free Software.

This is a custom configuration for Dragora, intended to be generic and work
well in all environments.
"

license="GPLv2 only"

# Refresh 'srcdir'
srcdir=linux-${version}

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    # Support LZIP (Thanks to the friend of the house "Antonio Diaz Diaz")

    patch -p1 < "${worktree}/patches/kernel/linux-5.16.11_lzip-0.diff"

    # Support Reiserfs4 (Thanks to "Edward Shishkin")

    patch -p1 < "${worktree}/patches/kernel/reiser4-for-5.16.patch"

    make mrproper

    echo "Copying config-amd64_generic ..."
    cp -p "${worktree}/archive/kernel/config-amd64_generic" .config

    # An environment variable for config purposes
    if test ! -z "$PRESERVE"
    then
        echo "PRESERVE has been set."
        exit 99;
    fi

    make -j${jobs} ARCH=x86_64 bzImage
    make -j${jobs} ARCH=x86_64 modules
    make -j${jobs} ARCH=x86_64 \
     INSTALL_MOD_PATH="$destdir" modules_install

    # To extract the kernel string version
    strver="$(ls -d "${destdir}"/lib/modules/*)"
    strver="${strver##*/}"

    # Install kernel images
    mkdir -p "${destdir}/boot"

    cp -p .config "${destdir}/boot/config-${arch}_generic-${strver}"
    cp -p System.map "${destdir}/boot/System.map-${arch}_generic-${strver}"

    if test -e "arch/x86_64/boot/bzImage"
    then
        cp -p "arch/x86_64/boot/bzImage" \
              "${destdir}/boot/vmlinuz-${arch}_generic-${strver}"
    elif test -e "arch/x86_64/boot/zImage"
    then
        cp -p "arch/x86_64/boot/zImage" \
              "${destdir}/boot/vmlinuz-${arch}_generic-${strver}"
    else
        echo "${0}: No kernel image found: bzImage or zImage" 1>&2
        exit 1;
    fi

    # Exclude files from the Graft installation,
    # this will be copied via post-intall, since
    # /boot could be a separated partition
    touch "${destdir}/boot/.nograft"

    # Insert post-install script manually

    # This must be recreated on post-installation
    rm -f "${destdir}"/lib/modules/${strver}/build \
          "${destdir}"/lib/modules/${strver}/source

    mkdir -p "${destdir}/var/lib/qi"
    cat << EOF > "${destdir}/var/lib/qi/${full_pkgname}.sh"

# Kernel string version
strver=$strver

# Copy kernel image from 'packagedir' to 'rootdir/boot'

mkdir -p -- "\${rootdir}/boot"

cp -pf -- "\$rootdir${packagedir}/${full_pkgname}/boot/System.map-${arch}_generic-${strver}" \\
          "\${rootdir}/boot/"

cp -pf -- "\$rootdir${packagedir}/${full_pkgname}/boot/config-${arch}_generic-${strver}" \\
          "\${rootdir}/boot/"

cp -pf -- "\$rootdir${packagedir}/${full_pkgname}/boot/vmlinuz-${arch}_generic-${strver}" \\
          "\${rootdir}/boot/"

# Make generic symlinks for this kernel version

srcdir="${srcdir##*/}"

(
    cd lib/modules/${strver} || exit 1
    rm -f build source
    ln -sf /usr/src/${srcdir} build
    ln -sf /usr/src/${srcdir} source
)

# Generate or update the module dependency list
chroot "\$rootdir" /sbin/depmod -a $strver

EOF

    # Preserve 'srcdir' in order to produce "kernel/buildtree-generic"
    keep_srcdir=keep_srcdir

    # Save 'version' and 'release' number to compose
    # variable values for "kernel/buildtree-generic"
    kernel_generic_version=$version
    kernel_generic_release=$release

    export keep_srcdir kernel_generic_version kernel_generic_release
}


code:
# Build instructions for GNU Linux-libre (i586+, generic).
#
# Copyright (c) 2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=linux-libre
version=4.14.281
release=1

# Define a category for the output of the package name
pkgcategory=kernel

tarname=${program}-${version}-gnu1.tar.lz

# Remote source(s)
fetch=https://linux-libre.fsfla.org/pub/linux-libre/releases/${version}-gnu1/$tarname

homepage=https://www.gnu.org/software/linux-libre

description="
The GNU Linux-libre kernel (image and modules for ${arch}).

GNU Linux-libre is a project to maintain and publish 100% Free distributions of
Linux, suitable for use in Free System Distributions, removing software that is
included without source code, with obfuscated or obscured source code, under
non-Free Software licenses, that do not permit you to change the software so
that it does what you wish, and that induces or requires you to install
additional pieces of non-Free Software.

This is a custom configuration for Dragora, which is for uni-processors, is
intended to be or run on Intel 586 family (MMX) machines or higher.
"

license="GPLv2 only"

# Refresh 'srcdir'
srcdir=linux-${version}

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    # Support LZIP (Thanks to the friend of the house "Antonio Diaz Diaz")

    patch -p1 < "${worktree}/patches/kernel/linux-4.14.40_lzip-3.diff"

    # Support Reiserfs4 (Thanks to "Edward Shishkin")
    #
    # TODO: Needs a re-adaptation
    #patch -p1 < "${worktree}/patches/kernel/reiser4-for-4.14.1.patch"

    make mrproper

    echo "Copying config-i586_generic ..."
    cp -p "${worktree}/archive/kernel/config-i586_generic" .config

    # An environment variable for config purposes
    if test ! -z "$PRESERVE"
    then
        echo "PRESERVE has been set."
        exit 99;
    fi

    make -j${jobs} ARCH=i386 bzImage
    make -j${jobs} ARCH=i386 modules
    make -j${jobs} ARCH=i386 \
     INSTALL_MOD_PATH="$destdir" modules_install

    # To extract the kernel string version
    strver="$(ls -d "${destdir}"/lib/modules/*)"
    strver="${strver##*/}"

    # Install kernel images
    mkdir -p "${destdir}/boot"

    cp -p .config "${destdir}/boot/config-${arch}_generic-${strver}"
    cp -p System.map "${destdir}/boot/System.map-${arch}_generic-${strver}"

    if test -e "arch/i386/boot/bzImage"
    then
        cp -p "arch/i386/boot/bzImage" \
              "${destdir}/boot/vmlinuz-${arch}_generic-${strver}"
    elif test -e "arch/i386/boot/zImage"
    then
        cp -p "arch/i386/boot/zImage" \
              "${destdir}/boot/vmlinuz-${arch}_generic-${strver}"
    else
        echo "${0}: No kernel image found: bzImage or zImage" 1>&2
        exit 1;
    fi

    # Exclude files from the Graft installation,
    # this will be copied via post-intall, since
    # /boot could be a separated partition
    touch "${destdir}/boot/.nograft"

    # Insert post-install script manually

    # This must be recreated on post-installation
    rm -f "${destdir}"/lib/modules/${strver}/build \
          "${destdir}"/lib/modules/${strver}/source

    mkdir -p "${destdir}/var/lib/qi"
    cat << EOF > "${destdir}/var/lib/qi/${full_pkgname}.sh"

# Kernel string version
strver=$strver

# Copy kernel image from 'packagedir' to 'rootdir/boot'

mkdir -p -- "\${rootdir}/boot"

cp -pf -- "\$rootdir${packagedir}/${full_pkgname}/boot/System.map-${arch}_generic-${strver}" \\
          "\${rootdir}/boot/"

cp -pf -- "\$rootdir${packagedir}/${full_pkgname}/boot/config-${arch}_generic-${strver}" \\
          "\${rootdir}/boot/"

cp -pf -- "\$rootdir${packagedir}/${full_pkgname}/boot/vmlinuz-${arch}_generic-${strver}" \\
          "\${rootdir}/boot/"

# Make generic symlinks for this kernel version

srcdir="${srcdir##*/}"

(
    cd lib/modules/${strver} || exit 1
    rm -f build source
    ln -sf /usr/src/${srcdir} build
    ln -sf /usr/src/${srcdir} source
)

# Generate or update the module dependency list
chroot "\$rootdir" /sbin/depmod -a $strver

EOF

    # Preserve 'srcdir' in order to produce "kernel/buildtree-generic"
    keep_srcdir=keep_srcdir

    # Save 'version' and 'release' number to compose
    # variable values for "kernel/buildtree-generic"
    kernel_generic_version=$version
    kernel_generic_release=$release

    export keep_srcdir kernel_generic_version kernel_generic_release
}


code:
# Build recipe for GNU Linux-libre (wrapper).
#
# Copyright (c) 2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Load specific instructions for supported architectures
case "$(uname -m)" in
x86_64*)
    . "${CWD}/amd64"
    ;;
i586 | i686 )
    . "${CWD}/i586"
    ;;
*)
    echo "${0}: There are no kernel recipe available for your architecture." 1>&2
    echo "    Feel free to contact the developers." 1>&2
    exit 1;
    ;;
esac

path: recipes/kernel/generic/recipe


code:
# Build recipe for GNU Linux-libre headers.
#
# Copyright (c) 2015-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=linux-libre

# Set 'version' and 'release' for supported architectures
case "$(uname -m)" in
i?86)
    version=4.14.281
    release=1
    _gnu_suffix="gnu1"
    ;;
*)
    version=5.16.20
    release=2
    _gnu_suffix="gnu"
    ;;
esac

# Define a category for the output of the package name
pkgcategory=kernel

# Use a custom package name
pkgname=linux-libre-headers

tarname=${program}-${version}-${_gnu_suffix}.tar.lz

# Remote source(s)
fetch=https://linux-libre.fsfla.org/pub/linux-libre/releases/${version}-${_gnu_suffix}/$tarname

description="
The GNU Linux-libre headers (${arch}).

This package contains the Linux headers provided by the GNU Linux-libre
project to expose the kernel's API.
"

homepage=https://www.gnu.org/software/linux-libre
license="GPLv2 only"

# Limit parallel jobs for the compiler
jobs=1

# To match 'srcdir'
srcdir=linux-${version}

build()
{
    unpack "${tardir}/$tarname"
    unset -v _gnu_suffix

    cd "$srcdir"

    patch -p1 < "${worktree}/patches/linux-headers/revert-broken-uapi.patch"
    patch -p1 < "${worktree}/patches/linux-headers/0003-remove-inclusion-of-sysinfo.h-in-kernel.h.patch"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    make -j${jobs} mrproper
    make -j${jobs} headers || make -j${jobs} headers_check

    # Holy molly... the 'headers_install' target cannot be used
    # because it requires rsync(1), which is not available early.

    mkdir -p "${destdir}/usr/include"
    cp -Rp usr/include/* "${destdir}/usr/include/"

    # Remove cruft
    find "${destdir}/usr/include" -name '.*' -exec rm -rf {} +
    rm -f "${destdir}/usr/include/Makefile"
}

path: recipes/kernel/headers/recipe