【发布时间】:2010-10-21 23:45:15
【问题描述】:
我是 makefile 的新手。我从“使用 GNU make 管理项目”一书中学习了 makefile 创建和其他相关概念。 makefile 现在已经准备好了,我需要确保我创建的文件是好的。这是makefile
#Main makefile which does the build
#makedepend flags
DFLAGS =
#Compiler flags
#if mode variable is empty, setting debug build mode
ifeq ($(mode),release)
CFLAGS = -Wall
else
mode = debug
CFLAGS = -g -Wall
endif
CC = g++
PROG = fooexe
#each module will append the source files to here
SRC := main.cpp
#including the description
include bar/module.mk
include foo/module.mk
OBJ := $(patsubst %.cpp, %.o, $(filter %.cpp,$(SRC)))
.PHONY:all
all: information fooexe
information:
ifneq ($(mode),release)
ifneq ($(mode),debug)
@echo "Invalid build mode."
@echo "Please use 'make mode=release' or 'make mode=debug'"
@exit 1
endif
endif
@echo "Building on "$(mode)" mode"
@echo ".........................."
#linking the program
fooexe: $(OBJ)
$(CC) -o $(PROG) $(OBJ)
%.o:%.cpp
$(CC) $(CFLAGS) -c $< -o $@
depend:
makedepend -- $(DFLAGS) -- $(SRC)
.PHONY:clean
clean:
find . -name "*.o" | xargs rm -vf
rm -vf fooexe
问题
- 上面给出的 makefile 可以很好地用于发布和调试版本。但它的格式是否正确?或者您认为其中有什么缺陷?
- 当使用 make 调用时,上面的 makefile 默认会调试构建。对于发布版本,make mode=release 是必需的。这是正确的方法吗?
- 提供给 g++ 的调试和发布编译器标志是否正确?对于调试,我使用 -g -Wall,对于发布,只使用 -Wall。对吗?
任何帮助都会很棒。
【问题讨论】:
-
您是否计划发布您的软件源代码,包括 Makefile?或者你只是运送二进制文件? IE。除了您和您的团队之外,其他人会看到和使用这个 Makefile 吗?
-
是的。我将发布源代码,因为这将是一个开源项目。