commit 1c5c4fe3815d97f094ef4af8e757ac92b21aca63
parent 3c2a8bfb20904791d6517cc0e932b4fbccdc545f
Author: Michael Forney <mforney@mforney.org>
Date: Sat, 1 Nov 2014 06:43:26 +0000
Improve package cflags/libs detection
- Provide a useful error message when the package could not be found.
- Declare all dependencies up front in the toplevel Makefile.
- Don't sort libraries; the order matters when statically linking.
Diffstat:
4 files changed, 52 insertions(+), 30 deletions(-)
diff --git a/Makefile b/Makefile
@@ -22,11 +22,51 @@ TARGETS := swc.pc
SUBDIRS := launch libswc protocol cursor example
CLEAN_FILES := $(TARGETS)
-libinput_CONSTRAINTS := >= 0.4
-wayland-server_CONSTRAINTS := >= 1.6.0
-
include config.mk
+# Dependencies
+PACKAGES := \
+ libdrm \
+ libevdev \
+ pixman-1 \
+ wayland-server \
+ wld \
+ xkbcommon
+
+ifeq ($(ENABLE_XWAYLAND),1)
+PACKAGES += \
+ xcb \
+ xcb-composite \
+ xcb-ewmh \
+ xcb-icccm
+endif
+
+ifeq ($(ENABLE_LIBINPUT),1)
+PACKAGES += libinput libudev
+endif
+
+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))
+ endif
+ ifeq ($$(origin $(1)_LIBS),undefined)
+ ifneq ($$($(1)_EXISTS),yes)
+ $$(error Could not find package $(1))
+ endif
+ $(1)_LIBS = $$(shell $$(PKG_CONFIG) --libs $(1))
+ endif
+endef
+
+$(foreach pkg,$(PACKAGES),$(eval $(call check,$(pkg))))
+
ifeq ($(if $(V),$(V),0), 0)
define quiet
@echo " $1 $@"
@@ -52,8 +92,6 @@ endif
compile = $(call quiet,CC) $(FINAL_CPPFLAGS) $(FINAL_CFLAGS) -I . -c -o $@ $< \
-MMD -MP -MF .deps/$(basename $<).d -MT $(basename $@).o -MT $(basename $@).lo
link = $(call quiet,CCLD,$(CC)) $(LDFLAGS) -o $@ $^
-pkgconfig = $(sort $(foreach pkg,$(1),$(if $($(pkg)_$(3)),$($(pkg)_$(3)), \
- $(shell $(PKG_CONFIG) --$(2) $(pkg) "$($(pkg)_CONSTRAINTS)"))))
include $(SUBDIRS:%=%/local.mk)
diff --git a/common.mk b/common.mk
@@ -17,13 +17,11 @@ $(dir)/%.o: $(dir)/%.c | .deps/$(dir)
$(dir)/%.lo: $(dir)/%.c | .deps/$(dir)
$(compile) -fPIC $($(dir)_CFLAGS) $($(dir)_PACKAGE_CFLAGS)
-ifdef $(dir)_PACKAGES
- ifndef $(dir)_PACKAGE_CFLAGS
- $(dir)_PACKAGE_CFLAGS := $(call pkgconfig,$($(dir)_PACKAGES),cflags,CFLAGS)
- endif
- ifndef $(dir)_PACKAGE_LIBS
- $(dir)_PACKAGE_LIBS := $(call pkgconfig,$($(dir)_PACKAGES),libs,LIBS)
- endif
+ifeq ($(origin $(dir)_PACKAGE_CFLAGS),undefined)
+ $(dir)_PACKAGE_CFLAGS := $(foreach pkg,$($(dir)_PACKAGES),$($(pkg)_CFLAGS))
+endif
+ifeq ($(origin $(dir)_PACKAGE_LIBS),undefined)
+ $(dir)_PACKAGE_LIBS := $(foreach pkg,$($(dir)_PACKAGES),$($(pkg)_LIBS))
endif
CLEAN_FILES += $($(dir)_TARGETS)
diff --git a/launch/local.mk b/launch/local.mk
@@ -2,11 +2,8 @@
dir := launch
-$(dir)_TARGETS := $(dir)/swc-launch
-
-# Dependencies
-$(dir)_PACKAGES = \
- libdrm
+$(dir)_TARGETS := $(dir)/swc-launch
+$(dir)_PACKAGES := libdrm
$(dir)/swc-launch: $(dir)/launch.o $(dir)/protocol.o
$(link) $(launch_PACKAGE_LIBS)
diff --git a/libswc/local.mk b/libswc/local.mk
@@ -17,14 +17,7 @@ $(dir)_TARGETS += \
$(dir)/$(LIBSWC_LINK)
endif
-# Dependencies
-$(dir)_PACKAGES = \
- libdrm \
- libevdev \
- pixman-1 \
- wayland-server \
- wld \
- xkbcommon
+$(dir)_PACKAGES := libdrm libevdev pixman-1 wayland-server wld xkbcommon
SWC_SOURCES = \
launch/protocol.c \
@@ -73,11 +66,7 @@ endif
ifeq ($(ENABLE_XWAYLAND),1)
$(dir)_CFLAGS += -DENABLE_XWAYLAND
-$(dir)_PACKAGES += \
- xcb \
- xcb-composite \
- xcb-ewmh \
- xcb-icccm
+$(dir)_PACKAGES += xcb xcb-composite xcb-ewmh xcb-icccm
SWC_SOURCES += \
libswc/xserver.c \