| 1 |
# -*-Shell-script-*- |
| 2 |
# |
| 3 |
# Copyright (C) 2012-2021 SUSE Software Solutions Germany GmbH |
| 4 |
# |
| 5 |
# Author: |
| 6 |
# Frank Sundermeyer <fsundermeyer at opensuse dot org> |
| 7 |
# |
| 8 |
# Functions for ../bin/daps |
| 9 |
# |
| 10 |
# |
| 11 |
|
| 12 |
|
| 13 |
########################################################################### |
| 14 |
# |
| 15 |
# ARGUMENT PARSER FOR ALL SUBCOMMANDS |
| 16 |
# |
| 17 |
# Generic parser for the subcommands' command line switches. If a function |
| 18 |
# introduces a new switch, it needs to be added here |
| 19 |
# |
| 20 |
########################################################################### |
| 21 |
function parse_args { |
| 22 |
# |
| 23 |
# help is always handled within the function directly |
| 24 |
# everything else is parsed here |
| 25 |
|
| 26 |
# this functions only parses the getopts arguments and sets |
| 27 |
# variables accordingly. |
| 28 |
|
| 29 |
local SHORT_OPTS LONG_OPTS SUB_CMD |
| 30 |
SHORT_OPTS=$1 |
| 31 |
LONG_OPTS=$2 |
| 32 |
SUB_CMD=$3 |
| 33 |
shift 3 |
| 34 |
|
| 35 |
C_ARGS=$(getopt -s bash -o "$SHORT_OPTS" -l "$LONG_OPTS" -n "$0" -- "$@") |
| 36 |
if [[ 1 -eq $? ]]; then |
| 37 |
wrong_parameter "$SUB_CMD" |
| 38 |
fi |
| 39 |
|
| 40 |
eval set -- "$C_ARGS" |
| 41 |
|
| 42 |
while true ; do |
| 43 |
case "$1" in |
| 44 |
--check) |
| 45 |
# epub: validating result |
| 46 |
# also requires a minimum verbosity level of 1 |
| 47 |
# |
| 48 |
[[ 0 -eq "$VERBOSITY" ]] && export VERBOSITY=1 |
| 49 |
export RESULTCHECK=1 |
| 50 |
shift |
| 51 |
;; |
| 52 |
--clean) |
| 53 |
# html/webhelp: clean up previous builds |
| 54 |
export CLEAN_DIR=1 |
| 55 |
shift |
| 56 |
;; |
| 57 |
--color) |
| 58 |
# images: only create color images |
| 59 |
export IMAGES_COLOR=1 |
| 60 |
shift |
| 61 |
;; |
| 62 |
--compact) |
| 63 |
# getimages: one line filelist |
| 64 |
# no need to export (not passed to make) |
| 65 |
COMPACT=1 |
| 66 |
shift |
| 67 |
;; |
| 68 |
--cropmarks) |
| 69 |
# pdf/package-pdf/show-names: PDF Cropmarks |
| 70 |
export CROPMARKS=1 |
| 71 |
shift |
| 72 |
;; |
| 73 |
--css) |
| 74 |
# epub/html/package-html/webhelp: Path to custom CSS file |
| 75 |
# processed differently in respective targets |
| 76 |
# no direct export here |
| 77 |
declare P_CSS |
| 78 |
if [[ $2 != "none" ]]; then |
| 79 |
sanitize_path "$2" "P_CSS" |
| 80 |
else |
| 81 |
P_CSS="$2" |
| 82 |
fi |
| 83 |
shift 2 |
| 84 |
;; |
| 85 |
--def-file) |
| 86 |
# locdrop/package-src: include DEF-file |
| 87 |
declare DEF_FILE |
| 88 |
sanitize_path "$2" "DEF_FILE" |
| 89 |
export DEF_FILE |
| 90 |
shift 2 |
| 91 |
;; |
| 92 |
--desktopfiles) |
| 93 |
# package-html/package-pdf: Create desktop files |
| 94 |
export DESKTOPFILES=1 |
| 95 |
shift |
| 96 |
;; |
| 97 |
--documentfiles) |
| 98 |
# package-html/package-pdf: Create document files |
| 99 |
export DOCUMENTFILES=1 |
| 100 |
shift |
| 101 |
;; |
| 102 |
--draft) |
| 103 |
# html/pdf/profile-first/show-names/webhelp: draft mode |
| 104 |
# exported in init_env |
| 105 |
DRAFT=yes |
| 106 |
shift |
| 107 |
;; |
| 108 |
--epub3) |
| 109 |
# epub: Create ePub 3 |
| 110 |
export EPUB3=1 |
| 111 |
shift |
| 112 |
;; |
| 113 |
--export-dir) |
| 114 |
# locdrop: export directory |
| 115 |
declare EXPORT_DIR |
| 116 |
sanitize_path "$2" "EXPORT_DIR" |
| 117 |
export EXPORT_DIR |
| 118 |
shift 2 |
| 119 |
;; |
| 120 |
--extra-dict) |
| 121 |
# spellcheck: additional dictionary |
| 122 |
# no need to export (not passed to make) |
| 123 |
SPELL_EXTRA_DICT="$2" |
| 124 |
shift 2 |
| 125 |
;; |
| 126 |
--file) |
| 127 |
# getimages/linkcheck/spellcheck/stylecheck/xmlformat |
| 128 |
# no need to export (not passed to make) |
| 129 |
declare P_FILE |
| 130 |
sanitize_path "$2" "P_FILE" |
| 131 |
shift 2 |
| 132 |
;; |
| 133 |
--formatter) |
| 134 |
# package-pdf/pdf/show-names: PDF formatter |
| 135 |
if [[ xep = "$2" || fop = "$2" ]]; then |
| 136 |
export FORMATTER="$2" |
| 137 |
else |
| 138 |
exit_on_error "Wrong parameter for --formatter: must be \"xep\" or \"fop\"!" |
| 139 |
fi |
| 140 |
shift 2 |
| 141 |
;; |
| 142 |
--gen) |
| 143 |
# images: no links |
| 144 |
export IMAGES_GEN=1 |
| 145 |
shift |
| 146 |
;; |
| 147 |
--grayscale) |
| 148 |
# images/pdf/package-pdf/show-names: only grayscale images |
| 149 |
export GRAYSCALE=1 |
| 150 |
shift |
| 151 |
;; |
| 152 |
-h|--help) |
| 153 |
# basically all targets |
| 154 |
# no need to export (not passed to make) |
| 155 |
P_HELP=1 |
| 156 |
shift |
| 157 |
;; |
| 158 |
--html5) |
| 159 |
# html/package-html: create html5 |
| 160 |
export HTML5=1 |
| 161 |
shift |
| 162 |
;; |
| 163 |
--ignore-styleroot) |
| 164 |
# text / call_make: force use upstream DB stylesheets |
| 165 |
export TXT_IGNORE_STYLEROOT=1 |
| 166 |
shift |
| 167 |
;; |
| 168 |
--imgonly) |
| 169 |
# "meta" attribute, will preset other attributes for |
| 170 |
# list-srcfiles |
| 171 |
# no need to export (not passed to make) |
| 172 |
P_LIST_IMG_ONLY=1 |
| 173 |
shift |
| 174 |
;; |
| 175 |
--lang) |
| 176 |
# spellcheck: Language |
| 177 |
# no need to export (not passed to make) |
| 178 |
P_LANG="$2" |
| 179 |
shift 2 |
| 180 |
;; |
| 181 |
--lean) |
| 182 |
# pdf: create PDF with rediced graphics quailty |
| 183 |
export LEAN="1" |
| 184 |
shift |
| 185 |
;; |
| 186 |
--list) |
| 187 |
# spellcheck: dump misspelled to STDOUT |
| 188 |
# no need to export (not passed to make) |
| 189 |
LISTMODE=1 |
| 190 |
shift |
| 191 |
;; |
| 192 |
--locdrop) |
| 193 |
# package-src: include manifest files for translation |
| 194 |
export IS_LOCDROP=1 |
| 195 |
shift |
| 196 |
;; |
| 197 |
--meta) |
| 198 |
# html/pdf: display meta data in draft mode |
| 199 |
# exported in init_env |
| 200 |
META=1 |
| 201 |
shift |
| 202 |
;; |
| 203 |
--modified) |
| 204 |
# getimages: show file modification times |
| 205 |
# no need to export (not passed to make) |
| 206 |
MOD=1 |
| 207 |
shift |
| 208 |
;; |
| 209 |
--name) |
| 210 |
# used almost everywhere to set the filename |
| 211 |
export OUTPUTNAME="$2" BOOK="$2" |
| 212 |
shift 2 |
| 213 |
;; |
| 214 |
--nodc) |
| 215 |
# filelists: Do not show DC-file |
| 216 |
export LIST_NODC=1 |
| 217 |
shift |
| 218 |
;; |
| 219 |
--noent) |
| 220 |
# filelists: Do not show entity files |
| 221 |
export LIST_NOENT=1 |
| 222 |
shift |
| 223 |
;; |
| 224 |
--nogzip) |
| 225 |
# man: do not gzip man pages |
| 226 |
export GZIP_MAN="no" |
| 227 |
shift |
| 228 |
;; |
| 229 |
--noimg) |
| 230 |
# filelists: Do not show images |
| 231 |
export LIST_NOIMG=1 |
| 232 |
shift |
| 233 |
;; |
| 234 |
--nopdf) |
| 235 |
# locdrop: Do not generate PDF |
| 236 |
export NOPDF=1 |
| 237 |
shift |
| 238 |
;; |
| 239 |
--nosearch) |
| 240 |
export WH_SEARCH="no" |
| 241 |
shift |
| 242 |
;; |
| 243 |
--nostatic) |
| 244 |
# html/webhelp: Do not copy images, link them |
| 245 |
export STATIC_HTML=0 |
| 246 |
shift |
| 247 |
;; |
| 248 |
--norefcheck) |
| 249 |
# used in many targets: do not validate xrefs |
| 250 |
export NOREFCHECK="1" |
| 251 |
shift |
| 252 |
;; |
| 253 |
--notrans-dir) |
| 254 |
# unpack-locdrop: path to en directory |
| 255 |
# no need to export (not passed to make) |
| 256 |
declare P_NOTRANS_DIR |
| 257 |
sanitize_path "$2" "P_NOTRANS_DIR" |
| 258 |
shift 2 |
| 259 |
;; |
| 260 |
--not-validate-tables) |
| 261 |
export NOT_VALIDATE_TABLES=1 |
| 262 |
shift |
| 263 |
;; |
| 264 |
--novalid) |
| 265 |
# bigfile: Do not validate profiled sources |
| 266 |
export NOVALID=1 |
| 267 |
shift |
| 268 |
;; |
| 269 |
--noxml|--noadoc) |
| 270 |
# filelists: Do not show XML/ADOC files |
| 271 |
export LIST_NOXML=1 |
| 272 |
shift |
| 273 |
;; |
| 274 |
--online) |
| 275 |
# images: generate online images |
| 276 |
export IMAGES_ONLINE=1 |
| 277 |
shift |
| 278 |
;; |
| 279 |
--optipng) |
| 280 |
# locdrop/package-src/unpack-locdrop: Optimize PNGs |
| 281 |
export OPTIPNG=1 |
| 282 |
shift |
| 283 |
;; |
| 284 |
--output-dir) |
| 285 |
# unpack lockdrop: output directory |
| 286 |
# no need to export (not passed to make) |
| 287 |
declare P_OUTPUT_DIR="" |
| 288 |
sanitize_path "$2" "P_OUTPUT_DIR" |
| 289 |
shift 2 |
| 290 |
;; |
| 291 |
--pagefiles) |
| 292 |
# package-html/package-pdf: Generate pagefiles |
| 293 |
export PAGEFILES=1 |
| 294 |
shift |
| 295 |
;; |
| 296 |
--param) |
| 297 |
# various targets: xslt (numeric) parameters |
| 298 |
# Values are concatenated here |
| 299 |
# exported in init_env |
| 300 |
P_PARAMS="$P_PARAMS --param $2" |
| 301 |
shift 2 |
| 302 |
;; |
| 303 |
--pretty) |
| 304 |
# filelists: make outpot human readyble |
| 305 |
export PRETTY_FILELIST=1 |
| 306 |
shift |
| 307 |
;; |
| 308 |
--remarks) |
| 309 |
# epub/html/pdf/profile-first/show-names/webhelp: draft mode |
| 310 |
# exported in init_env |
| 311 |
REMARKS=1 |
| 312 |
shift |
| 313 |
;; |
| 314 |
--remove-dm) |
| 315 |
# unpack-locdrop: Remove Docmanager blocks |
| 316 |
# no need to export (not passed to make) |
| 317 |
P_REMOVEDM=1 |
| 318 |
shift |
| 319 |
;; |
| 320 |
--rootid) |
| 321 |
# used almost everywhere: ROOTID |
| 322 |
# P_ROOTID is needed for |
| 323 |
# getimages/linkcheck//spellcheck/stylecheck/xmlformat |
| 324 |
# to distinguish between valkues provided by |
| 325 |
# config and command line |
| 326 |
P_ROOTID="$2" |
| 327 |
export ROOTID="$2" |
| 328 |
shift 2 |
| 329 |
;; |
| 330 |
--show) |
| 331 |
# getimages/linkcheck/stylecheck |
| 332 |
export SHOW=1 |
| 333 |
shift |
| 334 |
;; |
| 335 |
--set-date) |
| 336 |
# package-html/package-pdf/package-src: manually set date |
| 337 |
SETDATE=$(date -d "$2" +"%b %d %Y" 2>/dev/null) || exit_on_error "Wrong value for set-date: must be in a \"date\" compatible format,\ne.g. \"YYYY-MM-DD\"!" |
| 338 |
export SETDATE |
| 339 |
shift 2 |
| 340 |
;; |
| 341 |
--single) |
| 342 |
# html/package-html/show-names: create single HTML |
| 343 |
export HTMLSINGLE=1 |
| 344 |
shift |
| 345 |
;; |
| 346 |
--spellchecker) |
| 347 |
# spellcheck: aspell or hunspell |
| 348 |
SPELL_CHECKER="$2" |
| 349 |
shift 2 |
| 350 |
;; |
| 351 |
--static) |
| 352 |
ccecho -- "warn" "--static is deprecated, since it is the default now." |
| 353 |
shift |
| 354 |
;; |
| 355 |
--statdir) |
| 356 |
# epub/html/package-html: directory containing js and css |
| 357 |
declare STATIC_DIR |
| 358 |
sanitize_path "$2" "STATIC_DIR" |
| 359 |
export STATIC |
| 360 |
shift 2 |
| 361 |
;; |
| 362 |
--stringparam) |
| 363 |
# various targets: xslt (numeric) parameters |
| 364 |
# Values are concatenated here |
| 365 |
# exported in init_env |
| 366 |
P_STRINGPARAMS="$P_STRINGPARAMS --stringparam $2" |
| 367 |
shift 2 |
| 368 |
;; |
| 369 |
--subdirs) |
| 370 |
# mnn: use subdirectories |
| 371 |
export MAN_SUBDIRS="yes" |
| 372 |
shift |
| 373 |
;; |
| 374 |
--target) |
| 375 |
# dapsenv/showvariable: specify subcommand |
| 376 |
TARGET="$2" |
| 377 |
shift 2 |
| 378 |
;; |
| 379 |
--trans-files) |
| 380 |
# unpack_locdrop |
| 381 |
# no need to export (not passed to make) |
| 382 |
P_TRANS_FILES="$2" |
| 383 |
shift 2 |
| 384 |
;; |
| 385 |
--validate-ids) |
| 386 |
export VALIDATE_IDS=1 |
| 387 |
shift |
| 388 |
;; |
| 389 |
--validate-images) |
| 390 |
export VALIDATE_IMAGES=1 |
| 391 |
shift |
| 392 |
;; |
| 393 |
--viewer) |
| 394 |
# getimages: specify image viewer |
| 395 |
# no need to export (not passed to make) |
| 396 |
IMG_VIEWER="$2" |
| 397 |
shift 2 |
| 398 |
;; |
| 399 |
--xmlonly|--adoconly) |
| 400 |
# "meta" attribute, will preset other attributes for |
| 401 |
# list-srcfiles |
| 402 |
# no need to export (not passed to make) |
| 403 |
P_LIST_XML_ONLY=1 |
| 404 |
shift |
| 405 |
;; |
| 406 |
--) |
| 407 |
shift |
| 408 |
break |
| 409 |
;; |
| 410 |
*) |
| 411 |
wrong_parameter "$SUB_CMD" |
| 412 |
;; |
| 413 |
esac |
| 414 |
done |
| 415 |
|
| 416 |
P_REMAIN_ARGS="$*" |
| 417 |
|
| 418 |
# Deprecation warning if PDFNAME is still used (and does not |
| 419 |
# get overwritten by --name) |
| 420 |
# |
| 421 |
if [[ -n "$PDFNAME" && -z "$P_NAME" ]]; then |
| 422 |
ccecho "warn" "Warning: PDFNAME is deprecated. Use OUTPUTNAME instead." |
| 423 |
fi |
| 424 |
} |
| 425 |
|
| 426 |
########################################################################### |
| 427 |
# |
| 428 |
# INITIALIZE ENVIRONMENT |
| 429 |
# |
| 430 |
# Create needed directories and links |
| 431 |
# Finally export some variables |
| 432 |
# |
| 433 |
########################################################################### |
| 434 |
function init_env { |
| 435 |
# Create the log directory and a link to the DC-file in R_DIR |
| 436 |
# (R_DIR and LOG_DIR are set in bin/daps) |
| 437 |
|
| 438 |
local DC_COUNT TEST_ROOTID_RESULT |
| 439 |
|
| 440 |
# create directories |
| 441 |
|
| 442 |
mkdir -p "$R_DIR" |
| 443 |
if [[ 1 -eq $WRITE_LOG ]]; then |
| 444 |
mkdir -p "$LOG_DIR" || exit_on_error "Cannot create $LOG_DIR" |
| 445 |
fi |
| 446 |
|
| 447 |
|
| 448 |
if [[ -n $"$DOCCONF" && ! -f ${R_DIR}/$(basename "$DOCCONF") ]]; then |
| 449 |
ln -sf "$DOCCONF" "${R_DIR}/$(basename "$DOCCONF")" |
| 450 |
if [[ 0 -ne $? && 0 -ne $VERBOSITY ]]; then |
| 451 |
ccecho "warn" "Warning: Cannot create link to $DOCCONF in $R_DIR" |
| 452 |
fi |
| 453 |
fi |
| 454 |
|
| 455 |
# There should only be one DC-file in $R_DIR |
| 456 |
# |
| 457 |
DC_COUNT=$(find -L "$R_DIR" -maxdepth 1 -name "${CONF_PREFIX}*" -type f | wc -l 2>/dev/null) |
| 458 |
if [[ $DC_COUNT -gt 1 && 0 -ne $VERBOSITY ]]; then |
| 459 |
ccecho "warn" "$R_DIR contains more than one DC-file" |
| 460 |
fi |
| 461 |
|
| 462 |
# test if ROOTID exist |
| 463 |
# |
| 464 |
if [[ -n "$ROOTID" ]]; then |
| 465 |
EXISTS_ROOTID=$($XSLTPROC --stringparam "rootid=$ROOTID" --xinclude --stylesheet "${DAPSROOT}/daps-xslt/common/check_rootid.xsl" --file "$MAIN" "$XSLTPROCESSOR" 2>/dev/null) |
| 466 |
TEST_ROOTID_RESULT=$? |
| 467 |
if [[ 0 -eq $TEST_ROOTID_RESULT && "yes" != "$EXISTS_ROOTID" ]]; then |
| 468 |
exit_on_error "Fatal: ROOTID \"$ROOTID\" does not exist." |
| 469 |
elif [[ 0 -ne $TEST_ROOTID_RESULT && 0 -ne $VERBOSITY ]]; then |
| 470 |
ccecho "warn" "Warning: Could not determine whether ROOTID \"$ROOTID\" exists." |
| 471 |
fi |
| 472 |
fi |
| 473 |
|
| 474 |
# |
| 475 |
# The DocBook stylesheets require a 0|1 for REMARKS, but |
| 476 |
# yes|no for DRAFT |
| 477 |
# In order not to add to that confusion we will accept 0|1|yes|no for |
| 478 |
# all of them and export the correct value here. Since META falls |
| 479 |
# into a similar category, we also handle it the same way. |
| 480 |
# We also need to reset the _STR variables that get added to the resulting |
| 481 |
# filename here, when REMARKS, META or DRAFT has been disabled |
| 482 |
# |
| 483 |
# DRAFT must be set to yes|no |
| 484 |
case "$DRAFT" in |
| 485 |
1|yes) |
| 486 |
export DRAFT="yes" ;; |
| 487 |
0|no|"") |
| 488 |
export DRAFT="no" ;; |
| 489 |
*) |
| 490 |
exit_on_error "Wrong value for DRAFT. Must be \"yes\" or \"no\"" ;; |
| 491 |
esac |
| 492 |
|
| 493 |
# REMARKS must be set to 1|0 |
| 494 |
# if enabled (set to 1) implies DRAFT mode |
| 495 |
case "$REMARKS" in |
| 496 |
1|yes) |
| 497 |
export REMARKS=1 DRAFT="yes" ;; |
| 498 |
0|no|"") |
| 499 |
export REMARKS=0 ;; |
| 500 |
*) |
| 501 |
exit_on_error "Invalid value for REMARKS. Must be \"yes\" or \"no\"" |
| 502 |
;; |
| 503 |
esac |
| 504 |
|
| 505 |
# META must be set to 1|0 |
| 506 |
# if enabled (set to 1) implies DRAFT mode |
| 507 |
case "$META" in |
| 508 |
1|yes) |
| 509 |
export META=1 DRAFT="yes" ;; |
| 510 |
0|no|"") |
| 511 |
export META=0 ;; |
| 512 |
*) |
| 513 |
exit_on_error "Invalid value for META. Must be \"yes\" or \"no\"" |
| 514 |
;; |
| 515 |
esac |
| 516 |
|
| 517 |
# COLOR must be set to 1|0 |
| 518 |
# if we are not in a terminal but rather in a pipe, script, etc. |
| 519 |
# disable color output otherwise use the value specified on the |
| 520 |
# command line or in the config |
| 521 |
if [[ -t 1 ]]; then |
| 522 |
case $COLOR in |
| 523 |
"1" | "yes") |
| 524 |
export COLOR=1 ;; |
| 525 |
"0" | "no" | "") |
| 526 |
COLOR=0 ;; |
| 527 |
*) |
| 528 |
exit_on_error "Invalid value for COLOR. Must be \"yes\" or \"no\"" |
| 529 |
;; |
| 530 |
esac |
| 531 |
else |
| 532 |
# No terminal |
| 533 |
COLOR=0 |
| 534 |
fi |
| 535 |
|
| 536 |
# export PARAMS and STRINGPARAMS |
| 537 |
[[ -n "$P_PARAMS" ]] && export PARAMS="$P_PARAMS" |
| 538 |
[[ -n "$P_STRINGPARAMS" ]] && export STRINGPARAMS="$P_STRINGPARAMS" |
| 539 |
|
| 540 |
# Unset the strings last, because values for DRAFT or REMARKS |
| 541 |
# may have been altered in-between |
| 542 |
[[ "no" = "$DRAFT" ]] && unset DRAFT_STR |
| 543 |
[[ 0 -eq $META ]] && unset META_STR |
| 544 |
[[ 0 -eq $REMARKS ]] && unset REMARK_STR |
| 545 |
|
| 546 |
} |
| 547 |
|
| 548 |
########################################################################### |
| 549 |
# |
| 550 |
# Get Stylesheet Version |
| 551 |
# |
| 552 |
########################################################################### |
| 553 |
|
| 554 |
function get_stylesheet { |
| 555 |
# |
| 556 |
# takes an URN to VERSION.xsl as a required parameter |
| 557 |
|
| 558 |
local STYLE_FILE STYLE_URN STYLE_VERSION |
| 559 |
|
| 560 |
STYLE_URN=$1 |
| 561 |
|
| 562 |
[[ -z $STYLE_URN ]] && exit_on_error "Function get_stylesheet must be called with an URN" |
| 563 |
|
| 564 |
# saxon6 (at least on openSUSE) does not properly resolve http Urls |
| 565 |
# (because it does not ask the catalog but rather directly accesses |
| 566 |
# the URl) we need to resolve it via xmlcatalog first |
| 567 |
# |
| 568 |
STYLE_FILE=$(xmlcatalog "$XML_MAIN_CATALOG" "$STYLE_URN") |
| 569 |
STYLE_FILE=${STYLE_FILE##*file://} |
| 570 |
STYLE_VERSION=$($XSLTPROC --stylesheet "$DAPSROOT/daps-xslt/common/get-dbxslt-version.xsl" --file "$STYLE_FILE" "$XSLTPROCESSOR" 2>/dev/null || echo "Not available") |
| 571 |
echo "$STYLE_VERSION" |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
########################################################################### |
| 576 |
# |
| 577 |
# RUN MAKE |
| 578 |
# |
| 579 |
# Set up log writing and verbosity |
| 580 |
# and call make |
| 581 |
# |
| 582 |
########################################################################### |
| 583 |
function call_make { |
| 584 |
local COLWIDTH CORE_NO DBSTYLE_FILE DBSTYLE_VERS FB_STYLESHEET_VERS |
| 585 |
local LOGFILE MAKE_BIN MAKE_OPTIONS MAKE_CMD PROFVAR STRING SILENT |
| 586 |
local STYLEROOT_VERS SUB_CMD V |
| 587 |
local -a PROFVARIABLES |
| 588 |
|
| 589 |
# first argument passed to the function is the subcommand |
| 590 |
|
| 591 |
# Second and optional argument is "silent" - if set all debug and |
| 592 |
# verbosity settings are ignored. This allows to run call_make to set |
| 593 |
# variables (e.g. FILELIST=$(call_make "list-srcfiles") |
| 594 |
|
| 595 |
# In some cases, additional arguments are passed to this |
| 596 |
# function - they remain in $@ and will be passed "as is" to make |
| 597 |
# |
| 598 |
SUB_CMD=$1 |
| 599 |
shift |
| 600 |
|
| 601 |
if [[ "silent" = "$1" ]]; then |
| 602 |
SILENT="1" |
| 603 |
shift |
| 604 |
fi |
| 605 |
|
| 606 |
# Check the remaining $@ - if it contains variable definitions (FOO=BAR |
| 607 |
# or FOO="BAR") it's OK, if it contains barewords, exit with an error |
| 608 |
# |
| 609 |
if [[ -n "$@" ]]; then |
| 610 |
for STRING in "$@"; do |
| 611 |
[[ $STRING =~ ^[a-zA-Z][a-zA-Z0-9_]*=..* ]] || exit_on_error "Unknown parameter \"$STRING\"." |
| 612 |
done |
| 613 |
fi |
| 614 |
|
| 615 |
# set up the final environment |
| 616 |
init_env |
| 617 |
|
| 618 |
#------ |
| 619 |
# the make command |
| 620 |
# |
| 621 |
|
| 622 |
MAKE_OPTIONS="-f $DAPSROOT/make/selector.mk" |
| 623 |
MAKE_BIN="/usr/bin/make" |
| 624 |
if [[ 1 -ne $SILENT ]]; then |
| 625 |
if [[ 1 -eq $DEBUG || 3 -eq $VERBOSITY ]]; then |
| 626 |
# use remake if installed when in debug or highest verbosity mode |
| 627 |
IS_REMAKE=$(which remake 2>/dev/null) |
| 628 |
[[ -n "$IS_REMAKE" ]] && MAKE_BIN="/usr/bin/remake" |
| 629 |
MAKE_OPTIONS="$MAKE_OPTIONS --debug=b" |
| 630 |
fi |
| 631 |
fi |
| 632 |
|
| 633 |
# By default the number of parallel jobs for make is set to the number of |
| 634 |
# CPU cores. This can be overwritten with --jobs. |
| 635 |
# If verbosity 3 (-v3) is set, "make -j1" is forced |
| 636 |
# |
| 637 |
if [[ 0 -eq $VERBOSITY || 1 -eq $VERBOSITY || 2 -eq $VERBOSITY ]]; then |
| 638 |
MAKE_OPTIONS="$MAKE_OPTIONS -j${JOBS}" |
| 639 |
[[ 1 -ne $DEBUG || 1 -eq $SILENT ]] && MAKE_OPTIONS="$MAKE_OPTIONS -s" |
| 640 |
else |
| 641 |
# highest verbosity level - use -j1 for a better readability |
| 642 |
MAKE_OPTIONS="$MAKE_OPTIONS -j1" |
| 643 |
fi |
| 644 |
|
| 645 |
# Is --force set to force a rebuild? |
| 646 |
[[ 1 -eq $FORCE_REBUILD ]] && MAKE_OPTIONS="$MAKE_OPTIONS --always-make" |
| 647 |
|
| 648 |
MAKE_CMD="$MAKE_BIN $MAKE_OPTIONS $SUB_CMD $*" |
| 649 |
|
| 650 |
|
| 651 |
# Variable settings summary printed on debug and high verbosity mode |
| 652 |
if [[ 2 -le $VERBOSITY && 1 -ne $SILENT ]]; then |
| 653 |
# list of profiling variables for the debug output |
| 654 |
# |
| 655 |
PROFVARIABLES=( |
| 656 |
PROFARCH |
| 657 |
PROFAUDIENCE |
| 658 |
PROFCONDITION |
| 659 |
PROFCONFORMANCE |
| 660 |
PROFLANG |
| 661 |
PROFOS |
| 662 |
PROFOUTPUTFORMAT |
| 663 |
PROFREVISION |
| 664 |
PROFREVISIONFLAG |
| 665 |
PROFROLE |
| 666 |
PROFSECURITY |
| 667 |
PROFSTATUS |
| 668 |
PROFUSERLEVEL |
| 669 |
PROFVENDOR |
| 670 |
PROFWORDSIZE ) |
| 671 |
|
| 672 |
# column width debug output (for printf) |
| 673 |
COLWIDTH=20 |
| 674 |
|
| 675 |
# get DocBook stylesheet version |
| 676 |
# |
| 677 |
DBSTYLE_VERS=$(get_stylesheet "http://docbook.sourceforge.net/release/xsl/current/VERSION.xsl") |
| 678 |
|
| 679 |
STYLEROOT_VERS=$(get_stylesheet "file://${STYLEROOT}/VERSION.xsl") |
| 680 |
FB_STYLEROOT_VERS=$(get_stylesheet "file://${FALLBACK_STYLEROOT}/VERSION.xsl") |
| 681 |
|
| 682 |
echo -e "---------------\n" |
| 683 |
# DAPS version |
| 684 |
printf "%${COLWIDTH}s: %s\n" "$MY_NAME VERSION" "$VERSION" |
| 685 |
|
| 686 |
echo |
| 687 |
|
| 688 |
# Directories |
| 689 |
for V in DOC_DIR BUILD_DIR DAPSROOT DOCCONF BOOK; do |
| 690 |
printf "%${COLWIDTH}s: %s\n" "$V" "${!V}" |
| 691 |
done |
| 692 |
|
| 693 |
echo |
| 694 |
|
| 695 |
# Profiling |
| 696 |
# show all profiling variables and their values |
| 697 |
for PROFVAR in ${PROFVARIABLES[*]}; do |
| 698 |
[[ -n ${!PROFVAR} ]] && printf "%${COLWIDTH}s: %s\n" "$PROFVAR" "${!PROFVAR}" |
| 699 |
done |
| 700 |
|
| 701 |
echo |
| 702 |
|
| 703 |
# DocBook |
| 704 |
for V in DOCBOOK_VERSION DOCBOOK5_RNG DBSTYLE_VERS; do |
| 705 |
printf "%${COLWIDTH}s: %s\n" "$V" "${!V}" |
| 706 |
done |
| 707 |
|
| 708 |
echo |
| 709 |
|
| 710 |
# Styleroot / Fallback styleroot |
| 711 |
if [[ $SUB_CMD =~ text && "yes" == "$TXT_IGNORE_STYLEROOT" || 1 -eq "$TXT_IGNORE_STYLEROOT" ]]; then |
| 712 |
printf "%${COLWIDTH}s: %s\n" "STYLEROOT" "$DOCBOOK_STYLES" |
| 713 |
else |
| 714 |
if [[ -n "$STYLEDEVEL" ]]; then |
| 715 |
printf "%${COLWIDTH}s: %s\n" "STYLEROOT" "$STYLEDEVEL" |
| 716 |
else |
| 717 |
if [[ -n "$STYLEROOT" ]]; then |
| 718 |
printf "%${COLWIDTH}s: %s\n" "STYLEROOT" "$STYLEROOT" |
| 719 |
else |
| 720 |
printf "%${COLWIDTH}s: %s\n" "STYLEROOT" "$DOCBOOK_STYLES" |
| 721 |
fi |
| 722 |
fi |
| 723 |
|
| 724 |
printf "%${COLWIDTH}s: %s\n" "STYLEROOT_VERS" "$STYLEROOT_VERS" |
| 725 |
|
| 726 |
if [[ -n "$FALLBACK_STYLEROOT" ]]; then |
| 727 |
printf "%${COLWIDTH}s: %s\n" "FALLBACK_STYLEROOT" "$FALLBACK_STYLEROOT" |
| 728 |
else |
| 729 |
# no fallback if STYLEROOT is not set |
| 730 |
if [[ -n "$STYLEROOT" ]]; then |
| 731 |
printf "%${COLWIDTH}s: %s\n" "FALLBACK_STYLEROOT" "$DOCBOOK_STYLES" |
| 732 |
fi |
| 733 |
fi |
| 734 |
printf "%${COLWIDTH}s: %s\n" "FB_STYLEROOT_VERS" "$FB_STYLEROOT_VERS" |
| 735 |
fi |
| 736 |
|
| 737 |
# CSS |
| 738 |
printf "%${COLWIDTH}s: %s\n" "EPUB_CSS" "$EPUB_CSS" |
| 739 |
printf "%${COLWIDTH}s: %s\n" "HTML_CSS" "$HTML_CSS" |
| 740 |
|
| 741 |
echo |
| 742 |
|
| 743 |
# PDF |
| 744 |
printf "%${COLWIDTH}s: %s\n" "PDF FORMATTER" "$FORMATTER" |
| 745 |
if which "$FORMATTER" >/dev/null 2>&1; then |
| 746 |
printf "%${COLWIDTH}s: %s\n" "FORMATTER VERSION" "$($FORMATTER -version)" |
| 747 |
else |
| 748 |
printf "%${COLWIDTH}s: %s\n" "FORMATTER VERSION" |
| 749 |
fi |
| 750 |
if [[ "fop" = "$FORMATTER" ]]; then |
| 751 |
printf "%${COLWIDTH}s: %s\n" "FORMATTER WRAPPER" "$FOP_WRAPPER" |
| 752 |
printf "%${COLWIDTH}s: %s\n" "FORMATTER CONFIG" "$FOP_CONFIG_FILE" |
| 753 |
elif [[ "xep" = "$FORMATTER" ]]; then |
| 754 |
printf "%${COLWIDTH}s: %s\n" "FORMATTER WRAPPER" "$XEP_WRAPPER" |
| 755 |
printf "%${COLWIDTH}s: %s\n" "FORMATTER CONFIG:" "$XEP_CONFIG_FILE" |
| 756 |
fi |
| 757 |
|
| 758 |
echo |
| 759 |
|
| 760 |
# Misc |
| 761 |
for V in MAKE_CMD XSLTPROCESSOR XML_CATALOG_FILES; do |
| 762 |
printf "%${COLWIDTH}s: %s\n" "$V" "${!V}" |
| 763 |
done |
| 764 |
echo -e "\n---------------\n" |
| 765 |
fi |
| 766 |
|
| 767 |
if [[ 1 -eq $WRITE_LOG ]]; then |
| 768 |
LOGFILE="${LOG_DIR}/make_${SUB_CMD}.log" |
| 769 |
date &> "$LOGFILE" |
| 770 |
fi |
| 771 |
|
| 772 |
if [[ 0 -ne $VERBOSITY ]]; then |
| 773 |
if [[ 1 -eq $WRITE_LOG ]]; then |
| 774 |
$MAKE_CMD 2>&1 | tee -a "$LOGFILE" |
| 775 |
# see http://www.unix.com/shell-programming-scripting/92163-command-does-not-return-exit-status-due-tee.html |
| 776 |
[[ 0 -eq ${PIPESTATUS[0]} ]] || exit 1 |
| 777 |
else |
| 778 |
$MAKE_CMD 2>&1 |
| 779 |
fi |
| 780 |
else |
| 781 |
if [[ 1 -eq $WRITE_LOG ]]; then |
| 782 |
$MAKE_CMD >> "$LOGFILE" 2>&1 |
| 783 |
if [[ 0 -eq $? ]]; then |
| 784 |
# make command successful, only show last line (aka result) |
| 785 |
tail -n 1 "$LOGFILE" |
| 786 |
else |
| 787 |
# an error occured in make |
| 788 |
# show complete logfile except the first line containing the |
| 789 |
# date |
| 790 |
tail -n +2 "$LOGFILE" |
| 791 |
exit 1 |
| 792 |
fi |
| 793 |
else |
| 794 |
$MAKE_CMD |
| 795 |
fi |
| 796 |
fi |
| 797 |
} |
| 798 |
|
| 799 |
########################################################## |
| 800 |
# |
| 801 |
# FUNCTION TEMPLATE |
| 802 |
# |
| 803 |
########################################################## |
| 804 |
# local SHORT_OPTS LONG_OPTS SUB_CMD |
| 805 |
|
| 806 |
# The subcommand value is passed when calling this function |
| 807 |
# SUB_CMD=$1 |
| 808 |
# shift |
| 809 |
|
| 810 |
# SHORT_OPTS: Value for the getopt -o option |
| 811 |
# LONG_OPTS: VALUE for the getopt -l option |
| 812 |
# SHORT_OPTS="h" |
| 813 |
# LONG_OPTS="draft,formatter:,help,name:,remarks,rootid:" |
| 814 |
|
| 815 |
# Call the argument parser |
| 816 |
# parse_args $SHORT_OPTS $LONG_OPTS $SUB_CMD "$@" |
| 817 |
|
| 818 |
# Reset this functions $@ to what is remaining after having parsed the |
| 819 |
# subcommand switches |
| 820 |
# eval set -- "$P_REMAIN_ARGS" |
| 821 |
|
| 822 |
# #------ Computing the values returned from the parser ----- |
| 823 |
|
| 824 |
# <REPLACE ME> |
| 825 |
|
| 826 |
# call_make "$UB_CMD" "$@" |
| 827 |
|
| 828 |
|
| 829 |
########################################################################### |
| 830 |
# |
| 831 |
# Generic BUILD function |
| 832 |
# |
| 833 |
# Subcommands: all commands that does not fit elsewhere |
| 834 |
# |
| 835 |
########################################################################### |
| 836 |
function build_generic { |
| 837 |
local SHORT_OPTS LONG_OPTS SUB_CMD |
| 838 |
SUB_CMD=$1 |
| 839 |
shift |
| 840 |
|
| 841 |
SHORT_OPTS="h" |
| 842 |
LONG_OPTS="help,name:,norefcheck,param:,rootid:,stringparam:" |
| 843 |
|
| 844 |
parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@" |
| 845 |
eval set -- "$P_REMAIN_ARGS" |
| 846 |
|
| 847 |
#------ Computing the values returned from the parser ----- |
| 848 |
if [[ 1 -eq $P_HELP ]]; then |
| 849 |
help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}" |
| 850 |
help_help |
| 851 |
help_name |
| 852 |
help_norefcheck |
| 853 |
help_param |
| 854 |
help_rootid |
| 855 |
help_stringparam |
| 856 |
echo |
| 857 |
exit 0 |
| 858 |
fi |
| 859 |
|
| 860 |
call_make "$SUB_CMD" "$@" |
| 861 |
} |
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
########################################################################### |
| 866 |
# |
| 867 |
# PROFILE First |
| 868 |
# |
| 869 |
# Some subcommands (such as projectgraphics and various dist and packaging |
| 870 |
# targets) require an up-tp-date .profiled/* |
| 871 |
# Therefore we call make profile first and then call make a second time |
| 872 |
# with the real target |
| 873 |
# |
| 874 |
########################################################################### |
| 875 |
function profile_first { |
| 876 |
local SHORT_OPTS LONG_OPTS SUB_CMD |
| 877 |
SUB_CMD=$1 |
| 878 |
shift |
| 879 |
|
| 880 |
SHORT_OPTS="h" |
| 881 |
LONG_OPTS="draft,help,name:,remarks,rootid:" |
| 882 |
|
| 883 |
parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@" |
| 884 |
eval set -- "$P_REMAIN_ARGS" |
| 885 |
|
| 886 |
#------ Computing the values returned from the parser ----- |
| 887 |
if [[ 1 -eq $P_HELP ]]; then |
| 888 |
help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}" |
| 889 |
help_draft |
| 890 |
help_name |
| 891 |
help_remarks |
| 892 |
help_rootid |
| 893 |
echo |
| 894 |
exit 0 |
| 895 |
fi |
| 896 |
|
| 897 |
# we do not want to write a logfile this time |
| 898 |
WRITE_LOG=0 |
| 899 |
call_make "profile" "$@" || exit_on_error "Profiling failed" |
| 900 |
call_make "$SUB_CMD" "$@" |
| 901 |
} |
| 902 |
|
| 903 |
########################################################################### |
| 904 |
# |
| 905 |
# VALIDATION |
| 906 |
# |
| 907 |
# Subcommand: validate |
| 908 |
# |
| 909 |
########################################################################### |
| 910 |
function validate { |
| 911 |
local SHORT_OPTS LONG_OPTS SUB_CMD |
| 912 |
SUB_CMD=$1 |
| 913 |
shift |
| 914 |
|
| 915 |
SHORT_OPTS="h" |
| 916 |
LONG_OPTS="help,norefcheck,not-validate-tables,remarks,validate-ids,validate-images" |
| 917 |
|
| 918 |
parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@" |
| 919 |
eval set -- "$P_REMAIN_ARGS" |
| 920 |
|
| 921 |
#------ Computing the values returned from the parser ----- |
| 922 |
if [[ 1 -eq $P_HELP ]]; then |
| 923 |
help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}" |
| 924 |
help_norefcheck |
| 925 |
help_not-validate-tables |
| 926 |
help_remarks |
| 927 |
help_validate-ids |
| 928 |
help_validate-images |
| 929 |
echo |
| 930 |
exit 0 |
| 931 |
fi |
| 932 |
|
| 933 |
# we do not want to write a logfile this time |
| 934 |
WRITE_LOG=0 |
| 935 |
call_make "$SUB_CMD" "$@" |
| 936 |
|
| 937 |
} |
| 938 |
|
| 939 |
########################################################################### |
| 940 |
# |
| 941 |
# FILELISTS |
| 942 |
# |
| 943 |
# Subcommands: list-files, list-srcfiles*, list-images-* |
| 944 |
# |
| 945 |
########################################################################### |
| 946 |
function filelists { |
| 947 |
local SHORT_OPTS LONG_OPTS SUB_CMD |
| 948 |
SUB_CMD=$1 |
| 949 |
shift |
| 950 |
|
| 951 |
SHORT_OPTS="h" |
| 952 |
LONG_OPTS="adoconly,help,imgonly,noadoc,nodc,noent,noimg,noxml,pretty,rootid:,xmlonly" |
| 953 |
|
| 954 |
parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@" |
| 955 |
eval set -- "$P_REMAIN_ARGS" |
| 956 |
|
| 957 |
#------ Computing the values returned from the parser ----- |
| 958 |
if [[ 1 -eq $P_HELP ]]; then |
| 959 |
help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}" |
| 960 |
help_help |
| 961 |
if [[ $SUB_CMD =~ list-srcfiles ]]; then |
| 962 |
help_adoconly |
| 963 |
help_imgonly |
| 964 |
help_noadoc |
| 965 |
help_nodc |
| 966 |
help_noent |
| 967 |
help_noimg |
| 968 |
help_noxml |
| 969 |
help_xmlonly |
| 970 |
fi |
| 971 |
[[ $SUB_CMD != list-file ]] && help_pretty |
| 972 |
help_rootid |
| 973 |
echo |
| 974 |
exit 0 |
| 975 |
fi |
| 976 |
|
| 977 |
# --imgonly and --xmlonly are shortcuts |
| 978 |
# |
| 979 |
if [[ 1 -eq $P_LIST_IMG_ONLY ]]; then |
| 980 |
export LIST_NODC=1 LIST_NOENT=1 LIST_NOXML=1 |
| 981 |
elif [[ 1 -eq $P_LIST_XML_ONLY ]]; then |
| 982 |
export LIST_NODC=1 LIST_NOENT=1 LIST_NOIMG=1 |
| 983 |
fi |
| 984 |
|
| 985 |
if [[ $SUB_CMD = list-file && -z $ROOTID ]]; then |
| 986 |
exit_on_error "You need to specify an ID with --rootid with the list-file command." |
| 987 |
fi |
| 988 |
|
| 989 |
# we do not want to write a logfile this time |
| 990 |
WRITE_LOG=0 |
| 991 |
call_make "$SUB_CMD" "$@" |
| 992 |
} |
| 993 |
|
| 994 |
########################################################################### |
| 995 |
# |
| 996 |
# SHOW NAMES |
| 997 |
# |
| 998 |
# function for all targets showing a filename or a directory |
| 999 |
# (pdf-name, htmlsingle-name, etc.) |
| 1000 |
# |
| 1001 |
########################################################################### |
| 1002 |
|
| 1003 |
function show_names { |
| 1004 |
local SHORT_OPTS LONG_OPTS SUB_CMD |
| 1005 |
SUB_CMD=$1 |
| 1006 |
shift |
| 1007 |
|
| 1008 |
SHORT_OPTS="h" |
| 1009 |
LONG_OPTS="cropmarks,draft,formatter:,grayscale,help,meta,name:,remarks,rootid:,single" |
| 1010 |
|
| 1011 |
parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@" |
| 1012 |
eval set -- "$P_REMAIN_ARGS" |
| 1013 |
|
| 1014 |
#------ Computing the values returned from the parser ----- |
| 1015 |
if [[ 1 -eq $P_HELP ]]; then |
| 1016 |
help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}" |
| 1017 |
[[ "pdf-name" = "$SUB_CMD" ]] && help_cropmarks |
| 1018 |
help_draft |
| 1019 |
[[ "pdf-name" = "$SUB_CMD" ]] && help_formatter |
| 1020 |
[[ "pdf-name" = "$SUB_CMD" ]] && help_grayscale_pdf |
| 1021 |
help_help |
| 1022 |
help_meta |
| 1023 |
help_name |
| 1024 |
help_remarks |
| 1025 |
help_rootid |
| 1026 |
[[ "html-dir-name" = "$SUB_CMD" ]] && help_single |
| 1027 |
echo |
| 1028 |
exit 0 |
| 1029 |
fi |
| 1030 |
|
| 1031 |
# we do not want to write a logfile this time |
| 1032 |
WRITE_LOG=0 |
| 1033 |
call_make "$SUB_CMD" "$@" |
| 1034 |
} |
| 1035 |
|
| 1036 |
########################################################################### |
| 1037 |
# |
| 1038 |
# Debugging function |
| 1039 |
# |
| 1040 |
# Subcommands: dapsenv, nothing, showvariable |
| 1041 |
# |
| 1042 |
########################################################################### |
| 1043 |
function debugging { |
| 1044 |
local SHORT_OPTS LONG_OPTS SUB_CMD |
| 1045 |
SUB_CMD=$1 |
| 1046 |
shift |
| 1047 |
|
| 1048 |
SHORT_OPTS="h" |
| 1049 |
LONG_OPTS="help,name:,rootid:,target:" |
| 1050 |
|
| 1051 |
parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@" |
| 1052 |
eval set -- "$P_REMAIN_ARGS" |
| 1053 |
|
| 1054 |
#------ Computing the values returned from the parser ----- |
| 1055 |
if [[ 1 -eq $P_HELP ]]; then |
| 1056 |
help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}" |
| 1057 |
help_help |
| 1058 |
help_name |
| 1059 |
help_rootid |
| 1060 |
help_target |
| 1061 |
echo |
| 1062 |
exit 0 |
| 1063 |
fi |
| 1064 |
|
| 1065 |
call_make "$SUB_CMD" "$@" |
| 1066 |
} |
| 1067 |
|
| 1068 |
########################################################################### |
| 1069 |
# |
| 1070 |
# MISC |
| 1071 |
# |
| 1072 |
# various functions |
| 1073 |
# |
| 1074 |
########################################################################### |
| 1075 |
|
| 1076 |
# call make directly |
| 1077 |
# for functions with no command line options |
| 1078 |
# do not write a log |
| 1079 |
function no_opts { |
| 1080 |
local CURR_DIR SHORT_OPTS LONG_OPTS SUB_CMD |
| 1081 |
local SUB_CMD=$1 |
| 1082 |
shift |
| 1083 |
|
| 1084 |
SHORT_OPTS="h" |
| 1085 |
LONG_OPTS="help" |
| 1086 |
|
| 1087 |
parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@" |
| 1088 |
eval set -- "$P_REMAIN_ARGS" |
| 1089 |
|
| 1090 |
#------ Computing the values returned from the parser ----- |
| 1091 |
if [[ 1 -eq $P_HELP ]]; then |
| 1092 |
help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}" "0" |
| 1093 |
exit 0 |
| 1094 |
fi |
| 1095 |
|
| 1096 |
WRITE_LOG=0 |
| 1097 |
if [[ $SUB_CMD =~ ^clean.* ]]; then |
| 1098 |
# |
| 1099 |
# Use the cd commands to avoid errors when running DAPS from |
| 1100 |
# one of the directories that get removed |
| 1101 |
# |
| 1102 |
CURR_DIR=$(pwd 2>/dev/null) |
| 1103 |
cd $DOC_DIR > /dev/null |
| 1104 |
call_make "$SUB_CMD" "$@" |
| 1105 |
[[ -d $CURR_DIR ]] && cd $CURR_DIR |
| 1106 |
else |
| 1107 |
call_make "$SUB_CMD" "$@" |
| 1108 |
fi |
| 1109 |
} |
| 1110 |
|
| 1111 |
# error message for deprecated targets |
| 1112 |
function deprecated { |
| 1113 |
local SUB_CMD=$1 |
| 1114 |
ccecho "error" "${HELP_SUBCOMMAND[$SUB_CMD]}" |
| 1115 |
exit 1 |
| 1116 |
} |
| 1117 |
|
| 1118 |
|
| 1119 |
# error message when specifying an invalid subcommand |
| 1120 |
function wrong_parameter { |
| 1121 |
local SUB_CMD=$1 |
| 1122 |
echo "Type '$ME $SUB_CMD help' to get a list of valid parameters" |
| 1123 |
exit 1; |
| 1124 |
} |
| 1125 |
|
| 1126 |
# needed by docmanager |
| 1127 |
function showenv { |
| 1128 |
echo "DOC_DIR=$DOC_DIR;DOCCONF=$DOCCONF" |
| 1129 |
exit 0 |
| 1130 |
} |
| 1131 |
|
| 1132 |
########################################################################### |
| 1133 |
# |
| 1134 |
# HELP |
| 1135 |
# |
| 1136 |
# There are a lot of options, several functions have in common. |
| 1137 |
# In order to not have to write the same text again and again, we |
| 1138 |
# provide a help function for each option |
| 1139 |
# |
| 1140 |
########################################################################### |
| 1141 |
|
| 1142 |
# first line of help |
| 1143 |
# |
| 1144 |
function help_scmd_head { |
| 1145 |
echo -e "$ME [--global-options] $1 [options] |
| 1146 |
|
| 1147 |
$2\n" |
| 1148 |
|
| 1149 |
[[ 0 -ne $3 ]] && echo -e " Command options:" |
| 1150 |
} |
| 1151 |
|
| 1152 |
function help_adoconly { |
| 1153 |
cat <<EOF |
| 1154 |
--adoconly Only list AsciiDoc and include files. |
| 1155 |
Shortcut for --nodc --noent --noimg. |
| 1156 |
EOF |
| 1157 |
} |
| 1158 |
function help_check { |
| 1159 |
cat <<EOF |
| 1160 |
--check Validate the resulting document. |
| 1161 |
Implies a verbosity level of at least 1. |
| 1162 |
Default: unset |
| 1163 |
EOF |
| 1164 |
} |
| 1165 |
function help_clean { |
| 1166 |
cat <<EOF |
| 1167 |
--clean Clean up the result directory (delete all files |
| 1168 |
and subdirectories) before building the document. |
| 1169 |
Default: unset |
| 1170 |
EOF |
| 1171 |
} |
| 1172 |
function help_color { |
| 1173 |
cat <<EOF |
| 1174 |
--color Only generate color images. |
| 1175 |
Default: off |
| 1176 |
EOF |
| 1177 |
} |
| 1178 |
function help_compact { |
| 1179 |
cat <<EOF |
| 1180 |
--compact Print the filelist on a single line. |
| 1181 |
Ignored when -s|--show is set. |
| 1182 |
Default: off |
| 1183 |
EOF |
| 1184 |
} |
| 1185 |
function help_cropmarks { |
| 1186 |
cat <<EOF |
| 1187 |
--cropmarks Add cropmarks to the PDF. Only available for |
| 1188 |
the XEP formatter, FOP currently does not support |
| 1189 |
cropmarks. |
| 1190 |
Ignored when FOP is used. |
| 1191 |
Default: off |
| 1192 |
EOF |
| 1193 |
} |
| 1194 |
function help_css { |
| 1195 |
cat <<EOF |
| 1196 |
--css=filename, Specify a path to a css file. |
| 1197 |
--css=none The special string \"none\" forces DAPS to use |
| 1198 |
no css, even when configured elsewhere |
| 1199 |
(e.g. in a config file). |
| 1200 |
Default: unset |
| 1201 |
EOF |
| 1202 |
} |
| 1203 |
function help_css_epub { |
| 1204 |
cat <<EOF |
| 1205 |
--css=filename Specify a path to a css file. |
| 1206 |
Default: unset |
| 1207 |
EOF |
| 1208 |
} |
| 1209 |
function help_def-file { |
| 1210 |
cat <<EOF |
| 1211 |
--def-file=FILE Specify a DEF-* file containing build |
| 1212 |
information |
| 1213 |
EOF |
| 1214 |
} |
| 1215 |
function help_desktopfiles { |
| 1216 |
cat <<EOF |
| 1217 |
--desktopfiles Generate .desktop files. |
| 1218 |
Default: off |
| 1219 |
EOF |
| 1220 |
} |
| 1221 |
function help_documentfiles { |
| 1222 |
cat <<EOF |
| 1223 |
--documentfiles Generate .document files. |
| 1224 |
Default: off |
| 1225 |
EOF |
| 1226 |
} |
| 1227 |
function help_draft { |
| 1228 |
cat <<EOF |
| 1229 |
--draft Add a 'DRAFT' watermark to all pages of the book |
| 1230 |
Default: off |
| 1231 |
EOF |
| 1232 |
} |
| 1233 |
function help_epub3 { |
| 1234 |
cat <<EOF |
| 1235 |
--epub3 Generate ePUB version 3 eBooks. |
| 1236 |
Default: ePUB version 2 |
| 1237 |
EOF |
| 1238 |
} |
| 1239 |
function help_export-dir { |
| 1240 |
cat <<EOF |
| 1241 |
--export-dir=DIRECTORY Specify a directory where to copy the results |
| 1242 |
of the $TARGET command. The directory will be |
| 1243 |
created if it does not exist. |
| 1244 |
Default: <BUILD_DIRECTORY>/locdrop |
| 1245 |
EOF |
| 1246 |
} |
| 1247 |
function help_extra-dict { |
| 1248 |
cat <<EOF |
| 1249 |
--extra-dict=filename Specify a path to an additional custom |
| 1250 |
dictionary. |
| 1251 |
Default: unset |
| 1252 |
EOF |
| 1253 |
} |
| 1254 |
function help_file { |
| 1255 |
cat <<EOF |
| 1256 |
--file=FILE Specify the name of an input file |
| 1257 |
EOF |
| 1258 |
} |
| 1259 |
function help_formatter { |
| 1260 |
cat <<EOF |
| 1261 |
--formatter=FORMATTER Specify the PDF formatter to be used. Currently |
| 1262 |
'xep' or 'fop' are supported. |
| 1263 |
Default: 'fop' |
| 1264 |
EOF |
| 1265 |
} |
| 1266 |
function help_gen { |
| 1267 |
cat <<EOF |
| 1268 |
--gen Do all image conversions (images/gen) but |
| 1269 |
do not generate or link the images to |
| 1270 |
images/color or images/grayscale. |
| 1271 |
Default: unset |
| 1272 |
EOF |
| 1273 |
} |
| 1274 |
function help_grayscale_images { |
| 1275 |
cat <<EOF |
| 1276 |
--grayscale Only generate grayscale images. |
| 1277 |
Default: off |
| 1278 |
EOF |
| 1279 |
} |
| 1280 |
function help_grayscale_pdf { |
| 1281 |
cat <<EOF |
| 1282 |
--grayscale Generate a grayscale PDF for printing. |
| 1283 |
Default: off |
| 1284 |
EOF |
| 1285 |
} |
| 1286 |
function help_help { |
| 1287 |
cat <<EOF |
| 1288 |
--help, -h Print this help text |
| 1289 |
EOF |
| 1290 |
} |
| 1291 |
function help_html5 { |
| 1292 |
cat <<EOF |
| 1293 |
--html5 HTML builds are generated as XHTML files. |
| 1294 |
Force HTML 5 with this switch. |
| 1295 |
Default: unset |
| 1296 |
EOF |
| 1297 |
} |
| 1298 |
function help_ignore-styleroot { |
| 1299 |
cat <<EOF |
| 1300 |
--ignore-styleroot Ignore all stylesheet assignments (e.g. the |
| 1301 |
DC file) and use the original DocBook stylesheets |
| 1302 |
instead. Use this option if your custom |
| 1303 |
stylesheets produce text output you are not |
| 1304 |
satisfied with. |
| 1305 |
Default: unset |
| 1306 |
EOF |
| 1307 |
} |
| 1308 |
function help_imgonly { |
| 1309 |
cat <<EOF |
| 1310 |
--imgonly Only list images files. |
| 1311 |
Shortcut for --nodc --noent --noxml|--noadoc. |
| 1312 |
EOF |
| 1313 |
} |
| 1314 |
function help_lang { |
| 1315 |
cat <<EOF |
| 1316 |
--lang Specify a language to use for spellchecking. |
| 1317 |
See \"man aspell \" for details. |
| 1318 |
Default: en_US |
| 1319 |
EOF |
| 1320 |
} |
| 1321 |
function help_lean { |
| 1322 |
cat <<EOF |
| 1323 |
--lean Create a lean PDF with reduced graphics |
| 1324 |
quality and a small file size (e.g. for |
| 1325 |
sharing via email). This PDF will be created |
| 1326 |
in addition to the regular one. |
| 1327 |
Default: off |
| 1328 |
EOF |
| 1329 |
} |
| 1330 |
function help_list { |
| 1331 |
cat <<EOF |
| 1332 |
--list Dumps a sorted list of misspelled words to |
| 1333 |
standard output instead of starting the |
| 1334 |
interactive spellchecker. |
| 1335 |
EOF |
| 1336 |
} |
| 1337 |
function help_locdrop { |
| 1338 |
cat <<EOF |
| 1339 |
--locdrop Use this option to create a source tarball |
| 1340 |
from a previous locdrop after translation. |
| 1341 |
If set, will include the files manifest_*.txt |
| 1342 |
in the source tarball. |
| 1343 |
Default: off |
| 1344 |
EOF |
| 1345 |
} |
| 1346 |
function help_meta { |
| 1347 |
cat <<EOF |
| 1348 |
--meta If set, prints additional status information |
| 1349 |
(filename, maintainer and status) for each file. |
| 1350 |
Implies draft mode. |
| 1351 |
Default: off |
| 1352 |
Does not work with AsciiDoc sources |
| 1353 |
EOF |
| 1354 |
} |
| 1355 |
function help_modified { |
| 1356 |
cat <<EOF |
| 1357 |
--modified Print the image modification time. |
| 1358 |
Ignored when --compact is set. |
| 1359 |
Default: off |
| 1360 |
EOF |
| 1361 |
} |
| 1362 |
function help_name { |
| 1363 |
cat <<EOF |
| 1364 |
--name=BOOKNAME File and directory names for generated content |
| 1365 |
are derived from BOOKNAME. |
| 1366 |
Default: generated by stripping 'DC-' from the |
| 1367 |
doc config filename |
| 1368 |
EOF |
| 1369 |
} |
| 1370 |
function help_noadoc { |
| 1371 |
cat <<EOF |
| 1372 |
--noxml Exclude AsciiDoc and include files from list. |
| 1373 |
Default: unset |
| 1374 |
EOF |
| 1375 |
} |
| 1376 |
function help_nodc { |
| 1377 |
cat <<EOF |
| 1378 |
--nodc Exclude DC-file from list. |
| 1379 |
Default: unset |
| 1380 |
EOF |
| 1381 |
} |
| 1382 |
function help_noent { |
| 1383 |
cat <<EOF |
| 1384 |
--noent Exclude Entity files from list. |
| 1385 |
Default: unset |
| 1386 |
EOF |
| 1387 |
} |
| 1388 |
function help_nogzip { |
| 1389 |
cat <<EOF |
| 1390 |
--nogzip If specified, man pages will not be compressed |
| 1391 |
with gzip. |
| 1392 |
Default: unset |
| 1393 |
EOF |
| 1394 |
} |
| 1395 |
function help_noimg { |
| 1396 |
cat <<EOF |
| 1397 |
--noimg Exclude images from list. |
| 1398 |
Default: unset |
| 1399 |
EOF |
| 1400 |
} |
| 1401 |
function help_nohelp { |
| 1402 |
cat <<EOF |
| 1403 |
|
| 1404 |
No further help for subcommand \"$1\" available. |
| 1405 |
EOF |
| 1406 |
} |
| 1407 |
function help_nopdf { |
| 1408 |
cat <<EOF |
| 1409 |
--nopdf Deactivates creating the color-pdf. Useful when |
| 1410 |
"locdropping" a complete set where you |
| 1411 |
want to deliver separate PDFs for each book |
| 1412 |
rather than one huge PDF for the whole set. |
| 1413 |
Default: PDF is created |
| 1414 |
EOF |
| 1415 |
} |
| 1416 |
function help_norefcheck { |
| 1417 |
cat <<EOF |
| 1418 |
--norefcheck Disables checking internal links |
| 1419 |
(ID/IDREF/IDREFS) and thus allows to build |
| 1420 |
or validate with e.g. xref-links pointing |
| 1421 |
to non-existing IDs. |
| 1422 |
This option only affects DocBook 5 sources and is |
| 1423 |
ignored when processing DocBook 4. |
| 1424 |
Default: unset |
| 1425 |
EOF |
| 1426 |
} |
| 1427 |
function help_nosearch { |
| 1428 |
cat <<EOF |
| 1429 |
--nosearch Deactivates creating the search tab in webhtml |
| 1430 |
builds. |
| 1431 |
Default: enabled |
| 1432 |
EOF |
| 1433 |
} |
| 1434 |
function help_nostatic { |
| 1435 |
cat <<EOF |
| 1436 |
--nostatic Normally images and css files in HTML builds |
| 1437 |
are copied from elsewhere in the file system. |
| 1438 |
Use this option to link these files in order |
| 1439 |
to save disk space. Note that this eventually |
| 1440 |
produces nested links which may cause errors |
| 1441 |
with CSS and Javascript. |
| 1442 |
EOF |
| 1443 |
} |
| 1444 |
function help_not-validate-tables { |
| 1445 |
cat <<EOF |
| 1446 |
--not-validate-tables Disable checking for tables that contain |
| 1447 |
structural errors (e.g. missing cells). |
| 1448 |
Default: unset (table check is performed) |
| 1449 |
EOF |
| 1450 |
} |
| 1451 |
function help_novalid { |
| 1452 |
cat <<EOF |
| 1453 |
--novalid Do not perform a validation check on the |
| 1454 |
(profiled) sources. However, they need to be |
| 1455 |
well-formed. |
| 1456 |
Implies a validation check on the resulting |
| 1457 |
bigfile. |
| 1458 |
Default: unset |
| 1459 |
EOF |
| 1460 |
} |
| 1461 |
function help_noxml { |
| 1462 |
cat <<EOF |
| 1463 |
--noxml Exclude XML files from list. |
| 1464 |
Default: unset |
| 1465 |
EOF |
| 1466 |
} |
| 1467 |
function help_online { |
| 1468 |
cat <<EOF |
| 1469 |
--online Only generate images used for HTML builds. |
| 1470 |
Default: off |
| 1471 |
EOF |
| 1472 |
} |
| 1473 |
function help_optipng { |
| 1474 |
cat <<EOF |
| 1475 |
--optipng Optimize PNG images by reducing the color |
| 1476 |
palette (using optipng), Modifies the original |
| 1477 |
sources! |
| 1478 |
Default: off |
| 1479 |
EOF |
| 1480 |
} |
| 1481 |
function help_pagefiles { |
| 1482 |
cat <<EOF |
| 1483 |
--pagefiles Generate .page files. |
| 1484 |
Default: off |
| 1485 |
EOF |
| 1486 |
} |
| 1487 |
function help_param { |
| 1488 |
cat <<EOF |
| 1489 |
--param="KEY=VALUE" Add an xslt processor parameter. |
| 1490 |
Useful to temporarily overwrite/set style sheet |
| 1491 |
parameters such as margins. |
| 1492 |
This parameter can be specified multiple times. |
| 1493 |
Default: unset |
| 1494 |
EOF |
| 1495 |
} |
| 1496 |
function help_pretty { |
| 1497 |
cat <<EOF |
| 1498 |
--pretty Pretty print file lists (one filename per line) |
| 1499 |
EOF |
| 1500 |
} |
| 1501 |
function help_remarks { |
| 1502 |
cat <<EOF |
| 1503 |
--remarks Include remarks (<remark>...</remark>) in book |
| 1504 |
Implies draft mode. |
| 1505 |
Default: off |
| 1506 |
EOF |
| 1507 |
} |
| 1508 |
function help_rootid { |
| 1509 |
cat <<EOF |
| 1510 |
--rootid=ID Specify a ROOTID to build only parts of a book |
| 1511 |
(parts or chapters). Default: Usually set |
| 1512 |
in the DC-file; if not set the complete set |
| 1513 |
defined in \$MAIN will be built |
| 1514 |
Does not work with AsciiDoc sources |
| 1515 |
EOF |
| 1516 |
} |
| 1517 |
function help_set-date { |
| 1518 |
cat <<EOF |
| 1519 |
--set-date=YYYY/MM/DD Set a publication date. If not set, the current |
| 1520 |
date will automatically be chosen. |
| 1521 |
Default: current date |
| 1522 |
EOF |
| 1523 |
} |
| 1524 |
function help_show_images { |
| 1525 |
cat <<EOF |
| 1526 |
--show Show images with an image viewer that either |
| 1527 |
has been specified with --viewer or by setting |
| 1528 |
IMG_VIEWER in the config file |
| 1529 |
Default: off |
| 1530 |
EOF |
| 1531 |
} |
| 1532 |
function help_show_check { |
| 1533 |
cat <<EOF |
| 1534 |
--show Show the result of the check command |
| 1535 |
in a browser. Uses \$BROWSER if defined, |
| 1536 |
otherwise xdg-open. |
| 1537 |
Default: off |
| 1538 |
EOF |
| 1539 |
} |
| 1540 |
function help_single { |
| 1541 |
cat <<EOF |
| 1542 |
--single Creates a single file HTML output (as opposed to |
| 1543 |
the default, which generates chunked HTML, |
| 1544 |
consisting of several HTML pages. |
| 1545 |
Default: off |
| 1546 |
EOF |
| 1547 |
} |
| 1548 |
function help_spellchecker { |
| 1549 |
cat <<EOF |
| 1550 |
--spell-checker Specify the name of the spell checking command, |
| 1551 |
such as 'aspell' or 'hunspell'. |
| 1552 |
DEFAULT: aspell |
| 1553 |
EOF |
| 1554 |
} |
| 1555 |
function help_statdir { |
| 1556 |
cat <<EOF |
| 1557 |
--statdir=DIRECTORY Specify a DIRECTORY containing resource files |
| 1558 |
(CSS, images, Javascript etc.). |
| 1559 |
DEFAULT: \$STYLEROOT/static |
| 1560 |
EOF |
| 1561 |
} |
| 1562 |
function help_stringparam { |
| 1563 |
cat <<EOF |
| 1564 |
--stringparam="KEY=VALUE" Add an xslt processor parameter. |
| 1565 |
Useful to temporarily overwrite/set style sheet |
| 1566 |
parameters such as margins. |
| 1567 |
This parameter can be specified multiple times. |
| 1568 |
Default: unset |
| 1569 |
Does not work with AsciiDoc sources |
| 1570 |
EOF |
| 1571 |
} |
| 1572 |
function help_subdirs { |
| 1573 |
cat <<EOF |
| 1574 |
--subdirs Man pages are created in a man/ directory. |
| 1575 |
To also enable the subdirectories man1/, man2/, |
| 1576 |
etc., specify this parameter. |
| 1577 |
Default: off |
| 1578 |
EOF |
| 1579 |
} |
| 1580 |
function help_target { |
| 1581 |
cat <<EOF |
| 1582 |
--target=TARGET Specify a potential target (such as pdf) |
| 1583 |
to retrieve correct values for target-specific |
| 1584 |
values. |
| 1585 |
Default: same as daps subcommand |
| 1586 |
EOF |
| 1587 |
} |
| 1588 |
function help_validate-ids { |
| 1589 |
cat <<EOF |
| 1590 |
--validate-ids Also check IDs to include no other |
| 1591 |
characters than '[-a-zA-Z0-9]. |
| 1592 |
Default: unset |
| 1593 |
EOF |
| 1594 |
} |
| 1595 |
function help_validate-images { |
| 1596 |
cat <<EOF |
| 1597 |
--validate-images Also check for missing and duplicated images. |
| 1598 |
Missing images cause an error, duplicated |
| 1599 |
imnages a warning only. |
| 1600 |
Default: unset |
| 1601 |
EOF |
| 1602 |
} |
| 1603 |
function help_viewer { |
| 1604 |
cat <<EOF |
| 1605 |
--viewer=VIEWER Image viewer to be used. |
| 1606 |
Default: IMG_VIEWER setting from config file |
| 1607 |
EOF |
| 1608 |
} |
| 1609 |
function help_xmlonly { |
| 1610 |
cat <<EOF |
| 1611 |
--xmlonly Only list XML files. |
| 1612 |
Shortcut for --nodc --noent --noimg. |
| 1613 |
EOF |
| 1614 |
} |