diff --git a/CMakeLists.txt b/CMakeLists.txt index e02180f..8f3dc14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,10 @@ if (NOT DEFINED bshell_interactive) set(bshell_interactive 1) endif () +if (NOT DEFINED bshell_enable_native_commands) + set(bshell_enable_native_commands 1) +endif () + if (NOT DEFINED bshell_verbose) set(bshell_verbose 0) endif () @@ -15,12 +19,16 @@ if (NOT DEFINED bshell_enable_floating_point) set(bshell_enable_floating_point 1) endif () -set(required_fx_assemblies fx.runtime fx.collections fx.io fx.diagnostics fx.cmdline) +set(required_fx_assemblies fx.runtime fx.collections fx.cmdline fx.io) if (bshell_interactive) set(required_fx_assemblies ${required_fx_assemblies} fx.term) endif () +if (bshell_enable_native_commands) + set(required_fx_assemblies ${required_fx_assemblies} fx.diagnostics) +endif () + find_package(Python COMPONENTS Interpreter REQUIRED) find_package(FX REQUIRED COMPONENTS ${required_fx_assemblies}) diff --git a/bshell.core/CMakeLists.txt b/bshell.core/CMakeLists.txt index f543fdb..b9f7d1a 100644 --- a/bshell.core/CMakeLists.txt +++ b/bshell.core/CMakeLists.txt @@ -18,3 +18,5 @@ target_include_directories(bshell.core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/includ target_compile_definitions(bshell.core PUBLIC BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point} BSHELL_VERSION="${bshell_version}") + +install(TARGETS bshell.core) diff --git a/bshell.runtime/CMakeLists.txt b/bshell.runtime/CMakeLists.txt index 794e7cd..d34a996 100644 --- a/bshell.runtime/CMakeLists.txt +++ b/bshell.runtime/CMakeLists.txt @@ -1,6 +1,10 @@ set(source_dirs ast compile parse parse/lex parse/syntax - format runtime command line-editor) + format runtime command) + +if (bshell_interactive) + set(source_dirs ${source_dirs} line-editor) +endif () file(GLOB sources *.c @@ -15,15 +19,22 @@ endforeach (d) add_library(bshell.runtime SHARED ${sources}) -target_link_libraries(bshell.runtime FX::Runtime FX::Collections FX::Io FX::Diagnostics) +target_link_libraries(bshell.runtime FX::Runtime FX::Collections FX::Io) if (bshell_interactive) target_link_libraries(bshell.runtime FX::Term) endif () +if (bshell_enable_native_commands) + target_link_libraries(bshell.runtime FX::Diagnostics) +endif () + target_include_directories(bshell.runtime PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_compile_definitions(bshell.runtime PUBLIC BSHELL_VERSION="${bshell_version}" BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point} + BSHELL_ENABLE_NATIVE_COMMANDS=${bshell_enable_native_commands} BSHELL_INTERACTIVE=${bshell_interactive} BSHELL_VERBOSE=${bshell_verbose}) + +install(TARGETS bshell.runtime) diff --git a/bshell.runtime/command/native-command.c b/bshell.runtime/command/native-command.c index 6dc7eea..de8baaf 100644 --- a/bshell.runtime/command/native-command.c +++ b/bshell.runtime/command/native-command.c @@ -1,3 +1,4 @@ +#if BSHELL_ENABLE_NATIVE_COMMANDS == 1 #include #include #include @@ -231,3 +232,4 @@ FX_TYPE_DEFINITION_BEGIN(bshell_native_command) FX_TYPE_INSTANCE_FINI(fini); FX_TYPE_INSTANCE_PRIVATE(struct bshell_native_command_p); FX_TYPE_DEFINITION_END(bshell_native_command) +#endif diff --git a/bshell.runtime/runtime/cmdcall.c b/bshell.runtime/runtime/cmdcall.c index f85806d..1b330e2 100644 --- a/bshell.runtime/runtime/cmdcall.c +++ b/bshell.runtime/runtime/cmdcall.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -15,6 +14,10 @@ #include #include +#if BSHELL_ENABLE_NATIVE_COMMANDS == 1 +#include +#endif + #if BSHELL_INTERACTIVE == 1 #include #endif @@ -107,6 +110,7 @@ static bshell_command *resolve_cmdlet( static const fx_string *get_path(void) { +#if BSHELL_ENABLE_NATIVE_COMMANDS == 1 fx_process *self = fx_process_get_self(); if (!self) { return NULL; @@ -125,8 +129,12 @@ static const fx_string *get_path(void) const fx_string *path = NULL; fx_value_get_object(path_v, (fx_object **)&path); return path; +#else + return NULL; +#endif } +#if BSHELL_ENABLE_NATIVE_COMMANDS == 1 static bshell_command *resolve_native_command_local( struct bshell_cmdcall_p *cmdcall, struct bshell_runtime *rt, @@ -188,6 +196,7 @@ static bshell_command *resolve_native_command( fx_iterator_unref(it); return result; } +#endif static enum bshell_status resolve_call_target( struct bshell_cmdcall_p *cmdcall, @@ -206,11 +215,13 @@ static enum bshell_status resolve_call_target( return BSHELL_SUCCESS; } +#if BSHELL_ENABLE_NATIVE_COMMANDS == 1 if ((cmdcall->cmd_target = resolve_native_command(cmdcall, rt, cmd_name_s))) { cmdcall->cmd_type = CMDCALL_NATIVE; return BSHELL_SUCCESS; } +#endif const char *cmd_name_cstr = fx_string_get_cstr(cmd_name_s); #if BSHELL_INTERACTIVE == 1 diff --git a/bshell/CMakeLists.txt b/bshell/CMakeLists.txt index 496fad6..fa39537 100644 --- a/bshell/CMakeLists.txt +++ b/bshell/CMakeLists.txt @@ -33,3 +33,5 @@ target_compile_definitions(bshell PUBLIC BSHELL_ENABLE_FLOATING_POINT=${bshell_enable_floating_point} BSHELL_INTERACTIVE=${bshell_interactive} BSHELL_VERBOSE=${bshell_verbose}) + +install(TARGETS bshell) diff --git a/bshell/main.c b/bshell/main.c index 4ba4639..755fcba 100644 --- a/bshell/main.c +++ b/bshell/main.c @@ -4,10 +4,6 @@ #include #include #include -#include -#include -#include -#include #include #include #include @@ -16,6 +12,13 @@ #include #include +#if BSHELL_INTERACTIVE == 1 +#include +#include +#include +#include +#endif + enum { CMD_ROOT, OPT_LEX, @@ -75,6 +78,7 @@ static enum frontend_flags collect_frontend_flags(const fx_arglist *opt) return result; } +#if BSHELL_INTERACTIVE == 1 static void new_line_ed(void) { bshell_line_ed_core *ed_core = bshell_line_ed_core_create(); @@ -96,9 +100,11 @@ static void new_line_ed(void) fx_string_unref(line); bshell_line_ed_unref(ed); } +#endif static enum bshell_status load_profile(struct frontend_ctx *ctx) { +#if BSHELL_INTERACTIVE == 1 enum bshell_status status = BSHELL_SUCCESS; fx_path *config_base_dir = fx_path_get_system(FX_PATH_CONFIG); fx_path *profile_path = fx_path_join_list( @@ -124,6 +130,8 @@ static enum bshell_status load_profile(struct frontend_ctx *ctx) } fx_path_unref(profile_path); return status; +#endif + return BSHELL_SUCCESS; } static int bshell(