Просмотр исходного кода

Allow changing template whitespace

By default templates use tabs. Unfortunately there are misguided
heretics who prefer spaces. Bummer.

Two variables are introduced:

* SP=<number> can be set to use <number> spaces per indentation level.
* WS=<string> can be set to use <string> for each indentation level.

Most users will just want to use SP, for example:

  make new t=gen_server n=my_server SP=4

Note that people who want tabs don't have to do anything; tabs
are still the default.

WS is reserved for advanced users. Normal Make rules apply: all
whitespaces are trimmed. To specify 4 spaces using WS, you can
do the following:

  make new t=gen_server n=my_server WS='$(empty)    $(empty)'

Ugly, right? So just use SP.

Finally, SP and WS can be put in your Makefile directly.
In fact, erlang.mk will automatically add SP to a newly
created project if it was used during creation. For example:

  make -f erlang.mk bootstrap SP=2

So in time we should only need to make a note in the docs
at project creation time, as there is very little value
after that point.
Loïc Hoguin 10 лет назад
Родитель
Сommit
2f49c09aea
2 измененных файлов с 24 добавлено и 3 удалено
  1. 1 0
      core/core.mk
  2. 23 3
      plugins/bootstrap.mk

+ 1 - 0
core/core.mk

@@ -119,6 +119,7 @@ help::
 
 empty :=
 space := $(empty) $(empty)
+tab := $(empty)	$(empty)
 comma := ,
 
 define newline

+ 23 - 3
plugins/bootstrap.mk

@@ -46,10 +46,21 @@ define bs_appsrc_lib
 ]}.
 endef
 
+ifdef SP
+define bs_Makefile
+PROJECT = $(PROJECT)
+
+# Whitespace to be used when creating files from templates.
+SP = $(SP)
+
+include erlang.mk
+endef
+else
 define bs_Makefile
 PROJECT = $(PROJECT)
 include erlang.mk
 endef
+endif
 
 define bs_app
 -module($(PROJECT)_app).
@@ -323,11 +334,20 @@ endef
 # Plugin-specific targets.
 
 define render_template
-	@echo "$${$(1)}" > $(2)
+	@echo "$${_$(1)}" > $(2)
 endef
 
-$(foreach template,$(filter bs_%,$(.VARIABLES)),$(eval export $(template)))
-$(foreach template,$(filter tpl_%,$(.VARIABLES)),$(eval export $(template)))
+ifndef WS
+ifdef SP
+WS = $(subst a,,a $(wordlist 1,$(SP),a a a a a a a a a a a a a a a a a a a a))
+else
+WS = $(tab)
+endif
+endif
+
+$(foreach template,$(filter bs_% tpl_%,$(.VARIABLES)), \
+	$(eval _$(template) = $$(subst $$(tab),$$(WS),$$($(template)))) \
+	$(eval export _$(template)))
 
 bootstrap:
 ifneq ($(wildcard src/),)