Add C++ support to Makefile, and proof-of-concept simple.cpp example
This is a work in progress based on @mikejac's work. Missing: * No 'new' operator. * I don't think STL is currently supported.
This commit is contained in:
parent
372827ac42
commit
cc97067fa1
5 changed files with 92 additions and 3 deletions
14
common.mk
14
common.mk
|
|
@ -220,13 +220,15 @@ $(1)_DEFAULT_ROOT := $(dir $(lastword $(MAKEFILE_LIST)))
|
|||
$(1)_ROOT ?= $$($(1)_DEFAULT_ROOT)
|
||||
$(1)_OBJ_DIR = $(call lc,$(BUILD_DIR)$(1)/)
|
||||
### determine source files and object files ###
|
||||
$(1)_SRC_FILES ?= $$(foreach sdir,$$($(1)_SRC_DIR), \
|
||||
$$(wildcard $$(sdir)/*.c) $$(wildcard $$(sdir)/*.S)) \
|
||||
$(1)_SRC_FILES ?= $$(foreach sdir,$$($(1)_SRC_DIR), \
|
||||
$$(wildcard $$(sdir)/*.c) $$(wildcard $$(sdir)/*.S) \
|
||||
$$(wildcard $$(sdir)/*.cpp)) \
|
||||
$$($(1)_EXTRA_SRC_FILES)
|
||||
$(1)_REAL_SRC_FILES = $$(foreach sfile,$$($(1)_SRC_FILES),$$(realpath $$(sfile)))
|
||||
$(1)_REAL_ROOT = $$(realpath $$($(1)_ROOT))
|
||||
# patsubst here substitutes real component root path for the relative OBJ_DIR path, making things short again
|
||||
$(1)_OBJ_FILES_C = $$(patsubst $$($(1)_REAL_ROOT)%.c,$$($(1)_OBJ_DIR)%.o,$$($(1)_REAL_SRC_FILES))
|
||||
$(1)_OBJ_FILES_CXX = $$(patsubst $$($(1)_REAL_ROOT)%.cpp,$$($(1)_OBJ_DIR)%.o,$$($(1)_REAL_SRC_FILES))
|
||||
$(1)_OBJ_FILES_C = $$(patsubst $$($(1)_REAL_ROOT)%.c,$$($(1)_OBJ_DIR)%.o,$$($(1)_OBJ_FILES_CXX))
|
||||
$(1)_OBJ_FILES = $$(patsubst $$($(1)_REAL_ROOT)%.S,$$($(1)_OBJ_DIR)%.o,$$($(1)_OBJ_FILES_C))
|
||||
# the last included makefile is our component's component.mk makefile (rebuild the component if it changes)
|
||||
$(1)_MAKEFILE ?= $(lastword $(MAKEFILE_LIST))
|
||||
|
|
@ -244,6 +246,12 @@ $$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.c $$($(1)_MAKEFILE) $(wildcard $(ROOT)*
|
|||
$$($(1)_CC_ARGS) -c $$< -o $$@
|
||||
$$($(1)_CC_ARGS) -MM -MT $$@ -MF $$(@:.o=.d) $$<
|
||||
|
||||
$$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.cpp $$($(1)_MAKEFILE) $(wildcard $(ROOT)*.mk) | $$($(1)_SRC_DIR)
|
||||
$(vecho) "C++ $$<"
|
||||
$(Q) mkdir -p $$(dir $$@)
|
||||
$$($(1)_CXX_ARGS) -c $$< -o $$@
|
||||
$$($(1)_CXX_ARGS) -MM -MT $$@ -MF $$(@:.o=.d) $$<
|
||||
|
||||
$$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.S $$($(1)_MAKEFILE) $(wildcard $(ROOT)*.mk) | $$($(1)_SRC_DIR)
|
||||
$(vecho) "AS $$<"
|
||||
$(Q) mkdir -p $$(dir $$@)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue