????Linux ?? make ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????Щ????????? make ???????????????
????Make ??ι?????
???????????????????????????make ???????????в???????????????Щ????????????? “Makefile” ????????????????У??????????????????????????????????????????? Makefiles ??ι?????????????
?????? make ??????????????????? Makefile ??????????????????????Щ?????????????????????Щ??????? Makefile ???????????????????????????????????????????????????????????? make ??????????
????????????????????????????????????????? make ?????????????????????????????????????????????????????????????????
????Make ???????
???????????????????????????
????OS —— Ubunut 13.04
????Shell —— Bash 4.2.45
????Application —— GNU Make 3.81
???????????????????
????$ ls
????anotherTest.c Makefile test.c test.h
?????????? Makefile ???????
????all: test
????test: test.o anotherTest.o
????gcc -Wall test.o anotherTest.o -o test
????test.o: test.c
????gcc -c -Wall test.c
????anotherTest.o: anotherTest.c
????gcc -c -Wall anotherTest.c
????clean:
????rm -rf *.o test
???????????????? Linux ???Щ make ?????????????
????1. ???????????
?????????????????????????????? make ?????? make ??????????? all??
????$ make
????gcc -c -Wall test.c
????gcc -c -Wall anotherTest.c
????gcc -Wall test.o anotherTest.o -o test
??????????? make ???????δ???????????????????
???????????β????????????????Щ .o ?????????????
????$ ls
????anotherTest.c anotherTest.o Makefile test test.c test.h test.o
???????????????? test.c ????????Щ??????????? make ???????
????$ make
????gcc -c -Wall test.c
????gcc -Wall test.o anotherTest.o -o test
??????????????? test.o ???±?????????????? Test.o ??????±???
???????????????е???????????????? test????????????? clean:
????$ make clean
????rm -rf *.o test
????$ ls
????anotherTest.c Makefile test.c test.h
???????????????е? .o ??????????? test ??????????
????2. ??? -B ???????????????????????
???????????????????? make ???????????Щ?????α????????и??????????????????????? make ????????????????????? -B ??
????????????????
????$ make
????make: Nothing to be done for `all’.
????$ make
????make: Nothing to be done for `all’.
????$ make -B
????gcc -c -Wall test.c
????gcc -c -Wall anotherTest.c
????gcc -Wall test.o anotherTest.o -o test
???????????????? make ??????????κ????????? make -B ???????????е?????????????????????
????3. ??? -d ????????????
?????????????? make ?????????????????? -d ??
????????????????
$ make -d | more
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation?? Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Reading makefiles…
Reading makefile `Makefile’…
Updating makefiles….
Considering target file `Makefile’.
Looking for an implicit rule for `Makefile’.
Trying pattern rule with stem `Makefile’.
Trying implicit prerequisite `Makefile.o’.
Trying pattern rule with stem `Makefile’.
Trying implicit prerequisite `Makefile.c’.
Trying pattern rule with stem `Makefile’.
Trying implicit prerequisite `Makefile.cc’.
Trying pattern rule with stem `Makefile’.
Trying implicit prerequisite `Makefile.C’.
Trying pattern rule with stem `Makefile’.
Trying implicit prerequisite `Makefile.cpp’.
Trying pattern rule with stem `Makefile’.
--More--
??????????????????????????????? more ??????????????????
????4. ??? -C ???????
?????????? make ?????????????·????????? Makefile ?????л??????
?????????????????????????????:
????$ ls
????file file2 frnd frnd1.cpp log1.txt log3.txt log5.txt
????file1 file name with spaces frnd1 frnd.cpp log2.txt log4.txt
???????????????е? make ????? Makefile ????????? ../make-dir/ ???£??????????????
????$ make -C ../make-dir/
????make: Entering directory `/home/himanshu/practice/make-dir’
????make: Nothing to be done for `all’.
????make: Leaving directory `/home/himanshu/practice/make-dir
??????????? make ?????????е?????????£???????У???????л???????
????5. ??? -f ?????????????? Makefile
????????????????? Makefile ????????????? my_makefile ??????????????????????? make ????????? Makefile????????? -f ??
????make -f my_makefile
????????????????make ??????????? my_makefile ?????? Makefile??