【发布时间】:2019-04-30 20:55:42
【问题描述】:
我对制作非常陌生。到目前为止,我已经设法使用在线找到的一些 GNU 手册和教程创建了以下内容。我想让 make 将所有创建的目标文件放入目录“obj”中。我已经能够成功创建此目录,但我不知道如何将文件放入其中。任何建议或提示表示赞赏。另外,一般来说,除了 GNU 文档之外,是否还有学习如何使用 make 的好资源?
# specify compiler
CC := gcc
# set compiler flags
CFLAGS := -M -Igen/display -Igen/logic -Iman -Ilib/include -pipe -march=native -ftime-report
# set linker flags
LDFLAGS := -lglut32 -loglx -lopengl32 -Llib
# specify separate directory for objects
OBJDIR := obj
# include all sources
SOURCES := $(wildcard gen/display/*.c gen/logic/*.c man/*.c)
# create objects from the source files
OBJECTS := $(patsubst %.c,%.o,$(SOURCES))
# specify the name and the output directory of executable
EXECUTABLE := win32/demo
# all isn't a real file
all: $(EXECUTABLE)
# compile
%.o: %.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $(OBJDIR)/$@
# link
$(EXECUTABLE): $(OBJECTS)
$(CC) $^ $(LDFLAGS) -o $@
# clean objects
clean:
@$(RM) -rf $(OBJDIR)
.PHONY: all clean
【问题讨论】: