Quantcast
Channel: Programming – Gea-Suan Lin's BLOG
Viewing all articles
Browse latest Browse all 143

帶有 make help 說明的 Makefile

$
0
0

Lobsters 上看到「Self-documenting Makefiles」這篇裡面提到怎麼設計 make help 的方法,還蠻不錯的。

他的想法是讓 make help 去讀 Makefile 自己內容,把註解 # 後面的文字拉出來,產生出一包 help document,這邊拿他最後的成品來看:

.PHONY: help
help: # Shows interactive help.
	@cat README.md
	@echo
	@echo "make variables:"
	@echo
	@sed -e 's/^\([^ 	]\+\)[ 	]*?=[^#]\+#\(.*\)$$/\1 \2/p;d' Makefile | column -t -l 2 | sort
	@echo
	@echo "make targets:"
	@echo
	@sed -e's/^\([^: 	]\+\):.*#\(.*\)$$/\1 \2/p;d' Makefile | column -t -l 2 | sort

變數的部分這樣設定說明的部分:

DEVELOPER ?= 0# Set to 1 to enable developer builds.

而 target 的部分這樣設定說明的部分:

target/debug/program: # Builds the program.
target/debug/program: src/main.rs src/lib.rs

主要是抓概念,實務上可以自行變通,像是可以修改 sed 的替換規則,讓他支援 double-colon rules (::)。

這種設計用起來有一點點 Pythonheredoc 寫說明的感覺。


Viewing all articles
Browse latest Browse all 143

Trending Articles


FORECLOSURE OF REAL ESTATE MORTGAGE


Tinkerbell para colorear, pintar e imprimir


Pokemon para colorear


Arbol genealogico para colorear


Dibujos de animales para imprimir


Long Distance Relationship Tagalog Love Quotes


RE: Mutton Pies (jameskoiman)


Hagibis (1946) by Francisco V. Coching


Ka riam ka beit bad ka por riam


Vimeo Create - Video Maker & Editor 1.5.5 by Vimeo Inc