diff --git a/litex/soc/software/demo/Makefile b/litex/soc/software/demo/Makefile index cc39cdebe..a9a99c206 100644 --- a/litex/soc/software/demo/Makefile +++ b/litex/soc/software/demo/Makefile @@ -3,7 +3,10 @@ BUILD_DIR?=../build/ include $(BUILD_DIR)/software/include/generated/variables.mak include $(SOC_DIRECTORY)/software/common.mak -OBJECTS=isr.o donut.o helloc.o hellocpp.o main.o +OBJECTS = isr.o donut.o helloc.o main.o +ifdef WITH_CXX + OBJECTS += hellocpp.o +endif all: demo.bin @@ -33,6 +36,7 @@ donut.o: CFLAGS += -w helloc.o: CFLAGS += -w hellocpp.o: CXXFLAGS += -w + %.o: %.cpp $(compilexx) diff --git a/litex/soc/software/demo/demo.py b/litex/soc/software/demo/demo.py index 9c258f6ed..6f94d4c32 100644 --- a/litex/soc/software/demo/demo.py +++ b/litex/soc/software/demo/demo.py @@ -12,7 +12,8 @@ from distutils.dir_util import copy_tree def main(): parser = argparse.ArgumentParser(description="LiteX Bare Metal Demo App.") - parser.add_argument("--build-path", help="Target's build path (ex build/board_name)", required=True) + parser.add_argument("--build-path", help="Target's build path (ex build/board_name).", required=True) + parser.add_argument("--with-cxx", action="store_true", help="Enable CXX support.") args = parser.parse_args() # Create demo directory @@ -24,7 +25,7 @@ def main(): # Compile demo build_path = args.build_path if os.path.isabs(args.build_path) else os.path.join("..", args.build_path) - os.system(f"export BUILD_DIR={build_path} && cd demo && make") + os.system(f"export BUILD_DIR={build_path} && {'export WITH_CXX=1 &&' if args.with_cxx else ''} cd demo && make") # Copy demo.bin os.system("cp demo/demo.bin ./") diff --git a/litex/soc/software/demo/main.c b/litex/soc/software/demo/main.c index be38cb521..f628b5b88 100644 --- a/litex/soc/software/demo/main.c +++ b/litex/soc/software/demo/main.c @@ -88,7 +88,9 @@ static void help(void) #endif puts("donut - Spinning Donut demo"); puts("helloc - Hello C"); +#ifdef WITH_CXX puts("hellocpp - Hello C++"); +#endif } /*-----------------------------------------------------------------------*/ @@ -148,6 +150,7 @@ static void helloc_cmd(void) helloc(); } +#ifdef WITH_CXX extern void hellocpp(void); static void hellocpp_cmd(void) @@ -155,6 +158,8 @@ static void hellocpp_cmd(void) printf("Hello C++ demo...\n"); hellocpp(); } +#endif + /*-----------------------------------------------------------------------*/ /* Console service / Main */ /*-----------------------------------------------------------------------*/ @@ -179,8 +184,10 @@ static void console_service(void) donut_cmd(); else if(strcmp(token, "helloc") == 0) helloc_cmd(); +#ifdef WITH_CXX else if(strcmp(token, "hellocpp") == 0) hellocpp_cmd(); +#endif prompt(); }