linux 一个超简单的makefile

makefile 自动化变量:code

 

$@ : 规则的目标文件名自动化

 例如:main:main.o test.oclass

                   g++ -Wall -g  main.o test.o -o main thread

 能够写成:test

           main:main.o test.o变量

                   g++ -Wall -g  main.o test.o -o $@ file

 

$< : 规则的第一个依赖文件名程序

  例如:main.o: main.cpp makefile

                   g++ -Wall -g -c main.cpp -o main.odi

  能够写成:

             main.o: main.cpp 

                   g++ -Wall -g -c $< -o main.o

 

$^ : 规则的全部依赖文件列表。

  例如:test.o:test.cpp test.h

                    g++ -Wall -g -c test.cpp test.h -o test.o

  能够写成:

             test.o:test.cpp test.h

                    g++ -Wall -g -c $^ -o test.o

 

 //程序文件包括main.cpp test.cpp test.h

.PHONY:clean
  XX=g++
  exe=dididididididididi
  obj=main.o test.o
  $(exe):$(obj)
          $(XX) -pthread -Wall -g -o $(exe) $(obj)
  main.o:main.cpp test.h
          $(XX) -c main.cpp -o main.o
  test.o:test.cpp test.h
         $(XX) -c test.cpp -o test.o
 clean:
         rm -f *.o $(exe)
相关文章
相关标签/搜索