summaryrefslogtreecommitdiff
path: root/examples/make.mk
diff options
context:
space:
mode:
authortobozo <[email protected]>2023-03-30 19:30:24 +0000
committerGitHub <[email protected]>2023-03-30 19:30:24 +0000
commit290f18a1fe4551cb0376d356627bda595c621518 (patch)
tree789f93ee268cb9c9cccc03702f8a1769ae4a3d9d /examples/make.mk
parent9e38b4cc68d9eeeb055349a97caf30d1cf4000e0 (diff)
parent5add4c97fa834004e6a3b267345a13c6d3c9514a (diff)
Merge branch 'hathach:master' into master
Diffstat (limited to 'examples/make.mk')
-rw-r--r--examples/make.mk93
1 files changed, 70 insertions, 23 deletions
diff --git a/examples/make.mk b/examples/make.mk
index bed46d02b..2ce6fb398 100644
--- a/examples/make.mk
+++ b/examples/make.mk
@@ -2,6 +2,35 @@
# Common make definition for all examples
# ---------------------------------------
+#-------------- TOP and CURRENT_PATH ------------
+
+# Set TOP to be the path to get from the current directory (where make was
+# invoked) to the top of the tree. $(lastword $(MAKEFILE_LIST)) returns
+# the name of this makefile relative to where make was invoked.
+THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
+
+# strip off /tools/top.mk to get for example ../../..
+# and Set TOP to an absolute path
+TOP = $(abspath $(subst make.mk,..,$(THIS_MAKEFILE)))
+
+# Set CURRENT_PATH to the relative path from TOP to the current directory, ie examples/device/cdc_msc_freertos
+CURRENT_PATH = $(subst $(TOP)/,,$(abspath .))
+
+# Detect whether shell style is windows or not
+# https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069
+ifeq '$(findstring ;,$(PATH))' ';'
+# PATH contains semicolon - so we're definitely on Windows.
+CMDEXE := 1
+
+# makefile shell commands should use syntax for DOS CMD, not unix sh
+# Unfortunately, SHELL may point to sh or bash, which can't accept DOS syntax.
+# We can't just use sh, because while sh and/or bash shell may be available,
+# many Windows environments won't have utilities like realpath used below, so...
+# Force DOS command shell on Windows.
+SHELL := cmd.exe
+endif
+
+
# Build directory
BUILD := _build/$(BOARD)
@@ -45,33 +74,40 @@ else
SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(FAMILY_PATH)/*.c))
endif
-# Fetch submodules depended by family
-fetch_submodule_if_empty = $(if $(wildcard $(TOP)/$1/*),,$(info $(shell git -C $(TOP) submodule update --init $1)))
-ifdef DEPS_SUBMODULES
- $(foreach s,$(DEPS_SUBMODULES),$(call fetch_submodule_if_empty,$(s)))
-endif
-
#-------------- Cross Compiler ------------
# Can be set by board, default to ARM GCC
CROSS_COMPILE ?= arm-none-eabi-
-# Allow for -Os to be changed by board makefiles in case -Os is not allowed
-CFLAGS_OPTIMIZED ?= -Os
-CC = $(CROSS_COMPILE)gcc
-CXX = $(CROSS_COMPILE)g++
-GDB = $(CROSS_COMPILE)gdb
-OBJCOPY = $(CROSS_COMPILE)objcopy
-SIZE = $(CROSS_COMPILE)size
-MKDIR = mkdir
+ifeq ($(CC),iccarm)
+USE_IAR = 1
+endif
+
+ifdef USE_IAR
+ AS = iasmarm
+ LD = ilinkarm
+ OBJCOPY = ielftool
+ SIZE = size
+
+else
+ CC = $(CROSS_COMPILE)gcc
+ CXX = $(CROSS_COMPILE)g++
+ AS = $(CC) -x assembler-with-cpp
+ LD = $(CC)
+
+ GDB = $(CROSS_COMPILE)gdb
+ OBJCOPY = $(CROSS_COMPILE)objcopy
+ SIZE = $(CROSS_COMPILE)size
+endif
ifeq ($(CMDEXE),1)
CP = copy
RM = del
+ MKDIR = mkdir
PYTHON = python
else
- SED = sed
CP = cp
RM = rm
+ MKDIR = mkdir
PYTHON = python3
endif
@@ -83,20 +119,23 @@ SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(BOARD_PATH)/*.c))
INC += $(TOP)/$(FAMILY_PATH)
-# Compiler Flags
-CFLAGS += \
+# Allow for -Os to be changed by board makefiles in case -Os is not allowed
+CFLAGS_OPTIMIZED ?= -Os
+
+# GCC Compiler Flags
+GCC_CFLAGS += \
-ggdb \
-fdata-sections \
-ffunction-sections \
-fsingle-precision-constant \
-fno-strict-aliasing \
- -Wdouble-promotion \
- -Wstrict-prototypes \
- -Wstrict-overflow \
-Wall \
-Wextra \
-Werror \
-Wfatal-errors \
+ -Wdouble-promotion \
+ -Wstrict-prototypes \
+ -Wstrict-overflow \
-Werror-implicit-function-declaration \
-Wfloat-equal \
-Wundef \
@@ -108,13 +147,21 @@ CFLAGS += \
-Wcast-align \
-Wcast-function-type \
-Wcast-qual \
- -Wnull-dereference
+ -Wnull-dereference \
+ -Wuninitialized \
+ -Wunused \
+ -Wreturn-type \
+ -Wredundant-decls
+
+# conversion is too strict for most mcu driver, may be disable sign/int/arith-conversion
+# -Wconversion
# Debugging/Optimization
ifeq ($(DEBUG), 1)
- CFLAGS += -Og
+ GCC_CFLAGS += -O0
+ NO_LTO = 1
else
- CFLAGS += $(CFLAGS_OPTIMIZED)
+ GCC_CFLAGS += $(CFLAGS_OPTIMIZED)
endif
# Log level is mapped to TUSB DEBUG option