如何解决SCons:确保在程序之前构建库
我正在尝试将我的 Wayland 合成器从 make 移植到 scons,但是我在构建顺序方面遇到了问题。我需要使用 wayland-scanner 生成 xdg-shell-protocol 并在其他任何事情之前构建。使用 make,只需要这样:
WLSCAN_INFO = @echo " WLSCAN " $@;
CC_INFO = @echo " CC " $@;
CFLAGS= -g \
-Werror \
-I. \
-DWLR_USE_UNSTABLE
LIBS = "-Lxdg-shell-protocol.h" \
$(shell pkg-config --cflags --libs wlroots) \
$(shell pkg-config --cflags --libs wayland-server) \
$(shell pkg-config --cflags --libs xkbcommon) \
WAYLAND_PROTOCOLS=$(shell pkg-config --variable=pkgdatadir wayland-protocols)
WAYLAND_SCANNER=$(shell pkg-config --variable=wayland_scanner wayland-scanner)
XDG_SHELL_DEPS = xdg-shell-protocol.c xdg-shell-protocol.h
xdg-shell-protocol.h:
$(WLSCAN_INFO)$(WAYLAND_SCANNER) server-header \
$(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@
xdg-shell-protocol.c: xdg-shell-protocol.h
$(WLSCAN_INFO)$(WAYLAND_SCANNER) private-code \
$(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@
OBJS = \
xdg-shell-protocol.o \
output.o \
renderer.o \
input.o \
xdg.o \
cursor.o \
keyboard.o \
main.o
%.o: %.c xdg-shell-protocol.h
$(CC_INFO)$(CC) $(CFLAGS) -c $(LIBS) -o $@ $<
wlc: $(OBJS)
$(CC_INFO)$(CC) $(CFLAGS) $(LIBS) -o $@ $(OBJS)
clean:
rm -f wlc $(XDG_SHELL_DEPS) *.o
.DEFAULT_GOAL = wlc
.PHONY: wlc clean
使用 scons,我尝试了这个:
CCFLAGS = "-fdiagnostics-color=always -g -Werror -DWLR_USE_UNSTABLE"
CPPPATH = ["./","./include"]
env = Environment()
env.Append(CCFLAGS = CCFLAGS)
env.Append(CPPPATH = ["./","./include"])
env.ParseConfig("pkg-config --cflags --libs wlroots")
env.ParseConfig("pkg-config --cflags --libs wayland-server")
env.ParseConfig("pkg-config --cflags --libs xkbcommon")
env.Command( source = "",target = "xdg-shell-protocol.h",action = "`pkg-config --variable=wayland_scanner wayland-scanner` server-header \
`pkg-config --variable=pkgdatadir wayland-protocols`/stable/xdg-shell/xdg-shell.xml \
$TARGET"
)
env.Command( source = "",target = "xdg-shell-protocol.c",action = "`pkg-config --variable=wayland_scanner wayland-scanner` private-code \
`pkg-config --variable=pkgdatadir wayland-protocols`/stable/xdg-shell/xdg-shell.xml \
$TARGET"
)
xdg_shell_protocol = env.Library(
target = "xdg-shell-protocol",source = [
"xdg-shell-protocol.h","xdg-shell-protocol.c"
]
)
wlc = env.Program(
target = "wlc",source = [
Glob("input/*"),Glob("output/*"),Glob("shell/*"),"main.c",],LIBS=[xdg_shell_protocol],LIBPATH="."
)
env.Depends(wlc,"xdg-shell-protocol.h")
)
但 wlc
总是在 xdg_shell_protocol
之前构建,最终失败,因为 xdg-shell-protocol.h
尚未生成。我也试过:
- 通过在末尾添加
env.Depends(wlc,"xdg-shell-protocol.h")
或env.Depends(wlc,xdg_shell_protocol)
来定义显式依赖项, - 在
LIBS = ["xdg-shell-protocol"]
中设置wlc
, - 不使用
Library
,只是在xdg-shell-protocol.h
中的xdg-shell-protocol.c
开头添加source
和wlc
。 但是main.c
或其他一些源文件总是首先被编译并失败,因为xdg-shell-protocol.h
还不存在。 我做错了什么?
编辑:
- 扩展了上面的
...
(请注意,makefile 来自我将源文件移动到子目录之前的文件,这是我决定更改构建系统的主要原因)。 - Output of
$ scons --tree=prune
解决方法
请发布完整的文件,“...”可能是相关的。
您的 overflow: auto;
是否指定了 Command()
参数?
第 1 行是:source
吗?
尝试添加这一行
include/shell/xdg.h
注意:这不是一个好的解决方案,但有助于找出问题所在。
现在.. 尝试将您的 env.Depends('input/cursor.c','xdg-shell-protocol.h')
更改为此,并删除您明确的 Program(..)
。
Depends()
,
该问题是由于源扫描器没有看到对 xdg-shell-protocol.h
的依赖,因为它来自于包含通常不会被扫描的 /usr/include/wlr/types/wlr_xdg_shell.h
(这是上述建议添加/usr/include
到 CPPPATH
但这似乎还不够好),因此您不会得到您想要的顺序 - 如果它注意到该依赖项,则强制尽早生成该标头。从您的解决方法来看,我认为您可以简化为:
env.Depends("include/shell/xdg.h","xdg-shell-protocol.h")
这可能最终仍然不是最漂亮的答案...
,显然我必须为每个源文件定义显式依赖:
wlc_source = [
"main.c",Glob("input/*.c"),Glob("output/*.c"),Glob("shell/*.c"),]
for source in wlc_source:
env.Depends(source,xdg_shell_protocol)
wlc = env.Program(
target = "wlc",source = wlc_source
)
这解决了问题,但我认为这不是最好的解决方案。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。