aboutsummaryrefslogblamecommitdiff
path: root/v2/src/bin/makemake
blob: 665bb846bf26c024981695de6fd2876f8e4b8f85 (plain) (tree)

































































                                                                            

            

        
     
         
         

 



























                                                      
                  

                       













                                                                                               

                                






                                                                                
            
 









                                                                                   
 


                                                                       
 


                                                              
 






                                                           
    




                                               

 

                                     

                             
                                 
                         
                                
#!/bin/sh
set -eu


usage() {
	cat <<-'EOF'
		Usage:
		  makemake
		  makemake -h
	EOF
}

help() {
	cat <<-'EOF'

		Options:
		  -h, --help    show this message


		Generate make(1) code for later evaluation by make(1).  What
		this scripts does is fill the gap where make(1) can't handle
		globs and dynamic dependencies, and uses some ad-hoc scripts
		to generate those.
	EOF
}

for flag in "$@"; do
	case "$flag" in
		--)
			break
			;;
		--help)
			usage
			help
			exit
			;;
		*)
			;;
	esac
done

while getopts 'h' flag; do
	case "$flag" in
		h)
			usage
			help
			exit
			;;
		*)
			usage >&2
			exit 2
			;;
	esac
done
shift $((OPTIND - 1))



varlist() {
	printf '%s = \\\n' "$1"
	sed \
		-e 's/^/	/' \
		-e 's/$/ \\/'
	printf '\n'
}


EXTENSIONS='
.conf
.content
.html
.snippets
.htmlbody
'

COLL_EXTENSIONS='
.sortref
.xmlentry
'

page_ext_filter="^($(echo "$COLL_EXTENSIONS" |
	tr ' ' '\n' |
	grep . |
	paste -sd'|'
))\$"


extensions() {
	echo "$EXTENSIONS" "$COLL_EXTENSIONS" "$@" |
		tr ' ' '\n' |
		grep .
}


printf '.POSIX:\n\n\n'
for lang in $(langs); do
	for c in pages $(collections); do
		if [ "$c" = 'pages' ]; then
			filter="$page_ext_filter"
			dir="$CONTENT_PREFIX/$lang"
		else
			filter='^$'
			dir="$CONTENT_PREFIX/$lang/$c"
		fi

		mds() {
			find "$dir"/*.md 2>/dev/null
		}

		exts() {
			extensions | grep -Ev "$filter"
		}

		mds | varlist "$c.$lang.md"
		exts | sed "s|^\(.*\)\$|$c.$lang\1 = \$($c.$lang.md:.md=\1)|"
		exts | sed "s|^\(.*\)\$|\$($c.$lang\1)|" | varlist "$c.$lang"

		mds | sed 's/^\(.*\)\.md$/\1.conf \1.content: \1.md/'
		mds | sed 's/^\(.*\)\.md$/\1.snippets \1.htmlbody \1.html: \1.conf \1.content/'
		if [ "$c" = 'pages' ]; then
			continue
		fi

		mds | sed 's/^\(.*\)\.md$/\1.sortref: \1.md/'
		mds | sed 's/^\(.*\)\.md$/\1.xmlentry: \1.html/'

		echo "$CONTENT_PREFIX/$lang/feeds/$c.xml: \$($c.$lang.xmlentry)"

		printf '\n\n'
	done

	for e in $(extensions); do
		{
			if ! printf '%s\n' "$e" | grep -qE "$page_ext_filter"; then
				echo pages
			fi
			collections
		} |
		sed "s|^\(.*\)\$|\$(\1.$lang$e)|" |
		varlist "all-generated.$lang$e"
	done

	collections |
		sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/feeds/\1.xml|" |
		varlist "all-generated.$lang.xml"

	extensions '.xml' |
		sed "s|^\(.*\)\$|\$(all-generated.$lang\1)|" |
		varlist "all-generated.$lang"

	printf '\n'
done

for e in $(extensions .xml); do
	langs |
		sed "s|^\(.*\)\$|\$(all-generated.\1$e)|" |
		varlist "all-generated$e"
done

# shellcheck disable=2016
langs |
	sed 's|^\(.*\)$|$(all-generated.\1)|' |
	varlist 'all-generated'


git ls-files src/ |
	grep -v ^"$CONTENT_PREFIX"/ |
	varlist 'non-content'

git ls-files "$CONTENT_PREFIX"/ |
	grep -v '\.md$' |
	varlist 'static-content'