Finish switch to pattern rules in phase 2 Makefile
All checks were successful
the build was successful

This commit is contained in:
Reinhard Müller 2019-03-11 18:34:11 +01:00
parent f22a025540
commit a2577d9419
7 changed files with 68 additions and 289 deletions

View File

@ -34,10 +34,6 @@ if [ -z "$inc_arguments" ]; then
command="$1$command"
[ "$#" -gt 0 ] && shift 1 && target="$1"
;;
svn_build_into)
command="$1$command"
[ "$#" -gt 0 ] && shift 1 && target="$1"
;;
build_xmlstream)
command="$1$command"
[ "$#" -gt 0 ] && shift 1 && workfile="$1"
@ -81,7 +77,6 @@ if [ -z "$inc_arguments" ]; then
case "$command" in
build_into) [ -z "$target" ] && die "Missing destination directory" ;;
git_build_into) [ -z "$target" ] && die "Missing destination directory" ;;
svn_build_into) [ -z "$target" ] && die "Missing destination directory" ;;
process_file) [ -z "$workfile" ] && die "Need at least input file" ;;
build_xmlstream) [ -z "$workfile" ] && die "Missing xhtml file name" ;;
tree_maker) [ -z "$target" ] && die "Missing target location" ;;

View File

@ -38,7 +38,7 @@ buildpids=$(
| egrep "[s]h ${0} .*" \
| wc -l
)
if [ $command = "build_into" -o $command = "git_build_into" -o $command = "svn_build_into" ] && [ "$buildpids" -gt 2 ]; then
if [ $command = "build_into" -o $command = "git_build_into" ] && [ "$buildpids" -gt 2 ]; then
debug "build script is already running"
exit 1
fi
@ -59,12 +59,6 @@ case "$command" in
else
git_build_into
fi ;;
svn_build_into) if [ "${statusdir}/full_build" -nt "${statusdir}/index.cgi" ]; then
debug "discovered flag file, performing full build"
build_into
else
svn_build_into
fi ;;
build_into) build_into ;;
process_file) process_file "$workfile" "$processor" ;;
build_xmlstream) build_xmlstream "$(get_shortname "$workfile")" "$(get_language "$workfile")" ;;

View File

