lkml.org 
[lkml]   [2011]   [Mar]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH trace-cmd v2] trace-cmd: allow setting CC and AR, or CROSS_COMPILE from command line
Date
Makefiles suck: Use some makefile magic to get the best of all worlds for
CC and AR: Sane defaults and the ability to override CC, and AR, or use
CROSS_COMPILE to set a prefix.

Signed-off-by: David Sharp <dhsharp@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Darren Hart <dvhart@linux.intel.com>
---
Makefile | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 169fcbc..c4cd926 100644
--- a/Makefile
+++ b/Makefile
@@ -13,8 +13,22 @@ FILE_VERSION = 6

MAKEFLAGS += --no-print-directory

-CC ?= $(CROSS_COMPILE)gcc
-AR ?= $(CROSS_COMPILE)ar
+
+# Makefiles suck: This macro sets a default value of $(2) for the
+# variable named by $(1), unless the variable has been set by
+# environment or command line. This is necessary for CC and AR
+# because make sets default values, so the simpler ?= approach
+# won't work as expected.
+define allow-override
+ $(if $(or $(findstring environment,$(origin $(1))),\
+ $(findstring command line,$(origin $(1)))),,\
+ $(eval $(1) = $(2)))
+endef
+
+# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
+$(call allow-override,CC,$(CROSS_COMPILE)gcc)
+$(call allow-override,AR,$(CROSS_COMPILE)ar)
+
EXT = -std=gnu99
INSTALL = install

--
1.7.3.1


\
 
 \ /
  Last update: 2011-03-10 22:15    [W:0.059 / U:0.280 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site