(原創) 标准的makefile写法 (C/C++)
一个很典型的Linux C/C++的makefile写法,其它的应用可根据此template修改。
(注意每一行的前面若有空格,是tab,不是space)
1#Source file
2
3SRC = ThreadQueue.cpp
4#Object file
5OBJ = $(SRC:.cpp=.o)
6
7#Output execution file
8PROGRAM = ThreadQueue
9
10#Compiler
11CC = g++
12
13#Include
14
15INCLUDE = -I/usr/include/ncurses -I/usr/include/
16#Linker Parameter
17LINKPARAM = -lpthread -lncurses
18#Options for development
19
20#CFLAGS = -ansi -g -Wall
21#Options for release
22
23CFLAGS = -ansi -O -Wall
24
25
26
27all: $(PROGRAM)
28
29
30
31$(PROGRAM): $(OBJ)
32
33 $(CC) -o $(PROGRAM) $(LINKPARAM) $(OBJ)
34
35.SUFFIXES : .cpp
36
37
38
39.cpp.o:
40
41 $(CC) $(INCLUDE) $(CFLAGS) -c $<
42
43
44
45clean:
46
47 -rm *.o
48
2
3SRC = ThreadQueue.cpp
4#Object file
5OBJ = $(SRC:.cpp=.o)
6
7#Output execution file
8PROGRAM = ThreadQueue
9
10#Compiler
11CC = g++
12
13#Include
14
15INCLUDE = -I/usr/include/ncurses -I/usr/include/
16#Linker Parameter
17LINKPARAM = -lpthread -lncurses
18#Options for development
19
20#CFLAGS = -ansi -g -Wall
21#Options for release
22
23CFLAGS = -ansi -O -Wall
24
25
26
27all: $(PROGRAM)
28
29
30
31$(PROGRAM): $(OBJ)
32
33 $(CC) -o $(PROGRAM) $(LINKPARAM) $(OBJ)
34
35.SUFFIXES : .cpp
36
37
38
39.cpp.o:
40
41 $(CC) $(INCLUDE) $(CFLAGS) -c $<
42
43
44
45clean:
46
47 -rm *.o
48