【问题标题】:Makefile - Issue with referencing parent directoryMakefile - 引用父目录的问题
【发布时间】:2012-04-29 19:46:56
【问题描述】:

我有一个来自示例项目的 makefile,它尝试将父目录引用为“../bin”。运行“make install”时,这似乎不起作用。我得到的错误是:

cp: cannot stat `/bin/build/*': No such file or directory

项目的布局是:

/bin

/src/makefile

(所以当我运行makefile时,当前目录是/src/)

似乎用“..”引用父目录是不正确的。我知道我可以使用 {$CURDIR} 变量引用当前目录,但我需要知道正确的变量或引用父目录的方法,以便正确引用 /bin/。我想我可以通过移动 makefile 来解决这个问题,但我想知道这样做的真正方法以备将来使用。

makefile 看起来像这样(问题用##### 问题###### 突出显示)

# The name of the extension.
extension_name := xulschoolhello

# The UUID of the extension.
extension_uuid := helloworld@xulschool.com

# The name of the profile dir where the extension can be installed.
profile_dir := 8mtbjosv.development

# The zip application to be used.
ZIP := zip

# The target location of the build and build files.
bin_dir := ../bin ##### problem ######

# The target XPI file.
xpi_file := $(bin_dir)/$(extension_name)2.xpi

# The type of operating system this make command is running on.
os_type := $(patsubst darwin%,darwin,$(shell echo $(OSTYPE)))

# The location of the extension profile.
ifeq ($(os_type), darwin)
  profile_location := \
    ~/Library/Application\ Support/Firefox/Profiles/$(profile_dir)/extensions/\{$(extension_uuid)\}
else
  ifeq ($(os_type), linux-gnu)
    profile_location := \
      ~/.mozilla/firefox/$(profile_dir)/extensions/
  else
    profile_location := \
      "$(subst \,\\,$(APPDATA))\\Mozilla\\Firefox\\Profiles\\$(profile_dir)\\extensions\\{$(extension_uuid)}"
  endif
endif

# The temporary location where the extension tree will be copied and built.
build_dir := $(bin_dir)/build ##### problem ######

# This builds the extension XPI file.
.PHONY: all
all: $(xpi_file)
    @echo
    @echo "Build finished successfully."
    @echo

# This cleans all temporary files and directories created by 'make'.
.PHONY: clean
clean:
    @rm -rf $(build_dir)
    @rm -f $(xpi_file)
    @echo "Cleanup is done."

# The sources for the XPI file.
xpi_built := install.rdf \
             chrome.manifest \
             $(wildcard content/*.js) \
             $(wildcard content/*.xul) \
             $(wildcard content/*.xml) \
             $(wildcard content/*.css) \
             $(wildcard skin/*.css) \
             $(wildcard skin/*.png) \
             $(wildcard locale/*/*.dtd) \
             $(wildcard locale/*/*.properties)

$(build_dir) $(xpi_built): $(xpi_built)

# This builds everything except for the actual XPI, and then it copies it to the
# specified profile directory, allowing a quick update that requires no install.
.PHONY: install
install: $(build_dir) $(xpi_built)
    @echo "Installing in profile folder: $(profile_location)"
    @cp -Rf $(build_dir)/* $(profile_location)     ##### problem ######
    @echo "Installing in profile folder. Done!"
    @echo


$(xpi_file): $(xpi_built)
    @echo "Creating XPI file."
    @$(ZIP) $(xpi_file) $(xpi_built)
    @echo "Creating XPI file. Done!"

我在 Linux Mint 12 上使用 GNU Make 3.81。

谢谢。

输出

@echo "Installing in profile folder: $(profile_location)"
    @echo ${build_dir}
    @echo ${profile_location}

是:

Installing in profile folder: ~/.mozilla/firefox/8mtbjosv.development/extensions/
../bin/build
/home/owner/.mozilla/firefox/8mtbjosv.development/extensions/

【问题讨论】:

    标签: makefile gnu-make


    【解决方案1】:

    我认为您应该尝试检查目标文件夹$(profile_location) 是否存在并且是否可写。此外,请确保行尾具有正确的 Linux 格式 (\n)。我目前无法发现任何其他错误。

    【讨论】:

    • 似乎不是问题。我 chmod'd $(profile_location) 仍然得到同样的错误。行尾也很好。
    • 这太奇怪了...你能在$(build_dir)$(profile_location) 上而不是cp 上做回声吗?另外,您是在此处输入错误还是从终端复制了错误?如果您仔细看的话,引号中有一个小的不一致之处……也许这是一个线索。
    • 输出直接来自终端 - 我同意它看起来很奇怪,但不确定是什么原因造成的。我已将您要求的输出附加到问题的末尾。
    • 我刚刚注意到我有一条来自 chmod 的错误消息(与此问题无关),它具有相同的引用格式,所以我认为这只是终端很奇怪:“尝试 `chmod --help'了解更多信息。”
    • 也许“*”与应有的不匹配。您可以尝试以特定文件为目标吗?就像一个测试......
    【解决方案2】:

    如果它正在运行以使 ../bin 与 makefile 所在的位置相关,但与它正在运行的位置无关,该怎么办?如果 make clean 有效,那么这是一个可能是这种情况的迹象。寻找一些编译器选项来提供详细的输出,然后在其中放置一个“pwd”语句以查看它是如何解析的。

    【讨论】:

    • makefile 和我运行的位置都是相同的(src 目录)。在“cp”命令之前发出“pwd”正确显示当前目录是project/src。
    • 也许 cp 命令的 build_dir 上的 /* 不包含任何目录 - cp 命令上的 -R 用于递归,我相信如果你只放 build_dir 它会起作用而是在那里
    • 我尝试删除递归选项以及摆脱“/*”,但都没有成功。
    【解决方案3】:

    不是直接的答案,但是当尝试使用 GNU Make 4.2.1 在命令中引用父目录时,我发现我必须转义正斜杠...

    backup:
        @tar -czvpf ..\/$(PROGRAM)-`date +'%Y%m%d%H%M'`.tar.gz $(FILES)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-08
      • 2011-06-23
      • 1970-01-01
      • 2021-04-04
      • 2015-09-15
      • 1970-01-01
      相关资源
      最近更新 更多