/*
 * tardy - a tar post-processor
 * Copyright (C) 2011, 2012 Peter Miller
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

all += etc/reference.pdf;
integration-build-targets += archive/[project_minus].pdf;

etc/%.so.d: etc/%.so
    set no-cascade
{
    if [quiet] then
        function print Depends [target];
    c_incl -nc -ns -api -nrec
        --lang\=roff
        [addprefix "-I" [search_list]]
        [resolve etc/%.so]
        -prefix "'cascade etc/%.so ='"
        -suffix "';'"
        [addprefix "-rlp=" [search_list]]
        -o [target];
}

etc/%.man.d: etc/%.man
    set no-cascade
{
    if [quiet] then
        function print Depends [target];
    c_incl -nc -ns -api -nrec
        --lang\=roff
        [addprefix "-I" [search_list]]
        [resolve etc/%.man]
        -prefix "'cascade etc/%.man ='"
        -suffix "';'"
        [addprefix "-rlp=" [search_list]]
        -o [target];
}

#include-cooked [addsuffix ".d" [match_mask etc/%.man [source_files]]]

etc/%.pdf: etc/%.man etc/page-list.awk
    etc/groff.sh
{
    if [quiet] then
        function print Groff [target];
    sh [resolve etc/groff.sh]
        [addprefix "-I" [search_list]]
        -t -man
        [resolve etc/%.man]
        > %.ps.tmp;
    psselect -p`awk -f [resolve etc/page-list.awk] %.ps.tmp`
        ['if' [quiet] 'then' -q ]
        %.ps.tmp > %.ps;
    rm %.ps.tmp
        set silent;
    ps2pdf %.ps [target];
    rm %.ps
        set silent;
}

cascade etc/reference.man = etc/ref-index.so etc/ref-parts.so;

etc/ref-index.so: [match_mask man/man%1/%2.%1 [source_files]]
        etc/ref-ptx1.awk etc/ref-ptx.ignore etc/ref-ptx2.awk
{
    if [quiet] then
        function print Generate [target];
    [awk] -f [resolve etc/ref-ptx1.awk]
        [resolve [match_mask man/man%1/%2.%1 [source_files]]]
    | ptx -O -r -w1000 -i[resolve etc/ref-ptx.ignore]
    | sort -t'\'"\'' -f -d +5 -6 +3 -4
    | [awk] -F'\'"\'' -f [resolve etc/ref-ptx2.awk]
    > [target];
}

#include-cooked etc/ref-index.so.d

etc/ref-parts.so: [match_mask man/man%1/%2.%1 [source_files]]
        etc/ref-ptx.sh
{
    if [quiet] then
        function print Generate [target];
    sh -f [resolve etc/ref-ptx.sh]
        [match_mask man/man%1/%2.%1 [source_files]]
        > [target];
}

#include-cooked etc/ref-parts.so.d


archive/[project_minus].pdf: etc/reference.pdf
    set shallow
{
    if [quiet] then
        function print Copy [target];
    cp [need] [target];
}

/* vim: set ts=8 sw=4 et : */
