Makefile - 引用父目录的问题

时间:2012-04-29 19:46:56

标签: makefile gnu-make

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

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

项目的布局是:

/ bin中

/ SRC /生成文件

(所以当我运行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/

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

如果它正在运行,那么../bin是相对于makefile的位置,而不是它在哪里运行?如果make clean工作,那么这可能就是一个标志。查找一些编译器选项以提供详细输出,然后在其中放置一个“pwd”语句以查看它是如何解析的。

答案 2 :(得分:0)

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

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