qmk build system

This commit is contained in:
huangjimin
2020-07-15 16:51:41 +08:00
parent 25f293d49a
commit d895c15e4f
27 changed files with 3320 additions and 136 deletions

View File

@@ -1,8 +0,0 @@
CFGFLAGS += -I${QTOP}/arch/linux/common/include/
CFGFLAGS += -I${QTOP}/arch/linux/posix/gcc
ARCH_LSCRS := $(wildcard ${QTOP}/arch/linux/posix/gcc/*.c)
ARCH_LSCRS += $(wildcard ${QTOP}/arch/linux/common/*.c)

View File

View File

@@ -22,7 +22,14 @@ ifeq ($(filter-out Linux Darwin,$(uname)),)
endif
endif
include ${QTOP}/qmk/arch-pack/ap.linux.posix.gcc
CFGFLAGS += -I${QTOP}/arch/linux/common/include/
CFGFLAGS += -I${QTOP}/arch/linux/posix/gcc
ARCH_LSCRS := $(wildcard ${QTOP}/arch/linux/posix/gcc/*.c)
ARCH_LSCRS += $(wildcard ${QTOP}/arch/linux/common/*.c)
CFGFLAGS += -O0 -Wall -g2 -ggdb

View File

@@ -0,0 +1,88 @@
CROSS_COMPILE =arm-none-eabi-
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
LD = $(CROSS_COMPILE)ld
AR = $(CROSS_COMPILE)ar
ARFLAGS = -rc
STRIP = $(CROSS_COMPILE)strip
RANLIB = $(CROSS_COMPILE)ranlib
# cpu
CFGFLAGS += -mcpu=cortex-m4
# fpu
CFGFLAGS += -mfpu=fpv4-sp-d16
# float-abi
CFGFLAGS += -mfloat-abi=hard -mthumb
# Device
CFGFLAGS += -DUSE_HAL_DRIVER -DSTM32L431xx
CFGFLAGS += -Wall -fdata-sections -ffunction-sections
CFGFLAGS += -g -gdwarf-2
# C includes
# Kernel
CFGFLAGS += -I${QTOP}/kernel/core/include
CFGFLAGS += -I${QTOP}/kernel/evtdrv/include
CFGFLAGS += -I${QTOP}/kernel/hal/include
CFGFLAGS += -I${QTOP}/kernel/pm/include
# Arch
CFGFLAGS += -I$(QTOP)/arch/arm/arm-v7m/common/include
CFGFLAGS += -I$(QTOP)/arch/arm/arm-v7m/cortex-m4/gcc
ARCH_LSRCS += $(wildcard ${QTOP}/arch/arm/arm-v7m/cortex-m4/gcc/*.c)
ARCH_LSRCS += $(wildcard ${QTOP}/arch/arm/arm-v7m/cortex-m4/gcc/*.s)
ARCH_LSRCS += $(wildcard ${QTOP}/arch/arm/arm-v7m/cortex-m4/gcc/*.S)
ARCH_LSRCS += $(wildcard ${QTOP}/arch/arm/arm-v7m/common/*.c)
ARCH_LSRCS += $(wildcard ${QTOP}/arch/arm/arm-v7m/common/*.s)
ARCH_LSRCS += $(wildcard ${QTOP}/arch/arm/arm-v7m/common/*.S)
# Board
CFGFLAGS += -I$(QTOP)/board/TencentOS_tiny_EVB_MX_Plus/TOS-CONFIG
# CMSIS
CFGFLAGS += -I${QTOP}/osal/cmsis_os
#board BSP
CFGFLAGS += -I$(QTOP)/board/TencentOS_tiny_EVB_MX_Plus/BSP/Inc
CFGFLAGS += -I$(QTOP)/platform/vendor_bsp/st/STM32L4xx_HAL_Driver/Inc
CFGFLAGS += -I$(QTOP)/platform/vendor_bsp/st/STM32L4xx_HAL_Driver/Inc/Legacy
CFGFLAGS += -I$(QTOP)/platform/vendor_bsp/st/CMSIS/Device/ST/STM32L4xx/Include
CFGFLAGS += -I$(QTOP)/platform/vendor_bsp/st/CMSIS/Include
CFGFLAGS += -I$(QTOP)/board/TencentOS_tiny_EVB_MX_Plus/BSP/Hardware/DHT11
CFGFLAGS += -I$(QTOP)/board/TencentOS_tiny_EVB_MX_Plus/BSP/Hardware/BH1750
CFGFLAGS += -I$(QTOP)/board/TencentOS_tiny_EVB_MX_Plus/BSP/Hardware/OLED
CFGFLAGS += -I$(QTOP)/examples/event_driven_at_module/at_evtdrv/include
#board BSP
CFGFLAGS += -I$(QTOP)/net/at/include
CFGFLAGS += -I$(QTOP)/net/sal_module_wrapper
CFGFLAGS += -I$(QTOP)/board/TencentOS_tiny_EVB_MX_Plus/BSP/Hardware/PM25
CFGFLAGS += -I$(QTOP)/board/TencentOS_tiny_EVB_MX_Plus/BSP/Hardware/Modbus_Port
CFGFLAGS += -I$(QTOP)/board/TencentOS_tiny_EVB_MX_Plus/BSP/Hardware/E53_IA1
CFGFLAGS += -I$(QTOP)/devices/esp8266
CFGFLAGS += -I$(QTOP)/components/connectivity/Modbus/3rdparty/freemodbus-v1.6/modbus/include
CFGFLAGS += -I$(QTOP)/components/shell/include
CFGFLAGS += -I$(QTOP)/components/connectivity/mqttclient/mqttclient
CFGFLAGS += -I$(QTOP)/components/connectivity/mqttclient/mqtt
CFGFLAGS += -I$(QTOP)/components/connectivity/mqttclient/common
CFGFLAGS += -I$(QTOP)/components/connectivity/mqttclient/platform/TencentOS-tiny
CFGFLAGS += -I$(QTOP)/components/connectivity/mqttclient/network
CFGFLAGS += -I$(QTOP)/components/fs/kv/include
CFGFLAGS += -I$(QTOP)/components/ota/common/flash
CFGFLAGS += -I$(QTOP)/components/connectivity/Eclipse-Paho-MQTT/wrapper/include
CFGFLAGS += -I$(QTOP)/components/utils/JSON/include
BSP_LSRCS += $(shell find $(QTOP)/board/TencentOS_tiny_EVB_MX_Plus/BSP/Src -name "*.c" -o -name "*.s")
BSP_LSRCS += $(shell find $(QTOP)/board/TencentOS_tiny_EVB_MX_Plus/BSP/Hardware -name "*.c" -o -name "*.s")
#platform/vendor_bsp
PLATFORM_VENDOR_BSP_LSRCS += $(shell find $(QTOP)/platform/vendor_bsp/st/STM32L4xx_HAL_Driver/Src -name "*.c" -o -name "*.s")
PLATFORM_HAL_LSRCS += $(shell find $(QTOP)/platform/hal/st/stm32l4xx -name "*.c" -o -name "*.s")

View File

@@ -42,10 +42,9 @@ $(targetexec): $(OUTDIR)/.tree ${LD_O_FILES}
@$(ECHO) "[$(BP)] LINK $@" # This is needed for error parsing
$(Q)/bin/ls $(LIBDIR)
$(Q)$(CC) \
-o $@ \
-L${LIBDIR} \
$(_LD_START_GROUP) $(LD_O_FILES) $(LD_A_FILES) $(LD_L_LISTS) $(LDFLAGS) $(_LD_END_GROUP) \
$(LD_INFO_OPTS)
$(patsubst -I%,,${CFLAGS} ${EXTRA_CFLAGS} ${LDFLAGS}) \
-o $@ -L${LIBDIR} \
$(_LD_START_GROUP) $(LD_O_FILES) $(LD_A_FILES) $(_LD_END_GROUP) $(LD_L_LISTS) $(LD_INFO_OPTS)
$(Q)$(STRIP) --strip-debug $@ -o $(OUTDIR)/$(basename $(notdir $@)).strip
$(Q)$(OBJCOPY) -O binary -S $@ $(OUTDIR)/$(basename $(notdir $@)).bin
$(Q)$(OBJCOPY) -O ihex $@ $(OUTDIR)/$(basename $(notdir $@)).hex

View File

@@ -115,13 +115,13 @@ ifeq (,$(strip ${LSRCS})) # LSRCS
ifeq (,$(filter n no NO 0,$(TREE_LIB_ENABLE))) # TREE_LIB_ENABLE yes
ifeq (,$(strip ${LSRCS_DIRS})) # LSRCS_DIRS
LSRCS_ALL = $(patsubst ./%,%, $(sort $(shell find . -name "*.c" -o -name "*.cpp" -o -name "*.s" -o -name "*.cc")))
LSRCS_ALL = $(patsubst ./%,%, $(sort $(shell find . -name "*.c" -o -name "*.cpp" -o -name "*.s" -o -name "*.S" -o -name "*.cc")))
else
LSRCS_ALL = $(patsubst ./%,%, $(sort $(shell find ${LSRCS_DIRS} -name "*.c" -o -name "*.cpp" -o -name "*.s" -o -name "*.cc")))
LSRCS_ALL = $(patsubst ./%,%, $(sort $(shell find ${LSRCS_DIRS} -name "*.c" -o -name "*.cpp" -o -name "*.s" -o -name "*.S" -o -name "*.cc")))
endif # LSRCS_DIRS
else # TREE_LIB_ENABLE
LSRCS_ALL = $(patsubst ./%,%,$(sort $(wildcard *.c *.cpp *.s *.cc *.C))) # only include src in this dir.
LSRCS_ALL = $(patsubst ./%,%,$(sort $(wildcard *.c *.cpp *.s *.S *.cc *.C))) # only include src in this dir.
endif # TREE_LIB_ENABLE
endif # LSRCS
@@ -136,7 +136,7 @@ else
$(info $(shell echo -e "[$(BP)] INFO LSRCS is defined by users, LSRCS=$(LSRCS)"))
endif
LOBJS = $(addsuffix .o, $(basename ${LSRCS}))
LOBJS = $(patsubst $(QTOP)/%,%,$(addsuffix .o, $(basename ${LSRCS})))
BOBJS = $(addprefix ${BLDDIR}/,${LOBJS})
#
@@ -154,7 +154,7 @@ BOBJS = $(addprefix ${BLDDIR}/,${LOBJS})
# Rule allowing build through CPP only, creates .i file from .c file.
%.i: %.c
@$Q$(ECHO) "EEEE ${LOCALDIR}/$<"
@$Q$(ECHO) "[$(BP)] EEEE ${LOCALDIR}/$<"
$Q$(CC) -E ${CFLAGS} $< | $(SED) -e '/^ *$$/d' -e p -e d > $@
# Rule allowing build through source only, creates .s file from .c file.
@@ -170,110 +170,13 @@ NO_QMK_DEPS = 1
# dependency makefiles
#
ifndef NO_QMK_DEPS
# take the compiler generated .d file and reparse it
# to generate a dependency graph rule for this object
# file
# the two steps generate:
# file.o: file.c \
# file.h ...
#
# file.h:
# header.h:
# some compilers will generate errors without the latter
# part of the list
.PHONY: .phony
zDEPS_SED = \
$(CP) $(BLDDIR)/$*.d $(BLDDIR)/$*.tmp;\
$(ECHO) >> $(BLDDIR)/$*.tmp;\
$(SED) -e 's/\#.*//' -e 's/^[^:]*: *//' \
-e 's/ *\\$$//' -e '/^$$/ d' -e 's/$$/ :/' \
-e '/^ .$$/d' \
< $(BLDDIR)/$*.d >> $(BLDDIR)/$*.tmp; \
$(SED) -e 's|^\([^\/ ].*\.o\):|'$(BLDDIR)/'\1:|g' \
-e 's|.*?/\(.*\.o\):|'$(BLDDIR)/'\1:|g' \
< $(BLDDIR)/$*.tmp > $(BLDDIR)/$*.P; \
$(RM) -f $(BLDDIR)/$*.d $(BLDDIR)/$*.tmp
zDEPS_CMD = $(zDEPS_SED)
zDEPS_OPT = -MMD -MP -MF'$(@:%.o=%.d)'
endif # ifndef NO_QMK_DEPS
# newer gnu-based compilers allow -MD -MF
zDEPS_OPT = -MD -MF $(BLDDIR)/$*.d
zDEPS_CMD = $(zDEPS_SED)
# From gmsl
# Standard definitions for true and false. true is any non-empty
# string, false is an empty string. These are intended for use with
# $(if).
true := T
false :=
# ----------------------------------------------------------------------------
# Function: not
# Arguments: 1: A boolean value
# Returns: Returns the opposite of the arg. (true -> false, false -> true)
# ----------------------------------------------------------------------------
not = $(if $1,$(false),$(true))
# ----------------------------------------------------------------------------
# Function: map
# Arguments: 1: Name of function to $(call) for each element of list
# 2: List to iterate over calling the function in 1
# Returns: The list after calling the function on each element
# ----------------------------------------------------------------------------
map = $(strip $(foreach a,$2,$(call $1,$a)))
# ----------------------------------------------------------------------------
# Function: seq
# Arguments: 1: A string to compare against...
# 2: ...this string
# Returns: Returns $(true) if the two strings are identical
# ----------------------------------------------------------------------------
seq = $(if $(filter-out xx,x$(subst $1,,$2)$(subst $2,,$1)x),$(false),$(true))
# ----------------------------------------------------------------------------
# Function: sne
# Arguments: 1: A string to compare against...
# 2: ...this string
# Returns: Returns $(true) if the two strings are not the same
# ----------------------------------------------------------------------------
sne = $(call not,$(call seq,$1,$2))
# End from gmsl
# Define comma symbol so we can repace it with a variable
comma :=,
# Signature
last_target :=
adump_var = $$(eval $1 := $($1))
define new_rule
@echo '$(call map,adump_var,@ < *)' > $S
@$(if $(wildcard $F),,touch $F)
@echo $@: $F >> $S
endef
define zdo
$(eval S := $(BLDDIR)/$*.sig)$(eval F := $(BLDDIR)/$*.force)$(eval C := $1)
$(if $(call sne,$@,$(last_target)),$(call new_rule),$(eval last_target := $@))
@echo '$$(if $$(call sne,$$(sort $1),$(sort $(subst $(comma),$$(comma),$C))),$$(shell touch $F))' >> $S
$Q$C
endef
# end of Signature
else # ifndef NO_QMK_DEPS
# No dependency files, faster compile times
# no partial compile support
zDEPS_SED =
zDEPS_OPT =
zDEPS_CPY =
zDEPS_CMD = /bin/true
@@ -282,38 +185,58 @@ $(eval C := $1)
$Q$C
endef
endif # ifndef NO_QMK_DEPS
#
# Default Build rules for .c --> .o, leaving the binary in BLDDIR/X.o,
# even if file not built from directory of source.
#
${BLDDIR}/%.o: %.c
ifdef EEEE
@$Q$(ECHO) "EEEE ${LOCALDIR}/$<"
$Q$(CC) -E ${CFLAGS} $(EXTRA_CFLAGS) $< | $(SED) -e '/^ *$$/d' -e p -e d > $(@:.o=.i)
endif
# echo Compiling needed to properly process errors
$Q$(MKDIR) $(BLDDIR)/
${BLDDIR}/%.o: $(QTOP)/%.c
$Q$(MKDIR) $(dir $@)
$Q$(RM) -f $@
ifdef E
@$Q$(ECHO) '[$(BP)] EEEE ${LOCALDIR}/$<'
$Q$(CC) -E ${CFLAGS} $(EXTRA_CFLAGS) $< | $(SED) -e '/^ *$$/d' -e p -e d > $(@:.o=.i)
endif
ifdef S
@$Q$(ECHO) "[$(BP)] SSSS ${LOCALDIR}/$<"
$Q$(CC) -S ${CFLAGS} $<
endif
@$Q$(ECHO) "[$(BP)] CCCC $<"
$Q$(call zdo,$$(CC) $$(zDEPS_OPT) $$(CFLAGS) $$(EXTRA_CFLAGS) -o $$@ -c $$(realpath $$<)) && ($(zDEPS_CMD))
${BLDDIR}/%.o: %.c
$Q$(MKDIR) $(dir $@)
$Q$(RM) -f $@
ifdef E
@$Q$(ECHO) "[$(BP)] EEEE ${LOCALDIR}/$<"
$Q$(CC) -E ${CFLAGS} $(EXTRA_CFLAGS) $< | $(SED) -e '/^ *$$/d' -e p -e d > $(@:.o=.i)
endif
@$Q$(ECHO) "[$(BP)] CCCC ${LOCALDIR}/$<"
$Q$(call zdo,$$(CC) $$(zDEPS_OPT) $$(CFLAGS) $$(EXTRA_CFLAGS) -o $$@ -c $$(realpath $$<)) && ($(zDEPS_CMD))
${BLDDIR}/%.o: %.s
ifeq (@,$(Q))
@$(ECHO) ASAS ${LOCALDIR}/$<
endif
$Q$(MKDIR) $(dir $@)
$Q$(ECHO) "[$(BP)] ASAS ${LOCALDIR}/$<"
# $Q$(MKDIR) $(BLDDIR)/
# $Q$(MKDIR) $(dir $@)
$Q$(RM) -f $@
$Q$(CC) ${CFLAGS} ${EXTRA_CFLAGS} -o $@ -c $(realpath $<)
${BLDDIR}/%.o: %.S
$Q$(MKDIR) $(dir $@)
$Q$(ECHO) "[$(BP)] ASAS ${LOCALDIR}/$<"
$Q$(RM) -f $@
$Q$(CC) ${CFLAGS} ${EXTRA_CFLAGS} -o $@ -c $(realpath $<)
${BLDDIR}/%.o: %.cpp
$Q$(MKDIR) $(dir $@)
ifeq (@,$(Q))
@$(ECHO) "[$(BP)] CCCC ${LOCALDIR}/$<"
endif
$Q$(CXX) ${CXXFLAGS} -o $@ -c $(realpath $<)
${BLDDIR}/%.o: %.cc ${BLDDIR}/.tree
${BLDDIR}/%.o: %.cc
$Q$(MKDIR) $(dir $@)
ifeq (@,$(Q))
@$(ECHO) "[$(BP)] CCCC ${LOCALDIR}/$<"
endif
@@ -342,7 +265,7 @@ help:
$Q$(ECHO) -e "\t make clean all"
$Q$(ECHO) -e "Debug build, verbose print, generate preprocess .i for .c"
$Q$(ECHO) -e "\t make V=1 "
$Q$(ECHO) -e "\t make EEEE=1 "
$Q$(ECHO) -e "\t make E=1 "
$Q$(ECHO) -e "Debug Makefile"
$Q$(ECHO) -e "\t make dm"
endif