@ -24,9 +24,9 @@ build_into(){
make -C "$basedir" | t_logstatus premake
) || exit 1
dir_maker "$basedir" "$stagedir"
dir_maker "$basedir" "$stagedir" || exit 1
tree_maker "$basedir" "$stagedir" "$@" > "$(logname Makefile)"
tree_maker "$basedir" "$stagedir" > "$(logname Makefile)" || exit 1
(
# Make sure that the following pipe exits with a nonzero exit code if the
@ -58,86 +58,16 @@ git_build_into(){
gitterm="$?"
if [ "$gitterm" -ne 0 ]; then
die "GIT reported the following problem:\n" \
"$(cat "$GITerrors")"
#elif egrep '^(C...|.C..|...C) .+' "$SVNchanges"; then
# die "GIT encountered a conflict:\n" \
# "$(cat "$SVNchanges")"
elif egrep '^Already up-to-date\.' "$GITchanges"; then
debug "No changes to GIT:\n" \
"$(cat "$GITchanges")"
die "GIT reported the following problem:\n$(cat "$GITerrors")"
fi
if egrep '^Already up-to-date\.' "$GITchanges"; then
debug "No changes to GIT:\n$(cat "$GITchanges")"
# Exit status should only be 0 if there was a successful build.
# So set it to 1 here.
exit 1
else
logstatus GITlatest <"$GITchanges"
regen_xhtml=false
regen_xsldeps=false
regen_copy=false
# What to do, if a certain file type gets added, deleted, modified
egrep -q '^ (delete|rename) .*\.xhtml' "$GITchanges" && regen_xhtml=true
egrep -q '^ (create|rename) .*\.sources' "$GITchanges" && regen_xhtml=true
egrep -q '^ (delete|rename) .*\.sources' "$GITchanges" && regen_xhtml=true
egrep -q '^ (create|rename) .*\.xsl' "$GITchanges" && regen_xhtml=true
egrep -q '^ (delete|rename) .*\.xsl' "$GITchanges" && regen_xhtml=true && regen_xsldeps=true
egrep -q '^ .*\.xsl *\|' "$GITchanges" && regen_xsldeps=true
egrep -v '.*(\.xml|\.xsl|\.xhtml|\.sources|Makefile)' "$GITchanges" \
| egrep -q '^ (delete|rename)' && regen_copy=true
build_into $(sed -rn '
/^ create mode [0-7]{6} .*(Makefile|\.xml)/d
/^ rename .* => .*(Makefile|\.xml)\}? \([0-9]+%\)/d
s;^ create mode [0-7]{6} (.+);\1;p;
s;^ rename ([^{]+ => )(.*) \([0-9]+%\);\2;p;
s;^ rename ([^{]*)(\{.* => )(.+)\}(.*) \([0-9]+%\);\1\3\4;p
' "$GITchanges" \
| xargs -d\\n printf "${basedir}"/%s\\n
)
fi
}
svn_build_into(){
forcelog SVNchanges; SVNchanges="$(logname SVNchanges)"
forcelog SVNerrors; SVNerrors="$(logname SVNerrors)"
svn --non-interactive update "$basedir" >"$SVNchanges" 2>"$SVNerrors"
svnterm="$?"
if [ "$svnterm" -ne 0 ]; then
die "SVN reported the following problem:\n" \
"$(cat "$SVNerrors")"
elif egrep '^(C...|.C..|...C) .+' "$SVNchanges"; then
die "SVN encountered a conflict:\n" \
"$(cat "$SVNchanges")"
elif egrep '^At revision [0-9]+\.' "$SVNchanges"; then
debug "No changes to SVN:\n" \
"$(cat "$SVNchanges")"
# Exit status should only be 0 if there was a successful build.
# So set it to 1 here.
exit 1
else
logstatus SVNlatest <"$SVNchanges"
regen_xhtml=false
regen_xsldeps=false
regen_copy=false
# What to do, if a certain file type gets added, deleted, modified
egrep -q '^[A]... .*\.xml' "$SVNchanges" && true
egrep -q '^[D]... .*\.xml' "$SVNchanges" && true
egrep -q '^[UGR]... .*\.xml' "$SVNchanges" && true
egrep -q '^[A]... .*\.xhtml' "$SVNchanges" && true
egrep -q '^[D]... .*\.xhtml' "$SVNchanges" && regen_xhtml=true
egrep -q '^[UGR]... .*\.xhtml' "$SVNchanges" && true
egrep -q '^[A]... .*\.sources' "$SVNchanges" && regen_xhtml=true
egrep -q '^[D]... .*\.sources' "$SVNchanges" && regen_xhtml=true
egrep -q '^[UGR]... .*\.sources' "$SVNchanges" && true
egrep -q '^[A]... .*\.xsl' "$SVNchanges" && regen_xhtml=true
egrep -q '^[D]... .*\.xsl' "$SVNchanges" && regen_xhtml=true && regen_xsldeps=true
egrep -q '^[UGR]... .*\.xsl' "$SVNchanges" && regen_xsldeps=true
egrep -v '.*(\.xml|\.xsl|\.xhtml|\.sources|Makefile)$' "$SVNchanges" \
| egrep -q '^[D]... .*' && regen_copy=true
build_into $(sed -rn '/.*(Makefile|\.xml)$/d;s;^A... (.+)$;\1;p' "$SVNchanges")
fi
logstatus GITlatest < "$GITchanges"
build_into
}

View File

@ -4,24 +4,12 @@ inc_fundraising=true
[ -z "$inc_filenames" ] && . "$basedir/build/filenames.sh"
[ -z "$inc_languages" ] && . "$basedir/build/languages.sh"
cache_fundraising(){
cache_fundraising="$(for lang in $(get_languages); do
if [ -f "$basedir/fundraising-${lang}.xml" ]; then
echo -n " ${lang}:<$basedir/fundraising-${lang}.xml> "
elif [ -f "$basedir/fundraising-en.xml" ]; then
echo -n " ${lang}:<$basedir/fundraising-en.xml> "
fi
done)"
}
get_fundraisingfile(){
# get the fundraising file for a given language
# TODO: integrate with regular texts function
lang="$1"
if [ -n "$cache_fundraising" ]; then
echo "$cache_fundraising" |sed -r 's;^.* '"$lang"':<([^>]+)> .*$;\1;p'
elif [ -f "$basedir/fundraising-${lang}.xml" ]; then
if [ -f "$basedir/fundraising-${lang}.xml" ]; then
echo "$basedir/fundraising-${lang}.xml"
elif [ -f "$basedir/fundraising-en.xml" ]; then
echo "$basedir/fundraising-en.xml"

View File

@ -1,152 +1,22 @@
#!/bin/bash
inc_makerules=true
[ -z "$inc_misc" ] && . "$basedir/build/misc.sh"
[ -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"
sourcefind() {
find "$input" -name .svn -prune -o -name .git -prune -o -type f "$@" -printf '%P\n'
}
mio(){
# make input/output abstraction, produce reusable makefiles
# by replacing in and out pathes with make variables.
for each in "$@"; do
case "$each" in
"$input"/*) printf '${INPUTDIR}/%s\n' "${each#${input}/}" ;;
"$output"/*) printf '${OUTPUTDIR}/%s\n' "${each#${output}/}" ;;
*) printf %s\\n "$each" ;;
esac
done
}
mes(){
# make escape... escape a filename for make syntax
# possibly not complete
mio "$@" \
| sed -r ':X; $bY; N; bX; :Y;
s;[ #];\\&;g; s;\n; ;g'
}
xhtml_maker(){
# generate make rules for building html files out of xhtml
# account for included xml files and xsl rules
shortname="$input/$1"
outpath="\${OUTPUTDIR}/${2}"
outpath="${outpath%/*}"
textsen="$(get_textsfile "en")"
menufile="$basedir/tools/menu-global.xml"
filedir="${shortname%/*}"
shortbase="${shortname##*/}"
processor="$(get_processor "$shortname")"
list_file="`dirname ${shortname}`/.`basename ${shortname}`.xmllist"
[ -f "${list_file}" ] && xmllist="${list_file}" || unset xmllist
# For speed considerations: avoid all disk I/O in this loop
for lang in $(get_languages); do
infile="${shortname}.${lang}.xhtml"
depfile="${shortname}.*.xhtml"
infile="$(mio "$infile")"
outbase="${shortbase}.${lang}.html"
outfile="${outpath}/${outbase}"
textsfile="$(get_textsfile "$lang")"
fundraisingfile="$(get_fundraisingfile "$lang")"
cat <<MakeEND
all: $(mes "$outfile")
$(mes "$outfile"): $(mes "$depfile" "$processor" "$textsen" "$textsfile" "$fundraisingfile" "$menufile" "$xmllist")
\${PROCESSOR} \${PROCFLAGS} process_file "${infile}" "$(mio "$processor")" >"$outfile" || { rm $outfile; exit 1; }
MakeEND
done
}
xhtml_makers(){
# generate make rules concerning all .xhtml files in source tree
sourcefind -name '*.[a-z][a-z].xhtml' \
| sed -r 's;\.[a-z][a-z]\.xhtml$;;' \
| sort -u \
| while read shortpath; do
xhtml_maker "$shortpath" "${shortpath}"
done
}
xhtml_additions(){
printf "%s\n" "$@" \
| sed -rn 's;\.[a-z][a-z]\.xhtml$;;p' \
| sort -u \
| xargs realpath \
| while read addition; do
xhtml_maker "${addition#$input/}" "${addition#$input/}"
done
}
xslt_dependencies(){
# list referenced xsl files for a given xsl file
# *not* recursive since Make will handle recursive
# dependency resolution
file="$1"
cat "$file" \
| tr '\n\t\r' ' ' \
| sed -r 's;(<xsl:(include|import)[^>]*>);\n\1\n;g' \
| sed -nr '/<xsl:(include|import)[^>]*>/s;^.*href *= *"([^"]*)".*$;\1;gp'
}
xslt_maker(){
# find external references in a xsl file and generate
# Make dependencies accordingly
file="$input/$1"
dir="${file%/*}"
deps="$( xslt_dependencies "$file" |xargs -I'{}' realpath "$dir/{}" )"
cat <<MakeEND
$(mes "$file"): $(mes $deps)
touch "$(mio "$file")"
MakeEND
}
xslt_makers(){
# generate make dependencies for all .xsl files in input tree
sourcefind -name '*.xsl' \
| while read filepath; do
xslt_maker "$filepath"
done
}
xslt_additions(){
printf "%s\n" "$@" \
| egrep '.+\.xsl$' \
| xargs realpath \
| while read addition; do
xslt_maker "${addition#$input/}"
done
}
tree_maker(){
# walk through file tree and issue Make rules according to file type
input="$(realpath "$1")"
output="$(realpath "$2")"
shift 2
# List of languages in a single line, separated by blanks
languages=$(get_languages)
cache_textsfile
cache_fundraising
cat <<EOF
# -----------------------------------------------------------------------------
# Makefile for FSFE website build, phase 2
# -----------------------------------------------------------------------------
.PHONY: all
.DELETE_ON_ERROR:
.SECONDEXPANSION:
PROCESSOR = "$basedir/build/process_file.sh"
PROCFLAGS = --source "$basedir" --statusdir "$statusdir" --domain "$domain"
INPUTDIR = $input
@ -154,6 +24,35 @@ OUTPUTDIR = $output
STATUSDIR = $statusdir
LANGUAGES = $languages
# -----------------------------------------------------------------------------
# Touch all XSL files depending on a newer other XSL file
# -----------------------------------------------------------------------------
EOF
# Generate make dependencies for all .xsl files in input tree
find "${input}" -name '*.xsl' -not -name '.default.xsl' -printf '%P\n' \
| while read xsl_file; do
prerequisites=$(echo $(
cat "${input}/${xsl_file}" \
| tr '\n\t\r' ' ' \
| sed -r 's;(<xsl:(include|import)[^>]*>);\n\1\n;g' \
| sed -nr '/<xsl:(include|import)[^>]*>/s;^.*href *= *"([^"]*)".*$;\1;gp' \
| xargs -I'{}' realpath "${input}/$(dirname ${xsl_file})/{}" \
| sed -r "s;^${input};\$(INPUTDIR);"
))
if [ -n "${prerequisites}" ]; then
echo "all: \$(INPUTDIR)/${xsl_file}"
echo "\$(INPUTDIR)/${xsl_file}: ${prerequisites}"
echo ""
fi
done
cat <<EOF
%.xsl:
@echo "* Touching \$*"
@touch \$@
# -----------------------------------------------------------------------------
# Build .html files from .xhtml sources
# -----------------------------------------------------------------------------
@ -174,6 +73,25 @@ HTML_DST_BASES := \$(patsubst \$(INPUTDIR)/%,\$(OUTPUTDIR)/%,\$(HTML_SRC_BASES))
# List of .<lang>.html files to build
HTML_DST_FILES := \$(foreach base,\$(HTML_DST_BASES),\$(foreach lang,\$(LANGUAGES),\$(base).\$(lang).html))
# .xmllist file used to build a html file
XMLLIST_DEP = \$(wildcard \$(INPUTDIR)/\$(dir \$*).\$(notdir \$*).xmllist)
# .xsl file used to build a html file
XSL_DEP = \$(firstword \$(wildcard \$(INPUTDIR)/\$*.xsl) \$(INPUTDIR)/\$(dir \$*).default.xsl)
all: \$(HTML_DST_FILES)
EOF
for lang in ${languages}; do
cat<<EOF
\$(OUTPUTDIR)/%.${lang}.html: \$(INPUTDIR)/%.*.xhtml \$\$(XMLLIST_DEP) \$\$(XSL_DEP) \$(INPUTDIR)/tools/menu-global.xml \$(INPUTDIR)/tools/.texts-${lang}.xml \$(INPUTDIR)/tools/texts-en.xml \$(INPUTDIR)/.fundraising.${lang}.xml \$(INPUTDIR)/fundraising.en.xml
@echo "* Building \$*.${lang}.html"
@\${PROCESSOR} \${PROCFLAGS} process_file \$(INPUTDIR)/\$*.${lang}.xhtml > \$@
EOF
done
cat <<EOF
# -----------------------------------------------------------------------------
# Create index.* symlinks
# -----------------------------------------------------------------------------
@ -250,7 +168,7 @@ EOF
for lang in ${languages}; do
cat<<EOF
\$(OUTPUTDIR)/%.${lang}.rss: \$(INPUTDIR)/%.*.xhtml \$(INPUTDIR)/.%.xmllist \$(INPUTDIR)/%.rss.xsl \$(INPUTDIR)/tools/menu-global.xml $(get_textsfile "en") $(get_fundraisingfile "${lang}")
\$(OUTPUTDIR)/%.${lang}.rss: \$(INPUTDIR)/%.*.xhtml \$\$(XMLLIST_DEP) \$(INPUTDIR)/%.rss.xsl \$(INPUTDIR)/tools/menu-global.xml \$(INPUTDIR)/tools/.texts-${lang}.xml \$(INPUTDIR)/tools/texts-en.xml \$(INPUTDIR)/.fundraising.${lang}.xml \$(INPUTDIR)/fundraising.en.xml
@echo "* Building \$*.${lang}.rss"
@\${PROCESSOR} \${PROCFLAGS} process_file \$(INPUTDIR)/\$*.${lang}.xhtml \$(INPUTDIR)/\$*.rss.xsl > \$@
EOF
@ -279,7 +197,7 @@ EOF
for lang in ${languages}; do
cat<<EOF
\$(OUTPUTDIR)/%.${lang}.ics: \$(INPUTDIR)/%.*.xhtml \$(INPUTDIR)/.%.xmllist \$(INPUTDIR)/%.ics.xsl \$(INPUTDIR)/tools/menu-global.xml $(get_textsfile "en") $(get_fundraisingfile "${lang}")
\$(OUTPUTDIR)/%.${lang}.ics: \$(INPUTDIR)/%.*.xhtml \$\$(XMLLIST_DEP) \$(INPUTDIR)/%.ics.xsl \$(INPUTDIR)/tools/menu-global.xml \$(INPUTDIR)/tools/.texts-${lang}.xml \$(INPUTDIR)/tools/texts-en.xml \$(INPUTDIR)/.fundraising.${lang}.xml \$(INPUTDIR)/fundraising.en.xml
@echo "* Building \$*.${lang}.ics"
@\${PROCESSOR} \${PROCFLAGS} process_file \$(INPUTDIR)/\$*.${lang}.xhtml \$(INPUTDIR)/\$*.ics.xsl > \$@
EOF
@ -335,26 +253,5 @@ clean:
# -----------------------------------------------------------------------------
EOF
forcelog Make_xslt; Make_xslt="$(logname Make_xslt)"
Make_xhtml="$(logname Make_xhtml)"
trap "trap - 0 2 3 6 9 15; killall \"${0##*/}\"" 0 2 3 6 9 15
[ "$regen_xslt" = false -a -s "$Make_xslt" ] && \
xslt_additions "$@" >>"$Make_xslt" \
|| xslt_makers >"$Make_xslt" &
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
wait
trap - 0 2 3 6 9 15
cat "$Make_xslt"
}

View File

@ -4,24 +4,12 @@ inc_translations=true
[ -z "$inc_filenames" ] && . "$basedir/build/filenames.sh"
[ -z "$inc_languages" ] && . "$basedir/build/languages.sh"
cache_textsfile(){
cache_textsfile="$(for lang in $(get_languages); do
if [ -f "$basedir/tools/texts-${lang}.xml" ]; then
echo -n " ${lang}:<$basedir/tools/texts-${lang}.xml> "
else
echo -n " ${lang}:<$basedir/tools/texts-en.xml> "
fi
done)"
}
get_textsfile(){
# get the texts file for a given language
# fall back to english if necessary
lang="$1"
if [ -n "$cache_textsfile" ]; then
echo "$cache_textsfile" |sed -nr 's;^.* '"$lang"':<([^>]+)> .*$;\1;p'
elif [ -f "$basedir/tools/texts-${1}.xml" ]; then
if [ -f "$basedir/tools/texts-${1}.xml" ]; then
echo "$basedir/tools/texts-${1}.xml"
else
echo "$basedir/tools/texts-en.xml"

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
To externalise xsl code to a new file, copy this template,
copy the new content to it, and replace the according section
in the originating file with an include like this:
<xsl:include href="template.xsl" />
-->
</xsl:stylesheet>