tools: respect CFLAGS and LDFLAGS from environment

The build environment might want to pass extra CFLAGS or LDFLAGS to the build of
the acrn tools. With conventional build systems like automake, Meson, etc this
is possible by just setting CFLAGS and LDFLAGS in the environment.

However as the tools are built using bare Makefiles, these environment variables
are overwritten.  Respect them by renaming the variables in the Makefiles to
e.g. LOG_CFLAGS and adding CFLAGS to that.

Tracked-On: #2316
Signed-off-by: Ross Burton <ross.burton@intel.com>
This commit is contained in:
Ross Burton
2019-01-11 11:27:50 +00:00
committed by wenlingz
parent 899c914606
commit 912be6c4dd
3 changed files with 64 additions and 58 deletions

View File

@@ -2,15 +2,16 @@ T := $(CURDIR)
OUT_DIR ?= $(shell mkdir -p $(T)/build;cd $(T)/build;pwd)
CC ?= gcc
CFLAGS := -g -O0 -std=gnu11
CFLAGS += -D_GNU_SOURCE
CFLAGS += -DNO_OPENSSL
CFLAGS += -m64
CFLAGS += -Wall -ffunction-sections
CFLAGS += -Werror
CFLAGS += -O2 -D_FORTIFY_SOURCE=2
CFLAGS += -Wformat -Wformat-security -fno-strict-aliasing
CFLAGS += -fpie -fpic
TRACE_CFLAGS := -g -O0 -std=gnu11
TRACE_CFLAGS += -D_GNU_SOURCE
TRACE_CFLAGS += -DNO_OPENSSL
TRACE_CFLAGS += -m64
TRACE_CFLAGS += -Wall -ffunction-sections
TRACE_CFLAGS += -Werror
TRACE_CFLAGS += -O2 -D_FORTIFY_SOURCE=2
TRACE_CFLAGS += -Wformat -Wformat-security -fno-strict-aliasing
TRACE_CFLAGS += -fpie -fpic
TRACE_CFLAGS += $(CFLAGS)
GCC_MAJOR=$(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)
GCC_MINOR=$(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1)
@@ -20,22 +21,23 @@ STACK_PROTECTOR := 1
ifdef STACK_PROTECTOR
ifeq (true, $(shell [ $(GCC_MAJOR) -gt 4 ] && echo true))
CFLAGS += -fstack-protector-strong
TRACE_CFLAGS += -fstack-protector-strong
else
ifeq (true, $(shell [ $(GCC_MAJOR) -eq 4 ] && [ $(GCC_MINOR) -ge 9 ] && echo true))
CFLAGS += -fstack-protector-strong
TRACE_CFLAGS += -fstack-protector-strong
else
CFLAGS += -fstack-protector
TRACE_CFLAGS += -fstack-protector
endif
endif
endif
LDFLAGS := -Wl,-z,noexecstack
LDFLAGS += -Wl,-z,relro,-z,now
LDFLAGS += -pie
TRACE_LDFLAGS := -Wl,-z,noexecstack
TRACE_LDFLAGS += -Wl,-z,relro,-z,now
TRACE_LDFLAGS += -pie
TRACE_LDFLAGS += $(LDFLAGS)
all:
$(CC) -o $(OUT_DIR)/acrntrace acrntrace.c sbuf.c -I. -lpthread -lrt $(CFLAGS) $(LDFLAGS)
$(CC) -o $(OUT_DIR)/acrntrace acrntrace.c sbuf.c -I. -lpthread -lrt $(TRACE_CFLAGS) $(TRACE_LDFLAGS)
clean:
rm -f $(OUT_DIR)/acrntrace