我具有以下结构:
当前的生成文件:
CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -flto -Ofast
BIN = bin
# Dependency list for each layered tier
DEP_LOGGER = Logger/src/logger.o
DEP_LEXER = Lexer/src/tokens.o Lexer/src/lexer.o
# Nuua dependencies
DEPENDENCIES = nuua.o $(DEP_LOGGER) $(DEP_LEXER)
ifeq ($(OS),Windows_NT)
EXECUTABLE := nuua.exe
else
EXECUTABLE := nuua
endif
# Main entry point
all: $(BIN)/$(EXECUTABLE)
# Build the nuua programming language
$(BIN)/$(EXECUTABLE): $(DEPENDENCIES)
$(CXX) $(CXXFLAGS) -o $@ $^
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
.PHONY: clean
clean:
rm build/*.o
.PHONY: push
push:
git push
git subtree push --prefix=Lexer Lexer master
git subtree push --prefix=Logger Logger master
这就是窍门:我是否可以自动导入所有文件 在 Lexer / src / 和 Logger / src / 内,然后将所有.o编译到build /目录中,而不是与各自的.cpp文件位于同一文件夹中?当然,我不想单独定义每个.cpp和.o。如果我决定放置一个新的.cpp来自动检测并编译它,我将获得自由。
build / 目录中的.o可以与各自的.cpp文件具有相同的名称。没有.cpp名称,即使它们位于不同的文件夹中也是如此。
您还可以在此处查看存储库:https://github.com/nuua-io/Nuua
编辑
我能得到的最接近的是以下解决方案,但需要build / MODULE文件夹。
# Configuration
CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -flto -Ofast
BIN = bin
BUILD = build
# Dependency list for each layered tier
MODULES = Logger Lexer
# Objects required to build nuua
OBJS = $(BUILD)/nuua.o $(foreach module,$(MODULES),$(patsubst $(module)/src/%.cpp,$(BUILD)/$(module)/%.o,$(wildcard $(module)/src/*.cpp)))
ifeq ($(OS),Windows_NT)
EXECUTABLE := nuua.exe
else
EXECUTABLE := nuua
endif
# Main entry point
all: $(BIN)/$(EXECUTABLE)
# Build the nuua programming language
$(BIN)/$(EXECUTABLE): $(OBJS)
$(CXX) $(CXXFLAGS) -o $@ $^
build/nuua.o: nuua.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
build/Lexer/%.o: Lexer/src/%.cpp Lexer/include/%.hpp
$(CXX) $(CXXFLAGS) -c $< -o $@
build/Logger/%.o: Logger/src/%.cpp Logger/include/%.hpp
$(CXX) $(CXXFLAGS) -c $< -o $@
.PHONY: clean
clean:
rm build/*.o
.PHONY: push
push:
git push
git subtree push --prefix=Lexer Lexer master
git subtree push --prefix=Logger Logger master