build: Add C++ support

Adds C++ support to the build system.

Change-Id: Ice1e57a13598e7a48b0bf3298fc318f4ce012ee6
Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com>
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
This commit is contained in:
Peter Mitsis 2016-01-13 13:02:56 -05:00 committed by Anas Nashif
commit 8e35cc8eb4
22 changed files with 448 additions and 3 deletions

View file

@ -300,8 +300,10 @@ AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld LD = $(CROSS_COMPILE)ld
ifeq ($(USE_CCACHE),1) ifeq ($(USE_CCACHE),1)
CC = $(CCACHE) $(CROSS_COMPILE)gcc CC = $(CCACHE) $(CROSS_COMPILE)gcc
CXX = $(CCACHE) $(CROSS_COMPILE)g++
else else
CC = $(CROSS_COMPILE)gcc CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
endif endif
CPP = $(CC) -E CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar AR = $(CROSS_COMPILE)ar
@ -366,6 +368,18 @@ KBUILD_CFLAGS := -c -g -std=c99 \
-Wno-format-zero-length \ -Wno-format-zero-length \
-Wno-main -ffreestanding -Wno-main -ffreestanding
KBUILD_CXXFLAGS := -c -g -std=c++11 \
-fno-reorder-functions \
-fno-asynchronous-unwind-tables \
-fno-omit-frame-pointer \
-fcheck-new \
-fno-defer-pop -Wall \
-Wno-unused-but-set-variable \
-Wno-format-zero-length \
-Wno-main -ffreestanding \
-ffunction-sections -fdata-sections \
-fno-rtti -fno-exceptions
KBUILD_AFLAGS := -c -g -xassembler-with-cpp KBUILD_AFLAGS := -c -g -xassembler-with-cpp
LDFLAGS += $(call ld-option,-nostartfiles) LDFLAGS += $(call ld-option,-nostartfiles)
@ -377,13 +391,13 @@ KERNELVERSION = $(VERSION_MAJOR)$(if $(VERSION_MINOR),.$(VERSION_MINOR)$(if $(PA
export VERSION_MAJOR VERSION_MINOR PATCHLEVEL VERSION_RESERVED EXTRAVERSION export VERSION_MAJOR VERSION_MINOR PATCHLEVEL VERSION_RESERVED EXTRAVERSION
export KERNELRELEASE KERNELVERSION export KERNELRELEASE KERNELVERSION
export ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC export ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC CXX
export CPP AR NM STRIP OBJCOPY OBJDUMP export CPP AR NM STRIP OBJCOPY OBJDUMP
export MAKE AWK INSTALLKERNEL PERL PYTHON GENIDT GENOFFSET_H export MAKE AWK INSTALLKERNEL PERL PYTHON GENIDT GENOFFSET_H
export HOSTCXX HOSTCXXFLAGS CHECK CHECKFLAGS export HOSTCXX HOSTCXXFLAGS CHECK CHECKFLAGS
export KBUILD_CPPFLAGS NOSTDINC_FLAGS ZEPHYRINCLUDE OBJCOPYFLAGS LDFLAGS export KBUILD_CPPFLAGS NOSTDINC_FLAGS ZEPHYRINCLUDE OBJCOPYFLAGS LDFLAGS
export KBUILD_CFLAGS CFLAGS_GCOV KBUILD_AFLAGS AFLAGS_KERNEL export KBUILD_CFLAGS KBUILD_CXXFLAGS CFLAGS_GCOV KBUILD_AFLAGS AFLAGS_KERNEL
export KBUILD_ARFLAGS export KBUILD_ARFLAGS
@ -599,6 +613,7 @@ export LDFLAG_LINKERCMD
include arch/$(ARCH)/Makefile include arch/$(ARCH)/Makefile
KBUILD_CFLAGS += $(CFLAGS) KBUILD_CFLAGS += $(CFLAGS)
KBUILD_CXXFLAGS += $(CXXFLAGS)
KBUILD_AFLAGS += $(CFLAGS) KBUILD_AFLAGS += $(CFLAGS)
@ -1103,6 +1118,10 @@ qemu: zephyr
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.o: %.c prepare scripts FORCE %.o: %.c prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.o: %.cpp prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.o: %.cxx prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.lst: %.c prepare scripts FORCE %.lst: %.c prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.s: %.S prepare scripts FORCE %.s: %.S prepare scripts FORCE

View file

@ -4,4 +4,5 @@ arch-$(CONFIG_CPU_ARCEM4) = $(call cc-option,-mARCv2EM) \
$(call cc-option,-mav2em,) $(call cc-option,-mno-sdata) $(call cc-option,-mav2em,) $(call cc-option,-mno-sdata)
KBUILD_CFLAGS += $(arch-y) $(cflags-y) KBUILD_CFLAGS += $(arch-y) $(cflags-y)
KBUILD_CXXFLAGS += $(arch-y) $(cflags-y)
KBUILD_AFLAGS += $(arch-y) KBUILD_AFLAGS += $(arch-y)

View file

@ -8,6 +8,7 @@ arch-$(CONFIG_CPU_CORTEX_M4) += $(call cc-option,-mthumb -mcpu=cortex-m4) \
cflags-$(CONFIG_LTO) = $(call cc-option,-flto,) cflags-$(CONFIG_LTO) = $(call cc-option,-flto,)
KBUILD_CFLAGS += $(cflags-y) $(arch-y) KBUILD_CFLAGS += $(cflags-y) $(arch-y)
KBUILD_CXXFLAGS += $(cflags-y) $(arch-y)
KBUILD_AFLAGS += $(arch-y) KBUILD_AFLAGS += $(arch-y)
QEMU_CPU_TYPE_arm = cortex-m3 QEMU_CPU_TYPE_arm = cortex-m3

View file

@ -10,6 +10,7 @@ obj-y = atomic.o exc_exit.o irq_init.o \
fault_s.o gdb_stub.o isr_wrapper.o \ fault_s.o gdb_stub.o isr_wrapper.o \
fatal.o sys_fatal_error_handler.o fatal.o sys_fatal_error_handler.o
obj-$(CONFIG_CPLUSPLUS) += __aeabi_atexit.o
obj-$(CONFIG_MICROKERNEL) += task_abort.o obj-$(CONFIG_MICROKERNEL) += task_abort.o
obj-$(CONFIG_IRQ_OFFLOAD) += irq_offload.o obj-$(CONFIG_IRQ_OFFLOAD) += irq_offload.o
obj-$(CONFIG_CPU_CORTEX_M) += cortex_m/ obj-$(CONFIG_CPU_CORTEX_M) += cortex_m/

View file

@ -0,0 +1,38 @@
/*
* Copyright (c) 2016 Wind River Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @file
* @brief Basic C++ destructor module for globals for ARM
*/
#include <toolchain.h>
EXTERN_C int __cxa_atexit(void (*destructor)(void *), void *objptr, void *dso);
/**
* @brief Register destructor for a global object
*
* @param objptr global object pointer
* @param destructor the global object destructor function
* @param dso Dynamic Shared Object handle for shared libraries
*
* Wrapper for __cxa_atexit()
*/
int __aeabi_atexit(void *objptr, void (*destructor)(void *), void *dso)
{
return __cxa_atexit(destructor, objptr, dso);
}

View file

@ -25,6 +25,7 @@ arch-$(CONFIG_CPU_ATOM) += $(call cc-option,-march=atom) \
arch-$(CONFIG_CPU_MINUTEIA) += $(call cc-option,-march=pentium) arch-$(CONFIG_CPU_MINUTEIA) += $(call cc-option,-march=pentium)
KBUILD_CFLAGS += $(cflags-y) $(arch-y) KBUILD_CFLAGS += $(cflags-y) $(arch-y)
KBUILD_CXXFLAGS += $(cflags-y) $(arch-y)
KBUILD_AFLAGS += $(arch-y) KBUILD_AFLAGS += $(arch-y)
QEMU_BIOS ?= /usr/share/qemu QEMU_BIOS ?= /usr/share/qemu

View file

@ -86,6 +86,7 @@ SECTIONS {
*(.text) *(.text)
*(".text.*") *(".text.*")
*(.gnu.linkonce.t.*)
_image_text_end = .; _image_text_end = .;
} GROUP_LINK_IN(ROMABLE_REGION) } GROUP_LINK_IN(ROMABLE_REGION)
@ -98,6 +99,7 @@ SECTIONS {
__devconfig_end = .; __devconfig_end = .;
} GROUP_LINK_IN(ROMABLE_REGION) } GROUP_LINK_IN(ROMABLE_REGION)
#ifdef CONFIG_CPLUSPLUS
SECTION_PROLOGUE(_CTOR_SECTION_NAME,,) { SECTION_PROLOGUE(_CTOR_SECTION_NAME,,) {
/* /*
* The compiler fills the constructor pointers table below, hence * The compiler fills the constructor pointers table below, hence
@ -114,9 +116,19 @@ SECTIONS {
__CTOR_END__ = .; __CTOR_END__ = .;
} GROUP_LINK_IN(ROMABLE_REGION) } GROUP_LINK_IN(ROMABLE_REGION)
SECTION_PROLOGUE(init_array, (OPTIONAL),)
{
. = ALIGN(4);
__init_array_start = .;
KEEP(*(SORT_BY_NAME(".init_array*")))
__init_array_end = .;
} GROUP_LINK_IN(ROMABLE_REGION)
#endif
SECTION_PROLOGUE(_RODATA_SECTION_NAME,,) { SECTION_PROLOGUE(_RODATA_SECTION_NAME,,) {
*(.rodata) *(.rodata)
*(".rodata.*") *(".rodata.*")
*(.gnu.linkonce.r.*)
} GROUP_LINK_IN(ROMABLE_REGION) } GROUP_LINK_IN(ROMABLE_REGION)
_image_rom_end = .; _image_rom_end = .;

View file

@ -101,6 +101,7 @@ SECTIONS
_image_text_start = .; _image_text_start = .;
*(.text) *(.text)
*(".text.*") *(".text.*")
*(.gnu.linkonce.t.*)
} GROUP_LINK_IN(ROMABLE_REGION) } GROUP_LINK_IN(ROMABLE_REGION)
_image_text_end = .; _image_text_end = .;
@ -128,10 +129,38 @@ SECTIONS
__exidx_end = .; __exidx_end = .;
} GROUP_LINK_IN(ROMABLE_REGION) } GROUP_LINK_IN(ROMABLE_REGION)
#ifdef CONFIG_CPLUSPLUS
SECTION_PROLOGUE(_CTOR_SECTION_NAME,,)
{
/*
* The compiler fills the constructor pointers table below, hence symbol
* __CTOR_LIST__ must be aligned on 4 byte boundary.
* To align with the C++ standard, the first elment of the array
* contains the number of actual constructors. The last element is
* NULL.
*/
. = ALIGN(4);
__CTOR_LIST__ = .;
LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
KEEP(*(SORT_BY_NAME(".ctors*")))
LONG(0)
__CTOR_END__ = .;
} GROUP_LINK_IN(ROMABLE_REGION)
SECTION_PROLOGUE(init_array, (OPTIONAL),)
{
. = ALIGN(4);
__init_array_start = .;
KEEP(*(SORT_BY_NAME(".init_array*")))
__init_array_end = .;
} GROUP_LINK_IN(ROMABLE_REGION)
#endif
SECTION_PROLOGUE(_RODATA_SECTION_NAME,,) SECTION_PROLOGUE(_RODATA_SECTION_NAME,,)
{ {
*(.rodata) *(.rodata)
*(".rodata.*") *(".rodata.*")
*(.gnu.linkonce.r.*)
} GROUP_LINK_IN(ROMABLE_REGION) } GROUP_LINK_IN(ROMABLE_REGION)
_image_rom_end = .; _image_rom_end = .;

View file

@ -74,6 +74,7 @@ SECTIONS
*(".text_start.*") *(".text_start.*")
*(.text) *(.text)
*(".text.*") *(".text.*")
*(.gnu.linkonce.t.*)
*(.eh_frame) *(.eh_frame)
*(.init) *(.init)
*(.fini) *(.fini)
@ -83,6 +84,33 @@ SECTIONS
_image_text_end = .; _image_text_end = .;
#ifdef CONFIG_CPLUSPLUS
SECTION_PROLOGUE(_CTOR_SECTION_NAME, ,)
{
/*
* The compiler fills the constructor pointers table below, hence symbol
* __CTOR_LIST__ must be aligned on 4 byte boundary.
* To align with the C++ standard, the first elment of the array
* contains the number of actual constructors. The last element is
* NULL.
*/
. = ALIGN(4);
__CTOR_LIST__ = .;
LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
KEEP(*(SORT_BY_NAME(".ctors*")))
LONG(0)
__CTOR_END__ = .;
} GROUP_LINK_IN(ROMABLE_REGION)
SECTION_PROLOGUE(init_array, (OPTIONAL),)
{
. = ALIGN(4);
__init_array_start = .;
KEEP(*(SORT_BY_NAME(".init_array*")))
__init_array_end = .;
} GROUP_LINK_IN(ROMABLE_REGION)
#endif
SECTION_PROLOGUE(devconfig, (OPTIONAL),) SECTION_PROLOGUE(devconfig, (OPTIONAL),)
{ {
__devconfig_start = .; __devconfig_start = .;
@ -95,6 +123,7 @@ SECTIONS
{ {
*(.rodata) *(.rodata)
*(".rodata.*") *(".rodata.*")
*(.gnu.linkonce.r.*)
#if ALL_DYN_STUBS == 0 #if ALL_DYN_STUBS == 0
IDT_MEMORY IDT_MEMORY
#endif #endif

View file

@ -1363,6 +1363,35 @@ struct nano_timer *_track_list_nano_timer;
} }
#endif #endif
#if defined(CONFIG_CPLUSPLUS) && defined(__cplusplus)
/*
* Define new and delete operators.
* At this moment they do nothing since objects are supposed
* to be statically allocated
*/
inline void operator delete(void *ptr)
{
(void)ptr;
}
inline void operator delete[](void *ptr)
{
(void)ptr;
}
inline void *operator new(size_t size)
{
(void)size;
return NULL;
}
inline void *operator new[](size_t size)
{
(void)size;
return NULL;
}
#endif
/* architecture-specific nanokernel public APIs */ /* architecture-specific nanokernel public APIs */
#include <arch/cpu.h> #include <arch/cpu.h>

View file

@ -96,6 +96,14 @@ void _main(void)
_sys_device_do_config_level(_SYS_INIT_LEVEL_MICROKERNEL); _sys_device_do_config_level(_SYS_INIT_LEVEL_MICROKERNEL);
_sys_device_do_config_level(_SYS_INIT_LEVEL_APPLICATION); _sys_device_do_config_level(_SYS_INIT_LEVEL_APPLICATION);
#ifdef CONFIG_CPLUSPLUS
/* Process the .ctors and .init_array sections */
extern void __do_global_ctors_aux(void);
extern void __do_init_array_aux(void);
__do_global_ctors_aux();
__do_init_array_aux();
#endif
#ifdef CONFIG_WORKLOAD_MONITOR #ifdef CONFIG_WORKLOAD_MONITOR
_k_workload_monitor_calibrate(); _k_workload_monitor_calibrate();

View file

@ -105,6 +105,14 @@ static void _main(void)
_sys_device_do_config_level(_SYS_INIT_LEVEL_NANOKERNEL); _sys_device_do_config_level(_SYS_INIT_LEVEL_NANOKERNEL);
_sys_device_do_config_level(_SYS_INIT_LEVEL_APPLICATION); _sys_device_do_config_level(_SYS_INIT_LEVEL_APPLICATION);
#ifdef CONFIG_CPLUSPLUS
/* Process the .ctors and .init_array sections */
extern void __do_global_ctors_aux(void);
extern void __do_init_array_aux(void);
__do_global_ctors_aux();
__do_init_array_aux();
#endif
extern void main(void); extern void main(void);
main(); main();
} }

View file

@ -93,6 +93,12 @@ config TOOLCHAIN_VARIANT
For optimized compilers with reduced features, specify the name For optimized compilers with reduced features, specify the name
of the variant. of the variant.
config CPLUSPLUS
bool "Enable C++ support for the application"
default n
help
This option enables the use of applications built with C++.
choice choice
prompt "C Library" prompt "C Library"
default MINIMAL_LIBC default MINIMAL_LIBC

View file

@ -1,4 +1,6 @@
obj-y = obj-y =
obj-$(CONFIG_CPLUSPLUS) += cpp_virtual.o cpp_vtable.o \
cpp_init_array.o cpp_ctors.o cpp_dtors.o
obj-$(CONFIG_PRINTK) += printk.o obj-$(CONFIG_PRINTK) += printk.o
obj-$(CONFIG_REBOOT) += reboot.o obj-$(CONFIG_REBOOT) += reboot.o
obj-y += generated/ obj-y += generated/

53
misc/cpp_ctors.c Normal file
View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file - Constructor module
* @brief
* The ctors section contains a list of function pointers that execute the
* C++ constructors of static global objects. These must be executed before
* the application's main() routine.
*
* NOTE: Not all compilers put those function pointers into the ctors section;
* some put them into the init_array section instead.
*/
/* What a constructor function pointer looks like */
typedef void (*CtorFuncPtr)(void);
/* Constructor function pointer list is generated by the linker script. */
extern CtorFuncPtr __CTOR_LIST__[];
extern CtorFuncPtr __CTOR_END__[];
/**
*
* @brief Invoke all C++ style global object constructors
*
* This routine is invoked by the kernel prior to the execution of the
* application's main().
*/
void __do_global_ctors_aux(void)
{
unsigned int nCtors;
nCtors = (unsigned int)__CTOR_LIST__[0];
while (nCtors >= 1) {
__CTOR_LIST__[nCtors--]();
}
}

45
misc/cpp_dtors.c Normal file
View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2016 Wind River Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @file
* @brief Basic C++ destructor module for globals
*
*/
#include <toolchain.h>
void *__dso_handle = 0;
/**
* @brief Register destructor for a global object
*
* @param destructor the global object destructor function
* @param objptr global object pointer
* @param dso Dynamic Shared Object handle for shared libraries
*
* Function does nothing at the moment, assuming the global objects
* do not need to be deleted
*
* @return N/A
*/
int __cxa_atexit(void (*destructor)(void *), void *objptr, void *dso)
{
ARG_UNUSED(destructor);
ARG_UNUSED(objptr);
ARG_UNUSED(dso);
return 0;
}

39
misc/cpp_init_array.c Normal file
View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 2015 Wind River Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @file
* @brief Execute initialization routines referenced in .init_array section
*/
typedef void (*func_ptr)(void);
extern func_ptr __init_array_start[0];
extern func_ptr __init_array_end[0];
/**
* @brief Execute initialization routines referenced in .init_array section
*
* @return N/A
*/
void __do_init_array_aux(void)
{
for (func_ptr *func = __init_array_start;
func < __init_array_end;
func++) {
(*func)();
}
}

35
misc/cpp_virtual.c Normal file
View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2015 Wind River Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @file
* @brief Stub for C++ pure virtual functions
*/
/**
* @brief Stub for pure virtual functions
*
* This routine is needed for linking C++ code that uses pure virtual
* functions.
*
* @return N/A
*/
void __cxa_pure_virtual(void)
{
while (1) {
;
}
}

37
misc/cpp_vtable.cpp Normal file
View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 2015 Wind River Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @file
* @brief Stub for C++ virtual tables
*/
/**
*
* @brief basic virtual tables required for classes to build
*
*/
namespace __cxxabiv1 {
class __class_type_info {
virtual void dummy();
};
class __si_class_type_info {
virtual void dummy();
};
void __class_type_info::dummy() { } // causes the vtable to get created here
void __si_class_type_info::dummy() { } // causes the vtable to get created here
};

View file

@ -20,6 +20,7 @@ subdir-y :=
subdir-m := subdir-m :=
EXTRA_AFLAGS := EXTRA_AFLAGS :=
EXTRA_CFLAGS := EXTRA_CFLAGS :=
EXTRA_CXXFLAGS :=
EXTRA_CPPFLAGS := EXTRA_CPPFLAGS :=
EXTRA_LDFLAGS := EXTRA_LDFLAGS :=
asflags-y := asflags-y :=
@ -196,6 +197,47 @@ quiet_cmd_cc_lst_c = MKLST $@
$(obj)/%.lst: $(src)/%.c FORCE $(obj)/%.lst: $(src)/%.c FORCE
$(call if_changed_dep,cc_lst_c) $(call if_changed_dep,cc_lst_c)
# C++ (.cpp and .cxx) files
# The C++ file is compiled and updated dependency information is generated.
# (See cmd_cc_o_cxx + relevant part of rule_cc_o_cxx)
# No support for module versioning for C++ (for now)
quiet_cmd_cc_o_cxx = C++ $(quiet_modtag) $@
cmd_cc_o_cxx = $(CXX) $(cxx_flags) -c -o $@ $<
define rule_cc_o_cxx
$(call echo-cmd,checksrc) $(cmd_checksrc) \
$(call echo-cmd,cc_o_cxx) $(cmd_cc_o_cxx); \
$(cmd_modversions) \
$(call echo-cmd,record_mcount) \
$(cmd_record_mcount) \
scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_cxx)' > \
$(dot-target).tmp; \
rm -f $(depfile); \
mv -f $(dot-target).tmp $(dot-target).cmd
endef
# Built-in and composite module parts
$(obj)/%.o: $(src)/%.cpp $(recordmcount_source) FORCE
$(call cmd,force_checksrc)
$(call if_changed_rule,cc_o_cxx)
$(obj)/%.o: $(src)/%.cxx $(recordmcount_source) FORCE
$(call cmd,force_checksrc)
$(call if_changed_rule,cc_o_cxx)
quiet_cmd_cc_lst_cxx = MKLST $@
cmd_cc_lst_cxx = $(CXX) $(cxx_flags) -g -c -o $*.o $< && \
$(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
System.map $(OBJDUMP) > $@
$(obj)/%.lst: $(src)/%.cxx FORCE
$(call if_changed_dep,cc_lst_cxx)
$(obj)/%.lst: $(src)/%.cpp FORCE
$(call if_changed_dep,cc_lst_cxx)
# Compile assembler sources (.S) # Compile assembler sources (.S)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------

View file

@ -3,6 +3,7 @@
asflags-y += $(EXTRA_AFLAGS) asflags-y += $(EXTRA_AFLAGS)
ccflags-y += $(EXTRA_CFLAGS) ccflags-y += $(EXTRA_CFLAGS)
cppflags-y += $(EXTRA_CPPFLAGS) cppflags-y += $(EXTRA_CPPFLAGS)
cxxflags-y += $(EXTRA_CXXFLAGS)
ldflags-y += $(EXTRA_LDFLAGS) ldflags-y += $(EXTRA_LDFLAGS)
# #
@ -114,6 +115,9 @@ _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \ _a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \
$(asflags-y) $(AFLAGS_$(basetarget).o) $(asflags-y) $(AFLAGS_$(basetarget).o)
_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F)) _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
orig_cxx_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CXXFLAGS) $(KBUILD_SUBDIR_CXXFLAGS) \
$(cxxflags-y) $(CXXFLAGS_$(basetarget).o)
_cxx_flags = $(filter-out $(CXXFLAGS_REMOVE_$(basetarget).o), $(orig_cxx_flags))
# If building the kernel in a separate objtree expand all occurrences # If building the kernel in a separate objtree expand all occurrences
# of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
@ -122,6 +126,7 @@ ifeq ($(KBUILD_SRC),)
__c_flags = $(_c_flags) __c_flags = $(_c_flags)
__a_flags = $(_a_flags) __a_flags = $(_a_flags)
__cpp_flags = $(_cpp_flags) __cpp_flags = $(_cpp_flags)
__cxx_flags = $(_cxx_flags)
else else
# -I$(obj) locates generated .h files # -I$(obj) locates generated .h files
@ -131,6 +136,7 @@ else
__c_flags = $(call addtree,-I$(obj)) $(call flags,_c_flags) __c_flags = $(call addtree,-I$(obj)) $(call flags,_c_flags)
__a_flags = $(call flags,_a_flags) __a_flags = $(call flags,_a_flags)
__cpp_flags = $(call flags,_cpp_flags) __cpp_flags = $(call flags,_cpp_flags)
__cxx_flags = $(call flags,_cxx_flags)
endif endif
c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(ZEPHYRINCLUDE) \ c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(ZEPHYRINCLUDE) \
@ -149,6 +155,10 @@ dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \
-I$(srctree)/drivers/of/testcase-data \ -I$(srctree)/drivers/of/testcase-data \
-undef -D__DTS__ -undef -D__DTS__
cxx_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(ZEPHYRINCLUDE) \
$(__cxx_flags) $(modkern_cflags) \
-D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags)
# Finds the multi-part object the current object will be linked into # Finds the multi-part object the current object will be linked into
modname-multi = $(sort $(foreach m,$(multi-used),\ modname-multi = $(sort $(foreach m,$(multi-used),\
$(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=)))) $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))

View file

@ -320,7 +320,7 @@ def kernel_main_c_tasks():
kernel_main_c_out("\n") kernel_main_c_out("\n")
for task in task_list: for task in task_list:
kernel_main_c_out("extern void %s(void);\n" % task[2]) kernel_main_c_out("EXTERN_C void %s(void);\n" % task[2])
# task descriptors (including one for idle task) # task descriptors (including one for idle task)
# #