English 中文(简体)
我如何在档案中写明指挥员?
原标题:How do I write the cd command in a makefile?

例如,在我的发言中,我有这样的情况:

all:
     cd some_directory

但当我打上<代码>make<>/code>时。 我只看到了某些方向,如<代码>echo的指挥。

最佳回答

它实际上执行指挥,将目录改为<编码>,但以分处理法进行,既不影响你的工作,也不影响你的工作。

如果你在<条码>中重新寻找更多的任务,则<>指示,你需要添加一个半殖民地,并向其他指挥机构加上。 请注意,你不能使用新行,因为它们被解释为规则的结尾,因此,你为澄清而使用的任何新行都必须用斜体来规避。

例如:

all:
        cd some_dir; echo "I m in some_dir"; 
          gcc -Wall -o myTest myTest.c

并请注意,即使你增加斜坡和一条新线,每一指挥官之间仍有必要有分界线。 这是因为,整个护卫按弹壳划为一线。 正如评论中指出的那样,你应使用和安放,并加入指挥系统,这意味着只有在前指挥成功的情况下才能执行。

all:
        cd some_dir && echo "I m in some_dir" && 
          gcc -Wall -o myTest myTest.c

在从事诸如清理等破坏性工作时,这一点尤其重要,因为如果<条码>d<>c>d因任何原因失败,你会破坏错误的 st。

不过,一种共同的用法是,在子标题中,你可能想去。 这里有一条指挥线选择,因此,你不必打上<条码>cd。 yourself,因此,你的规则希望这样做。

all:
        $(MAKE) -C some_dir all

将改为some_dir,并在该名录中实施Makefile,目标为“all”。 作为一项最佳做法,使用<代码>$(MAKE)而不是直接打电话make<>/code>,因为它谨慎地称之为正确做事(例如,如果你为你的建筑环境使用特别的造物版本),并在使用诸如<代码>-t等某些开关时提供略有不同的行为。

www.un.org/Depts/DGACM/index_french.htm 即便没有产出,也是你所看到的。

问题回答

这里是处理名录和制作的切.。 a. 每一指挥部不使用多线或“cd”,而是界定了简单薄功能:

CHDIR_SHELL := $(SHELL)
define chdir
   $(eval _D=$(firstword $(1) $(@D)))
   $(info $(MAKE): cd $(_D)) $(eval SHELL = cd $(_D); $(CHDIR_SHELL))
endef

那么,你们都必须这样做,就象你这样说:

all:
          $(call chdir,some_dir)
          echo "I m now always in some_dir"
          gcc -Wall -o myTest myTest.c

你们甚至可以做以下工作:

some_dir/myTest:
          $(call chdir)
          echo "I m now always in some_dir"
          gcc -Wall -o myTest myTest.c

你们一旦到那里去就想做些什么? 每个指挥部都在一个小小区执行,因此,小区更改目录,但最终结果是,下届指挥部仍然处于目前的指挥状态。

有了德国全国妇女联盟,你可以做这样的事情:

BIN=/bin
foo:
    $(shell cd $(BIN); ls)

这里所用的模式是:

.PHONY: test_py_utils
PY_UTILS_DIR = py_utils
test_py_utils:
    cd $(PY_UTILS_DIR) && black .
    cd $(PY_UTILS_DIR) && isort .
    cd $(PY_UTILS_DIR) && mypy .
    cd $(PY_UTILS_DIR) && pytest -sl .
    cd $(PY_UTILS_DIR) && flake8 .

我的动机是:

  • The above solution is simple and readable (albeit verbose)
  • I read the classic paper "Recursive Make Considered Harmful", which discouraged me from using $(MAKE) -C some_dir all
  • I didn t want to use just one line of code (punctuated by semicolons or &&) because it is less readable, and I fear that I will make a typo when editing the make recipe.
  • I didn t want to use the .ONESHELL special target because:
    • that is a global option that affects all recipes in the makefile
    • using .ONESHELL causes all lines of the recipe to be executed even if one of the earlier lines has failed with a nonzero exit status. Workarounds like calling set -e are possible, but such workarounds would have to be implemented for every recipe in the makefile.

改变继承

foo: 
    $(MAKE) -C mydir

multi:
    $(MAKE) -C / -C my-custom-dir   ## Equivalent to /my-custom-dir

PYTHON = python3

test: cd src/mainscripts; ${PYTHON} -m pytest

# 保存在原目录中,从上面为我工作的来源进行测试。





相关问题
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 ...

热门标签