如何理解makefile和Python

2 投票
1 回答
1390 浏览
提问于 2025-04-16 03:45

我正在尝试理解一个makefile是如何工作的,目的是把一些.ui文件编译成.py文件(从PyQt转换到Python)。这是我正在使用的自动生成的makefile:

# Makefile for a PyQGIS plugin 
UI_FILES = Ui_UrbanAnalysis.py

RESOURCE_FILES = resources.py

default: compile
    compile: $(UI_FILES) $(RESOURCE_FILES)

%.py : %.qrc
    pyrcc4 -o $@  $<

%.py : %.ui
    pyuic4 -o $@ $<

当我输入:

$ make

我收到以下消息:

make: *** No rule to make target `compile', needed by `default'.  Stop.

我哪里做错了呢?

谢谢。

1 个回答

2

我不知道你想要实现的构建步骤是什么,但这两行代码:

default: compile
    compile: $(UI_FILES) $(RESOURCE_FILES)

看起来像是目标行,所以它们可能应该改成:

default: compile

compile: $(UI_FILES) $(RESOURCE_FILES)

因为在执行时,make 可能会把 compile:... 这一行当作一个动作来理解,但这样做不会有任何效果,并且意味着没有 compile 这个目标。


还有一件事,你可能想用

PHONY: default compile

来告诉 make 这些是抽象目标,并不代表具体的文件。这也是一种良好的编程习惯。

撰写回答