Fix -l and -L build options.

This commit is contained in:
Christoffer Lerno
2022-08-10 22:21:29 +02:00
parent 92b4eeaa35
commit aa337049ea
6 changed files with 28 additions and 18 deletions

View File

@@ -412,26 +412,12 @@ static void parse_option(BuildOptions *options)
return;
case 'L':
if (at_end() || next_is_opt()) error_exit("error: -L needs a directory.");
add_linker_arg(options, "-L");
add_linker_arg(options, check_dir(next_arg()));
options->linker_lib_dir[options->linker_lib_dir_count++] = check_dir(next_arg());
return;
case 'l':
{
if (at_end() || next_is_opt()) error_exit("error: -l needs a library name.");
const char *lib = next_arg();
const char *framework = str_remove_suffix(lib, ".framework");
if (framework)
{
add_linker_arg(options, "-framework");
add_linker_arg(options, framework);
}
else
{
add_linker_arg(options, "-l");
add_linker_arg(options, lib);
}
options->linker_libs[options->linker_lib_count++] = next_arg();
return;
}
case 'P':
if (options->compile_option != COMPILE_NORMAL)
{

View File

@@ -176,6 +176,14 @@ static void update_build_target_from_options(BuildTarget *target, BuildOptions *
{
vec_add(target->link_args, options->linker_args[i]);
}
for (int i = 0; i < options->linker_lib_dir_count; i++)
{
vec_add(target->linker_libdirs, options->linker_lib_dir[i]);
}
for (int i = 0; i < options->linker_lib_count; i++)
{
vec_add(target->linker_libs, options->linker_libs[i]);
}
target->no_stdlib = options->no_stdlib;
target->emit_llvm = options->emit_llvm;
target->emit_asm = options->emit_asm;

View File

@@ -402,7 +402,14 @@ static bool linker_setup(const char ***args_ref, const char **files_to_link, uns
}
if (use_win)
{
add_arg2(lib, ".lib");
if (str_has_suffix(lib, ".lib"))
{
add_arg(lib);
}
else
{
add_arg2(lib, ".lib");
}
}
else
{

View File

@@ -99,6 +99,7 @@ void taskqueue_wait_for_completion(TaskQueueRef queue);
const char *str_remove_suffix(const char *name, const char *suffix);
bool str_has_suffix(const char *name, const char *suffix);
char *str_trim(char *str);
const char *str_trim_start(const char *str);
void str_trim_end(char *str);

View File

@@ -93,6 +93,14 @@ const char *str_remove_suffix(const char *name, const char *suffix)
return name_copy;
}
bool str_has_suffix(const char *name, const char *suffix)
{
size_t name_len = strlen(name);
size_t suffix_len = strlen(suffix);
if (name_len <= suffix_len) return false;
return memcmp(name + name_len - suffix_len, suffix, suffix_len) == 0;
}
StringSlice slice_next_token(StringSlice *slice, char separator)
{

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.3.10"
#define COMPILER_VERSION "0.3.11"