I'm trying to port my wayland compositor from make to scons, but I'm having trouble with the build order. I need xdg-shell-protocol to be generated with wayland-scanner and built before anything else. With make, something like this is all it takes:
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
With scons, I tried this:
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")
)
But wlc
always gets built before xdg_shell_protocol
, and ends up failing because xdg-shell-protocol.h
hasn't been generated yet. I also tried:
- Defining an explicit dependency by adding
env.Depends(wlc, "xdg-shell-protocol.h")
orenv.Depends(wlc, xdg_shell_protocol)
at the end, - Setting
LIBS = ["xdg-shell-protocol"]
inwlc
, - Not using
Library
and just addingxdg-shell-protocol.h
andxdg-shell-protocol.c
to the beginning ofsource
inwlc
. Butmain.c
or some other source file always ends up being compiled first and fails becausexdg-shell-protocol.h
doesn't exist yet. What am I doing wrong?
EDIT:
- Expanded
...
above (note that the makefile is from before I moved source files to subdirectories, which was the main reason I decided to change build systems). - Output of
$ scons --tree=prune