Skip to content

Commit 840d705

Browse files
committed
Refine dependency checking with unified 'dep'
This replaces all individual dependency macros with a single, concise interface: $(call dep,flag-type,package-name[s]) Where: - flag-type: cflags or libs - package-name[s]: Single package or space-separated list
1 parent d4cf5bb commit 840d705

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

Makefile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,18 @@ libtwin.a_files-y += src/screen-ops.c
9494
# Renderer implementations (draw-builtin.c includes all compositing operations)
9595
libtwin.a_files-$(CONFIG_RENDERER_BUILTIN) += src/draw-builtin.c
9696
libtwin.a_files-$(CONFIG_RENDERER_PIXMAN) += src/draw-pixman.c
97-
libtwin.a_cflags-$(CONFIG_RENDERER_PIXMAN) += $(shell pkg-config --cflags pixman-1)
97+
libtwin.a_cflags-$(CONFIG_RENDERER_PIXMAN) += $(call dep,cflags,pixman-1)
9898
ifeq ($(CONFIG_RENDERER_PIXMAN), y)
99-
TARGET_LIBS += $(shell pkg-config --libs pixman-1)
99+
TARGET_LIBS += $(call dep,libs,pixman-1)
100100
endif
101101

102102
# Image loaders
103103

104104
ifeq ($(CONFIG_LOADER_JPEG), y)
105105
libtwin.a_files-y += src/image-jpeg.c
106106
ifneq ($(CC_IS_EMCC), 1)
107-
libtwin.a_cflags-y += $(shell pkg-config --cflags libjpeg)
108-
TARGET_LIBS += $(shell pkg-config --libs libjpeg)
107+
libtwin.a_cflags-y += $(call dep,cflags,libjpeg)
108+
TARGET_LIBS += $(call dep,libs,libjpeg)
109109
else
110110
# Emscripten libjpeg port - flags needed for both compile and link
111111
libtwin.a_cflags-y += -sUSE_LIBJPEG=1
@@ -116,8 +116,8 @@ endif
116116
ifeq ($(CONFIG_LOADER_PNG), y)
117117
libtwin.a_files-y += src/image-png.c
118118
ifneq ($(CC_IS_EMCC), 1)
119-
libtwin.a_cflags-y += $(shell pkg-config --cflags libpng)
120-
TARGET_LIBS += $(shell pkg-config --libs libpng)
119+
libtwin.a_cflags-y += $(call dep,cflags,libpng)
120+
TARGET_LIBS += $(call dep,libs,libpng)
121121
else
122122
# Emscripten libpng port (includes zlib) - flags needed for both compile and link
123123
libtwin.a_cflags-y += -sUSE_LIBPNG=1 -sUSE_ZLIB=1
@@ -156,8 +156,8 @@ BACKEND := none
156156
ifeq ($(CONFIG_BACKEND_SDL), y)
157157
BACKEND = sdl
158158
libtwin.a_files-y += backend/sdl.c
159-
libtwin.a_cflags-y += $(shell sdl2-config --cflags)
160-
TARGET_LIBS += $(shell sdl2-config --libs)
159+
libtwin.a_cflags-y += $(call dep,cflags,sdl2)
160+
TARGET_LIBS += $(call dep,libs,sdl2)
161161
endif
162162

163163
ifeq ($(CONFIG_BACKEND_FBDEV), y)
@@ -171,8 +171,8 @@ ifeq ($(CONFIG_BACKEND_VNC), y)
171171
BACKEND = vnc
172172
libtwin.a_files-y += backend/vnc.c
173173
libtwin.a_files-y += src/cursor.c
174-
libtwin.a_cflags-y += $(shell pkg-config --cflags neatvnc aml pixman-1)
175-
TARGET_LIBS += $(shell pkg-config --libs neatvnc aml pixman-1)
174+
libtwin.a_cflags-y += $(call dep,cflags,neatvnc aml pixman-1)
175+
TARGET_LIBS += $(call dep,libs,neatvnc aml pixman-1)
176176
endif
177177

