# Build recipe for icewm.
#
# Copyright (c) 2018-2019 Matias Fonzo, <selk@dragora.org>.
# Copyright (c) 2019 Lucas Skoldqvist, <frusen@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.

program=icewm
version=1.6.2
release=1

# Set 'outdir' for a nice and well-organized output directory
outdir="${outdir}/${arch}/x-apps"

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

# Remote source(s)
fetch=http://github.com/ice-wm/icewm/releases/download/${version}/$tarname

homepage=http://ice-wm.org/

description="
IceWM Window Manager.

IceWM is a window manager for the X Window System.  The goal of IceWM
is speed, simplicity, and not getting in the user's way.  It comes with
a taskbar with pager, global and per-window keybindings and a dynamic
menu system.

For more information, visit: $homepage
"

license=LGPLv2+

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

build()
{
    set -e

    unpack "${tardir}/$tarname"

    cd "$srcdir"

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

    ./configure CXXFLAGS="$QICXXFLAGS" LDFLAGS="$QILDFLAGS" \
     $configure_args \
     --libdir=/usr/lib${libSuffix} \
     --mandir=$mandir \
     --with-docdir=$docsdir \
     --disable-rpath \
     --build="$(cc -dumpmachine)"

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

    mkdir -p "${destdir}/usr/share/xsessions" \
             "${destdir}/usr/share/applications"
    cp -p lib/icewm-session.desktop "${destdir}/usr/share/xsessions"
    cp -p lib/icewm.desktop "${destdir}/usr/share/applications"

    # Include xinitrc file to start IceWM
    mkdir -p "${destdir}/etc/X11/xinit"
    cp -p "${worktree}/archive/icewm/xinitrc-icewm" "${destdir}/etc/X11/xinit/"
    chmod 644 "${destdir}/etc/X11/xinit/xinitrc-icewm"

    touch "${destdir}/etc/X11/xinit/.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}"
}

