(obj: Object, src_path: Path)
| 1000 | n.newline() |
| 1001 | |
| 1002 | def c_build(obj: Object, src_path: Path) -> Optional[Path]: |
| 1003 | # Avoid creating duplicate build rules |
| 1004 | if obj.src_obj_path is None or obj.src_obj_path in source_added: |
| 1005 | return obj.src_obj_path |
| 1006 | source_added.add(obj.src_obj_path) |
| 1007 | |
| 1008 | cflags = obj.options["cflags"] |
| 1009 | extra_cflags = obj.options["extra_cflags"] |
| 1010 | |
| 1011 | # Add appropriate language flag if it doesn't exist already |
| 1012 | # Added directly to the source so it flows to other generation tasks |
| 1013 | if not any(flag.startswith("-lang") for flag in cflags) and not any( |
| 1014 | flag.startswith("-lang") for flag in extra_cflags |
| 1015 | ): |
| 1016 | # Ensure extra_cflags is a unique instance, |
| 1017 | # and insert into there to avoid modifying shared sets of flags |
| 1018 | extra_cflags = obj.options["extra_cflags"] = list(extra_cflags) |
| 1019 | if file_is_cpp(src_path): |
| 1020 | extra_cflags.insert(0, "-lang=c++") |
| 1021 | else: |
| 1022 | extra_cflags.insert(0, "-lang=c") |
| 1023 | |
| 1024 | all_cflags = cflags + extra_cflags |
| 1025 | cflags_str = make_flags_str(all_cflags) |
| 1026 | used_compiler_versions.add(obj.options["mw_version"]) |
| 1027 | |
| 1028 | # Add MWCC build rule |
| 1029 | lib_name = obj.options["lib"] |
| 1030 | build_rule = "mwcc" |
| 1031 | build_implcit = mwcc_implicit |
| 1032 | variables = { |
| 1033 | "mw_version": Path(obj.options["mw_version"]), |
| 1034 | "cflags": cflags_str, |
| 1035 | "basedir": os.path.dirname(obj.src_obj_path), |
| 1036 | "basefile": obj.src_obj_path.with_suffix(""), |
| 1037 | } |
| 1038 | |
| 1039 | if obj.options["shift_jis"] and obj.options["extab_padding"] is not None: |
| 1040 | build_rule = "mwcc_sjis_extab" |
| 1041 | build_implcit = mwcc_sjis_extab_implicit |
| 1042 | variables["extab_padding"] = "".join( |
| 1043 | f"{i:02x}" for i in obj.options["extab_padding"] |
| 1044 | ) |
| 1045 | elif obj.options["shift_jis"]: |
| 1046 | build_rule = "mwcc_sjis" |
| 1047 | build_implcit = mwcc_sjis_implicit |
| 1048 | elif obj.options["extab_padding"] is not None: |
| 1049 | build_rule = "mwcc_extab" |
| 1050 | build_implcit = mwcc_extab_implicit |
| 1051 | variables["extab_padding"] = "".join( |
| 1052 | f"{i:02x}" for i in obj.options["extab_padding"] |
| 1053 | ) |
| 1054 | n.comment(f"{obj.name}: {lib_name} (linked {obj.completed})") |
| 1055 | n.build( |
| 1056 | outputs=obj.src_obj_path, |
| 1057 | rule=build_rule, |
| 1058 | inputs=src_path, |
| 1059 | variables=variables, |
no test coverage detected