English 中文(简体)
定义 makefile 中的默认值
原标题:defining default values in makefile

我的造文件有这样一行的线

   CFLAGS = -c -g -D OPT1 -D OPT2

我想通过这样的命令行来通过这些争论

 make ARG1= OPT1 ARG2 =OPT2    

如果我不通过命令行通过这些参数, 我要使用文件来使用在文件文件中定义的默认值。 我该怎么做?

最佳回答

只是做这样的事情 在文件:

OPT1 = MY_OPT_1 # defaults
OPT2 = MY_OPT_2

CFLAGS = -c -g -D $(OPT1) -D $(OPT2)

然后在命令线上:

$ make -e OPT1=SOME_OTHER_OPT1 OPT2=SOME_OTHER_OPT2

在命令行指定 OPT1 和/或 OPT2 的 flues时,这些功能将超越 makefile 中的默认值。

请注意,您可能希望大多数情况下都使用 -e 选项,使用 make 来强制重新构建所有新 OPT1 , OPT2

问题回答

另一种方式是使用 ? {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{> 指派运算运算符}}。只有在没有在运行时定义该值时,它才指定该值。

OPT1?=opt1_default
OPT2?=opt2_default

你们在召唤的时候,

make OPT1=a OPT2=b
# OR
make # to use default values

"https://www.gnu.org/ software/ make/manual/html_node/Setting.html" rel="没有跟随 noreferrer"> more info





相关问题
Command Line Parameters

I m trying to add my file in Visual Studio as command line parameters. I know my code works since when I use fopen("whole path here", "r"), it runs. I then add the file as a command line parameter ...

Read from File, or STDIN

I ve written a command line utility that uses getopt for parsing arguments given on the command line. I would also like to have a filename be an optional argument, such as it is in other utilities ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...