English 中文(简体)
2. 造册目录
原标题:Get makefile directory
  • 时间:2010-01-05 08:19:26
  •  标签:
  • makefile

我正在分发我的剪辑文件以及一份文件。 现在,文件目录与文件目录相同。

有哪些变数(如果有的话)使我能够检索到现在的造册的目录? 这样,我就可以利用这一变量来具体规定我的汇编方法。

我的发言如下:

all:
    g++ ($makeFileDir)/main.cpp ($makeFileDir)/hello.cpp ($makeFileDir)/factorial.cpp -o ($makeFileDir)/hello.exe

www.un.org/Depts/DGACM/index_spanish.htm Edit:我正在视窗上查阅我的论文。

最佳回答

I remember I had the exact same problem. It s not possible, as far as I remember. The best bet you can have is to pass it as a variable. That is both cross platform and guaranteed to work, as you know the makefile dir at invoke time (otherwise you can t invoke it).

换言之,你可以做一小小trick,意思是你试图把你目前的道路(你可以拿到作为核心的美元(CURDIR))与援引证明书的道路(这可以trick笑,取决于你)结合起来。

问题回答

这里是获取马克图书目录的跨平台方式,该目录应完全 she。

makeFileDir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

请注意,这将为您提供Makefile目前被解释的名录<>。 如果你使用另一个人的陈述列入一份男性档案,你可能会有坏(或好!)的惊讶。

如果你利用最近对窗户(即Chocolatey s的话,就足够了。

Issues with older make for Windows

根据您在视窗上重新使用这一版本,处理回击可能会有不一致之处。 您可能需要以下一种变量。 The s case for 例如,GnuWin s ,3.81 binary

  • Make the path separator consistent. The statement below uses forward slashes only, just swap and / to get the opposite behavior. From my experience (with GnuWin s make), you might have to use forward slashes to use such a variable for make include statements or to use it in VPATH. But you would of course need backslashes in the DOS shell, and therefore in recipes... You might need two versions of the variable, but at least the substitution makes sure that the path separator is consistent!
makeFileDir := $(subst ,/,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
  • The abspath function of GnuWin make 3.81 is broken and doesn t handle paths with drive letters in it. Here is a workaround to handle Windows absolute paths (with drive letter) as well. You can then use it to get the directory of the Makefile (here with the path separator substitution as well). I won t explain the details, but the workaround simply returns the argument if that s already a Windows absolute path, i.e. if there is : in the root of the path, and uses the builtin abspath otherwise.
define fixabspath
$(if $(findstring :,$(firstword $(subst /, ,$(subst ,/,$(1))))),$$
$(1),$
$(abspath $(1)))

makeFileDir := $(subst ,/,$(dir $(call fixabspath,$(lastword $(MAKEFILE_LIST)))))

  • There might be sources I m omitting here and I m sorry for that. It s been a long time ago.
  • In the fixabspath definition, $ are just here to split the line for readability.
  • The MAKEFILE_LIST variable contains a list of the Makefiles being interpreted, the last one being the current one. See the corresponding manual page.
  • If I remember correctly, this also works with macOS native make.

cy子和lin子使用I ve通过在纸面上直接从规则中提炼而解决这一问题:

do.%: %.cpp
  echo "Running command in " `pwd`
  somecommand $^

您可使用美元。

接着:





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