diff options
Diffstat (limited to 'mk/help')
-rw-r--r-- | mk/help/help.awk | 73 | ||||
-rw-r--r-- | mk/help/help.mk | 38 |
2 files changed, 111 insertions, 0 deletions
diff --git a/mk/help/help.awk b/mk/help/help.awk new file mode 100644 index 00000000000..c319ea7599a --- /dev/null +++ b/mk/help/help.awk @@ -0,0 +1,73 @@ +# $NetBSD: help.awk,v 1.1 2006/10/23 14:40:15 rillig Exp $ +# + +BEGIN { + no = 0; yes = 1; + hline = "==============="; + hline = hline hline hline hline hline; + found = no; var = no; comment = no; n = 0; + rcsid = ""; + last_line_was_rcsid = no; + last_line_was_empty = yes; + topic = ENVIRON["TOPIC"]; + uctopic = toupper(topic); +} + +/.*/ { + if ($0 ~ /^#.*\$.*\$$/) { + rcsid = $0; + last_line_was_rcsid = yes; + } else { + if (last_line_was_rcsid && $0 == "#") { + # Skip this line + } else if ($0 == "") { + # Skip completely empty lines, too. + } else { + lines[n++] = $0; + } + last_line_was_rcsid = no; + } +} + +/./ { + # When looking for "configure", catch lines that contain + # "configure" and "CONFIGURE", but not "Configure". + w1 = ($1 == tolower($1)) ? toupper($1) : $1; + w2 = ($2 == tolower($2)) ? toupper($2) : $2; + + if ((w1 == uctopic"?=") || + (w1 == "#"uctopic"=") || + (w1 == "#" && last_line_was_empty && + (w2 == uctopic || w2 == uctopic":"))) { + var = 1; + } +} + +/^#/ { + comment = 1; +} + +/^$/ { + if (var && comment) { + found = yes; + print hline; + if (rcsid != "") { print rcsid; print "#"; } + for (i = 0; i < n; i++) { print lines[i]; } + } + var = no; comment = no; n = 0; +} + +/./ { + last_line_was_empty = no; +} +/^#$/ || /^$/ { + last_line_was_empty = yes; +} + +END { + if (found) { + print hline; + } else { + print "No help found for "topic"."; + } +} diff --git a/mk/help/help.mk b/mk/help/help.mk new file mode 100644 index 00000000000..2c05935f47e --- /dev/null +++ b/mk/help/help.mk @@ -0,0 +1,38 @@ +# $NetBSD: help.mk,v 1.1 2006/10/23 14:40:15 rillig Exp $ +# + +# This is the integrated pkgsrc online help system. To query for the +# meaning of a variable, run "make help TOPIC=VARNAME". All variables from +# certain pkgsrc Makefile fragments that have inline comments are eligible +# for querying. + +.if !defined(_PKGSRC_HELP_MK) +_PKGSRC_HELP_MK= # defined + +_HELP_FILES= mk/*.mk mk/*/*.mk + +.if defined(VARNAME) +TOPIC?= ${VARNAME} +.endif +.if defined(topic) +TOPIC?= ${topic} +.endif + +.PHONY: help +help: +.if !defined(TOPIC) + @${PRINTF} "usage: %s help topic=<topic>\\n" ${MAKE:Q} + @${PRINTF} "\\n" + @${PRINTF} "\\t<topic> may be a variable name or a make target,\\n" + @${PRINTF} "\\tfor example CONFIGURE_DIRS or patch. For convenience,\\n" + @${PRINTF} "\\tyou don't need to use uppercase letters when typing\\n" + @${PRINTF} "\\tvariable names.\\n" + @${PRINTF} "\\n" +.else + ${_PKG_SILENT}${_PKG_DEBUG} set -e; \ + cd ${PKGSRCDIR}; \ + { for i in ${_HELP_FILES}; do ${CAT} "$$i"; ${ECHO} ""; done; } \ + | env TOPIC=${TOPIC:Q} ${AWK} -f ${PKGSRCDIR}/mk/help/help.awk +.endif + +.endif |