/*
 * fhist - file history and comparison tools
 * Copyright (C) 1998, 2002, 2008, 2010, 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/>.
 */

command_list = [commands];
loop
{
    command = [head [command_list]];
    if [not [count [command]]] then
        loopstop;
    command_list = [tail [command_list]];

    [command],I =
        [fromto [command]/%0%.y [command]/%0%.yacc.c,I
            [match_mask [command]/%0%.y [source_files]]
        ]
        [fromto [command]/%0%.c [command]/%0%.c,I
            [match_mask [command]/%0%.c [source_files]]
        ]
        ;
}
common,I =
    [fromto common/%0%.y common/%0%.yacc.c,I
        [match_mask common/%0%.y [source_files]]
    ]
    [fromto common/%0%.c common/%0%.c,I
        [match_mask common/%0%.c [source_files]]
    ]
    ;
all,I =
    [fromto %0%.y %0%.yacc.c,I [match_mask %0%.y [source_files]]]
    [fromto %0%.c %0%.c,I [match_mask %0%.c [source_files]]]
    ;

/*
 * Translate the locatization files into their binary form.  This will
 * be different for each architecture and operating system (in theory,
 * if not in practice).
 */

internationalization:
    lib/common.ok
    [fromto lib/%0%.po [arch]/lib/%0%.mo
        [match_mask lib/%0%.po [source_files]]
    ]
    [fromto lib/%0%.po lib/%0%.merge
        [match_mask lib/%0%.po [source_files]]
    ]
    /* LICENSE */
    ;

lib/common.ok: lib/common.pot etc/zer-len-msg.sh
{
    function if_quiet Generate;
    sh [resolve etc/zer-len-msg.sh lib/common.pot];
    touch [target];
}

msgcomm = msgcomm;

lib/common.pot: [prepost "lib/" ".po" [commands]]
{
    function if_quiet Generate;
    [msgcomm]
        --force-po
        --omit-header
        --sort-output
        --add-location
        --indent
        --width\=75
        -o [target]
        [prepost "--dir=" "" [search_list]]
        [need];
}


msgmerge = msgmerge;
msgcmp = msgcmp;

lib/%0%.merge: lib/%0%.po lib/%.po
{
    function if_quiet Generate;
    [msgmerge]
    [addprefix --compendium\= [glob "c/%0*.po" ]]
    ['if' [not [in % common]] 'then'
        --compendium\=[resolve lib/%0common.po]
    ]
    --indent
    --sort-output
    --width\=75
    -v -v
    --no-location
    --force-po
    -o [target]
    [resolve lib/%0%.po lib/%.po]
    ;

    /*
     * There should be no differences.
     * If there are, this next command will show them.
     */
    [msgcmp] --use-fuzzy [resolve lib/%0%.po] [target];

    /*
     * Only need the timestamp, discard the file contents.
     */
    > [target];
}


[arch]/lib/%0%.mo: lib/%0%.po: lib/%0common.po
    etc/msgfmt.sh
    set ['if' [not [defined baseline]] 'then' shallow]
{
    function if_quiet Generate;
    /*
     * This only works for GNU gettext (and Solaris).
     * The SunOS msgfmt program does not grok the -o option.
     */
    sh [resolve etc/msgfmt.sh]
        --msgfmt\=[msgfmt]
        --msgcat\=[msgcat]
        --output\=[target]
        [resolve lib/%0%.po lib/%0common.po]
    ;
}


xgettext = xgettext;

/*
 * These files act as a "header files" to check the lib/%0%.po files
 * against.  There should not be any extras or omitions.
 */

lib/common.po: [all,I] [prepost "lib/en/LC_MESSAGES/" ".po" [commands]]
{
    function if_quiet Generate;
    /*
     * The author only speaks English, so the master translation is
     * "en", hence lib/en/LC_MESSAGES/....po are the files intended.
     */
    [xgettext]
        --sort-output
        --indent
        --omit-header
        --add-location
        --force-po
        --width\=75
        -o [target]
        [prepost "--dir=" "" [search_list]]
        [prepost "--exclude-file=lib/en/LC_MESSAGES/" ".po" [commands]]
        --language\=PO
        [all,I];
}

lib/%.po: [%,I]: lib/en/LC_MESSAGES/common.po
{
    function if_quiet Generate;
    /*
     * The author only speaks English, so the master translation is
     * "en", hence lib/en/LC_MESSAGES/common.po is the file
     * intended.
     */
    [xgettext]
        --sort-output
        --indent
        --omit-header
        --add-location
        --force-po
        -o [target]
        [prepost "--dir=" "" [search_list]]
        --exclude-file\=lib/en/LC_MESSAGES/common.po
        --language\=PO
        [%,I];
}

%0%.c,I: %0%.c
    set no-cascade
{
    [xgettext]
        --sort-output
        --indent
        --omit-header
        --force-po
        --add-location
        -o [target]
        --msgstr-prefix\=
        --msgstr-suffix\=
        --keyword\=i18n
        --keyword\=error_intl
        --keyword\=fatal_intl
        --keyword\=verbose_intl
        --keyword\=subst_intl
        --keyword\=fngrprnt_error
        --keyword\=lex_error
        --keyword\=lex_warning
        [prepost "--dir=" "" [search_list]]
        %0%.c;
}


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