英文:
Running a Batch Script through a Make File variable
问题
I have an executable that I am currently running through a batch script. But due to certain requirements, I need to be able to run the batch script through a makefile. My batch script for reference:
@echo off
start name.exe
I have tried the following:
run:
@cmd /C "$(CURDIR)\name.bat"
Command used:
make run
This ran as expected and created a log file, so I tried to run the following:
run:
@cmd /C "@cmd /C "$(CURDIR)\name.bat"
MOVE:=run
.PHONY: all
all: $(MOVE)
Command used:
make all
The above ran just fine and generated the log file and moved some object files that were present to the appropriate locations, which is the desired output. When I tried to extend this logic to the main makefile that I need to work with, of which below is a watered-down version:
run:
@cmd /C "$(CURDIR)/move.bat"
FILE_LIST = BASE_SW
MOVE:=run
FILE_LIST:=BASE_SW (directory containing files)
LIB_FILE:= $(FILE_LIST).a
$(LIB_FILE): $(MOVE) $(other dependency)
@mkdir-mingw -p $(dir name)
@$(AR) cr $(LIB_FILE_APP) $(ALL_OBJS_APP)
.PHONY: all
all: $(LIB_FILE)
Command used:
make all
When this is executed, it is all rosy till the Variable for the batch script is encountered at which point the batch script is not being run.
My main aim is to be able to run the batch script when the makefile has a structure like below:
run:
@cmd /C "$(CURDIR)/move.bat
MOVE:=run
LIB_FILE:= $(FILE).a
$(LIB_FILE): $(MOVE) $(Other dependencies)
recipe
.PHONY: all
all: $(LIB_FILE)
英文:
I have an executable that I am currently running through a batch script. But due to certain requirements, I need to be able to run the batch script through a makefile. My batch script for reference:
@echo off
start name.exe
I have tried the following:
run:
@cmd /C "$(CURDIR)\name.bat"
Command used:
make run
This ran as expected and created a log file, so I tried to run the following:
run:
@cmd /C "@cmd /C "$(CURDIR)\name.bat"
MOVE:=run
.PHONY: all
all: $(MOVE)
Command used:
make all
The above ran just fine and generated the log file and moved some object files that were present to the appropriate locations, which is the desired output. When I tried to extend this logic to the main make file that I need to work with, of which below is a watered-down version:
run:
@cmd /C "$(CURDIR)/move.bat"
FILE_LIST = BASE_SW
MOVE:= run
FILE_LIST:= BASE_SW (directory containing files)
LIB_FILE:= $(FILE_LIST).a
$(LIB_FILE): $(MOVE) $(other dependency)
@mkdir-mingw -p $(dir name)
@$(AR) cr $(LIB_FILE_APP) $(ALL_OBJS_APP)
.PHONY:all
all: $(LIB_FILE)
make all
When this is executed, it is all rosy till the Variable for the batch script is encountered at which point the batch script is not being run.
My main aim is to be able to run the batch script when the make file has a structure like below:
run:
@cmd /C "$(CURDIR)/move.bat
MOVE:= run
LIB_FILE:= $(FILE).a
$(LIB_FILE): $(MOVE) $(Other dependencies)
recipe
.PHONY: all
all: $(LIB_FILE)
答案1
得分: 0
你还没有展示(通过剪切和粘贴)你得到的结果。我会提出一些建议:
首先,你绝对应该移除你的食谱中的 @
前缀。通过添加这些,你正在丢弃了最有用的调试输出,因为 make 不会显示它在做什么。
其次,假设你使用的是足够新的 GNU Make 版本,你应该使用 --trace
选项来查看 make 的操作过程。
第三点,注意通过添加 $(LIB_FILE): $(MOVE) ...
你正在表明你想要在 LIB_FILE
目标运行之前运行 MOVE
目标(前提总是在目标构建之前完全构建)。我不知道这是否符合你的意愿。
英文:
You still haven't shown (via cut and paste) the results you get. I'll make a few points:
First, you should absolutely remove the @
prefix on your recipes. By adding these you are throwing away your most useful debugging output since make doesn't show you what it's doing.
Second, assuming you have a new-enough version of GNU Make you should use the --trace
option to see what make is doing.
Third, note that by adding $(LIB_FILE): $(MOVE) ...
you're saying that you want the MOVE
target to run before the LIB_FILE
target (prerequisites are always completely built before the target is built). I don't know if that's what you want or not.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论