ÎÞÂÛÊÇÔÚLinux»¹ÊÇÔÚUnix»·¾³ÖУ¬make¶¼ÊÇÒ»¸ö·Ç³£ÖØÒªµÄ±àÒëÃüÁî¡£²»¹ÜÊÇ×Ô¼º½øÐÐÏîÄ¿¿ª·¢»¹ÊÇ°²×°Ó¦ÓÃÈí¼þ£¬ÎÒÃǶ¼¾³£ÒªÓõ½make»òmake install¡£ÀûÓÃmake¹¤¾ß£¬ÎÒÃÇ¿ÉÒÔ½«´óÐ͵Ŀª·¢ÏîÄ¿·Ö½â³ÉΪ¶à¸ö¸üÒ×ÓÚ¹ÜÀíµÄÄ£¿é£¬¶ÔÓÚÒ»¸ö°üÀ¨¼¸°Ù¸öÔ´ÎļþµÄÓ¦ÓóÌÐò£¬Ê¹ÓÃmakeºÍmakefile¹¤¾ß¾Í¿ÉÒÔ¼ò½àÃ÷¿ìµØÀí˳¸÷¸öÔ´ÎļþÖ®¼ä·×·±¸´ÔÓµÄÏ໥¹Øϵ¡£¶øÇÒÈç´Ë¶àµÄÔ´Îļþ£¬Èç¹ûÿ´Î¶¼Òª¼üÈëgccÃüÁî½øÐбàÒëµÄ»°£¬ÄǶԳÌÐòÔ±À´Ëµ¼òÖ±¾ÍÊÇÒ»³¡ÔÖÄÑ¡£¶ømake¹¤¾ßÔò¿É×Ô¶¯Íê³É±àÒ빤×÷£¬²¢ÇÒ¿ÉÒÔÖ»¶Ô³ÌÐòÔ±ÔÚÉϴαàÒëºóÐ޸ĹýµÄ²¿·Ö½øÐбàÒë¡£Òò´Ë£¬ÓÐЧµÄÀûÓÃmakeºÍmakefile¹¤¾ß¿ÉÒÔ´ó´óÌá¸ßÏîÄ¿¿ª·¢µÄЧÂÊ¡£Í¬Ê±ÕÆÎÕmakeºÍmakefileÖ®ºó£¬ÄúÒ²²»»áÔÙÃæ¶Ô×ÅLinuxϵÄÓ¦ÓÃÈí¼þÊÖ×ãÎÞ´ëÁË¡£
µ«ÁîÈËÒź¶µÄÊÇ£¬ÔÚÐí¶à½²ÊöLinuxÓ¦ÓõÄÊé¼®É϶¼Ã»ÓÐÏêϸ½éÉÜÕâ¸ö¹¦ÄÜÇ¿´óµ«Óַdz£¸´ÔӵıàÒ빤¾ß¡£ÔÚÕâÀïÎÒ¾ÍÏò´ó¼ÒÏêϸ½éÉÜÒ»ÏÂmake¼°ÆäÃèÊöÎļþmakefile¡£
MakefileÎļþ
Make¹¤¾ß×îÖ÷ÒªÒ²ÊÇ×î»ù±¾µÄ¹¦ÄܾÍÊÇͨ¹ýmakefileÎļþÀ´ÃèÊöÔ´³ÌÐòÖ®¼äµÄÏ໥¹Øϵ²¢×Ô¶¯Î¬»¤±àÒ빤×÷¡£¶ømakefile ÎļþÐèÒª°´ÕÕijÖÖÓï·¨½øÐбàд£¬ÎļþÖÐÐèҪ˵Ã÷ÈçºÎ±àÒë¸÷¸öÔ´Îļþ²¢Á¬½ÓÉú³É¿ÉÖ´ÐÐÎļþ£¬²¢ÒªÇó¶¨ÒåÔ´ÎļþÖ®¼äµÄÒÀÀµ¹Øϵ¡£makefile ÎļþÊÇÐí¶à±àÒëÆ÷--°üÀ¨ Windows NT ϵıàÒëÆ÷--ά»¤±àÒëÐÅÏ¢µÄ³£Ó÷½·¨£¬Ö»ÊÇÔÚ¼¯³É¿ª·¢»·¾³ÖУ¬Óû§Í¨¹ýÓѺõĽçÃæÐÞ¸Ä makefile Îļþ¶øÒÑ¡£
ÔÚ UNIX ϵͳÖУ¬Ï°¹ßʹÓà Makefile ×÷Ϊ makfile Îļþ¡£Èç¹ûҪʹÓÃÆäËûÎļþ×÷Ϊ makefile£¬Ôò¿ÉÀûÓÃÀàËÆÏÂÃæµÄ make ÃüÁîÑ¡ÏîÖ¸¶¨ makefile Îļþ£º
$ make -f Makefile.debug
ÀýÈ磬һ¸öÃûΪprogµÄ³ÌÐòÓÉÈý¸öCÔ´Îļþfilea.c¡¢fileb.cºÍfilec.cÒÔ¼°¿âÎļþLS±àÒëÉú³É£¬ÕâÈý¸öÎļþ»¹·Ö±ð°üº¬×Ô¼ºµÄÍ·Îļþa.h ¡¢b.hºÍc.h¡£Í¨³£Çé¿öÏ£¬C±àÒëÆ÷½«»áÊä³öÈý¸öÄ¿±êÎļþfilea.o¡¢fileb.oºÍfilec.o¡£¼ÙÉèfilea.cºÍfileb.c¶¼ÒªÉùÃ÷Óõ½Ò»¸öÃûΪdefsµÄÎļþ£¬µ«filec.c²»Ó᣼´ÔÚfilea.cºÍfileb.cÀﶼÓÐÕâÑùµÄÉùÃ÷£º
#include "defs"
ÄÇôÏÂÃæµÄÎĵµ¾ÍÃèÊöÁËÕâЩÎļþÖ®¼äµÄÏ໥ÁªÏµ:
#It is a example for describing makefile
prog : filea.o fileb.o filec.o
cc filea.o fileb.o filec.o -LS -o prog
filea.o : filea.c a.h defs
cc -c filea.c
fileb.o : fileb.c b.h defs
cc -c fileb.c
filec.o : filec.c c.h
cc -c filec.c
Õâ¸öÃèÊöÎĵµ¾ÍÊÇÒ»¸ö¼òµ¥µÄmakefileÎļþ¡£
´ÓÉÏÃæµÄÀý×Ó×¢Òâµ½£¬µÚÒ»¸ö×Ö·ûΪ # µÄÐÐΪעÊÍÐС£µÚÒ»¸ö·Ç×¢ÊÍÐÐÖ¸¶¨progÓÉÈý¸öÄ¿±êÎļþfilea.o¡¢fileb.oºÍfilec.oÁ´½ÓÉú³É¡£µÚÈýÐÐÃèÊöÁËÈçºÎ´ÓprogËùÒÀÀµµÄÎļþ½¨Á¢¿ÉÖ´ÐÐÎļþ¡£½ÓÏÂÀ´µÄ4¡¢6¡¢8ÐзֱðÖ¸¶¨Èý¸öÄ¿±êÎļþ£¬ÒÔ¼°ËüÃÇËùÒÀÀµµÄ.cºÍ.hÎļþÒÔ¼°defsÎļþ¡£¶ø5¡¢7¡¢9ÐÐÔòÖ¸¶¨ÁËÈçºÎ´ÓÄ¿±êËùÒÀÀµµÄÎļþ½¨Á¢Ä¿±ê¡£
µ±filea.c»òa.hÎļþÔÚ±àÒëÖ®ºóÓÖ±»Ð޸ģ¬Ôò make ¹¤¾ß¿É×Ô¶¯ÖØбàÒëfilea.o£¬Èç¹ûÔÚÇ°ºóÁ½´Î±àÒëÖ®¼ä£¬filea.C ºÍa.h ¾ùûÓб»Ð޸ģ¬¶øÇÒ test.o »¹´æÔڵĻ°£¬¾ÍûÓбØÒªÖØбàÒë¡£ÕâÖÖÒÀÀµ¹ØϵÔÚ¶àÔ´ÎļþµÄ³ÌÐò±àÒëÖÐÓÈÆäÖØÒª¡£Í¨¹ýÕâÖÖÒÀÀµ¹ØϵµÄ¶¨Ò壬make ¹¤¾ß¿É±ÜÃâÐí¶à²»±ØÒªµÄ±àÒ빤×÷¡£µ±È»£¬ÀûÓà Shell ½Å±¾Ò²¿ÉÒÔ´ïµ½×Ô¶¯±àÒëµÄЧ¹û£¬µ«ÊÇ£¬Shell ½Å±¾½«È«²¿±àÒëÈκÎÔ´Îļþ£¬°üÀ¨ÄÄЩ²»±ØÒªÖØбàÒëµÄÔ´Îļþ£¬¶ø make ¹¤¾ßÔò¿É¸ù¾ÝÄ¿±êÉÏÒ»´Î±àÒëµÄʱ¼äºÍÄ¿±êËùÒÀÀµµÄÔ´ÎļþµÄ¸üÐÂʱ¼ä¶ø×Ô¶¯ÅжÏÓ¦µ±±àÒëÄĸöÔ´Îļþ¡£
MakefileÎļþ×÷ΪһÖÖÃèÊöÎĵµÒ»°ãÐèÒª°üº¬ÒÔÏÂÄÚÈÝ:
¡ô ºê¶¨Òå
¡ô Ô´ÎļþÖ®¼äµÄÏ໥ÒÀÀµ¹Øϵ
¡ô ¿ÉÖ´ÐеÄÃüÁî
MakefileÖÐÔÊÐíʹÓüòµ¥µÄºêÖ¸´úÔ´Îļþ¼°ÆäÏà¹Ø±àÒëÐÅÏ¢£¬ÔÚLinuxÖÐÒ²³ÆºêΪ±äÁ¿¡£ÔÚÒýÓúêʱֻÐèÔÚ±äÁ¿Ç°¼Ó$·ûºÅ£¬µ«ÖµµÃ×¢ÒâµÄÊÇ£¬Èç¹û±äÁ¿ÃûµÄ³¤¶È³¬¹ýÒ»¸ö×Ö·û£¬ÔÚÒýÓÃʱ¾Í±ØÐë¼ÓÔ²À¨ºÅ£¨£©¡£
ÏÂÃ涼ÊÇÓÐЧµÄºêÒýÓãº
$(CFLAGS)
$2
$Z
$(Z)
ÆäÖÐ×îºóÁ½¸öÒýÓÃÊÇÍêÈ«Ò»Öµġ£
ÐèҪעÒâµÄÊÇһЩºêµÄÔ¤¶¨Òå±äÁ¿£¬ÔÚUnixϵͳÖУ¬$*¡¢$@¡¢$?ºÍ$<ËĸöÌØÊâºêµÄÖµÔÚÖ´ÐÐÃüÁîµÄ¹ý³ÌÖлᷢÉúÏàÓ¦µÄ±ä»¯£¬¶øÔÚGNU makeÖÐÔò¶¨ÒåÁ˸ü¶àµÄÔ¤¶¨Òå±äÁ¿¡£¹ØÓÚÔ¤¶¨Òå±äÁ¿µÄÏêϸÄÚÈÝ£¬ºê¶¨ÒåµÄʹÓÿÉÒÔʹÎÒÃÇÍÑÀëÄÇЩÈß³¤·¦Î¶µÄ±àÒëÑ¡ÏΪ±àдmakefileÎļþ´øÀ´ºÜ´óµÄ·½±ã¡£
# Define a macro for the object files
OBJECTS= filea.o fileb.o filec.o
# Define a macro for the library file
LIBES= -LS
# use macros rewrite makefile
prog: $(OBJECTS)
cc $(OBJECTS) $(LIBES) -o prog
¡¡
´ËʱÈç¹ûÖ´Ðв»´ø²ÎÊýµÄmakeÃüÁ½«Á¬½ÓÈý¸öÄ¿±êÎļþºÍ¿âÎļþLS£»µ«ÊÇÈç¹ûÔÚmakeÃüÁîºó´øÓÐеĺ궨Ò壺
make "LIBES= -LL -LS"
ÔòÃüÁîÐкóÃæµÄºê¶¨Ò彫¸²¸ÇmakefileÎļþÖеĺ궨Òå¡£ÈôLLÒ²ÊÇ¿âÎļþ£¬´ËʱmakeÃüÁÁ¬½ÓÈý¸öÄ¿±êÎļþÒÔ¼°Á½¸ö¿âÎļþLSºÍLL¡£
ÔÚUnixϵͳÖÐûÓжԳ£Á¿NULL×÷³öÃ÷È·µÄ¶¨Ò壬Òò´ËÎÒÃÇÒª¶¨ÒåNULL×Ö·û´®Ê±ÒªÊ¹ÓÃÏÂÊöºê¶¨Ò壺
STRINGNAME=
MakeÃüÁî
ÔÚmakeÃüÁîºó²»½ö¿ÉÒÔ³öÏֺ궨Ò壬»¹¿ÉÒÔ¸úÆäËûÃüÁîÐвÎÊý£¬ÕâЩ²ÎÊýÖ¸¶¨ÁËÐèÒª±àÒëµÄÄ¿±êÎļþ¡£Æä±ê×¼ÐÎʽΪ£º
target1 [target2 ¡]:[:][dependent1 ¡][;commands][#¡]
[(tab) commands][#¡]
·½À¨ºÅÖмäµÄ²¿·Ö±íʾ¿ÉÑ¡Ïî¡£TargetsºÍdependentsµ±ÖпÉÒÔ°üº¬×Ö·û¡¢Êý×Ö¡¢¾äµãºÍ"/"·ûºÅ¡£³ýÁËÒýÓã¬commandsÖв»Äܺ¬ÓÐ"#",Ò²²»ÔÊÐí»»ÐС£
ÔÚͨ³£µÄÇé¿öÏÂÃüÁîÐвÎÊýÖÐÖ»º¬ÓÐÒ»¸ö":"£¬´ËʱcommandÐòÁÐͨ³£ºÍmakefileÎļþÖÐijЩ¶¨ÒåÎļþ¼äÒÀÀµ¹ØϵµÄÃèÊöÐÐÓйء£Èç¹ûÓëÄ¿±êÏà¹ØÁ¬µÄÄÇЩÃèÊöÐÐÖ¸¶¨ÁËÏà¹ØµÄcommandÐòÁУ¬ÄÇô¾ÍÖ´ÐÐÕâЩÏà¹ØµÄcommandÃüÁ¼´Ê¹ÔڷֺźÍ(tab)ºóÃæµÄaommand×Ö¶ÎÉõÖÁÓпÉÄÜÊÇNULL¡£Èç¹ûÄÇЩÓëÄ¿±êÏà¹ØÁ¬µÄÐÐûÓÐÖ¸¶¨command£¬ÄÇô½«µ÷ÓÃϵͳĬÈϵÄÄ¿±êÎļþÉú³É¹æÔò¡£
Èç¹ûÃüÁîÐвÎÊýÖк¬ÓÐÁ½¸öðºÅ"::"£¬Ôò´ËʱµÄcommandÐòÁÐÒ²Ðí»áºÍmakefileÖÐËùÓÐÃèÊöÎļþÒÀÀµ¹ØϵµÄÐÐÓйء£´Ëʱ½«Ö´ÐÐÄÇЩÓëÄ¿±êÏà¹ØÁ¬µÄÃèÊöÐÐËùÖ¸ÏòµÄÏà¹ØÃüÁͬʱ»¹½«Ö´ÐÐbuild-in¹æÔò¡£
Èç¹ûÔÚÖ´ÐÐcommandÃüÁîʱ·µ»ØÁËÒ»¸ö·Ç"0"µÄ³ö´íÐźţ¬ÀýÈçmakefileÎļþÖгöÏÖÁË´íÎóµÄÄ¿±êÎļþÃû»òÕß³öÏÖÁËÒÔÁ¬×Ö·û´òÍ·µÄÃüÁî×Ö·û´®£¬make²Ù×÷Ò»°ã»á¾Í´ËÖÕÖ¹£¬µ«Èç¹ûmakeºó´øÓÐ"-i"²ÎÊý£¬Ôòmake½«ºöÂÔ´ËÀà³ö´íÐźš£
MakeÃü±¾Éí¿É´øÓÐËÄÖÖ²ÎÊý£º±êÖ¾¡¢ºê¶¨Òå¡¢ÃèÊöÎļþÃûºÍÄ¿±êÎļþÃû¡£Æä±ê×¼ÐÎʽΪ£º
Make [flags] [macro definitions] [targets]
Unixϵͳϱê־λflagsÑ¡Ïî¼°Æ京ÒåΪ£º
-f file¡¡ Ö¸¶¨fileÎļþΪÃèÊöÎļþ£¬Èç¹ûfile²ÎÊýΪ"-"·û£¬ÄÇôÃèÊöÎļþÖ¸Ïò±ê×¼ÊäÈë¡£Èç¹ûûÓÐ"-f"²ÎÊý£¬Ôòϵͳ½«Ä¬Èϵ±Ç°Ä¿Â¼ÏÂÃûΪmakefile»òÕßÃûΪMakefileµÄÎļþΪÃèÊöÎļþ¡£ÔÚLinuxÖУ¬ GNU make ¹¤¾ßÔÚµ±Ç°¹¤×÷Ŀ¼Öа´ÕÕGNUmakefile¡¢makefile¡¢MakefileµÄ˳ÐòËÑË÷ makefileÎļþ¡£
-i ¡¡¡¡ºöÂÔÃüÁîÖ´Ðзµ»ØµÄ³ö´íÐÅÏ¢¡£
-s ¡¡¡¡³ÁĬģʽ£¬ÔÚÖ´ÐÐ֮ǰ²»Êä³öÏàÓ¦µÄÃüÁîÐÐÐÅÏ¢¡£
-r ¡¡¡¡½ûֹʹÓÃbuild-in¹æÔò¡£
-n ¡¡¡¡·ÇÖ´ÐÐģʽ£¬Êä³öËùÓÐÖ´ÐÐÃüÁµ«²¢²»Ö´ÐС£
-t ¡¡¡¡¸üÐÂÄ¿±êÎļþ¡£
-q¡¡¡¡ make²Ù×÷½«¸ù¾ÝÄ¿±êÎļþÊÇ·ñÒѾ¸üзµ»Ø"0"»ò·Ç"0"µÄ״̬ÐÅÏ¢¡£
-p¡¡¡¡ Êä³öËùÓк궨ÒåºÍÄ¿±êÎļþÃèÊö¡£
-d¡¡¡¡ Debugģʽ£¬Êä³öÓйØÎļþºÍ¼ì²âʱ¼äµÄÏêϸÐÅÏ¢¡£
LinuxÏÂmake±ê־λµÄ³£ÓÃÑ¡ÏîÓëUnixϵͳÖÐÉÔÓв»Í¬£¬ÏÂÃæÎÒÃÇÖ»ÁгöÁ˲»Í¬²¿·Ö£º
-c dir¡¡¡¡ ÔÚ¶ÁÈ¡ makefile ֮ǰ¸Ä±äµ½Ö¸¶¨µÄĿ¼dir¡£
-I dir ¡¡¡¡µ±°üº¬ÆäËû makefileÎļþʱ£¬ÀûÓøÃÑ¡ÏîÖ¸¶¨ËÑË÷Ŀ¼¡£
-h ¡¡¡¡helpÎĵ²£¬ÏÔʾËùÓеÄmakeÑ¡Ïî¡£
-w ¡¡¡¡ÔÚ´¦Àí makefile ֮ǰºÍÖ®ºó£¬¶¼ÏÔʾ¹¤×÷Ŀ¼¡£
ͨ¹ýÃüÁîÐвÎÊýÖеÄtarget £¬¿ÉÖ¸¶¨makeÒª±àÒëµÄÄ¿±ê£¬²¢ÇÒÔÊÐíͬʱ¶¨Òå±àÒë¶à¸öÄ¿±ê£¬²Ù×÷ʱ°´ÕÕ´Ó×óÏòÓÒµÄ˳ÐòÒÀ´Î±àÒëtargetÑ¡ÏîÖÐÖ¸¶¨µÄÄ¿±êÎļþ¡£Èç¹ûÃüÁîÐÐÖÐûÓÐÖ¸¶¨Ä¿±ê£¬ÔòϵͳĬÈÏtargetÖ¸ÏòÃèÊöÎļþÖеÚÒ»¸öÄ¿±êÎļþ¡£
ͨ³££¬makefile Öл¹¶¨ÒåÓÐ clean Ä¿±ê£¬¿ÉÓÃÀ´Çå³ý±àÒë¹ý³ÌÖеÄÖмäÎļþ£¬ÀýÈ磺
clean:
rm -f *.o
ÔËÐÐ make clean ʱ£¬½«Ö´ÐÐ rm -f *.o ÃüÁ×îÖÕɾ³ýËùÓбàÒë¹ý³ÌÖвúÉúµÄËùÓÐÖмäÎļþ¡£
Òþº¬¹æÔò
ÔÚmake ¹¤¾ßÖаüº¬ÓÐһЩÄÚÖõĻòÒþº¬µÄ¹æÔò£¬ÕâЩ¹æÔò¶¨ÒåÁËÈçºÎ´Ó²»Í¬µÄÒÀÀµÎļþ½¨Á¢Ìض¨ÀàÐ͵ÄÄ¿±ê¡£Unixϵͳͨ³£Ö§³ÖÒ»ÖÖ»ùÓÚÎļþÀ©Õ¹Ãû¼´ÎļþÃûºó׺µÄÒþº¬¹æÔò¡£ÕâÖÖºó׺¹æÔò¶¨ÒåÁËÈçºÎ½«Ò»¸ö¾ßÓÐÌض¨ÎļþÃûºó׺µÄÎļþ£¨ÀýÈç.cÎļþ£©£¬×ª»»³ÉΪ¾ßÓÐÁíÒ»ÖÖÎļþÃûºó׺µÄÎļþ£¨ÀýÈç.oÎļþ£©£º
.c:.o
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
ϵͳÖÐĬÈϵij£ÓÃÎļþÀ©Õ¹Ãû¼°Æ京ÒåΪ£º
.o ¡¡Ä¿±êÎļþ
.c ¡¡CÔ´Îļþ
.f ¡¡FORTRANÔ´Îļþ
.s ¡¡»ã±àÔ´Îļþ
.y ¡¡Yacc-CÔ´Óï·¨
.l ¡¡LexÔ´Óï·¨
ÔÚÔçÆÚµÄUnixϵͳϵͳÖл¹Ö§³ÖYacc-CÔ´Óï·¨ºÍLexÔ´Óï·¨¡£ÔÚ±àÒë¹ý³ÌÖУ¬ÏµÍ³»áÊ×ÏÈÔÚmakefileÎļþÖÐÑ°ÕÒÓëÄ¿±êÎļþÏà¹ØµÄ.CÎļþ£¬Èç¹û»¹ÓÐÓëÖ®ÏàÒÀÀµµÄ.yºÍ.lÎļþ£¬ÔòÊ×ÏȽ«Æäת»»Îª.cÎļþºóÔÙ±àÒëÉú³ÉÏàÓ¦µÄ.oÎļþ£»Èç¹ûûÓÐÓëÄ¿±êÏà¹ØµÄ.cÎļþ¶øÖ»ÓÐÏà¹ØµÄ.yÎļþ£¬Ôòϵͳ½«Ö±½Ó±àÒë.yÎļþ¡£
¶øGNU make ³ýÁËÖ§³Öºó׺¹æÔòÍ⻹֧³ÖÁíÒ»ÖÖÀàÐ͵ÄÒþº¬¹æÔò--ģʽ¹æÔò¡£ÕâÖÖ¹æÔò¸ü¼ÓͨÓã¬ÒòΪ¿ÉÒÔÀûÓÃģʽ¹æÔò¶¨Òå¸ü¼Ó¸´ÔÓµÄÒÀÀµÐÔ¹æÔò¡£Ä£Ê½¹æÔò¿´ÆðÀ´·Ç³£ÀàËÆÓÚÕýÔò¹æÔò£¬µ«ÔÚÄ¿±êÃû³ÆµÄÇ°Ãæ¶àÁËÒ»¸ö % ºÅ£¬Í¬Ê±¿ÉÓÃÀ´¶¨ÒåÄ¿±êºÍÒÀÀµÎļþÖ®¼äµÄ¹Øϵ£¬ÀýÈçÏÂÃæµÄģʽ¹æÔò¶¨ÒåÁËÈçºÎ½«ÈÎÒâÒ»¸ö file.c Îļþת»»Îª file.o Îļþ£º
%.c:%.o
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
#EXAMPLE#
ÏÂÃ潫¸ø³öÒ»¸ö½ÏΪȫÃæµÄʾÀýÀ´¶ÔmakefileÎļþºÍmakeÃüÁîµÄÖ´ÐнøÐнøÒ»²½µÄ˵Ã÷£¬ÆäÖÐmakeÃüÁî²»½öÉæ¼°µ½ÁËCÔ´Îļþ»¹°üÀ¨ÁËYaccÓï·¨¡£±¾ÀýÑ¡×Ô"Unix Programmer's Manual 7th Edition, Volume 2A" Page 283-284
ÏÂÃæÊÇÃèÊöÎļþµÄ¾ßÌåÄÚÈÝ£º
#Description file for the Make command
#Send to print
P=und -3 | opr -r2
#The source files that are needed by object files
FILES= Makefile version.c defs main.c donamc.c misc.c file.c dosys.c gram.y lex.c gcos.c
#The definitions of object files
OBJECTS= vesion.o main.o donamc.o misc.o file.o dosys.o gram.o
LIBES= -LS
LINT= lnit -p
CFLAGS= -O
make: $(OBJECTS)
cc $(CFLAGS) $(OBJECTS) $(LIBES) -o make
size make
$(OBJECTS): defs
gram.o: lex.c
cleanup:
-rm *.o gram.c
install:
@size make /usr/bin/make
cp make /usr/bin/make rm make
#print recently changed files
print: $(FILES)
pr $? | $P
touch print
test:
make -dp | grep -v TIME>1zap
/usr/bin/make -dp | grep -v TIME>2zap
diff 1zap 2zap
rm 1zap 2zap
lint: dosys.c donamc.c file.c main.c misc.c version.c gram.c
$(LINT) dosys.c donamc.c file.c main.c misc.c version.c gram.c
rm gram.c
arch:
ar uv /sys/source/s2/make.a $(FILES)
ͨ³£ÔÚÃèÊöÎļþÖÐÓ¦ÏóÉÏÃæÒ»Ñù¶¨ÒåÒªÇóÊä³ö½«ÒªÖ´ÐеÄÃüÁî¡£ÔÚÖ´ÐÐÁËmakeÃüÁîÖ®ºó£¬Êä³ö½á¹ûΪ£º
$ make
cc -c version.c
cc -c main.c
cc -c donamc.c
cc -c misc.c
cc -c file.c
cc -c dosys.c
yacc gram.y
mv y.tab.c gram.c
cc -c gram.c
cc version.o main.o donamc.o misc.o file.o dosys.o gram.o -LS -o make
13188+3348+3044=19580b=046174b
×îºóµÄÊý×ÖÐÅÏ¢ÊÇÖ´ÐÐ"@size make"ÃüÁîµÄÊä³ö½á¹û¡£Ö®ËùÒÔÖ»ÓÐÊä³ö½á¹û¶øûÓÐÏàÓ¦µÄÃüÁîÐУ¬ÊÇÒòΪ"@size make"ÃüÁîÒÔ"@"Æðʼ£¬Õâ¸ö·ûºÅ½ûÖ¹´òÓ¡Êä³öËüËùÔÚµÄÃüÁîÐС£
ÃèÊöÎļþÖеÄ×îºó¼¸ÌõÃüÁîÐÐÔÚά»¤±àÒëÐÅÏ¢·½Ãæ·Ç³£ÓÐÓá£ÆäÖÐ"print"ÃüÁîÐеÄ×÷ÓÃÊÇ´òÓ¡Êä³öÔÚÖ´ÐйýÉÏ´Î"make print"ÃüÁîºóËùÓиĶ¯¹ýµÄÎļþÃû³Æ¡£ÏµÍ³Ê¹ÓÃÒ»¸öÃûΪprintµÄ0×Ö½ÚÎļþÀ´È·¶¨Ö´ÐÐprintÃüÁîµÄ¾ßÌåʱ¼ä£¬¶øºê$?ÔòÖ¸ÏòÄÇЩÔÚprintÎļþ¸Ä¶¯¹ýÖ®ºó½øÐÐÐ޸ĵÄÎļþµÄÎļþÃû¡£Èç¹ûÏëÒªÖ¸¶¨Ö´ÐÐprintÃüÁîºó£¬½«Êä³ö½á¹ûËÍÈëij¸öÖ¸¶¨µÄÎļþ£¬ÄÇô¾Í¿ÉÐÞ¸ÄPµÄºê¶¨Ò壺
make print "P= cat>zap"
ÔÚLinuxÖдó¶àÊýÈí¼þÌṩµÄÊÇÔ´´úÂ룬¶ø²»ÊÇÏֳɵĿÉÖ´ÐÐÎļþ£¬Õâ¾ÍÒªÇóÓû§¸ù¾Ý×Ô¼ºÏµÍ³µÄʵ¼ÊÇé¿öºÍ×ÔÉíµÄÐèÒªÀ´ÅäÖᢱàÒëÔ´³ÌÐòºó£¬Èí¼þ²ÅÄÜʹÓá£Ö»ÓÐÕÆÎÕÁËmake¹¤¾ß£¬²ÅÄÜÈÃÎÒÃÇÕæÕýÏíÊܵ½µ½LinuxÕâ¸ö×ÔÓÉÈí¼þÊÀ½çµÄ´ø¸øÎÒÃÇÎÞÇîÀÖȤ¡£
liuchun12255 ÓÚ 2009-11-04 16:35:25·¢±í:
лл¥Ö÷
XKXQXQXK ÓÚ 2009-11-04 16:01:21·¢±í:
ÐÂÊÖѧϰÁË£¬Ð»Ð»LZ
tjwangzhen ÓÚ 2009-09-20 19:03:00·¢±í:
ѧϰÁË Ð»Ð»Â¥Ö÷·ÖÏí ºÜºÃµÄ×ÊÁÏ
zzy870720z ÓÚ 2009-09-20 16:18:13·¢±í:
ѧϰ£¬¸Õѧ±àÒë
kevinfedora ÓÚ 2009-08-12 16:50:23·¢±í:
ºÃÌû×Ó,ѧϰÁË
wide ÓÚ 2006-05-01 01:05:20·¢±í:
ѧϰÁË