mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Using C files now correctly places object files in build folder.
This commit is contained in:
@@ -385,16 +385,11 @@ void compiler_compile(void)
|
|||||||
|
|
||||||
if (cfiles)
|
if (cfiles)
|
||||||
{
|
{
|
||||||
platform_compiler(active_target.csources, cfiles, active_target.cflags);
|
|
||||||
for (int i = 0; i < cfiles; i++)
|
for (int i = 0; i < cfiles; i++)
|
||||||
{
|
{
|
||||||
char *filename = NULL;
|
const char *file = active_target.csources[i];
|
||||||
bool split_worked = file_namesplit(active_target.csources[i], &filename, NULL);
|
const char *obj = platform_compiler(file, active_target.cflags);
|
||||||
assert(split_worked);
|
obj_files[output_file_count + i] = obj;
|
||||||
size_t len = strlen(filename);
|
|
||||||
// .c -> .o (quick hack to fix the name on linux)
|
|
||||||
filename[len - 1] = 'o';
|
|
||||||
obj_files[output_file_count + i] = filename;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2980,7 +2980,7 @@ bool static_lib_linker(const char *output_file, const char **files, unsigned fil
|
|||||||
bool dynamic_lib_linker(const char *output_file, const char **files, unsigned file_count);
|
bool dynamic_lib_linker(const char *output_file, const char **files, unsigned file_count);
|
||||||
bool linker(const char *output_file, const char **files, unsigned file_count);
|
bool linker(const char *output_file, const char **files, unsigned file_count);
|
||||||
void platform_linker(const char *output_file, const char **files, unsigned file_count);
|
void platform_linker(const char *output_file, const char **files, unsigned file_count);
|
||||||
void platform_compiler(const char **files, unsigned file_count, const char* flags);
|
const char *platform_compiler(const char *file, const char* flags);
|
||||||
const char *arch_to_linker_arch(ArchType arch);
|
const char *arch_to_linker_arch(ArchType arch);
|
||||||
|
|
||||||
#define CAT(a,b) CAT2(a,b) // force expand
|
#define CAT(a,b) CAT2(a,b) // force expand
|
||||||
|
|||||||
@@ -735,8 +735,30 @@ void platform_linker(const char *output_file, const char **files, unsigned file_
|
|||||||
printf("Program linked to executable '%s'.\n", output_file);
|
printf("Program linked to executable '%s'.\n", output_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void platform_compiler(const char **files, unsigned file_count, const char *flags)
|
const char *platform_compiler(const char *file, const char *flags)
|
||||||
{
|
{
|
||||||
|
const char *dir = active_target.object_file_dir;
|
||||||
|
if (!dir) dir = active_target.build_dir;
|
||||||
|
|
||||||
|
char *filename = NULL;
|
||||||
|
bool split_worked = file_namesplit(file, &filename, NULL);
|
||||||
|
if (!split_worked) error_exit("Cannot compile '%s'", file);
|
||||||
|
size_t len = strlen(filename);
|
||||||
|
// Remove .cpp or .c
|
||||||
|
if (len > 5 && memcmp(filename + len - 4, ".cpp", 4) == 0)
|
||||||
|
{
|
||||||
|
len -= 4;
|
||||||
|
filename[len] = 0;
|
||||||
|
}
|
||||||
|
else if (len > 2 && memcmp(filename + len - 2, ".c", 2) == 0)
|
||||||
|
{
|
||||||
|
len -= 2;
|
||||||
|
filename[len] = 0;
|
||||||
|
}
|
||||||
|
const char *out_name = dir
|
||||||
|
? str_printf("%s/%s%s", dir, filename, get_object_extension())
|
||||||
|
: str_printf("%s%s", filename, get_object_extension());
|
||||||
|
|
||||||
const char **parts = NULL;
|
const char **parts = NULL;
|
||||||
vec_add(parts, active_target.cc);
|
vec_add(parts, active_target.cc);
|
||||||
|
|
||||||
@@ -750,17 +772,19 @@ void platform_compiler(const char **files, unsigned file_count, const char *flag
|
|||||||
{
|
{
|
||||||
append_fpie_pic_options(platform_target.reloc_model, &parts);
|
append_fpie_pic_options(platform_target.reloc_model, &parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec_add(parts, "-c");
|
vec_add(parts, "-c");
|
||||||
if (flags) vec_add(parts, flags);
|
if (flags) vec_add(parts, flags);
|
||||||
for (unsigned i = 0; i < file_count; i++)
|
vec_add(parts, file);
|
||||||
{
|
vec_add(parts, "-o");
|
||||||
vec_add(parts, files[i]);
|
vec_add(parts, out_name);
|
||||||
}
|
|
||||||
const char *output = concat_string_parts(parts);
|
const char *output = concat_string_parts(parts);
|
||||||
if (system(output) != 0)
|
if (system(output) != 0)
|
||||||
{
|
{
|
||||||
error_exit("Failed to compile c sources using command '%s'.\n", output);
|
error_exit("Failed to compile c sources using command '%s'.\n", output);
|
||||||
}
|
}
|
||||||
|
return out_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dynamic_lib_linker(const char *output_file, const char **files, unsigned file_count)
|
bool dynamic_lib_linker(const char *output_file, const char **files, unsigned file_count)
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
#define COMPILER_VERSION "0.4.5"
|
#define COMPILER_VERSION "0.4.6"
|
||||||
Reference in New Issue
Block a user