From 6f0e8a693def0a924c5daf9e7bf479cb64e6788b Mon Sep 17 00:00:00 2001 From: Jami Kettunen Date: Thu, 30 Nov 2023 20:54:40 +0200 Subject: [PATCH] [build] Support pkg-config cross-compilation Previously to cross-compile one would need to add a pkg-config executable in $PATH wrapping all the search paths required; now one can e.g. make PKG_CONFIG=foreign-arch-target-pkg-config with the wrapper executable being separate and allowing programs for host to also be built if needed for example. --- Makefile | 5 +++-- test/binder-call/Makefile | 5 +++-- test/common/Makefile | 5 +++-- unit/common/Makefile | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 954b2a0..ba4a42d 100644 --- a/Makefile +++ b/Makefile @@ -126,6 +126,7 @@ COVERAGE_BUILD_DIR = $(BUILD_DIR)/coverage # Tools and flags # +PKG_CONFIG ?= pkg-config CC ?= $(CROSS_COMPILE)gcc STRIP ?= strip LD = $(CC) @@ -135,9 +136,9 @@ DEFINES += -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32 \ INCLUDES += -I$(INCLUDE_DIR) BASE_FLAGS = -fPIC FULL_CFLAGS = $(BASE_FLAGS) $(CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) \ - -MMD -MP $(shell pkg-config --cflags $(PKGS)) + -MMD -MP $(shell $(PKG_CONFIG) --cflags $(PKGS)) FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname,$(LIB_SONAME) \ - $(shell pkg-config --libs $(PKGS)) -lpthread + $(shell $(PKG_CONFIG) --libs $(PKGS)) -lpthread DEBUG_FLAGS = -g RELEASE_FLAGS = COVERAGE_FLAGS = -g diff --git a/test/binder-call/Makefile b/test/binder-call/Makefile index 35b5cb3..2eacb34 100644 --- a/test/binder-call/Makefile +++ b/test/binder-call/Makefile @@ -45,6 +45,7 @@ RELEASE_BUILD_DIR = $(BUILD_DIR)/release # Tools and flags # +PKG_CONFIG ?= pkg-config CC ?= $(CROSS_COMPILE)gcc LD = $(CC) WARNINGS = -Wall @@ -52,8 +53,8 @@ DEFINES += -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32 \ -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_MAX_ALLOWED INCLUDES = -I$(LIB_DIR)/include -I$(GEN_DIR) -I$(SRC_DIR) CFLAGS += -fPIC $(DEFINES) $(WARNINGS) $(INCLUDES) -MMD -MP \ - $(shell pkg-config --cflags $(PKGS)) -LDFLAGS += -pie $(shell pkg-config --libs $(PKGS)) + $(shell $(PKG_CONFIG) --cflags $(PKGS)) +LDFLAGS += -pie $(shell $(PKG_CONFIG) --libs $(PKGS)) QUIET_MAKE = $(MAKE) --no-print-directory DEBUG_FLAGS = -g RELEASE_FLAGS = diff --git a/test/common/Makefile b/test/common/Makefile index d37c07a..e81df69 100644 --- a/test/common/Makefile +++ b/test/common/Makefile @@ -43,6 +43,7 @@ RELEASE_BUILD_DIR = $(BUILD_DIR)/release # Tools and flags # +PKG_CONFIG ?= pkg-config CC ?= $(CROSS_COMPILE)gcc LD = $(CC) WARNINGS = -Wall @@ -50,8 +51,8 @@ DEFINES += -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32 \ -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_MAX_ALLOWED INCLUDES = -I$(LIB_DIR)/include CFLAGS += -fPIC $(DEFINES) $(WARNINGS) $(INCLUDES) -MMD -MP \ - $(shell pkg-config --cflags $(PKGS)) -LDFLAGS += -pie $(shell pkg-config --libs $(PKGS)) + $(shell $(PKG_CONFIG) --cflags $(PKGS)) +LDFLAGS += -pie $(shell $(PKG_CONFIG) --libs $(PKGS)) QUIET_MAKE = $(MAKE) --no-print-directory DEBUG_FLAGS = -g RELEASE_FLAGS = diff --git a/unit/common/Makefile b/unit/common/Makefile index 3164237..b9f6341 100644 --- a/unit/common/Makefile +++ b/unit/common/Makefile @@ -66,6 +66,7 @@ COVERAGE_BUILD_DIR = $(BUILD_DIR)/coverage # Tools and flags # +PKG_CONFIG ?= pkg-config CC ?= $(CROSS_COMPILE)gcc LD = $(CC) WARNINGS += -Wall -Wno-deprecated-declarations @@ -76,9 +77,9 @@ BASE_FLAGS = -fPIC BASE_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) BASE_CFLAGS = $(BASE_FLAGS) $(CFLAGS) FULL_CFLAGS = $(BASE_CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) -MMD -MP \ - $(shell pkg-config --cflags $(PKGS)) + $(shell $(PKG_CONFIG) --cflags $(PKGS)) FULL_LDFLAGS = $(BASE_LDFLAGS) -LIBS = $(shell pkg-config --libs $(PKGS)) -lpthread +LIBS = $(shell $(PKG_CONFIG) --libs $(PKGS)) -lpthread QUIET_MAKE = $(MAKE) --no-print-directory DEBUG_FLAGS = -g RELEASE_FLAGS =