diff --git a/CMakeLists.txt b/CMakeLists.txt index d3763ea..b5a44cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,8 @@ pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0) # TOML-C99 # # ------------------------------------------------ # +execute_process(COMMAND git submodule init -- dep/tomlc99) + add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/dep/tomlc99/toml.c COMMAND git ARGS submodule update --init --recursive --checkout diff --git a/Dockerfile b/Dockerfile index 68265d8..bb287f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,5 +10,7 @@ COPY --chown=lorang CMakeLists.txt /home/lorang/ COPY --chown=lorang run-check-test.sh /home/lorang/ COPY --chown=lorang .env /home/lorang/ COPY --chown=lorang run-docker-build.sh /home/lorang/ +COPY --chown=lorang dep /home/lorang/dep +COPY --chown=lorang .git /home/lorang/.git RUN cmake . diff --git a/src/cfg/opt.c b/src/cfg/opt.c index 3f5b829..92577d8 100644 --- a/src/cfg/opt.c +++ b/src/cfg/opt.c @@ -5,19 +5,20 @@ #include #include #include +#include TargetConfig* default_target_config() { DEBUG("generating default target config..."); TargetConfig* config = malloc(sizeof(TargetConfig)); - config->name = NULL; + config->name = strdup("out"); config->print_ast = false; config->print_asm = false; config->print_ir = false; config->mode = Application; - config->archive_directory = NULL; - config->archive_directory = NULL; + config->archive_directory = strdup("archive"); + config->output_directory = strdup("bin"); config->optimization_level = 1; config->root_module = NULL; @@ -43,8 +44,10 @@ TargetConfig* default_target_config_from_args(int argc, char *argv[]) { config->mode = Application; } else if (strcmp(option, "--mode=lib") == 0) { config->mode = Library; - } else { + } else if (config->root_module == NULL) { config->root_module = strdup(option); + } else { + print_message(Warning, "Got more than one file to compile, using first by ignoring others."); } } @@ -185,7 +188,7 @@ static int parse_targets(ProjectConfig *config, toml_table_t *root) { toml_table_t *targets = toml_table_in(root, "target"); if (targets == NULL) { - printf("Project has no targets\n"); + print_message(Warning, "Project has no targets"); return PROJECT_SEMANTIC_ERR; } @@ -209,7 +212,7 @@ int load_project_config(ProjectConfig *config) { FILE *config_file = fopen(PROJECT_CONFIG_FILE, "r"); if (config_file == NULL) { - printf("Cannot open file %s: %s\n", PROJECT_CONFIG_FILE, strerror(errno)); + print_message(Error, "Cannot open file %s: %s", PROJECT_CONFIG_FILE, strerror(errno)); ERROR("project file not found"); return PROJECT_TOML_ERR; } @@ -220,17 +223,17 @@ int load_project_config(ProjectConfig *config) { fclose(config_file); if (!conf) { - printf("Invalid project configuration: %s\n\n", err_buf); + print_message(Error, "Invalid project configuration: %s", err_buf); return PROJECT_SEMANTIC_ERR; } toml_table_t *project = toml_table_in(conf, "project"); - if (project) { - if (parse_project_table(config, project) == PROJECT_OK) { - return parse_targets(config, conf); - } - } else { - printf("Invalid project configuration: missing project table\n\n"); + if (!project) { + print_message(Error, "Invalid project configuration: missing project table."); + } + + if (parse_project_table(config, project) == PROJECT_OK) { + return parse_targets(config, conf); } toml_free(conf); diff --git a/src/main.c b/src/main.c index a309dc9..397c652 100644 --- a/src/main.c +++ b/src/main.c @@ -95,6 +95,12 @@ void setup(void) { DEBUG("finished starting up gemstone..."); } +static void setup_target_environment(const TargetConfig* target) { + if (target->output_directory) { + + } +} + void build_target(ModuleFileStack *unit, TargetConfig *target) { print_message(Info, "Compiling file: %s", target->root_module); @@ -103,8 +109,7 @@ void build_target(ModuleFileStack *unit, TargetConfig *target) { ModuleFile *file = push_file(unit, target->root_module); if (compile_file_to_ast(ast, file) == EXIT_SUCCESS) { - - + setup_target_environment(target); if (target->print_ast) {