2015-05-21 16:31:43 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
inc_makerules=true
|
2015-05-24 23:18:52 +00:00
|
|
|
[ -z "$inc_misc" ] && . "$basedir/build/misc.sh"
|
2015-05-21 16:31:43 +00:00
|
|
|
[ -z "$inc_translations" ] && . "$basedir/build/translations.sh"
|
|
|
|
|
[ -z "$inc_filenames" ] && . "$basedir/build/filenames.sh"
|
|
|
|
|
[ -z "$inc_fundraising" ] && . "$basedir/build/fundraising.sh"
|
|
|
|
|
[ -z "$inc_languages" ] && . "$basedir/build/languages.sh"
|
|
|
|
|
[ -z "$inc_sources" ] && . "$basedir/build/sources.sh"
|
|
|
|
|
|
2015-05-28 14:55:27 +00:00
|
|
|
sourcefind() {
|
|
|
|
|
find "$input" -name .svn -prune -o -type f "$@" -printf '%P\n'
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-29 15:55:00 +00:00
|
|
|
mio(){
|
|
|
|
|
# make input/output abstraction, produce reusable makefiles
|
|
|
|
|
# by replacing in and out pathes with make variables.
|
|
|
|
|
for each in "$@"; do
|
2015-05-30 14:04:30 +00:00
|
|
|
case "$each" in
|
|
|
|
|
"$input"/*) echo "\${INPUTDIR}/${each#$input/}" ;;
|
|
|
|
|
"$output"/*) echo "\${OUTPUTDIR}/${each#$output/}" ;;
|
|
|
|
|
*) echo "$each" ;;
|
|
|
|
|
esac
|
2015-05-29 15:55:00 +00:00
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 16:31:43 +00:00
|
|
|
mes(){
|
|
|
|
|
# make escape... escape a filename for make syntax
|
|
|
|
|
# possibly not complete
|
2015-05-29 15:55:00 +00:00
|
|
|
mio "$@" \
|
2015-05-21 16:31:43 +00:00
|
|
|
| sed -r 's;([ #]);\\\1;g' \
|
|
|
|
|
| tr '\n' ' '
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glob_maker(){
|
2015-05-29 15:55:00 +00:00
|
|
|
# issue make rules for preglobbed sources files
|
2015-06-01 17:23:28 +00:00
|
|
|
sourcesfile="$1"
|
2015-05-21 16:31:43 +00:00
|
|
|
|
2015-05-29 15:55:00 +00:00
|
|
|
filedir="\${INPUTDIR}/$(dirname "$sourcesfile")"
|
2015-05-21 16:31:43 +00:00
|
|
|
shortbase="$(basename "$sourcesfile" |sed -r 's;\.sources$;;')"
|
2015-06-01 19:27:36 +00:00
|
|
|
sourceglobfile="${filedir%/.}/._._${shortbase}.sourceglobs"
|
2015-05-21 16:31:43 +00:00
|
|
|
|
|
|
|
|
cat <<MakeEND
|
2015-05-29 15:55:00 +00:00
|
|
|
$(mes "$sourceglobfile"): $(mes $(all_sources "$input/$sourcesfile"))
|
|
|
|
|
\${PGLOBBER} \${PROCFLAGS} sourceglobs "\${INPUTDIR}/$sourcesfile" >"$sourceglobfile"
|
2015-05-21 16:31:43 +00:00
|
|
|
MakeEND
|
|
|
|
|
|
|
|
|
|
for lang in $(get_languages); do
|
2015-06-01 19:27:36 +00:00
|
|
|
globfile="${filedir%/.}/._._${shortbase}.${lang}.sourceglobs"
|
2015-05-21 16:31:43 +00:00
|
|
|
cat <<MakeEND
|
|
|
|
|
$(mes "$globfile"): $(mes "$sourceglobfile")
|
2015-05-29 15:55:00 +00:00
|
|
|
\${PGLOBBER} \${PROCFLAGS} cast_globfile "$sourceglobfile" "$lang" "$globfile"
|
2015-05-21 16:31:43 +00:00
|
|
|
MakeEND
|
|
|
|
|
done
|
|
|
|
|
}
|
2015-05-31 21:09:48 +00:00
|
|
|
|
2015-05-28 14:55:27 +00:00
|
|
|
glob_makers(){
|
2015-05-31 21:09:48 +00:00
|
|
|
# generate make rules for globbing all .sources files
|
|
|
|
|
# within input tree
|
2015-05-28 14:55:27 +00:00
|
|
|
sourcefind -name '*.sources' \
|
|
|
|
|
| while read filepath; do
|
2015-05-29 15:55:00 +00:00
|
|
|
glob_maker "$filepath"
|
2015-05-28 14:55:27 +00:00
|
|
|
done
|
|
|
|
|
}
|
2015-05-21 16:31:43 +00:00
|
|
|
|
2015-05-31 21:09:48 +00:00
|
|
|
glob_additions(){
|
|
|
|
|
printf "$input/%s\n" "$@" \
|
|
|
|
|
| egrep '.+\.sources$' \
|
|
|
|
|
| xargs realpath \
|
|
|
|
|
| while read addition; do
|
|
|
|
|
glob_maker "${addition#$input/}"
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 16:31:43 +00:00
|
|
|
xhtml_maker(){
|
|
|
|
|
# generate make rules for building html files out of xhtml
|
|
|
|
|
# account for included xml files and xsl rules
|
|
|
|
|
|
2015-05-29 15:55:00 +00:00
|
|
|
shortname="$input/$1"
|
2015-06-04 17:21:37 +00:00
|
|
|
outpath="\${OUTPUTDIR}/${2}"
|
|
|
|
|
outpath="${outpath%/.}"
|
2015-05-21 16:31:43 +00:00
|
|
|
|
|
|
|
|
textsen="$(get_textsfile "en")"
|
|
|
|
|
menufile="$basedir/tools/menu-global.xml"
|
|
|
|
|
filedir="$(dirname "$shortname")"
|
|
|
|
|
shortbase="$(basename "$shortname")"
|
|
|
|
|
processor="$(get_processor "$shortname")"
|
|
|
|
|
|
|
|
|
|
[ -f "$shortname".rss.xsl ] && bool_rss=true || bool_rss=false
|
|
|
|
|
[ -f "$shortname".ics.xsl ] && bool_ics=true || bool_ics=false
|
|
|
|
|
|
|
|
|
|
olang="$(echo "${shortname}".[a-z][a-z].xhtml "${shortname}".[e]n.xhtml |sed -rn 's;^.*\.([a-z]{2})\.xhtml.*$;\1;p')"
|
|
|
|
|
|
|
|
|
|
if [ "${shortbase}" = "$(basename "$filedir")" ] && \
|
|
|
|
|
[ ! -f "${filedir}/index.${olang}.xhtml" ]; then
|
|
|
|
|
bool_indexname=true
|
|
|
|
|
else
|
|
|
|
|
bool_indexname=false
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
[ -f "${shortname}.sources" ] && bool_sourceinc=true || bool_sourceinc=false
|
|
|
|
|
|
|
|
|
|
# For speed considerations: avoid all disk I/O in this loop
|
|
|
|
|
for lang in $(get_languages); do
|
|
|
|
|
infile="${shortname}.${lang}.xhtml"
|
2015-05-29 15:55:00 +00:00
|
|
|
[ -e "$infile" ] && depfile="$infile" || depfile="${shortname}.${olang}.xhtml"
|
2015-05-21 16:31:43 +00:00
|
|
|
|
2015-05-29 15:55:00 +00:00
|
|
|
infile="$(mio "$infile")"
|
2015-05-21 16:31:43 +00:00
|
|
|
outbase="${shortbase}.${lang}.html"
|
|
|
|
|
outfile="${outpath}/${outbase}"
|
|
|
|
|
outlink="${outpath}/${shortbase}.html.$lang"
|
|
|
|
|
rssfile="${outpath}/${shortbase}.${lang}.rss"
|
|
|
|
|
icsfile="${outpath}/${shortbase}.${lang}.ics"
|
|
|
|
|
|
|
|
|
|
textsfile="$(get_textsfile "$lang")"
|
|
|
|
|
fundraisingfile="$(get_fundraisingfile "$lang")"
|
2015-06-01 19:27:36 +00:00
|
|
|
$bool_sourceinc && sourceglobs="${filedir#./}/._._${shortbase}.${lang}.sourceglobs" || unset sourceglobs
|
2015-05-21 16:31:43 +00:00
|
|
|
|
|
|
|
|
cat <<MakeEND
|
|
|
|
|
all: $(mes "$outfile" "$outlink")
|
|
|
|
|
$(mes "$outfile"): $(mes "$depfile" "$processor" "$textsen" "$textsfile" "$fundraisingfile" "$menufile" "$sourceglobs")
|
2015-05-31 21:09:48 +00:00
|
|
|
\${PROCESSOR} \${PROCFLAGS} process_file "${infile}" "$(mio "$processor")" "$olang" >"$outfile"
|
2015-05-21 16:31:43 +00:00
|
|
|
$(mes "$outlink"):
|
|
|
|
|
ln -sf "${outbase}" "${outlink}"
|
|
|
|
|
MakeEND
|
|
|
|
|
$bool_rss && cat<<MakeEND
|
|
|
|
|
all: $(mes "$rssfile")
|
|
|
|
|
$(mes "$rssfile"): $(mes "$depfile" "${shortname}.rss.xsl" "$textsen" "$textsfile" "$fundraisingfile" "$menufile" "$sourceglobs")
|
2015-05-31 21:09:48 +00:00
|
|
|
\${PROCESSOR} \${PROCFLAGS} process_file "${infile}" "$(mio "${shortname}.rss.xsl")" "$olang" >"$rssfile"
|
2015-05-21 16:31:43 +00:00
|
|
|
MakeEND
|
|
|
|
|
$bool_ics && cat<<MakeEND
|
|
|
|
|
all: $(mes "$icsfile")
|
|
|
|
|
$(mes "$icsfile"): $(mes "$depfile" "${shortname}.ics.xsl" "$textsen" "$textsfile" "$fundraisingfile" "$menufile" "$sourceglobs")
|
2015-05-31 21:09:48 +00:00
|
|
|
\${PROCESSOR} \${PROCFLAGS} process_file "${infile}" "$(mio "${shortname}.ics.xsl")" "$olang" >"$icsfile"
|
2015-05-21 16:31:43 +00:00
|
|
|
MakeEND
|
|
|
|
|
$bool_indexname && cat <<MakeEND
|
|
|
|
|
all: $(mes "$outpath/index.${lang}.html" "$outpath/index.html.$lang")
|
|
|
|
|
$(mes "$outpath/index.${lang}.html"):
|
|
|
|
|
ln -sf "$outbase" "$outpath/index.${lang}.html"
|
|
|
|
|
$(mes "$outpath/index.html.$lang"):
|
|
|
|
|
ln -sf "$outbase" "$outpath/index.html.$lang"
|
|
|
|
|
MakeEND
|
|
|
|
|
done
|
|
|
|
|
}
|
2015-05-31 21:09:48 +00:00
|
|
|
|
2015-05-28 14:55:27 +00:00
|
|
|
xhtml_makers(){
|
2015-05-31 21:09:48 +00:00
|
|
|
# generate make rules concerning all .xhtml files in source tree
|
2015-05-28 14:55:27 +00:00
|
|
|
sourcefind -name '*.[a-z][a-z].xhtml' \
|
2015-05-31 21:09:48 +00:00
|
|
|
| sed -r 's;\.[a-z][a-z]\.xhtml$;;' \
|
2015-05-28 14:55:27 +00:00
|
|
|
| sort -u \
|
|
|
|
|
| while read shortpath; do
|
2015-05-29 15:55:00 +00:00
|
|
|
xhtml_maker "$shortpath" "$(dirname "$shortpath")"
|
2015-05-28 14:55:27 +00:00
|
|
|
done
|
|
|
|
|
}
|
2015-05-21 16:31:43 +00:00
|
|
|
|
2015-05-31 21:09:48 +00:00
|
|
|
xhtml_additions(){
|
|
|
|
|
printf "$input/%s\n" "$@" \
|
|
|
|
|
| sed -rn 's;\.[a-z][a-z]\.xhtml$;;p' \
|
|
|
|
|
| sort -u \
|
|
|
|
|
| xargs realpath \
|
|
|
|
|
| while read addition; do
|
|
|
|
|
xhtml_maker "${addition#$input/}" "$(dirname "${addition#$input/}")"
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 16:31:43 +00:00
|
|
|
copy_maker(){
|
|
|
|
|
# generate make rule for copying a plain file
|
2015-05-29 15:55:00 +00:00
|
|
|
infile="\${INPUTDIR}/$1"
|
2015-06-04 17:21:37 +00:00
|
|
|
outpath="\${OUTPUTDIR}/${2}"
|
|
|
|
|
outpath="${outpath%/.}"
|
2015-05-21 16:31:43 +00:00
|
|
|
outfile="$outpath/$(basename "$infile")"
|
2015-05-29 15:55:00 +00:00
|
|
|
|
2015-05-21 16:31:43 +00:00
|
|
|
cat <<MakeEND
|
|
|
|
|
all: $(mes "$outfile")
|
|
|
|
|
$(mes "$outfile"): $(mes "$infile")
|
|
|
|
|
cp "$infile" "$outfile"
|
|
|
|
|
MakeEND
|
|
|
|
|
}
|
2015-05-31 21:09:48 +00:00
|
|
|
|
2015-05-28 14:55:27 +00:00
|
|
|
copy_makers(){
|
2015-05-31 21:09:48 +00:00
|
|
|
# generate copy rules for entire input tree
|
2015-05-28 14:55:27 +00:00
|
|
|
sourcefind \! -name 'Makefile' \! -name '*.sourceglobs' \! -name '*.sources' \
|
|
|
|
|
\! -name '*.xhtml' \! -name '*.xml' \! -name '*.xsl' \
|
|
|
|
|
| while read filepath; do
|
2015-05-29 15:55:00 +00:00
|
|
|
copy_maker "$filepath" "$(dirname "$filepath")"
|
2015-05-28 14:55:27 +00:00
|
|
|
done
|
|
|
|
|
}
|
2015-05-21 16:31:43 +00:00
|
|
|
|
2015-05-31 21:09:48 +00:00
|
|
|
copy_additions(){
|
|
|
|
|
printf "$input/%s\n" "$@" \
|
|
|
|
|
| egrep -v '.+(\.sources|\.sourceglobs|\.xhtml|\.xml|\.xsl|/Makefile|/)$' \
|
|
|
|
|
| xargs realpath \
|
|
|
|
|
| while read addition; do
|
|
|
|
|
copy_maker "${addition#$input/}" "$(dirname "${addition#$input/}")"
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 16:31:43 +00:00
|
|
|
xslt_dependencies(){
|
2015-05-31 21:09:48 +00:00
|
|
|
# list referenced xsl files for a given xsl file
|
|
|
|
|
# *not* recursive since Make will handle recursive
|
|
|
|
|
# dependency resolution
|
2015-05-21 16:31:43 +00:00
|
|
|
file="$1"
|
|
|
|
|
|
|
|
|
|
cat "$file" \
|
2015-05-29 15:55:00 +00:00
|
|
|
| tr '\n\t' ' ' \
|
2015-05-21 16:31:43 +00:00
|
|
|
| sed -r 's;(<xsl:(include|import)[^>]*>);\n\1\n;g' \
|
2015-05-29 15:55:00 +00:00
|
|
|
| sed -nr '/<xsl:(include|import)[^>]*>/s;^.*href *= *"([^"]*)".*$;\1;gp'
|
2015-05-21 16:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xslt_maker(){
|
|
|
|
|
# find external references in a xsl file and generate
|
|
|
|
|
# Make dependencies accordingly
|
|
|
|
|
|
2015-05-29 15:55:00 +00:00
|
|
|
file="$input/$1"
|
2015-05-21 16:31:43 +00:00
|
|
|
dir="$(dirname "$file")"
|
|
|
|
|
|
2015-06-01 00:01:37 +00:00
|
|
|
deps="$( xslt_dependencies "$file" |xargs -I'{}' realpath "$dir/{}" )"
|
2015-05-21 16:31:43 +00:00
|
|
|
cat <<MakeEND
|
2015-05-29 15:55:00 +00:00
|
|
|
$(mes "$file"): $(mes $deps)
|
|
|
|
|
touch "$(mio "$file")"
|
2015-05-21 16:31:43 +00:00
|
|
|
MakeEND
|
|
|
|
|
}
|
2015-05-31 21:09:48 +00:00
|
|
|
|
2015-05-28 14:55:27 +00:00
|
|
|
xslt_makers(){
|
2015-05-31 21:09:48 +00:00
|
|
|
# generate make dependencies for all .xsl files in input tree
|
2015-05-28 14:55:27 +00:00
|
|
|
sourcefind -name '*.xsl' \
|
|
|
|
|
| while read filepath; do
|
2015-05-29 15:55:00 +00:00
|
|
|
xslt_maker "$filepath"
|
2015-05-28 14:55:27 +00:00
|
|
|
done
|
|
|
|
|
}
|
2015-05-21 16:31:43 +00:00
|
|
|
|
2015-05-31 21:09:48 +00:00
|
|
|
xslt_additions(){
|
|
|
|
|
printf "$input/%s\n" "$@" \
|
|
|
|
|
| egrep '.+\.xsl$' \
|
|
|
|
|
| xargs realpath \
|
|
|
|
|
| while read addition; do
|
|
|
|
|
xslt_maker "${addition#$input/}"
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-28 14:55:27 +00:00
|
|
|
copy_sources(){
|
2015-05-31 21:09:48 +00:00
|
|
|
# generate rules to copy all .xhtml files in the input to
|
|
|
|
|
# the public source directory
|
2015-05-28 14:55:27 +00:00
|
|
|
sourcefind -name '*.xhtml' \
|
|
|
|
|
| while read filepath; do
|
2015-05-29 15:55:00 +00:00
|
|
|
copy_maker "$filepath" "source/$(dirname "$filepath")"
|
2015-05-24 23:18:52 +00:00
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-31 21:09:48 +00:00
|
|
|
copy_sourceadditions(){
|
|
|
|
|
printf "$input/%s\n" "$@" \
|
|
|
|
|
| egrep '.+\.xhtml$' \
|
|
|
|
|
| xargs realpath \
|
|
|
|
|
| while read addition; do
|
|
|
|
|
copy_maker "${addition#$input/}" "source/$(dirname "${addition#$input/}")"
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 16:31:43 +00:00
|
|
|
tree_maker(){
|
|
|
|
|
# walk through file tree and issue Make rules according to file type
|
2015-05-30 14:04:30 +00:00
|
|
|
input="$(realpath "$1")"
|
2015-05-31 21:09:48 +00:00
|
|
|
output="$(realpath "$2")"
|
|
|
|
|
shift 2
|
2015-05-21 16:31:43 +00:00
|
|
|
|
|
|
|
|
cache_textsfile
|
|
|
|
|
cache_fundraising
|
|
|
|
|
|
2015-05-29 15:55:00 +00:00
|
|
|
cat <<-MakeHead
|
2015-05-22 18:50:24 +00:00
|
|
|
.PHONY: all
|
|
|
|
|
PROCESSOR = "$basedir/build/process_file.sh"
|
2015-05-29 15:55:00 +00:00
|
|
|
PGLOBBER = "$basedir/build/source_globber.sh"
|
2015-05-22 18:50:24 +00:00
|
|
|
PROCFLAGS = --source "$basedir" --statusdir "$statusdir" --domain "$domain"
|
2015-05-29 15:55:00 +00:00
|
|
|
INPUTDIR = $input
|
|
|
|
|
OUTPUTDIR = $output
|
2015-05-22 18:50:24 +00:00
|
|
|
MakeHead
|
|
|
|
|
|
2015-05-28 14:55:27 +00:00
|
|
|
forcelog Make_globs; Make_globs="$(logname Make_globs)"
|
|
|
|
|
forcelog Make_xslt; Make_xslt="$(logname Make_xslt)"
|
|
|
|
|
forcelog Make_copy; Make_copy="$(logname Make_copy)"
|
|
|
|
|
forcelog Make_sourcecopy; Make_sourcecopy="$(logname Make_sourcecopy)"
|
2015-05-29 15:55:00 +00:00
|
|
|
Make_xhtml="$(logname Make_xhtml)"
|
|
|
|
|
|
|
|
|
|
trap "trap - 0 2 3 6 9 15; killall \"$(basename "$0")\"" 0 2 3 6 9 15
|
2015-05-28 14:55:27 +00:00
|
|
|
|
2015-05-31 21:09:48 +00:00
|
|
|
[ "$regen_globs" = false -a -s "$Make_globs" ] && \
|
|
|
|
|
glob_additions "$@" >>"$Make_globs" \
|
2015-05-28 14:55:27 +00:00
|
|
|
|| glob_makers >"$Make_globs" &
|
2015-05-31 21:09:48 +00:00
|
|
|
[ "$regen_xslt" = false -a -s "$Make_xslt" ] && \
|
|
|
|
|
xslt_additions "$@" >>"$Make_xslt" \
|
2015-05-28 14:55:27 +00:00
|
|
|
|| xslt_makers >"$Make_xslt" &
|
2015-05-31 21:09:48 +00:00
|
|
|
[ "$regen_copy" = false -a -s "$Make_copy" ] && \
|
|
|
|
|
copy_additions "$@" >>"$Make_copy" \
|
2015-05-28 14:55:27 +00:00
|
|
|
|| copy_makers >"$Make_copy" &
|
2015-05-31 21:09:48 +00:00
|
|
|
[ "$regen_xhtml" = false -a -s "$Make_sourcecopy" ] && \
|
|
|
|
|
copy_sourceadditions "$@" >>"$Make_sourcecopy" \
|
2015-05-28 14:55:27 +00:00
|
|
|
|| copy_sources >"$Make_sourcecopy" &
|
2015-05-31 21:09:48 +00:00
|
|
|
if [ "$regen_xhtml" = false -a -s "$Make_xhtml" ]; then
|
|
|
|
|
cat "$Make_xhtml"
|
|
|
|
|
xhtml_additions "$@" |tee -a "$Make_xhtml"
|
|
|
|
|
else
|
|
|
|
|
xhtml_makers |tee "$Make_xhtml"
|
|
|
|
|
fi
|
2015-05-29 15:55:00 +00:00
|
|
|
|
2015-05-28 14:55:27 +00:00
|
|
|
wait
|
|
|
|
|
trap - 0 2 3 6 9 15
|
2015-05-31 21:09:48 +00:00
|
|
|
|
2015-05-29 15:55:00 +00:00
|
|
|
cat "$Make_globs" "$Make_xslt" "$Make_copy" "$Make_sourcecopy"
|
2015-05-21 16:31:43 +00:00
|
|
|
}
|
|
|
|
|
|