Skip to content

Commit

Permalink
[make] Add support for c++0x for all architectures
Browse files Browse the repository at this point in the history
  • Loading branch information
fvantienen committed Mar 5, 2019
1 parent 1c12f16 commit 399e964
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 12 deletions.
9 changes: 9 additions & 0 deletions conf/Makefile.chibios
Expand Up @@ -74,6 +74,12 @@ else
$(TARGET).CFLAGS += -DCH_DBG_THREADS_PROFILING=TRUE
endif

#
# Add syscalls and c++ new/delete operators
#
$(TARGET).srcs += c++.cpp pprz_syscalls.c
$(TARGET).CXXFLAGS += -fno-sized-deallocation

#
# General rules
#
Expand Down Expand Up @@ -312,6 +318,9 @@ CPPWARN = -Wall -Wextra
# List all user C define here, like -D_DEBUG=1
UDEFS = $($(TARGET).CFLAGS) $(USER_CFLAGS) $(BOARD_CFLAGS)

# List all extra user CPP define here
UPDEFS = $($(TARGET).CXXFLAGS)

# Define ASM defines here
UADEFS = $($(TARGET).CFLAGS) $(USER_CFLAGS) $(BOARD_CFLAGS)

Expand Down
4 changes: 3 additions & 1 deletion conf/Makefile.linux
Expand Up @@ -37,6 +37,7 @@ OPT ?= 3
# Slightly bigger .elf files but gains the ability to decode macros
DEBUG_FLAGS ?= -ggdb3
CSTANDARD ?= -std=gnu99
CXXSTANDARD ?= -std=c++0x
CINCS = $(INCLUDES) -I$(PAPARAZZI_SRC)/sw/include

#
Expand Down Expand Up @@ -65,10 +66,11 @@ CFLAGS += $(USER_CFLAGS) $(BOARD_CFLAGS)
CXXFLAGS += $(CINCS)
CXXFLAGS += -O$(OPT) -fPIC
CXXFLAGS += $(DEBUG_FLAGS)
CXXFLAGS += $(CXXSTANDARD)
CXXFLAGS += -pipe -fshow-column -ffast-math
CXXFLAGS += -g -ffunction-sections -fdata-sections
CXXFLAGS += -Wall -Wextra
#CXXFLAGS += $($(TARGET).CFLAGS)
CXXFLAGS += $($(TARGET).CFLAGS)
CXXFLAGS += $($(TARGET).CXXFLAGS)
CXXFLAGS += $(USER_CFLAGS) $(BOARD_CFLAGS)

Expand Down
8 changes: 6 additions & 2 deletions conf/Makefile.stm32
Expand Up @@ -36,7 +36,6 @@ Q=@
#
include $(PAPARAZZI_SRC)/conf/Makefile.arm-embedded-toolchain


ifeq ($(ARCH_L),f4)
MCU = cortex-m4
else
Expand All @@ -47,9 +46,13 @@ OPT ?= s
DEBUG_FLAGS ?= -ggdb3

CSTANDARD ?= -std=gnu99
CXXSTANDARD ?= -std=c++98
CXXSTANDARD ?= -std=c++0x
CINCS = $(INCLUDES) -I$(PAPARAZZI_SRC)/sw/include

# add syscalls and c++ new/delete operators
$(TARGET).srcs += c++.cpp pprz_syscalls.c
$(TARGET).CXXFLAGS += -fno-sized-deallocation

# input files
SRCS = $($(TARGET).srcs)
#ASRC =
Expand Down Expand Up @@ -145,6 +148,7 @@ CFLAGS += -DPPRZLINK_UNALIGNED_ACCESS=1

# C++ only flags
CXXFLAGS += $(CXXSTANDARD)
CXXFLAGS += -I. -I./$(ARCH) -I../ext/libopencm3/include $(INCLUDES)
CXXFLAGS += -pipe -fshow-column -ffast-math
CXXFLAGS += -ffunction-sections -fdata-sections
CXXFLAGS += $($(TARGET).CXXFLAGS)
Expand Down
2 changes: 1 addition & 1 deletion conf/chibios/chibios_rules.mk
Expand Up @@ -118,7 +118,7 @@ ODFLAGS = -x --syms
ASFLAGS = $(MCFLAGS) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.s=.lst)) $(ADEFS)
ASXFLAGS = $(MCFLAGS) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.S=.lst)) $(ADEFS)
CFLAGS = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.c=.lst)) $(DEFS)
CPPFLAGS = $(MCFLAGS) $(OPT) $(CPPOPT) $(CPPWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.cpp=.lst)) $(DEFS)
CPPFLAGS = $(MCFLAGS) $(OPT) $(CPPOPT) $(CPPWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.cpp=.lst)) $(DEFS) $(UPDEFS)
LDFLAGS = $(MCFLAGS) $(OPT) -nostartfiles $(LLIBDIR) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch,--library-path=$(RULESPATH)/ld,--script=$(LDSCRIPT)$(LDOPT)

