ãMakefileã®æ¸ãæ¹ï¼ããã°ã©ãã³ã°è¨èªMakeãã®ã³ã¡ã³ãæ¬ã§ãshiroãããããå¼æ°ä»ãé¢æ°ãã¦ã¼ã¶ã¼å®ç¾©ã§ããããã¨ãææããã ãã¾ããã
http://www.gnu.org/software/automake/manual/make/index.htmlãè¦ã¦ã¿ãããæè¿ã®GNU Makeã§ã¯å¼æ°ãæ±ãããã¨ãå¤æãä¾ãã°ã次ã®ããã«ä½¿ãã¾ãã
SUBDIRS := src include testfiles = $(wildcard $(1)/*.erl) $(wildcard $(1)/*.hrl)
ALL_FILES := $(foreach dir,$(SUBDIRS),$(call files,$(dir)))
filesãå¼æ°ä»ãé¢æ°ï¼Makeç¨èªã§ã¯ãã©ã¡ã¼ã¿ãæã¤å帰çå¤æ°ï¼ã§ã(($(wildcard $(1)/*.erl) $(wildcard $(1)/*.hrl)
ã¯ã$(wildcard $(1)/*.erl $(1)/*.hrl)
ã¨ãã¦ãçµæã¯å¤ããã¾ããã))ãä»®å¼æ°ï¼ãã©ã¡ã¼ã¿ï¼ã¯çªå·$(1), $(2), â¦ã§èå¥ãã¾ããæ®å¿µãªããååã¯ä½¿ãã¾ããã
ã¦ã¼ã¶ã¼å®ç¾©é¢æ°ãå¼ã³åºãã¨ãã¯çµã¿è¾¼ã¿é¢æ°callã使ãã¾ããä¾ãã°ã$(call files,src)
ã®ããã«ãåãªãå¤æ°åç
§ãå¼ã³åºããªã®ã§ã$(FOO)
ã®ä»£ããã«$(call FOO)
ã§ãåãã§ãã
çµã¿è¾¼ã¿é¢æ°foreachã¯ã確ãã«ã¹ã¯ãªããè¨èªã®foreachã¨ãä¼¼ã¦ãããã§ãããåä½ã¯é¢æ°åè¨èªã®ãããã³ã°é¢æ°ã¨åãã§ãããªã¹ãã«æ²¿ã£ã¦å¦çãç¹°ãè¿ãã¦ãçµæããªã¹ãã«ã¾ã¨ãã¦è¿ããã¾ãã
ä¸ã®Makeããã°ã©ã ãLispã«ç¿»è¨³ããã°ãããªæãã§ãããã
(setq SUBDIRS '("src" "include" "test"))(defun files (dir)
(append
(wildcard (concat dir "/*.erl"))
(wildcard (concat dir "/*.hrl"))))(setq ALL_FILES
(flatten (mapcar (function files) SUBDIRS)))
flattenã¯ããªã¹ãã®å ¥ãåãï¼ãããããã°ï¼ã¯ããã¦å¹³ããªãªã¹ãã«ããé¢æ°ã®ã¤ãããä¾ãã°ï¼
(defun flatten (lis)
(cond ((null lis) lis)
((not (consp lis)) (list lis))
(t (append (flatten (car lis)) (flatten (cdr lis))))))
Makeè¨èªã§ã¯ãã¡ããã¨ãããªã¹ãã¯ããã¾ããããèªï¼ã¯ã¼ãï¼ã空ç½ãã¯ããã§ä¸¦ã¹ãæååã¯ãªã¹ãæ±ãã§ãã¾ãã
ã¡ãªã¿ã«ãMakeè¨èªã§ãªã¹ãå¦çé¢æ°ãæ¸ããã¨ããããã¾ãããã¾ããã§ãããå帰å¼ã³åºããç¦æ¢ããã¦ãããã§ãããé¢æ°åè¨èªã§å帰ã使ããªãã¨ãããããããã§ããã[追è¨]ãããå帰å¼ã³åºãã§ããããã§ããã³ã¡ã³ãæ¬ã¨æ¬¡ã®ã¨ã³ããªã¼ã®æå¾åç §ã[追è¨]