Makefile
Àº ±âº»ÀûÀ¸·Î ¾Æ·¡¿Í °°ÀÌ ¸ñÇ¥(target), ÀÇÁ¸ °ü°è(dependency),
¸í·É(command)ÀÇ ¼¼°³·Î ÀÌ·ç¾îÁø ±âºÐÀûÀÎ ±ÔÄ¢(rule)µéÀÌ °è¼ÓÀûÀ¸·Î
³ª¿µÇ¾î ÀÖ´Ù°í ºÁµµ ¹«¹æÇÏ´Ù. make°¡ Áö´ÉÀûÀ¸·Î ÆÄÀÏÀ» °»½ÅÇÏ´Â °Íµµ
¸ðµÎ ÀÌ °£´ÜÇÑ ±ÔÄ¢¿¡ ÀÇÇϱ⠶§¹®ÀÌ´Ù.
target ... : dependency ...
command
...
...
¿©±â¼ ¸ñÇ¥(target) ºÎºÐÀº ¸í·É(command)ÀÌ ¼öÇàÀÌ µÇ¾î¼ ³ª¿Â °á°ú ÆÄÀÏÀ» ÁöÁ¤ÇÑ´Ù. ´ç¿¬È÷ ¸ñÀû ÆÄÀÏ(object file)À̳ª ½ÇÇà ÆÄÀÏÀÌ µÉ °ÍÀÌ´Ù.
¸í·É(command)ºÎºÐ¿¡ Á¤ÀÇµÈ ¸í·ÉµéÀº ÀÇÁ¸ °ü°è(depenency)ºÎºÐ¿¡ Á¤ÀÇµÈ ÆÄÀÏÀÇ ³»¿ëÀÌ ¹Ù²î¾ú°Å³ª, ¸ñÇ¥ ºÎºÐ¿¡ ÇØ´çÇÏ´Â ÆÄÀÏÀÌ ¾øÀ» ¶§ ÀÌ°÷¿¡ Á¤ÀÇµÈ °ÍµéÀÌ Â÷·Ê´ë·Î ½ÇÇàÀÌ µÈ´Ù. ÀϹÝÀûÀ¸·Î ½©¿¡¼ ¾µ ¼ö ÀÖ´Â ¸ðµç ¸í·É¾îµéÀ» »ç¿ëÇÒ ¼ö°¡ ÀÖÀ¸¸ç bash¿¡ ±â¹ÝÇÑ ½© ½ºÅ©¸³Æ®µµ Áö¿øÇÑ´Ù.
=> Âü°í: Âü°í·Î ¸ñÇ¥ ºÎºÐ¿¡´Â °á°ú ÆÄÀϸ¸ ¿Ã ¼ö ÀÖ´Â °ÍÀÌ ¾Æ´Ï°í, º¸Åë make clean ¿¡¼¿Í °°ÀÌ °£´ÜÇÑ ·¹À̺í(label) ±â´ÉÀ» Á¦°øÇϱ⵵ ÇÑ´Ù.
=> ¸í·É ºÎºÐÀº ²À TAB ±ÛÀÚ·Î ½ÃÀÛÇØ¾ß ÇÑ´Ù. ±×³É ºóÄ µîÀ» »ç¿ëÇϸé make ½ÇÇà Áß¿¡ ¿¡·¯°¡ ³´Ù. ¸í½ÉÇϼ¼¿ä. make°¡ ¸í·É¾îÀÎÁö ¾Æ´ÑÁö¸¦ TAB °¡Áö°í ±¸º°Çϱ⠶§¹®ÀÌÁÒ.
°£´ÜÇÑ Makefile
À» ¸¸µé¾î º»´Ù. ¿ì¸®°¡ ¸¸µé·Á°í ÇÏ´Â ÇÁ·Î±×·¥Àº
main.c read.c write.c
·Î ±¸¼ºµÇ¾î ÀÖ°í ¸ðµÎ io.h
¶ó´Â
Çì´õ ÆÄÀÏÀ» »ç¿ëÇÑ´Ù°í °¡Á¤ÇÑ´Ù. (Èå... ±¸¼ºÀ» °£´ÜÇÏ°Ô ÇսôÙ.)
À̵éÀ» °¢°¢ ÄÄÆÄÀÏÇؼ test ¶ó´Â ½ÇÇà ÆÄÀÏÀ» »ý¼º½ÃŲ´Ù.
% gcc -c main.c
% gcc -c read.c
% gcc -c write.c
% gcc -o test main.o read.o write.o
À§ÀÇ ¹æ½ÄÀº make¸¦ ¾²Áö ¾Ê°í ±×³É ¸í·É¾î¸¦ ÁÖ´Â ¹æ½ÄÀÌ´Ù. ÆÄÀÏÀÇ ¼ö°¡ À۾Ƽ ¿ÀÈ÷·Á ´õ °£´ÜÇÏ°Ô º¸ÀÏ ¼ö ÀÖÀ¸³ª, ÆÄÀÏÀÌ 100°³Á¤µµ µÈ´Ù°í °¡Á¤Çϸé... ¾ÆÂñ...
±×¸®°í, ¾Æ·¡´Â À§¿Í ¶È°°Àº ÀÏÀ» ¼öÇàÇÏ´Â Makefile
ÀÇ ³»¿ëÀÌ´Ù.
Makefile
test : main.o read.o write.o
gcc -o test main.o read.o write.o
main.o : io.h main.c
gcc -c main.c
read.o : io.h read.c
gcc -c read.c
write.o: io.h write.c
gcc -c write.c
(´ëÃæ ¾Ë¾Æº¸½Ã°Ú¾î¿ä? Âü TAB¹®ÀÚ ¾²´Â °Í ÀÖÁö ¸¶¼¼¿ä)
make´Â Makefile
ÀÇ ³»¿ëÀ» º¸°í, ³»ºÎÀûÀ¸·Î ¾î¶»°Ô ÆÄÀϵéÀÌ ÀÇÁ¸ÇÏ°í
ÀÖ´ÂÁö Á¶»çÇÑ´Ù. À§ÀÇ Makefile
À» ¹ÙÅÁÀ¸·Î ÀÇÁ¸ °ü°è¸¦ ±×¸²À¸·Î
³ªÅ¸³» º¸¸é ¾Æ·¡¿Í °°´Ù.
+---------------+
| io.h |
+------+--------+
|
+---------+----------+
| |
+--------------+ | +------+-------+ | +--------------+
| main.c | | | read.c | | | write.c |
+------+-------+ | +------+-------+ | +------+-------+
| | | | |
+------+-------+ | +------+-------+ | +------+-------+
| main.o +--+--| read.o | +--+ write.o |
+------+-------+ +------+-------+ +------+-------+
| | |
+--------------------+--------------------+
+-------|-------+
| test |
+------+--------+
(ÅؽºÆ® ±â¹ÝÀÌ¶ó¼ ±×¸² ±×¸®±â°¡ ²Ï ¾î·Æ³×¿ä. =)
À§ÀÇ ±×¸²¿¡¼ º¸¸é test °¡ ¸¸µé¾îÁö±â À§Çؼ´Â main.o read.o write.o°¡ ÇÊ¿äÇÏ°Ô °¢°¢ÀÇ ¸ñÀû ÆÄÀϵéÀº ¸ðµÎ ÀÚ½ÅÀÇ ¼Ò½º ÆÄÀÏ°ú io.h ¿¡ ÀÇÁ¸ÇÔÀ» ¾Ë ¼ö°¡ ÀÖ´Ù.
°¡·É main.c¸¦ °íÃÆ´Ù°í »ý°¢ÇÑ´Ù¸é main.o°¡ ÄÄÆÄÀÏµÇ¾î ´Ù½Ã »ý±â°í, test µµ ´Ù½Ã ¸µÅ©µÇ¾î °»½ÅµÈ´Ù. ¸¸¾à io.h°¡ ¹Ù²î¾ú´Ù°í °¡Á¤ÇÏ¸é ¸ðµç ÆÄÀϵéÀÌ ÄÄÆÄÀÏµÇ¾î¼ ¸ñÀû ÆÄÀÏÀÌ »ý±â°í, ±×°ÍµéÀÌ ¸µÅ©°¡ µÇ¾î test°¡ »ý±ä´Ù.
À§¿Í °°ÀÌ ÆÄÀϵéÀ» ±¸¼ºÇÑ ´ÙÀ½ Makefile
À» ½ÇÇà½ÃÄÑ º¸ÀÚ. Makefile
ÀÇ
½ÇÇàÀº ±×³É make¶ó°í¸¸ Ä¡¸é µÈ´Ù.
% make
gcc -c main.c
gcc -c read.c
gcc -c write.c
gcc -o test main.o read.o write.o <- OK
=> Âü°í: ±×³É Å×½ºÆ®¿¡ ºÒ°úÇϱ⠶§¹®¿¡ read.c writec io.h ´Â ¸ðµÎ ³»¿ë ¾øÀÌ ÆÄÀϸ¸ ¸¸µé¾î µÎ±â·Î ÇÏ°í, main.c ¿¡ °£´ÜÈ÷ printf ÇÔ¼ö¸¸ Àû¾î º¾½Ã´Ù. Á¤¸» À§¿Í °°ÀÌ µÊÀ» ½Ç°¨ÇÒ²¨¿¹¿ä... ½Å±âÇÏ°Ô...
°£´ÜÇÑ ¸ÅÅ©·Î ±â´ÉÀ» »ç¿ëÇØ º¸ÀÚ. main.o read.o write.o¶ó´Â °ÍÀ»
OBJECTS ¶ó´Â ¸ÅÅ©·Î·Î ¹Ù²Ù´Â °ÍÀÌ ¾Æ·¡ÀÇ
Makefile
OBJECTS = main.o read.o write.o
test : $(OBJECTS)
gcc -o test $(OBJECTS)
main.o : io.h main.c
gcc -c main.c
read.o : io.h read.c
gcc -c read.c
write.o: io.h write.c
gcc -c write.c
À§¿¡¼ º¸´Ù½ÃÇÇ ¸ÅÅ©·Î´Â ±×³É ÇÁ·Î±×·¥ © ¶§¿Í °°ÀÌ »ç¿ëÇؼ °ªÀ» ´ëÀÔÇÑ´Ù. ´ë½Å »ç¿ëÇÒ ¶§´Â ¹Ýµå½Ã $(..) ¾È¿¡ ³Ö¾î¼ »ç¿ëÇÑ´Ù. ¸ÅÅ©·Î ġȯÀ» À§ÇÑ Æ¯¼öÇÑ ¹æ¹ýÀÌ ¾Æ´Ò±î... È÷... ¸ÅÅ©·ÎÀÇ »ç¿ë¹ýÀº À§¿Í °°ÀÌ °£´ÜÇϹǷΠ´Ù¾çÇÏ°Ô Á¤ÀÇÇؼ »ç¿ëÇÒ ¼ö ÀÖ´Ù. ¸ÅÅ©·Î¿¡ ´ëÇÑ ÀÚ¼¼ÇÑ ¼³¸íÀº ´ÙÀ½ Àå¿¡¼ ¾ð±ÞÇϱâ·Î ÇÑ´Ù.
¸ñÇ¥ ºÎºÐ¿¡ ÇØ´çÇÏ´Â ºÎºÐÀÌ ±×³É ·¹À̺í°ú °°ÀÌ »ç¿ëµÉ ¼öµµ ÀÖ´Ù°í À̹Ì
¼³¸íÇÏ¿´´Ù.
Makefile
OBJECTS = main.o read.o write.o
test : $(OBJECTS)
gcc -o test $(OBJECTS)
main.o : io.h main.c
gcc -c main.c
read.o : io.h read.c
gcc -c read.c
write.o: io.h write.c
gcc -c write.c
clean :
rm $(OBECTS)
·¹À̺í·Î »ç¿ëµÉ ¶§´Â ´ç¿¬È÷ ÀÇÁ¸ °ü°è ºÎºÐÀº ¾ø¾îµµ µÈ´Ù. ±×¸®°í cleanÀ» ½ÇÇà½ÃÅ°·Á¸é ¾Æ·¡¿Í °°ÀÌ ÇÑ´Ù.
% make clean
rm main.o read.o write.o <- OK
´ÙÀ½ Àå¿¡¼´Â...
Áö±Ý±îÁö´Â Makefile
ÀÇ °£´ÜÇÑ ¿¹Á¦¸¦ °¡Áö°í ¹«¾ùÀ» ÇÒ ¼ö ÀÖ´ÂÁö ´ëÃæ
¾Ë¾Æº¸¾Ò½À´Ï´Ù. ¿¹Á¦¸¦ ¸¹ÀÌ ¾²´Ù º¸´Ï±î ³»¿ëÀÌ ºÒ¾î³ª°Ô µÆ±º¿ä. RCS¿Í
´Þ¸® make´Â Çѹø ¾Ë°í ÀÖÀ¸¸é Á¤¸» À¯¿ëÇÑ À¯Æ¿¸®Æ¼ÀÔ´Ï´Ù.
´ÙÀ½ Àå¿¡¼´Â º»°ÝÀûÀ¸·Î Makefile
ÀÇ ±¸¼º¹× ±× »ç¿ë¹ýÀ» ÀÚ¼¼È÷ ¾Ë¾Æ
º¸°íÀÚ ÇÕ´Ï´Ù. ±×³É ÀϹÝÀûÀ¸·Î Makefile
»ç¿ëÇϽ÷Á¸é ¿À´Ã ÇÑ °Í¿¡
¸î °¡Áö¸¸ ´õ ¾Ë°í °è½Ã¸é µË´Ï´Ù. °è¼Ó ¿¹Á¦ Áß½ÉÀ¸·Î ÀÌÇØ°¡ Àߵǵµ·Ï...
±×·³ °è¼Ó ºÁÁÖ½Ã¸é °¨»ç.