ä¸æMakefileã«åã£ã¦ãã¾ãããMakefileã®è¨è¿°æ§æã®ãªãã«ããLispã«ä¼¼ãå°ããªé¢æ°åè¨èªãåãè¾¼ã¾ãã¦ãããã ãã¨ãè¨ã£ã¦ã¾ãããããããã¯ã¾ã¼ãéã³ååãªãã ãã©ããã®ãã®ç¥èã¯ãå®éã«Makefileãèªã¿æ¸ãããã¨ãã«ãå½¹ã«ãã¡ã¾ãã
éå»ã®Makefileé¢ä¿ã¨ã³ããªã¼ãèªã¿è¿ããã¨æã£ããããã£ããéãããããç´ä½æ²æããããã§ãããã«æ´çãã¦ã¾ã¨ãã¦ãããã¨æãã¾ãã
å 容ï¼
- åèè³æ
- æ¦å¿µã¨ç¨èª
- ãã¼ã¿å
- å¤æ°
- é¢æ°
- å¶å¾¡æ§é
- ç»é¢åºåã¨å¼·å¶çµäº
âåèè³æ
Makefileã«é¢ãã¦ã¯ã次ã®ã¨ã³ããªã¼ç¾¤ã§ã´ã¿ã´ã¿ã¨èª¬æãã¦ãã¾ãã
- Makefileã®æ¸ãæ¹ããã®åã©ãã
- Makefileã®æ¸ãæ¹ï¼ããã°ã©ãã³ã°è¨èªMake
- ããã°ã©ãã³ã°è¨èªMake è£éºï¼å¼æ°ä»ãã®é¢æ°
- Make è£éºã®è£éºï¼éãã§ããã ã
- Makeè¨èªã§ç®è¡æ¼ç® <-- ãã«ï¼
ãã£ã¨ãä¿¡é ¼ã§ããåå ¸ã¯ï¼
âæ¦å¿µã¨ç¨èª
ããã§ã¯ãGNU makeã®Makefileæ§æã®ä¸é¨ãé¢æ°åè¨èªã¨èãã¾ãããã£ã¦ãããã°ã©ãã³ã°è¨èªã®ç¨èªæ³ã使ããã¨ã«ãã¾ãã
ããã§ä½¿ãç¨èª | æ®é使ããã¦ããç¨èª |
---|---|
Makeè¨èª | Makefileã®è¨è¿°æ§æ |
è¨èªå¦çç³» | GNU makeã³ãã³ã |
ã½ã¼ã¹ã³ã¼ã | Makefile |
å¤æ° | åç´å¤æ° |
é¢æ° | å帰çå¤æ° |
é¢æ°ã®å¼æ° | å帰çå¤æ°ã®ãã©ã¡ã¼ã¿ |
ä»£å ¥ | := ã«ããä»£å ¥ |
é¢æ°å®ç¾© | = ã«ããä»£å ¥ |
ã½ã¼ã¹ã³ã¼ãã®æ¡å¼µåã¯.mkã¨ãã¾ãã次ãã½ã¼ã¹ã³ã¼ãã¨å¦çç³»ï¼ã¤ã³ã¿ããªã¿ï¼å®è¡ã®ä¾ã§ããMakeè¨èªã®å¦çç³»ï¼GNU makeã®ãã¨ãï¼ã¯ãã¼ã¸ã§ã³3.81以ä¸ã使ç¨ãã¦ãã ããã
# hello.mk
$(info Hello, world.)end:
@echo Done.
$ make -f hello.mk
Hello, world.
Done.$
以ä¸ã§ã¯ãLispã¨è¦ªåæ§ãé«ã $(...)
ã¨ããæ§æã使ãã¾ããã${...}
ã使ãã¾ãããªããåã
ã®çµã¿è¾¼ã¿é¢æ°ã«ã¤ãã¦ã¯èª¬æããªãã®ã§ãããã¥ã¢ã«ãªã©ã«ããã£ã¦ãã ããã
âãã¼ã¿å
Makeè¨èªã®ãã¼ã¿ã¯åºæ¬çã«ããã¹ãæååï¼ã¹ããªã³ã°ï¼ã§ããããããæèã«ããæååãã¯ã¼ãããªã¹ããã¾ãã¯ãã¼ã«å¤ï¼booleanï¼ã¨ãã¦è§£éããã¾ãã
- ã¯ã¼ã ï¼ ç©ºç½ãå«ã¾ãªãæåã®ä¸¦ã³
- ãªã¹ã ï¼ ããã¤ãã®ã¯ã¼ãã空ç½ã§åºåã£ã¦ä¸¦ã¹ããã®
- ãã¼ã«å¤ ï¼ ç©ºæååãå½ããã®ä»ã¯ç
次ã®ä¾ã§ã¯ãå¤æ°peopleã®å¤ã¯ãforeachç¹°ãè¿ãæ§æã®ãªãã§ã¯ãªã¹ãã¨ãã¦è§£éããã¾ããforeachã«é¢ãã¦ã¯å¾ã§ã¾ãåãä¸ãã¾ããããé°å²æ°ã ãã¤ããã§ãã ããã
# helloEverybody.mk
people := Taro Hanako Akira Yoko
$(foreach person,$(people),$(info Hello, $(person).))end:
@echo Done.
$ make -f helloEverybody.mk
Hello, Taro.
Hello, Hanako.
Hello, Akira.
Hello, Yoko.
Done.$
次ã®ä¾ã§ã¯ãå¤æ°peopleã®å¤ã¯ãifæ¡ä»¶å¼ã®ãªãã§ã¯ãã¼ã«å¤ãã¦è§£éãããé¢æ°strip, substã®ãªãã§ã¯åãªãæååã¨è§£éããã¦ãã¾ãã
# helloEverybody-2.mk
NIL :=
SPACE :=$(NIL) $(NIL)
COMMA :=,# ARGã®å¤ã¯ã³ãã³ãã©ã¤ã³ããè¨å®ããã
people := $(ARG)
people := $(if $(people),$(strip $(people)),nobody)
people := $(subst $(SPACE),$(COMMA) ,$(people))$(info Hello, $(people).)
end:
@echo Done.
$ make -f helloEverybody-2.mk
Hello, nobody.
Done.$ make ARG='Taro Hanako ' -f helloEverybody-2.mk
Hello, Taro, Hanako.
Done.$
âå¤æ°
å¤æ°å := å¼
ã«ããå¤æ°ã®å®£è¨ã¨åæåãããããå¤æ°å :=
ã«ããå¤æ°ã«ç©ºæååãè¨å®ãããã$(å¤æ°å)
ã«ããå¤æ°åç §ãã§ããã- 宣è¨ããã¦ãªãï¼æªå®ç¾©ï¼å¤æ°ã®å¤ã¯ç©ºæååã¨ã¿ãªããããæªå®ç¾©å¤æ°ã¨å¤ãã»ãã¨ã«ç©ºæååã§ããå¤æ°ã®åºå¥ã¯originé¢æ°ã§è¡ããï¼ä¸ã®ä¾ï¼ã
- ã³ãã³ãã©ã¤ã³æå®ã®å¤æ°ãç°å¢å¤æ°ã¯å®£è¨ãªãã«åç §ã§ããããããã®å¤æ°ã¯ãå¤ãæ¸ãæããã¹ãã§ã¯ãªãï¼ã³ãã³ãã©ã¤ã³ããã®å¤æ°ã¯ããããæ¸ãæãã§ããªãï¼ã
å¤æ°å += å¼
ã§å¤ãå¤ã¸ã®è¿½å ï¼ã¢ãã³ãï¼ãå¤æ°å ?= å¼
ã§å¤æ°ãæªå®ç¾©ã®ã¨ãã ãä»£å ¥ãã§ãããã+=ããé¢æ°å®ç¾©ï¼å¾è¿°ï¼ã«ä½¿ãã¹ãã§ã¯ãªãã
# vars.mk
foo :=
$(info foo='$(foo)')
$(info bar='$(bar)')
$(info baz='$(baz)')$(info origin(foo) is $(origin foo))
$(info origin(bar) is $(origin bar))
$(info origin(baz) is $(origin baz))end:
@echo Done.
$ make baz= -f vars.mk
foo=''
bar=''
baz=''
origin(foo) is file
origin(bar) is undefined
origin(baz) is command line
Done.$
âé¢æ°
é¢æ°å = å¼
ã«ããé¢æ°ãå®ç¾©ã§ããã- é¢æ°ã¸ã®å¼æ°ã¯ãé¢æ°å®ç¾©ã®å³è¾ºå 㧠$(1), $(2), ... ãªã©ã§ç¤ºãã
$(é¢æ°å)
ã«ããå¼æ°ãªãé¢æ°ãå¼ã³åºããã$(é¢æ°å å¼æ°1,å¼æ°2,...)
ã«ããçµã¿è¾¼ã¿é¢æ°ãå¼ã³åºããã$(call é¢æ°å,å¼æ°1,å¼æ°2,...)
ã«ããã¦ã¼ã¶ã¼å®ç¾©é¢æ°ãå¼ã³åºãããæ®å¿µãªãããçµã¿è¾¼ã¿é¢æ°ã¨åãæ§æã§ã¦ã¼ã¶ã¼å®ç¾©é¢æ°ãå¼ã³åºããã¨ã¯ã§ããªãã*1
次ã¯ãé¢æ°åè¨èªã§ãã使ãå¶å¾¡æ§é ï¼é«éé¢æ°ï¼ã§ããfoldrãå®ç¾©ãã¦ãfoldrã使ã£ã¦ãªã¹ããéé ã«ããé¢æ°reverseãå®ç¾©ãããã®ã§ãã
# reverse.mkNull = $(if $(1),,T)
Cdr = $(wordlist 2,$(words $(1)),$(1))Foldr = \
$(if $(call Null,$(3)),$(2),$(call $(1),$(firstword $(3)),$(call Foldr,$(1),$(2),$(call Cdr,$(3)))))PutLast = $(2) $(1)
Reverse = $(call Foldr,PutLast,,$(1))
FRUITS := apple orange banana
$(info FRUITS=$(FRUITS))
$(info Reverse(FRUITS)=$(call Reverse,$(FRUITS)))end:
@echo Done.
$ make -f reverse.mk
FRUITS=apple orange banana
Reverse(FRUITS)= banana orange apple
Done.$
ä¸è¨ã®Makeè¨èªã½ã¼ã¹ãå¿ å®ã«JavaScriptï¼å¦çç³»ã¯Rhinoï¼ã«ç¿»è¨³ããã¨æ¬¡ã®ããã«ãªãã¾ãããã ããMakeè¨èªã®ãªã¹ããJavaScriptã®é åã¨ãã¦è§£éãã¦ãã¾ãã
/* listã¯é åã ã¨ãã *//* Null = $(if $(1),,T) */
function Null(list) {
if (list.length) {
return false;
} else {
return true;
}
}/* Cdr = $(wordlist 2,$(words $(1)),$(1)) */
function Cdr(list) {
return list.slice(1, list.length);
}/*
* Foldr = \
* $(if $(call Null,$(3)),
* $(2),
* $(call $(1),$(firstword $(3)),
* $(call Foldr,$(1),$(2),$(call Cdr,$(3)))))
*/
function Foldr(fun, acc, list) {
if (Null(list)) {
return acc;
} else {
return fun(list[0], Foldr(fun, acc, Cdr(list)));
}
}/* PutLast = $(2) $(1) */
function PutLast(item, list) {
list.push(item);
return list;
}/* Reverse = $(call Foldr,PutLast,,$(1)) */
function Reverse(list) {
return Foldr(PutLast, [], list);
}/* FRUITS := apple orange banana */
var FRUITS = ["apple", "orange", "banana"];/* $(info FRUITS=$(FRUITS)) */
print("FRUITS=" + FRUITS);/* $(info Reverse(FRUITS)=$(call Reverse,$(FRUITS))) */
print("Reverse(FRUITS)=" + Reverse(FRUITS));
âå¶å¾¡æ§é
- æ¡ä»¶åå²ã¯
$(if æ¡ä»¶å¼,å¼)
ãã¾ãã¯$(if æ¡ä»¶å¼,å¼1,å¼2)
ã - ç¹°ãè¿ãã¯
$(foreach å¤æ°å,ãªã¹ã,å¼)
ããªã¹ãã®åè¦ç´ ãå¤æ°åã§æå®ããå¤æ°ã«ä»£å ¥ãããå¼ãå®è¡ããããå¼ã®ãªãã§ã¯ä»£å ¥ãããå¤æ°å¤ï¼åé ç®ï¼ã使ç¨ã§ãããå ¨ã¦ã®è©ä¾¡çµæã空ç½ãã¯ããã§é£çµãããªã¹ãæååãå¤ã¨ãªãï¼ä¸ã®ä¾ãåç §ï¼ã - ç絡çã«å®è¡ãããï¼ã·ã§ã¼ããµã¼ãããè©ä¾¡ãããï¼andã¨orãå¶å¾¡æ§é ã¨ãã¦ä½¿ãããæ§æã¯ã
$(and å¼1ï¼»,å¼2,â¦ï¼½)
ã$(or å¼1ï¼»,å¼2,â¦ï¼½)
ãandã¯ãå¼æ°ã«å½ï¼ç©ºæååï¼ãåºç¾ããã¨ããã§è©ä¾¡ãçµããã空æååãè¿ããããorã¯ãå¼æ°ã«çï¼é空æååï¼ãåºç¾ããã¨ããã§è©ä¾¡ãçµããããã®é空æååãè¿ãããã
# helloEverybody-3.mk
people := Taro Hanako Akira Yoko
greeting := $(foreach person,$(people),Hello, $(person).)
$(info $(greeting))end:
@echo Done.
$ make -f helloEverybody-3.mk
Hello, Taro. Hello, Hanako. Hello, Akira. Hello, Yoko.
Done.$
# eq.mk
Eq = $(and $(findstring $(1)X,$(2)X),$(findstring $(2)X,$(1)X))$(info '$(ARG1)' and '$(ARG2)':$(if $(call Eq,$(ARG1),$(ARG2)),Equal,NOT Equal))
end:
@echo Done.
$ make ARG1=foo ARG2=foo -f eq.mk
'foo' and 'foo':Equal
Done.$ make ARG1=foo ARG2=bar -f eq.mk
'foo' and 'bar':NOT Equal
Done.$
âç»é¢åºåã¨å¼·å¶çµäº
$(info å¼)
ã§å¼ã®è©ä¾¡çµæãç»é¢ã«æ¸ãåºããã$(info å¼)
å ¨ä½ã¯ç©ºæååã«è©ä¾¡ãããã$(error å¼)
ã§å¼ã®è©ä¾¡çµæãã¨ã©ã¼ã¡ãã»ã¼ã¸ã¨ãã¦ç»é¢ã«è¡¨ç¤ºããå¦çç³»ãçµäºããã
# deadOrAlive.mk
Eq = $(and $(findstring $(1)X,$(2)X),$(findstring $(2)X,$(1)X))$(if $(call Eq,$(ARG),Die),$(error Dead),$(info Alive))
end:
@echo Done.
$ make ARG=Hello -f deadOrAlive.mk
Alive
Done.$ make ARG=Die -f deadOrAlive.mk
deadOrAlive.mk:4: *** Dead. Stop.$
*1:ã¦ã¼ã¶ã¼å®ç¾©é¢æ°ãçµã¿è¾¼ã¿é¢æ°ã¨åãããã«å¼ã³åºããã°ãåçã«å¯èªæ§ãåä¸ããã§ãããã«ãã»ãã¨ã«æ®å¿µã