mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Compile c files to separate directories. Add compressed library to example test project.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"provides" : "clib",
|
||||
"c-sources" : ["hello.c"],
|
||||
"c-sources" : ["hello2.c"],
|
||||
"targets" : {
|
||||
"macos-x64" : {
|
||||
},
|
||||
|
||||
BIN
resources/testproject/lib/clib2.c3l
Normal file
BIN
resources/testproject/lib/clib2.c3l
Normal file
Binary file not shown.
@@ -12,7 +12,7 @@
|
||||
"./**"
|
||||
],
|
||||
"dependency-search-paths": [ "./lib" ],
|
||||
"dependencies": ["clib"],
|
||||
"dependencies": ["clib", "clib2"],
|
||||
|
||||
"features": ["ABCD"],
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user