commit 1c5c4fe

Michael Forney  ·  2014-11-01 06:43:26 +0000 UTC
parent 3c2a8bf
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.
4 files changed,  +52, -30
+43, -5
 1@@ -22,11 +22,51 @@ TARGETS         := swc.pc
 2 SUBDIRS         := launch libswc protocol cursor example
 3 CLEAN_FILES     := $(TARGETS)
 4 
 5-libinput_CONSTRAINTS        := >= 0.4
 6-wayland-server_CONSTRAINTS  := >= 1.6.0
 7-
 8 include config.mk
 9 
10+# Dependencies
11+PACKAGES :=         \
12+    libdrm          \
13+    libevdev        \
14+    pixman-1        \
15+    wayland-server  \
16+    wld             \
17+    xkbcommon
18+
19+ifeq ($(ENABLE_XWAYLAND),1)
20+PACKAGES +=         \
21+    xcb             \
22+    xcb-composite   \
23+    xcb-ewmh        \
24+    xcb-icccm
25+endif
26+
27+ifeq ($(ENABLE_LIBINPUT),1)
28+PACKAGES += libinput libudev
29+endif
30+
31+libinput_CONSTRAINTS        := --atleast-version=0.4
32+wayland-server_CONSTRAINTS  := --atleast-version=1.6.0
33+
34+define check
35+    $(1)_EXISTS = $$(shell $$(PKG_CONFIG) --exists $$($(1)_CONSTRAINTS) $(1) && echo yes)
36+
37+    ifeq ($$(origin $(1)_CFLAGS),undefined)
38+        ifneq ($$($(1)_EXISTS),yes)
39+            $$(error Could not find package $(1))
40+        endif
41+        $(1)_CFLAGS = $$(shell $$(PKG_CONFIG) --cflags $(1))
42+    endif
43+    ifeq ($$(origin $(1)_LIBS),undefined)
44+        ifneq ($$($(1)_EXISTS),yes)
45+            $$(error Could not find package $(1))
46+        endif
47+        $(1)_LIBS = $$(shell $$(PKG_CONFIG) --libs $(1))
48+    endif
49+endef
50+
51+$(foreach pkg,$(PACKAGES),$(eval $(call check,$(pkg))))
52+
53 ifeq ($(if $(V),$(V),0), 0)
54     define quiet
55         @echo "  $1	$@"
56@@ -52,8 +92,6 @@ endif
57 compile     = $(call quiet,CC) $(FINAL_CPPFLAGS) $(FINAL_CFLAGS) -I . -c -o $@ $< \
58               -MMD -MP -MF .deps/$(basename $<).d -MT $(basename $@).o -MT $(basename $@).lo
59 link        = $(call quiet,CCLD,$(CC)) $(LDFLAGS) -o $@ $^
60-pkgconfig   = $(sort $(foreach pkg,$(1),$(if $($(pkg)_$(3)),$($(pkg)_$(3)), \
61-                $(shell $(PKG_CONFIG) --$(2) $(pkg) "$($(pkg)_CONSTRAINTS)"))))
62 
63 include $(SUBDIRS:%=%/local.mk)
64 
+5, -7
 1@@ -17,13 +17,11 @@ $(dir)/%.o: $(dir)/%.c | .deps/$(dir)
 2 $(dir)/%.lo: $(dir)/%.c | .deps/$(dir)
 3 	$(compile) -fPIC $($(dir)_CFLAGS) $($(dir)_PACKAGE_CFLAGS)
 4 
 5-ifdef $(dir)_PACKAGES
 6-    ifndef $(dir)_PACKAGE_CFLAGS
 7-        $(dir)_PACKAGE_CFLAGS := $(call pkgconfig,$($(dir)_PACKAGES),cflags,CFLAGS)
 8-    endif
 9-    ifndef $(dir)_PACKAGE_LIBS
10-        $(dir)_PACKAGE_LIBS := $(call pkgconfig,$($(dir)_PACKAGES),libs,LIBS)
11-    endif
12+ifeq ($(origin $(dir)_PACKAGE_CFLAGS),undefined)
13+    $(dir)_PACKAGE_CFLAGS := $(foreach pkg,$($(dir)_PACKAGES),$($(pkg)_CFLAGS))
14+endif
15+ifeq ($(origin $(dir)_PACKAGE_LIBS),undefined)
16+    $(dir)_PACKAGE_LIBS := $(foreach pkg,$($(dir)_PACKAGES),$($(pkg)_LIBS))
17 endif
18 
19 CLEAN_FILES += $($(dir)_TARGETS)
+2, -5
 1@@ -2,11 +2,8 @@
 2 
 3 dir := launch
 4 
 5-$(dir)_TARGETS := $(dir)/swc-launch
 6-
 7-# Dependencies
 8-$(dir)_PACKAGES =   \
 9-    libdrm
10+$(dir)_TARGETS  := $(dir)/swc-launch
11+$(dir)_PACKAGES := libdrm
12 
13 $(dir)/swc-launch: $(dir)/launch.o $(dir)/protocol.o
14 	$(link) $(launch_PACKAGE_LIBS)
+2, -13
 1@@ -17,14 +17,7 @@ $(dir)_TARGETS +=                   \
 2     $(dir)/$(LIBSWC_LINK)
 3 endif
 4 
 5-# Dependencies
 6-$(dir)_PACKAGES =   \
 7-    libdrm          \
 8-    libevdev        \
 9-    pixman-1        \
10-    wayland-server  \
11-    wld             \
12-    xkbcommon
13+$(dir)_PACKAGES := libdrm libevdev pixman-1 wayland-server wld xkbcommon
14 
15 SWC_SOURCES =                       \
16     launch/protocol.c               \
17@@ -73,11 +66,7 @@ endif
18 
19 ifeq ($(ENABLE_XWAYLAND),1)
20 $(dir)_CFLAGS += -DENABLE_XWAYLAND
21-$(dir)_PACKAGES +=                  \
22-    xcb                             \
23-    xcb-composite                   \
24-    xcb-ewmh                        \
25-    xcb-icccm
26+$(dir)_PACKAGES += xcb xcb-composite xcb-ewmh xcb-icccm
27 
28 SWC_SOURCES +=                      \
29     libswc/xserver.c                \