summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@wdc.com>2019-01-04 06:15:36 +0300
committerAnup Patel <anup@brainfault.org>2019-01-05 14:10:22 +0300
commit2e5ede82796960435fff80b27b21dfb399d2e2fb (patch)
tree7d5fa74aa42a6b13fc519cdae180cbc66e8a3529 /Makefile
parent45c9e14a2f329950645fa7eb30306913650642d8 (diff)
downloadopensbi-2e5ede82796960435fff80b27b21dfb399d2e2fb.tar.xz
Makefile: Use '=' instead of '?=' for make variables
The '?=' will not assign value if the target make variable is overriden via command-line or is set in environment variable. On other hand, '=' will not assign value only if variable is overriden via command-line parameter. It is quite common to have CC, AS, CPP, LD, etc to be set as environment variables pointing to native compiler and binutils. If '-rR' option is not set in MAKEFLAGS then this results in compile error because '?=' will use the native compiler and binutils. If '-rR' option is set in MAKEFLAGS then this again results in compile error because CC, AS, CPP, etc are set to empty strings which causes '?=' to use empty string as compiler and binutils. To handle this, we use '?=' only when CROSS_COMPILE is not defined and we use '=' when CROSS_COMPILE is defined. Signed-off-by: Anup Patel <anup.patel@wdc.com>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile32
1 files changed, 26 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 139ca46..5c7d4fb 100644
--- a/Makefile
+++ b/Makefile
@@ -100,7 +100,11 @@ GENFLAGS += $(platform-genflags-y)
GENFLAGS += $(firmware-genflags-y)
# Setup compilation environment
-CC ?= $(CROSS_COMPILE)gcc
+ifdef CROSS_COMPILE
+CC = $(CROSS_COMPILE)gcc
+else
+CC ?= gcc
+endif
CFLAGS = -g -Wall -Werror -nostdlib -fno-strict-aliasing -O2
CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
CFLAGS += -mno-save-restore -mstrict-align
@@ -108,12 +112,16 @@ CFLAGS += $(GENFLAGS)
CFLAGS += $(platform-cflags-y)
CFLAGS += $(firmware-cflags-y)
-CPP ?= $(CROSS_COMPILE)cpp
+ifdef CROSS_COMPILE
+CPP = $(CROSS_COMPILE)cpp
+else
+CPP ?= cpp
+endif
CPPFLAGS += $(GENFLAGS)
CPPFLAGS += $(platform-cppflags-y)
CPPFLAGS += $(firmware-cppflags-y)
-AS = $(CC)
+AS = $(CC)
ASFLAGS = -g -Wall -nostdlib -D__ASSEMBLY__
ASFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
ASFLAGS += -mno-save-restore -mstrict-align
@@ -121,17 +129,29 @@ ASFLAGS += $(GENFLAGS)
ASFLAGS += $(platform-asflags-y)
ASFLAGS += $(firmware-asflags-y)
-AR ?= $(CROSS_COMPILE)ar
+ifdef CROSS_COMPILE
+AR = $(CROSS_COMPILE)ar
+else
+AR ?= ar
+endif
ARFLAGS = rcs
-LD ?= $(CROSS_COMPILE)ld
+ifdef CROSS_COMPILE
+LD = $(CROSS_COMPILE)ld
+else
+LD ?= ld
+endif
LDFLAGS += -g -Wall -nostdlib -Wl,--build-id=none -N
LDFLAGS += $(platform-ldflags-y)
LDFLAGS += $(firmware-ldflags-y)
MERGEFLAGS += -r
-OBJCOPY ?= $(CROSS_COMPILE)objcopy
+ifdef CROSS_COMPILE
+OBJCOPY = $(CROSS_COMPILE)objcopy
+else
+OBJCOPY ?= objcopy
+endif
# Setup functions for compilation
define dynamic_flags