diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-03-21 20:32:48 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-03-21 20:32:48 -0400 |
| commit | 4b0ddb817bb5d4effd8cd2dd0844ac278e35e1d5 (patch) | |
| tree | ea0112fc930bf6a51b62136f10a60560c3c96bd9 /src/codegen.cpp | |
| parent | 28ad78cb7f4a567ce6a595b8ff466e90b311f3e4 (diff) | |
| download | zig-4b0ddb817bb5d4effd8cd2dd0844ac278e35e1d5.tar.gz zig-4b0ddb817bb5d4effd8cd2dd0844ac278e35e1d5.zip | |
zig cc: better support for the preprocessor option (-E)
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index 7729172c2f..7b481f7c21 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -9723,13 +9723,17 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { buf_len(c_source_basename), 0); Buf *final_o_basename = buf_alloc(); - // We special case when doing build-obj for just one C file - if (main_output_dir_is_just_one_c_object_pre(g)) { - buf_init_from_buf(final_o_basename, g->root_out_name); + if (c_file->preprocessor_only_basename == nullptr) { + // We special case when doing build-obj for just one C file + if (main_output_dir_is_just_one_c_object_pre(g)) { + buf_init_from_buf(final_o_basename, g->root_out_name); + } else { + os_path_extname(c_source_basename, final_o_basename, nullptr); + } + buf_append_str(final_o_basename, target_o_file_ext(g->zig_target)); } else { - os_path_extname(c_source_basename, final_o_basename, nullptr); + buf_init_from_str(final_o_basename, c_file->preprocessor_only_basename); } - buf_append_str(final_o_basename, target_o_file_ext(g->zig_target)); CacheHash *cache_hash; if ((err = create_c_object_cache(g, &cache_hash, true))) { @@ -9780,13 +9784,18 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { args.append(buf_ptr(self_exe_path)); args.append("clang"); + if (c_file->preprocessor_only_basename != nullptr) { + args.append("-E"); + } else { + args.append("-c"); + } + Buf *out_dep_path = buf_sprintf("%s.d", buf_ptr(out_obj_path)); add_cc_args(g, args, buf_ptr(out_dep_path), false); args.append("-o"); args.append(buf_ptr(out_obj_path)); - args.append("-c"); args.append(buf_ptr(c_source_file)); for (size_t arg_i = 0; arg_i < c_file->args.length; arg_i += 1) { @@ -9841,6 +9850,7 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { os_path_join(artifact_dir, final_o_basename, o_final_path); } + g->c_artifact_dir = artifact_dir; g->link_objects.append(o_final_path); g->caches_to_release.append(cache_hash); |
