$* - a $@ - a.t $? - file.h a.c $< - a.c .c.t : $* - b $@ - b.t $? - file.h b.c $< - b.c .c.t : $* - c $@ - c.t $? - file.h c.c $< - c.c result - 24 - $@ - result $? - d.t a.t b.t c.t , .k.t , - .c.t - , , result. "?" , - . "@" - - , - - ._2. make - . Make- , make -r. . , : .out - ; .o - ; .c - ; .f - ; .p - ; .s - ; .l - lex; .y - yacc; , Make- : LOADLIBES = # AS = as - # CC = cc # - CFLAGS = # - PC = pc # - PFLAGS = # - FF = f77 # f77- FFLAGS = # f77- LEX = lex # LFLAGS = # lex YACC = yacc # YFLAGS = # yacc Make-, , CFLAGS = -O, CFLAGS Make-e. - Make-, - . - 25 - .c .f .p .s .l .y | | | | | | |------------------------- | | ---> .out <--- .o --- | | -------------------------- | | | | | | .p .f .c .s .l .y | --- | | .l .y - 26 - .l.out: $(LEX) $< $(CC) $(CFLAGS) lex.yy.c $(LOADLIBES) -ll -o $@ rm lex.yy.c .y.out: $(YACC) $(YFLAGS) $< $(CC) $(CFLAGS) y.tab.c $(LOADLIBES) -ly -o $@ rm y.tab.c .f.out: $(FF) $(FFLAGS) $< $(LOADLIBES) -o $@ -rm $*.o .o.out: $(CC) $(CFLAGS) $< $(LOADLIBES) -o $@ .c.out: $(CC) $(CFLAGS) $< $(LOADLIBES) -o $@ .p.out: $(PC) $(PFLAGS) $< $(LOADLIBES) -o $@ .s.out: $(CC) $(CFLAGS) $< $(LOADLIBES) -o $@ .l.c: $(LEX) $< mv lex.yy.c $@ .y.c: $(YACC) $(YFLAGS) $< mv y.tab.c $@ .l.o: $(LEX) $(LFLAGS) $< $(CC) $(CFLAGS) -c lex.yy.c rm lex.yy.c; mv lex.yy.o $@ .y.o: $(YACC) $(YFLAGS) $< $(CC) $(CFLAGS) -c y.tab.c rm y.tab.c; mv y.tab.o $@ .s.o: $(AS) -o $@ $< .f.o: $(FF) $(FFLAGS) -c $< .c.o: $(CC) $(CFLAGS) -c $< - 27 - .p.o: $(PC) $(PFLAGS) -c $< .SUFFIXES: .out .o .c .f .p .y .l .s , f[1-6].c - result. f[1-3].c # include file1.h # include file2.h f[4-6].c # include file3.h result: CFLAGS = -O LDFLAGS = -s -n -o OBJS = f1.o f2.o f3.o f4.o f5.o f6.o result: ${OBJS} ${CC} ${OBJS} ${LDFLAGS} $@ f1.o f2.o f3.o : file1.h file2.h f4.o f5.o f6.o : file3.h : cc -O -c f1.c cc -O -c f2.c cc -O -c f3.c cc -O -c f4.c cc -O -c f5.c cc -O -c f6.c cc f1.o f2.o f3.o f4.o f5.o f6.o -s -n -o result touch file3.h , : cc -O -c f4.c cc -O -c f5.c cc -O -c f6.c cc f1.o f2.o f3.o f4.o f5.o f6.o -s -n -o result touch f3.c - 28 - cc -O -c f3.c cc f1.o f2.o f3.o f4.o f5.o f6.o -s -n -o result ( -r), , Make-. , - a1.t, a2.t a3.t, sed, - a1.c a2.c a3.c. Make- : CFLAGS = -O LDFLAGS = -o OBJS = a1.o a2.o a3.o f1.o f2.o f3.o f4.o f5.o f6.o result: ${OBJS} ${CC} ${OBJS} ${LDFLAGS} $@ f1.o f2.o f3.o : file1.h file2.h f4.o f5.o f6.o : file3.h a1.c: a1.t a2.c: a2.t a3.c: a3.t .t.c: sed s/aaa/bbb/ < $< > $*.c .SUFFIXES: .t : sed s/aaa/bbb/ < a1.t > a1.c cc -O -c a1.c sed s/aaa/bbb/ < a2.t > a2.c cc -O -c a2.c sed s/aaa/bbb/ < a3.t > a3.c cc -O -c a3.c cc -O -c f1.c cc -O -c f2.c cc -O -c f3.c cc -O -c f4.c cc -O -c f5.c cc -O -c f6.c cc a1.o a2.o a3.o f1.o f2.o f3.o f4.o f5.o f6.o -o result Make - . SUFFIXES t, - c . - 29 - 8. Make- : ( - ). , , , . : _ (, , , , ). Make- : _ . ( _ ). _ - : __(_____) , - __((____)) Make- libP.a: L = libP.a CFLAGS = -O $(L):: ar r $(L) $(L):: $(L)(Ia.o) $(L)(La.o) $(L)(Da.o) # Iabs, Labs, Dabs - $(L)(Iabs.o): lib/Ia.c $(CC) $(CFLAGS) lib/Ia.c ar r $(L) Ia.o -rm -f Ia.o $(L)(Labs.o): lib/La.c $(CC) $(CFLAGS) lib/La.c ar r $(L) La.o -rm -f La.o $(L)(Dabs.o): lib/Da.c $(CC) $(CFLAGS) lib/Da.c ar r $(L) Da.o -rm -f Da.o - - 30 - Make- . "$(L)::" - . - , , 100, 100 . - , , , , Make-. , , . Make-, . mylib m1.c m2.c m3.c m4.s m5.c m6.c m7.s , - : m4.o m2.o m1.o m5.o m6.o m7.o m3.o Make-: - 31 - CFLAGS = -O SRC = m1.c m2.c m3.c m4.s m5.c m6.c m7.s LIB = mylib ${LIB}: ${SRC} echo $? | sed s/\\.[cs]/\\.o/g > list make `cat list` ar cr $@ `cat list` lorder $@ | tsort > list -@if cmp list topology ; \ then \ rm -f `cat list` list;\ else \ ar x ${LIB}; rm $@;\ mv list topology;\ ar cr $@ `cat topology`;\ rm -f `cat topology`;\ echo $@ .;\ fi ranlib ${LIB} echo $@ . m1.c : x.h touch m1.c m2.c : x.h y.h touch m2.c m3.c : x.h touch m3.c m5.c : y.h touch m5.c m6.c : x.h touch m6.c . , . e . , "?" - , - mylib. , . , Make- , o, make . list - . echo $? | sed s/\\.[cs]/\\.o/g > list - 32 - list o. sed - c s o. , list -, . , , : make `cat list` . mylib ar rc mylib `cat list` mylib , , , ( ar cr). "make `cat list`" Makefile ( Make- ). , Make-. , . make , - Make-. , - Make- - . , -, make . , . Make- lorder tsort. Lorder - , tsort , - , .. . Make- , list topology. : , topology list. . topology list , -, topology, -, ( ), - 33 - . - ar x mylib . . , topology : ar rc mylib `cat topology` shell if : if _;\ then \ _;\ else \ _;\ fi Makefile : -@if cmp list topology ; \ then \ rm -f `cat list` list;\ else \ ar x $(LIB); rm $@;\ mv list topology;\ ar cr $@ `cat topology`;\ rm -f `cat topology`;\ echo $@ .;\ fi : ''-@if cmp list topology ; \ 8 . "-" , shell if 0. "@" . Make- . ( ) LIB, SRC . , ranlib $@. . - 34 - , make -s cc -c m1.c cc -c m2.c cc -c m3.c as - -o m4.o m4.s cc -c m5.c cc -c m6.c as - -o m7.o m7.s cmp: topology mylib . mylib . mylib , - , x.h touch x.h make -s cc -c m1.c cc -c m2.c cc -c m3.c cc -c m6.c mylib . m5.c. - : m5 m1 make -s cc -c m5.c mylib . mylib . topology m4.o m2.o m5.o m1.o m6.o m7.o m3.o . - SRC Make-. m8.c , - m5.c cc -c m8.c list topology : char 12, line 3 mylib . mylib . topology m4.o m2.o m8.o m5.o m1.o m6.o m7.o m3.o - 35 - m1.c , m2.c, m2.c m1.c, .. - m1 m2 make -s cc -c m1.c tsort: tsort: m2.o tsort: m1.o mylib . mylib . tsort - . , , - . mylib , , . 9. Make Make- Makefile. make make -f _ Make- , Make-, make make -f _1 -f _2 .. Make- , . Make- make Make-, : LLL: a b c d make -k -f _Make- $? , - , -k - Make-, . , Make-, Makefile . - . , Make- - 36 - SRC = a1.c a2.c a3.c # a3.c # 9 , , SRC. "<" "*" , - . , - shell. - "-" "@" make. make - . - , shell. , , ''#cat file , "exec(# cat file);" -? , . : _:[:]; __ [# ] ";" . Make- , . , - , - () Make-. , -, - : print: f1 f2 f3 print $? touch print .DEFAULT: touch print print. , - . DEFAULT , print . touch , - . - 37 - , make . make : -d , Make-. -f Make-. - Makefile makefile. , Makefile. - -f . -i . IGNORE. -k , - , - . -n , Make- . -p Make-. -q . , - -1, 0. -r - , . -s . - SILENT. -S Make- - - . -t (- ) . 10. Make- Make- - , - . mkmf. . - f.h, f1.c, f2.c f3.c, - a.out: - 38 - /* ** f.h */ # include <stdio.h> # include <ctype.h> # include <time.h> /* ** f1.c */ # include f.h main(ac, av) int ac; char **av; { f1(); f2(); f3(); printf(" example.\n"); } f1(){ return; } /* ** f2.c */ # include f.h int f2(){ return( a2()); } # include <stat.h> char *a2(){ return; } /* ** f3.c */ # include f.h int f3(){ return( nn()); } char *nn(){ return; } . mkmf. Makefile a.out: - 39 - DEST = . EXTHDRS = /usr/include/ctype.h \ /usr/include/stat.h \ /usr/include/stdio.h \ /usr/include/time.h HDRS = f.h LDFLAGS = LIBS = LINKER = cc MAKEFILE = Makefile OBJS = f1.o f2.o f3.o PRINT = pr PROGRAM = a.out SRCS = f1.c f2.c f3.c all: $(PROGRAM) $(PROGRAM): $(OBJS) $(LIBS) @echo -n " $(PROGRAM) ..." @$(LINKER) $(LDFLAGS) $(OBJS) \ $(LIBS) -o $(PROGRAM) @echo "." clean:; @rm -f $(OBJS) depend:; @mkmf -f $(MAKEFILE) \ PROGRAM=$(PROGRAM) DEST=$(DEST) index:; @ctags -wx $(HDRS) $(SRCS) install: $(PROGRAM) @echo $(PROGRAM) $(DEST) @install -s $(PROGRAM) $(DEST) print:; @$(PRINT) $(HDRS) $(SRCS) program:; $(PROGRAM) tags: $(HDRS) $(SRCS) @ctags $(HDRS) $(SRCS) update: $(DEST)/$(PROGRAM) - 40 - $(DEST)/$(PROGRAM): $(SRCS) $(LIBS) \ $(HDRS) $(EXTHDRS) @make -f $(MAKEFILE) \ DEST=$(DEST) install ### f1.o: f.h /usr/include/stdio.h \ /usr/include/ctype.h \ /usr/include/time.h f2.o: f.h /usr/include/stdio.h \ /usr/include/ctype.h \ /usr/include/time.h \ /usr/include/stat.h f3.o: f.h /usr/include/stdio.h \ /usr/include/ctype.h \ /usr/include/time.h mkmf - - /usr/new/lib/p.Makefile, - . mkmf : - - , include- , - -. . Makefile , - . , mkmf, , . Makefile, -, : CFLAGS -; DEST , ; EXTHDRS include-; HDRS include-, ; LIBS ; - 41 - MAKEFILE Make-; OBJS , - ; PROGRAM , ; SRCS ; EXTHDRS, HDRS, OBJS, SRCS mkmf . Makefile , . Make-, : all , ; clean ; depend Make- - Makefile; index ; install , ; print include- ; tags ./tags - , , ; update Makefile, , . , . - 42 - f[123].c, f.h Makefile, DEST /usr/tmp - PROGRAM - example. : % make program install clean cc -c f1.c cc -c f2.c cc -c f3.c example ... . example example /usr/tmp % make index a2 5 f2.c char *a2(){ f1 11 f1.c f1(){ f2 2 f2.c int f2(){ f3 2 f3.c int f3(){ main 5 f1.c main(ac, av) nn 6 f3.c char *nn(){ mkmf Makefile - . - /usr/new/lib/l.Makefile - LIBRARY ( ) extract (- ), library ( ). - /usr/new/lib/[lp].Makefile . l.Makefile p.Makefile. - 43 - 1. " ., . UNIX. - .: , 1986." AI 2. " . UNIX.- .: , 1986." AN 3. " . UNIX. - .: , 1987." AM 4. " . UNIX. - .: , 1985." AE 5. " . - : , 1985." AK 6. " / .. , .. , .. . - .: , 1985." AH 7. " ., ., . . . - .: , 1985." AF 8. " . UNIX. - .: , 1985." AJ 9. " ., . . - .: , 1986." AG 10. "Aho A. V., Kernighan Brian V. W., Weinberger Peter J. AWK - a pattern scanning and processing language. Second edition. UNIX Programmers manual, 42 BSD, 1980. Bell Laboratries: Murray Hill, New Jersey, 1978." AL 11. "Feldman S. I. Make - a program maitaining computer pro- gramms. Bell Laboratries: Murray Hill, New Jersey, 1978." AB 12. "Joy W. N. An introduction the UNIX C-shell. UNIX Pro- grammers manual, 42 BSD, 1980. Bell Laboratries: Murray Hill, New Jersey, 1978." AA 13. "Johnson S. C. YACC - yet another compiler-compiler. Comp. Sci. tech. rep. N 32. Bell Laboratries: Murray Hill, New Jersey, 1975." AD 14. "Lesk M. E. Lex - lexical analyzer generator. Comp. Sci. tech. rep. N 39. Bell Laboratries: Murray Hill, New Jer- sey, 1975." AC - 44 - ......................................... 2 1. .......................................... 3 2. Make- ................ 4 3. Make ............................. 10 4. ..................... 13 5. Make- ................ 16 6. Make- .................. 18 7. .............................. 21 8. Make- ............... 30 9. Make ........ 36 10. Make- ...... 38 ........................................ 44 - 45 -