私はmakefilesを初めて使用します。「GNUmakeによるプロジェクトの管理」の本から、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は、リリースビルドとデバッグビルドでうまく機能します。しかし、それは正しい形式ですか?それとも、そこに欠陥がありますか?
- 上記のmakefileは、 makeを使用して呼び出された場合、デフォルトでデバッグビルドを実行します。リリースビルドの場合、make mode=releaseが必要です。これは正しいアプローチですか?
- g ++に提供されているデバッグおよびリリースコンパイラフラグは正しいですか?デバッグには-g-Wallを使用し、リリースには-Wallのみを使用します。これは正しいですか?
どんな助けでも素晴らしいでしょう。