| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# Authors: |
| 4 |
# Pavel Březina <[email protected]> |
| 5 |
# |
| 6 |
# Copyright (C) 2018 Red Hat |
| 7 |
# |
| 8 |
# This program is free software; you can redistribute it and/or modify |
| 9 |
# it under the terms of the GNU General Public License as published by |
| 10 |
# the Free Software Foundation; either version 3 of the License, or |
| 11 |
# (at your option) any later version. |
| 12 |
# |
| 13 |
# This program is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
# |
| 21 |
# |
| 22 |
# Translate and build manual pages. |
| 23 |
# |
| 24 |
# Usage: manpages-build.sh prefix exec_prefix |
| 25 |
# |
| 26 |
|
| 27 |
prefix=$1 |
| 28 |
exec_prefix=$2 |
| 29 |
STAMPFILE="@abs_top_builddir@/src/man/build.stamp" |
| 30 |
SCRIPTFILE="@abs_top_builddir@/src/man/build.sh" |
| 31 |
|
| 32 |
# Get last modification time of a file. |
| 33 |
# Usage: last-modification-time FILE |
| 34 |
last-modification-time() { |
| 35 |
local MOD=`stat -c %Y "$1" 2> /dev/null` |
| 36 |
|
| 37 |
if [ $? -ne 0 ] || [ -z $MOD ]; then |
| 38 |
echo 0 |
| 39 |
return 0 |
| 40 |
fi |
| 41 |
|
| 42 |
echo $MOD |
| 43 |
return 0 |
| 44 |
} |
| 45 |
|
| 46 |
# Print current configuration. |
| 47 |
# Usage: print-configuration |
| 48 |
print-configuration() { |
| 49 |
echo $prefix |
| 50 |
echo $exec_prefix |
| 51 |
} |
| 52 |
|
| 53 |
# Test if configuration changed. |
| 54 |
# Return: 0 if yes, 1 otherwise. |
| 55 |
# Usage: configuration-changed |
| 56 |
configuration-changed() { |
| 57 |
local TIME_STAMP=`last-modification-time "$STAMPFILE"` |
| 58 |
local TIME_BUILD=`last-modification-time "$SCRIPTFILE"` |
| 59 |
|
| 60 |
if [ ! -f "$STAMPFILE" ]; then |
| 61 |
return 0 |
| 62 |
fi |
| 63 |
|
| 64 |
if [ $TIME_STAMP -lt $TIME_BUILD ]; then |
| 65 |
return 0 |
| 66 |
fi |
| 67 |
|
| 68 |
if [ "x`cat "$STAMPFILE"`" != "x`print-configuration`" ]; then |
| 69 |
return 0 |
| 70 |
fi |
| 71 |
|
| 72 |
return 1 |
| 73 |
} |
| 74 |
|
| 75 |
# Check if manual page needs new translation. |
| 76 |
# Return: 0 if yes, 1 otherwise. |
| 77 |
# Usage: need-translation PATH_SOURCE PATH_PO PATH_TRANSLATION |
| 78 |
need-translation() { |
| 79 |
local PATH_SOURCE="$1" |
| 80 |
local PATH_PO="$2" |
| 81 |
local PATH_TRANSLATION="$3" |
| 82 |
|
| 83 |
local TIME_SOURCE=`last-modification-time "$PATH_SOURCE"` |
| 84 |
local TIME_PO=`last-modification-time "$PATH_PO"` |
| 85 |
local TIME_TRANSLATION=`last-modification-time "$PATH_TRANSLATION"` |
| 86 |
|
| 87 |
if configuration-changed; then |
| 88 |
return 0 |
| 89 |
fi |
| 90 |
|
| 91 |
# Translation does not yet exist. |
| 92 |
if [ ! -f "$PATH_TRANSLATION" ] && [ -f "$PATH_PO" ]; then |
| 93 |
return 0 |
| 94 |
fi |
| 95 |
|
| 96 |
# Translation is outdated. |
| 97 |
if [ $TIME_TRANSLATION -lt $TIME_PO ]; then |
| 98 |
return 0 |
| 99 |
fi |
| 100 |
|
| 101 |
# Source file is updated. |
| 102 |
if [ $TIME_TRANSLATION -lt $TIME_SOURCE ]; then |
| 103 |
return 0 |
| 104 |
fi |
| 105 |
|
| 106 |
return 1 |
| 107 |
} |
| 108 |
|
| 109 |
# Check if manual page needs new compilation. |
| 110 |
# Return: 0 if yes, 1 otherwise. |
| 111 |
# Usage: need-compilation PATH_SOURCE PATH_DEST |
| 112 |
need-compilation() { |
| 113 |
local PATH_SOURCE="$1" |
| 114 |
local PATH_DEST="$2" |
| 115 |
|
| 116 |
local TIME_SOURCE=`last-modification-time "$PATH_SOURCE"` |
| 117 |
local TIME_DEST=`last-modification-time "$PATH_DEST"` |
| 118 |
|
| 119 |
if configuration-changed; then |
| 120 |
return 0 |
| 121 |
fi |
| 122 |
|
| 123 |
# Build does not yet exist. |
| 124 |
if [ ! -f "$PATH_DEST" ] && [ -f "$PATH_SOURCE" ]; then |
| 125 |
return 0 |
| 126 |
fi |
| 127 |
|
| 128 |
# Build is outdated. |
| 129 |
if [ $TIME_DEST -lt $TIME_SOURCE ]; then |
| 130 |
return 0 |
| 131 |
fi |
| 132 |
|
| 133 |
return 1 |
| 134 |
} |
| 135 |
|
| 136 |
# Find files in directories. |
| 137 |
# Usage: search-dirs PATTERN DIRECTORIES |
| 138 |
search-dirs() { |
| 139 |
local PATTERN=$1 |
| 140 |
shift 1 |
| 141 |
|
| 142 |
find $@ -type f -name "$PATTERN" -printf '%d\t%p\n' 2> /dev/null \ |
| 143 |
| sort -nk1 | cut -f2- |
| 144 |
} |
| 145 |
|
| 146 |
# Find asciidoc sources for manual pages. |
| 147 |
# Usage: manpages-find |
| 148 |
manpages-find() { |
| 149 |
search-dirs "*.adoc" "@abs_top_srcdir@/src/man" "@abs_top_builddir@/src/man" |
| 150 |
} |
| 151 |
|
| 152 |
# Find asciidoc translation sources for manual pages. |
| 153 |
# Usage: manpages-find-translations |
| 154 |
manpages-find-translations() { |
| 155 |
search-dirs "*.po" "@abs_top_srcdir@/src/man/po" |
| 156 |
} |
| 157 |
|
| 158 |
# Translate ascii doc files with po table |
| 159 |
# - source man pages are found in: src/man, name: name.section.adoc |
| 160 |
# - translations are found in: src/man/po, name: manpage.language.po |
| 161 |
# - result is stored in: src/man/translation/$language/name.section.adoc |
| 162 |
# |
| 163 |
# Usage: manpages-translate |
| 164 |
manpages-translate() { |
| 165 |
local DIR_MANS="@abs_top_srcdir@/src/man" |
| 166 |
local DIR_TRANS="@abs_top_builddir@/src/man/translations" |
| 167 |
|
| 168 |
for pofilepath in `manpages-find-translations`; do |
| 169 |
local pofilename=`basename $pofilepath` |
| 170 |
local adoc=`echo $pofilename | sed -E 's/(.*)\.adoc\.[^.]+\.po/\1.adoc/'` |
| 171 |
local lang=`echo $pofilename | sed -E 's/.*\.adoc\.([^.]+)\.po/\1/'` |
| 172 |
local source="$DIR_MANS/$adoc" |
| 173 |
local dest="$DIR_TRANS/$lang/$adoc" |
| 174 |
|
| 175 |
if ! need-translation "$source" "$pofilepath" "$dest" |
| 176 |
then |
| 177 |
continue |
| 178 |
fi |
| 179 |
|
| 180 |
echo "Translating $source to $lang" |
| 181 |
@PO4A_TRANSLATE@ -f asciidoc \ |
| 182 |
--master "$source" \ |
| 183 |
--po "$pofilepath" \ |
| 184 |
--localized "$dest" \ |
| 185 |
--keep 70 > /dev/null |
| 186 |
|
| 187 |
if [ $? -ne 0 ]; then |
| 188 |
echo "Unable to translate manual page: $adoc, $pofilename" |
| 189 |
return 1 |
| 190 |
fi |
| 191 |
done |
| 192 |
|
| 193 |
return 0 |
| 194 |
} |
| 195 |
|
| 196 |
# Compile ascii doc into manual page format. |
| 197 |
# Usage: manpages-compile SOURCE [additional a2x parameters] |
| 198 |
manpages-compile() { |
| 199 |
local FILE=$1 |
| 200 |
local DIR=`dirname $FILE` |
| 201 |
local MAN=`basename $FILE | sed -E 's/(.*)\.adoc/\1/'` |
| 202 |
local LOG="@abs_top_builddir@/translations.log" |
| 203 |
|
| 204 |
if ! need-compilation "$FILE" "$DIR/$MAN" |
| 205 |
then |
| 206 |
return 0 |
| 207 |
fi |
| 208 |
|
| 209 |
shift 1 |
| 210 |
|
| 211 |
echo "Building manpage: $FILE" |
| 212 |
|
| 213 |
mkdir -p "$DIR" |
| 214 |
@A2X@ -D "$DIR" --doctype manpage --format manpage "$FILE" $* |
| 215 |
if [ $? -ne 0 ]; then |
| 216 |
# Repeat with increased verbosity and save to log |
| 217 |
echo ">>> Unable to compile translation \"$FILE\":" &>> $LOG |
| 218 |
echo "@A2X@ -D \"$DIR\" --doctype manpage --format manpage \"$FILE\" $* -vv" &>> $LOG |
| 219 |
@A2X@ -D "$DIR" --doctype manpage --format manpage "$FILE" $* -vv &>> $LOG |
| 220 |
fi |
| 221 |
} |
| 222 |
|
| 223 |
ATTR="" |
| 224 |
ATTR+=" -a sysconfdir=\"@sysconfdir@\"" |
| 225 |
ATTR+=" -a AUTHSELECT_CONFIG_DIR=\"@AUTHSELECT_CONFIG_DIR@\"" |
| 226 |
ATTR+=" -a AUTHSELECT_CUSTOM_DIR=\"@AUTHSELECT_CUSTOM_DIR@\"" |
| 227 |
ATTR+=" -a AUTHSELECT_DCONF_BIN=\"@AUTHSELECT_DCONF_BIN@\"" |
| 228 |
ATTR+=" -a AUTHSELECT_DCONF_DIR=\"@AUTHSELECT_DCONF_DIR@\"" |
| 229 |
ATTR+=" -a AUTHSELECT_DCONF_FILE=\"@AUTHSELECT_DCONF_FILE@\"" |
| 230 |
ATTR+=" -a AUTHSELECT_NSSWITCH_CONF=\"@AUTHSELECT_NSSWITCH_CONF@\"" |
| 231 |
ATTR+=" -a AUTHSELECT_PAM_DIR=\"@AUTHSELECT_PAM_DIR@\"" |
| 232 |
ATTR+=" -a AUTHSELECT_PROFILE_DIR=\"@AUTHSELECT_PROFILE_DIR@/default\"" |
| 233 |
ATTR+=" -a AUTHSELECT_VENDOR_DIR=\"@AUTHSELECT_PROFILE_DIR@/vendor\"" |
| 234 |
ATTR+=" -a AUTHSELECT_BACKUP_DIR=\"@AUTHSELECT_BACKUP_DIR@\"" |
| 235 |
|
| 236 |
manpages-translate |
| 237 |
|
| 238 |
rm "@abs_top_builddir@/translations.log" &> /dev/null |
| 239 |
for ADOC in `manpages-find` ; do \ |
| 240 |
manpages-compile $ADOC $ATTR |
| 241 |
done |
| 242 |
|
| 243 |
# Create a timestamp file and remember prefix variables so we can use it next |
| 244 |
# time to determine whether the manual pages require rebuild or no. |
| 245 |
print-configuration > $STAMPFILE |