如何根据命令行输入更新makefile变量?

问题描述 投票:0回答:1

假设我在makefile中定义了一个变量'ABC = 0'。现在,当运行makefile时,会向用户询问“它是什么类型的程序?”,如果用户输入“ pq”,则将makefile变量“ ABC”更新为1,否则保持不变。

makefile gnu-make
1个回答
0
投票

不是为用户交互而设计的,但是它可以将该任务委托给脚本。

考虑此脚本:

#!/bin/bash

echo What type of program is it?
read

if [ "$REPLY" = pq ]; then
    echo 1
else
    echo 0
fi

使执行该脚本,收集输出并将其分配给变量。唯一的窍门是它将收集输出的[[all,因此不属于任何内容(例如“它是什么类型的程序”)都应从脚本中删除:

#!/bin/bash read if [ "$REPLY" = pq ]; then echo 1 else echo 0 fi
并由makefile处理:

$(info What type of program is it?) ABC := $(shell ./ask.bsh)

© www.soinside.com 2019 - 2024. All rights reserved.