例如:
CC := gcc
CFLAGS := -Wall -g -Os
SHDIR := ../common
OBJS = ftserve.o $(SHDIR)/common.o
all: ftserve
ftserve: $(OBJS)
@$(CC) -o ftserve $(CFLAGS) $(OBJS)
$(OBJS) : %.o: %.c
@$(CC) -c $(CFLAGS) $< -o $@
.PHONY:
clean:
@rm -f *.o ftserve
@rm -f ../common/*.o
@echo Done cleaning
中 all有什么用?
转载自:http://bbs.csdn.net/topics/300199783
Makefile 的规则格式是这样的
1
2
3
4
|
target ... : prerequisites ...
command
...
...
|
比如 lz 要把一个 hello.cpp 文件编译成 hello
1
2
3
4
5
6
7
|
all : hello another
hello : hello.cpp
g++ -o $@ $<
another : another.cpp
g++ -o $@ $<
|
直接 make 或 make all 的话会执行 hello.cpp 和 another.cpp 的编译命令
后面不加参数的话,会把第一个目标作为默认的
make hello 的话只编译 hello.cpp
make another 的话只编译 another.cpp