Skip to content

Commit 386e7c6

Browse files
dkulpclaude
andcommitted
perf(build): resolve pkg-config once at parse time, not once per recipe
CFLAGS is a recursively-expanded variable, so "CFLAGS += $(shell pkg-config ...)" appends the shell call itself rather than its result, and make re-runs it every time CFLAGS is expanded -- which is once per compile recipe. Three helpers were wired up that way (gstreamer, libdrm, and GraphicsMagick++-config on generic-Linux builds), so a build forked them several hundred times to recompute a string that never changes. Capture each into a simply-expanded variable and append that instead. The resulting compile lines are unchanged token for token; only the number of forks differs. pkg-config invocations per build 406 -> 3 make -n over a full build, 1-core armhf 11.5s -> 0.9s make -n over a full build, 4-core aarch64 0.8s -> 0.2s The cost is paid on every make invocation, so it is proportionally largest on no-op and incremental builds. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 1f121a3 commit 386e7c6

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/makefiles/fpp_so.mk

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,25 @@ LIBS_fpp_so += \
160160
$(LIBS_GPIO_ADDITIONS)
161161

162162
# GStreamer support
163+
#
164+
# Resolve pkg-config with := so it runs once while the makefiles are read.
165+
# CFLAGS is a recursively-expanded variable, so a bare "CFLAGS += $(shell ...)"
166+
# appends the shell call itself rather than its result, and make then re-runs
167+
# pkg-config every time CFLAGS is expanded -- which is once per compile recipe,
168+
# several hundred forks per build on boards that can least afford them.
163169
ifneq ($(wildcard /usr/include/gstreamer-1.0/gst/gst.h),)
164-
CFLAGS += $(shell pkg-config --cflags gstreamer-1.0 gstreamer-app-1.0 gstreamer-net-1.0)
165-
LIBS_fpp_so += $(shell pkg-config --libs gstreamer-1.0 gstreamer-app-1.0 gstreamer-net-1.0)
170+
GSTREAMER_CFLAGS := $(shell pkg-config --cflags gstreamer-1.0 gstreamer-app-1.0 gstreamer-net-1.0)
171+
GSTREAMER_LIBS := $(shell pkg-config --libs gstreamer-1.0 gstreamer-app-1.0 gstreamer-net-1.0)
172+
CFLAGS += $(GSTREAMER_CFLAGS)
173+
LIBS_fpp_so += $(GSTREAMER_LIBS)
166174
endif
167175

168176
# DRM/KMS. fpp.cpp and framebuffer/KMSFrameBuffer.h enable the KMS code on
169177
# __has_include(<xf86drm.h>), so the flags have to key off that same header --
170178
# xf86drm.h itself pulls in <drm.h>, which only resolves with libdrm's -I.
171179
ifneq ($(wildcard /usr/include/xf86drm.h),)
172-
CFLAGS += $(shell pkg-config --cflags libdrm)
180+
LIBDRM_CFLAGS := $(shell pkg-config --cflags libdrm)
181+
CFLAGS += $(LIBDRM_CFLAGS)
173182
LIBS_fpp_so += -ldrm
174183
endif
175184

src/makefiles/platform/linux.mk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ ifeq '$(ISLINUX)' '1'
3535
# do something Linux-y
3636

3737
ifeq ($(wildcard /usr/include/Magick++.h),)
38-
CFLAGS += $(shell GraphicsMagick++-config --cppflags)
38+
# := so the helper runs once at parse time rather than on every expansion of the
39+
# recursively-expanded CFLAGS, i.e. once per compile recipe. See the pkg-config
40+
# note in makefiles/fpp_so.mk.
41+
GMAGICK_CFLAGS := $(shell GraphicsMagick++-config --cppflags)
42+
CFLAGS += $(GMAGICK_CFLAGS)
3943
endif
4044

4145
ifneq ($(wildcard /etc/fpp/container),)

0 commit comments

Comments
 (0)