mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
.obj / .exe default suffix now depends on target, not compiler platform.
This commit is contained in:
@@ -351,8 +351,8 @@ static void parse_option(BuildOptions *options)
|
||||
options->linker_args[options->linker_arg_count++] = next_arg();
|
||||
return;
|
||||
case 'o':
|
||||
if (at_end()) error_exit("error: -o needs a value");
|
||||
options->output_name=next_arg();
|
||||
if (at_end()) error_exit("error: -o needs a name");
|
||||
options->output_name = next_arg();
|
||||
return;
|
||||
case 'O':
|
||||
if (options->optimization_setting_override != OPT_SETTING_NOT_SET)
|
||||
|
||||
@@ -145,12 +145,12 @@ static void update_build_target_from_options(BuildTarget *target, BuildOptions *
|
||||
}
|
||||
}
|
||||
|
||||
void init_default_build_target(BuildTarget *target, BuildOptions *options, const char *name)
|
||||
void init_default_build_target(BuildTarget *target, BuildOptions *options)
|
||||
{
|
||||
*target = (BuildTarget) {
|
||||
.type = TARGET_TYPE_EXECUTABLE,
|
||||
.source_dirs = options->files,
|
||||
.name = name,
|
||||
.name = options->output_name,
|
||||
.optimization_level = OPTIMIZATION_DEFAULT,
|
||||
.size_optimization_level = SIZE_OPTIMIZATION_NONE,
|
||||
.symtab_size = DEFAULT_SYMTAB_SIZE,
|
||||
|
||||
@@ -270,6 +270,20 @@ static void setup_int_define(const char *id, uint64_t i, Type *type)
|
||||
}
|
||||
}
|
||||
|
||||
static const char *active_target_name(void)
|
||||
{
|
||||
if (active_target.name) return active_target.name;
|
||||
switch (active_target.arch_os_target)
|
||||
{
|
||||
case X86_WINDOWS:
|
||||
case X64_WINDOWS:
|
||||
case X64_WINDOWS_GNU:
|
||||
return "a.exe";
|
||||
default:
|
||||
return "a.out";
|
||||
}
|
||||
}
|
||||
|
||||
static void setup_bool_define(const char *id, bool value)
|
||||
{
|
||||
TokenType token_type = TOKEN_CONST_IDENT;
|
||||
@@ -464,13 +478,14 @@ void compiler_compile(void)
|
||||
|
||||
if (create_exe)
|
||||
{
|
||||
const char *output_name = active_target_name();
|
||||
if (active_target.arch_os_target == ARCH_OS_TARGET_DEFAULT)
|
||||
{
|
||||
platform_linker(active_target.name, obj_files, output_file_count);
|
||||
platform_linker(output_name, obj_files, output_file_count);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!obj_format_linking_supported(platform_target.object_format) || !linker(active_target.name, obj_files,
|
||||
if (!obj_format_linking_supported(platform_target.object_format) || !linker(output_name, obj_files,
|
||||
output_file_count))
|
||||
{
|
||||
printf("No linking is performed due to missing linker support.\n");
|
||||
@@ -479,7 +494,7 @@ void compiler_compile(void)
|
||||
}
|
||||
if (active_target.run_after_compile)
|
||||
{
|
||||
system(strformat("./%s", active_target.name));
|
||||
system(strformat("./%s", output_name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -532,8 +547,7 @@ static const char **target_expand_source_names(const char** dirs, const char *su
|
||||
|
||||
void compile_target(BuildOptions *options)
|
||||
{
|
||||
if(options->output_name == NULL) options->output_name = DEFAULT_EXE;
|
||||
init_default_build_target(&active_target, options, options->output_name);
|
||||
init_default_build_target(&active_target, options);
|
||||
compile();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,6 @@ void compile();
|
||||
void compile_target(BuildOptions *options);
|
||||
void compile_file_list(BuildOptions *options);
|
||||
void init_build_target(BuildTarget *build_target, BuildOptions *build_options);
|
||||
void init_default_build_target(BuildTarget *target, BuildOptions *options, const char *name);
|
||||
void init_default_build_target(BuildTarget *target, BuildOptions *options);
|
||||
void symtab_init(uint32_t max_size);
|
||||
|
||||
|
||||
@@ -26,17 +26,6 @@ typedef uint32_t ArraySize;
|
||||
typedef uint64_t BitSize;
|
||||
|
||||
|
||||
#if PLATFORM_WINDOWS
|
||||
#define DEFAULT_EXE "a.exe"
|
||||
#else
|
||||
#define DEFAULT_EXE "a.out"
|
||||
#endif
|
||||
|
||||
#if PLATFORM_WINDOWS
|
||||
#define DEFAULT_OBJ_FILE_EXT ".obj"
|
||||
#else
|
||||
#define DEFAULT_OBJ_FILE_EXT ".o"
|
||||
#endif
|
||||
|
||||
|
||||
typedef uint32_t SourceLoc;
|
||||
|
||||
@@ -4,6 +4,18 @@
|
||||
|
||||
#include "llvm_codegen_internal.h"
|
||||
|
||||
const char *get_object_extension(void)
|
||||
{
|
||||
switch (active_target.arch_os_target)
|
||||
{
|
||||
case X64_WINDOWS:
|
||||
case X86_WINDOWS:
|
||||
case X64_WINDOWS_GNU:
|
||||
return ".obj";
|
||||
default:
|
||||
return ".o";
|
||||
}
|
||||
}
|
||||
|
||||
void gencontext_begin_module(GenContext *c)
|
||||
{
|
||||
@@ -22,7 +34,7 @@ void gencontext_begin_module(GenContext *c)
|
||||
}
|
||||
const char *result = scratch_buffer_to_string();
|
||||
c->ir_filename = strformat("%s.ll", result);
|
||||
c->object_filename = strformat("%s%s", result, DEFAULT_OBJ_FILE_EXT);
|
||||
c->object_filename = strformat("%s%s", result, get_object_extension());
|
||||
|
||||
c->module = LLVMModuleCreateWithNameInContext(c->code_module->name->module, c->context);
|
||||
c->machine = llvm_target_machine_create();
|
||||
|
||||
Reference in New Issue
Block a user