批处理模式规则 [nmake] 中的多个源路径
Multiple source paths in batch-mode rule [nmake]
我正在为我的 makefile 使用 batch-mode rule。目前我有以下目标:
DIR_SRC = src
DIR_INCLUDE = include
DIR_LIB = lib
DIR_BIN = bin\x64
DIR_BUILD = build\x64
{$(DIR_SRC)}.cpp{$(DIR_BUILD)}.obj ::
@echo Compiling...
cl /c /EHsc /Fo$(DIR_BUILD)\ /MD /I$(DIR_INCLUDE) $<
$(EXECUTABLE_NAME) : $(DIR_BUILD)\*.obj
@echo Linking $(EXECUTABLE_NAME)...
link /out:$(DIR_BIN)$(EXECUTABLE_NAME) $(DIR_BUILD)\*.obj
“bin/x64/*.obj”目标使用“src”文件夹内的所有 cpp 文件。是否可以为其添加另一个源路径?
我想要这样的东西
{$(DIR_SRC) $(ANOTHER_DIR)}.cpp{$(DIR_BUILD)}.obj ::
如果您添加一个 second 构建目录来匹配您的第二个源目录,您可以让它工作。例如,如果我们将您的 makefile 修改为:
DIR_SRC = src
DIR_SRC2 = another
DIR_INCLUDE = include
DIR_BIN = bin\x64
DIR_BUILD = build\x64
DIR_BUILD2 = build_another\x64
EXECUTABLE_NAME = foo.exe
{$(DIR_SRC)}.cpp{$(DIR_BUILD)}.obj ::
@echo Compiling...
cl -nologo /c /EHsc /Fo$(DIR_BUILD)\ /MD /I$(DIR_INCLUDE) $<
{$(DIR_SRC2)}.cpp{$(DIR_BUILD2)}.obj ::
@echo Compiling...
cl -nologo /c /EHsc /Fo$(DIR_BUILD2)\ /MD /I$(DIR_INCLUDE) $<
$(DIR_BIN)$(EXECUTABLE_NAME) : $(DIR_BUILD)\*.obj $(DIR_BUILD2)\*.obj
@echo Linking $(EXECUTABLE_NAME)...
link -nologo /out:$@ $**
那么我们将得到:
nmake -nologo
Compiling...
cl -nologo /c /EHsc /Fobuild\x64\ /MD /Iinclude src\*.cpp
s1.cpp
s2.cpp
Generating Code...
Compiling...
cl -nologo /c /EHsc /Fobuild_another\x64\ /MD /Iinclude another\*.cpp
a1.cpp
a2.cpp
Generating Code...
Linking foo.exe...
link -nologo /out:bin\x64\foo.exe build\x64\*.obj build_another\x64\*.obj
其中 src
包含 s1.cpp
和 s2.spp
,而 another
包含 a1.cpp
和 a2.cpp
。
我正在为我的 makefile 使用 batch-mode rule。目前我有以下目标:
DIR_SRC = src
DIR_INCLUDE = include
DIR_LIB = lib
DIR_BIN = bin\x64
DIR_BUILD = build\x64
{$(DIR_SRC)}.cpp{$(DIR_BUILD)}.obj ::
@echo Compiling...
cl /c /EHsc /Fo$(DIR_BUILD)\ /MD /I$(DIR_INCLUDE) $<
$(EXECUTABLE_NAME) : $(DIR_BUILD)\*.obj
@echo Linking $(EXECUTABLE_NAME)...
link /out:$(DIR_BIN)$(EXECUTABLE_NAME) $(DIR_BUILD)\*.obj
“bin/x64/*.obj”目标使用“src”文件夹内的所有 cpp 文件。是否可以为其添加另一个源路径?
我想要这样的东西
{$(DIR_SRC) $(ANOTHER_DIR)}.cpp{$(DIR_BUILD)}.obj ::
如果您添加一个 second 构建目录来匹配您的第二个源目录,您可以让它工作。例如,如果我们将您的 makefile 修改为:
DIR_SRC = src
DIR_SRC2 = another
DIR_INCLUDE = include
DIR_BIN = bin\x64
DIR_BUILD = build\x64
DIR_BUILD2 = build_another\x64
EXECUTABLE_NAME = foo.exe
{$(DIR_SRC)}.cpp{$(DIR_BUILD)}.obj ::
@echo Compiling...
cl -nologo /c /EHsc /Fo$(DIR_BUILD)\ /MD /I$(DIR_INCLUDE) $<
{$(DIR_SRC2)}.cpp{$(DIR_BUILD2)}.obj ::
@echo Compiling...
cl -nologo /c /EHsc /Fo$(DIR_BUILD2)\ /MD /I$(DIR_INCLUDE) $<
$(DIR_BIN)$(EXECUTABLE_NAME) : $(DIR_BUILD)\*.obj $(DIR_BUILD2)\*.obj
@echo Linking $(EXECUTABLE_NAME)...
link -nologo /out:$@ $**
那么我们将得到:
nmake -nologo
Compiling...
cl -nologo /c /EHsc /Fobuild\x64\ /MD /Iinclude src\*.cpp
s1.cpp
s2.cpp
Generating Code...
Compiling...
cl -nologo /c /EHsc /Fobuild_another\x64\ /MD /Iinclude another\*.cpp
a1.cpp
a2.cpp
Generating Code...
Linking foo.exe...
link -nologo /out:bin\x64\foo.exe build\x64\*.obj build_another\x64\*.obj
其中 src
包含 s1.cpp
和 s2.spp
,而 another
包含 a1.cpp
和 a2.cpp
。