diff options
Diffstat (limited to 'Makefile.macros')
-rw-r--r-- | Makefile.macros | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/Makefile.macros b/Makefile.macros new file mode 100644 index 000000000..37a9954d4 --- /dev/null +++ b/Makefile.macros @@ -0,0 +1,137 @@ +# -*- mode: makefile-gmake -*- +## +## Netsurf library and feature macros +## + +# A macro that conditionaly adds flags to the build when a feature is enabled. +# +# 1: Feature name (ie, NETSURF_USE_BMP -> BMP) +# 2: Parameters to add to CFLAGS +# 3: Parameters to add to LDFLAGS +# 4: Human-readable name for the feature +define feature_enabled + ifeq ($$(NETSURF_USE_$(1)),YES) + CFLAGS += $(2) + CXXFLAGS += $(2) + LDFLAGS += $(3) + ifneq ($(MAKECMDGOALS),clean) + $$(info M.CONFIG: $(4) enabled (NETSURF_USE_$(1) := YES)) + endif + else ifeq ($$(NETSURF_USE_$(1)),NO) + ifneq ($(MAKECMDGOALS),clean) + $$(info M.CONFIG: $(4) disabled (NETSURF_USE_$(1) := NO)) + endif + else + $$(info M.CONFIG: $(4) error (NETSURF_USE_$(1) := $$(NETSURF_USE_$(1)))) + $$(error NETSURF_USE_$(1) must be YES or NO) + endif +endef + +# A macro that conditionaly adds flags to the build with a uniform display. +# +# 1: Feature name (ie, NETSURF_USE_BMP -> BMP) +# 2: Human-readable name for the feature +# 3: Parameters to add to CFLAGS when enabled +# 4: Parameters to add to LDFLAGS when enabled +# 5: Parameters to add to CFLAGS when disabled +# 6: Parameters to add to LDFLAGS when disabled +define feature_switch + ifeq ($$(NETSURF_USE_$(1)),YES) + CFLAGS += $(3) + CXXFLAGS += $(3) + LDFLAGS += $(4) + ifneq ($(MAKECMDGOALS),clean) + $$(info M.CONFIG: $(2) enabled (NETSURF_USE_$(1) := YES)) + endif + else ifeq ($$(NETSURF_USE_$(1)),NO) + CFLAGS += $(5) + CXXFLAGS += $(5) + LDFLAGS += $(6) + ifneq ($(MAKECMDGOALS),clean) + $$(info M.CONFIG: $(2) disabled (NETSURF_USE_$(1) := NO)) + endif + else + $$(info M.CONFIG: $(4) error (NETSURF_USE_$(1) := $$(NETSURF_USE_$(1)))) + $$(error NETSURF_USE_$(1) must be YES or NO) + endif +endef + +# Extend flags with appropriate values from pkg-config for enabled features +# +# 1: pkg-config required modules for feature +# 2: Human-readable name for the feature +define pkg_config_find_and_add + ifeq ($$(PKG_CONFIG),) + $$(error pkg-config is required to auto-detect feature availability) + endif + + PKG_CONFIG_$(1)_EXISTS := $$(shell $$(PKG_CONFIG) --exists $(1) && echo yes) + + ifeq ($$(PKG_CONFIG_$(1)_EXISTS),yes) + CFLAGS += $$(shell $$(PKG_CONFIG) --cflags $(1)) + CXXFLAGS += $$(shell $$(PKG_CONFIG) --cflags $(1)) + LDFLAGS += $$(shell $$(PKG_CONFIG) --libs $(1)) + ifneq ($(MAKECMDGOALS),clean) + $$(info PKG.CNFG: $(2) ($(1)) enabled) + endif + else + ifneq ($(MAKECMDGOALS),clean) + $$(info PKG.CNFG: $(2) ($(1)) failed) + $$(error Unable to find library for: $(2) ($(1))) + endif + endif +endef + +# Extend flags with appropriate values from pkg-config for enabled features +# +# 1: Feature name (ie, NETSURF_USE_RSVG -> RSVG) +# 2: pkg-config required modules for feature +# 3: Human-readable name for the feature +define pkg_config_find_and_add_enabled + ifeq ($$(PKG_CONFIG),) + $$(error pkg-config is required to auto-detect feature availability) + endif + + NETSURF_FEATURE_$(1)_AVAILABLE := $$(shell $$(PKG_CONFIG) --exists $(2) && echo yes) + NETSURF_FEATURE_$(1)_CFLAGS ?= -DWITH_$(1) + + ifeq ($$(NETSURF_USE_$(1)),YES) + ifeq ($$(NETSURF_FEATURE_$(1)_AVAILABLE),yes) + CFLAGS += $$(shell $$(PKG_CONFIG) --cflags $(2)) $$(NETSURF_FEATURE_$(1)_CFLAGS) + CXXFLAGS += $$(shell $$(PKG_CONFIG) --cflags $(2)) $$(NETSURF_FEATURE_$(1)_CFLAGS) + LDFLAGS += $$(shell $$(PKG_CONFIG) --libs $(2)) $$(NETSURF_FEATURE_$(1)_LDFLAGS) + ifneq ($(MAKECMDGOALS),clean) + $$(info M.CONFIG: $(3) ($(2)) enabled (NETSURF_USE_$(1) := YES)) + endif + else + ifneq ($(MAKECMDGOALS),clean) + $$(info M.CONFIG: $(3) ($(2)) failed (NETSURF_USE_$(1) := YES)) + $$(error Unable to find library for: $(3) ($(2))) + endif + endif + else ifeq ($$(NETSURF_USE_$(1)),AUTO) + ifeq ($$(NETSURF_FEATURE_$(1)_AVAILABLE),yes) + CFLAGS += $$(shell $$(PKG_CONFIG) --cflags $(2)) $$(NETSURF_FEATURE_$(1)_CFLAGS) + CXXFLAGS += $$(shell $$(PKG_CONFIG) --cflags $(2)) $$(NETSURF_FEATURE_$(1)_CFLAGS) + LDFLAGS += $$(shell $$(PKG_CONFIG) --libs $(2)) $$(NETSURF_FEATURE_$(1)_LDFLAGS) + ifneq ($(MAKECMDGOALS),clean) + $$(info M.CONFIG: $(3) ($(2)) auto-enabled (NETSURF_USE_$(1) := AUTO)) + NETSURF_USE_$(1) := YES + endif + else + ifneq ($(MAKECMDGOALS),clean) + $$(info M.CONFIG: $(3) ($(2)) auto-disabled (NETSURF_USE_$(1) := AUTO)) + NETSURF_USE_$(1) := NO + endif + endif + else ifeq ($$(NETSURF_USE_$(1)),NO) + ifneq ($(MAKECMDGOALS),clean) + $$(info M.CONFIG: $(3) ($(2)) disabled (NETSURF_USE_$(1) := NO)) + endif + else + ifneq ($(MAKECMDGOALS),clean) + $$(info M.CONFIG: $(3) ($(2)) error (NETSURF_USE_$(1) := $$(NETSURF_USE_$(1)))) + $$(error NETSURF_USE_$(1) must be YES, NO, or AUTO) + endif + endif +endef |