我想尝试GCC整个程序优化。为此,我必须立即将所有C文件传递给编译器前端。但是,我使用makefile来自动化我的构建过程,而且在makefile魔术方面我不是专家。
如果我想仅使用一次GCC调用来编译(甚至链接),我该如何修改makefile?
供参考 - 我的makefile如下所示:
LIBS = -lkernel32 -luser32 -lgdi32 -lopengl32
CFLAGS = -Wall
OBJ = 64bitmath.o \
monotone.o \
node_sort.o \
planesweep.o \
triangulate.o \
prim_combine.o \
welding.o \
test.o \
main.o
%.o : %.c
gcc -c $(CFLAGS) $< -o $@
test: $(OBJ)
gcc -o $@ $^ $(CFLAGS) $(LIBS)
答案 0 :(得分:56)
LIBS = -lkernel32 -luser32 -lgdi32 -lopengl32
CFLAGS = -Wall
# Should be equivalent to your list of C files, if you don't build selectively
SRC=$(wildcard *.c)
test: $(SRC)
gcc -o $@ $^ $(CFLAGS) $(LIBS)
答案 1 :(得分:41)
SRCS=$(wildcard *.c)
OBJS=$(SRCS:.c=.o)
all: $(OBJS)
答案 2 :(得分:1)
您需要取出后缀规则(%。o:%。c)以支持大爆炸规则。 像这样:
LIBS = -lkernel32 -luser32 -lgdi32 -lopengl32
CFLAGS = -Wall
OBJ = 64bitmath.o \
monotone.o \
node_sort.o \
planesweep.o \
triangulate.o \
prim_combine.o \
welding.o \
test.o \
main.o
SRCS = $(OBJ:%.o=%.c)
test: $(SRCS)
gcc -o $@ $(CFLAGS) $(LIBS) $(SRCS)
如果您要尝试GCC的整个程序优化,请制作 确保在上面的CFLAGS中添加适当的标志。
在阅读这些标志的文档时,我会看到关于链接时的注释 优化;你也应该调查这些。