Compile c files to separate directories. Add compressed library to example test project.

This commit is contained in:
Christoffer Lerno
2024-07-10 13:35:01 +02:00
parent 5cf1f13328
commit e7d8f64a49
8 changed files with 14 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ module hello_world;
import std;
import bar;
import clib;
import clib2;
fn int test_doubler(int x) @if(env::WIN32) => x * x;
extern fn int test_doubler(int) @if(!env::WIN32);
@@ -14,5 +15,6 @@ fn int main()
printf("Hello double: %d\n", test_doubler(11));
if ($feature(ABCD)) io::printn("ABCD");
clib::hello_from_c();
clib2::hello_from_c_zip();
return 0;
}

View File

@@ -1,6 +1,6 @@
{
"provides" : "clib",
"c-sources" : ["hello.c"],
"c-sources" : ["hello2.c"],
"targets" : {
"macos-x64" : {
},

Binary file not shown.

View File

@@ -12,7 +12,7 @@
"./**"
],
"dependency-search-paths": [ "./lib" ],
"dependencies": ["clib"],
"dependencies": ["clib", "clib2"],
"features": ["ABCD"],

View File

@@ -253,12 +253,13 @@ static void free_arenas(void)
if (debug_stats) print_arena_status();
}
static int compile_cfiles(const char *compiler, const char **files, const char *flags, const char **out_files)
static int compile_cfiles(const char *compiler, const char **files, const char *flags, const char **out_files,
const char *output_subdir)
{
int total = 0;
FOREACH(const char *, file, files)
{
out_files[total++] = cc_compiler(compiler, file, flags);
out_files[total++] = cc_compiler(compiler, file, flags, output_subdir);
}
return total;
}
@@ -468,14 +469,15 @@ void compiler_compile(void)
if (cfiles)
{
int compiled = compile_cfiles(active_target.cc, active_target.csources, active_target.cflags, &obj_files[output_file_count]);
int compiled = compile_cfiles(active_target.cc, active_target.csources, active_target.cflags, &obj_files[output_file_count], "tmp_c_compile");
assert(cfiles == compiled);
(void)compiled;
}
const char **obj_file_next = &obj_files[output_file_count + cfiles];
FOREACH(LibraryTarget *, lib, active_target.ccompling_libraries)
{
obj_file_next += compile_cfiles(lib->cc ? lib->cc : active_target.cc, lib->csources, lib->cflags, obj_file_next);
obj_file_next += compile_cfiles(lib->cc ? lib->cc : active_target.cc, lib->csources,
lib->cflags, obj_file_next, lib->parent->provides);
}
Task **tasks = NULL;

View File

@@ -3504,7 +3504,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);
const char *cc_compiler(const char *cc, const char *file, const char *flags);
const char *cc_compiler(const char *cc, const char *file, const char *flags, const char *output_subdir);
const char *arch_to_linker_arch(ArchType arch);
#define CAT(a,b) CAT2(a,b) // force expand

View File

@@ -761,11 +761,12 @@ void platform_linker(const char *output_file, const char **files, unsigned file_
printf("Program linked to executable '%s'.\n", output_file);
}
const char *cc_compiler(const char *cc, const char *file, const char *flags)
const char *cc_compiler(const char *cc, const char *file, const char *flags, const char *output_subdir)
{
const char *dir = active_target.object_file_dir;
if (!dir) dir = active_target.build_dir;
if (output_subdir) dir = file_append_path(dir, output_subdir);
dir_make(dir);
bool is_cl_exe = str_eq(cc, "cl.exe");
char *filename = NULL;
bool split_worked = file_namesplit(file, &filename, NULL);