Using C files now correctly places object files in build folder.

This commit is contained in:
Christoffer Lerno
2023-01-07 01:38:44 +01:00
parent 38be3d57dd
commit 009bbeb48f
4 changed files with 34 additions and 15 deletions

View File

@@ -385,16 +385,11 @@ void compiler_compile(void)
if (cfiles)
{
platform_compiler(active_target.csources, cfiles, active_target.cflags);
for (int i = 0; i < cfiles; i++)
{
char *filename = NULL;
bool split_worked = file_namesplit(active_target.csources[i], &filename, NULL);
assert(split_worked);
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;
const char *file = active_target.csources[i];
const char *obj = platform_compiler(file, active_target.cflags);
obj_files[output_file_count + i] = obj;
}
}

View File

@@ -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 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);
#define CAT(a,b) CAT2(a,b) // force expand

View File

@@ -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);
}
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;
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);
}
vec_add(parts, "-c");
if (flags) vec_add(parts, flags);
for (unsigned i = 0; i < file_count; i++)
{
vec_add(parts, files[i]);
}
vec_add(parts, file);
vec_add(parts, "-o");
vec_add(parts, out_name);
const char *output = concat_string_parts(parts);
if (system(output) != 0)
{
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)

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.5"
#define COMPILER_VERSION "0.4.6"