Я новичок в makefiles. Я научился создавать make-файлы и другие связанные с ними концепции из книги «Управление проектами с помощью GNU make». Makefile готов, и мне нужно убедиться, что созданный мной файл в порядке. Вот make-файл
#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
Вопросы
- Приведенный выше make-файл хорошо работает с релизными и отладочными сборками. Но это в правильном формате? Или вы видите в этом какие-то недостатки?
- Выше makefile отлаживает сборку по умолчанию при вызове с помощью make . Для сборок выпуска требуется make mode = release . Это правильный подход?
- Правильны ли флаги компилятора отладки и выпуска, поставляемые в g ++? Для отладки я использую -g -Wall , а для выпуска просто -Wall . Это правильно?
Любая помощь будет отличной.