English 中文(简体)
B. 利用文件指标制定备选办法
原标题:using makefile targets to set build options
  • 时间:2010-05-06 21:15:52
  •  标签:
  • makefile

这要么是轻视的,要么与如何使用这一理论背道而驰,但我要有一个指挥线,即“m变”,而不是“make DEBUG=1”。 我试图设定一个叫做“ de”的电话目标,除确定数字外,别无选择,但“面包 de建设”和“面包建筑 de”之间有差别,即,在一个案例中,建筑工程发生后,变形 set。

是否有办法给予某些目标以优先地位?

感谢您的帮助。

最佳回答

你们也可以通过研究MAKECMDGOALS变量来做到这一点。

ifneq "$(findstring debug, $(MAKECMDGOALS))" ""
DEBUG = 1
endif

build:
    @echo build and DEBUG is [$(DEBUG)]

debug:

这就是你称之为:

$ make build
build and DEBUG is []
$ make build debug
build and DEBUG is [1]
make: Nothing to be done for `debug .
$ make debug build
make: Nothing to be done for `debug .
build and DEBUG is [1]
问题回答

见http://www.gnu.org/software/make/manual/make.html#Setting”rel=“noreferer”>。

您可撰写以下文件:

.PHONY: debug
debug:
        $(MAKE) -$(MAKEFLAGS) build DEBUG=1

build:
        echo makeflags= $(MAKEFLAGS)  debug=${DEBUG}

这至少将与马克、博迪·马克和尼克斯公司合作。 我没有尝试所有其他执行。

可以与GnuMake做的一件事是使用宏观方法,将其扩大到与foreach订立的规则。 类似:

TARGETS := build all foo bar baz

define DEBUG_TARGET_RULE
$(1).debug:
        $$(MAKE) DEBUG=1 $(1)
debug.$(1):
        $$(MAKE) DEBUG=1 $(1)
endef

$(foreach target,$(TARGETS),$(eval $(call DEBUG_TARGET_RULE,$(target))))

这将使你能够打上<代码>make debug.foo或make foo.debug,并将自动改成make DEBUG=1 foo,并针对您在$>(TARGETS上提出的任何目标开展工作。

如果你的精减将只用于建筑目标,那么你还可以打上灯光灯,以便你能够打上<条码>make debug<>/code>或<条码>make Building,其中<条码>make 建设<>/条码>为非建议。

但是,就你的实际问题而言,我不熟悉能够回答问题的档案。

一种做法是,在建设和减小目标中建立附属关系,制定规则,但将你的欺骗选择纳入减标目标。 简单的例子:

文件

program:        program.c
                gcc -o program program.c
debug:          program.c
                gcc -D DEBUG -o program program.c

方案c

#include <stdio.h>
int main(void) {
#ifdef DEBUG
  printf("DEBUG on!
");
#endif
  printf("in the program
");
  return 0;
}




相关问题
makefile: how to show line numbers for debugging?

Is there a way to have make display the line number where it declares an error? The -d switch doesn t seem to cut it. Updated: Example output: Reaping winning child 0x08aa8648 PID 9381 /bin/sh: ...

What is the reasoning behind the Makefile whitespace syntax?

I m revisiting Python after Michael Sparks s excellent walk through of Peter Norvig s Python spell checker at the SO DevDay in London. One of the points he highlighted was how clean Python is to look ...

Debugging GNU make

Is there a command line way in make to find out which of the prerequisites of a target is not updated?

How to add an all rule to this Makefile?

I want to just type make all and have the following Makefile do everything it s supposed to do: LEX = lex YACC = yacc CC = gcc calcu: y.tab.o lex.yy.o $(CC) -o calcu y.tab.o lex.yy.o -ly -lfl ...

How to discover number of *logical* cores on Mac OS X?

How can you tell, from the command line, how many cores are on the machine when you re running Mac OS X? On Linux, I use: x=$(awk /^processor/ {++n} END {print n+1} /proc/cpuinfo) It s not ...

Using extern in C doesn t work as expected

I have created two files: tunables.h #ifndef TUNABLES_H #define TUNABLES_H void tunables_load_conservative(); void tunables_load_aggressive(); extern int timer_x; #endif /*TUNABLES_H */ and ...

热门标签