# Build recipe for dwm.
#
# Copyright (c) 2018-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=dwm
version=6.2
release=1

# Define a category for the output of the package name
pkgcategory=x-apps

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

# Remote source(s)
fetch=https://dl.suckless.org/dwm/$tarname

description="
Dynamic Window Manager.

dwm is a dynamic window manager for X.  It manages windows in tiled,
monocle and floating layouts.  All of the layouts can be applied
dynamically, optimising the environment for the application in use
and the task performed.
"

homepage=https://dwm.suckless.org
license="MIT X Consortium"

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

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

    cd "$srcdir"

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

    # Set default font size to '14'
    patch -p0 < "${worktree}/patches/dwm/dwm-fontsize.diff"

    cat "${worktree}/archive/dwm/config.mk" > ./config.mk

    make -j${jobs} \
     X11INC=/usr/include/X11 \
     X11LIB=/usr/lib${libSuffix}/X11 \
     FREETYPEINC=/usr/include/freetype2

    make -j${jobs} PREFIX=/usr DESTDIR="$destdir" install

    strip --strip-unneeded "${destdir}/usr/bin/dwm"
    lzip -9 "${destdir}/${mandir}/man1/dwm.1"

    # Include xinitrc file to start DWM

    mkdir -p "${destdir}/etc/X11/xinit"
    cp -p "${worktree}/archive/dwm/xinitrc-dwm" "${destdir}/etc/X11/xinit/"
    chmod 644 "${destdir}/etc/X11/xinit/xinitrc-dwm"

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

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

