ºìÁªLinuxÃÅ»§
Linux°ïÖú

ÇëÎÊÒ»¸ö¹ØÓÚmakefile αĿ±êʹÓõÄÎÊÌâ

·¢²¼Ê±¼ä:2012-12-13 17:18:30À´Ô´:ºìÁª×÷Õß:lemonliucy
×î½üÔÚѧmakefileµÄ±àд£¬Óöµ½Ò»¸öÎÊÌ⣬Çë¸÷λ´óÅ£Ìáµã¡£

ÔÚ×ÊÁÏÀïÃæ¿´µ½£¬ÔÚmakefileÀïÃæµÄÒÀÀµ¹ØϵÊǵ±ÒÀÀµÎļþ±ÈÄ¿±êÎļþеÄʱºò£¬¾Í»á¸üÐÂÄ¿±êÎļþ£¬±ÈÈ磺
edit : main.o
cc -o edit main.o

main.o : main.c
cc -o main.c
ÆäÖÐmain.oµÄ¸üÐÂÈÕÆÚ±ÈeditҪеĻ°£¬ÄÇôedit¾Í»á±»ÖØбàÒëÁ´½Ó¡£

µ«Êǵ±ÎÒ¿´µ½Î±Ä¿±êµÄ¡°Ò»´ÎÐÔÉú³É¶àÄ¿±ê¡±µÄ¹¦ÄܵÄʱºò£¬ÎÊÌâ¾ÍÀ´ÁË¡£
Ô­ÎÄÊÇÕâÑù£º
αĿ±êÒ»°ãûÓÐÒÀÀµµÄÎļþ¡£µ«ÊÇ£¬ÎÒÃÇÒ²¿ÉÒÔΪαĿ±êÖ¸¶¨ËùÒÀÀµµÄÎļþ¡£Î±Ä¿±êͬÑù¿ÉÒÔ×÷Ϊ¡°Ä¬ÈÏÄ¿±ê¡±£¬Ö»Òª½«Æä·ÅÔÚµÚÒ»¸ö¡£Ò»¸öʾÀý¾ÍÊÇ£¬Èç¹ûÄãµÄMakefileÐèÒªÒ»¿ÚÆøÉú³ÉÈô¸É¸ö¿ÉÖ´ÐÐÎļþ£¬µ«ÄãÖ»Ïë¼òµ¥µØÇÃÒ»¸ömakeÍêÊ£¬²¢ÇÒ£¬ËùÓеÄÄ¿±êÎļþ¶¼Ð´ÔÚÒ»¸öMakefileÖУ¬ÄÇôÄã¿ÉÒÔʹÓá°Î±Ä¿±ê¡±Õâ¸öÌØÐÔ£º
all : prog1 prog2 prog3
.PHONY : all

prog1 : prog1.o utils.o
cc -o prog1 prog1.o utils.o
prog2 : prog2.o
cc -o prog2 prog2.o
prog3 : prog3.o sort.o utils.o
cc -o prog3 prog3.o sort.o utils.o
ÎÒÃÇÖªµÀ£¬MakefileÖеĵÚÒ»¸öÄ¿±ê»á±»×÷ΪÆäĬÈÏÄ¿±ê¡£ÎÒÃÇÉùÃ÷ÁËÒ»¸ö¡°all¡±µÄαĿ±ê£¬ÆäÒÀÀµÓÚÆäËüÈý¸öÄ¿±ê¡£ÓÉÓÚαĿ±êµÄÌØÐÔÊÇ£¬×ÜÊDZ»Ö´Ðеģ¬ËùÒÔÆäÒÀÀµµÄÄÇÈý¸öÄ¿±ê¾Í×ÜÊDz»Èç¡°all¡±Õâ¸öÄ¿±êС£ËùÒÔ£¬ÆäËüÈý¸öÄ¿±êµÄ¹æÔò×ÜÊǻᱻ¾öÒé¡£Ò²¾Í´ïµ½ÁËÎÒÃÇÒ»¿ÚÆøÉú³É¶à¸öÄ¿±êµÄÄ¿µÄ¡£¡°.PHONY : all¡±ÉùÃ÷ÁË¡°all¡±Õâ¸öÄ¿±êΪ¡°Î±Ä¿±ê¡±¡£

ÎÒÀí½âÆðÀ´£¬ÕâÀïµÄÒâ˼ÊÇÓÉÓÚ¡°all¡±Õâ¸öαĿ±êÊÇÇ¿ÖƸüеģ¬ÄÇô¾Í»á·¢ÏÖÆäËûÈý¸öÒÀÀµÎļþ±ÈÕâ¸ö¾É£¬È»ºó²Å»á¸üÐÂÕâÈý¸öÒÀÀµÎļþ¡£µ«ÊÇÕâôһÀ´µÄ»°£¬ÒÀÀµ¹ØϵÆñ²»Êǵߵ¹¹ýÀ´ÁË£¬±ä³ÉÒÀÀµÎļþÓÉÓÚÄ¿±êÎļþµÄ¹Øϵ¶ø±»¸üÐÂÁËô£¿
ÊDz»ÊÇmakefile¶ÔÓÚ¡°Ê±¼äÒÀÀµ¡±ÕâÑùµÄ¸ÅÄîÊÇË«ÏòµÄ£¬¼ÈÒª±£³ÖÄ¿±êÎļþ²»ÄܱÈÒÀÀµÎļþ¾É£¬ÓÖÒª±£³ÖÒÀÀµÎļþ²»ÄܱÈÄ¿±êÎļþ¾É£¿

Çó¸÷λ´óÉñÖ¸µã°¡£¡£¡
¹òл£¡£¡
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 1 ÌõÆÀÂÛ

  1. alick ÓÚ 2012-12-14 22:47:45·¢±í:

    ÄãÓ¦¸ÃÊÇÏë¶àÁË¡£¡£¡£¿ÉÒÔÊÔÒ»ÊÔÂï¡£

    µ±prog1,prog2,prog3ÒѾ­ÊÇ×îеģ¨ËûÃÇÒÀÀµµÄÎļþÊÇ×îеÄʱ£©£¬make all ÎÞÐè×öÈκÎÊ¡£