# Thumb interwork enabled only if needed because it kills performance.
Expand Down
1 change: 1 addition & 0 deletions conf/firmwares/fixedwing.makefile
Expand Up @@ -21,6 +21,7 @@ SRC_MODULES=modules
FIXEDWING_INC = -I$(SRC_FIRMWARE) -I$(SRC_FIXEDWING) -I$(SRC_BOARD)

VPATH += $(PAPARAZZI_HOME)/var/share
VPATH += $(PAPARAZZI_HOME)/sw/ext

# Standard Fixed Wing Code
include $(CFG_FIXEDWING)/autopilot.makefile
Expand Down
1 change: 1 addition & 0 deletions conf/firmwares/rotorcraft.makefile
Expand Up @@ -37,6 +37,7 @@ ap.ARCHDIR = $(ARCH)


VPATH += $(PAPARAZZI_HOME)/var/share
VPATH += $(PAPARAZZI_HOME)/sw/ext

######################################################################
##
Expand Down
1 change: 0 additions & 1 deletion conf/modules/ins_mekf_wind.xml
Expand Up @@ -82,7 +82,6 @@
<define name="EIGEN_NO_DEBUG"/>
<flag name="CXXFLAGS" value="Wno-bool-compare"/>
<flag name="CXXFLAGS" value="Wno-logical-not-parentheses"/>
<file name="pprz_syscalls.c" dir="."/>
</makefile>
<makefile target="sim" firmware="fixedwing">
<define name="AHRS_TYPE_H" value="subsystems/ahrs/ahrs_sim.h" type="string"/>
Expand Down
7 changes: 0 additions & 7 deletions conf/modules/rust_demo_module.xml
Expand Up @@ -26,13 +26,6 @@
<init fun="rust_function()"/>
<periodic fun="rust_periodic()" freq="1." autorun="TRUE"/>

<makefile target="ap">
<!-->
Additional defines needed by Rust's `alloc` crate
-->
<file name="pprz_syscalls.c" dir="."/>
</makefile>

<makefile target="ap|nps|hitl">
<!--
MODULE_PATH is where the module lives.
Expand Down
60 changes: 60 additions & 0 deletions sw/airborne/c++.cpp
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2019 Freek van Tienen <freek.v.tienen@gmail.com>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>

/**
* Replace new and delete operators of C++
*/

void * operator new(size_t size)
{
if (size < 1) {
size = 1;
}
return(calloc(size, 1));
}

void operator delete(void *p)
{
if (p) free(p);
}

void * operator new[](size_t size)
{
if (size < 1) {
size = 1;
}
return(calloc(size, 1));
}

void operator delete[](void * ptr)
{
if (ptr) free(ptr);
}

/*void operator delete(void* ptr, unsigned int size)
{
if (ptr) free(ptr);
}
void operator delete [](void* ptr, unsigned int size)
{
if (ptr) free(ptr);
}*/
13 changes: 13 additions & 0 deletions sw/airborne/pprz_syscalls.c
Expand Up @@ -151,6 +151,13 @@ int _isatty_r(struct _reent *r, int fd)

/***************************************************************************/

__attribute__((used))
void _fini(void) {
return;
}

/***************************************************************************/

__attribute__((used))
pid_t _getpid(void)
{
Expand All @@ -169,6 +176,12 @@ void _exit(int i) {

void _kill(void) {}

/***************************************************************************/

void *__dso_handle;
void __cxa_pure_virtual(void);
void __cxa_pure_virtual() { while (1); } //TODO: Handle properly, maybe generate a traceback

#pragma GCC diagnostic pop

/*** EOF ***/

0 comments on commit 399e964

Please sign in to comment.