diff --git a/include/functions.h b/include/functions.h index 45ca07167..2153756fd 100644 --- a/include/functions.h +++ b/include/functions.h @@ -8,6 +8,10 @@ #include "stdlib/stdarg.h" #include "libc/xstdio.h" +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + f32 fabsf(f32 f); f64 fabs(f64 f); f32 cosine(s16 arg0); @@ -1096,4 +1100,8 @@ void restore_map_collision_data(void); void mdl_load_all_textures(struct ModelNode* model, s32 romOffset, s32 size); void mdl_calculate_model_sizes(void); +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + #endif diff --git a/include/macros.h b/include/macros.h index e77e8c1bf..945134b56 100644 --- a/include/macros.h +++ b/include/macros.h @@ -22,8 +22,14 @@ #define NAME_SUFFIX #define NAME_PREFIX +#ifdef _LANGUAGE_C_PLUS_PLUS +// use C++ namespaces instead of these macros! +#define A(sym) sym +#define N(sym) sym +#else #define A(sym) NS(AREA, NAME_PREFIX, sym, NAME_SUFFIX) #define N(sym) NS(NAMESPACE, NAME_PREFIX, sym, NAME_SUFFIX) +#endif #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) diff --git a/include/npc.h b/include/npc.h index b4ff96ab2..d665f6f4f 100644 --- a/include/npc.h +++ b/include/npc.h @@ -5,6 +5,10 @@ #include "enums.h" #include "script_api/map.h" +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + // battle and stage are optional in overloaded NPC_GROUP macros #define NPC_GROUP(args...) VFUNC(NPC_GROUP, args) #define NPC_GROUP1(npcs) { sizeof(npcs) / sizeof(NpcData), (NpcData*) &npcs, 0, 0 } @@ -657,4 +661,8 @@ Enemy* get_enemy_safe(s32 npcID); void set_npc_sprite(Npc* npc, s32 anim, AnimID* extraAnimList); +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + #endif diff --git a/include/script_api/battle.h b/include/script_api/battle.h index 24947817d..35fb07a09 100644 --- a/include/script_api/battle.h +++ b/include/script_api/battle.h @@ -9,6 +9,10 @@ #include "effects.h" +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + API_CALLABLE(EnablePartnerBlur); API_CALLABLE(DisablePartnerBlur); API_CALLABLE(UseBattleCamPreset); @@ -378,4 +382,8 @@ extern EvtScript Rumble_Unused_2; extern EvtScript Rumble_Unused_3; extern EvtScript Rumble_Unused_4; +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + #endif diff --git a/include/script_api/common.h b/include/script_api/common.h index d6abe66a4..8b53600fd 100644 --- a/include/script_api/common.h +++ b/include/script_api/common.h @@ -11,6 +11,10 @@ #include "../common.h" #include "macros.h" +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + /// @{ /// @name Map @@ -1373,4 +1377,8 @@ API_CALLABLE(DemoJoystickXY); extern EvtScript EnemyNpcHit; extern EvtScript EnemyNpcDefeat; +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + #endif diff --git a/include/script_api/macros.h b/include/script_api/macros.h index 8cbd5212d..ec66a9f30 100644 --- a/include/script_api/macros.h +++ b/include/script_api/macros.h @@ -4,6 +4,10 @@ #include "evt.h" #include "stdlib/stdarg.h" +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + /****** EXPRESSIONS ***************************************************************************************************/ /// Expressions in EVT instructions should be one of the following types: @@ -830,4 +834,8 @@ #define PlayEffect14(effect, subtype, a, b, c, d, e, f, g, h, i, j, k, l) \ Call(PlayEffect_impl, effect, subtype, a, b, c, d, e, f, g, h, i, j, k, l) +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + #endif diff --git a/include/script_api/map.h b/include/script_api/map.h index afd6c3025..aa959684f 100644 --- a/include/script_api/map.h +++ b/include/script_api/map.h @@ -6,6 +6,10 @@ #include "script_api/common.h" +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + API_CALLABLE(MakeNpcs); API_CALLABLE(BasicAI_Main); API_CALLABLE(ResetFromLava); @@ -56,4 +60,8 @@ extern EvtScript BaseEnterDoor; extern EvtScript EnterPostPipe; extern EvtScript EVS_ShopOwnerDialog; +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + #endif diff --git a/src/dx/debug_menu.h b/src/dx/debug_menu.h index 1db089381..e99cf5998 100644 --- a/src/dx/debug_menu.h +++ b/src/dx/debug_menu.h @@ -2,6 +2,10 @@ #include "dx/config.h" #if DX_DEBUG_MENU || defined(DX_QUICK_LAUNCH_BATTLE) +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + #define DX_DEBUG_DUMMY_ID 0xDEAD typedef enum DebugCheat { @@ -25,6 +29,8 @@ void dx_debug_set_battle_info(s32 battleID, char* stageName); void dx_debug_begin_battle_with_IDs(s16 battle, s16 stage); +void dx_hashed_debug_printf(char* filename, s32 line, char* fmt, ...); + #define debug_print(text) dx_hashed_debug_printf(__FILE__,__LINE__,text) #define debug_printf(fmt, args...) dx_hashed_debug_printf(__FILE__,__LINE__,fmt,##args) @@ -68,4 +74,8 @@ API_CALLABLE(_dxDebugFloatPrintf); #define DebugFloatPrintf8(text, a, b, c, d, e, f, g) \ Call(_dxDebugFloatPrintf, Ref(__FILE__), __LINE__, Ref(text), a, b, c, d, e, f, g) +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + #endif diff --git a/tools/build/configure.py b/tools/build/configure.py index 18ba38873..6abc7634e 100755 --- a/tools/build/configure.py +++ b/tools/build/configure.py @@ -66,11 +66,12 @@ def write_ninja_rules( cc_egcs_dir = f"{BUILD_TOOLS}/cc/egcs/" cc_egcs = f"{cc_egcs_dir}/gcc" cxx = f"{BUILD_TOOLS}/cc/gcc/g++" + cxx_modern = f"{cross}g++" BFDNAME = "elf32-tradbigmips" CPPFLAGS_COMMON = ( - "-Iver/$version/include -Iver/$version/build/include -Iinclude -Isrc -Iassets/$version -D_LANGUAGE_C -D_FINALROM " + "-Iver/$version/include -Iver/$version/build/include -Iinclude -Isrc -Iassets/$version -D_FINALROM " "-DVERSION=$version -DF3DEX_GBI_2 -D_MIPS_SZLONG=32" ) @@ -80,9 +81,9 @@ def write_ninja_rules( CPPFLAGS = "-w " + CPPFLAGS_COMMON + " -nostdinc" - cflags = f"-c -G0 -O2 -gdwarf-2 -x c -B {BUILD_TOOLS}/cc/gcc/ {extra_cflags}" + cflags = f"-c -G0 -O2 -gdwarf-2 -B {BUILD_TOOLS}/cc/gcc/ {extra_cflags}" - cflags_modern = f"-c -G0 -O2 -gdwarf-2 -fdiagnostics-color=always -fno-builtin-bcopy -fno-tree-loop-distribute-patterns -funsigned-char -mgp32 -mfp32 -mabi=32 -mfix4300 -march=vr4300 -mno-gpopt -fno-toplevel-reorder -mno-abicalls -fno-pic -fno-exceptions -fno-stack-protector -fno-zero-initialized-in-bss -Wno-builtin-declaration-mismatch -x c {extra_cflags}" + cflags_modern = f"-c -G0 -O2 -gdwarf-2 -fdiagnostics-color=always -fno-builtin-bcopy -fno-tree-loop-distribute-patterns -funsigned-char -mgp32 -mfp32 -mabi=32 -mfix4300 -march=vr4300 -mno-gpopt -fno-toplevel-reorder -mno-abicalls -fno-pic -fno-exceptions -fno-stack-protector -fno-zero-initialized-in-bss -Wno-builtin-declaration-mismatch {extra_cflags}" cflags_272 = f"-c -G0 -mgp32 -mfp32 -mips3 {extra_cflags}" cflags_272 = cflags_272.replace("-ggdb3", "-g1") @@ -147,7 +148,7 @@ def write_ninja_rules( ninja.rule( "cc_modern", description="gcc_modern $in", - command=f"{ccache}{cc_modern} {cflags_modern} $cflags {CPPFLAGS} {extra_cppflags} $cppflags -MD -MF $out.d $in -o $out", + command=f"{ccache}{cc_modern} {cflags_modern} $cflags {CPPFLAGS} {extra_cppflags} $cppflags -D_LANGUAGE_C -MD -MF $out.d $in -o $out", depfile="$out.d", deps="gcc", ) @@ -178,6 +179,14 @@ def write_ninja_rules( deps="gcc", ) + ninja.rule( + "cxx_modern", + description="cxx_modern $in", + command=f"{ccache}{cxx_modern} {cflags_modern} $cflags {CPPFLAGS} {extra_cppflags} $cppflags -std=c++20 -D_LANGUAGE_C_PLUS_PLUS -MD -MF $out.d $in -o $out", + depfile="$out.d", + deps="gcc", + ) + ninja.rule( "dead_cc_fix", description="dead_cc_fix $in", @@ -698,19 +707,22 @@ def build( task = "cxx" if modern_gcc: - task = "cc_modern" + if task == "cxx": + task = "cxx_modern" + else: + task = "cc_modern" if entry.src_paths[0].suffixes[-1] == ".s": task = "as" elif "gcc_272" in cflags: - task = "cc_272" + #task = "cc_272" cflags = cflags.replace("gcc_272", "") elif "egcs" in cflags: - if sys.platform == "darwin" and non_matching: - print(f"warning: using default compiler for {seg.name} because egcs is not supported on macOS") - else: - task = "cc_egcs" - cflags = cflags.replace("egcs", "") + if sys.platform == "darwin" and non_matching: + print(f"warning: using default compiler for {seg.name} because egcs is not supported on macOS") + else: + #task = "cc_egcs" + cflags = cflags.replace("egcs", "") elif "gcc_modern" in cflags: task = "cc_modern" cflags = cflags.replace("gcc_modern", "") @@ -1488,7 +1500,7 @@ def make_current(self, ninja: ninja_syntax.Writer): if args.shift: extra_cppflags += " -DSHIFT" - extra_cflags += " -Wmissing-braces -Wimplicit -Wredundant-decls -Wstrict-prototypes -Wno-redundant-decls" + extra_cflags += " -Wmissing-braces -Wredundant-decls -Wno-redundant-decls" # add splat to python import path sys.path.insert(0, str((ROOT / args.splat / "src").resolve()))