Skip to content

Commit a5d0b01

Browse files
authored
Merge pull request #143 from sysprog21/quiet-configure
Refine dependency checking with unified 'dep'
2 parents 8789d45 + ad4ecc9 commit a5d0b01

File tree

2 files changed

+67
-14
lines changed

2 files changed

+67
-14
lines changed

Makefile

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-include .config
2+
include mk/deps.mk
23

34
# Set default goal explicitly
45
.DEFAULT_GOAL := all
@@ -93,18 +94,18 @@ libtwin.a_files-y += src/screen-ops.c
9394
# Renderer implementations (draw-builtin.c includes all compositing operations)
9495
libtwin.a_files-$(CONFIG_RENDERER_BUILTIN) += src/draw-builtin.c
9596
libtwin.a_files-$(CONFIG_RENDERER_PIXMAN) += src/draw-pixman.c
96-
libtwin.a_cflags-$(CONFIG_RENDERER_PIXMAN) += $(shell pkg-config --cflags pixman-1)
97+
libtwin.a_cflags-$(CONFIG_RENDERER_PIXMAN) += $(call dep,cflags,pixman-1)
9798
ifeq ($(CONFIG_RENDERER_PIXMAN), y)
98-
TARGET_LIBS += $(shell pkg-config --libs pixman-1)
99+
TARGET_LIBS += $(call dep,libs,pixman-1)
99100
endif
100101

101102
# Image loaders
102103

103104
ifeq ($(CONFIG_LOADER_JPEG), y)
104105
libtwin.a_files-y += src/image-jpeg.c
105106
ifneq ($(CC_IS_EMCC), 1)
106-
libtwin.a_cflags-y += $(shell pkg-config --cflags libjpeg)
107-
TARGET_LIBS += $(shell pkg-config --libs libjpeg)
107+
libtwin.a_cflags-y += $(call dep,cflags,libjpeg)
108+
TARGET_LIBS += $(call dep,libs,libjpeg)
108109
else
109110
# Emscripten libjpeg port - flags needed for both compile and link
110111
libtwin.a_cflags-y += -sUSE_LIBJPEG=1
@@ -115,8 +116,8 @@ endif
115116
ifeq ($(CONFIG_LOADER_PNG), y)
116117
libtwin.a_files-y += src/image-png.c
117118
ifneq ($(CC_IS_EMCC), 1)
118-
libtwin.a_cflags-y += $(shell pkg-config --cflags libpng)
119-
TARGET_LIBS += $(shell pkg-config --libs libpng)
119+
libtwin.a_cflags-y += $(call dep,cflags,libpng)
120+
TARGET_LIBS += $(call dep,libs,libpng)
120121
else
121122
# Emscripten libpng port (includes zlib) - flags needed for both compile and link
122123
libtwin.a_cflags-y += -sUSE_LIBPNG=1 -sUSE_ZLIB=1
@@ -155,8 +156,8 @@ BACKEND := none
155156
ifeq ($(CONFIG_BACKEND_SDL), y)
156157
BACKEND = sdl
157158
libtwin.a_files-y += backend/sdl.c
158-
libtwin.a_cflags-y += $(shell sdl2-config --cflags)
159-
TARGET_LIBS += $(shell sdl2-config --libs)
159+
libtwin.a_cflags-y += $(call dep,cflags,sdl2)
160+
TARGET_LIBS += $(call dep,libs,sdl2)
160161
endif
161162

162163
ifeq ($(CONFIG_BACKEND_FBDEV), y)
@@ -170,8 +171,8 @@ ifeq ($(CONFIG_BACKEND_VNC), y)
170171
BACKEND = vnc
171172
libtwin.a_files-y += backend/vnc.c
172173
libtwin.a_files-y += src/cursor.c
173-
libtwin.a_cflags-y += $(shell pkg-config --cflags neatvnc aml pixman-1)
174-
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)
175176
endif
176177

177178
ifeq ($(CONFIG_BACKEND_HEADLESS), y)
@@ -251,11 +252,11 @@ font-edit_files-y = \
251252
tools/font-edit/font-edit.c
252253
font-edit_includes-y := tools/font-edit
253254
font-edit_cflags-y := \
254-
$(shell pkg-config --cflags cairo) \
255-
$(shell sdl2-config --cflags)
255+
$(call dep,cflags,cairo) \
256+
$(call dep,cflags,sdl2)
256257
font-edit_ldflags-y := \
257-
$(shell pkg-config --libs cairo) \
258-
$(shell sdl2-config --libs) \
258+
$(call dep,libs,cairo) \
259+
$(call dep,libs,sdl2) \
259260
-lm
260261

261262
# Headless control tool

mk/deps.mk

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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
11+
#
12+
# Verbose mode: Set V=1 to show dependency-checking errors
13+
# make V=1 # Show all pkg-config/config-tool errors
14+
# make # Silent mode (default)
15+
16+
# Conditional stderr redirection based on V= flag
17+
ifeq ($(V),1)
18+
_dep_stderr :=
19+
else
20+
_dep_stderr := 2>/dev/null
21+
endif
22+
23+
# Internal: Try package-specific config tool (single package only)
24+
# Usage: $(call _dep-config,package-name,flag-type)
25+
define _dep-config
26+
$(shell command -v $(1)-config >/dev/null 2>&1 && $(1)-config --$(2) $(_dep_stderr))
27+
endef
28+
29+
# Internal: Try pkg-config (supports multiple packages)
30+
# Usage: $(call _dep-pkg,package-names,flag-type)
31+
define _dep-pkg
32+
$(shell pkg-config --$(2) $(1) $(_dep_stderr))
33+
endef
34+
35+
# Internal: Check if input contains multiple packages
36+
# Usage: $(call _dep-multi,package-names)
37+
define _dep-multi
38+
$(filter-out $(firstword $(1)),$(1))
39+
endef
40+
41+
# Main entry point: Unified dependency checker
42+
# Usage: $(call dep,flag-type,package-name[s])
43+
# Example: $(call dep,cflags,cairo)
44+
# $(call dep,libs,sdl2)
45+
# $(call dep,cflags,neatvnc aml pixman-1)
46+
define dep
47+
$(if $(call _dep-multi,$(2)),\
48+
$(call _dep-pkg,$(2),$(1)),\
49+
$(if $(call _dep-config,$(2),$(1)),\
50+
$(call _dep-config,$(2),$(1)),\
51+
$(call _dep-pkg,$(2),$(1))))
52+
endef

0 commit comments

Comments
 (0)