mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 20:13:32 +01:00
Re-add everthing needed for building and packaging ytools. This is a big commit, 2002 lines of code. It mostly consists of C/C++ machinery, plus some documentation-related stuff. Signed-off-by: Jan Lindemann <jan@janware.com>
808 lines
28 KiB
Makefile
808 lines
28 KiB
Makefile
ifndef JW_BUILD_CPP_DEFS_MK_INCLUDED
|
|
JW_BUILD_CPP_DEFS_MK_INCLUDED := true
|
|
|
|
# performance optimization for clean targets
|
|
ifeq ($(filter clean distclean,$(MAKECMDGOALS)),)
|
|
|
|
# -- default choices
|
|
|
|
#COMPILER_SUITE ?= clang
|
|
COMPILER_SUITE ?= gcc
|
|
CPP_STANDARD_VERSION ?= 17
|
|
C_STANDARD_VERSION ?= 11
|
|
USE_PROJECT_LIB ?= true
|
|
EXPORT_PROJECT_LIB ?= $(USE_PROJECT_LIB)
|
|
USE_JW_BUILD ?= true
|
|
USE_EXCEPTIONS_IN_C ?= true
|
|
USE_COMPILER_OPTIMIZATION_OPTS ?= false
|
|
USE_COMPILER_DEBUG_OPTS ?= true
|
|
USE_VERSION_MACROS ?= true
|
|
COMPILE_DEBUG_CODE ?= true
|
|
|
|
ifeq ($(findstring $(TARGET_OS),linux),)
|
|
USE_SYSTEMD := false
|
|
endif
|
|
|
|
ifeq ($(USE_CCACHE),true)
|
|
CCACHE := ccache$(space)
|
|
endif
|
|
|
|
# -- build TAGGED_TMPL_TAGS cascade
|
|
|
|
TAGGED_TMPL_MAKEFILES = $(wildcard $(addsuffix .mk,$(foreach t,$(TAGGED_TMPL_DIRS),$(addprefix $(t)/,$(TAGGED_TMPL_TAGS)))))
|
|
|
|
# TODO: maybe push this whome MCU-specific stuff somewhere else
|
|
ifneq ($(findstring st-nucleo-f103rb,$(TAGGED_TMPL_TAGS)),)
|
|
TAGGED_TMPL_TAGS += cortex-m3
|
|
MCU_BOARD_MODEL ?= ST-NUCLEO-F103RB
|
|
FINAL_CPPFLAGS += -DST_NUCLEO_F103RB
|
|
MCU_FLASH_OFFSET ?= 0x0000000
|
|
MCU_FLASH_SIZE ?= 0x5000
|
|
MCU_MEM_FETCH_OFFSET ?= 0x08000000
|
|
MCU_MEM_FETCH_SIZE ?= $(MCU_FLASH_SIZE)
|
|
#MCU_OPENOCD_CFG_NAME ?= openocd-$(MCU_BOARD_LC).cfg
|
|
ifneq ($(findstring j-link,$(TAGGED_TMPL_TAGS)),)
|
|
MCU_OPENOCD_CFG_NAME ?= openocd-st-nucleo-f103rb-jlink.cfg
|
|
else
|
|
MCU_OPENOCD_CFG_NAME ?= openocd-st-nucleo-f103rb.cfg
|
|
endif
|
|
MODM_BSPS += modm:nucleo-f103rb
|
|
MCU_FLASH_BANK_NAME ?= internal
|
|
ifneq ($(MCU_FLASH_BANK_NAME),internal)
|
|
$(error Unsupported flash bank name "$(MCU_FLASH_BANK_NAME)")
|
|
endif
|
|
else ifneq ($(findstring st-disc1-f429i,$(TAGGED_TMPL_TAGS)),)
|
|
TAGGED_TMPL_TAGS += cortex-m4
|
|
MCU_BOARD_MODEL ?= ST-DISC1-F429I
|
|
FINAL_CPPFLAGS += -DST_DISC1_F429I
|
|
#MCU_OPENOCD_CFG_NAME ?= openocd-st-stm32f429disc1.cfg
|
|
MCU_OPENOCD_CFG_NAME ?= openocd-st-stm32f429discovery.cfg
|
|
MCU_FLASH_BANK_NAME ?= internal
|
|
ifeq ($(MCU_FLASH_BANK_NAME),internal)
|
|
MCU_FLASH_OFFSET ?= 0x00000000
|
|
MCU_FLASH_SIZE ?= 0x00200000
|
|
MCU_MEM_FETCH_OFFSET ?= 0x08000000
|
|
MCU_MEM_FETCH_SIZE ?= $(MCU_FLASH_SIZE)
|
|
else ifeq ($(MCU_FLASH_BANK_NAME),otp)
|
|
MCU_FLASH_OFFSET ?= 0x00000000
|
|
MCU_FLASH_SIZE ?= 0x00000200
|
|
MCU_MEM_FETCH_OFFSET ?= 0x1fff7800
|
|
MCU_MEM_FETCH_SIZE ?= $(MCU_FLASH_SIZE)
|
|
else
|
|
$(error Unsupported flash bank name "$(MCU_FLASH_BANK_NAME)")
|
|
endif
|
|
ifeq ($(MCU_OPENOCD_CFG_NAME),openocd-st-stm32f429disc1.cfg)
|
|
ifeq ($(MCU_FLASH_BANK_NAME),internal)
|
|
MCU_FLASH_BANK ?= 1
|
|
endif
|
|
else ifeq ($(MCU_OPENOCD_CFG_NAME),openocd-st-stm32f429discovery.cfg)
|
|
ifeq ($(MCU_FLASH_BANK_NAME),internal)
|
|
MCU_FLASH_BANK ?= 1
|
|
endif
|
|
endif
|
|
|
|
# modm:disco-f769ni (SIC), not disco-f769i. mbed does the same, despite the
|
|
# fact that a board of this name doesn't exist.
|
|
MODM_BSPS += modm:disco-f429zi
|
|
else ifneq ($(findstring st-disco-f769i,$(TAGGED_TMPL_TAGS)),)
|
|
TAGGED_TMPL_TAGS += cortex-m7
|
|
MCU_BOARD_MODEL ?= ST-DISCO-F769I
|
|
FINAL_CPPFLAGS += -DST_DISCO_F769I
|
|
ifneq ($(findstring j-link,$(TAGGED_TMPL_TAGS)),)
|
|
MCU_OPENOCD_CFG_NAME ?= openocd-stmqspi-st-stm32f769i-disco-jlink.cfg
|
|
else
|
|
MCU_OPENOCD_CFG_NAME ?= openocd-stmqspi-st-stm32f769i-disco.cfg
|
|
endif
|
|
MCU_FLASH_BANK_NAME ?= external
|
|
ifeq ($(MCU_FLASH_BANK_NAME),external)
|
|
MCU_FLASH_OFFSET ?= 0x00000000
|
|
MCU_FLASH_SIZE ?= 0x04000000
|
|
MCU_MEM_FETCH_OFFSET ?= 0x90000000
|
|
MCU_MEM_FETCH_SIZE ?= $(MCU_FLASH_SIZE)
|
|
else ifeq ($(MCU_FLASH_BANK_NAME),internal)
|
|
MCU_FLASH_OFFSET ?= 0x00000000
|
|
MCU_FLASH_SIZE ?= 0x00200000
|
|
MCU_MEM_FETCH_OFFSET ?= 0x08000000
|
|
MCU_MEM_FETCH_SIZE ?= $(MCU_FLASH_SIZE)
|
|
else
|
|
$(error Unsupported flash bank name "$(MCU_FLASH_BANK_NAME)")
|
|
endif
|
|
ifeq ($(MCU_OPENOCD_CFG_NAME),openocd-stmqspi-st-stm32f769i-disco.cfg)
|
|
ifeq ($(MCU_FLASH_BANK_NAME),external)
|
|
MCU_FLASH_BANK ?= 1
|
|
else ifeq ($(MCU_FLASH_BANK_NAME),internal)
|
|
MCU_FLASH_BANK ?= 0
|
|
endif
|
|
else ifeq ($(MCU_OPENOCD_CFG_NAME),openocd-st-stm32f7discovery.cfg)
|
|
ifeq ($(MCU_FLASH_BANK_NAME),external)
|
|
MCU_FLASH_BANK ?= 2
|
|
endif
|
|
endif
|
|
|
|
# modm:disco-f769ni (SIC), not disco-f769i. mbed does the same, despite the
|
|
# fact that a board of this name doesn't exist.
|
|
MODM_BSPS += modm:disco-f769ni
|
|
else
|
|
MCU_OPENOCD_CFG_NAME ?= openocd-$(MCU_BOARD_LC).cfg
|
|
endif
|
|
|
|
ifneq ($(findstring cortex-m,$(TAGGED_TMPL_TAGS)),)
|
|
TAGGED_TMPL_TAGS += cortex-m
|
|
ifneq ($(findstring cortex-m3,$(TAGGED_TMPL_TAGS)),)
|
|
TARGET_CPU = cortex-m3
|
|
else ifneq ($(findstring cortex-m4,$(TAGGED_TMPL_TAGS)),)
|
|
TARGET_CPU = cortex-m4
|
|
else ifneq ($(findstring cortex-m7,$(TAGGED_TMPL_TAGS)),)
|
|
TARGET_CPU = cortex-m7
|
|
endif
|
|
endif
|
|
|
|
ifneq ($(findstring cortex,$(TAGGED_TMPL_TAGS)),)
|
|
TAGGED_TMPL_TAGS += cortex
|
|
endif
|
|
|
|
# ----- tool chain
|
|
|
|
ifneq ($(TARGET_TRIPLET),$(HOST_TRIPLET)) # we're cross-compiling
|
|
|
|
TC_BIN_PREFIX ?= $(TARGET_TRIPLET)-
|
|
TC_SYS_ROOT ?= /usr/$(TARGET_TRIPLET)
|
|
|
|
ifeq ($(TARGET),mingw)
|
|
|
|
ifneq ($(wildcard $(TC_BIN_PREFIX)gcc),)
|
|
CROSS_TOOL_DIR ?=
|
|
TC_SYS_ROOT ?= /usr/$(TARGET_TRIPLET)/sys-root/mingw
|
|
else
|
|
CROSS_TOOL_DIR ?= /opt/cross-tools
|
|
TC_BIN_PREFIX ?= $(CROSS_TOOL_DIR)/bin/i686-pc-mingw32-
|
|
endif
|
|
|
|
FINAL_CPPFLAGS += -D_WINDOWS
|
|
FINAL_LDFLAGS += -lws2_32
|
|
WINDRES ?= $(TC_BIN_PREFIX)windres
|
|
USE_GFILTER ?= false
|
|
MS_LD ?= wine $(HOME)/local/mingw/packages/msvcpp/bin/LIB.EXE
|
|
endif
|
|
|
|
#FINAL_CPPFLAGS += -I$(TC_SYS_ROOT)/include
|
|
#FINAL_LDFLAGS += -L$(TC_SYS_ROOT)/lib
|
|
|
|
else # we're not cross-compiling
|
|
|
|
TC_SYS_ROOT ?= /usr
|
|
FINAL_LIBFLAGS += -pthread
|
|
|
|
endif
|
|
|
|
ifeq ($(COMPILER_SUITE),gcc)
|
|
|
|
GCC ?= $(CCACHE)$(TC_BIN_PREFIX)gcc
|
|
GXX ?= $(CCACHE)$(TC_BIN_PREFIX)g++
|
|
GNU_LD ?= $(TC_BIN_PREFIX)ld
|
|
CLANG ?= $(CCACHE)$(TC_BIN_PREFIX)clang
|
|
CLANGPP ?= $(CCACHE)$(TC_BIN_PREFIX)clang++
|
|
STRIP ?= $(TC_BIN_PREFIX)strip
|
|
RANLIB ?= $(TC_BIN_PREFIX)ranlib
|
|
AR ?= $(TC_BIN_PREFIX)ar
|
|
PKG_CONFIG_EXE ?= $(TC_BIN_PREFIX)pkg-config
|
|
CPP_FILT ?= $(TC_BIN_PREFIX)c++filt
|
|
OBJCOPY ?= $(TC_BIN_PREFIX)objcopy
|
|
OBJDUMP ?= $(TC_BIN_PREFIX)objdump
|
|
|
|
# compiler and linker
|
|
# gcc
|
|
GCC_VERSION := $(shell $(GCC) -v 2>&1 | $(SED) '/gcc.version/I !d; s/.*version *//I; s/ \+.*//')
|
|
GCC_VERSION_NUMBERS := $(subst ., ,$(GCC_VERSION))
|
|
GCC_MAJOR := $(word 1,$(GCC_VERSION_NUMBERS))
|
|
GCC_MINOR := $(word 2,$(GCC_VERSION_NUMBERS))
|
|
GCC_REV := $(word 3,$(GCC_VERSION_NUMBERS))
|
|
|
|
# Not needed anywhere
|
|
#GNU_LD_VERSION := $(shell $(LD) -V | $(SED) '/GNU ld/ !d; s/(.*)//; s/[^0-9.-]*//')
|
|
#GNU_LD_VERSION_NUMBERS := $(subst ., ,$(GNU_LD_VERSION))
|
|
#GNU_LD_MAJOR := $(word 1,$(GNU_LD_VERSION_NUMBERS))
|
|
#GNU_LD_MINOR := $(word 2,$(GNU_LD_VERSION_NUMBERS))
|
|
#GNU_LD_REV := $(word 3,$(GNU_LD_VERSION_NUMBERS))
|
|
|
|
CC = $(GCC)
|
|
CXX = $(GXX)
|
|
LD = $(GXX)
|
|
|
|
FINAL_CXXFLAGS += -std=c++$(CPP_STANDARD_VERSION)
|
|
FINAL_CFLAGS += -std=gnu$(C_STANDARD_VERSION)
|
|
|
|
ifeq ($(shell $(TEST) $(GCC_MAJOR) -ge 5; $(ECHO) $$?),0)
|
|
ifeq ($(USE_CPP_FORCE_OVERRIDE),true)
|
|
GCC_CXXFLAGS += -Werror=suggest-override
|
|
endif
|
|
endif
|
|
|
|
ifeq ($(GCC_MAJOR),2)
|
|
FINAL_LPPFLAGS += -lm
|
|
FINAL_CPPFLAGS += -I/usr/local/include
|
|
else ifeq ($(GCC_MAJOR),3)
|
|
ifeq ($(GCC_MINOR),3)
|
|
FINAL_LPPFLAGS += -lgcc_s
|
|
# FINAL_LPPFLAGS += -L/usr/local/gcc3.3/lib
|
|
endif
|
|
else
|
|
FINAL_CPPFLAGS += -DGCC_HASCLASSVISIBILITY
|
|
endif
|
|
|
|
else ifeq ($(COMPILER_SUITE),clang)
|
|
|
|
# clang
|
|
CLANG_CXXFLAGS += -Wno-unused-private-field -Wno-self-assign-field -Wno-overloaded-virtual
|
|
CC = $(CLANG)
|
|
CXX = $(CLANGPP)
|
|
LD = $(CLANGPP)
|
|
|
|
ifeq ($(USE_CPP_WARN_INCONSISTENT_OVERRIDE),true)
|
|
CLANG_CXXFLAGS += -Winconsistent-missing-override
|
|
endif
|
|
|
|
endif # COMPILER_SUITE
|
|
|
|
# -- jw-build variables based on arch and toolchain
|
|
|
|
ifeq ($(TARGET_TRIPLET),arm-none-eabi)
|
|
LIBTYPE ?= static
|
|
else
|
|
LIBTYPE ?= shared
|
|
endif
|
|
|
|
INTEL_ARCHS := i386 i486 i586 i686 x86_64
|
|
|
|
ifneq ($(findstring $(TARGET_ARCH),$(INTEL_ARCHS)),)
|
|
TAGGED_TMPL_TAGS += x86
|
|
endif
|
|
|
|
ifeq ($(COMPILER_SUITE),gcc)
|
|
DEBUGGER ?= gdb
|
|
FINAL_EXTRA_DEBUG_FLAGS += -ggdb
|
|
else ifeq ($(COMPILER_SUITE),clang)
|
|
DEBUGGER = lldb
|
|
endif
|
|
|
|
# -- gather compiler options in BUILD_XXXFLAGS
|
|
|
|
FINAL_CFLAGS += $(CFLAGS)
|
|
FINAL_CXXFLAGS += $(CXXFLAGS)
|
|
FINAL_CPPFLAGS += $(CPPFLAGS)
|
|
FINAL_LDFLAGS += $(LDFLAGS)
|
|
|
|
FINAL_CPPFLAGS += -D_FILE_OFFSET_BITS=64 -Wall -Wno-unused-value -Wno-deprecated -DPROJECT_STR=\"$(PROJECT)\"
|
|
FINAL_LDFLAGS += -Wall
|
|
|
|
ifeq ($(TARGET_ARCH),$(ARCH_32))
|
|
FINAL_CPPFLAGS += -m32
|
|
FINAL_LDFLAGS += -m32
|
|
endif
|
|
|
|
ifneq ($(findstring $(TARGET_ARCH),$(INTEL_ARCHS)),)
|
|
FINAL_CPPFLAGS += -fPIC
|
|
ifeq ($(findstring mingw,$(TARGET_ABI)),)
|
|
ifeq ($(LIBTYPE),shared)
|
|
FINAL_LIBFLAGS += -ldl
|
|
else
|
|
FINAL_LIBFLAGS += -l:libdl.a
|
|
endif
|
|
endif
|
|
endif
|
|
|
|
ifeq ($(TARGET_ARCH),armv7hl)
|
|
FINAL_CPPFLAGS += -fPIC
|
|
else ifeq ($(TARGET_ARCH),aarch64)
|
|
FINAL_CPPFLAGS += -fPIC
|
|
endif
|
|
|
|
ifeq ($(DEVELOPMENT),true)
|
|
FINAL_CPPFLAGS += -D_DEVELOPMENT_
|
|
export G_SLICE = always-malloc
|
|
export G_DEBUG = gc-friendly,resident-modules
|
|
export MALLOC_CHECK_ = 2
|
|
endif
|
|
|
|
ifneq ($(LOG_QUAL_PREFIX),)
|
|
FINAL_CPPFLAGS += -DKEEP_FILES_OPEN -DLOG_QUAL_PREFIX=\"$(LOG_QUAL_PREFIX)\"
|
|
endif
|
|
|
|
ifeq ($(CATCH_ONLY_YERROR),true)
|
|
FINAL_CPPFLAGS += -DCATCH_ONLY_YERROR
|
|
endif
|
|
|
|
ifeq ($(USE_VERSION_MACROS),true)
|
|
FINAL_CPPFLAGS += -DVERSION=$(HEX_VERSION) -DVERSION_STR=\"$(VERSION)\"
|
|
endif
|
|
|
|
ifeq ($(TARGET_TRIPLET),arm-none-eabi)
|
|
|
|
ifeq ($(TARGET_CPU),cortex-m3)
|
|
FINAL_CPPFLAGS += -mcpu=cortex-m3 -mthumb
|
|
FINAL_LDFLAGS += -mcpu=cortex-m3 -mthumb
|
|
else ifeq ($(TARGET_CPU),cortex-m4)
|
|
FINAL_CPPFLAGS += -mcpu=cortex-m4 -mthumb
|
|
FINAL_LDFLAGS += -mcpu=cortex-m4 -mthumb
|
|
else ifeq ($(TARGET_CPU),cortex-m7)
|
|
FINAL_CPPFLAGS += -mcpu=cortex-m7 -mthumb
|
|
FINAL_LDFLAGS += -mcpu=cortex-m7 -mthumb
|
|
endif
|
|
|
|
ifneq ($(findstring cortex-m,$(TARGET_CPU)),)
|
|
|
|
# don't wrap error message lines
|
|
#FINAL_LDFLAGS += -fmessage-length=0
|
|
|
|
# don't know what kind of optimization that is
|
|
#FINAL_LDFLAGS += -Og
|
|
|
|
# stick with what janware code tends to expect
|
|
FINAL_LDFLAGS += -fsigned-char
|
|
|
|
# I have no clue which part would evaluate these names
|
|
FINAL_LDFLAGS += -ffunction-sections
|
|
FINAL_LDFLAGS += -fdata-sections
|
|
FINAL_LDFLAGS += -ffreestanding
|
|
FINAL_LDFLAGS += -fno-move-loop-invariants
|
|
|
|
# skip any automatic initialization
|
|
FINAL_LDFLAGS += -nostartfiles
|
|
|
|
# garbage collect unused input sections
|
|
FINAL_LDFLAGS += -Xlinker --gc-sections
|
|
#FINAL_LDFLAGS += -Xlinker --print-gc-sections
|
|
|
|
# create map file
|
|
FINAL_LDFLAGS += -Wl,-Map,"$(EXE_MAP)"
|
|
|
|
# use newlib-nano, provides symbols _write _close _fstat _isatty _lseek (at least)
|
|
# (TODO: No -Wl necessary?)
|
|
FINAL_LDFLAGS += --specs=nano.specs
|
|
FINAL_LDFLAGS += --specs=nosys.specs
|
|
|
|
endif
|
|
|
|
USE_DISABLE_COMPILER_OPTIMISATION_OPTS = false
|
|
USE_EXCEPTIONS_IN_C = false
|
|
ARM_NONE_EABI_ALLFLAGS += -fno-exceptions
|
|
ifeq ($(USE_DISABLE_COMPILER_OPTIMISATION_OPTS),true)
|
|
ARM_NONE_EABI_ALLFLAGS += -Os
|
|
endif
|
|
FINAL_LDFLAGS += $(ARM_NONE_EABI_ALLFLAGS)
|
|
FINAL_CPPFLAGS += $(ARM_NONE_EABI_ALLFLAGS)
|
|
FINAL_CXXFLAGS += -fno-rtti
|
|
|
|
# -- used by modm, but currently disabled for test purposes
|
|
#FINAL_CFLAGS += -fno-threadsafe-statics
|
|
#FINAL_CFLAGS += -fno-unwind-tables
|
|
#FINAL_CFLAGS += -fstrict-enums
|
|
#FINAL_CFLAGS += -fuse-cxa-atexit
|
|
#FINAL_CFLAGS += -fshort-wchar
|
|
#FINAL_CFLAGS += -fsingle-precision-constant
|
|
#FINAL_CFLAGS += -funsigned-bitfields
|
|
#FINAL_CFLAGS += -funsigned-char
|
|
#FINAL_CFLAGS += -fwrapv
|
|
#FINAL_CFLAGS += -g3
|
|
#FINAL_CFLAGS += -gdwarf
|
|
#FINAL_CFLAGS += -W
|
|
#FINAL_CFLAGS += -Wall
|
|
#FINAL_CFLAGS += -Wdouble-promotion
|
|
#FINAL_CFLAGS += -Wduplicated-cond
|
|
#FINAL_CFLAGS += -Werror=format
|
|
#FINAL_CFLAGS += -Werror=maybe-uninitialized
|
|
#FINAL_CFLAGS += -Werror=overflow
|
|
#FINAL_CFLAGS += -Werror=sign-compare
|
|
#FINAL_CFLAGS += -Wextra
|
|
#FINAL_CFLAGS += -Wlogical-op
|
|
#FINAL_CFLAGS += -Wpointer-arith
|
|
#FINAL_CFLAGS += -Wundef
|
|
|
|
|
|
#FINAL_CXXFLAGS += -fdata-sections
|
|
#FINAL_CXXFLAGS += -ffunction-sections
|
|
#FINAL_CXXFLAGS += -finline-limit=10000
|
|
#FINAL_CPPFLAGS += -fshort-wchar
|
|
#FINAL_CPPFLAGS += -fsingle-precision-constant
|
|
#FINAL_CPPFLAGS += -funsigned-bitfields
|
|
#FINAL_CPPFLAGS += -funsigned-char
|
|
#FINAL_CPPFLAGS += -fwrapv
|
|
#FINAL_CPPFLAGS += -g3
|
|
#FINAL_CPPFLAGS += -gdwarf
|
|
#FINAL_CPPFLAGS += -W
|
|
#FINAL_CPPFLAGS += -Wall
|
|
#FINAL_CPPFLAGS += -Wdouble-promotion
|
|
#FINAL_CPPFLAGS += -Wduplicated-cond
|
|
#FINAL_CPPFLAGS += -Werror=format
|
|
#FINAL_CPPFLAGS += -Werror=maybe-uninitialized
|
|
#FINAL_CPPFLAGS += -Werror=overflow
|
|
#FINAL_CPPFLAGS += -Werror=sign-compare
|
|
#FINAL_CPPFLAGS += -Wextra
|
|
#FINAL_CPPFLAGS += -Wlogical-op
|
|
#FINAL_CXXFLAGS += -Wpointer-arith
|
|
#FINAL_CPPFLAGS += -Wundef
|
|
#FINAL_CXXFLAGS += -fno-threadsafe-statics
|
|
#FINAL_CPPFLAGS += -fno-unwind-tables
|
|
#FINAL_CXXFLAGS += -fstrict-enums
|
|
#FINAL_CPPFLAGS += -fuse-cxa-atexit
|
|
#FINAL_CXXFLAGS += -std=c++17
|
|
#FINAL_CXXFLAGS += -Woverloaded-virtual
|
|
#FINAL_CXXFLAGS += -fno-move-loop-invariants
|
|
#FINAL_CPPFLAGS += -fno-split-wide-types
|
|
#FINAL_CPPFLAGS += -fno-tree-loop-optimize
|
|
|
|
#FINAL_CPPFLAGS += -fno-exceptions
|
|
#FINAL_CXXFLAGS += -fno-rtti
|
|
|
|
ifneq ($(findstring gnu-mcu-eclipse,$(TAGGED_TMPL_TAGS)),)
|
|
LD_DEFINE_SYMBOLS += _sbrk
|
|
endif
|
|
|
|
endif
|
|
|
|
FINAL_LDFLAGS += $(addprefix -u ,$(LD_DEFINE_SYMBOLS))
|
|
|
|
# -- target files and dirs
|
|
|
|
SRC_SUFFIX += $(sort $(suffix $(wildcard $(TOPDIR)/hdr/*)))
|
|
LOCAL_SRC += Makefile $(wildcard $(addprefix *,$(SRC_SUFFIX)))
|
|
SRC_HEADERED += $(shell if [ "$(LOCAL_SRC)" ]; then grep -ic "it services" $(LOCAL_SRC) | $(SED) '/:0$$/ d; s/:.*$$//'; fi)
|
|
SRC_UNHEADERED += $(filter-out $(SRC_HEADERED),$(LOCAL_SRC))
|
|
LOCAL_C ?= $(wildcard *.c)
|
|
LOCAL_CPP ?= $(wildcard *.cc *.cpp *.C)
|
|
LOCAL_H ?= $(wildcard *.h *.H *.hpp *.hh)
|
|
SFILES ?= $(wildcard *.S *.sx)
|
|
#PREREQ_H += $(foreach dir,$(PREREQ_DIR),$(wildcard $(dir)/*.h))
|
|
ALL_H += $(LOCAL_H) $(PREREQ_H)
|
|
SRC_ALL_CPP += $(filter-out $(SRC_ALL_CPP_IGNORE),$(LOCAL_C) $(LOCAL_CPP) $(LOCAL_H))
|
|
SRC_C += $(filter %.c, $(SRC_ALL_CPP))
|
|
SRC_CPP += $(filter %.cc %.cpp %.C, $(SRC_ALL_CPP))
|
|
BUILD_OBJ += $(addprefix $(FLAVOUR_PREFIX),$(patsubst %.C,%.o,$(patsubst %.cpp,%.o,$(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(filter %.c %.cpp %.cc %.C, $(SRC_ALL_CPP)))))))
|
|
BUILD_OBJ += $(addprefix $(FLAVOUR_PREFIX),$(patsubst %.sx,%.o,$(patsubst %.S,%.o,$(SFILES))))
|
|
|
|
#PREREQ_C += $(foreach dir,$(PREREQ_DIR),$(wildcard $(dir)/*.c))
|
|
#PREREQ_CPP += $(foreach dir,$(PREREQ_DIR),$(wildcard $(dir)/*.c)) \
|
|
# $(foreach dir,$(PREREQ_DIR),$(wildcard $(dir)/*.cpp))
|
|
#PREREQ_CSRC += $(PREREQ_H) $(PREREQ_C) $(PREREQ_CPP)
|
|
REQUIRED_DIR += $(patsubst %,$(JWBDIR)/%,$(REQUIRED))
|
|
REQUIRED_DONE += $(patsubst %,%/all.done,$(REQUIRED_DIR))
|
|
REQUIRED_H += $(foreach dir,$(REQUIRED_DIR),$(wildcard $(dir)/*.h))
|
|
REQUIRED_C += $(foreach dir,$(REQUIRED_DIR),$(wildcard $(dir)/*.c))
|
|
REQUIRED_CPP += $(foreach dir,$(REQUIRED_DIR),$(wildcard $(dir)/*.cpp)) \
|
|
$(foreach dir,$(PREREQ_DIR),$(wildcard $(dir)/*.cpp))
|
|
REQUIRED_CSRC += $(REQUIRED_H) $(REQUIRED_C) $(REQUIRED_CPP)
|
|
|
|
ALL_C += $(LOCAL_C) $(PREREQ_CPP)
|
|
ALL_CPP += $(LOCAL_CPP) $(PREREQ_CPP)
|
|
ALL_CSRC += $(LOCAL_CSRC) $(PREREQ_CSRC)
|
|
|
|
ifeq ($(USE_QT),true)
|
|
include $(JWBDIR)/make/qtversion.mk
|
|
include $(JWBDIR)/make/qt-defs.mk
|
|
endif
|
|
|
|
ifeq ($(USE_X),true)
|
|
FINAL_LDFLAGS += -L/usr/X11/$(SYSTEM_LIBDIR_NAME) -lXext -lX11
|
|
endif
|
|
|
|
ifneq ($(TARGET_TRIPLET),arm-none-eabi)
|
|
FINAL_LPPFLAGS += -lstdc++
|
|
endif
|
|
|
|
ifeq ($(TARGET),mingw)
|
|
FINAL_CPPFLAGS += -DWIN32
|
|
# see https://stackoverflow.com/questions/4492799
|
|
FINAL_LDFLAGS += -fstack-protector
|
|
endif
|
|
|
|
ifeq ($(LOG_THREAD_NAMES), true)
|
|
FINAL_CPPFLAGS += -DSLOG_THREAD_NAMES
|
|
endif
|
|
|
|
# ----- standard features, switched on with USE_XXX = true
|
|
|
|
#include $(JWBDIR)/make/lib-deps.mk
|
|
|
|
ifeq ($(USE_GFILTER),true)
|
|
GFILT = sh $(firstword $(wildcard $(JWBDIR)/contrib/gfilt/gfilt $(JWBDIR)/bin/gfilt))
|
|
ifneq ($(strip $(GFILT)),sh)
|
|
GXX = $(GFILT)
|
|
endif
|
|
endif
|
|
|
|
ifeq ($(USE_PROJECT_LIB),true)
|
|
PROJECTLIB_LDFLAGS += -L$(TOPDIR)/lib -l$(LIBNAME)
|
|
endif
|
|
|
|
ifneq ($(filter jw-build,$(PREREQ_BUILD)),)
|
|
ifeq ($(TARGET),mingw)
|
|
JW_FINAL_LDFLAGS += -lglib-2.0 -lws2_32 -lstdc++
|
|
endif
|
|
endif
|
|
|
|
ifeq ($(USE_SYSTEMD),true)
|
|
FINAL_CPPFLAGS += -D_USE_SYSTEMD_ $(shell $(PKG_CONFIG_EXE) --cflags libsystemd)
|
|
FINAL_LDFLAGS += $(shell $(PKG_CONFIG_EXE) --libs libsystemd)
|
|
endif
|
|
|
|
ifeq ($(USE_TIMER),true)
|
|
FINAL_CPPFLAGS += -D_USE_TIMER_
|
|
endif
|
|
|
|
ifeq ($(USE_FAST_LOG),false)
|
|
FINAL_CPPFLAGS += -D_USE_FAST_LOG_=0
|
|
endif
|
|
|
|
ifeq ($(USE_YAMD),true)
|
|
CC = yamd-gcc
|
|
endif
|
|
|
|
ifeq ($(USE_MPATROL),true)
|
|
#FINAL_CPPFLAGS += -include /usr/include/mpatrol.h
|
|
FINAL_LDFLAGS += -lmpatrolmt -lbfd -liberty
|
|
endif
|
|
|
|
ifeq ($(USE_VALGRIND),true)
|
|
FINAL_CPPFLAGS += -include /usr/include/valgrind/memcheck.h -D_VALGRIND_
|
|
# FINAL_LDFLAGS +=
|
|
endif
|
|
|
|
ifeq ($(USE_MCHECK),true)
|
|
FINAL_LDFLAGS += -lmcheck
|
|
endif
|
|
|
|
ifeq ($(USE_STACK_PROTECTOR),true)
|
|
FINAL_CPPFLAGS += -fstack-protector-all
|
|
#FINAL_CPPFLAGS += -fstack-protector
|
|
endif
|
|
|
|
ifeq ($(USE_STACK_CHECKER),true)
|
|
ifeq "$(COMPILER_SUITE)" "clang"
|
|
FINAL_CPPFLAGS += -fsanitize=address -fno-omit-frame-pointer
|
|
FINAL_LDFLAGS += -fsanitize=address
|
|
endif
|
|
endif
|
|
|
|
ifeq ($(USE_DBMALLOC),true)
|
|
CONTRIB_LIBS += dbmalloc
|
|
FINAL_CPPFLAGS += -DDBMALLOC -DEXITFUN=_exit -I$(TOPDIR)/contrib/dbmalloc
|
|
FINAL_LDFLAGS += -ldbmalloc
|
|
endif
|
|
|
|
ifeq ($(USE_DMALLOC),true)
|
|
FINAL_CPPFLAGS += -DDMALLOC -DDMALLOC_FUNC_CHECK -DSTORE_SEEN_COUNT
|
|
FINAL_LDFLAGS += -ldmallocthcxx -ldmallocth
|
|
endif
|
|
|
|
ifeq ($(USE_MEMWATCH),true)
|
|
FINAL_CPPFLAGS += -DMEMWATCH -DMW_STDIO
|
|
endif
|
|
|
|
ifeq ($(USE_EFENCE),true)
|
|
FINAL_CPPFLAGS += -DEFENCE
|
|
FINAL_LDFLAGS += -lefence
|
|
endif
|
|
|
|
ifeq ($(USE_TRACING),true)
|
|
FINAL_CPPFLAGS += -D_DO_TRACE_
|
|
endif
|
|
|
|
ifeq ($(USE_ASSERTIONS),false)
|
|
FINAL_CPPFLAGS += -DNDEBUG
|
|
endif
|
|
|
|
ifeq ($(COMPILE_DEBUG_CODE),true)
|
|
FINAL_CPPFLAGS += -D_DEBUG_
|
|
endif
|
|
|
|
ifeq ($(COMPILE_DEBUG_LOG),true)
|
|
FINAL_CPPFLAGS += -D_LOG_DEBUG_
|
|
endif
|
|
|
|
ifeq ($(USE_MPATROL),true)
|
|
FINAL_CPPFLAGS += -include $(JWBDIR)/include/mpatrol.h
|
|
FINAL_LDFLAGS += -lmpatrolmt -lbfd -liberty
|
|
endif
|
|
|
|
ifeq ($(BREAK_ABI),true)
|
|
FINAL_CPPFLAGS += -D_BREAK_ABI_
|
|
endif
|
|
|
|
ifeq ($(USE_STACK_CHECK),true)
|
|
FINAL_CPPFLAGS += -fstack-check
|
|
endif
|
|
|
|
ifeq ($(USE_COMPILER_DEBUG_OPTS),true)
|
|
#FINAL_EXTRA_DEBUG_FLAGS += -gdwarf-2
|
|
FINAL_CPPFLAGS += -g3 $(FINAL_EXTRA_DEBUG_FLAGS)
|
|
FINAL_LDFLAGS += -g3 $(FINAL_EXTRA_DEBUG_FLAGS)
|
|
ifneq ($(USE_COMPILER_OPTIMIZATION_OPTS),true)
|
|
FINAL_CPPFLAGS += -Og
|
|
FINAL_LDFLAGS += -Og
|
|
endif
|
|
endif
|
|
|
|
ifeq ($(CC),$(GCC))
|
|
GCC_NO_OPT_FLAGS = \
|
|
-fno-inline-functions-called-once \
|
|
-fno-tree-loop-optimize \
|
|
-fno-early-inlining \
|
|
-fno-default-inline
|
|
else ifeq ($(CC),$(CLANG))
|
|
FINAL_CPPFLAGS += -Werror
|
|
endif
|
|
|
|
ifeq ($(USE_COMPILER_OPTIMIZATION_OPTS),true)
|
|
FINAL_CPPFLAGS += -funroll-loops -O3
|
|
else ifeq ($(USE_DISABLE_COMPILER_OPTIMISATION_OPTS),true)
|
|
NO_OPT_FLAGS = \
|
|
-O0 -g -fno-inline -fno-omit-frame-pointer \
|
|
-fno-optimize-sibling-calls \
|
|
$(GCC_NO_OPT_FLAGS)
|
|
# -fconserve-stack
|
|
|
|
# breaks constexpr
|
|
#NO_OPT_FLAGS += -fno-builtin
|
|
|
|
_NO_OPT_FLAGS = \
|
|
-O0 \
|
|
-fno-implicit-inline-templates \
|
|
-fno-implement-inlines \
|
|
-fno-default-inline \
|
|
-fno-inline \
|
|
-finline-limit=0 \
|
|
-fkeep-inline-functions \
|
|
-fno-inline-functions \
|
|
$(GCC_NO_OPT_FLAGS)
|
|
|
|
FINAL_CPPFLAGS += $(NO_OPT_FLAGS)
|
|
FINAL_LDFLAGS += $(NO_OPT_FLAGS)
|
|
endif
|
|
|
|
ifeq ($(USE_EXCEPTIONS_IN_C),true)
|
|
FINAL_CFLAGS += -fexceptions
|
|
ifeq ($(LIBTYPE),shared)
|
|
GCC_LDFLAGS += -shared-libgcc
|
|
endif
|
|
endif
|
|
|
|
ifeq ($(STRIP_SYMBOLS),true)
|
|
STRIP_DONE ?= strip.done
|
|
endif
|
|
|
|
FINAL_INCLUDE += $(LOCAL_INCLUDE)
|
|
|
|
# force use of double quotes, allow header namespaces
|
|
ifeq ($(HDRDIR_SCOPE_SUFFIX),)
|
|
FINAL_INCLUDE += -I.
|
|
else
|
|
FINAL_INCLUDE += -iquote .
|
|
endif
|
|
|
|
ifeq ($(USE_PROJECT_LIB),true)
|
|
FINAL_INCLUDE += $(PROJECT_INCLUDE) -I$(TOPDIR)/include
|
|
FINAL_LIBFLAGS += -L$(BUILD_LIBDIR)
|
|
endif
|
|
|
|
FINAL_INCLUDE += $(call proj_query, cflags $(PREREQ_BUILD) $(PROJECT))
|
|
|
|
LDFLAGS_QUERY_ARGS = $(addprefix --exclude ,$(LDFLAGS_EXCLUDE))
|
|
FINAL_LIBFLAGS += $(call proj_query, ldflags $(LDFLAGS_QUERY_ARGS) --add-self $(PREREQ_BUILD))
|
|
|
|
# the following is necessary, because not all projects have build.libname = none in project.conf
|
|
ifeq ($(USE_PROJECT_LIB),true)
|
|
LDFLAGS_QUERY_ARGS_SELF = --add-self
|
|
endif
|
|
FINAL_LIBFLAGS += $(call proj_query, ldflags $(LDFLAGS_QUERY_ARGS) $(LDFLAGS_QUERY_ARGS_SELF) $(PROJECT))
|
|
|
|
ifeq ($(USE_SNDFILE),true)
|
|
FINAL_LIBFLAGS += -lsndfile
|
|
endif
|
|
|
|
ifeq ($(USE_FFTW),true)
|
|
FINAL_LIBFLAGS += -lfftw3
|
|
endif
|
|
|
|
ifeq ($(USE_GLIB),true)
|
|
FINAL_CPPFLAGS += $(shell $(PKG_CONFIG_EXE) --cflags glib-2.0)
|
|
FINAL_LIBFLAGS += $(shell $(PKG_CONFIG_EXE) --libs glib-2.0)
|
|
endif
|
|
|
|
ifeq ($(CC),$(CLANG))
|
|
COMPILER_CFLAGS += $(CLANG_CFLAGS)
|
|
COMPILER_CPPFLAGS += $(CLANG_CPPFLAGS)
|
|
COMPILER_CXXFLAGS += $(CLANG_CXXFLAGS)
|
|
COMPILER_LDFLAGS += $(CLANG_LDFLAGS)
|
|
endif
|
|
|
|
ifeq ($(CC),$(GCC))
|
|
COMPILER_CFLAGS += $(GCC_CFLAGS)
|
|
COMPILER_CPPFLAGS += $(GCC_CPPFLAGS)
|
|
COMPILER_CXXFLAGS += $(GCC_CXXFLAGS)
|
|
COMPILER_LDFLAGS += $(GCC_LDFLAGS)
|
|
endif
|
|
|
|
FINAL_CFLAGS += $(LOCAL_CFLAGS) $(PROJECT_CFLAGS) $(COMPLILER_CFLAGS) $(FINAL_INCLUDE)
|
|
FINAL_CPPFLAGS += $(LOCAL_CPPFLAGS) $(PROJECT_INCLUDE) $(PROJECT_CPPFLAGS) $(COMPILER_CPPFLAGS) $(FINAL_INCLUDE)
|
|
FINAL_CXXFLAGS += $(LOCAL_CXXFLAGS) $(PROJECT_CXXFLAGS) $(COMPILER_CXXFLAGS) $(FINAL_INCLUDE)
|
|
FINAL_LDFLAGS += $(LOCAL_LDFLAGS) $(PROJECTLIB_LDFLAGS) $(PROJECT_LDFLAGS) $(COMPILER_LDFLAGS) $(FINAL_LPPFLAGS) $(FINAL_LIBFLAGS)
|
|
|
|
#RPM_REQUIRES = $(shell $(ECHO) "$(RPM_REQUIRES_RUN) $(RPM_REQUIRES_DEVEL)" | $(add_flavour_prefix))
|
|
RPM_REQUIRES += $(RPM_REQUIRES_RUN) $(RPM_REQUIRES_DEVEL)
|
|
|
|
REAL_CFLAGS ?= $(FINAL_CFLAGS)
|
|
REAL_CPPFLAGS ?= $(FINAL_CPPFLAGS)
|
|
REAL_CXXFLAGS ?= $(FINAL_CXXFLAGS)
|
|
REAL_LDFLAGS ?= $(FINAL_LDFLAGS)
|
|
|
|
# -- LIB
|
|
INSTALLATION_FILE_TYPES += LIB
|
|
#BUILD_PIDIR = $(BUILD_LIBDIR)
|
|
#BUILD_PI = $(addprefix $(BUILD_PIDIR)/,$(PLUGIN))
|
|
#INSTALL_PIDIR = $(INSTALL_LIBDIR)
|
|
#INSTALLED_PI = $(addprefix $(INSTALL_PIDIR)/,$(PLUGIN))
|
|
|
|
BUILD_LIBDIR ?= $(TOPDIR)/lib
|
|
|
|
LOCAL_LIBS += $(CONTRIB_LIBS) $(PLUGIN)
|
|
ifeq ($(TARGET),mingw)
|
|
ifeq ($(TC_SYS_ROOT),)
|
|
CONTRIB_LIBS_PATH += $(CROSS_TOOL_DIR)/bin
|
|
else
|
|
CONTRIB_LIBS_PATH += $(TC_SYS_ROOT)/lib
|
|
endif
|
|
endif
|
|
|
|
INSTALL_LIBDIR ?= $(EXE_PREFIX)/lib
|
|
|
|
ifeq ($(LIBTYPE),shared)
|
|
ifneq ($(TARGET),mingw)
|
|
FINAL_LDFLAGS += -rdynamic
|
|
endif
|
|
else
|
|
LIB_SO ?=
|
|
FINAL_LDFLAGS += -static
|
|
endif
|
|
|
|
ifeq ($(USE_PROJECT_LIB),true)
|
|
LIBNAME ?= $(PROJECT)
|
|
MEMBERS += $(LIB_A)($(BUILD_OBJ))
|
|
VERSION_SCRIPT = $(BUILD_LIBDIR)/version.ldscript
|
|
# TODO: use something like this as unifying variable, there are far too many
|
|
# lib-related variables
|
|
LOCAL_LIBS +=
|
|
ifneq ($(TARGET),mingw)
|
|
LIB_A ?= $(BUILD_LIBDIR)/lib$(LIBNAME).a
|
|
SO_SUFFIX ?= so.$(MAJOR_MINOR_RELEASE)
|
|
SO_PREFIX ?= lib
|
|
LIB_SO ?= $(BUILD_LIBDIR)/lib$(LIBNAME).$(SO_SUFFIX)
|
|
LINKS_SO += $(filter-out $(LIB_SO),$(shell $(ECHO) $(LIB_SO) | $(SED) -e "s/\.so\..*$$/.so/"))
|
|
INSTALLED_LINKS_SO += $(filter-out $(INSTALLED_LIB_SO),$(shell $(ECHO) $(INSTALLED_LIB_SO) | $(SED) -e "s/\.so\..*$$/.so/"))
|
|
INSTALLED_LIB_A = $(INSTALL_LIBDIR)/lib$(LIBNAME).a
|
|
else
|
|
LIB_A = $(BUILD_LIBDIR)/lib$(LIBNAME)-static.a
|
|
#WINRES_RC_TMPL = $(JWBDIR)/make/winres-minimal.rc.tmpl
|
|
WINRES_RC_TMPL = $(JWBDIR)/make/winres.rc.tmpl
|
|
WINRES_RC = $(BUILD_LIBDIR)/$(PROJECT).rc
|
|
WINRES_O = $(WINRES_RC).o
|
|
SO_SUFFIX ?= dll
|
|
SO_PREFIX ?=
|
|
LIB_DEF = $(BUILD_LIBDIR)/$(LIBNAME).def
|
|
MSVCPP_IMPLIB = $(BUILD_LIBDIR)/$(LIBNAME).lib
|
|
LIB_SO ?= $(BUILD_LIBDIR)/$(LIBNAME).dll
|
|
INSTALLED_LIB_A = $(INSTALL_LIBDIR)/lib$(LIBNAME).a
|
|
endif # mingw
|
|
BUILD_LIB += $(LIB_SO)
|
|
endif # USE_PROJECT_LIB
|
|
|
|
INSTALLED_LIB_SO = $(addprefix $(INSTALL_LIBDIR)/,$(notdir $(LIB_SO)))
|
|
INSTALLED_DEF = $(addprefix $(INSTALL_LIBDIR)/,$(wildcard *.lib *.exp))
|
|
INSTALLED_LIB += $(addprefix $(INSTALL_LIBDIR)/,$(LOCAL_LIBS))
|
|
BUILD_LIB += $(addprefix $(BUILD_LIBDIR)/,$(LOCAL_LIBS))
|
|
INSTALLED_ALL_LIBS = $(addprefix $(INSTALL_LIBDIR)/,$(wildcard *.a))
|
|
INSTALLED_LIB += $(INSTALLED_LIB_SO) $(INSTALLED_SHOBJS) \
|
|
$(INSTALLED_LINKS_SO) $(sort $(INSTALLED_LIB_A) $(INSTALLED_ALL_LIBS)) \
|
|
$(INSTALLED_DEF)
|
|
|
|
endif # ifeq ($(filter clean distclean,$(MAKECMDGOALS)),)
|
|
endif # ifndef JW_BUILD_CPP_DEFS_MK_INCLUDED
|