commit 882003c11e28dd9af03e307f198eedf90ef10f13
parent 10de13871fef09a36626a69c1b90ff89feb609ae
Author: Michael Forney <mforney@mforney.org>
Date: Wed, 6 Apr 2016 06:26:56 +0000
Improve pkg-config usage in Makefile
Diffstat:
2 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/Makefile b/Makefile
@@ -50,19 +50,11 @@ libinput_CONSTRAINTS := --atleast-version=0.4
wayland-server_CONSTRAINTS := --atleast-version=1.6.0
define check
- $(1)_EXISTS = $$(shell $$(PKG_CONFIG) --exists $$($(1)_CONSTRAINTS) $(1) && echo yes)
-
- ifeq ($$(origin $(1)_CFLAGS),undefined)
- ifneq ($$($(1)_EXISTS),yes)
- $$(error Could not find package $(1))
- endif
- $(1)_CFLAGS = $$(shell $$(PKG_CONFIG) --cflags $(1))
+ ifeq ($$(origin $(1)_EXISTS),undefined)
+ $(1)_EXISTS = $$(shell $$(PKG_CONFIG) --exists $$($(1)_CONSTRAINTS) $(1) && echo yes)
endif
- ifeq ($$(origin $(1)_LIBS),undefined)
- ifneq ($$($(1)_EXISTS),yes)
- $$(error Could not find package $(1))
- endif
- $(1)_LIBS = $$(shell $$(PKG_CONFIG) --libs $(1))
+ ifneq ($$($(1)_EXISTS),yes)
+ $$(error Could not find package $(1) $$($(1)_CONSTRAINTS))
endif
endef
@@ -95,6 +87,8 @@ Q_SYM = $(call quiet,SYM )
compile = $(Q_CC)$(CC) $(FINAL_CPPFLAGS) $(FINAL_CFLAGS) -I . -c -o $@ $< \
-MMD -MP -MF .deps/$(basename $<).d -MT $(basename $@).o -MT $(basename $@).lo
link = $(Q_CCLD)$(CC) $(LDFLAGS) -o $@ $^
+pkgconfig = $(foreach pkg,$(1),$(if $($(pkg)_$(3)),$($(pkg)_$(3)), \
+ $(shell $(PKG_CONFIG) --$(2) $(pkg))))
include $(SUBDIRS:%=%/local.mk)
diff --git a/common.mk b/common.mk
@@ -18,10 +18,10 @@ $(dir)/%.lo: $(dir)/%.c | .deps/$(dir)
$(compile) -fPIC $($(dir)_CFLAGS) $($(dir)_PACKAGE_CFLAGS)
ifeq ($(origin $(dir)_PACKAGE_CFLAGS),undefined)
- $(dir)_PACKAGE_CFLAGS := $(foreach pkg,$($(dir)_PACKAGES),$($(pkg)_CFLAGS))
+ $(dir)_PACKAGE_CFLAGS := $(call pkgconfig,$($(dir)_PACKAGES),cflags,CFLAGS)
endif
ifeq ($(origin $(dir)_PACKAGE_LIBS),undefined)
- $(dir)_PACKAGE_LIBS := $(foreach pkg,$($(dir)_PACKAGES),$($(pkg)_LIBS))
+ $(dir)_PACKAGE_LIBS := $(call pkgconfig,$($(dir)_PACKAGES),libs,LIBS)
endif
CLEAN_FILES += $($(dir)_TARGETS)