# includes change. This function is designed to be used as a command in a rule.
# It takes one argument only, the type of file to compile (typically "c" or
# "cpp"). What to compile and the output files are built using the automatic
-# variables from a rule.
+# variables from a rule. You can add non-propagated object-specific flags
+# defining a variable with the name of the target followed with ".EXTRA_FLAGS".
define compile
$(if $(GCH),\
$Vif test -f $O/$*.d; then \
rm "$$tmp"; \
else \
mv "$$tmp" "$O/$*.$1.h"; \
- $(call vexec,$(COMPILE.$1) -o "$O/$*.$1.h.gch" "$O/$*.$1.h",\
- $O/$*.$1.h.gch); \
+ $(call vexec,$(COMPILE.$1) $($@.EXTRA_FLAGS) \
+ -o "$O/$*.$1.h.gch" "$O/$*.$1.h",$O/$*.$1.h.gch); \
fi \
else \
touch "$O/$*.$1.h"; \
fi \
)
-$(call exec,$(COMPILE.$1) -o $@ -MMD -MP $(if $(GCH),-include $O/$*.$1.h) $<)
+$(call exec,$(COMPILE.$1) $($@.EXTRA_FLAGS) -o $@ -MMD -MP \
+ $(if $(GCH),-include $O/$*.$1.h) $<)
endef
# Link object files to build an executable. The objects files are taken from
# taken from the rule automatic variables. If an argument is provided, it's
# included in the link command line. The variable LINKER is used to link the
# executable; for example, if you want to link a C++ executable, you should use
-# LINKER := $(CXX).
-link = $(call exec,$(LINKER) $(LDFLAGS) $(TARGET_ARCH) -o $@ $1 \
+# LINKER := $(CXX). You can add non-propagated target-specific flags defining
+# a variable with the name of the target followed with ".EXTRA_FLAGS". You can
+# specify a non-propagated object-specific linker defining a variable with the
+# name of the target followed with ".LINKER".
+link = $(call exec,$(if $($@.LINKER),$($@.LINKER),$(LINKER)) \
+ $(LDFLAGS) $(TARGET_ARCH) $($@.EXTRA_FLAGS) -o $@ $1 \
$(patsubst $L/lib%.so,-l%,$(filter %.so,$^)) \
$(foreach obj,$(filter %.o,$^),$(obj)))
endef
include_subdirs = $(foreach d,$1,$(eval $(build_subdir_code)))
-# Run a command through valgrind if $(VALGRIND) is non-empty. The first and
-# only argument is the command to. If $(VALGRIND) is empty, the command is
+# Run a command through valgrind if $(VALGRIND) is non-empty. The first
+# argument is the command to run. If $(VALGRIND) is empty, the command is
# executed as passed to this function. If valgrind is used, the
# $(VALGRIND_CMD) is prepended to the command to run. See VALGRIND_CMD
-# definition for extra options that can be passed as make variables.
+# definition for extra options that can be passed as make variables. The
+# second argument is the name of the command to print when $V is non-empty (if
+# omitted, the first word of the first argument is used).
valgrind = $(call exec,$(if $(VALGRIND),$(VALGRIND_CMD)) $1,\
$(if $(VALGRIND),[$(firstword $(VALGRIND_CMD))], ),\
- $(firstword $1))
+ $(if $2,$2,$(firstword $1)))
# Overridden flags