178178
ifeq ($(CONFIG_BACKEND_HEADLESS), y)
@@ -252,11 +252,11 @@ font-edit_files-y = \
252252
tools/font-edit/font-edit.c
253253
font-edit_includes-y := tools/font-edit
254254
font-edit_cflags-y := \
255-
$(call pkg-config-cflags,cairo) \
256-
$(call sdl2-cflags)
255+
$(call dep,cflags,cairo) \
256+
$(call dep,cflags,sdl2)
257257
font-edit_ldflags-y := \
258-
$(call pkg-config-libs,cairo) \
259-
$(call sdl2-libs) \
258+
$(call dep,libs,cairo) \
259+
$(call dep,libs,sdl2) \
260260
-lm
261261

262262
# Headless control tool

mk/deps.mk

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
# Dependency checking and flag retrieval macros
1+
# Unified dependency checking and flag retrieval system
2+
#
3+
# Usage: $(call dep,flag-type,package-name[s])
4+
# flag-type: cflags or libs
5+
# package-name[s]: single package or space-separated list (e.g., "cairo", "neatvnc aml")
6+
#
7+
# Automatically detects the right tool:
8+
# 1. Try package-config tool first (e.g., sdl2-config) - single package only
9+
# 2. Fall back to pkg-config if available - supports multiple packages
10+
# 3. Return empty string if package(s) not found
211

3-
# Check if pkg-config package exists and retrieve flags
4-
# Usage: $(call pkg-config-cflags,package-name)
5-
# Returns: CFLAGS or empty string if package not found
6-
define pkg-config-cflags
7-
$(shell pkg-config --cflags $(1) 2>/dev/null)
12+
# Internal: Try package-specific config tool (single package only)
13+
# Usage: $(call _dep-config,package-name,flag-type)
14+
define _dep-config
15+
$(shell command -v $(1)-config >/dev/null 2>&1 && $(1)-config --$(2) 2>/dev/null)
816
endef
917

10-
# Usage: $(call pkg-config-libs,package-name)
11-
# Returns: LDFLAGS or empty string if package not found
12-
define pkg-config-libs
13-
$(shell pkg-config --libs $(1) 2>/dev/null)
18+
# Internal: Try pkg-config (supports multiple packages)
19+
# Usage: $(call _dep-pkg,package-names,flag-type)
20+
define _dep-pkg
21+
$(shell pkg-config --$(2) $(1) 2>/dev/null)
1422
endef
1523

16-
# Check if sdl2-config exists and retrieve flags
17-
# Usage: $(call sdl2-cflags)
18-
# Returns: CFLAGS or empty string if sdl2-config not found
19-
define sdl2-cflags
20-
$(shell sdl2-config --cflags 2>/dev/null)
24+
# Internal: Check if input contains multiple packages
25+
# Usage: $(call _dep-multi,package-names)
26+
define _dep-multi
27+
$(filter-out $(firstword $(1)),$(1))
2128
endef
2229

23-
# Usage: $(call sdl2-libs)
24-
# Returns: LDFLAGS or empty string if sdl2-config not found
25-
define sdl2-libs
26-
$(shell sdl2-config --libs 2>/dev/null)
27-
endef
28-
29-
# Check if a command exists
30-
# Usage: $(call command-exists,command-name)
31-
# Returns: non-empty if command exists
32-
define command-exists
33-
$(shell command -v $(1) 2>/dev/null)
34-
endef
35-
36-
# Check if pkg-config package exists
37-
# Usage: $(call pkg-exists,package-name)
38-
# Returns: "yes" if package exists, empty otherwise
39-
define pkg-exists
40-
$(shell pkg-config --exists $(1) 2>/dev/null && echo "yes")
30+
# Main entry point: Unified dependency checker
31+
# Usage: $(call dep,flag-type,package-name[s])
32+
# Example: $(call dep,cflags,cairo)
33+
# $(call dep,libs,sdl2)
34+
# $(call dep,cflags,neatvnc aml pixman-1)
35+
define dep
36+
$(if $(call _dep-multi,$(2)),\
37+
$(call _dep-pkg,$(2),$(1)),\
38+
$(if $(call _dep-config,$(2),$(1)),\
39+
$(call _dep-config,$(2),$(1)),\
40+
$(call _dep-pkg,$(2),$(1))))
4141
endef

0 commit comments

Comments
 (0)