kati ã«ã¤ãã¦
https://github.com/google/kati
kati ã«ã¤ãã¦ãããã¥ã¡ã³ãæ¸ããâ¦ã¨æã£ã¦ããã®ã§ãããªããªãé²ã¾ãªãã®ã§ãã¨ããããæ¥æ¬èªã§æ¸ãã¦ã¿ããã¨ã«ãã¾ãããä½æ¸ããããã¾ãæ確ãããªããã¼ããªã®ã§ãä½æ¸ããèããã®ã¨è±èªèããã®ã両æ¹åæã«ããã®ãå°ã大å¤ã§ã
åæ©
kati 㯠GNU make ã®ã¯ãã¼ã³ã§ãããããå®å ¨ãªã³ã³ããã«ãªãã¨å¬ããã§ããããªããªãé£ããã ããã¨å人çã«ã¯è«¦ãã¦ãã¾ããç¨éã«å¯¾ãã¦å®ç¨çãªãã°è¯ãããªã¨ã
åæ©ã¨ãã¦ã¯ã Android platform ã®ãã«ãã·ã¹ãã ãããªããªãã·ã¥ã¼ã«ãª GNU make é»éè¡ã§æ§æããã¦ãã¦ã make ãå®éã«ãªãããã¯ãããã¾ã§ãé ãã£ãã®ã§ããããé«éåãããã¨ãããã®ã§ããã
ãã«ãã·ã¹ãã ãé ãã¨ããæãã¾ãã ããããã«ãã«ãã¨ãã«ãã«ãã®2ç¹ãèãã¾ãããã«ãã«ãã¦ã®ã¯çæç©ãå ¨ã¦ã§ãã¦ããæã®ã make ã¦å©ãã¦ãã Nothing to be done ã¦åºãã¾ã§ã®æéã§ããã«ãã«ãã¯çæç©ãå ¨ããªãæã®æéã§ããç¾å®ã®ãã«ãã¯ä¸¡è ã®éã«ãªãã¾ããã大éæã«è¨ã£ã¦ããã«ãã«ãã¯éçºä¸ã« .c ãä¸ã¤ããã£ãæã®ã¿ã¼ã³ã¢ã©ã¦ã³ãæéãªã©ã«å¼·ãå½±é¿ãããã«ãã«ãã¯æ°ãããªãã¸ã§ã³ããã§ãã¯ã¢ã¦ãããæãå¤ãã®ãã¡ã¤ã«ãã include ããã¦ããã¡ã¤ã«ãããã£ãæãªã©ã®ãã«ãæéã«å½±é¿ãã¾ãã
Android ã®å ´åãçµæ§ç«æ´¾ãªã¯ã¼ã¯ã¹ãã¼ã·ã§ã³+SSDã§ããã«ãã«ãã100ç§ã»ã©ããã«ãã«ãã30åã¦ã¨ãã§ããã30åã¯ã¾ãè¯ããã§ãã30000ã¿ã¼ã²ãã以ä¸ããã®ã§ããã«ãã«ã100ç§ã®æ¹ãçµãã£ã¦ãã¾ãã C ãã¡ã¤ã«ä¸åæ¸ãæãã¦ãã³ã³ãã¤ã«ãéããããããã®ã100ç§å¾ã¨ããã®ã¯çµæ§ã¤ããã kati 使ã㨠Makefile æ¸ãæãã Java ãã¡ã¤ã«è¿½å ãç¡ãæã®ãã«ãã«ãã¯5ç§ãããå ´åã§50ç§ã¦ã¨ãã§ãã
ã¨ãããã㧠GNU make ã¯ãã¼ã³ä½ã£ã¦ã¿ãã®ã¯ã©ãããã¨ãããã¨ã§å§ããããã¸ã§ã¯ãã§ãããæåã¯ã³ãã³ãå®è¡ãããäºå®ã§ãããã ninja åºåããæ¹ãè²ã é½åãè¯ãé¨åãããä»ã¯ãããªã£ã¦ãã¾ãã 20% çã«å§ããããã¸ã§ã¯ãã§ããããæ°ãã¤ãããæ¬è·ã«ãªã£ã¦ã¦ã AOSP 㧠make ã¦å©ãã¨åæã« kati+ninja ã§ãã«ããããããã«ãªãã¾ããã
æåã¯è²ããªãã®ãã£ãã·ã¥ããã¨ãã¡ããã¨ããã°ååããã©ã¼ãã³ã¹ãåºãã ãããã¨ããè¦éã㧠ukai ãã㨠Go ã§æ¸ãå§ããã®ã§ããã主㫠GC ã®ããããããé ãã£ãã®ã§ä¸äººã§ C++ ã§æ¸ãç´ãã¾ãããã¨ã¯ããããã¾ã§ã«ããã£ãç¥è¦ããã¹ãã±ã¼ã¹ãçãããããã»ã¼ Go ã®ã³ã¼ããåç´ä½æ¥ã§ C++ ã«ç¿»è¨³ããã°è¯ãé¨åãå¤ãã£ããã¨ããã Go ãã¼ã¸ã§ã³ãç¡é§ã§ã¯ãªãã£ããã¨ããæãã§ããã
æ§æ
大éæã«è¨ã£ã¦ã kati ã«ã¯ä»¥ä¸ã®ãããªã³ã³ãã¼ãã³ããããã¾ã:
- ãã¼ãµ
- è©ä¾¡ããã¨ã
- ä¾åã°ã©ãä½ãã¨ã
- ä¾åã°ã©ããå®è¡ããã¨ã
- ä¾åã°ã©ããã ninja ãã¡ã¤ã«ãä½ãã¨ã
GNU make ã§ã¯ãã¼ãµã¨è©ä¾¡ããã¨ãã¯ã²ã£ã¤ãã¦ãã¨æããã¾ã(GNU make ã®ã³ã¼ã㯠OSS ãããã¯ã©ã¹ã®ä¿ºçå¯èªæ§ã®ä½ããªã®ã§ãã»ã¨ãã©èªãã§ãªãã§ã)ãæå¾ã®å®è¡ããã¨ãã㨠ninja ãã¡ã¤ã«ãä½ãã¨ããã¯ã¢ã¼ãã«ãã£ã¦åãæ¿ãããã¨ã«ãªãã¾ãã
ãã¼ãµã¨è©ä¾¡å¨ã¯æã®ãã¼ã¹/è©ä¾¡ã¨å¼ã®ãã¼ã¹/è©ä¾¡ã«ãããã2ã¤ããã¾ãã make ã¯è¡æåãªã®ã§æã¯1è¡ã¨å¯¾å¿ããä¸ã¤ã®æã¯ç¨®é¡ã«ãã£ã¦0å以ä¸ã®å¼ãæã¡ã¾ãã
æ®éã® make ã¦ã¼ã¶ã¯ãè©ä¾¡å¨ããã¾ãæèããªããã§ãªããã¨æãã¾ãããã å®ã¯é¢æ°ã¨ãä½ãã¦ãã®é¨åã¯ãã¥ã¼ãªã³ã°å®å ¨ã§ããã¾ãã Android ã®ãã«ãã«ãã®ã»ã¨ãã©ã®æéãããã«ä½¿ããã¦ãã¾ããã°ã©ãä½ãã¨ããã¨ã stat ãã¦ã¾ããã®ãç¸å¯¾çã«ãããããã¨ãªãã®ã¯ããã¶ã Android åºæã®è©±ã§ããè¦ã¯é»éè¡é§ä½¿ãããã¦ãã®ã§è©ä¾¡å¨ã®è² æ ããããã
è©ä¾¡ãçµãã£ã¦å¾ãããã®ã¯ã«ã¼ã«ã®ãªã¹ãã¨ãå¤æ°ãã¼ãã«ã§ããã«ã¼ã«ã次ã ã¨é©ç¨ããã¦ããã¨ä¾åã°ã©ããå®æãã¾ãããã®ãã§ã¼ãºã§å¤æ°ãã¼ãã«ã¯åºæ¬ä½¿ããªãã§ãã
å®è¡ããæã ninja ãã¡ã¤ã«ãçæããæã«ã³ãã³ãã«å¯¾ããå¼ã®è©ä¾¡ãè¡ãªããã¾ãããã®æã«å度å¤æ°ãã¼ãã«ãå¿ è¦ã§ãã
以ä¸ã§ã¯åã ã®ã³ã³ãã¼ãã³ããè¦ã¦ããã¾ãã CS ã®å¸¸èãéç¨ããªãã GNU make ã®çæ°ãæ£è¦ãããäºå®ã§ãã
æã®ãã¼ãµ
æ¢ã«æ¸ããéããæã®ãã¼ãµã¨å¼ã®ãã¼ãµãããã¾ãããã¨å®ã¯ã«ã¼ã«ã®ãã¼ãµã¨ããã®ãããã¾ããããã¯å¾ã§ãåè¿°ã®éã GNU make ã§ã¯ãããããã¼ãµã¨è©ä¾¡å¨ã¯ã²ã£ã¤ãã¦ã¾ããã kati ã§åããçç±ã¯é度ã®ããã§ããæ®éã¯åããªãã¦è¯ãã¨æãã®ã§ããã Android ã®ãã«ãã§ã¯åããã¡ã¤ã«ãå¼ãä½åº¦ãåç §ãã¾ããã©ã®ããããã¨ããã¨3åãã¡ã¤ã«ã5ä¸åãè¶ããåæ°èªã¿ã¾ããæãä½åº¦ãèªã¾ãããã¡ã¤ã«ã¯5åå以ä¸èªã¾ãã¾ãããããªãã®ãæ¯åº¦ãã¼ã¹ããã®ã¯å®å ¨ã«ã ãã§ãã Android ã®å ´åãæã®ãã¼ã¹çµæãè¨æ¶ãã¦ããã®ããããã¨ããã¼ã¹ã¨è©ä¾¡ã®é¨åãåç¨åº¦é ããªãã¾ãã
æã®ç¨®é¡ã¯
- ã«ã¼ã«
- ä»£å ¥
- ã³ãã³ã
- ãã£ã¬ã¯ãã£ã
ã®4ã¤ã§ãããã£ã¬ã¯ãã£ãã«ã¯ if ç³»ã include ç³»ã export/unexport ãããã¾ããéè¦ã§ãªãã§ãããã¨å é¨çã«ã¯ãã¼ã¹ã¨ã©ã¼æã¨ããã®ãããã¾ããã¨ããã®ã¯ GNU make ã® if ç³»ã¯å®è¡ããªãã¨ããã®ãã¼ã¹ã¨ã©ã¼ã¯ã¨ã©ã¼ã«ãªããªãã®ã§ããããããè©ä¾¡ããããã¨ã©ã¼ããããã¼ãã¨ããæãå¿ è¦ãªã®ã§ããã
æ®ãã®3ã¤ã¯
VAR := yay! # ããã¯ä»£å ¥ all: # ããã¯ã«ã¼ã« echo $(VAR) # ããã¯ã³ãã³ã
ã¨ãªã£ã¦ãã¾ãã make ã§ã«ã¼ã«ã¨è¨ãã¨æ®éã³ãã³ããå«ãæ°ããã¾ãããã¾ãããå¼ãã§ãã¾ãã
æã®ãã¼ãµã§åä»ãªã®ã¯ãã³ã³ããã¹ãã«ä¾åãã¦ãã¼ã¹çµæãå¤ããªãã¨ãããªããã¨ã§ããä¸ã¤ç®ã¨ãã¦ãå¼ãè©ä¾¡ããªãã¨æã®ç¨®é¡ãããããªãã±ã¼ã¹ããããã¨ãããã¾ããä¾ãã°ãã®2è¡ç®ã¯ãªãã§ãããã
$(VAR) X=hoge echo $${X}
ãã®2è¡ç®ã¯ã $(VAR) ã®å±éçµæãã«ã¼ã«ãªãã³ãã³ãæã§ãããã§ãªããã°ä»£å ¥æã§ããããæåã«
VAR := all:
ãªãã¦ã®ãããã¨ã³ãã³ãã«ãªãããã§ãããã³ãã³ãå¤æ°ã«å ¥ãã¦å±éãã¦ãã«ã¼ã«ã¨ãã¦èªèããããã¨ããã®ãä¸ã¤é©ããªã®ã§ã¯ãªããã¨æãã¾ããå¼ãè©ä¾¡ãã¦ã¿ãªãã¨ã«ã¼ã«ã®ä¸èº«ã®ãã¼ã¹ã«å ¥ããªãã¨ãããã¨ãªã®ã§ãã§ã¯å¿ ãå¼ã®è©ä¾¡ããã¦ããæã®ç¨®é¡å¤å®ãè¡ãªããããã¨ããã¨ãããã§ã¯ãªããã«ã¼ã«ã ããå¼è©ä¾¡ã®å¾ã«ä¸èº«ãã§ãã¯ããªããã¾ããå¤æ°ã« X=Y ã®ãããªä»£å ¥æã include ãã£ã¬ã¯ãã£ããªã©ãå ¥ãã¦ããããã¯åã«ã«ã¼ã«ã¨è§£éããã¾ããä¾ãã°
ASSIGN := A=B $(ASSIGN): echo $@
㯠A ã« B: ãä»£å ¥ããã®ã§ã¯ãªãã A=B ã¨ããã¿ã¼ã²ããã«å¯¾ãããã«ãã«ã¼ã«ã§ãã
ãããã£ãçç±ããã kati ã§ã¯ã¿ãã§å§ã¾ã£ã¦ãè¡ã¯ã¨ããããã³ãã³ãã¨ãã¦è§£éãã¤ã¤å ã®æååãè¦ãã¦ãããããééã£ã¦ãããã¼ã¹ããªãããã¨ãããã¨ããã¦ãã¾ãã
ã¾ãã2ã¤ç®ã®åä»ãªç¹ã¨ãã¦ãæ®éã®ããã°ã©ã è¨èªã§ã¯ãã¼ã¹ã®åã« \ ã«ããè¡é£çµã # ã«ããã³ã¡ã³ãã®å¦çãè¡ãªãããã®ã§ã¯ãªããã¨æãã¾ããã GNU make ã§ã¯ãããã®å¦çã®ä»æ¹ã3種é¡ããã®ã§ããã®æ®µéã§ã¾ã ã§ããªãã¨ãããã¨ãããã¾ããä¾ãã°
VAR := has\ space all: echo $(VAR) echo has\ nospace
ã®çµæ㯠has space 㨠hasnospace ãã§ãã
å¼ã®ãã¼ãµ
A := B
ã®ãããªä»£å ¥æã ã¨ã A 㨠B ãããããå¼ã§ããå¼ã¯ä¸è¬çã«ã¯ä»ã®å¼ã®é åã§æ¨æ§é ããªãã¦ãã¦ããªã¼ãã¯ããªãã©ã«ãå¤æ°åç §ãå¤æ°å°ããããåç §ãé¢æ°ãã¨ãªã£ã¦ã¾ãã
å¼ã®ãã¼ã¹ã§çã£ã¦ããã®ã¯ãåè¿°ã®éããã®ã¿ã¤ãã³ã°ã§ \ ã # ã«ããè¡é£çµã¨ã³ã¡ã³ãã«å¯¾å¿ããªãã¨ãããªããã¨ã対å¿ãåãã¦ãªãæ¬å¼§ã®çµãã¨ã©ã¼ã«ãªããªãå ´åããããã¨ããã¨ã¯é¢æ°ã«ãã£ã¦ãã¼ã¹ã®ä»æ¹ãå°ãéããã®ããããã¨ãã§ãã
ã¾ã対å¿ãåããªãæ¬å¼§ã¯ã $($(foo) ãªã©ã¨ããå¼ãããå ´åã "$(foo" ã¨ããååã®å¤æ°ãåç §ãããã¨ããã®ã GNU make ã®æåã«ãªã£ã¦ãã¾ãããããæå³çã«å©ç¨ãã Makefile ã¯ç¡ãã§ããããã©ã GNU make ã許ã以ä¸æ¬å¼§ã®å¯¾å¿ãåãã¦ãªãå¼ã¯ä¸ã®ä¸ã«åå¨ããã®ã§ãããã«å¯¾ãã¦é©åã«ã«ã©æååãåºãå¿ è¦ãããã¾ãã
GNU make ã«ã¯é¢æ°ãããã¾ããã ãããã®äººã¯ $(wildcard ...) ã $(subst ...) ããããã使ããªããã¤ã§ããã§ãããã¯å®ã¯ $(if ...) ã $(call ...) ãªã©ããã£ã¦ãæ¡ä»¶åå²ã¨é¢æ°å¼ã³åºããã§ããã®ã§ã GNU make ã®è©ä¾¡å¨ã¯ãã¥ã¼ãªã³ã°å®å ¨ã«ãªã£ã¦ã¾ãããã¼ã¹ã§ãããåé¡ã«ãªãã®ã¯ $(if ...) ã $(and ...) ã $(or ...) ã®3ã¤ã ãã空ç½ã®å¦çã®éããããå°ãéããã¨ãããã¨ã§ãã
ã«ã¼ã«ã®ãã¼ãµ
ä»£å ¥ã§ãã³ãã³ãã§ããã£ã¬ã¯ãã£ãã§ãç¡ããã®ã¯ã«ã¼ã«æã¨ãã¦ããããã§ããããã®ã«ã¼ã«æã¯è©ä¾¡ã®å¾ãå®éã«ã¯4ã¤ã®ãã®ã«ãªããã¾ãã
- ã«ã¼ã«
- target specific variable
- 空ç½ã ãã®å ´åä½ãããªã
- ã³ãã³ãç¡ã空ç½ä»¥å¤ã®æååã ã¨ã¨ã©ã¼
ããã§ããã«ã¼ã«ã¨ããã®ã all: hello.exe ã¿ãããªãã¤ã§ãã target specific variable ã¨ããã®ã¯ãã»ã¨ãã©ã®äººãç¥ããªãã¨æãã¾ããããã使ãã¨ç¹å®ã®ã¿ã¼ã²ããã ãã§æå¹ãªå¤æ°ãå®ç¾©ãããã¨ãã§ãã¦ãä¾ãã°
VAR := X target1: VAR := Y target1: echo $(VAR) target2: echo $(VAR)
ãªã©ã¨ããã¨ã target1 㯠Y ã¨è¡¨ç¤ºãã target2 㯠X ã表示ãã¾ããæè¦ã¨ãã¦ã¯ namespace ã®ãããªåãããããã®ã§ãã詳ããã¯å¾è¿°ãã¾ããã GNU make ã§ã®å¤æ°ã¯2種é¡ãã£ã¦ã := ã®å³è¾ºã¯å³åº§ã«è©ä¾¡ã = ã®å³è¾ºã®è©ä¾¡ã¯å±éæã«é 延ããããã¨ããç¹å¾´ãããã¾ããã¤ã¾ã target specific variable ã®ããã«ã¼ã«æã®å³è¾ºã®è©ä¾¡ã¯é 延ããªãã¨ãããªãããããã«ã¼ã«æå ¨ä½ãã¨ããããè©ä¾¡ãã¦ãããã¼ã¹ãããã¨ãããããªç°¡åãªããæ¹ã¯éç¨ãã¾ããããã®ã¸ããã®ãããã³ã¼ãã¼ã±ã¼ã¹ãããããããã®ã§ããã¶ã ckati ã¯å³å¯ã«å®è£ ãã¦ãªãã£ãè¨æ¶ãããã¾ãã
åæ§ã«ãã«ã¼ã«ã«ãå®è¡ãé 延ãããªããã°ãªããªãé¨åããã£ã¦ãã»ã¨ãã©ã®äººãç¥ããªãã§ãããã»ãã³ãã³ã¨ããã®ããã£ã¦ã
target: echo hi!
ã¨ããæ®éã® Makefile ã¨
target: ; echo hi!
ã¯ç価ã¨ãããã¨ã«ãªã£ã¦ãã¾ããããã®ããã§è©±ã2ã¤ã®æå³ã§ããããããªãã¾ãã1ã¤ç®ã¯ãã£ãã® = ã¨åãã§ã ; ããå ã®è©ä¾¡ã¯ã³ãã³ãå®è¡æã¾ã§é 延ãããªãã¨ãããªããã¨ãããã¨ãã㨠= 㨠; ã両æ¹ããå ´åã¯åºæ¬çã«ã¯å·¦ã«ããæ¹ãåã¤â¦ã¯ãã§ãã
2ã¤ç®ã¯ ; ãåå¨ããå ´åããã®å¾ã®ãã¼ã¹ã®ä»æ¹ãå¤ãããã¨ãããã¨ã§ããå ·ä½çã«ã¯åè¿°ã® \ 㨠# ã®å¦çããã³ãã³ãã¨ãã¦å¦çããæã®ã¢ã¼ãã«ãªãã¾ãã
ãã¨ãã¾ãã¨ãã¦ãããããæ®éç¥ããªãã§ãããã double colon rule ãã order only dependency ãªãã¦ãã®ã GNU make ã«ã¯ãã£ãããã¾ãâ¦ãããã§ã¯è©³ãããã¨ã¯æ¸ãã¾ããã
æã®è©ä¾¡
æã®ç¨®é¡ã¯
- ã«ã¼ã«
- ä»£å ¥
- ã³ãã³ã
- ãã£ã¬ã¯ãã£ã
ã¨ãã話ã§ããããã£ã¬ã¯ãã£ãã¯å ¨ã¦æ¯è¼ç常èçãªæåãããã³ãã³ãã¯åã«ä¸åæåã®ã«ã¼ã«ã«ã³ãã³ãã®å¼ã追å ãã¦ããã ãã®ãã¨ã§ããã«ã¼ã«æã¯åè¿°ã®ã«ã¼ã«ãã¼ãµãã ãããã®å¦çããããã¨ã«ãªãã¾ãã
æå¤ã¨æ¬é¶ããã®ã¯ä»£å ¥ã§ããå ã«å°ãæ¸ããéã GNU make ã®å¤æ°ã«ã¯2種é¡ããã¾ãã recursive 㨠simple ã¨å¼ã°ãã¦ãã¾ãã $(info ...) ã¨ãã print ã¿ãã㪠GNU make é¢æ°ãããã®ã§ãããããã使ã£ã¦
A = $(info world!) B := $(info Hello,) $(A) $(B)
ã¨ããã³ã¼ããæ¸ããã¨æãã¾ããããã 㨠world! ãå ã«åºã¡ãããããâ¦ã¨æãããããã¾ããããããã¯ã¡ãã㨠Hello, ã¨åºåãã¦ãã world! ã¨åºåãã¾ãããªããããªããã¨ããã¨ã A 㯠= ã§ä»£å ¥ããã¦ã¦ãã£ã¡ã¯è©ä¾¡ãé 延ããã recursive ã¨ãã種é¡ã®å¤æ°å®ç¾©ã§ã B 㯠:= ãªã®ã§å³æè©ä¾¡ãªã®ã§ãããã£ã¦ A ã®æ¹ã¯ $(A) ã¨ããæã«å§ãã¦åºåãè¡ãªããã¦ããã®ã§ããã B ã®æ¹ã¯ä»£å ¥æã«è©ä¾¡ããã¦ãã¾ãã
å°ããããããã®ã¯ += 㨠?= ã§ãããããã¯ååã®ä»£å ¥æã®å½¢å¼ãå¼ãç¶ãã¾ããã¾ã å®ç¾©ããã¦ãªãå¤æ°ã« += ã ?= ã使ã£ãå ´å㯠recursive ãã¤ã¾ã = ã®æ¹ã®ä»£å ¥ã¨ãªãã¾ãã
ããã« target specific variable 㨠+= ãçµã¿åãããã¨ãçµæ§è¤éãªãã¨ã«ãªãã¾ãã詳ããã¯èª¬æãã¾ãããã http://shinh.skr.jp/slide/make/014.html ã«ä¸ä¾ãããã¾ãã
å¼ã®è©ä¾¡
ãªã«ã¶ãé¢æ°ã®ç¨®é¡ãå¤ãã¦å®è£ ã®éã¯å¤ãé¨åã§ããããã®é¨åã¯çµæ§æ®éã§ããã³ãã³ãè¡ãè©ä¾¡ãããå ´å㯠$@ ãªã©ã®ç¹æ®å¤æ°ãå®ç¾©ããããªã©ãããã¾ãããã¾ãã¨ã«ãã常èçãªåãããã¾ãã
å°ããã³ãªé¨å㯠$(wildcard ...) ãããã§ããã㯠GNU make ã®æé©åãå ¥ã£ã¦ãããããã³ãã³ãè¡ã«ãã£ã¦ãè©ä¾¡ã¿ã¤ãã³ã°ãé 延ãããªãã¨ããç¹å¾´ãããã¾ããã¨ãããè©ä¾¡ã¿ã¤ãã³ã°ããã³ãããã«ã¤ãã¦ã¯ kati 㯠Go ã®æ¹ã C++ ã®æ¹ãå¥ã®æå³ã§å®è£ ãæ£ãããªãã¨æã£ã¦ã¾ãâ¦ãå®å®³ã¯æ®éãªãã§ãã
ninja ãã¡ã¤ã«ãåºåããå ´åãã³ãã³ãã«å¯¾ãã¦ãã®é¨åãå°ãããããããªãã®ã§ãããããã¯å¾è¿°ã
Android ã® Makefile ã«ã¯ $(shell find ...) ã¨ãããã¿ã¼ã³ã大éã«åºã¦ãã¾ããããã¯åãã¨ããä½åº¦ã find ããã®ã§ãããé ãã§ãã kati ã§ã¯é«éåã®ããã« find ã³ãã³ãã®ã¨ãã¥ã¬ã¼ã¿ãæ¸ãã¦ãã£ã¦ãæåã«ã³ã¼ãå ¨åã find ãã¦ããã¦ããã®çµæã使ã£ã¦ $(shell find ...) ãé«éå®è¡ãããã¨ãããã¨ããã¦ãã¾ãã find ã³ãã³ãã£ã¦ãããªãã«ãããããã®ã§çµæ§ããã©ãããã£ãé¨åã§ãã
ä¾åã°ã©ããä½ã
ãã¦ããã¾ã§ã¯ GNU make ã®ã«ã¸ã¥ã¢ã«ã¦ã¼ã¶ã¼ã«ã¨ã£ã¦ã¯ç°ä¸çã®è©±ã ã£ãã¨æãã®ã§ãããããã¯é¦´æã¿ã®ãã話ãã¨ããã make ã¨ããã¨æãæµ®ãã¹ãã®ã¯ãã®é¨åãã¨æãã¾ãã
ãã®é¨åããããªãã«è¤éãªã®ã§ãããçä¸å°½ãªæåã¯ãã¾ããã GNU make ã®ã«ã¼ã«ã«ã¯3種é¡ã®ãã®ãããã¾ãã
- explicit rule
- implicit rule
- suffix rule
explicit rule ã¯ã¿ã¼ã²ããåãæ確ãªã«ã¼ã«ã§ã implicit rule ã¯ã¿ã¼ã²ããåã« % ãå«ã¾ãã¦ãã¦ãè²ããªãã®ã«ãããããã«ã¼ã«ã§ãã suffix rule ã¯ãµãã£ãã¯ã¹ã§ãããããæ´å²ã®ããæ¸ãæ¹ãè¦ã¯ãã®3ã¤
all: hoge.o hoge.o: echo explicit %.o: echo implicit .c.o: echo suffix
åªå é ä½ã¯ suffix ãæå¼±ã§ãå¾ã¯ % ã«ãããããéãå°ãªããã®ãåªå ããã¾ããè¦ã¯ããå³å¯ãªæ¹ãªã®ã§ã explicit rule ã¯åªå 度æ大ã§ãããã®ãããã³ã°ããã«ã¼ã«ã«ã³ãã³ããã¤ãã¦ãã¦ãåææ¡ä»¶ãæºããããã®ãè¦ã¤ããã¾ã§è¡ãªãã¾ãã
Android ã«ã¯ % ã®ã¤ãã¦ãã«ã¼ã«ã1000以ä¸ãã£ã¦ã³ãã³ãã®ã¤ãã¦ãªãã«ã¼ã«ãä¸åä½ã§ããããããã®ãããã³ã°ããã¤ã¼ãã«ããã¨100ä¸ååä½ã®ã«ã¼ããåã£ã¦ãé ãã§ãããã£ã¦ãã㯠trie 使ã£ã¦éããªãããã«ãã¦ããã¾ãã
è¦ã¤ãã£ãã«ã¼ã«ã¯è²ã ã¨ãã¼ã¸ããããããã®ã§è²ã ãããããã£ãããã¾ãããã®ã¸ã㯠kati ã¯å³å¯ã«ã¯ããããå®è£ ã«ãªã£ã¦ãã¯ãâ¦ã§ãã
ã³ãã³ãå®è¡ãã
ã³ãã³ãã®å¼ã¯å®è¡ããç´åã«ãç¹æ®å¤æ° $@ ãªã©ã¨ã target specific variable ãä»è¾¼ãã å¾ã«è©ä¾¡ããã¾ãããããã¾ãããããæ®éã§ãã
å®è£ èªä½ã¯æ®éãªã®ã§ããã target specific variable ã大å¤çã®æªããã®ã§ãããã¨ã説æãã¦ããããã¨æãã¾ãã target specific variable ã¯ããã® target specific variable ãä»è¾¼ãã§ããã¿ã¼ã²ããããèµ·çãããã¿ã¼ã²ããã«ãé©ç¨ããã¾ããã©ããããã¨ãã¨ããã¨ã
VAR:=global all: VAR:=target specific all: hoge hoge: echo $(VAR)
㯠"target specific" ã¨åºåãã¾ãã all ã«ä»è¾¼ãã§ãã target specific variable ãã¿ã¼ã²ãã hoge ã«ãå½±é¿ãåã¼ãã¦ããããã§ããã§ãä½ãåé¡ãã¨ããã¨ããã "make hoge" ã¨ãã¦ã¿ã¼ã²ãã hoge ãã¿ã¼ã²ããæå®ããã¨ãã¿ã¼ã²ãã all ããèµ·åããããããããªãã®ã§ã "global" ã¨åºåãã¡ãããã§ããã make ã£ã¦éä¸ã®ã¿ã¼ã²ããæå®ããå ´åãåããã®ãã§ãããã£ã¦ã®ã¯å½ããåã®æå¾ ã ã¨æãã®ã§ãããã¯æ¬å½ã«çãæªãã¨æãã¾ãã
ninja ãã¡ã¤ã«ãçæãã
GNU make ã®è©±ã¯ããã§çµäºã§ãã exec ãããããã«åãæ å ±ã ninja ãã¡ã¤ã«ã«æ¸ãè¾¼ãã°çµããâ¦ãªã®ã§ããããªããªããããé£ããã
ã¾ã GNU make ã¯ä¸ã¤ã®ã«ã¼ã«ã«ã³ãã³ããè¤æ°ãã£ã¤ãã¦ãããã¾ããããã㯠ninja ã«ã¯ç¡ãã®ã§ã (cmd1) && (cmd2) && ... ãªã©ã¨æ··ããããè²ããªãã®ãã¨ã¹ã±ã¼ããããã $(SHELL) ã«å¯¾å¿ãããâ¦ãªã©ãå²ã¨è²ã ãããã¨ãããã¾ãã
æ¬æ°ã§åä»ãªã®ã¯ãã³ãã³ãå ã«ããå¯ä½ç¨ã®ãã make é¢æ°ãå ·ä½çã« $(shell ...) ã§ããããã®å®è¡ã¯ ninja å®è¡æã«ããªããã°ãªããªãã®ã§ãé©å㪠shell script ã«å¤æããªãã¨ããã¾ãããã $(if $(shell ...),X,Y) ãªã©ã¨ $(shell ...) ã®çµæãã¾ã GNU make é¢æ°ã«æ¸¡ãããã¨è©°ã¿ã¾ãã
ããã®æ£ãã対å¦ã¯è©¦é¨çãªããããæ¸ãã¦ã¿ãã®ã§ãããããã©ãããããã®ã§æ¾æ£ãã¦ãã¦ã Android ã«åºã¦ãããã¿ã¼ã³ã ã対å¦ã§ããã°è¯ãããã¨ããã¢ãããã¯ãªã³ã¼ããå ¥ã£ã¦ãã¾ãã
ninja ãã¡ã¤ã«ã®åçæãå¿ è¦ãã©ãããå¤æãã
kati 㯠Android ã® Makefile ã«å¯¾ãã¦ã GNU make ãã3åç¨åº¦éã Makefile ãè©ä¾¡ãã¾ããã ninja ãçæãã¦ããæéãå«ããã¨2åç¨åº¦ããé«éã§ãªããæ¯åº¦å®è¡ãã¦ã㨠Android ã®ãã«ãã«ãã¯çµå±50ç§ç¨åº¦ã«ãªã£ã¦ãã¾ãã¾ãã
ããã ã¨å¥ã«ãã¾ãå¬ãããªãã®ã§ã ckati ã«ã¯ä»¥åçæãã ninja ãã¡ã¤ã«ãåçæå¿ è¦ãã©ãããå¤æããæ©è½ãã¤ãã¦ãã¾ããããã¯çµæ§é£ããåé¡ã§ãä¸çªèªæãªã®ã¯ Makefile ãæ¸ãå¤ãã£ãæã§ãããã¯åã«ãã¼ã¹ããå ¨ã¦ã® Makefile ã®ã¿ã¤ã ã¹ã¿ã³ããè¨é²ãã¦ããã°å¿ è¦ãªæã«åçæãã§ãã¾ããç¾ç¶ã ckati ããã§ãã¯ãã¦ããé ç®ã¯5ã¤ãã£ã¦
- ckati èµ·åæã®ã³ãã³ãã©ã¤ã³
- ãã¼ã¹ããå ¨ã¦ã® Makefile ã®ã¿ã¤ã ã¹ã¿ã³ã
- å ¨ã¦ã®è©ä¾¡ã«ç¨ããããç°å¢å¤æ°ãå ¨ã¦ã®æåã®è©ä¾¡æã«æªå®ç¾©ã ã£ãå¤æ°ãå¾è ã¯å®ç¾©ããã¦ãªãã£ãç°å¢å¤æ°ãå®ç¾©ããããã¨ã«ãã£ã¦ Makefile ã®æåãå¤åããå¯è½æ§ãããããã§ã
- $(wildcard ...) ã®çµæ
- $(shell ...) ã®çµæ
æå¾ã®ãããã©ãããã§ããã¨ããã®ã¯åè¿°ã®éãã $(shell find ...) ã¯é ãã®ã§ããããæ¯åº¦ãã§ãã¯ããã¨é ããªã£ã¦ãã¾ãããã§ãã幸ã ckati 㯠Android ã® find ã®ã»ã¨ãã©ã«å¯¾å¿ã§ãã find ã¨ãã¥ã¬ã¼ã¿ãæã£ã¦ããã®ã§ã find ã¨ãã¥ã¬ã¼ã¿ã§è©ä¾¡ããå ´åããã§ãã¯ãããã£ã¬ã¯ããªã®ã¿ã¤ã ã¹ã¿ã³ããå ¨ã¦è¦ãã¦ããã¦ããããã1ã¤ã§ãå¤åããæã«ã ã find ãèµ°ãããããªã©ã¨ãããã¨ããã¦ãã¾ãã
ãã¨ã¯ $(shell date) ã¿ãããªæ¯åå¤ããã®ãå½ç¶ã§ãã¤æ¬è³ªçã«éè¦ã§ãªããã®ã $(shell echo foo > file) ãªã©ã¨ãããã¡ã¤ã«æ¸ãè¾¼ã¿ã«ä½¿ããã¦ããã®ããããã¯åå®è¡ããå¿ è¦ããªãã®ã§ãã¦ã¾ããã
ãããªãããªã§ãã®ã¹ãããã¯1ç§ã»ã©ã§çµããã¾ãã ninja ã®èªã¿è¾¼ã¿ã«4ç§ã»ã©ãããã®ã§ããã¼ã¿ã«ã§5ç§ã®ãã«ãã«ãã«ãªã£ã¦ã¾ãã
goma ãµãã¼ã
Google å ã§ã¯ goma ã¨ããã主㫠Chrome ã§ä½¿ã£ã¦ããã«ãã¤ã³ãã©ã¨ãã¾ããã¨çµã¿åããããããã«ãªã£ã¦ã¦ããã«ãã«ãã2åãããéããªã£ã¦ãâ¦ã¯ãã§ããã¾ãå¤ããã¯è¦ãã¦ãªãã¦æå³ãªãã®ã§è©³ãã説æãã¾ãããããã ninja ã ããçµã¿åãããããæãã«ãªã£ã¦ãã¦ã GNU make ã ã¨å®ç¾ãå°é£ã ã£ãããã¾ãã
goma ã«ã¤ãã¦ã¯Google Developer Day 2011 Japan: 「Chromium 開発を支えるクラウドの技術Googleクラウドコンパイラ」 - Google Developer Japan Blogãã©ããã goma ã®è¨ãåºãã£ãºã§ããã£ãã®ã§ããã®ã¹ã©ã¤ãåºãæã¯ç§ã goma ãã¼ã ã«ãããããªæ°ããã¾ãããããã
TODO
ãã«ã TODO ã¨ãã¦ã¯ $(MAKE) ã§èµ·åããã sub-make ã¨å¼ã°ãã¦ããã®ããããã¾ãããã㯠ninja çµç±ã§æ£ããããã®ã¯çµæ§å¤§å¤â¦ã§èãä¸ã
ã¾ã¨ã
å§ããåãã GNU make ãè¤éãªãã®ã ã£ã¦ã®ã¯ç¥ã£ã¦ãã¤ããã ã£ãã®ã§ãããã¯ãã¼ã³ãæ¸ãã¦ã¿ãã¨æ³å以ä¸ã«å¤§å¤ã§ããããããã楽ããä½æ¥ãã¦ã¾ãããããã¾ã«ã¤ãããããã¾ããã