我想为服务器列表执行多个目标。从makefile输出看来,只有$(SERVERS)目标执行了两次。我希望Launch-%执行两次。我怎样才能让它发挥作用。如何访问目标Launch-%中的每个IP地址?请帮帮我。我有以下make文件源代码和输出。提前谢谢。
Makefile source code:
SERVERS=172.16.0.17 172.16.0.100
test-all: test-port-connectivity
test-port-connectivity: Launch-$(SERVERS)
echo "Test suit 1: Port Connectivity $<"
Launch-%: $(SERVERS)
echo "Launch Server $<"
$(SERVERS):
echo "Server IP - $@"
Output of Makefile:
# make
echo "Server IP - 172.16.0.17"
Server IP - 172.16.0.17
echo "Server IP - 172.16.0.100"
Server IP - 172.16.0.100
echo "Launch Server 172.16.0.17"
Launch Server 172.16.0.17
echo "Test suit 1: Port Connectivity Launch-172.16.0.17"
Test suit 1: Port Connectivity Launch-172.16.0.17
答案 0 :(得分:0)
SERVERS=172.16.0.17 172.16.0.100
LAUNCHES=$(addprefix Launch-, $(SERVERS)) # this will be Launch-172.16.0.17 Launch-172.16.0.100
test-all: test-port-connectivity
test-port-connectivity: $(LAUNCHES)
echo "Test suit 1: Port Connectivity $^"
$(LAUNCHES): Launch-%: %
echo "Launch Server $<"
$(SERVERS):
echo "Server IP - $@"
请注意,$(LAUNCHES)
规则是static pattern rule。 (更简单的pattern rule也足够了,但不够整洁。)另请注意在test-port-connectivity
规则中使用$^
。